!119 support deferred link

Merge pull request !119 from WoHoo/master
This commit is contained in:
openharmony_ci 2024-11-11 04:24:17 +00:00 committed by Gitee
commit 2952e7ec3d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 1413 additions and 56 deletions

113
.clang-format Normal file
View File

@ -0,0 +1,113 @@
---
BasedOnStyle: LLVM
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 60
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 1
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never

View File

@ -22,6 +22,9 @@ app_domain_verify_root_path = "//foundation/bundlemanager/app_domain_verify"
app_domain_verify_client_path =
"${app_domain_verify_root_path}/interfaces/inner_api/client"
app_domain_verify_kits_path =
"${app_domain_verify_root_path}/interfaces/kits/js"
app_domain_verify_service_path = "${app_domain_verify_root_path}/services"
app_domain_verify_common_path =

View File

@ -19,16 +19,21 @@
namespace OHOS {
namespace AppDomainVerify {
using Want = OHOS::AAFwk::Want;
using AbilityInfo = OHOS::AppExecFwk::AbilityInfo;
constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData";
constexpr const char* ENTITY_BROWSER = "entity.system.browsable";
class BundleInfoQuery {
public:
static bool GetBundleInfo(const std::string &bundleName, std::string &appIdentifier, std::string &fingerprint);
static bool GetBundleInfo(const std::string& bundleName, std::string& appIdentifier, std::string& fingerprint);
static bool GetBundleNameForUid(int uid, std::string& bundleName);
static bool GetBundleAbilityInfos(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos);
private:
static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
static int32_t GetCurrentAccountId();
BundleInfoQuery(){};
~BundleInfoQuery(){};
~BundleInfoQuery() = default;
};
}
}

View File

@ -19,16 +19,17 @@
#include "system_ability_definition.h"
#include "iservice_registry.h"
#include "app_domain_verify_hisysevent.h"
#include "ipc_skeleton.h"
namespace OHOS {
namespace AppDomainVerify {
bool BundleInfoQuery::GetBundleInfo(const std::string &bundleName, std::string &appIdentifier, std::string &fingerprint)
bool BundleInfoQuery::GetBundleInfo(const std::string& bundleName, std::string& appIdentifier, std::string& fingerprint)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
if (bundleMgrProxy == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "bundleMgrProxy is nullptr.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "bundleMgrProxy is nullptr.");
UNIVERSAL_ERROR_EVENT(CONNECT_OTHER_FAULT);
return false;
}
@ -40,58 +41,105 @@ bool BundleInfoQuery::GetBundleInfo(const std::string &bundleName, std::string &
auto ret = bundleMgrProxy->GetBundleInfoV9(bundleName,
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO), bundleInfo, userId);
if (ret != ERR_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "GetBundleInfo failed, ret: %{public}d.", ret);
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
return false;
}
appIdentifier = bundleInfo.signatureInfo.appIdentifier;
fingerprint = bundleInfo.signatureInfo.fingerprint;
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "call end");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
}
sptr<AppExecFwk::IBundleMgr> BundleInfoQuery::GetBundleMgrProxy()
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<ISystemAbilityManager> systemAbilityManager =
SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemAbilityManager) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE,
"GetBundleMgrProxy, systemAbilityManager is null");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleMgrProxy, systemAbilityManager is null");
return nullptr;
}
sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (!remoteObject) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "GetBundleMgrProxy, remoteObject is null");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleMgrProxy, remoteObject is null");
return nullptr;
}
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "call end");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
}
int32_t BundleInfoQuery::GetCurrentAccountId()
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
std::vector<int32_t> osAccountIds;
ErrCode ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(osAccountIds);
if (ret != ERR_OK) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "QueryActiveOsAccountIds failed.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "QueryActiveOsAccountIds failed.");
return -1;
}
if (osAccountIds.empty()) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "osAccountInfos is empty, no accounts.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "osAccountInfos is empty, no accounts.");
return -1;
}
auto iter = std::find_if(osAccountIds.cbegin(), osAccountIds.cend(),
[](const int32_t &accountId) { return accountId >= 0; });
auto iter = std::find_if(
osAccountIds.cbegin(), osAccountIds.cend(), [](const int32_t& accountId) { return accountId >= 0; });
if (iter != osAccountIds.end()) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "call end");
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return *iter;
}
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE,
"GetCurrentAccountId failed, no osAccountIds now.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetCurrentAccountId failed, no osAccountIds now.");
return -1;
}
bool BundleInfoQuery::GetBundleNameForUid(const int uid, std::string& bundleName)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
if (bundleMgrProxy == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "bundleMgrProxy is nullptr.");
UNIVERSAL_ERROR_EVENT(CONNECT_OTHER_FAULT);
return false;
}
// use sa identity
std::string identity = IPCSkeleton::ResetCallingIdentity();
auto ret = bundleMgrProxy->GetBundleNameForUid(uid, bundleName);
IPCSkeleton::SetCallingIdentity(identity);
if (!ret) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
return false;
}
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
}
bool BundleInfoQuery::GetBundleAbilityInfos(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
if (bundleMgrProxy == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "bundleMgrProxy is nullptr.");
UNIVERSAL_ERROR_EVENT(CONNECT_OTHER_FAULT);
return false;
}
AppExecFwk::BundleInfo bundleInfo;
// use sa identity
std::string identity = IPCSkeleton::ResetCallingIdentity();
auto ret = bundleMgrProxy->GetBundleInfo(bundleName,
AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES | AppExecFwk::BundleFlag::GET_BUNDLE_WITH_SKILL, bundleInfo,
AppExecFwk::Constants::ALL_USERID);
IPCSkeleton::SetCallingIdentity(identity);
if (!ret) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
return false;
}
abilityInfos = bundleInfo.abilityInfos;
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
};
}
}

View File

