diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 9dfa5ec0f6a74ec1a637637f267cf1abc72df4ab..8eb6ba1f468b7c2c05936abe216ff4356d8b035f 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -21,6 +21,7 @@ group("fuzztest") { "controlchannelstub_fuzzer:fuzztest", "corestub_fuzzer:fuzztest", "datachannelstub_fuzzer:fuzztest", + "enableupgrademanager_fuzzer:fuzztest", "imeenabledinfomanager_fuzzer:fuzztest", "imeeventmonitormanager_fuzzer:fuzztest", "imesystemchannel_fuzzer:fuzztest", diff --git a/test/fuzztest/enableupgrademanager_fuzzer/BUILD.gn b/test/fuzztest/enableupgrademanager_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..97368289f76652e45314c2b481f6c012cd3c6670 --- /dev/null +++ b/test/fuzztest/enableupgrademanager_fuzzer/BUILD.gn @@ -0,0 +1,79 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/inputmethod/imf/inputmethod.gni") + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("EnableUpgradeManagerFuzzTest") { + module_out_path = "imf/imf" + + fuzz_config_file = "//base/inputmethod/imf/test/fuzztest/enableupgrademanager_fuzzer" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + include_dirs = [ + "${inputmethod_path}/common/include", + "${inputmethod_path}/frameworks/native/inputmethod_ability/include", + "${inputmethod_path}/frameworks/native/inputmethod_controller/include", + "${inputmethod_path}/services/adapter/settings_data_provider/common/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + configs = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_native_public_config" ] + sources = [ + "enableupgrademanager_fuzzer.cpp" + ] + + deps = [ + "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability_static", + "${inputmethod_path}/services/adapter/settings_data_provider:settings_data_static", + "${inputmethod_path}/services:inputmethod_service_static", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", + "graphic_2d:librender_service_base", + "hilog:libhilog", + "input:libmmi-client", + "ipc:ipc_single", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":EnableUpgradeManagerFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/enableupgrademanager_fuzzer/corpus/init b/test/fuzztest/enableupgrademanager_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..65af8ee8d11bf23407ea34d4de49f7cbb6a2b791 --- /dev/null +++ b/test/fuzztest/enableupgrademanager_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..45f9a29ee60a4605868f24c40a97332ad067f582 --- /dev/null +++ b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "enableupgrademanager_fuzzer.h" + +#include +#include +#define private public +#define protected public +#include "enable_upgrade_manager.h" +#undef private + +using namespace OHOS::MiscServices; +namespace OHOS { + +void FuzzAgentStub(const uint8_t *data, size_t size) +{ + static std::vector imeInfos; + static std::set bundleNames; + static std::vector bundleNamesVec; + static std::vector enabledInfos; + std::string fuzzedString(reinterpret_cast(data), size); + auto fuzzInt32 = static_cast(size); + auto fuzzUint32 = static_cast(size); + auto fuzzedBool = static_cast(data[0] % 2); + int32_t userId = fuzzInt32; + FullImeInfo imeInfo; + imeInfo.isNewIme = fuzzedBool; + imeInfo.tokenId = fuzzUint32; + imeInfo.versionCode = fuzzUint32; + imeInfos.push_back(imeInfo); + bundleNames.insert(fuzzedString); + bundleNamesVec.push_back(fuzzedString); + ImeEnabledInfo imeEnabeleInfo; + imeEnabeleInfo.bundleName = fuzzedString; + imeEnabeleInfo.extensionName = fuzzedString; + + ImeEnabledCfg newEnabledCfg; + newEnabledCfg.version = fuzzedString; + newEnabledCfg.enabledInfos = enabledInfos; + ImePersistInfo persisInfo; + persisInfo.userId = userId; + persisInfo.currentIme = fuzzedString; + persisInfo.currentSubName = fuzzedString; + persisInfo.tempScreenLockIme = fuzzedString; + persisInfo.isDefaultImeSet = fuzzedBool; + EnabledStatus initStatus = EnabledStatus::DISABLED; + EnableUpgradeManager::GetInstance().Upgrade(userId, imeInfos); + EnableUpgradeManager::GetInstance().GetEnabledTable(userId, bundleNames); + EnableUpgradeManager::GetInstance().GetFullExperienceTable(userId, bundleNames); + EnableUpgradeManager::GetInstance().MergeTwoTable(userId, enabledInfos); + EnableUpgradeManager::GetInstance().PaddedByBundleMgr(userId, imeInfos, enabledInfos); + EnableUpgradeManager::GetInstance().UpdateGlobalEnabledTable(userId, newEnabledCfg); + EnableUpgradeManager::GetInstance().GetGlobalTableUserId(fuzzedString); + EnableUpgradeManager::GetInstance().GenerateGlobalContent(userId, bundleNamesVec); + EnableUpgradeManager::GetInstance().GetImePersistCfg(userId, persisInfo); + EnableUpgradeManager::GetInstance().PaddedByImePersistCfg(userId, enabledInfos); + EnableUpgradeManager::GetInstance().ComputeEnabledStatus(fuzzedString, initStatus); +} +} // namespace OHOS +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::FuzzAgentStub(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.h b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..48398846f4f9a7179726e4212bfd8413c50c0703 --- /dev/null +++ b/test/fuzztest/enableupgrademanager_fuzzer/enableupgrademanager_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ENABLE_UPGRADE_MANAGER_FUZZER_H +#define TEST_FUZZTEST_ENABLE_UPGRADE_MANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "enableupgrademanager_fuzzer" + +#endif // TEST_FUZZTEST_ENABLE_UPGRADE_MANAGER_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/enableupgrademanager_fuzzer/project.xml b/test/fuzztest/enableupgrademanager_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/test/fuzztest/enableupgrademanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/imfhisyseventreport_fuzzer/imfhisyseventreport_fuzzer.cpp b/test/fuzztest/imfhisyseventreport_fuzzer/imfhisyseventreport_fuzzer.cpp index 342dde487bb012f5ee1e693ddb0ff70176d95f76..ff870e5d73101467bff96f17d6c90e1942f56c98 100644 --- a/test/fuzztest/imfhisyseventreport_fuzzer/imfhisyseventreport_fuzzer.cpp +++ b/test/fuzztest/imfhisyseventreport_fuzzer/imfhisyseventreport_fuzzer.cpp @@ -21,6 +21,7 @@ #include "imf_hisysevent_reporter.h" #include "imf_hisysevent_util.h" #include "imsa_hisysevent_reporter.h" +#include "inputmethod_sysevent.h" #undef private #include @@ -143,6 +144,44 @@ void TestRecordBaseTextOperationStatistics(const uint8_t *data, size_t size) ImaHiSysEventReporter::GetInstance().RecordBaseTextOperationStatistics(*info); ImaHiSysEventReporter::GetInstance().RecordImeStartInputStatistics(*info); } + +void TestIntervalIndex(const uint8_t *data, size_t size) +{ + auto fuzzInt32 = static_cast(size); + ImaHiSysEventReporter::GetInstance().GetBaseTextOperationSucceedIntervalIndex(fuzzInt32); + ImaHiSysEventReporter::GetInstance().ReportStatisticsEvent(); + ImaHiSysEventReporter::GetInstance().ModImeCbTimeConsumeInfo(fuzzInt32); +} + +void TestInputMethodSysEvent(const uint8_t *data, size_t size) +{ + auto fuzzInt32 = static_cast(size); + auto fuzzUint32 = static_cast(size); + std::string fuzzedString(reinterpret_cast(data), size); + using TimerCallback = std::function; + TimerCallback tc; + InputMethodSysEvent::GetInstance().ServiceFaultReporter(fuzzedString, fuzzInt32); + InputMethodSysEvent::GetInstance().ImeUsageBehaviourReporter(); + InputMethodSysEvent::GetInstance().GetOperateInfo(fuzzInt32); + InputMethodSysEvent::GetInstance().StartTimer(tc, fuzzUint32); + InputMethodSysEvent::GetInstance().StartTimerForReport(); + InputMethodSysEvent::GetInstance().ReportSystemShortCut(fuzzedString); +} + +void TestOnDemandStartStopSa(const uint8_t *data, size_t size) +{ + auto fuzzInt32 = static_cast(size); + auto fuzzUint32 = static_cast(size); + std::string fuzzedString(reinterpret_cast(data), size); + using TimerCallback = std::function; + TimerCallback tc; + InputMethodSysEvent::GetInstance().ServiceFaultReporter(fuzzedString, fuzzInt32); + InputMethodSysEvent::GetInstance().ImeUsageBehaviourReporter(); + InputMethodSysEvent::GetInstance().GetOperateInfo(fuzzInt32); + InputMethodSysEvent::GetInstance().StartTimer(tc, fuzzUint32); + InputMethodSysEvent::GetInstance().StartTimerForReport(); + InputMethodSysEvent::GetInstance().ReportSystemShortCut(fuzzedString); +} } // namespace OHOS /* Fuzzer entry point */ @@ -158,5 +197,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::TestStartInput(data, size); OHOS::TestBaseTextOperation(data, size); OHOS::TestRecordBaseTextOperationStatistics(data, size); + OHOS::TestIntervalIndex(data, size); + OHOS::TestInputMethodSysEvent(data, size); return 0; } \ No newline at end of file diff --git a/test/fuzztest/settingsdatautils_fuzzer/settingsdatautils_fuzzer.cpp b/test/fuzztest/settingsdatautils_fuzzer/settingsdatautils_fuzzer.cpp index b59566984c9ad7ee05b07dbce4434baac001e478..3076d93ddaa43c2c6d6e28f6c770d459e23132a4 100644 --- a/test/fuzztest/settingsdatautils_fuzzer/settingsdatautils_fuzzer.cpp +++ b/test/fuzztest/settingsdatautils_fuzzer/settingsdatautils_fuzzer.cpp @@ -55,6 +55,12 @@ void FuzzGenerateTargetUri(const std::string &key) { SettingsDataUtils::GetInstance().GenerateTargetUri(SETTING_URI_PROXY, key); } + + +void FuzzSetStringValue(const std::string &key) +{ + SettingsDataUtils::GetInstance().SetStringValue(SETTING_URI_PROXY, key, key); +} } // namespace OHOS /* Fuzzer entry point */ diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index 77f18263d833f89a99c04c44ff28397f4c090da9..eab96a729b6aab180b4cc76bae696b5065979f55 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -2025,5 +2025,23 @@ HWTEST_F(InputMethodControllerTest, GetWindowScaleCoordinate, TestSize.Level0) EXPECT_EQ(x, 101); EXPECT_EQ(y, 101); } + +/** + * @tc.name: TestImcOptionalInputMethod + * @tc.desc: Test ImcOptionalInputMethod + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerTest, TestImcOptionalInputMethod, TestSize.Level0) +{ + IMSA_HILOGI("ImeProxyTest::TestImcOptionalInputMethod"); + Property property; + std::vector subProps; + auto ret = inputMethodController_->ListInputMethodSubtype(property, subProps); + EXPECT_NE(ret, ErrorCode::NO_ERROR); + ret = inputMethodController_->ShowOptionalInputMethod(); + EXPECT_NE(ret, ErrorCode::NO_ERROR); + ret = inputMethodController_->DisplayOptionalInputMethod(); + EXPECT_NE(ret, ErrorCode::NO_ERROR); +} } // namespace MiscServices } // namespace OHOS