!46 通过ext 刷新白名单

Merge pull request !46 from WoHoo/master
This commit is contained in:
openharmony_ci 2024-05-31 08:22:02 +00:00 committed by Gitee
commit 73efa177d4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 92 additions and 13 deletions

View File

@ -25,6 +25,7 @@
*ConvertCallbackProxy*;
*WhiteListChecker*;
*WhiteListUpdater*;
*WhiteListConfigMgr*;
local:
*;
};

View File

@ -21,7 +21,7 @@ class WhiteListUpdater : public WhiteListConfigMgr {
public:
WhiteListUpdater() = default;
~WhiteListUpdater() override = default;
void UpdateWhiteList(std::unordered_set<std::string>& whiteList);
void UpdateWhiteList(const std::unordered_set<std::string>& whiteList);
private:
std::mutex whiteListLock;

View File

@ -19,7 +19,7 @@
#include "domain_url_util.h"
namespace OHOS::AppDomainVerify {
void WhiteListUpdater::UpdateWhiteList(std::unordered_set<std::string>& whiteList)
void WhiteListUpdater::UpdateWhiteList(const std::unordered_set<std::string>& whiteList)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "%s called", __func__);
if (!init) {

View File

@ -15,6 +15,7 @@
#ifndef APP_DOMAIN_VERIFY_AGENT_EXT_H
#define APP_DOMAIN_VERIFY_AGENT_EXT_H
#include <string>
#include <unordered_set>
#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<void(std::unordered_set<std::string>)>;
class AppDomainVerifyAgentExt : public AppDomainVerifyExtBase {
public:
virtual ErrorCode CompleteVerifyRefresh(const BundleVerifyStatusInfo& bundleVerifyStatusInfo,
const std::vector<InnerVerifyStatus>& statuses, int delaySeconds, TaskType type);
virtual ErrorCode SingleVerify(const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector<SkillUri>& skillUris);
virtual ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback);
virtual ErrorCode UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate);
};
}
}

View File

@ -16,6 +16,7 @@
#ifndef APP_DOMAIN_VERIFY_EXTENSION_MGR_H
#define APP_DOMAIN_VERIFY_EXTENSION_MGR_H
#include <mutex>
#include <unordered_set>
#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<void(std::unordered_set<std::string>)>;
class AppDomainVerifyExtensionMgr {
public:
AppDomainVerifyExtensionMgr();
@ -36,6 +38,7 @@ public:
const std::vector<InnerVerifyStatus>& statuses, int delaySeconds, TaskType type);
ErrorCode SingleVerify(const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector<SkillUri>& skillUris);
ErrorCode ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback);
ErrorCode UpdateWhiteList(OnWhiteListUpdate&& onWhiteListUpdate);
protected:
virtual bool Init();

View File

@ -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;
}
}
}

View File

@ -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<AppDomainVerifyAgentExt>(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;
}
}
}

View File

@ -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<SkillUri> &skillUris) override;
API_EXPORT void SingleVerify(
const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector<SkillUri>& skillUris) override;
API_EXPORT void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback) override;
protected:
@ -51,11 +52,14 @@ private:
void ExecuteVerifyTask(
const AppVerifyBaseInfo& appVerifyBaseInfo, const std::vector<SkillUri>& skillUris, TaskType type);
bool IsIdle();
void OnWhiteListUpdate(const std::unordered_set<std::string>& whiteList);
void UpdateWhiteList();
private:
std::shared_ptr<ffrt::queue> continuationHandler_;
std::shared_ptr<AppDomainVerifyExtensionMgr> appDomainVerifyExtMgr_;
std::shared_ptr<AppDomainVerifyTaskMgr> appDomainVerifyTaskMgr_;
std::shared_ptr<WhiteListUpdater> updater_;
};
} // namespace AppDomainVerify

View File

@ -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<std::string>& whiteList)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "%s called", __func__);
if (updater_ == nullptr) {
updater_ = std::make_shared<WhiteListUpdater>();
}
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<decltype(set)>(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

View File

@ -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);
}
}

View File

@ -91,8 +91,8 @@ HWTEST_F(AppDomainVerifyExtensionMgrTest, AppDomainVerifyExtensionMgrTest002, Te
const std::vector<InnerVerifyStatus> 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<InnerVerifyStatus> 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<InnerVerifyStatus> 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<SkillUri> skillUris;
ASSERT_TRUE(appDomainVerifyExtensionMgr.UpdateWhiteList(std::move(func)) == ErrorCode::E_EXTENSIONS_LIB_NOT_FOUND);
}
/**
* @tc.name: AppDomainVerifyExtensionRegisterTest001
* @tc.desc: ExtensionMgr test.