@ -24,6 +24,7 @@ config("app_domain_verify_mgr_client_config") {
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/dfx",
"${app_domain_verify_frameworks_common_path}/include/bms",
]
cflags = [
"-fdata-sections",
@ -60,6 +61,7 @@ config("app_domain_verify_agent_client_config") {
ohos_shared_library("app_domain_verify_mgr_client") {
branch_protector_ret = "pac_ret"
sources = [
"${app_domain_verify_frameworks_common_path}/src/bms/bundle_info_query.cpp",
"${app_domain_verify_service_path}/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp",
"src/app_domain_verify_mgr_client.cpp",
]
@ -71,10 +73,12 @@ ohos_shared_library("app_domain_verify_mgr_client") {
"ability_base:want",
"ability_base:zuri",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hilog:libhilog",
"hisysevent:libhisysevent",
"ipc:ipc_core",
"os_account:os_account_innerkits",
"samgr:samgr_proxy",
]
defines = []

View File

@ -130,6 +130,14 @@ public:
*/
int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames);
/**
* GetDeferredLink
* @descrition get deferred link for app.
* @param link link to get.
* @return result status.
*/
int GetDeferredLink(std::string& link);
/**
* OnRemoteSaDied
* @descrition

View File

@ -72,7 +72,7 @@ void AppDomainVerifyAgentClient::ConnectService()
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_CLIENT, "ConnectService start.");
sptr<ISystemAbilityManager> samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_CLIENT, "Get SystemAbilityManager failed.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_CLIENT, "GetDeferredLink SystemAbilityManager failed.");
agentServiceProxy_ = nullptr;
return;
}
@ -81,7 +81,7 @@ void AppDomainVerifyAgentClient::ConnectService()
remoteObject = samgrProxy->LoadSystemAbility(APP_DOMAIN_VERIFY_AGENT_SA_ID, LOADSA_TIMEOUT_MS);
}
if (remoteObject != nullptr) {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_CLIENT, "Get AgentServiceProxy succeed.");
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_AGENT_MODULE_CLIENT, "GetDeferredLink AgentServiceProxy succeed.");
if (deathRecipient_ == nullptr) {
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new AgentSaDeathRecipient());
}

View File

@ -23,6 +23,7 @@
#include "comm_define.h"
#include "ipc_skeleton.h"
#include "common_utils.h"
#include "bundle_info_query.h"
namespace OHOS {
namespace AppDomainVerify {
@ -150,13 +151,14 @@ void AppDomainVerifyMgrClient::ConnectService()
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "ConnectService start.");
sptr<ISystemAbilityManager> samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (samgrProxy == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "Get SystemAbilityManager failed.");
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "ConnectService SystemAbilityManager failed.");
appDomainVerifyMgrServiceProxy_ = nullptr;
return;
}
sptr<IRemoteObject> remoteObject = samgrProxy->CheckSystemAbility(APP_DOMAIN_VERIFY_MANAGER_SA_ID);
if (remoteObject != nullptr) {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "Get AppDomainVerifyMgrServiceProxy succeed.");
APP_DOMAIN_VERIFY_HILOGI(
APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "ConnectService AppDomainVerifyMgrServiceProxy succeed.");
if (deathRecipient_ == nullptr) {
deathRecipient_ = sptr<IRemoteObject::DeathRecipient>(new AppDomainVerifyMgrSaDeathRecipient());
}
@ -257,8 +259,7 @@ bool AppDomainVerifyMgrClient::IsAtomicServiceUrl(const std::string& url)
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "not support, will return false!");
return false;
#else
APP_DOMAIN_VERIFY_HILOGI(
APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called, url %{public}s", MaskStr(url).c_str());
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called, url %{public}s", MaskStr(url).c_str());
Uri uri(url);
if (!IsValidUrl(uri)) {
APP_DOMAIN_VERIFY_HILOGW(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "url is invalid!");
@ -310,6 +311,16 @@ int AppDomainVerifyMgrClient::QueryAssociatedBundleNames(
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return CommonErrorCode::E_INTERNAL_ERR;
}
int AppDomainVerifyMgrClient::GetDeferredLink(std::string& link)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
std::lock_guard<std::mutex> autoLock(proxyLock_);
if (IsServiceAvailable()) {
return appDomainVerifyMgrServiceProxy_->GetDeferredLink(link);
}
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return CommonErrorCode::E_INTERNAL_ERR;
}
AppDomainVerifyMgrSaDeathRecipient::AppDomainVerifyMgrSaDeathRecipient()
{
}

View File

@ -15,7 +15,7 @@
#ifndef APP_DOMAIN_VERIFY_COMM_DEFINE_H
#define APP_DOMAIN_VERIFY_COMM_DEFINE_H
namespace OHOS::AppDomainVerify {
enum CommonErrorCode {
enum CommonErrorCode: uint32_t {
E_OK = 0,
E_PERMISSION_DENIED = 201,
E_IS_NOT_SYS_APP = 202,

View File

@ -20,6 +20,7 @@
#include "app_domain_verify_mgr_client.h"
#include "comm_define.h"
#include "api_event_reporter.h"
namespace OHOS::AppDomainVerify {
constexpr int32_t API_SUCCESS = 0;
constexpr int32_t API_FAIL = 1;

View File

@ -23,11 +23,13 @@ config("app_domain_verify_service_config") {
"include/manager/rdb",
"include/manager/zidl",
"include/manager/permission",
"include/manager/deferred_link",
"include/agent/core",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_common_path}/include/zidl",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",
"${app_domain_verify_frameworks_common_path}/include/bms",
"${app_domain_verify_frameworks_common_path}/include/config",
"${app_domain_verify_frameworks_common_path}/include/dfx",
]
@ -51,10 +53,13 @@ config("app_domain_verify_service_config") {
ohos_shared_library("app_domain_verify_mgr_service") {
branch_protector_ret = "pac_ret"
sources = [
"${app_domain_verify_frameworks_common_path}/src/bms/bundle_info_query.cpp",
"${app_domain_verify_frameworks_common_path}/src/config/white_list_config_mgr.cpp",
"${app_domain_verify_frameworks_common_path}/src/utils/domain_url_util.cpp",
"src/manager/core/app_domain_verify_data_mgr.cpp",
"src/manager/core/app_domain_verify_mgr_service.cpp",
"src/manager/deferred_link/ability_filter.cpp",
"src/manager/deferred_link/deferred_link_mgr.cpp",
"src/manager/permission/permission_manager.cpp",
"src/manager/rdb/app_domain_verify_rdb_data_manager.cpp",
"src/manager/rdb/app_domain_verify_rdb_open_callback.cpp",
@ -87,6 +92,7 @@ ohos_shared_library("app_domain_verify_mgr_service") {
"hisysevent:libhisysevent",
"ipc:ipc_core",
"json:nlohmann_json_static",
"os_account:os_account_innerkits",
"preferences:native_preferences",
"relational_store:native_rdb",
"safwk:system_ability_fwk",

View File

@ -27,7 +27,8 @@ enum AppDomainVerifyMgrInterfaceCode {
CONVERT_TO_EXPLICIT_WANT = 7,
UPDATE_WHITE_LIST_URLS = 8,
QUERY_ASSOCIATED_DOMAINS = 9,
QUERY_ASSOCIATED_BUNDLE_NAMES = 10
QUERY_ASSOCIATED_BUNDLE_NAMES = 10,
GET_DEFERRED_LINK = 11
};
}
} // namespace OHOS

View File

@ -25,6 +25,7 @@
#include "app_domain_verify_data_mgr.h"
#include "white_list_config_mgr.h"
#include "permission_manager.h"
#include "deferred_link_mgr.h"
namespace OHOS {
namespace AppDomainVerify {
@ -33,13 +34,13 @@ class AppDomainVerifyMgrService : public SystemAbility, public AppDomainVerifyMg
public:
API_EXPORT AppDomainVerifyMgrService();
API_EXPORT virtual ~AppDomainVerifyMgrService();
API_EXPORT ~AppDomainVerifyMgrService() override;
API_EXPORT void VerifyDomain(const std::string& appIdentifier, const std::string& bundleName,
const std::string& fingerprint, const std::vector<SkillUri>& skillUris) override;
API_EXPORT bool ClearDomainVerifyStatus(const std::string& appIdentifier, const std::string& bundleName) override;
API_EXPORT bool FilterAbilities(const OHOS::AAFwk::Want& want,
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos) override;
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos) override;
API_EXPORT bool QueryDomainVerifyStatus(
const std::string& bundleName, DomainVerifyStatus& domainVerificationState) override;
API_EXPORT bool QueryAllDomainVerifyStatus(BundleVerifyStatusInfo& bundleVerifyStatusInfo) override;
@ -51,6 +52,7 @@ public:
API_EXPORT int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) override;
API_EXPORT int QueryAssociatedBundleNames(
const std::string& domain, std::vector<std::string>& bundleNames) override;
API_EXPORT int GetDeferredLink(std::string& link) override;
protected:
void OnDump() override;
@ -63,12 +65,13 @@ private:
bool IsWantImplicit(const OHOS::AAFwk::Want& want);
static int CheckPermission();
static void CollectDomains(const std::vector<SkillUri>& skillUris, VerifyResultInfo& verifyResultInfo);
bool IsUrlInBlackList(const std::string& url);
private:
std::shared_ptr<AppDomainVerifyDataMgr> dataManager_ = nullptr;
bool InitConfigMgr();
std::shared_ptr<WhiteListConfigMgr> whiteListConfigMgr_;
std::mutex initConfigMutex_;
std::shared_ptr<DeferredLinkMgr> deferredLinkMgr_ = std::make_shared<DeferredLinkMgr>();
};
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -33,7 +33,7 @@ public:
virtual bool ClearDomainVerifyStatus(const std::string& appIdentifier, const std::string& bundleName) = 0;
virtual bool FilterAbilities(const OHOS::AAFwk::Want& want,
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos) = 0;
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos) = 0;
virtual bool QueryDomainVerifyStatus(
const std::string& bundleName, DomainVerifyStatus& domainVerificationState) = 0;
virtual bool QueryAllDomainVerifyStatus(BundleVerifyStatusInfo& bundleVerifyStatusInfo) = 0;
@ -43,6 +43,7 @@ public:
virtual void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback) = 0;
virtual int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) = 0;
virtual int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames) = 0;
virtual int GetDeferredLink(std::string& link) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appDomainVerify.IAppDomainVerifyMgrService");
};
} // namespace AppDomainVerify

View File

@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 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 APP_DOMAIN_VERIFY_ABILITY_FILTER_H
#define APP_DOMAIN_VERIFY_ABILITY_FILTER_H
#include <string>
#include <memory>
namespace OHOS::AppDomainVerify {
struct FilterInfo {
std::string url;
};
class AbilityFilter {
public:
/**
* Filter
* @descrition filter info can match abilities.
* @param info the info to filer.
* @return bool return true if can match abilities else false.
*/
virtual bool Filter(const FilterInfo& info) = 0;
virtual ~AbilityFilter() = default;
static std::shared_ptr<AbilityFilter> Create(const std::string& bundleName);
};
}
#endif // APP_DOMAIN_VERIFY_ABILITY_FILTER_H

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 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 APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
#define APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
#include <string>
#include <mutex>
#include <set>
#include "datetime_ex.h"
#include "uri.h"
#include "event_handler.h"
#include "event_runner.h"
#include "app_domain_verify_hilog.h"
#include "ability_filter.h"
namespace OHOS::AppDomainVerify {
struct DeferredLinkInfo {
std::string domain;
std::string url;
int64_t timeStamp;
};
/**
* DeferredLinkMgr
* @descrition
* The mgr keeps limited links which are generated when the link is clicked but app is not installed.
* After app installed, app can get the link which click to open it, and app can continue the browsing.
*/
class DeferredLinkMgr {
public:
DeferredLinkMgr();
/**
* PutDeferredLink
* @descrition put deferred link info
* @param info the link.
*/
void PutDeferredLink(const DeferredLinkInfo& info);
/**
* GetDeferredLink
* @descrition get deferred link within domains and bundleName
* @param bundleName the bundleName to filter link info.
* @param domains the domains to filter link info.
* @return url the deferred url to open.
*/
std::string GetDeferredLink(const std::string& bundleName, const std::vector<std::string>& domains);
~DeferredLinkMgr();
private:
void PostAgeCacheTask();
void AgeCacheProcess();
void CheckStartTimerUnlocked();
void CheckFullUnlocked();
void CheckRemoveExistedUnlocked(const DeferredLinkInfo& info);
/**
* cache list
* @descrition list contains deferred link info, newly in front, older in back.
*/
std::list<DeferredLinkInfo> caches_;
std::mutex cachesMutex_;
std::shared_ptr<AppExecFwk::EventHandler> ageHandler_;
std::shared_ptr<AppExecFwk::EventRunner> ageRunner_;
};
}
#endif // APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H

