diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 3de451c3c24cd313cefd3f9fbd5d22bd526299dc..64da555c53eddfb5f7c171e768108c51304132ce 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -170,6 +170,7 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/data_uri_utils.cpp", "${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp", "${ability_runtime_native_path}/ability/native/extension.cpp", + "${ability_runtime_native_path}/ability/native/extension_config_mgr.cpp", "${ability_runtime_native_path}/ability/native/extension_impl.cpp", "${ability_runtime_native_path}/ability/native/extension_module_loader.cpp", "${ability_runtime_native_path}/ability/native/mission_information.cpp", @@ -196,6 +197,7 @@ ohos_shared_library("abilitykit_native") { deps = [ ":continuation_ipc", + ":extension_blocklist_config", "${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/appkit:app_context", @@ -557,4 +559,14 @@ ohos_shared_library("dialog_request_callback") { subsystem_name = "ability" part_name = "ability_runtime" +} + +ohos_prebuilt_etc("extension_blocklist_config.json") { + source = "etc/extension_blocklist_config.json" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +group("extension_blocklist_config") { + deps = [ ":extension_blocklist_config.json" ] } \ No newline at end of file diff --git a/frameworks/native/ability/native/etc/extension_blocklist_config.json b/frameworks/native/ability/native/etc/extension_blocklist_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b29bcbee6f819263d69ec87382c380c5ebb1881c --- /dev/null +++ b/frameworks/native/ability/native/etc/extension_blocklist_config.json @@ -0,0 +1,22 @@ +{ + "blocklist": { + "ServiceExtension": [], + "FormExtension": [ + "ability.particleAbility", + "resourceschedule.backgroundTaskManager", + "multimedia.camera", + "multimedia.audio", + "multimedia.media" + ], + "FileAccessExtension": [], + "BackupExtension": [], + "EnterpriseAdminExtension": [], + "WindowExtensionExtension": [], + "WallpaperExtension": [], + "StaticSubscriberExtension": [], + "AccessibilityExtension": [], + "InputMethodExtension": [], + "WorkSchedulerExtension": [], + "DataShareExtension": [] + } +} \ No newline at end of file diff --git a/frameworks/native/ability/native/extension_config_mgr.cpp b/frameworks/native/ability/native/extension_config_mgr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a71a1082af68d96597063930e013b95d5f2358c --- /dev/null +++ b/frameworks/native/ability/native/extension_config_mgr.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2023 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 "extension_config_mgr.h" + +#include +#include + +#include "hilog_wrapper.h" + +namespace OHOS::AbilityRuntime { +namespace { + constexpr char EXTENSION_BLOCKLIST_FILE_PATH[] = "/system/etc/extension_blocklist_config.json"; + constexpr char BACK_SLASH[] = "/"; +} + +void ExtensionConfigMgr::Init() +{ + // clear cached data + blocklistConfig_.clear(); + extensionBlocklist_.clear(); + + // read blocklist from extension_blocklist_config.json + std::ifstream inFile; + inFile.open(EXTENSION_BLOCKLIST_FILE_PATH, std::ios::in); + if (!inFile.is_open()) { + HILOG_ERROR("read extension config error"); + return; + } + nlohmann::json extensionConfig; + inFile >> extensionConfig; + if (extensionConfig.is_discarded()) { + HILOG_ERROR("extension config json discarded error"); + inFile.close(); + return; + } + if (!extensionConfig.contains(ExtensionConfigItem::ITEM_NAME_BLOCKLIST)) { + HILOG_ERROR("extension config file have no blocklist node"); + inFile.close(); + return; + } + auto blackList = extensionConfig.at(ExtensionConfigItem::ITEM_NAME_BLOCKLIST); + std::unordered_set currentBlockList; + for (const auto& item : blackList.items()) { + if (!blackList[item.key()].is_array()) { + continue; + } + for (const auto& value : blackList[item.key()]) { + currentBlockList.emplace(value.get()); + } + blocklistConfig_.emplace(item.key(), std::move(currentBlockList)); + currentBlockList.clear(); + } + inFile.close(); +} + +void ExtensionConfigMgr::UpdateBundleExtensionInfo(NativeEngine& engine, AppExecFwk::BundleInfo& bundleInfo) +{ + std::unordered_map extensionInfo; + for (const auto &info : bundleInfo.extensionInfos) { + std::string path = info.moduleName + BACK_SLASH + info.srcEntrance; + extensionInfo.emplace(path, static_cast(info.type)); + } + engine.SetExtensionInfos(std::move(extensionInfo)); +} + +void ExtensionConfigMgr::AddBlockListItem(const std::string& name, int32_t type) +{ + HILOG_INFO("AddBlockListItem name = %{public}s, type = %{public}d", name.c_str(), type); + auto iter = blocklistConfig_.find(name); + if (iter == blocklistConfig_.end()) { + HILOG_ERROR("Extension name = %{public}s, not exist in blocklist config", name.c_str()); + return; + } + extensionBlocklist_.emplace(type, iter->second); +} + +void ExtensionConfigMgr::UpdateBlockListToEngine(NativeEngine& engine) +{ + engine.SetModuleBlocklist(std::forward(extensionBlocklist_)); +} +} \ No newline at end of file diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 6ee0b9e474086d442d2f5b1c29bf5bd5c57b5abc..0754c4043e534e5c700ec2b4262e6377ea504b55 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1105,15 +1105,18 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con AbilityLoader::GetInstance().RegisterExtension("FormExtension", [application = application_]() { return AbilityRuntime::FormExtension::Create(application->GetRuntime()); }); + AddExtensionBlockItem("FormExtension", static_cast(ExtensionAbilityType::FORM)); #endif AbilityLoader::GetInstance().RegisterExtension("StaticSubscriberExtension", [application = application_]() { return AbilityRuntime::StaticSubscriberExtension::Create(application->GetRuntime()); }); + AddExtensionBlockItem("StaticSubscriberExtension", + static_cast(ExtensionAbilityType::STATICSUBSCRIBER)); #ifdef APP_USE_ARM - LoadAllExtensions("system/lib/extensionability"); + LoadAllExtensions(jsEngine, "system/lib/extensionability"); #else - LoadAllExtensions("system/lib64/extensionability"); + LoadAllExtensions(jsEngine, "system/lib64/extensionability"); #endif std::shared_ptr nativeEngine(&jsEngine); idleTime_ = std::make_shared(mainHandler_, nativeEngine); @@ -1267,13 +1270,17 @@ void MainThread::HandleAbilityStage(const HapModuleInfo &abilityStage) appMgr_->AddAbilityStageDone(applicationImpl_->GetRecordId()); } -void MainThread::LoadAllExtensions(const std::string &filePath) +void MainThread::LoadAllExtensions(NativeEngine &nativeEngine, const std::string &filePath) { HILOG_DEBUG("LoadAllExtensions.filePath:%{public}s", filePath.c_str()); if (application_ == nullptr) { HILOG_ERROR("application launch failed"); return; } + if (!extensionConfigMgr_) { + return; + } + // scan all extensions in path std::vector extensionFiles; ScanDir(filePath, extensionFiles); @@ -1281,6 +1288,8 @@ void MainThread::LoadAllExtensions(const std::string &filePath) HILOG_ERROR("no extension files."); return; } + + std::map> extensionBlacklist; std::map extensionTypeMap; for (auto file : extensionFiles) { HILOG_DEBUG("Begin load extension file:%{public}s", file.c_str()); @@ -1312,12 +1321,15 @@ void MainThread::LoadAllExtensions(const std::string &filePath) std::string extensionName = it->second; extensionTypeMap.insert(std::pair(type, extensionName)); + AddExtensionBlockItem(extensionName, type); + HILOG_DEBUG("Success load extension type: %{public}d, name:%{public}s", type, extensionName.c_str()); AbilityLoader::GetInstance().RegisterExtension(extensionName, [application = application_, file]() { return AbilityRuntime::ExtensionModuleLoader::GetLoader(file.c_str()).Create(application->GetRuntime()); }); } application_->SetExtensionTypeMap(extensionTypeMap); + UpdateEngineExtensionBlockList(nativeEngine); } bool MainThread::PrepareAbilityDelegator(const std::shared_ptr &record, bool isStageBased, @@ -1407,6 +1419,7 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & mainThreadState_ = MainThreadState::RUNNING; std::shared_ptr stageContext = application_->AddAbilityStage(abilityRecord); + UpdateProcessExtensionType(abilityRecord); #ifdef APP_ABILITY_USE_TWO_RUNNER AbilityThread::AbilityThreadMain(application_, abilityRecord, stageContext); #else @@ -1704,6 +1717,7 @@ void MainThread::Init(const std::shared_ptr &runner) mainHandler_ = std::make_shared(runner, this); watchdog_ = std::make_shared(); signalHandler_ = std::make_shared(EventRunner::Create(SIGNAL_HANDLER)); + extensionConfigMgr_ = std::make_unique(); wptr weak = this; auto task = [weak]() { auto appThread = weak.promote(); @@ -1719,6 +1733,7 @@ void MainThread::Init(const std::shared_ptr &runner) TaskTimeoutDetected(runner); watchdog_->Init(mainHandler_); + extensionConfigMgr_->Init(); HILOG_DEBUG("MainThread:Init end."); } @@ -2213,5 +2228,41 @@ int32_t MainThread::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleNam return NO_ERROR; } + +void MainThread::UpdateProcessExtensionType(const std::shared_ptr &abilityRecord) +{ + auto &runtime = application_->GetRuntime(); + if (!runtime) { + HILOG_ERROR("Get runtime failed"); + return; + } + if (!abilityRecord) { + HILOG_ERROR("abilityRecord is nullptr"); + return; + } + auto &abilityInfo = abilityRecord->GetAbilityInfo(); + if (!abilityInfo) { + HILOG_ERROR("Get abilityInfo failed"); + return; + } + runtime->UpdateExtensionType(static_cast(abilityInfo->extensionAbilityType)); + HILOG_INFO("UpdateExtensionType, type = %{public}d", static_cast(abilityInfo->extensionAbilityType)); +} + +void MainThread::AddExtensionBlockItem(const std::string &extensionName, int32_t type) +{ + if (!extensionConfigMgr_) { + return; + } + extensionConfigMgr_->AddBlockListItem(extensionName, type); +} + +void MainThread::UpdateEngineExtensionBlockList(NativeEngine &nativeEngine) +{ + if (!extensionConfigMgr_) { + return; + } + extensionConfigMgr_->UpdateBlockListToEngine(nativeEngine); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 1d54c48ec1b7ddd472668c2e5a24392a7b939367..5dc1eb613b8fdc018ee67f518426eaee94cb393b 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -847,5 +847,19 @@ void JsRuntime::PreloadSystemModule(const std::string& moduleName) NativeValue* className = nativeEngine_->CreateString(moduleName.c_str(), moduleName.length()); nativeEngine_->CallFunction(nativeEngine_->GetGlobal(), methodRequireNapiRef_->Get(), &className, 1); } + +void JsRuntime::UpdateExtensionType(int32_t extensionType) +{ + if (nativeEngine_ == nullptr) { + HILOG_ERROR("UpdateExtensionType error, nativeEngine_ is nullptr"); + return; + } + NativeModuleManager* moduleManager = nativeEngine_->GetModuleManager(); + if (moduleManager == nullptr) { + HILOG_ERROR("UpdateExtensionType error, moduleManager is nullptr"); + return; + } + moduleManager->SetProcessExtensionType(extensionType); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index e6429303b94de993afe62053fdae4798d8c0761b..ed852e1a05f49ce554d13dc9ed623a0f2c30b258 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -70,6 +70,7 @@ public: void PreloadSystemModule(const std::string& moduleName) override; virtual void UpdateModuleNameAndAssetPath(const std::string& moduleName) {} + void UpdateExtensionType(int32_t extensionType) override; protected: JsRuntime() = default; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 7dc8ce5f5174840cf553631b0cde4611ebb9ab92..73b07ca5c8856cfa61d37dcf475b0ca9fac7b087 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -73,6 +73,7 @@ public: virtual bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) = 0; virtual bool NotifyHotReloadPage() = 0; virtual bool UnLoadRepairPatch(const std::string& patchFile) = 0; + virtual void UpdateExtensionType(int32_t extensionType) = 0; Runtime(const Runtime&) = delete; Runtime(Runtime&&) = delete; diff --git a/interfaces/kits/native/ability/native/extension_config_mgr.h b/interfaces/kits/native/ability/native/extension_config_mgr.h new file mode 100644 index 0000000000000000000000000000000000000000..41eca728a51d2ca20516cd6072764af974b0c366 --- /dev/null +++ b/interfaces/kits/native/ability/native/extension_config_mgr.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 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 OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H +#define OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H + +#include +#include +#include + +#include "bundle_info.h" +#include "extension_ability_info.h" +#include "native_engine/native_engine.h" + +namespace OHOS::AbilityRuntime { +namespace ExtensionConfigItem { + constexpr char ITEM_NAME_BLOCKLIST[] = "blocklist"; +} + +/** + * @brief Manage extension configuration. + */ +class ExtensionConfigMgr { +public: + ExtensionConfigMgr() = default; + + virtual ~ExtensionConfigMgr() = default; + + /** + * @brief ExtensionConfigMgr initialization + * + */ + void Init(); + + /** + * @brief Update bundle extension information + * + * @param engine JS NativeEngine + */ + void UpdateBundleExtensionInfo(NativeEngine &engine, AppExecFwk::BundleInfo &bundleInfo); + + /** + * @brief Add extension blocklist item + * + * @param name Extension name + * @param type Extension type + */ + void AddBlockListItem(const std::string &name, int32_t type); + + /** + * @brief Update extension blocklist to native engine + * + * @param engine JS NativeEngine + */ + void UpdateBlockListToEngine(NativeEngine &engine); + +private: + std::unordered_map> blocklistConfig_; + std::unordered_map> extensionBlocklist_; +}; +} // namespace OHOS::AbilityRuntime + +#endif // OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_HANDLER_H diff --git a/interfaces/kits/native/appkit/app/main_thread.h b/interfaces/kits/native/appkit/app/main_thread.h index 56de466979c0380b4dd833981c5523707497afc0..2e4ca84e57de9335c7e56398cb15e159a62e6b8d 100644 --- a/interfaces/kits/native/appkit/app/main_thread.h +++ b/interfaces/kits/native/appkit/app/main_thread.h @@ -19,6 +19,7 @@ #include #include #include "event_handler.h" +#include "extension_config_mgr.h" #include "idle_time.h" #include "inner_event.h" #include "app_scheduler_host.h" @@ -28,6 +29,7 @@ #include "resource_manager.h" #include "foundation/ability/ability_runtime/interfaces/inner_api/runtime/include/runtime.h" #include "ipc_singleton.h" +#include "native_engine/native_engine.h" #include "watchdog.h" #define ABILITY_LIBRARY_LOADER @@ -438,7 +440,13 @@ private: */ bool IsApplicationReady() const; - void LoadAllExtensions(const std::string &filePath); + /** + * @brief Load all extension so + * + * @param nativeEngine nativeEngine + * @param filePath extension so file path + */ + void LoadAllExtensions(NativeEngine &nativeEngine, const std::string &filePath); /** * @@ -450,6 +458,28 @@ private: bool PrepareAbilityDelegator(const std::shared_ptr &record, bool isStageBased, BundleInfo& bundleInfo); + /** + * @brief Update current process extension type + * + * @param abilityRecord current running ability record + */ + void UpdateProcessExtensionType(const std::shared_ptr &abilityRecord); + + /** + * @brief Add Extension block item + * + * @param extensionName extension name + * @param type extension type + */ + void AddExtensionBlockItem(const std::string &extensionName, int32_t type); + + /** + * @brief Update extension block list to nativeEngine + * + * @param nativeEngine nativeEngine instance + */ + void UpdateEngineExtensionBlockList(NativeEngine &nativeEngine); + static void HandleDumpHeap(bool isPrivate); static void HandleSignal(int signal); @@ -486,6 +516,7 @@ private: static std::shared_ptr mainHandler_; std::shared_ptr abilityRecordMgr_ = nullptr; std::shared_ptr watchdog_ = nullptr; + std::unique_ptr extensionConfigMgr_ = nullptr; MainThreadState mainThreadState_ = MainThreadState::INIT; sptr appMgr_ = nullptr; // appMgrService Handler sptr deathRecipient_ = nullptr; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 98f8b1cac290da20759f4a50dc9b8a60ab859722..5a86accd7eccf74a6c82013c81e96489ad118c6f 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -351,6 +351,7 @@ group("unittest") { "dlp_state_item_test:unittest", "dlp_utils_test:unittest", "event_report_test:unittest", + "extension_config_mgr_test:unittest", "file_path_utils_test:unittest", "form_extension_context_test:unittest", "frameworks_kits_ability_ability_runtime_test:unittest", diff --git a/test/unittest/extension_config_mgr_test/BUILD.gn b/test/unittest/extension_config_mgr_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ce9e7b17241803c02f1b4fd295014bf616309d1f --- /dev/null +++ b/test/unittest/extension_config_mgr_test/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2022 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/extension" + +ohos_unittest("extension_config_mgr_test") { + module_out_path = module_output_path + + sources = [ "extension_config_mgr_test.cpp" ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native" ] + + external_deps = [ + "bundle_framework:appexecfwk_base", + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + ] +} + +group("unittest") { + testonly = true + deps = [ ":extension_config_mgr_test" ] +} diff --git a/test/unittest/extension_config_mgr_test/extension_config_mgr_test.cpp b/test/unittest/extension_config_mgr_test/extension_config_mgr_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..46f86604ec7819da573c750b2de37ea0a14e046e --- /dev/null +++ b/test/unittest/extension_config_mgr_test/extension_config_mgr_test.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#define protected public +#include "extension_config_mgr.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { +namespace { + constexpr int32_t DEFAULT_BLOCKLIST_EXTENSION_NUM = 12; + constexpr int32_t EXTENSION_TYPE_FORM = 0; + constexpr int32_t EXTENSION_TYPE_WORK_SCHEDULER = 1; + constexpr int32_t EXTENSION_TYPE_INPUTMETHOD = 2; + constexpr int32_t EXTENSION_TYPE_SERVICE = 3; + constexpr int32_t EXTENSION_TYPE_ACCESSIBILITY = 4; + constexpr int32_t EXTENSION_TYPE_DATASHARE = 5; + constexpr int32_t EXTENSION_TYPE_STATICSUBSCRIBER = 7; + constexpr int32_t EXTENSION_TYPE_WALLPAPER = 8; + constexpr int32_t EXTENSION_TYPE_BACKUP = 9; + constexpr int32_t EXTENSION_TYPE_WINDOW = 10; + constexpr int32_t EXTENSION_TYPE_ENTERPRISE_ADMIN = 11; + constexpr int32_t EXTENSION_TYPE_FILE_ACCESS = 12; + constexpr char BLOCK_LIST_ITEM_SERVICE_EXTENSION[] = "ServiceExtension"; + constexpr char BLOCK_LIST_ITEM_FORM_EXTENSION[] = "FormExtension"; + constexpr char BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION[] = "FileAccessExtension"; + constexpr char BLOCK_LIST_ITEM_BACKUP_EXTENSION[] = "BackupExtension"; + constexpr char BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION[] = "EnterpriseAdminExtension"; + constexpr char BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION[] = "WindowExtensionExtension"; + constexpr char BLOCK_LIST_ITEM_WALLPAPER_EXTENSION[] = "WallpaperExtension"; + constexpr char BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION[] = "StaticSubscriberExtension"; + constexpr char BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION[] = "AccessibilityExtension"; + constexpr char BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION[] = "InputMethodExtension"; + constexpr char BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION[] = "WorkSchedulerExtension"; + constexpr char BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION[] = "DataShareExtension"; + constexpr char INVAILD_BLOCK_LIST_ITEM[] = "InvaildExtension"; +} + +class ExtensionConfigMgrTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void ExtensionConfigMgrTest::SetUpTestCase() +{} + +void ExtensionConfigMgrTest::TearDownTestCase() +{} + +void ExtensionConfigMgrTest::SetUp() +{} + +void ExtensionConfigMgrTest::TearDown() +{} + +/** + * @tc.name: Init_0100 + * @tc.desc: Init Test + * @tc.type: FUNC + * @tc.require: issueI581T3 + */ +HWTEST_F(ExtensionConfigMgrTest, Init_0100, TestSize.Level0) +{ + ExtensionConfigMgr mgr; + mgr.Init(); + EXPECT_EQ(static_cast(mgr.blocklistConfig_.size()), DEFAULT_BLOCKLIST_EXTENSION_NUM); + bool result = false; + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_SERVICE_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FORM_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_BACKUP_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); + result = (mgr.blocklistConfig_.find(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION) != mgr.blocklistConfig_.end()); + EXPECT_TRUE(result); +} + +/** + * @tc.name: AddBlockListItem_0100 + * @tc.desc: AddBlockListItem Test + * @tc.type: FUNC + * @tc.require: issueI581T3 + */ +HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0100, TestSize.Level0) +{ + ExtensionConfigMgr mgr; + mgr.Init(); + bool result = false; + mgr.AddBlockListItem(BLOCK_LIST_ITEM_FORM_EXTENSION, EXTENSION_TYPE_FORM); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_WORK_SCHEDULER_EXTENSION, EXTENSION_TYPE_WORK_SCHEDULER); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WORK_SCHEDULER) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_INPUT_METHOD_EXTENSION, EXTENSION_TYPE_INPUTMETHOD); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_INPUTMETHOD) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_SERVICE_EXTENSION, EXTENSION_TYPE_SERVICE); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_SERVICE) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_ACCESSIBILITY_EXTENSION, EXTENSION_TYPE_ACCESSIBILITY); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ACCESSIBILITY) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_DATA_SHARE_EXTENSION, EXTENSION_TYPE_DATASHARE); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_DATASHARE) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_STATIC_SUBSCRIBER_EXTENSION, EXTENSION_TYPE_STATICSUBSCRIBER); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_STATICSUBSCRIBER) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_WALLPAPER_EXTENSION, EXTENSION_TYPE_WALLPAPER); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WALLPAPER) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_BACKUP_EXTENSION, EXTENSION_TYPE_BACKUP); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_BACKUP) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_WINDOW_EXTENSION_EXTENSION, EXTENSION_TYPE_WINDOW); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_WINDOW) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_ENTERPRISE_ADMIN_EXTENSION, EXTENSION_TYPE_ENTERPRISE_ADMIN); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_ENTERPRISE_ADMIN) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); + mgr.AddBlockListItem(BLOCK_LIST_ITEM_FILE_ACCESS_EXTENSION, EXTENSION_TYPE_FILE_ACCESS); + result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FILE_ACCESS) != mgr.extensionBlocklist_.end()); + EXPECT_TRUE(result); +} + +/** + * @tc.name: AddBlockListItem_0200 + * @tc.desc: AddBlockListItem Test + * @tc.type: FUNC + * @tc.require: issueI5825N + */ +HWTEST_F(ExtensionConfigMgrTest, AddBlockListItem_0200, TestSize.Level0) +{ + ExtensionConfigMgr mgr; + mgr.Init(); + mgr.AddBlockListItem(INVAILD_BLOCK_LIST_ITEM, EXTENSION_TYPE_FORM); + bool result = (mgr.extensionBlocklist_.find(EXTENSION_TYPE_FORM) != mgr.extensionBlocklist_.end()); + EXPECT_FALSE(result); +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index d6c4d5d8e3c600d58424a85d64da1de856e6fed7..2b58a5a298fc28c025e293e62a4cfeaf86911aca 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -236,6 +236,7 @@ ohos_unittest("application_impl_test") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "napi:ace_napi", ] } @@ -373,6 +374,7 @@ ohos_unittest("ability_stage_test") { "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "napi:ace_napi", ] }