diff --git a/interfaces/inner_api/common/common.versionscript b/interfaces/inner_api/common/common.versionscript index 7c66e3a..9f87eac 100644 --- a/interfaces/inner_api/common/common.versionscript +++ b/interfaces/inner_api/common/common.versionscript @@ -25,6 +25,7 @@ *ConvertCallbackProxy*; *WhiteListChecker*; *WhiteListUpdater*; + *WhiteListConfigMgr*; local: *; }; \ No newline at end of file diff --git a/interfaces/inner_api/common/include/config/white_list_updater.h b/interfaces/inner_api/common/include/config/white_list_updater.h index e3c2f82..a01ad13 100644 --- a/interfaces/inner_api/common/include/config/white_list_updater.h +++ b/interfaces/inner_api/common/include/config/white_list_updater.h @@ -21,7 +21,7 @@ class WhiteListUpdater : public WhiteListConfigMgr { public: WhiteListUpdater() = default; ~WhiteListUpdater() override = default; - void UpdateWhiteList(std::unordered_set& whiteList); + void UpdateWhiteList(const std::unordered_set& whiteList); private: std::mutex whiteListLock; diff --git a/interfaces/inner_api/common/src/config/white_list_updater.cpp b/interfaces/inner_api/common/src/config/white_list_updater.cpp index 161b0ea..3ec3b93 100644 --- a/interfaces/inner_api/common/src/config/white_list_updater.cpp +++ b/interfaces/inner_api/common/src/config/white_list_updater.cpp @@ -19,7 +19,7 @@ #include "domain_url_util.h" namespace OHOS::AppDomainVerify { -void WhiteListUpdater::UpdateWhiteList(std::unordered_set& whiteList) +void WhiteListUpdater::UpdateWhiteList(const std::unordered_set& whiteList) { APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "%s called", __func__); if (!init) { diff --git a/interfaces/inner_api/extension/include/app_domain_verify_agent_ext.h b/interfaces/inner_api/extension/include/app_domain_verify_agent_ext.h index 3d407fd..61c822a 100644 --- a/interfaces/inner_api/extension/include/app_domain_verify_agent_ext.h +++ b/interfaces/inner_api/extension/include/app_domain_verify_agent_ext.h @@ -15,6 +15,7 @@ #ifndef APP_DOMAIN_VERIFY_AGENT_EXT_H #define APP_DOMAIN_VERIFY_AGENT_EXT_H #include +#include #include "skill_uri.h" #include "app_domain_verify_error.h" #include "app_domain_verify_ext_base.h" @@ -29,12 +30,14 @@ namespace OHOS { namespace AppDomainVerify { +using OnWhiteListUpdate = std::function)>; class AppDomainVerifyAgentExt : public AppDomainVerifyExtBase { public: virtual ErrorCode CompleteVerifyRefresh(const BundleVerifyStatusInfo& bundleVerifyStatusInfo, const std::vector& statuses, int delaySeconds, TaskType type); virtual ErrorCode SingleVerify(const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector& skillUris); virtual ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr& callback); + virtual ErrorCode UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate); }; } } diff --git a/interfaces/inner_api/extension/include/app_domain_verify_extension_mgr.h b/interfaces/inner_api/extension/include/app_domain_verify_extension_mgr.h index 37704e7..029b0b9 100644 --- a/interfaces/inner_api/extension/include/app_domain_verify_extension_mgr.h +++ b/interfaces/inner_api/extension/include/app_domain_verify_extension_mgr.h @@ -16,6 +16,7 @@ #ifndef APP_DOMAIN_VERIFY_EXTENSION_MGR_H #define APP_DOMAIN_VERIFY_EXTENSION_MGR_H #include +#include #include "app_domain_verify_error.h" #include "skill_uri.h" #include "app_verify_base_info.h" @@ -28,6 +29,7 @@ namespace OHOS { namespace AppDomainVerify { +using OnWhiteListUpdate = std::function)>; class AppDomainVerifyExtensionMgr { public: AppDomainVerifyExtensionMgr(); @@ -36,6 +38,7 @@ public: const std::vector& statuses, int delaySeconds, TaskType type); ErrorCode SingleVerify(const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector& skillUris); ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr& callback); + ErrorCode UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate); protected: virtual bool Init(); diff --git a/interfaces/inner_api/extension/src/app_domain_verify_agent_ext.cpp b/interfaces/inner_api/extension/src/app_domain_verify_agent_ext.cpp index 1e2df63..21d9dee 100644 --- a/interfaces/inner_api/extension/src/app_domain_verify_agent_ext.cpp +++ b/interfaces/inner_api/extension/src/app_domain_verify_agent_ext.cpp @@ -31,5 +31,9 @@ ErrorCode AppDomainVerifyAgentExt::ConvertToExplicitWant(AAFwk::Want& implicitWa { return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND; } +ErrorCode AppDomainVerifyAgentExt::UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate) +{ + return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND; +} } } \ No newline at end of file diff --git a/interfaces/inner_api/extension/src/app_domain_verify_extension_mgr.cpp b/interfaces/inner_api/extension/src/app_domain_verify_extension_mgr.cpp index 095d21a..c4e1343 100644 --- a/interfaces/inner_api/extension/src/app_domain_verify_extension_mgr.cpp +++ b/interfaces/inner_api/extension/src/app_domain_verify_extension_mgr.cpp @@ -118,5 +118,20 @@ ErrorCode AppDomainVerifyExtensionMgr::ConvertToExplicitWant( } return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND; } +ErrorCode AppDomainVerifyExtensionMgr::UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate) +{ + if (Init()) { + std::string verifierExtName = APP_DOMAIN_VERIFY_AGENT_EXT_NAME; + auto appDomainVerifierExt = GetAppDomainVerifyExt(verifierExtName); + if (appDomainVerifierExt != nullptr) { + return std::static_pointer_cast(appDomainVerifierExt) + ->UpdateWhiteList(std::move(onWhiteListUpdate)); + } + APP_DOMAIN_VERIFY_HILOGE( + APP_DOMAIN_VERIFY_MODULE_EXTENSION, "get verifierExt: %{public}s failed.", verifierExtName.c_str()); + return ErrorCode::E_EXTENSIONS_INTERNAL_ERROR; + } + return ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND; +} } } \ No newline at end of file diff --git a/services/include/agent/core/app_domain_verify_agent_service.h b/services/include/agent/core/app_domain_verify_agent_service.h index 47ff504..98131f2 100644 --- a/services/include/agent/core/app_domain_verify_agent_service.h +++ b/services/include/agent/core/app_domain_verify_agent_service.h @@ -25,6 +25,7 @@ #include "i_app_domain_verify_mgr_service.h" #include "app_domain_verify_task_mgr.h" #include "app_domain_verify_hisysevent.h" +#include "white_list_updater.h" namespace OHOS { namespace AppDomainVerify { @@ -34,8 +35,8 @@ class AppDomainVerifyAgentService : public SystemAbility, public AppDomainVerify public: API_EXPORT AppDomainVerifyAgentService(); API_EXPORT virtual ~AppDomainVerifyAgentService(); - API_EXPORT void SingleVerify(const AppVerifyBaseInfo &appVerifyBaseInfo, - const std::vector &skillUris) override; + API_EXPORT void SingleVerify( + const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector& skillUris) override; API_EXPORT void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr& callback) override; protected: @@ -51,11 +52,14 @@ private: void ExecuteVerifyTask( const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector& skillUris, TaskType type); bool IsIdle(); + void OnWhiteListUpdate(const std::unordered_set& whiteList); + void UpdateWhiteList(); private: std::shared_ptr continuationHandler_; std::shared_ptr appDomainVerifyExtMgr_; std::shared_ptr appDomainVerifyTaskMgr_; + std::shared_ptr updater_; }; } // namespace AppDomainVerify diff --git a/services/src/agent/core/app_domain_verify_agent_service.cpp b/services/src/agent/core/app_domain_verify_agent_service.cpp index 10c589a..281d76b 100644 --- a/services/src/agent/core/app_domain_verify_agent_service.cpp +++ b/services/src/agent/core/app_domain_verify_agent_service.cpp @@ -83,8 +83,8 @@ void AppDomainVerifyAgentService::CompleteVerifyRefresh(const BundleVerifyStatus } AppVerifyBaseInfo appVerifyBaseInfo; appVerifyBaseInfo.bundleName = it->first; - if (!BundleInfoQuery::GetBundleInfo(appVerifyBaseInfo.bundleName, appVerifyBaseInfo.appIdentifier, - appVerifyBaseInfo.fingerprint)) { + if (!BundleInfoQuery::GetBundleInfo( + appVerifyBaseInfo.bundleName, appVerifyBaseInfo.appIdentifier, appVerifyBaseInfo.fingerprint)) { APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "GetBundleInfo failed."); // todo delete this bundleName or not continue; @@ -163,6 +163,8 @@ void AppDomainVerifyAgentService::OnStart(const SystemAbilityOnDemandReason& sta InnerVerifyStatus::FAILURE_TIMEOUT }, 0, type); }; + auto updateWhiteListFunc = [this]() { UpdateWhiteList(); }; + continuationHandler_->submit(updateWhiteListFunc); continuationHandler_->submit(func); } @@ -204,5 +206,26 @@ bool AppDomainVerifyAgentService::IsIdle() return appDomainVerifyTaskMgr_->IsIdle(); } } +void AppDomainVerifyAgentService::OnWhiteListUpdate(const std::unordered_set& whiteList) +{ + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "%s called", __func__); + if (updater_ == nullptr) { + updater_ = std::make_shared(); + } + if (updater_) { + updater_->UpdateWhiteList(whiteList); + } else { + APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "can not update"); + } +} +void AppDomainVerifyAgentService::UpdateWhiteList() +{ + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "%s called", __func__); + auto onUpdate = [this](auto&& set) { OnWhiteListUpdate(std::forward(set)); }; + if (ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND != appDomainVerifyExtMgr_->UpdateWhiteList(std::move(onUpdate))) { + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "extension call end"); + return; + } +} } // namespace AppDomainVerify } // namespace OHOS diff --git a/test/unittest/extension/app_domain_verify_agent_ext_test/app_domain_verify_agent_ext_test.cpp b/test/unittest/extension/app_domain_verify_agent_ext_test/app_domain_verify_agent_ext_test.cpp index 59ebb06..9f77b9a 100644 --- a/test/unittest/extension/app_domain_verify_agent_ext_test/app_domain_verify_agent_ext_test.cpp +++ b/test/unittest/extension/app_domain_verify_agent_ext_test/app_domain_verify_agent_ext_test.cpp @@ -89,4 +89,15 @@ HWTEST_F(AppDomainVerifyAgentExtTest, AppDomainVerifyAgentExtTest002, TestSize.L ASSERT_TRUE(appDomainVerifyAgentExt.CompleteVerifyRefresh(bundleVerifyStatusInfo, statuses, delaySeconds, type) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); } +/** + * @tc.name: AppDomainVerifyAgentExtTest003 + * @tc.desc: ExtensionMgr test. + * @tc.type: FUNC + */ +HWTEST_F(AppDomainVerifyAgentExtTest, AppDomainVerifyAgentExtTest003, TestSize.Level0) +{ + AppDomainVerifyAgentExt appDomainVerifyAgentExt; + OnWhiteListUpdate func; + ASSERT_TRUE(appDomainVerifyAgentExt.UpdateWhiteList(std::move(func)) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); +} } diff --git a/test/unittest/extension/app_domain_verify_extension_mgr_test/app_domain_verify_extension_mgr_test.cpp b/test/unittest/extension/app_domain_verify_extension_mgr_test/app_domain_verify_extension_mgr_test.cpp index 374c17d..98e3dfe 100644 --- a/test/unittest/extension/app_domain_verify_extension_mgr_test/app_domain_verify_extension_mgr_test.cpp +++ b/test/unittest/extension/app_domain_verify_extension_mgr_test/app_domain_verify_extension_mgr_test.cpp @@ -91,8 +91,8 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest002, Te const std::vector statuses; int delaySeconds = 0; TaskType type = IMMEDIATE_TASK; - ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh(bundleVerifyStatusInfo, statuses, delaySeconds, - type) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); + ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh( + bundleVerifyStatusInfo, statuses, delaySeconds, type) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); } /** * @tc.name: AppDomainVerifyExtensionMgrTest003 @@ -129,8 +129,8 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest004, Te const std::vector statuses; int delaySeconds = 0; TaskType type = IMMEDIATE_TASK; - ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh(bundleVerifyStatusInfo, statuses, delaySeconds, - type) == ErrorCode::E_EXTENSIONS_INTERNAL_ERROR); + ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh( + bundleVerifyStatusInfo, statuses, delaySeconds, type) == ErrorCode::E_EXTENSIONS_INTERNAL_ERROR); } /** * @tc.name: AppDomainVerifyExtensionMgrTest005 @@ -215,8 +215,8 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest009, Te const std::vector statuses; int delaySeconds = 0; TaskType type = IMMEDIATE_TASK; - ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh(bundleVerifyStatusInfo, statuses, delaySeconds, - type) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); + ASSERT_TRUE(appDomainVerifyExtensionMgr.CompleteVerifyRefresh( + bundleVerifyStatusInfo, statuses, delaySeconds, type) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); } /** @@ -231,7 +231,7 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest010, Te } /** - * @tc.name: AppDomainVerifyExtensionMgrTest006 + * @tc.name: AppDomainVerifyExtensionMgrTest011 * @tc.desc: ExtensionMgr test. * @tc.type: FUNC */ @@ -244,6 +244,21 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest011, Te ASSERT_TRUE(appDomainVerifyExtensionMgr.Init() == true); APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_EXTENSION, "AppDomainVerifyExtensionMgrTest011 end"); } +/** + * @tc.name: AppDomainVerifyExtensionMgrTest012 + * @tc.desc: ExtensionMgr test. + * @tc.type: FUNC + */ +HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest012, TestSize.Level0) +{ + OnWhiteListUpdate func; + MockAppDomainVerifyExtensionMgr appDomainVerifyExtensionMgr; + EXPECT_CALL(appDomainVerifyExtensionMgr, Init()).Times(1).WillOnce(Return(false)); + + const AppVerifyBaseInfo appVerifyBaseInfo; + std::vector skillUris; + ASSERT_TRUE(appDomainVerifyExtensionMgr.UpdateWhiteList(std::move(func)) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND); +} /** * @tc.name: AppDomainVerifyExtensionRegisterTest001 * @tc.desc: ExtensionMgr test.