View File

@ -24,23 +24,24 @@ namespace AppDomainVerify {
class AppDomainVerifyMgrServiceProxy : public IRemoteProxy<IAppDomainVerifyMgrService> {
public:
explicit AppDomainVerifyMgrServiceProxy(const sptr<IRemoteObject>& object);
virtual ~AppDomainVerifyMgrServiceProxy();
virtual void VerifyDomain(const std::string& appIdentifier, const std::string& bundleName,
~AppDomainVerifyMgrServiceProxy() override;
void VerifyDomain(const std::string& appIdentifier, const std::string& bundleName,
const std::string& fingerprint, const std::vector<SkillUri>& skillUris) override;
virtual bool ClearDomainVerifyStatus(const std::string& appIdentifier, const std::string& bundleName) override;
virtual bool FilterAbilities(const OHOS::AAFwk::Want& want,
bool ClearDomainVerifyStatus(const std::string& appIdentifier, const std::string& bundleName) override;
bool FilterAbilities(const OHOS::AAFwk::Want& want,
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos) override;
virtual bool QueryDomainVerifyStatus(
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos) override;
bool QueryDomainVerifyStatus(
const std::string& bundleName, DomainVerifyStatus& domainVerificationState) override;
virtual bool QueryAllDomainVerifyStatus(BundleVerifyStatusInfo& bundleVerifyStatusInfo) override;
virtual bool SaveDomainVerifyStatus(
bool QueryAllDomainVerifyStatus(BundleVerifyStatusInfo& bundleVerifyStatusInfo) override;
bool SaveDomainVerifyStatus(
const std::string& bundleName, const VerifyResultInfo& verifyResultInfo) override;
virtual bool IsAtomicServiceUrl(const std::string& url) override;
virtual void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback) override;
virtual void UpdateWhiteListUrls(const std::vector<std::string>& urls) override;
virtual int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) override;
virtual int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames) override;
bool IsAtomicServiceUrl(const std::string& url) override;
void ConvertToExplicitWant(OHOS::AAFwk::Want& implicitWant, sptr<IConvertCallback>& callback) override;
void UpdateWhiteListUrls(const std::vector<std::string>& urls) override;
int QueryAssociatedDomains(const std::string& bundleName, std::vector<std::string>& domains) override;
int QueryAssociatedBundleNames(const std::string& domain, std::vector<std::string>& bundleNames) override;
int GetDeferredLink(std::string& link) override;
private:
static inline BrokerDelegator<AppDomainVerifyMgrServiceProxy> delegator_;
};

View File

@ -27,7 +27,7 @@ namespace AppDomainVerify {
class AppDomainVerifyMgrServiceStub : public IRemoteStub<IAppDomainVerifyMgrService> {
public:
API_EXPORT AppDomainVerifyMgrServiceStub();
API_EXPORT virtual ~AppDomainVerifyMgrServiceStub();
API_EXPORT ~AppDomainVerifyMgrServiceStub() override;
API_EXPORT int32_t OnRemoteRequest(
uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
@ -43,6 +43,7 @@ private:
int32_t OnUpdateWhiteListUrls(MessageParcel& data, MessageParcel& reply);
int32_t OnQueryAssociatedDomains(MessageParcel& data, MessageParcel& reply);
int32_t OnQueryAssociatedBundleNames(MessageParcel& data, MessageParcel& reply);
int32_t OnGetDeferredLink(MessageParcel& data, MessageParcel& reply);
};
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -17,11 +17,13 @@
#include <string>
#include <tuple>
#include <vector>
#include "ipc_skeleton.h"
#include "app_domain_verify_mgr_service.h"
#include "system_ability_definition.h"
#include "domain_url_util.h"
#include "app_domain_verify_agent_client.h"
#include "comm_define.h"
#include "bundle_info_query.h"
namespace OHOS {
namespace AppDomainVerify {
constexpr const char* GET_DOMAIN_VERIFY_INFO = "ohos.permission.GET_APP_DOMAIN_BUNDLE_INFO";
@ -76,7 +78,7 @@ bool AppDomainVerifyMgrService::ClearDomainVerifyStatus(const std::string& appId
bool AppDomainVerifyMgrService::FilterAbilities(const OHOS::AAFwk::Want& want,
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos)
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
if (!PermissionManager::IsSACall()) {
@ -104,10 +106,14 @@ bool AppDomainVerifyMgrService::FilterAbilities(const OHOS::AAFwk::Want& want,
auto itr = verifyResultInfo.hostVerifyStatusMap.find(hostVerifyKey);
if (itr != verifyResultInfo.hostVerifyStatusMap.end() &&
std::get<0>(itr->second) == InnerVerifyStatus::STATE_SUCCESS) {
filtedAbilityInfos.emplace_back(*it);
filteredAbilityInfos.emplace_back(*it);
}
}
}
if (filteredAbilityInfos.empty() && !IsUrlInBlackList(uriString)) {
deferredLinkMgr_->PutDeferredLink(
{ .domain = hostVerifyKey, .url = uriString, .timeStamp = GetSecondsSince1970ToNow() });
}
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return true;
}
@ -270,8 +276,8 @@ void AppDomainVerifyMgrService::DumpAllVerifyInfos(std::string& dumpString)
dumpString.append("\n");
dumpString.append(" domain verify status:\n");
for (const auto& hostVerifyStatus : verifyResultInfo.hostVerifyStatusMap) {
dumpString.append(" " + hostVerifyStatus.first + ":" +
InnerVerifyStatusMap[std::get<0>(hostVerifyStatus.second)]);
dumpString.append(
" " + hostVerifyStatus.first + ":" + InnerVerifyStatusMap[std::get<0>(hostVerifyStatus.second)]);
dumpString.append("\n");
}
}
@ -322,9 +328,33 @@ void AppDomainVerifyMgrService::CollectDomains(
}
// validUris remove duplicates
auto uri = it->scheme + "://" + host;
verifyResultInfo.hostVerifyStatusMap.insert(make_pair(
uri, std::make_tuple(InnerVerifyStatus::UNKNOWN, std::string(), 0)));
verifyResultInfo.hostVerifyStatusMap.insert(
make_pair(uri, std::make_tuple(InnerVerifyStatus::UNKNOWN, std::string(), 0)));
}
}
int AppDomainVerifyMgrService::GetDeferredLink(std::string& link)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
std::string bundleName;
BundleInfoQuery::GetBundleNameForUid(IPCSkeleton::GetCallingUid(), bundleName);
if (!bundleName.empty()) {
std::vector<std::string> domains;
if (dataManager_->QueryAssociatedDomains(bundleName, domains) && !domains.empty()) {
link = deferredLinkMgr_->GetDeferredLink(bundleName, domains);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "get link, %{private}s.", link.c_str());
return CommonErrorCode::E_OK;
} else {
APP_DOMAIN_VERIFY_HILOGW(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "can not get associate domains");
return CommonErrorCode::E_OK;
}
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "can not get bundleName.");
return CommonErrorCode::E_PERMISSION_DENIED;
}
}
bool AppDomainVerifyMgrService::IsUrlInBlackList(const std::string& url)
{
return IsAtomicServiceUrl(url);
}
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2024 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 <string>
#include <utility>
#include "ability_filter.h"
#include "bundle_info_query.h"
#include "app_domain_verify_hilog.h"
namespace OHOS::AppDomainVerify {
using Skill = OHOS::AppExecFwk::Skill;
class BundleAbilityFilterImpl : public AbilityFilter {
public:
explicit BundleAbilityFilterImpl(std::string bundleName) : bundleName_(std::move(bundleName))
{
Init();
}
bool Filter(const FilterInfo& info) override
{
Want urlWant;
urlWant.SetUri(info.url);
urlWant.AddEntity(ENTITY_BROWSER);
urlWant.SetAction(ACTION_VIEW_DATA);
auto matchedAbility = std::find_if(
abilityInfos_.cbegin(), abilityInfos_.cend(), [&urlWant](const AbilityInfo& abilityInfo) {
APP_DOMAIN_VERIFY_HILOGD(
APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "abilityInfo:%{private}s", abilityInfo.name.c_str());
auto skills = abilityInfo.skills;
auto matchedSkill = std::find_if(skills.cbegin(), skills.cend(),
[&urlWant](const Skill& skill) { return skill.domainVerify && skill.Match(urlWant); });
return matchedSkill != skills.cend();
});
return matchedAbility != abilityInfos_.cend();
}
void Init()
{
BundleInfoQuery::GetBundleAbilityInfos(bundleName_, abilityInfos_);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "abilityInfos size:%zu", abilityInfos_.size());
}
private:
std::vector<AbilityInfo> abilityInfos_;
std::string bundleName_;
};
std::shared_ptr<AbilityFilter> AbilityFilter::Create(const std::string& bundleName)
{
return std::make_shared<BundleAbilityFilterImpl>(bundleName);
}
}

View File

@ -0,0 +1,130 @@
/*
* Copyright (C) 2024 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 "deferred_link_mgr.h"
namespace OHOS::AppDomainVerify {
namespace {
constexpr const char* TASK_ID = "age";
constexpr int32_t DELAY_TIME = 60000; // 1min
constexpr int64_t MAX_CACHE_TIME = 600; // 10min
constexpr int MAX_CACHE_SIZE = 50;
}
void DeferredLinkMgr::PutDeferredLink(const DeferredLinkInfo& info)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
std::unique_lock<std::mutex> lock(cachesMutex_);
CheckStartTimerUnlocked();
CheckRemoveExistedUnlocked(info);
CheckFullUnlocked();
caches_.push_front(info);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "info domain:%{private}s, link:%{private}s.",
info.domain.c_str(), info.url.c_str());
}
std::string DeferredLinkMgr::GetDeferredLink(const std::string& bundleName, const std::vector<std::string>& domains)
{
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
{
std::unique_lock<std::mutex> lock(cachesMutex_);
if (caches_.empty() || domains.empty() || bundleName.empty()) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "empty to match return.");
return "";
}
}
std::set<std::string> domainSet(domains.begin(), domains.end());
auto filter = AbilityFilter::Create(bundleName);
std::list<DeferredLinkInfo> destination;
{
std::unique_lock<std::mutex> lock(cachesMutex_);
// find links in bundle's domain and can match bundle's ability, then remove all of them.
caches_.remove_if([filter, &domainSet, &destination](const DeferredLinkInfo& linkInfo) {
if (domainSet.count(linkInfo.domain) != 0 && filter->Filter({ .url = linkInfo.url })) {
// keep newly in front
destination.push_back(linkInfo);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "matched.");
return true;
}
return false;
});
}
std::string result = destination.empty() ? "" : destination.front().url;
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get deferred link:%{private}s", result.c_str());
return result;
}
void DeferredLinkMgr::PostAgeCacheTask()
{
if (ageHandler_) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "PostAgeCacheTask.");
ageHandler_->PostTask([this] { AgeCacheProcess(); }, TASK_ID, DELAY_TIME);
}
}
void DeferredLinkMgr::AgeCacheProcess()
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "age func in.");
std::unique_lock<std::mutex> lock(cachesMutex_);
int64_t now = GetSecondsSince1970ToNow();
caches_.remove_if([now](const DeferredLinkInfo& linkInfo) { return now - linkInfo.timeStamp >= MAX_CACHE_TIME; });
if (!caches_.empty()) {
APP_DOMAIN_VERIFY_HILOGD(
APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "post continue age task, remain size:%{public}zu.", caches_.size());
PostAgeCacheTask();
} else {
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "age task end.");
}
}
void DeferredLinkMgr::CheckStartTimerUnlocked()
{
if (caches_.empty()) {
PostAgeCacheTask();
}
}
void DeferredLinkMgr::CheckFullUnlocked()
{
if (caches_.size() == MAX_CACHE_SIZE) {
caches_.pop_back();
}
}
void DeferredLinkMgr::CheckRemoveExistedUnlocked(const DeferredLinkInfo& info)
{
caches_.remove_if([&info](const DeferredLinkInfo& curInfo) {
if (curInfo.url == info.url && curInfo.domain == info.domain) {
return true;
}
return false;
});
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
}
DeferredLinkMgr::DeferredLinkMgr()
{
ageRunner_ = AppExecFwk::EventRunner::Create("age_deferred_link", AppExecFwk::ThreadMode::FFRT);
if (ageRunner_ == nullptr) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "create runner failed.");
return;
}
ageHandler_ = std::make_shared<AppExecFwk::EventHandler>(ageRunner_);
}
DeferredLinkMgr::~DeferredLinkMgr()
{
if (ageHandler_) {
ageHandler_->RemoveAllEvents();
}
}
}

View File

@ -75,7 +75,7 @@ bool AppDomainVerifyMgrServiceProxy::ClearDomainVerifyStatus(
bool AppDomainVerifyMgrServiceProxy::FilterAbilities(const OHOS::AAFwk::Want& want,
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
std::vector<OHOS::AppExecFwk::AbilityInfo>& filtedAbilityInfos)
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
MessageParcel data;
@ -112,7 +112,7 @@ bool AppDomainVerifyMgrServiceProxy::FilterAbilities(const OHOS::AAFwk::Want& wa
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "Read Parcelable AbilityInfo failed");
return false;
}
filtedAbilityInfos.emplace_back(*info);
filteredAbilityInfos.emplace_back(*info);
}
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return true;
@ -323,5 +323,27 @@ int AppDomainVerifyMgrServiceProxy::QueryAssociatedBundleNames(
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return result;
}
int AppDomainVerifyMgrServiceProxy::GetDeferredLink(std::string& link)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
MessageParcel data;
MessageParcel reply;
MessageOption option;
WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(InterfaceToken, data, GetDescriptor());
int32_t error = Remote()->SendRequest(
AppDomainVerifyMgrInterfaceCode::GET_DEFERRED_LINK, data, reply, option);
if (error != ERR_NONE) {
APP_DOMAIN_VERIFY_HILOGE(
APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink failed, error: %d", error);
}
int32_t result = reply.ReadInt32();
if (result != 0) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "result failed, result: %d", result);
return result;
}
READ_PARCEL_AND_RETURN_INT_IF_FAIL(String, reply, link);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return result;
}
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -66,6 +66,8 @@ int32_t AppDomainVerifyMgrServiceStub::OnRemoteRequest(
return OnQueryAssociatedDomains(data, reply);
case static_cast<uint32_t>(AppDomainVerifyMgrInterfaceCode::QUERY_ASSOCIATED_BUNDLE_NAMES):
return OnQueryAssociatedBundleNames(data, reply);
case static_cast<uint32_t>(AppDomainVerifyMgrInterfaceCode::GET_DEFERRED_LINK):
return OnGetDeferredLink(data, reply);
default:
APP_DOMAIN_VERIFY_HILOGW(
APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "receive unknown code, code = %{public}d", code);
@ -263,5 +265,16 @@ int32_t AppDomainVerifyMgrServiceStub::OnQueryAssociatedBundleNames(MessageParce
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return ERR_OK;
}
int32_t AppDomainVerifyMgrServiceStub::OnGetDeferredLink(MessageParcel& data, MessageParcel& reply)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
std::string link;
int ret = GetDeferredLink(link);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, reply, ret);
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, reply, link);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return ERR_OK;
}
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -30,10 +30,12 @@ group("app_domain_verify_unit_test") {
"frameworks_common/config_test:app_domain_verify_config_test",
"frameworks_common/httpsession_test:app_domain_verify_httpsession_test",
"moduletest:app_domain_verify_module_test",
"services/ability_filter_test:ability_filter_test",
"services/app_domain_verify_agent_service_test:app_domain_verify_agent_service_test",
"services/app_domain_verify_data_mgr_test:app_domain_verify_data_mgr_test",
"services/app_domain_verify_mgr_service_test:app_domain_verify_mgr_service_test",
"services/app_domain_verify_rdb_test:app_domain_verify_rdb_test",
"services/deferred_link_test:deferred_link_test",
"verifier:app_domain_verify_agent_verifier_test",
]
}

View File

@ -289,6 +289,25 @@ HWTEST_F(AppDomainVerifyMgrClientTest, AppDomainVerifyMgrClientTest010, TestSize
ASSERT_TRUE(g_mgrInvokeOK);
AppDomainVerifyMgrClient::appDomainVerifyMgrServiceProxy_.ForceSetRefPtr(nullptr);
}
/**
* @tc.name: AppDomainVerifyMgrClientTest011
* @tc.desc: QueryAssociatedDomains test.
* @tc.type: FUNC
*/
HWTEST_F(AppDomainVerifyMgrClientTest, AppDomainVerifyMgrClientTest011, TestSize.Level0)
{
std::shared_ptr<AppDomainVerifyMgrRemoteStubMock> mgrStubMock_ =
std::make_shared<AppDomainVerifyMgrRemoteStubMock>();
EXPECT_CALL(*mgrStubMock_, SendRequest(_, _, _, _)).Times(1).WillOnce(::testing::Invoke(MgrInvokeOK));
AppDomainVerifyMgrClient::appDomainVerifyMgrServiceProxy_ = sptr<AppDomainVerifyMgrServiceProxy>::MakeSptr(
mgrStubMock_.get());
std::string link;
AppDomainVerifyMgrClient::GetInstance()->GetDeferredLink(link);
ASSERT_TRUE(g_mgrInvokeOK);
AppDomainVerifyMgrClient::appDomainVerifyMgrServiceProxy_.ForceSetRefPtr(nullptr);
}
/**
* @tc.name: AppDomainVerifyMgrSaDeathRecipientTest001
* @tc.desc: VerifyDomain test.

View File

@ -57,6 +57,10 @@ ohos_unittest("app_domain_verify_bms_test") {
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken_shared",
"access_token:libtokenid_sdk",
"access_token:libtokensetproc_shared",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",

View File

@ -177,4 +177,19 @@ HWTEST_F(BundleInfoQueryTest, BundleInfoQueryTest008, TestSize.Level0)
std::string fingerprint = FINGERPRINT;
ASSERT_FALSE(BundleInfoQuery::GetBundleInfo(bundleName, appIdentifier, fingerprint));
}
/**
* @tc.name: BundleGetBundleNameForUidTest001
* @tc.desc: GetBundleName success.
* @tc.type: FUNC
*/
HWTEST_F(BundleInfoQueryTest, BundleGetBundleNameForUidTest001, TestSize.Level0)
{
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleNameForUid(_, _)).WillOnce(Return(true));
g_mockBundleMgrService->impl = mocBundleMgrService;
int id = 0;
std::string bundleName;
ASSERT_TRUE(BundleInfoQuery::GetBundleNameForUid(id, bundleName));
}
}

View File

@ -35,6 +35,9 @@ public:
}
ErrCode GetBundleInfoV9(
const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId) override;
bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo,
int32_t userId = Constants::UNSPECIFIED_USERID) override;
bool GetBundleNameForUid(const int uid, std::string& bundleName) override;
};
class BundleMgrStub : public IRemoteStub<IBundleMgr> {
@ -50,6 +53,9 @@ public:
MOCK_METHOD(ErrCode, GetBundleInfoV9,
(const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId), (override));
MOCK_METHOD(bool, GetBundleInfo,
(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId), (override));
MOCK_METHOD(bool, GetBundleNameForUid, (const int uid, std::string& bundleName), (override));
};
class BundleMgrService : public BundleMgrStub {
@ -59,6 +65,9 @@ public:
ErrCode GetBundleInfoV9(
const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId) override;
bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo,
int32_t userId = Constants::UNSPECIFIED_USERID) override;
bool GetBundleNameForUid(const int uid, std::string& bundleName) override;
std::shared_ptr<MocBundleMgrService> impl = nullptr;
};

View File

@ -73,6 +73,10 @@ public:
{
return true;
}
virtual int GetDeferredLink(std::string& link) override
{
return true;
}
MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel&, MessageParcel&, MessageOption&));
MOCK_METHOD(sptr<IRemoteObject>, AsObject, (), (override));
};
@ -130,6 +134,10 @@ public:
{
return true;
}
virtual int GetDeferredLink(std::string& link) override
{
return true;
}
};
} // namespace AppDomainVerify
} // namespace OHOS

View File

@ -41,6 +41,25 @@ ErrCode BundleMgrService::GetBundleInfoV9(
bundleInfo.signatureInfo.fingerprint = AppDomainVerify::FINGERPRINT;
return ERR_OK;
}
bool BundleMgrService::GetBundleInfo(
const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId)
{
GTEST_LOG_(INFO) << "MOCK BundleMgrService GetBundleInfo";
if (impl != nullptr) {
GTEST_LOG_(INFO) << "MOCK BundleMgrService GetBundleInfo use mock";
return impl->GetBundleInfo(bundleName, flag, bundleInfo, userId);
}
bundleInfo.signatureInfo.fingerprint = AppDomainVerify::FINGERPRINT;
return true;
}
bool BundleMgrService::GetBundleNameForUid(const int uid, std::string& bundleName)
{
GTEST_LOG_(INFO) << "MOCK BundleMgrService GetBundleNameForUid";
if (impl != nullptr) {
GTEST_LOG_(INFO) << "MOCK BundleMgrService GetBundleNameForUid use mock";
return impl->GetBundleNameForUid(uid, bundleName);
}
return true;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -27,6 +27,7 @@ config("module_private_config") {
"${app_domain_verify_service_path}/include/manager/core",
"${app_domain_verify_service_path}/include/manager/constant",
"${app_domain_verify_service_path}/include/manager/zidl",
"${app_domain_verify_service_path}/include/manager/deferred_link",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",

View File

@ -0,0 +1,84 @@
# Copyright (C) 2024 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/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("module_private_config") {
visibility = [ ":*" ]
configs = [ "//build/config/compiler:exceptions" ]
include_dirs = [
"${app_domain_verify_client_path}/include",
"${app_domain_verify_service_path}/include",
"${app_domain_verify_service_path}/include/agent/core",
"${app_domain_verify_service_path}/include/agent/zidl",
"${app_domain_verify_service_path}/include/manager/rdb",
"${app_domain_verify_service_path}/include/manager/core",
"${app_domain_verify_service_path}/include/manager/constant",
"${app_domain_verify_service_path}/include/manager/zidl",
"${app_domain_verify_service_path}/include/manager/permission",
"${app_domain_verify_service_path}/include/manager/deferred_link",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",
"${app_domain_verify_frameworks_common_path}/include/bms",
"${app_domain_verify_frameworks_extension_path}/include",
"${app_domain_verify_test_path}/mock/include",
"${app_domain_verify_frameworks_common_path}/include/dfx",
]
}
module_output_path = "app_domain_verify/app_domain_verify"
ohos_unittest("ability_filter_test") {
module_out_path = module_output_path
sources = [
"${app_domain_verify_frameworks_common_path}/src/bms/bundle_info_query.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/ability_filter.cpp",
"${app_domain_verify_test_path}/mock/src/mock_bundle_manager.cpp",
"${app_domain_verify_test_path}/mock/src/mock_os_account_manager.cpp",
"${app_domain_verify_test_path}/mock/src/mock_service_registry.cpp",
"${app_domain_verify_test_path}/mock/src/mock_system_ability.cpp",
"${app_domain_verify_test_path}/mock/src/mock_system_ability_ondemand_reason.cpp",
"ability_filter_test.cpp",
]
configs = [ ":module_private_config" ]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken_shared",
"access_token:libtokenid_sdk",
"access_token:libtokensetproc_shared",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"image_framework:image_native",
"init:libbegetutil",
"ipc:ipc_core",
"netstack:http_client",
"os_account:os_account_innerkits",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
}

View File

@ -0,0 +1,205 @@
/*
* Copyright (C) 2024 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 "gtest/gtest.h"
#include "mock_constant.h"
#define private public
#define protected public
#include "ability_filter.h"
#undef private
#undef protected
#include "bms/bundle_info_query.h"
#include "mock_bundle_manager.h"
#include "mock_system_ability.h"
#include "mock_system_ability_registry.h"
#include "mock_os_accout_manager.h"
namespace OHOS::AppDomainVerify {
using Want = OHOS::AAFwk::Want;
using namespace OHOS::AppExecFwk;
using namespace testing;
using namespace testing::ext;
constexpr const char* BUNDLE_NAME_WRONG = "BUNDLE_NAME_WRONG";
constexpr const char* BUNDLE_DOMAIN = "https://www.openharmony.cn";
constexpr const char* BUNDLE_DOMAIN_WRONG = "https://www.openharmony_wrong.cn";
constexpr const char* BUNDLE_URL = "https://www.openharmony.cn/100";
constexpr const char* BUNDLE_URL_NEW = "https://www.openharmony.cn/new";
constexpr const char* TASK_ID = "age";
constexpr int MAX_CACHE_SIZE = 50;
class AbilityFilterTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
std::vector<AbilityInfo> g_mockAbilityInfos;
void AbilityFilterTest::SetUpTestCase(void)
{
GTEST_LOG_(INFO) << "SetUpTestCase";
OHOS::AccountSA::g_enableMockIds = true;
g_mockBundleMgrService = new AppExecFwk::BundleMgrService();
}
void AbilityFilterTest::TearDownTestCase(void)
{
g_mockAbilityInfos.clear();
}
void AbilityFilterTest::SetUp(void)
{
}
void AbilityFilterTest::TearDown(void)
{
GTEST_LOG_(INFO) << "TearDown";
g_mockBundleMgrService->impl = nullptr;
OHOS::AccountSA::g_accountIds.clear();
}
bool InvokeGetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId)
{
bundleInfo.abilityInfos = g_mockAbilityInfos;
return true;
}
/**
* @tc.name: DeferredLinkPutTest001
* @tc.desc: filter success.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, AbilityFilterTest001, TestSize.Level0)
{
std::vector<std::string> actions = { ACTION_VIEW_DATA };
std::vector<std::string> entities = { ENTITY_BROWSER };
std::vector<SkillUri> uris = { { .scheme = "https", .host = "www.openharmony.cn" } };
Skill skill;
skill.domainVerify = true;
skill.actions = actions;
skill.entities = entities;
skill.uris = uris;
std::vector<Skill> skills = { skill };
AbilityInfo abilityInfo;
abilityInfo.skills = skills;
g_mockAbilityInfos.push_back(abilityInfo);
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Invoke(InvokeGetBundleInfo));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_TRUE(filter->Filter({ .url = BUNDLE_URL }));
}
/**
* @tc.name: DeferredLinkPutTest002
* @tc.desc: filter with bms error.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, AbilityFilterTest002, TestSize.Level0)
{
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Return(false));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_FALSE(filter->Filter({ .url = BUNDLE_URL }));
}
/**
* @tc.name: DeferredLinkPutTest003
* @tc.desc: filter with no abilities.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, DeferredLinkPutTest003, TestSize.Level0)
{
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Return(true));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_FALSE(filter->Filter({ .url = BUNDLE_URL }));
}
/**
* @tc.name: DeferredLinkPutTest004
* @tc.desc: filter with no skill.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, DeferredLinkPutTest004, TestSize.Level0)
{
std::vector<Skill> skills;
AbilityInfo abilityInfo;
abilityInfo.skills = skills;
g_mockAbilityInfos.push_back(abilityInfo);
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Return(true));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_FALSE(filter->Filter({ .url = BUNDLE_URL }));
}
/**
* @tc.name: DeferredLinkPutTest005
* @tc.desc: filter with no domainVerify skill.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, DeferredLinkPutTest005, TestSize.Level0)
{
std::vector<std::string> actions = { ACTION_VIEW_DATA };
std::vector<std::string> entities = { ENTITY_BROWSER };
std::vector<SkillUri> uris = { { .scheme = "https", .host = "www.openharmony.cn" } };
Skill skill;
skill.domainVerify = false;
skill.actions = actions;
skill.entities = entities;
skill.uris = uris;
std::vector<Skill> skills = { skill };
AbilityInfo abilityInfo;
abilityInfo.skills = skills;
g_mockAbilityInfos.push_back(abilityInfo);
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Return(true));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_FALSE(filter->Filter({ .url = BUNDLE_URL }));
}
/**
* @tc.name: DeferredLinkPutTest006
* @tc.desc: filter with no matched skill.
* @tc.type: FUNC
*/
HWTEST_F(AbilityFilterTest, DeferredLinkPutTest006, TestSize.Level0)
{
std::vector<std::string> actions = { ACTION_VIEW_DATA };
std::vector<std::string> entities = { ENTITY_BROWSER };
std::vector<SkillUri> uris = { { .scheme = "https", .host = "www.openharmony1.cn" } };
Skill skill;
skill.domainVerify = true;
skill.actions = actions;
skill.entities = entities;
skill.uris = uris;
std::vector<Skill> skills = { skill };
AbilityInfo abilityInfo;
abilityInfo.skills = skills;
g_mockAbilityInfos.push_back(abilityInfo);
auto mocBundleMgrService = std::make_shared<OHOS::AppExecFwk::MocBundleMgrService>();
EXPECT_CALL(*mocBundleMgrService, GetBundleInfo(_, _, _, _)).WillOnce(Return(true));
g_mockBundleMgrService->impl = mocBundleMgrService;
auto filter = AbilityFilter::Create(BUNDLE_NAME);
EXPECT_FALSE(filter->Filter({ .url = BUNDLE_URL }));
}
}

View File

@ -28,6 +28,7 @@ config("module_private_config") {
"${app_domain_verify_service_path}/include/manager/constant",
"${app_domain_verify_service_path}/include/manager/zidl",
"${app_domain_verify_service_path}/include/manager/permission",
"${app_domain_verify_service_path}/include/manager/deferred_link",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",
@ -44,6 +45,8 @@ ohos_unittest("app_domain_verify_mgr_service_test") {
sources = [
"${app_domain_verify_service_path}/src/manager/core/app_domain_verify_data_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/core/app_domain_verify_mgr_service.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/ability_filter.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/deferred_link_mgr.cpp",
"${app_domain_verify_service_path}/src/manager/permission/permission_manager.cpp",
"${app_domain_verify_service_path}/src/manager/rdb/app_domain_verify_rdb_data_manager.cpp",
"${app_domain_verify_service_path}/src/manager/rdb/app_domain_verify_rdb_open_callback.cpp",

View File

@ -0,0 +1,81 @@
# Copyright (C) 2024 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/bundlemanager/app_domain_verify/app_domain_verify.gni")
config("module_private_config") {
visibility = [ ":*" ]
configs = [ "//build/config/compiler:exceptions" ]
include_dirs = [
"${app_domain_verify_client_path}/include",
"${app_domain_verify_service_path}/include",
"${app_domain_verify_service_path}/include/agent/core",
"${app_domain_verify_service_path}/include/agent/zidl",
"${app_domain_verify_service_path}/include/manager/rdb",
"${app_domain_verify_service_path}/include/manager/core",
"${app_domain_verify_service_path}/include/manager/constant",
"${app_domain_verify_service_path}/include/manager/zidl",
"${app_domain_verify_service_path}/include/manager/permission",
"${app_domain_verify_service_path}/include/manager/deferred_link",
"${app_domain_verify_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include",
"${app_domain_verify_frameworks_common_path}/include/utils",
"${app_domain_verify_frameworks_common_path}/include/bms",
"${app_domain_verify_frameworks_extension_path}/include",
"${app_domain_verify_test_path}/mock/include",
"${app_domain_verify_frameworks_common_path}/include/dfx",
]
}
module_output_path = "app_domain_verify/app_domain_verify"
ohos_unittest("deferred_link_test") {
module_out_path = module_output_path
sources = [
"${app_domain_verify_frameworks_common_path}/src/bms/bundle_info_query.cpp",
"${app_domain_verify_service_path}/src/manager/deferred_link/deferred_link_mgr.cpp",
"${app_domain_verify_test_path}/mock/src/mock_bundle_manager.cpp",
"deferred_link_mgr_test.cpp",
"mock_ability_filter.cpp",
]
configs = [ ":module_private_config" ]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"access_token:libaccesstoken_sdk",
"access_token:libnativetoken_shared",
"access_token:libtokenid_sdk",
"access_token:libtokensetproc_shared",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
"hisysevent:libhisysevent",
"image_framework:image_native",
"init:libbegetutil",
"ipc:ipc_core",
"netstack:http_client",
"os_account:os_account_innerkits",
"relational_store:native_rdb",
"samgr:samgr_proxy",
]
defines = [ "API_EXPORT=__attribute__((visibility (\"default\")))" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
}

View File

@ -0,0 +1,268 @@
/*
* Copyright (C) 2024 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 "gtest/gtest.h"
#include "mock_constant.h"
#define private public
#define protected public
#include "ability_filter.h"
#include "deferred_link_mgr.h"
#undef private
#undef protected
#include "mock_ability_filter.h"
namespace OHOS::AppDomainVerify {
using namespace testing;
using namespace testing::ext;
constexpr const char* BUNDLE_NAME_WRONG = "BUNDLE_NAME_WRONG";
constexpr const char* BUNDLE_DOMAIN = "https://www.openharmony.cn";
constexpr const char* BUNDLE_DOMAIN_WRONG = "https://www.openharmony_wrong.cn";
constexpr const char* BUNDLE_URL = "https://www.openharmony.cn/100";
constexpr const char* BUNDLE_URL_NEW = "https://www.openharmony.cn/new";
constexpr const char* TASK_ID = "age";
constexpr int MAX_CACHE_SIZE = 50;
class DeferredLinkMgrTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
};
void DeferredLinkMgrTest::SetUpTestCase(void)
{
}
void DeferredLinkMgrTest::TearDownTestCase(void)
{
}
void DeferredLinkMgrTest::SetUp(void)
{
}
void DeferredLinkMgrTest::TearDown(void)
{
}
/**
* @tc.name: DeferredLinkPutTest001
* @tc.desc: put one link, remain one.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkPutTest001, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
EXPECT_TRUE(deferredLinkMgr.caches_.front().domain == BUNDLE_DOMAIN);
EXPECT_TRUE(deferredLinkMgr.caches_.front().url == BUNDLE_URL);
}
/**
* @tc.name: DeferredLinkPutTest002
* @tc.desc: put max_size + 1 link, will remain maxsize.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkPutTest002, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
for (int i = 0; i < MAX_CACHE_SIZE + 1; i++) {
deferredLinkMgr.PutDeferredLink({ .domain = BUNDLE_DOMAIN + std::to_string(i),
.url = BUNDLE_URL,
.timeStamp = GetSecondsSince1970ToNow() });
}
EXPECT_TRUE(deferredLinkMgr.caches_.size() == MAX_CACHE_SIZE);
EXPECT_EQ(deferredLinkMgr.caches_.back().domain, BUNDLE_DOMAIN + std::to_string(1));
EXPECT_EQ(deferredLinkMgr.caches_.front().domain, BUNDLE_DOMAIN + std::to_string(MAX_CACHE_SIZE));
}
/**
* @tc.name: DeferredLinkPutTest003
* @tc.desc: put duplicate link, will unique and in back.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkPutTest003, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN + std::to_string(1), .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 2);
EXPECT_EQ(deferredLinkMgr.caches_.back().domain, BUNDLE_DOMAIN + std::to_string(1));
EXPECT_EQ(deferredLinkMgr.caches_.front().domain, BUNDLE_DOMAIN);
}
/**
* @tc.name: DeferredLinkGetTest001
* @tc.desc: get link with matched domain and matched url, return link.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest001, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(1).WillOnce(Return(true));
MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_FALSE(link.empty());
EXPECT_EQ(link, BUNDLE_URL);
EXPECT_TRUE(deferredLinkMgr.caches_.empty());
auto link1 = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_TRUE(link1.empty());
}
/**
* @tc.name: DeferredLinkGetTest002
* @tc.desc: get link with unmatched domains and matched bundleName, return none.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest002, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(0);
MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN_WRONG);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_TRUE(link.empty());
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
}
/**
* @tc.name: DeferredLinkGetTest003
* @tc.desc: get link with unmatched domains and matched bundleName, return none.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest003, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(0);
MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN_WRONG);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_TRUE(link.empty());
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
}
/**
* @tc.name: DeferredLinkGetTest004
* @tc.desc: get link with unmatched bundleName and matched domains, return none.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest004, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(1).WillOnce(Return(false));
MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME_WRONG, domains);
EXPECT_TRUE(link.empty());
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
}
/**
* @tc.name: DeferredLinkGetTest005
* @tc.desc: get link with matched domain and matched url, return new link, cache remove link all.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest005, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(2).WillRepeatedly(Return(true));
MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL_NEW, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 2);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_FALSE(link.empty());
EXPECT_EQ(link, BUNDLE_URL_NEW);
EXPECT_TRUE(deferredLinkMgr.caches_.empty());
auto link1 = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_TRUE(link1.empty());
}
/**
* @tc.name: DeferredLinkGetTest006
* @tc.desc: get link from empty cache, return null.
* @tc.type: FUNC
*/
HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest006, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
MockAbilityFilter(filter);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN);
auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
EXPECT_TRUE(link.empty());
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2024 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 "mock_ability_filter.h"
#include <utility>
namespace OHOS::AppDomainVerify {
std::shared_ptr<AbilityFilter> g_mockAbilityFilter = nullptr;
void MockAbilityFilter(std::shared_ptr<AbilityFilter> mockAbilityFilter)
{
g_mockAbilityFilter = std::move(mockAbilityFilter);
}
std::shared_ptr<AbilityFilter> AbilityFilter::Create(const std::string& bundleName)
{
return g_mockAbilityFilter;
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (C) 2024 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 APP_DOMAIN_VERIFY_MOCK_ABILITY_FILTER_H
#define APP_DOMAIN_VERIFY_MOCK_ABILITY_FILTER_H
#include "ability_filter.h"
#include <gmock/gmock.h>
namespace OHOS::AppDomainVerify {
void MockAbilityFilter(std::shared_ptr<AbilityFilter> mockAbilityFilter);
class MocAbilityFilter : public AbilityFilter {
public:
MOCK_METHOD(bool, Filter, (const FilterInfo& info), (override));
};
}
#endif // APP_DOMAIN_VERIFY_MOCK_ABILITY_FILTER_H