Signed-off-by: woohoa <wanghuan36@huawei.com>

This commit is contained in:
15950533375
2024-11-05 15:49:39 +08:00
parent eb8a10ae1c
commit 63955862bf
14 changed files with 5061 additions and 11 deletions
+113
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
@@ -0,0 +1,135 @@
From 64ea47933a5572f42e6e399f778757b9b043712f Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Mon, 4 Nov 2024 16:36:40 +0800
Subject: [PATCH] support deferred link bms query flag
Change-Id: If3e6258e962e0b66a4e1555c3d8a3cca94f8345f
---
frameworks/common/src/bms/bundle_info_query.cpp | 4 +++-
.../client/src/app_domain_verify_mgr_client.cpp | 6 ------
.../kits/js/deferred_link/src/deferred_link_napi.cpp | 4 ++--
.../src/manager/deferred_link/ability_filter.cpp | 10 +++-------
.../src/manager/deferred_link/deferred_link_mgr.cpp | 12 +++++++++---
5 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/frameworks/common/src/bms/bundle_info_query.cpp b/frameworks/common/src/bms/bundle_info_query.cpp
index daefb9d..1d63a6b 100644
--- a/frameworks/common/src/bms/bundle_info_query.cpp
+++ b/frameworks/common/src/bms/bundle_info_query.cpp
@@ -129,7 +129,9 @@ bool BundleInfoQuery::GetBundleAbilityInfos(const std::string& bundleName, std::
AppExecFwk::BundleInfo bundleInfo;
// use sa identity
std::string identity = IPCSkeleton::ResetCallingIdentity();
- auto ret = bundleMgrProxy->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo);
+ auto ret = bundleMgrProxy->GetBundleInfo(bundleName,
+ AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES | AppExecFwk::BundleFlag::GET_BUNDLE_WITH_SKILL, bundleInfo,
+ AppExecFwk::Constants::START_USERID);
IPCSkeleton::SetCallingIdentity(identity);
if (!ret) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
diff --git a/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp b/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
index e794673..415371a 100644
--- a/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
+++ b/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
@@ -303,12 +303,6 @@ int AppDomainVerifyMgrClient::QueryAssociatedDomains(const std::string& bundleNa
int AppDomainVerifyMgrClient::QueryAssociatedBundleNames(
const std::string& domain, std::vector<std::string>& bundleNames)
{
-
-
- APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink start");
- std::string link;
- GetDeferredLink(link);
- APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink end, link %{public}s", link.c_str());
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
std::lock_guard<std::mutex> autoLock(proxyLock_);
if (IsServiceAvailable()) {
diff --git a/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp b/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
index 2d12832..ad79f60 100644
--- a/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
+++ b/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
@@ -28,7 +28,7 @@ using namespace Dfx;
namespace {
constexpr const char* GET_DEFERRED_LINK = "GetDeferredLink";
}
-std::map<CommonErrorCode, const char*> ErrCodeMap = { { CommonErrorCode::E_INTERNAL_ERR, "Internal error." } };
+std::map<CommonErrorCode, const char*> g_ErrCodeMap = { { CommonErrorCode::E_INTERNAL_ERR, "Internal error." } };
struct GetDeferredLinkCallbackInfo : public BaseCallbackInfo {
GetDeferredLinkCallbackInfo(napi_env napiEnv, std::unique_ptr<Dfx::ApiEventReporter> reporter)
@@ -68,7 +68,7 @@ void GetDeferredLinkComplete(napi_env env, napi_status status, void* data)
NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
result[ARGS_SIZE_ONE] = BuildString(env, asyncCallbackInfo->deferred_link);
} else {
- result[0] = BuildError(env, CommonErrorCode::E_INTERNAL_ERR, "internal error.");
+ result[0] = BuildError(env, CommonErrorCode::E_INTERNAL_ERR, g_ErrCodeMap[CommonErrorCode::E_INTERNAL_ERR]);
}
if (asyncCallbackInfo->deferred) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "is deferred");
diff --git a/services/src/manager/deferred_link/ability_filter.cpp b/services/src/manager/deferred_link/ability_filter.cpp
index e918806..5711b15 100644
--- a/services/src/manager/deferred_link/ability_filter.cpp
+++ b/services/src/manager/deferred_link/ability_filter.cpp
@@ -39,13 +39,9 @@ public:
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) {
- if (skill.domainVerify && skill.Match(urlWant)) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill matched");
- return true;
- }
- return false;
- });
+ auto matchedSkill = std::find_if(skills.cbegin(), skills.cend(),
+ [&urlWant](const Skill& skill) { return skill.domainVerify && skill.Match(urlWant); });
+
return matchedSkill != skills.cend();
});
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
index d982508..3868a81 100644
--- a/services/src/manager/deferred_link/deferred_link_mgr.cpp
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -30,13 +30,20 @@ void DeferredLinkMgr::PutDeferredLink(const DeferredLinkInfo& info)
CheckFullUnlocked();
caches_.push_front(info);
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "info domain:%{private}s, url:%{private}s.",
+ 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);
@@ -44,7 +51,6 @@ std::string DeferredLinkMgr::GetDeferredLink(const std::string& bundleName, cons
{
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 })) {
@@ -58,7 +64,7 @@ std::string DeferredLinkMgr::GetDeferredLink(const std::string& bundleName, cons
}
std::string result = destination.empty() ? "" : destination.front().url;
- APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get deferred url:%{private}s", result.c_str());
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get deferred link:%{private}s", result.c_str());
return result;
}
--
2.25.1
@@ -0,0 +1,141 @@
From 095ab1d448c5b13353ae0585d862e67ca7ca81a6 Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Tue, 5 Nov 2024 15:05:54 +0800
Subject: [PATCH] support deferred link napi fix report
Change-Id: Ica1bd3b49c4b1f058bbb59e328cd3a7f77997f0f
---
.../src/app_domain_verify_manager_napi.cpp | 16 ++++++++--------
.../js/deferred_link/src/deferred_link_napi.cpp | 3 ++-
.../kits/js/event/include/api_event_reporter.h | 7 +++++--
.../kits/js/event/src/api_event_reporter.cpp | 9 +++++++++
4 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/interfaces/kits/js/app_domain_verify/src/app_domain_verify_manager_napi.cpp b/interfaces/kits/js/app_domain_verify/src/app_domain_verify_manager_napi.cpp
index faf40b8..39ddd40 100644
--- a/interfaces/kits/js/app_domain_verify/src/app_domain_verify_manager_napi.cpp
+++ b/interfaces/kits/js/app_domain_verify/src/app_domain_verify_manager_napi.cpp
@@ -37,22 +37,22 @@ napi_value QueryAssociatedDomains(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string bundleName = GetString(env, args[0]);
if (!CheckInput(bundleName)) {
- reporter.WriteEndEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
+ reporter.SetEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
return BuildError(env, CommonErrorCode::E_PARAM_ERROR, ErrCodeMap[CommonErrorCode::E_PARAM_ERROR]);
}
std::vector<std::string> domains;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedDomains(bundleName, domains);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<CommonErrorCode>(ret)) != 0) {
- reporter.WriteEndEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
+ reporter.SetEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
return BuildError(env, static_cast<CommonErrorCode>(ret), ErrCodeMap[static_cast<CommonErrorCode>(ret)]);
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
- reporter.WriteEndEvent(API_FAIL, ret);
+ reporter.SetEvent(API_FAIL, ret);
return BuildStringArray(env, domains);
}
}
- reporter.WriteEndEvent(API_SUCCESS, ret);
+ reporter.SetEvent(API_SUCCESS, ret);
return BuildStringArray(env, domains);
}
napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
@@ -64,22 +64,22 @@ napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string domain = GetString(env, args[0]);
if (!CheckInput(domain)) {
- reporter.WriteEndEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
+ reporter.SetEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
return BuildError(env, CommonErrorCode::E_PARAM_ERROR, ErrCodeMap[CommonErrorCode::E_PARAM_ERROR]);
}
std::vector<std::string> bundleNames;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedBundleNames(domain, bundleNames);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<CommonErrorCode>(ret)) != 0) {
- reporter.WriteEndEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
+ reporter.SetEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
return BuildError(env, static_cast<CommonErrorCode>(ret), ErrCodeMap[static_cast<CommonErrorCode>(ret)]);
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
- reporter.WriteEndEvent(API_FAIL, ret);
+ reporter.SetEvent(API_FAIL, ret);
return BuildStringArray(env, bundleNames);
}
}
- reporter.WriteEndEvent(API_SUCCESS, ret);
+ reporter.SetEvent(API_SUCCESS, ret);
return BuildStringArray(env, bundleNames);
}
}
\ No newline at end of file
diff --git a/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp b/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
index ad79f60..d151734 100644
--- a/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
+++ b/interfaces/kits/js/deferred_link/src/deferred_link_napi.cpp
@@ -68,6 +68,7 @@ void GetDeferredLinkComplete(napi_env env, napi_status status, void* data)
NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
result[ARGS_SIZE_ONE] = BuildString(env, asyncCallbackInfo->deferred_link);
} else {
+ asyncCallbackInfo->apiReporter->SetEvent(API_FAIL, CommonErrorCode::E_INTERNAL_ERR);
result[0] = BuildError(env, CommonErrorCode::E_INTERNAL_ERR, g_ErrCodeMap[CommonErrorCode::E_INTERNAL_ERR]);
}
if (asyncCallbackInfo->deferred) {
@@ -85,7 +86,7 @@ void GetDeferredLinkComplete(napi_env env, napi_status status, void* data)
NAPI_CALL_RETURN_VOID(
env, napi_call_function(env, nullptr, callback, sizeof(result) / sizeof(result[0]), result, &placeHolder));
}
- callbackPtr->apiReporter->WriteEndEvent(API_SUCCESS, asyncCallbackInfo->err);
+ callbackPtr->apiReporter->SetEvent(API_SUCCESS, asyncCallbackInfo->err);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called end");
}
diff --git a/interfaces/kits/js/event/include/api_event_reporter.h b/interfaces/kits/js/event/include/api_event_reporter.h
index d7cc018..71f0cff 100644
--- a/interfaces/kits/js/event/include/api_event_reporter.h
+++ b/interfaces/kits/js/event/include/api_event_reporter.h
@@ -22,16 +22,19 @@ constexpr int32_t API_FAIL = 1;
class ApiEventReporter {
public:
explicit ApiEventReporter(const std::string& apiName);
- ~ApiEventReporter() = default;
- void WriteEndEvent(const int result, const int32_t errCode);
+ ~ApiEventReporter();
+ void SetEvent(const int result, const int32_t errCode);
private:
+ void WriteEndEvent(const int result, const int32_t errCode);
int64_t AddProcessor();
private:
std::string transId_;
std::string apiName_;
int64_t startTime_;
+ int result_{ API_FAIL };
+ int32_t errCode_{ -1 };
};
}
#endif // APP_DOMAIN_VERIFY_MANAGER_API_EVENT_REPORTER_H
diff --git a/interfaces/kits/js/event/src/api_event_reporter.cpp b/interfaces/kits/js/event/src/api_event_reporter.cpp
index 046f4ec..60dca38 100644
--- a/interfaces/kits/js/event/src/api_event_reporter.cpp
+++ b/interfaces/kits/js/event/src/api_event_reporter.cpp
@@ -104,4 +104,13 @@ void ApiEventReporter::WriteEndEvent(const int result, const int32_t errCode)
"errCode:%{public}d, ret:%{public}d",
transId_.c_str(), apiName_.c_str(), SDK_NAME.c_str(), result, errCode, ret);
}
+void ApiEventReporter::SetEvent(const int result, const int errCode)
+{
+ result_ = result;
+ errCode_ = errCode;
+}
+ApiEventReporter::~ApiEventReporter()
+{
+ WriteEndEvent(result_, errCode_);
+}
}
\ No newline at end of file
--
2.25.1
+77
View File
@@ -0,0 +1,77 @@
From 5b0b90847c61a5e09aea7caa8e2adf814e71ace4 Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Tue, 29 Oct 2024 20:19:46 +0800
Subject: [PATCH] support deferred link napi fix
Change-Id: If7f22258a8affa6ea7d8ec75df22de005b5f0cd4
---
services/src/manager/deferred_link/ability_filter.cpp | 2 +-
services/src/manager/deferred_link/deferred_link_mgr.cpp | 2 --
.../src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp | 2 +-
test/unittest/services/deferred_link_test/BUILD.gn | 2 +-
.../services/deferred_link_test/deferred_link_mgr_test.cpp | 2 +-
5 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/services/src/manager/deferred_link/ability_filter.cpp b/services/src/manager/deferred_link/ability_filter.cpp
index 3e8633d..0f2cbbe 100644
--- a/services/src/manager/deferred_link/ability_filter.cpp
+++ b/services/src/manager/deferred_link/ability_filter.cpp
@@ -31,6 +31,6 @@ public:
};
std::shared_ptr<AbilityFilter> AbilityFilter::Create()
{
- return std::shared_ptr<AbilityFilterImpl>();
+ return std::make_shared<AbilityFilterImpl>();
}
}
\ No newline at end of file
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
index 5654cc4..bcd3aae 100644
--- a/services/src/manager/deferred_link/deferred_link_mgr.cpp
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -74,8 +74,6 @@ void DeferredLinkMgr::AgeCacheProcess()
std::unique_lock<std::mutex> lock(cachesMutex_);
int64_t now = GetSecondsSince1970ToNow();
caches_.remove_if([now](const DeferredLinkInfo& linkInfo) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
- "url:%{public}s, now:%{public}lld, timestamp%{public}lld.", linkInfo.url.c_str(), now, linkInfo.timeStamp);
return now - linkInfo.timeStamp >= MAX_CACHE_TIME;
});
if (!caches_.empty()) {
diff --git a/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp b/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
index 9e90a20..3cc9579 100644
--- a/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
+++ b/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
@@ -334,7 +334,7 @@ int AppDomainVerifyMgrServiceProxy::GetDeferredLink(std::string& link)
AppDomainVerifyMgrInterfaceCode::GET_DEFERRED_LINK, data, reply, option);
if (error != ERR_NONE) {
APP_DOMAIN_VERIFY_HILOGE(
- APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "QueryAssociatedBundleNames failed, error: %d", error);
+ APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink failed, error: %d", error);
}
int32_t result = reply.ReadInt32();
if (result != 0) {
diff --git a/test/unittest/services/deferred_link_test/BUILD.gn b/test/unittest/services/deferred_link_test/BUILD.gn
index 665184a..30375ef 100644
--- a/test/unittest/services/deferred_link_test/BUILD.gn
+++ b/test/unittest/services/deferred_link_test/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright (C) 2023 Huawei Device Co., Ltd.
+# 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
diff --git a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
index 248152b..fe81a2d 100644
--- a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
+++ b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2023 Huawei Device Co., Ltd.
+ * 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
--
2.25.1
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,961 @@
From 98d33921d87937a8170820b06c180592730cfdcb Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Thu, 31 Oct 2024 21:01:38 +0800
Subject: [PATCH] support deferred link opt ipc with bms/ut
Change-Id: Ifa4a08eb074e3da54f917a0431e49b784b440ac7
---
.../common/include/bms/bundle_info_query.h | 7 +-
.../common/src/bms/bundle_info_query.cpp | 42 +---
.../core/app_domain_verify_mgr_service.h | 2 +-
.../manager/deferred_link/ability_filter.h | 4 +-
.../manager/deferred_link/deferred_link_mgr.h | 2 -
.../core/app_domain_verify_mgr_service.cpp | 6 +-
.../manager/deferred_link/ability_filter.cpp | 55 ++---
.../deferred_link/deferred_link_mgr.cpp | 38 ++--
test/unittest/BUILD.gn | 1 +
.../app_domain_verify_mgr_client_test.cpp | 19 ++
.../frameworks_common/bms_test/BUILD.gn | 4 +
.../bms_test/bundle_info_query_test.cpp | 15 ++
.../mock/include/mock_bundle_manager.h | 9 +
.../unittest/mock/src/mock_bundle_manager.cpp | 21 +-
.../services/ability_filter_test/BUILD.gn | 84 +++++++
.../ability_filter_test.cpp | 206 ++++++++++++++++++
.../services/deferred_link_test/BUILD.gn | 2 +-
.../deferred_link_mgr_test.cpp | 12 +-
.../mock_ability_filter.cpp | 30 +++
.../deferred_link_test/mock_ability_filter.h | 2 +-
20 files changed, 444 insertions(+), 117 deletions(-)
create mode 100644 test/unittest/services/ability_filter_test/BUILD.gn
create mode 100644 test/unittest/services/ability_filter_test/ability_filter_test.cpp
create mode 100644 test/unittest/services/deferred_link_test/mock_ability_filter.cpp
diff --git a/frameworks/common/include/bms/bundle_info_query.h b/frameworks/common/include/bms/bundle_info_query.h
index f8ed716..c48845c 100644
--- a/frameworks/common/include/bms/bundle_info_query.h
+++ b/frameworks/common/include/bms/bundle_info_query.h
@@ -24,13 +24,10 @@ 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 GetBundleNameForUid(const int uid, std::string& bundleName);
- static bool QueryAbilityInfosByUrl(
- const std::string& bundleName, const std::string& url, std::vector<AbilityInfo>& abilityInfos);
- static bool GetBundleInfosV9(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos);
+ 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();
diff --git a/frameworks/common/src/bms/bundle_info_query.cpp b/frameworks/common/src/bms/bundle_info_query.cpp
index d6d03f9..daefb9d 100644
--- a/frameworks/common/src/bms/bundle_info_query.cpp
+++ b/frameworks/common/src/bms/bundle_info_query.cpp
@@ -23,7 +23,6 @@
namespace OHOS {
namespace AppDomainVerify {
-constexpr int USER_ID_DEFAULT = 100;
bool BundleInfoQuery::GetBundleInfo(const std::string& bundleName, std::string& appIdentifier, std::string& fingerprint)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
@@ -108,7 +107,7 @@ bool BundleInfoQuery::GetBundleNameForUid(const int uid, std::string& bundleName
std::string identity = IPCSkeleton::ResetCallingIdentity();
auto ret = bundleMgrProxy->GetBundleNameForUid(uid, bundleName);
IPCSkeleton::SetCallingIdentity(identity);
- if (ret != ERR_OK) {
+ if (!ret) {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
return false;
}
@@ -116,36 +115,7 @@ bool BundleInfoQuery::GetBundleNameForUid(const int uid, std::string& bundleName
return true;
}
-bool BundleInfoQuery::QueryAbilityInfosByUrl(
- const std::string& bundleName, const std::string& url, 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;
- }
- Want want;
- // want.SetBundle(bundleName);
- want.SetUri(url);
- want.AddEntity(ENTITY_BROWSER);
- want.SetAction(ACTION_VIEW_DATA);
-
- // use sa identity
- std::string identity = IPCSkeleton::ResetCallingIdentity();
- auto ret = bundleMgrProxy->QueryAbilityInfosV9(
- want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, USER_ID_DEFAULT, abilityInfos);
- IPCSkeleton::SetCallingIdentity(identity);
- if (ret != ERR_OK) {
- APP_DOMAIN_VERIFY_HILOGD(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::GetBundleInfosV9(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos)
+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();
@@ -159,13 +129,13 @@ bool BundleInfoQuery::GetBundleInfosV9(const std::string& bundleName, std::vecto
AppExecFwk::BundleInfo bundleInfo;
// use sa identity
std::string identity = IPCSkeleton::ResetCallingIdentity();
- auto ret = bundleMgrProxy->GetBundleInfoV9(
- bundleName, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, bundleInfo, USER_ID_DEFAULT);
+ auto ret = bundleMgrProxy->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo);
IPCSkeleton::SetCallingIdentity(identity);
- if (ret != ERR_OK) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
+ 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;
};
diff --git a/services/include/manager/core/app_domain_verify_mgr_service.h b/services/include/manager/core/app_domain_verify_mgr_service.h
index 97304f9..114d68f 100644
--- a/services/include/manager/core/app_domain_verify_mgr_service.h
+++ b/services/include/manager/core/app_domain_verify_mgr_service.h
@@ -65,7 +65,7 @@ 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();
diff --git a/services/include/manager/deferred_link/ability_filter.h b/services/include/manager/deferred_link/ability_filter.h
index 79cafb0..df693a4 100644
--- a/services/include/manager/deferred_link/ability_filter.h
+++ b/services/include/manager/deferred_link/ability_filter.h
@@ -21,7 +21,6 @@
namespace OHOS::AppDomainVerify {
struct FilterInfo {
- std::string bundleName;
std::string url;
};
class AbilityFilter {
@@ -33,9 +32,8 @@ public:
* @return bool return true if can match abilities else false.
*/
virtual bool Filter(const FilterInfo& info) = 0;
- virtual void SetBundleName(const std::string& bundleName);
virtual ~AbilityFilter() = default;
- static std::shared_ptr<AbilityFilter> Create();
+ static std::shared_ptr<AbilityFilter> Create(const std::string& bundleName);
};
}
#endif // APP_DOMAIN_VERIFY_ABILITY_FILTER_H
diff --git a/services/include/manager/deferred_link/deferred_link_mgr.h b/services/include/manager/deferred_link/deferred_link_mgr.h
index a6869d5..ad161fd 100644
--- a/services/include/manager/deferred_link/deferred_link_mgr.h
+++ b/services/include/manager/deferred_link/deferred_link_mgr.h
@@ -60,7 +60,6 @@ public:
~DeferredLinkMgr();
private:
- bool CanMatchAbility(const std::string& bundleName, const std::string& url);
void PostAgeCacheTask();
void AgeCacheProcess();
void CheckStartTimerUnlocked();
@@ -74,7 +73,6 @@ private:
std::mutex cachesMutex_;
std::shared_ptr<AppExecFwk::EventHandler> ageHandler_;
std::shared_ptr<AppExecFwk::EventRunner> ageRunner_;
- std::shared_ptr<AbilityFilter> abilityFilter_ = AbilityFilter::Create();
};
}
#endif // APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
diff --git a/services/src/manager/core/app_domain_verify_mgr_service.cpp b/services/src/manager/core/app_domain_verify_mgr_service.cpp
index 2f9d918..49568c2 100644
--- a/services/src/manager/core/app_domain_verify_mgr_service.cpp
+++ b/services/src/manager/core/app_domain_verify_mgr_service.cpp
@@ -110,7 +110,7 @@ bool AppDomainVerifyMgrService::FilterAbilities(const OHOS::AAFwk::Want& want,
}
}
}
- if (filteredAbilityInfos.empty()) {
+ if (filteredAbilityInfos.empty() && !IsUrlInBlackList(uriString)) {
deferredLinkMgr_->PutDeferredLink(
{ .domain = hostVerifyKey, .url = uriString, .timeStamp = GetSecondsSince1970ToNow() });
}
@@ -352,5 +352,9 @@ int AppDomainVerifyMgrService::GetDeferredLink(std::string& link)
return CommonErrorCode::E_PERMISSION_DENIED;
}
}
+bool AppDomainVerifyMgrService::IsUrlInBlackList(const std::string& url)
+{
+ return IsAtomicServiceUrl(url);
+}
} // namespace AppDomainVerify
} // namespace OHOS
diff --git a/services/src/manager/deferred_link/ability_filter.cpp b/services/src/manager/deferred_link/ability_filter.cpp
index 3b7bef7..e918806 100644
--- a/services/src/manager/deferred_link/ability_filter.cpp
+++ b/services/src/manager/deferred_link/ability_filter.cpp
@@ -13,72 +13,47 @@
* 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 AbilityFilterImpl : public AbilityFilter {
-public:
- void SetBundleName(const std::string& bundleName) override
- {
- AbilityFilter::SetBundleName(bundleName);
- }
- bool Filter(const FilterInfo& info) override
- {
- bool result{ false };
- std::vector<AbilityInfo> abilityInfos;
- if (BundleInfoQuery::QueryAbilityInfosByUrl(info.bundleName, info.url, abilityInfos)) {
- result = !abilityInfos.empty();
- }
- return result;
- }
-};
class BundleAbilityFilterImpl : public AbilityFilter {
public:
- void SetBundleName(const std::string& bundleName) override
+ explicit BundleAbilityFilterImpl(std::string bundleName) : bundleName_(std::move(bundleName))
{
- this->bundleName_ = bundleName;
Init();
}
bool Filter(const FilterInfo& info) override
{
- Want want;
- want.SetUri(info.url);
- want.AddEntity(ENTITY_BROWSER);
- want.SetAction(ACTION_VIEW_DATA);
+ Want urlWant;
+ urlWant.SetUri(info.url);
+ urlWant.AddEntity(ENTITY_BROWSER);
+ urlWant.SetAction(ACTION_VIEW_DATA);
auto matchedAbility = std::find_if(
- abilityInfos_.begin(), abilityInfos_.end(), [&want](const AbilityInfo& abilityInfo) {
+ 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.begin(), skills.end(), [&want](const Skill& skill) {
- APP_DOMAIN_VERIFY_HILOGD(
- APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "domainVerify:%{private}d", skill.domainVerify);
- if (skill.domainVerify && skill.Match(want)) {
+ auto matchedSkill = std::find_if(skills.cbegin(), skills.cend(), [&urlWant](const Skill& skill) {
+ if (skill.domainVerify && skill.Match(urlWant)) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill matched");
return true;
}
return false;
});
- if (matchedSkill != skills.end()) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill matched");
- return true;
- }
- return true;
+ return matchedSkill != skills.cend();
});
- if (matchedAbility != abilityInfos_.end()) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "ability matched");
- return true;
- }
- return false;
+
+ return matchedAbility != abilityInfos_.cend();
}
void Init()
{
- BundleInfoQuery::GetBundleInfosV9(bundleName_, abilityInfos_);
+ BundleInfoQuery::GetBundleAbilityInfos(bundleName_, abilityInfos_);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "abilityInfos size:%zu", abilityInfos_.size());
}
@@ -86,8 +61,8 @@ private:
std::vector<AbilityInfo> abilityInfos_;
std::string bundleName_;
};
-std::shared_ptr<AbilityFilter> AbilityFilter::Create()
+std::shared_ptr<AbilityFilter> AbilityFilter::Create(const std::string& bundleName)
{
- return std::make_shared<BundleAbilityFilterImpl>();
+ return std::make_shared<BundleAbilityFilterImpl>(bundleName);
}
}
\ No newline at end of file
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
index a951f5c..d982508 100644
--- a/services/src/manager/deferred_link/deferred_link_mgr.cpp
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -17,7 +17,7 @@
namespace OHOS::AppDomainVerify {
namespace {
constexpr const char* TASK_ID = "age";
-constexpr int32_t DELAY_TIME = 60000; // 1min
+constexpr int32_t DELAY_TIME = 60000; // 1min
constexpr int64_t MAX_CACHE_TIME = 600; // 10min
constexpr int MAX_CACHE_SIZE = 50;
}
@@ -39,29 +39,29 @@ std::string DeferredLinkMgr::GetDeferredLink(const std::string& bundleName, cons
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
std::set<std::string> domainSet(domains.begin(), domains.end());
- std::unique_lock<std::mutex> lock(cachesMutex_);
+ auto filter = AbilityFilter::Create(bundleName);
std::list<DeferredLinkInfo> destination;
- // find links in bundle's domain and can match bundle's ability, then remove all of them.
- caches_.remove_if([this, &bundleName, &domainSet, &destination](const DeferredLinkInfo& linkInfo) {
- if (domainSet.count(linkInfo.domain) != 0 && CanMatchAbility(bundleName, 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::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 url:%{private}s", result.c_str());
return result;
}
-bool DeferredLinkMgr::CanMatchAbility(const std::string& bundleName, const std::string& url)
-{
- abilityFilter_->SetBundleName(bundleName);
- return abilityFilter_->Filter({ .bundleName = bundleName, .url = url });
-}
void DeferredLinkMgr::PostAgeCacheTask()
{
if (ageHandler_) {
@@ -74,9 +74,7 @@ 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;
- });
+ 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());
diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn
index 6ac027c..39d6cb2 100644
--- a/test/unittest/BUILD.gn
+++ b/test/unittest/BUILD.gn
@@ -30,6 +30,7 @@ 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",
diff --git a/test/unittest/client/app_domain_verify_mgr_client_test/app_domain_verify_mgr_client_test.cpp b/test/unittest/client/app_domain_verify_mgr_client_test/app_domain_verify_mgr_client_test.cpp
index 8c7fd7b..d0a6cc8 100644
--- a/test/unittest/client/app_domain_verify_mgr_client_test/app_domain_verify_mgr_client_test.cpp
+++ b/test/unittest/client/app_domain_verify_mgr_client_test/app_domain_verify_mgr_client_test.cpp
@@ -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.
diff --git a/test/unittest/frameworks_common/bms_test/BUILD.gn b/test/unittest/frameworks_common/bms_test/BUILD.gn
index 31d2ee9..e3164da 100644
--- a/test/unittest/frameworks_common/bms_test/BUILD.gn
+++ b/test/unittest/frameworks_common/bms_test/BUILD.gn
@@ -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",
diff --git a/test/unittest/frameworks_common/bms_test/bundle_info_query_test.cpp b/test/unittest/frameworks_common/bms_test/bundle_info_query_test.cpp
index 6a665be..8dd3c83 100644
--- a/test/unittest/frameworks_common/bms_test/bundle_info_query_test.cpp
+++ b/test/unittest/frameworks_common/bms_test/bundle_info_query_test.cpp
@@ -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));
+}
}
\ No newline at end of file
diff --git a/test/unittest/mock/include/mock_bundle_manager.h b/test/unittest/mock/include/mock_bundle_manager.h
index 5219fcb..667fef8 100644
--- a/test/unittest/mock/include/mock_bundle_manager.h
+++ b/test/unittest/mock/include/mock_bundle_manager.h
@@ -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;
};
diff --git a/test/unittest/mock/src/mock_bundle_manager.cpp b/test/unittest/mock/src/mock_bundle_manager.cpp
index e49ffcf..f1428ea 100644
--- a/test/unittest/mock/src/mock_bundle_manager.cpp
+++ b/test/unittest/mock/src/mock_bundle_manager.cpp
@@ -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
\ No newline at end of file
diff --git a/test/unittest/services/ability_filter_test/BUILD.gn b/test/unittest/services/ability_filter_test/BUILD.gn
new file mode 100644
index 0000000..27ce2eb
--- /dev/null
+++ b/test/unittest/services/ability_filter_test/BUILD.gn
@@ -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",
+ ]
+}
diff --git a/test/unittest/services/ability_filter_test/ability_filter_test.cpp b/test/unittest/services/ability_filter_test/ability_filter_test.cpp
new file mode 100644
index 0000000..30f29c5
--- /dev/null
+++ b/test/unittest/services/ability_filter_test/ability_filter_test.cpp
@@ -0,0 +1,206 @@
+/*
+ * 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 }));
+//}
+}
\ No newline at end of file
diff --git a/test/unittest/services/deferred_link_test/BUILD.gn b/test/unittest/services/deferred_link_test/BUILD.gn
index 50a8bc9..d11bcd7 100644
--- a/test/unittest/services/deferred_link_test/BUILD.gn
+++ b/test/unittest/services/deferred_link_test/BUILD.gn
@@ -44,10 +44,10 @@ ohos_unittest("deferred_link_test") {
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_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 = [
diff --git a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
index fe81a2d..162aa59 100644
--- a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
+++ b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
@@ -127,7 +127,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest001, TestSize.Level0)
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(1).WillOnce(Return(true));
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
@@ -155,7 +155,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest002, TestSize.Level0)
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(0);
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
@@ -179,7 +179,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest003, TestSize.Level0)
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(0);
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
@@ -203,7 +203,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest004, TestSize.Level0)
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(1).WillOnce(Return(false));
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
EXPECT_TRUE(deferredLinkMgr.caches_.size() == 1);
@@ -227,7 +227,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest005, TestSize.Level0)
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
EXPECT_CALL(*filter, Filter(_)).Times(2).WillRepeatedly(Return(true));
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
deferredLinkMgr.PutDeferredLink(
@@ -256,7 +256,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest006, TestSize.Level0)
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
- deferredLinkMgr.abilityFilter_ = filter;
+ MockAbilityFilter(filter);
std::vector<std::string> domains;
domains.emplace_back(BUNDLE_DOMAIN);
diff --git a/test/unittest/services/deferred_link_test/mock_ability_filter.cpp b/test/unittest/services/deferred_link_test/mock_ability_filter.cpp
new file mode 100644
index 0000000..2363a4f
--- /dev/null
+++ b/test/unittest/services/deferred_link_test/mock_ability_filter.cpp
@@ -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;
+}
+}
\ No newline at end of file
diff --git a/test/unittest/services/deferred_link_test/mock_ability_filter.h b/test/unittest/services/deferred_link_test/mock_ability_filter.h
index db46f0a..9819965 100644
--- a/test/unittest/services/deferred_link_test/mock_ability_filter.h
+++ b/test/unittest/services/deferred_link_test/mock_ability_filter.h
@@ -18,10 +18,10 @@
#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));
- MOCK_METHOD(void, SetBundleName, (const std::string& bundleName), (override));
};
}
#endif // APP_DOMAIN_VERIFY_MOCK_ABILITY_FILTER_H
--
2.25.1
@@ -0,0 +1,335 @@
From 215559f2b219ca5b957f3b0584d4fde381a80e36 Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Thu, 31 Oct 2024 11:45:42 +0800
Subject: [PATCH] support deferred link opt ipc with bms
Change-Id: I858b50415d2ff8dd73ce06e5d4cd9227596971df
---
.../common/include/bms/bundle_info_query.h | 7 ++-
.../common/src/bms/bundle_info_query.cpp | 37 +++++------
.../manager/deferred_link/ability_filter.h | 1 +
.../manager/deferred_link/deferred_link_mgr.h | 2 +-
.../manager/deferred_link/ability_filter.cpp | 61 ++++++++++++++++++-
.../deferred_link/deferred_link_mgr.cpp | 5 +-
.../services/deferred_link_test/BUILD.gn | 1 +
.../deferred_link_test/mock_ability_filter.h | 30 ++++-----
8 files changed, 104 insertions(+), 40 deletions(-)
diff --git a/frameworks/common/include/bms/bundle_info_query.h b/frameworks/common/include/bms/bundle_info_query.h
index 4ad898f..f8ed716 100644
--- a/frameworks/common/include/bms/bundle_info_query.h
+++ b/frameworks/common/include/bms/bundle_info_query.h
@@ -21,6 +21,8 @@ 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:
@@ -28,12 +30,13 @@ public:
static bool GetBundleNameForUid(const int uid, std::string& bundleName);
static bool QueryAbilityInfosByUrl(
const std::string& bundleName, const std::string& url, std::vector<AbilityInfo>& abilityInfos);
- static bool GetBundleNameSelf(std::string& bundleName);
+ static bool GetBundleInfosV9(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos);
+
private:
static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
static int32_t GetCurrentAccountId();
BundleInfoQuery(){};
- ~BundleInfoQuery(){};
+ ~BundleInfoQuery() = default;
};
}
}
diff --git a/frameworks/common/src/bms/bundle_info_query.cpp b/frameworks/common/src/bms/bundle_info_query.cpp
index 0e10a04..d6d03f9 100644
--- a/frameworks/common/src/bms/bundle_info_query.cpp
+++ b/frameworks/common/src/bms/bundle_info_query.cpp
@@ -23,8 +23,6 @@
namespace OHOS {
namespace AppDomainVerify {
-constexpr const char* ACTION_VIEW_DATA = "ohos.want.action.viewData";
-constexpr const char* ENTITY_BROWSER = "entity.system.browsable";
constexpr int USER_ID_DEFAULT = 100;
bool BundleInfoQuery::GetBundleInfo(const std::string& bundleName, std::string& appIdentifier, std::string& fingerprint)
{
@@ -117,7 +115,9 @@ bool BundleInfoQuery::GetBundleNameForUid(const int uid, std::string& bundleName
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
}
-bool BundleInfoQuery::GetBundleNameSelf(std::string& bundleName)
+
+bool BundleInfoQuery::QueryAbilityInfosByUrl(
+ const std::string& bundleName, const std::string& url, std::vector<AbilityInfo>& abilityInfos)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
@@ -127,19 +127,25 @@ bool BundleInfoQuery::GetBundleNameSelf(std::string& bundleName)
UNIVERSAL_ERROR_EVENT(CONNECT_OTHER_FAULT);
return false;
}
+ Want want;
+ // want.SetBundle(bundleName);
+ want.SetUri(url);
+ want.AddEntity(ENTITY_BROWSER);
+ want.SetAction(ACTION_VIEW_DATA);
- OHOS::AppExecFwk::BundleInfo bundleInfo;
- auto ret = bundleMgrProxy->GetBundleInfoForSelf(0, bundleInfo);
+ // use sa identity
+ std::string identity = IPCSkeleton::ResetCallingIdentity();
+ auto ret = bundleMgrProxy->QueryAbilityInfosV9(
+ want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, USER_ID_DEFAULT, abilityInfos);
+ IPCSkeleton::SetCallingIdentity(identity);
if (ret != ERR_OK) {
- APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
return false;
}
- bundleName = bundleInfo.name;
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
}
-bool BundleInfoQuery::QueryAbilityInfosByUrl(
- const std::string& bundleName, const std::string& url, std::vector<AbilityInfo>& abilityInfos)
+bool BundleInfoQuery::GetBundleInfosV9(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos)
{
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = GetBundleMgrProxy();
@@ -149,16 +155,12 @@ bool BundleInfoQuery::QueryAbilityInfosByUrl(
UNIVERSAL_ERROR_EVENT(CONNECT_OTHER_FAULT);
return false;
}
- Want want;
- want.SetBundle(bundleName);
- want.SetUri(url);
- want.AddEntity(ENTITY_BROWSER);
- want.SetAction(ACTION_VIEW_DATA);
+ AppExecFwk::BundleInfo bundleInfo;
// use sa identity
std::string identity = IPCSkeleton::ResetCallingIdentity();
- auto ret = bundleMgrProxy->QueryAbilityInfosV9(
- want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, USER_ID_DEFAULT, abilityInfos);
+ auto ret = bundleMgrProxy->GetBundleInfoV9(
+ bundleName, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, bundleInfo, USER_ID_DEFAULT);
IPCSkeleton::SetCallingIdentity(identity);
if (ret != ERR_OK) {
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
@@ -166,7 +168,6 @@ bool BundleInfoQuery::QueryAbilityInfosByUrl(
}
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
return true;
-}
-
+};
}
}
\ No newline at end of file
diff --git a/services/include/manager/deferred_link/ability_filter.h b/services/include/manager/deferred_link/ability_filter.h
index 7857f1e..79cafb0 100644
--- a/services/include/manager/deferred_link/ability_filter.h
+++ b/services/include/manager/deferred_link/ability_filter.h
@@ -33,6 +33,7 @@ public:
* @return bool return true if can match abilities else false.
*/
virtual bool Filter(const FilterInfo& info) = 0;
+ virtual void SetBundleName(const std::string& bundleName);
virtual ~AbilityFilter() = default;
static std::shared_ptr<AbilityFilter> Create();
};
diff --git a/services/include/manager/deferred_link/deferred_link_mgr.h b/services/include/manager/deferred_link/deferred_link_mgr.h
index 5d24953..a6869d5 100644
--- a/services/include/manager/deferred_link/deferred_link_mgr.h
+++ b/services/include/manager/deferred_link/deferred_link_mgr.h
@@ -64,7 +64,7 @@ private:
void PostAgeCacheTask();
void AgeCacheProcess();
void CheckStartTimerUnlocked();
- void CheckFullUnlocked(const DeferredLinkInfo& info);
+ void CheckFullUnlocked();
void CheckRemoveExistedUnlocked(const DeferredLinkInfo& info);
/**
* cache list
diff --git a/services/src/manager/deferred_link/ability_filter.cpp b/services/src/manager/deferred_link/ability_filter.cpp
index 0f2cbbe..3b7bef7 100644
--- a/services/src/manager/deferred_link/ability_filter.cpp
+++ b/services/src/manager/deferred_link/ability_filter.cpp
@@ -12,13 +12,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <string>
#include "ability_filter.h"
#include "bundle_info_query.h"
+#include "app_domain_verify_hilog.h"
namespace OHOS::AppDomainVerify {
-
+using Skill = OHOS::AppExecFwk::Skill;
class AbilityFilterImpl : public AbilityFilter {
public:
+ void SetBundleName(const std::string& bundleName) override
+ {
+ AbilityFilter::SetBundleName(bundleName);
+ }
bool Filter(const FilterInfo& info) override
{
bool result{ false };
@@ -29,8 +35,59 @@ public:
return result;
}
};
+
+class BundleAbilityFilterImpl : public AbilityFilter {
+public:
+ void SetBundleName(const std::string& bundleName) override
+ {
+ this->bundleName_ = bundleName;
+ Init();
+ }
+ bool Filter(const FilterInfo& info) override
+ {
+ Want want;
+ want.SetUri(info.url);
+ want.AddEntity(ENTITY_BROWSER);
+ want.SetAction(ACTION_VIEW_DATA);
+
+ auto matchedAbility = std::find_if(
+ abilityInfos_.begin(), abilityInfos_.end(), [&want](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.begin(), skills.end(), [&want](const Skill& skill) {
+ APP_DOMAIN_VERIFY_HILOGD(
+ APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "domainVerify:%{private}d", skill.domainVerify);
+ if (skill.domainVerify && skill.Match(want)) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill matched");
+ return true;
+ }
+ return false;
+ });
+ if (matchedSkill != skills.end()) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "skill matched");
+ return true;
+ }
+ return true;
+ });
+ if (matchedAbility != abilityInfos_.end()) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "ability matched");
+ return true;
+ }
+ return false;
+ }
+ void Init()
+ {
+ BundleInfoQuery::GetBundleInfosV9(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()
{
- return std::make_shared<AbilityFilterImpl>();
+ return std::make_shared<BundleAbilityFilterImpl>();
}
}
\ No newline at end of file
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
index bcd3aae..a951f5c 100644
--- a/services/src/manager/deferred_link/deferred_link_mgr.cpp
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -27,7 +27,7 @@ void DeferredLinkMgr::PutDeferredLink(const DeferredLinkInfo& info)
std::unique_lock<std::mutex> lock(cachesMutex_);
CheckStartTimerUnlocked();
CheckRemoveExistedUnlocked(info);
- CheckFullUnlocked(info);
+ CheckFullUnlocked();
caches_.push_front(info);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "info domain:%{private}s, url:%{private}s.",
@@ -59,6 +59,7 @@ std::string DeferredLinkMgr::GetDeferredLink(const std::string& bundleName, cons
bool DeferredLinkMgr::CanMatchAbility(const std::string& bundleName, const std::string& url)
{
+ abilityFilter_->SetBundleName(bundleName);
return abilityFilter_->Filter({ .bundleName = bundleName, .url = url });
}
void DeferredLinkMgr::PostAgeCacheTask()
@@ -90,7 +91,7 @@ void DeferredLinkMgr::CheckStartTimerUnlocked()
PostAgeCacheTask();
}
}
-void DeferredLinkMgr::CheckFullUnlocked(const DeferredLinkInfo& info)
+void DeferredLinkMgr::CheckFullUnlocked()
{
if (caches_.size() == MAX_CACHE_SIZE) {
caches_.pop_back();
diff --git a/test/unittest/services/deferred_link_test/BUILD.gn b/test/unittest/services/deferred_link_test/BUILD.gn
index 30375ef..50a8bc9 100644
--- a/test/unittest/services/deferred_link_test/BUILD.gn
+++ b/test/unittest/services/deferred_link_test/BUILD.gn
@@ -43,6 +43,7 @@ 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/ability_filter.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",
diff --git a/test/unittest/services/deferred_link_test/mock_ability_filter.h b/test/unittest/services/deferred_link_test/mock_ability_filter.h
index 3a9693d..db46f0a 100644
--- a/test/unittest/services/deferred_link_test/mock_ability_filter.h
+++ b/test/unittest/services/deferred_link_test/mock_ability_filter.h
@@ -1,17 +1,17 @@
/*
-* 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.
-*/
+ * 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
@@ -20,8 +20,8 @@
namespace OHOS::AppDomainVerify {
class MocAbilityFilter : public AbilityFilter {
public:
- MOCK_METHOD(bool, Filter, (const FilterInfo& info),
- (override));
+ MOCK_METHOD(bool, Filter, (const FilterInfo& info), (override));
+ MOCK_METHOD(void, SetBundleName, (const std::string& bundleName), (override));
};
}
#endif // APP_DOMAIN_VERIFY_MOCK_ABILITY_FILTER_H
--
2.25.1
@@ -0,0 +1,207 @@
From cde26899644bbea87405cec843057114dfe71c00 Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Mon, 28 Oct 2024 16:52:45 +0800
Subject: [PATCH] support deferred link remove batch urls
Change-Id: I365f97415ec72388d21993419b1673142709a779
---
.../manager/deferred_link/deferred_link_mgr.h | 4 +-
.../deferred_link/deferred_link_mgr.cpp | 59 ++++++++++---------
.../deferred_link_mgr_test.cpp | 22 ++++---
3 files changed, 47 insertions(+), 38 deletions(-)
diff --git a/services/include/manager/deferred_link/deferred_link_mgr.h b/services/include/manager/deferred_link/deferred_link_mgr.h
index 77a4c63..5d59a53 100644
--- a/services/include/manager/deferred_link/deferred_link_mgr.h
+++ b/services/include/manager/deferred_link/deferred_link_mgr.h
@@ -61,11 +61,11 @@ public:
private:
bool CanMatchAbility(const std::string& bundleName, const std::string& url);
- void PostAgeTask();
+ void PostAgeCacheTask();
void AgeCacheProcess();
void CheckStartTimerUnlocked();
void CheckFullUnlocked(const DeferredLinkInfo& info);
- void CheckExistedUnlocked(const DeferredLinkInfo& info);
+ void CheckRemoveExistedUnlocked(const DeferredLinkInfo& info);
/**
* cache list
* @descrition list contains deferred link info, newly in front, older in back.
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
index 668416b..2192f9b 100644
--- a/services/src/manager/deferred_link/deferred_link_mgr.cpp
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -17,20 +17,19 @@
namespace OHOS::AppDomainVerify {
namespace {
constexpr const char* TASK_ID = "age";
-constexpr int32_t DELAY_TIME = 120000; // 2min
-constexpr int64_t MAX_CACHE_TIME = 1200000; // 10min
+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_);
- CheckExistedUnlocked(info);
+ CheckStartTimerUnlocked();
+ CheckRemoveExistedUnlocked(info);
CheckFullUnlocked(info);
caches.push_front(info);
-
- CheckStartTimerUnlocked();
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "info domain:%{private}s, url:%{private}s.",
info.domain.c_str(), info.url.c_str());
}
@@ -38,24 +37,22 @@ void DeferredLinkMgr::PutDeferredLink(const DeferredLinkInfo& info)
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::string result;
+
std::set<std::string> domainSet(domains.begin(), domains.end());
std::unique_lock<std::mutex> lock(cachesMutex_);
- auto target = std::find_if(
- caches.cbegin(), caches.cend(), [this, &bundleName, &domainSet](const DeferredLinkInfo& linkInfo) {
- if (domainSet.count(linkInfo.domain) != 0 && CanMatchAbility(bundleName, linkInfo.url)) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "matched.");
- return true;
- }
- return false;
- });
- if (target != caches.cend()) {
- result = target->url;
- caches.erase(target);
- APP_DOMAIN_VERIFY_HILOGD(
- APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "erase after get url:%{private}s", result.c_str());
- return result;
- }
+ std::list<DeferredLinkInfo> destination;
+ // find links in bundle's domain and can match bundle's ability, then remove all of them.
+ caches.remove_if([this, &bundleName, &domainSet, &destination](const DeferredLinkInfo& linkInfo) {
+ if (domainSet.count(linkInfo.domain) != 0 && CanMatchAbility(bundleName, 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 url:%{private}s", result.c_str());
return result;
}
@@ -64,9 +61,10 @@ bool DeferredLinkMgr::CanMatchAbility(const std::string& bundleName, const std::
{
return abilityFilter_->Filter({ .bundleName = bundleName, .url = url });
}
-void DeferredLinkMgr::PostAgeTask()
+void DeferredLinkMgr::PostAgeCacheTask()
{
if (ageHandler_) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "PostAgeCacheTask.");
ageHandler_->PostTask([this] { AgeCacheProcess(); }, TASK_ID, DELAY_TIME);
}
}
@@ -75,18 +73,23 @@ 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; });
+ caches.remove_if([now](const DeferredLinkInfo& linkInfo) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
+ "url:%{public}s, now:%{public}lld, timestamp%{public}lld.", linkInfo.url.c_str(), now, linkInfo.timeStamp);
+ return now - linkInfo.timeStamp >= MAX_CACHE_TIME;
+ });
if (!caches.empty()) {
- APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "post continue age task.");
- PostAgeTask();
+ 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.size() == 1) {
- PostAgeTask();
+ if (caches.empty()) {
+ PostAgeCacheTask();
}
}
void DeferredLinkMgr::CheckFullUnlocked(const DeferredLinkInfo& info)
@@ -95,7 +98,7 @@ void DeferredLinkMgr::CheckFullUnlocked(const DeferredLinkInfo& info)
caches.pop_back();
}
}
-void DeferredLinkMgr::CheckExistedUnlocked(const DeferredLinkInfo& info)
+void DeferredLinkMgr::CheckRemoveExistedUnlocked(const DeferredLinkInfo& info)
{
caches.remove_if([&info](const DeferredLinkInfo& curInfo) {
if (curInfo.url == info.url && curInfo.domain == info.domain) {
diff --git a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
index 26e1ca5..42eeac6 100644
--- a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
+++ b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
@@ -217,7 +217,7 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest004, TestSize.Level0)
/**
* @tc.name: DeferredLinkGetTest005
- * @tc.desc: get link with matched domain and matched url, return back link.
+ * @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)
@@ -225,7 +225,7 @@ 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(1).WillOnce(Return(true));
+ EXPECT_CALL(*filter, Filter(_)).Times(2).WillRepeatedly(Return(true));
deferredLinkMgr.abilityFilter_ = filter;
deferredLinkMgr.PutDeferredLink(
{ .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
@@ -239,20 +239,26 @@ HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest005, TestSize.Level0)
EXPECT_FALSE(link.empty());
EXPECT_EQ(link, BUNDLE_URL_NEW);
- EXPECT_TRUE(deferredLinkMgr.caches.size() == 1);
+ EXPECT_TRUE(deferredLinkMgr.caches.empty());
}
/**
- * @tc.name: DeferredLinkAgeTest001
- * @tc.desc: put one , will trigger age task after time count.
+ * @tc.name: DeferredLinkGetTest006
+ * @tc.desc: get link from empty cache, return null.
* @tc.type: FUNC
*/
-HWTEST_F(DeferredLinkMgrTest, DeferredLinkAgeTest001, TestSize.Level0)
+HWTEST_F(DeferredLinkMgrTest, DeferredLinkGetTest006, TestSize.Level0)
{
DeferredLinkMgr deferredLinkMgr;
deferredLinkMgr.ageHandler_ = nullptr;
+ std::shared_ptr<MocAbilityFilter> filter = std::make_shared<MocAbilityFilter>();
+ deferredLinkMgr.abilityFilter_ = filter;
- deferredLinkMgr.PutDeferredLink(
- { .domain = BUNDLE_DOMAIN, .url = BUNDLE_URL, .timeStamp = GetSecondsSince1970ToNow() });
+ std::vector<std::string> domains;
+ domains.emplace_back(BUNDLE_DOMAIN);
+ auto link = deferredLinkMgr.GetDeferredLink(BUNDLE_NAME, domains);
+
+ EXPECT_TRUE(link.empty());
}
+
}
\ No newline at end of file
--
2.25.1
File diff suppressed because it is too large Load Diff
+988
View File
@@ -0,0 +1,988 @@
From 870a28c2afabfd9980f9800e834e6ec3896cf80f Mon Sep 17 00:00:00 2001
From: woohoa <wanghuan36@huawei.com>
Date: Thu, 24 Oct 2024 14:59:58 +0800
Subject: [PATCH] support deferred link
Change-Id: I82f249121dd3a515a67f5f3f219775275b085496
---
.../common/include/bms/bundle_info_query.h | 8 +-
.../common/src/bms/bundle_info_query.cpp | 99 +++++++++++++++----
interfaces/inner_api/client/BUILD.gn | 4 +
.../include/app_domain_verify_mgr_client.h | 8 ++
.../src/app_domain_verify_agent_client.cpp | 4 +-
.../src/app_domain_verify_mgr_client.cpp | 32 +++++-
.../js/src/app_domain_verify_manager_napi.cpp | 1 +
services/BUILD.gn | 5 +
.../manager/core/app_domain_verify_data_mgr.h | 4 +-
.../app_domain_verify_mgr_interface_code.h | 3 +-
.../core/app_domain_verify_mgr_service.h | 7 +-
.../core/i_app_domain_verify_mgr_service.h | 3 +-
.../manager/deferred_link/deferred_link_mgr.h | 60 +++++++++++
.../app_domain_verify_mgr_service_proxy.h | 27 ++---
.../zidl/app_domain_verify_mgr_service_stub.h | 3 +-
.../core/app_domain_verify_mgr_service.cpp | 38 +++++--
.../deferred_link/deferred_link_mgr.cpp | 95 ++++++++++++++++++
.../app_domain_verify_mgr_service_proxy.cpp | 28 +++++-
.../app_domain_verify_mgr_service_stub.cpp | 16 +++
.../deferred_link_mgr_test.cpp | 61 ++++++++++++
20 files changed, 452 insertions(+), 54 deletions(-)
create mode 100644 services/include/manager/deferred_link/deferred_link_mgr.h
create mode 100644 services/src/manager/deferred_link/deferred_link_mgr.cpp
create mode 100644 test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
diff --git a/frameworks/common/include/bms/bundle_info_query.h b/frameworks/common/include/bms/bundle_info_query.h
index 780a158..862a9a1 100644
--- a/frameworks/common/include/bms/bundle_info_query.h
+++ b/frameworks/common/include/bms/bundle_info_query.h
@@ -19,11 +19,15 @@
namespace OHOS {
namespace AppDomainVerify {
+using Want = OHOS::AAFwk::Want;
+using AbilityInfo = OHOS::AppExecFwk::AbilityInfo;
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(const int uid, std::string& bundleName);
+ static bool QueryAbilityInfosByUrl(const std::string& url, std::vector<AbilityInfo>& abilityInfos);
+ static bool GetBundleNameSelf(std::string& bundleName);
private:
static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
static int32_t GetCurrentAccountId();
diff --git a/frameworks/common/src/bms/bundle_info_query.cpp b/frameworks/common/src/bms/bundle_info_query.cpp
index 667d15c..394064c 100644
--- a/frameworks/common/src/bms/bundle_info_query.cpp
+++ b/frameworks/common/src/bms/bundle_info_query.cpp
@@ -22,13 +22,14 @@
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,120 @@ 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;
+ }
+
+ OHOS::AppExecFwk::BundleInfo bundleInfo;
+ auto ret = bundleMgrProxy->GetBundleNameForUid(uid, bundleName);
+ if (ret != ERR_OK) {
+ 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::GetBundleNameSelf(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;
+ }
+
+ OHOS::AppExecFwk::BundleInfo bundleInfo;
+ auto ret = bundleMgrProxy->GetBundleInfoForSelf(0, bundleInfo);
+ if (ret != ERR_OK) {
+ APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
+ return false;
+ }
+ bundleName = bundleInfo.name;
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "call end");
+ return true;
+}
+bool BundleInfoQuery::QueryAbilityInfosByUrl(const std::string& url, 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;
+ }
+ Want want;
+ want.SetUri(url);
+ OHOS::AppExecFwk::BundleInfo bundleInfo;
+ auto ret = bundleMgrProxy->QueryAbilityInfosV9(
+ want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_DEFAULT, 0, abilityInfos);
+ if (ret != ERR_OK) {
+ 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;
+}
+
}
}
\ No newline at end of file
diff --git a/interfaces/inner_api/client/BUILD.gn b/interfaces/inner_api/client/BUILD.gn
index fb0566b..b9b44ff 100644
--- a/interfaces/inner_api/client/BUILD.gn
+++ b/interfaces/inner_api/client/BUILD.gn
@@ -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 = []
diff --git a/interfaces/inner_api/client/include/app_domain_verify_mgr_client.h b/interfaces/inner_api/client/include/app_domain_verify_mgr_client.h
index 6d6dc4d..1186d17 100644
--- a/interfaces/inner_api/client/include/app_domain_verify_mgr_client.h
+++ b/interfaces/inner_api/client/include/app_domain_verify_mgr_client.h
@@ -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
diff --git a/interfaces/inner_api/client/src/app_domain_verify_agent_client.cpp b/interfaces/inner_api/client/src/app_domain_verify_agent_client.cpp
index c7d37ef..15e9aa0 100644
--- a/interfaces/inner_api/client/src/app_domain_verify_agent_client.cpp
+++ b/interfaces/inner_api/client/src/app_domain_verify_agent_client.cpp
@@ -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());
}
diff --git a/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp b/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
index 91e1414..47d79db 100644
--- a/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
+++ b/interfaces/inner_api/client/src/app_domain_verify_mgr_client.cpp
@@ -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!");
@@ -302,6 +303,12 @@ int AppDomainVerifyMgrClient::QueryAssociatedDomains(const std::string& bundleNa
int AppDomainVerifyMgrClient::QueryAssociatedBundleNames(
const std::string& domain, std::vector<std::string>& bundleNames)
{
+
+
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink start");
+ std::string link;
+ GetDeferredLink(link);
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "GetDeferredLink end, link %{public}s", link.c_str());
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "called");
std::lock_guard<std::mutex> autoLock(proxyLock_);
if (IsServiceAvailable()) {
@@ -310,6 +317,23 @@ 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::string bundleName;
+
+ if(!BundleInfoQuery::GetBundleNameSelf(bundleName)){
+ APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "can not get bundleName");
+ return CommonErrorCode::E_INTERNAL_ERR;
+ }
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "bundleInfo %{public}s", bundleName.c_str());
+ std::lock_guard<std::mutex> autoLock(proxyLock_);
+ if (IsServiceAvailable()) {
+ return appDomainVerifyMgrServiceProxy_->GetDeferredLink(bundleName, link);
+ }
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
+ return CommonErrorCode::E_INTERNAL_ERR;
+}
AppDomainVerifyMgrSaDeathRecipient::AppDomainVerifyMgrSaDeathRecipient()
{
}
diff --git a/interfaces/kits/js/src/app_domain_verify_manager_napi.cpp b/interfaces/kits/js/src/app_domain_verify_manager_napi.cpp
index 84753fd..7fdcf6c 100644
--- a/interfaces/kits/js/src/app_domain_verify_manager_napi.cpp
+++ b/interfaces/kits/js/src/app_domain_verify_manager_napi.cpp
@@ -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;
diff --git a/services/BUILD.gn b/services/BUILD.gn
index 2e20fa3..d42cf3f 100644
--- a/services/BUILD.gn
+++ b/services/BUILD.gn
@@ -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,12 @@ 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/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 +91,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",
diff --git a/services/include/manager/core/app_domain_verify_data_mgr.h b/services/include/manager/core/app_domain_verify_data_mgr.h
index ec0e7fe..8c683b6 100644
--- a/services/include/manager/core/app_domain_verify_data_mgr.h
+++ b/services/include/manager/core/app_domain_verify_data_mgr.h
@@ -33,7 +33,7 @@ public:
virtual ~AppDomainVerifyDataMgr();
/**
- * @brief Get AppDomainVerify status.
+ * @brief GetDeferredLink AppDomainVerify status.
* @param bundleName Indicates the bundleName.
* @param verifyResultInfo output value.
* @return Returns true if this function is successfully called; returns false
@@ -68,7 +68,7 @@ public:
bool DeleteVerifyStatus(const std::string& bundleName);
/**
- * @brief Get all AppDomainVerify status.
+ * @brief GetDeferredLink all AppDomainVerify status.
* @return Returns verifyMap_ const ref
* otherwise.
*/
diff --git a/services/include/manager/core/app_domain_verify_mgr_interface_code.h b/services/include/manager/core/app_domain_verify_mgr_interface_code.h
index b47a96b..00a3c7a 100644
--- a/services/include/manager/core/app_domain_verify_mgr_interface_code.h
+++ b/services/include/manager/core/app_domain_verify_mgr_interface_code.h
@@ -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
diff --git a/services/include/manager/core/app_domain_verify_mgr_service.h b/services/include/manager/core/app_domain_verify_mgr_service.h
index 6465dc7..e742d9a 100644
--- a/services/include/manager/core/app_domain_verify_mgr_service.h
+++ b/services/include/manager/core/app_domain_verify_mgr_service.h
@@ -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(const std::string& bundleName, std::string& link) override;
protected:
void OnDump() override;
@@ -69,6 +71,7 @@ private:
bool InitConfigMgr();
std::shared_ptr<WhiteListConfigMgr> whiteListConfigMgr_;
std::mutex initConfigMutex_;
+ std::shared_ptr<DeferredLinkMgr> deferredLinkMgr_;
};
} // namespace AppDomainVerify
} // namespace OHOS
diff --git a/services/include/manager/core/i_app_domain_verify_mgr_service.h b/services/include/manager/core/i_app_domain_verify_mgr_service.h
index 4ece0a7..46ec1ae 100644
--- a/services/include/manager/core/i_app_domain_verify_mgr_service.h
+++ b/services/include/manager/core/i_app_domain_verify_mgr_service.h
@@ -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(const std::string& bundleName, std::string& link) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appDomainVerify.IAppDomainVerifyMgrService");
};
} // namespace AppDomainVerify
diff --git a/services/include/manager/deferred_link/deferred_link_mgr.h b/services/include/manager/deferred_link/deferred_link_mgr.h
new file mode 100644
index 0000000..9bb9363
--- /dev/null
+++ b/services/include/manager/deferred_link/deferred_link_mgr.h
@@ -0,0 +1,60 @@
+//
+// Created by w00373214 on 10/21/24.
+//
+
+#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 "bundle_info_query.h"
+
+namespace OHOS::AppDomainVerify {
+
+struct DeferredLinkInfo {
+ std::string domain;
+ std::string url;
+ int64_t timeStamp;
+};
+/**
+ * PutDeferredLink
+ * @descrition put deferred link info
+ * @param domain the domain of url.
+ * @param url the url to open.
+ */
+class DeferredLinkMgr {
+public:
+ DeferredLinkMgr() = default;
+ /**
+ * PutDeferredLink
+ * @descrition put deferred link info
+ * @param domain the domain of url.
+ * @param url the url to open.
+ */
+ void PutDeferredLink(const DeferredLinkInfo& info);
+ /**
+ * GetDeferredLink
+ * @descrition get deferred link within domains
+ * @param domains the domains to filter link info.
+ * @return url the deferred url to open.
+ */
+ std::string GetDeferredLink(const std::vector<std::string>& domains);
+
+ ~DeferredLinkMgr();
+
+private:
+ static bool CanMatchAbility(const std::string& url);
+ void PostAgeTask();
+ void AgeCacheProcess();
+ std::list<DeferredLinkInfo> caches;
+ std::mutex mutex_;
+ std::shared_ptr<AppExecFwk::EventHandler> ageHandler_;
+ std::shared_ptr<AppExecFwk::EventRunner> ageRunner_;
+};
+}
+#endif // APP_DOMAIN_VERIFY_DEFERRED_LINK_MGR_H
diff --git a/services/include/manager/zidl/app_domain_verify_mgr_service_proxy.h b/services/include/manager/zidl/app_domain_verify_mgr_service_proxy.h
index dfbf2ae..264ee94 100644
--- a/services/include/manager/zidl/app_domain_verify_mgr_service_proxy.h
+++ b/services/include/manager/zidl/app_domain_verify_mgr_service_proxy.h
@@ -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(const std::string& bundleName, std::string& link) override;
private:
static inline BrokerDelegator<AppDomainVerifyMgrServiceProxy> delegator_;
};
diff --git a/services/include/manager/zidl/app_domain_verify_mgr_service_stub.h b/services/include/manager/zidl/app_domain_verify_mgr_service_stub.h
index 0667ae1..6a481ed 100644
--- a/services/include/manager/zidl/app_domain_verify_mgr_service_stub.h
+++ b/services/include/manager/zidl/app_domain_verify_mgr_service_stub.h
@@ -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
diff --git a/services/src/manager/core/app_domain_verify_mgr_service.cpp b/services/src/manager/core/app_domain_verify_mgr_service.cpp
index d182734..f3b863d 100644
--- a/services/src/manager/core/app_domain_verify_mgr_service.cpp
+++ b/services/src/manager/core/app_domain_verify_mgr_service.cpp
@@ -17,11 +17,15 @@
#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 "deferred_link_mgr.h"
+#include "uri.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 +80,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 +108,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()) {
+ deferredLinkMgr_->PutDeferredLink(
+ { .domain = hostVerifyKey, .url = uriString, .timeStamp = GetSecondsSince1970ToNow() });
+ }
APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call end");
return true;
}
@@ -270,8 +278,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,8 +330,26 @@ 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(const std::string& bundleName, std::string& link)
+{
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called");
+ if (!PermissionManager::IsSACall()) {
+ std::vector<std::string> domains;
+ if (dataManager_->QueryAssociatedDomains(bundleName, domains)) {
+ link = deferredLinkMgr_->GetDeferredLink(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_INTERNAL_ERR;
+ }
+ } else {
+ APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "no support no app call.");
+ return CommonErrorCode::E_PERMISSION_DENIED;
}
}
} // namespace AppDomainVerify
diff --git a/services/src/manager/deferred_link/deferred_link_mgr.cpp b/services/src/manager/deferred_link/deferred_link_mgr.cpp
new file mode 100644
index 0000000..76e92d4
--- /dev/null
+++ b/services/src/manager/deferred_link/deferred_link_mgr.cpp
@@ -0,0 +1,95 @@
+//
+// Created by w00373214 on 10/23/24.
+//
+#include "deferred_link_mgr.h"
+
+namespace OHOS::AppDomainVerify {
+namespace {
+constexpr const char* TASK_ID = "age";
+constexpr int32_t DELAY_TIME = 120000; // 2min
+constexpr int64_t MAX_CACHE_TIME = 1200000; // 10min
+constexpr int MAX_SIZE = 50;
+}
+void DeferredLinkMgr::PutDeferredLink(const DeferredLinkInfo& info)
+{
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
+ std::unique_lock<std::mutex> lock(mutex_);
+ if (caches.size() == MAX_SIZE) {
+ caches.pop_back();
+ }
+ caches.push_front(info);
+ if (caches.size() == 1) {
+ PostAgeTask();
+ }
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "info domain:%{private}s, url:%{private}s.",
+ info.domain.c_str(), info.url.c_str());
+}
+/**
+ * GetDeferredLink
+ * @descrition get deferred link within domains
+ * @param domains the domains to filter link info.
+ * @return url the deferred url to open.
+ */
+std::string DeferredLinkMgr::GetDeferredLink(const std::vector<std::string>& domains)
+{
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called.");
+ std::string result;
+ std::set<std::string> domainSet(domains.begin(), domains.end());
+ std::unique_lock<std::mutex> lock(mutex_);
+ auto target = std::find_if(caches.cbegin(), caches.cend(), [&domainSet](const DeferredLinkInfo& linkInfo) {
+ Uri uri(linkInfo.url);
+ if (domainSet.count(uri.GetScheme() + "://" + uri.GetHost()) != 0 && CanMatchAbility(linkInfo.url)) {
+ APP_DOMAIN_VERIFY_HILOGI(
+ APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "find target url:%{private}s", linkInfo.url.c_str());
+ return true;
+ }
+ return false;
+ });
+ if (target != caches.end()) {
+ result = target->url;
+ caches.erase(target);
+ return result;
+ }
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get deferred url:%{private}s", result.c_str());
+ return result;
+}
+
+DeferredLinkMgr::~DeferredLinkMgr()
+{
+}
+
+bool DeferredLinkMgr::CanMatchAbility(const std::string& url)
+{
+ bool result{ false };
+ std::vector<AbilityInfo> abilityInfos;
+ if (BundleInfoQuery::QueryAbilityInfosByUrl(url, abilityInfos)) {
+ for (const auto& ability : abilityInfos) {
+ APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE,
+ "QueryAbilityInfosByUrl name:%{private}s,bundle name:%{private}s.", ability.name.c_str(),
+ ability.bundleName.c_str());
+ }
+ result = true;
+ }
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "CanMatchAbility %{public}d.", result);
+ return result;
+}
+void DeferredLinkMgr::PostAgeTask()
+{
+ if (ageHandler_) {
+ 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(mutex_);
+ 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.");
+ PostAgeTask();
+ } else {
+ APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "age task end.");
+ }
+}
+}
\ No newline at end of file
diff --git a/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp b/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
index 5bf6f17..b991d8d 100644
--- a/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
+++ b/services/src/manager/zidl/app_domain_verify_mgr_service_proxy.cpp
@@ -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,29 @@ int AppDomainVerifyMgrServiceProxy::QueryAssociatedBundleNames(
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_CLIENT, "call end");
return result;
}
+int AppDomainVerifyMgrServiceProxy::GetDeferredLink(const std::string& bundleName, 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());
+ WRITE_PARCEL_AND_RETURN_INT_IF_FAIL(String, data, bundleName);
+
+ 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, "QueryAssociatedBundleNames 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
diff --git a/services/src/manager/zidl/app_domain_verify_mgr_service_stub.cpp b/services/src/manager/zidl/app_domain_verify_mgr_service_stub.cpp
index 8bfd001..ad2f964 100644
--- a/services/src/manager/zidl/app_domain_verify_mgr_service_stub.cpp
+++ b/services/src/manager/zidl/app_domain_verify_mgr_service_stub.cpp
@@ -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,19 @@ 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 bundleName;
+ READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, data, bundleName);
+
+ std::string link;
+ int ret = GetDeferredLink(bundleName, 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
\ No newline at end of file
diff --git a/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
new file mode 100644
index 0000000..5941372
--- /dev/null
+++ b/test/unittest/services/deferred_link_test/deferred_link_mgr_test.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "gtest/gtest.h"
+#include "mock_constant.h"
+#define private public
+#define protected public
+#include "deferred_link_mgr.h"
+#undef private
+#undef protected
+namespace OHOS::AppDomainVerify {
+using namespace testing;
+using namespace testing::ext;
+
+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: RdbOpenCallbackTest001
+ * @tc.desc: Callback test
+ * @tc.type: FUNC
+ */
+HWTEST_F(DeferredLinkMgrTest, RdbOpenCallbackTest001, TestSize.Level0)
+{
+ DeferredLinkMgr deferredLinkMgr;
+ deferredLinkMgr.PutDeferredLink();
+ deferredLinkMgr.GetDeferredLink();
+}
+
+}
\ No newline at end of file
--
2.25.1
@@ -37,22 +37,22 @@ napi_value QueryAssociatedDomains(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string bundleName = GetString(env, args[0]);
if (!CheckInput(bundleName)) {
reporter.WriteEndEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
reporter.SetEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
return BuildError(env, CommonErrorCode::E_PARAM_ERROR, ErrCodeMap[CommonErrorCode::E_PARAM_ERROR]);
}
std::vector<std::string> domains;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedDomains(bundleName, domains);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<CommonErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
reporter.SetEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
return BuildError(env, static_cast<CommonErrorCode>(ret), ErrCodeMap[static_cast<CommonErrorCode>(ret)]);
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(API_FAIL, ret);
reporter.SetEvent(API_FAIL, ret);
return BuildStringArray(env, domains);
}
}
reporter.WriteEndEvent(API_SUCCESS, ret);
reporter.SetEvent(API_SUCCESS, ret);
return BuildStringArray(env, domains);
}
napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
@@ -64,22 +64,22 @@ napi_value QueryAssociatedBundleNames(napi_env env, napi_callback_info info)
NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), nullptr);
std::string domain = GetString(env, args[0]);
if (!CheckInput(domain)) {
reporter.WriteEndEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
reporter.SetEvent(API_FAIL, CommonErrorCode::E_PARAM_ERROR);
return BuildError(env, CommonErrorCode::E_PARAM_ERROR, ErrCodeMap[CommonErrorCode::E_PARAM_ERROR]);
}
std::vector<std::string> bundleNames;
auto ret = AppDomainVerifyMgrClient::GetInstance()->QueryAssociatedBundleNames(domain, bundleNames);
if (ret != 0) {
if (ErrCodeMap.count(static_cast<CommonErrorCode>(ret)) != 0) {
reporter.WriteEndEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
reporter.SetEvent(API_FAIL, static_cast<CommonErrorCode>(ret));
return BuildError(env, static_cast<CommonErrorCode>(ret), ErrCodeMap[static_cast<CommonErrorCode>(ret)]);
} else {
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "unknown error:%{public}d.", ret);
reporter.WriteEndEvent(API_FAIL, ret);
reporter.SetEvent(API_FAIL, ret);
return BuildStringArray(env, bundleNames);
}
}
reporter.WriteEndEvent(API_SUCCESS, ret);
reporter.SetEvent(API_SUCCESS, ret);
return BuildStringArray(env, bundleNames);
}
}
@@ -68,6 +68,7 @@ void GetDeferredLinkComplete(napi_env env, napi_status status, void* data)
NAPI_CALL_RETURN_VOID(env, napi_get_null(env, &result[0]));
result[ARGS_SIZE_ONE] = BuildString(env, asyncCallbackInfo->deferred_link);
} else {
asyncCallbackInfo->apiReporter->SetEvent(API_FAIL, CommonErrorCode::E_INTERNAL_ERR);
result[0] = BuildError(env, CommonErrorCode::E_INTERNAL_ERR, g_ErrCodeMap[CommonErrorCode::E_INTERNAL_ERR]);
}
if (asyncCallbackInfo->deferred) {
@@ -85,7 +86,7 @@ void GetDeferredLinkComplete(napi_env env, napi_status status, void* data)
NAPI_CALL_RETURN_VOID(
env, napi_call_function(env, nullptr, callback, sizeof(result) / sizeof(result[0]), result, &placeHolder));
}
callbackPtr->apiReporter->WriteEndEvent(API_SUCCESS, asyncCallbackInfo->err);
callbackPtr->apiReporter->SetEvent(API_SUCCESS, asyncCallbackInfo->err);
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called end");
}
@@ -22,16 +22,19 @@ constexpr int32_t API_FAIL = 1;
class ApiEventReporter {
public:
explicit ApiEventReporter(const std::string& apiName);
~ApiEventReporter() = default;
void WriteEndEvent(const int result, const int32_t errCode);
~ApiEventReporter();
void SetEvent(const int result, const int32_t errCode);
private:
void WriteEndEvent(const int result, const int32_t errCode);
int64_t AddProcessor();
private:
std::string transId_;
std::string apiName_;
int64_t startTime_;
int result_{ API_FAIL };
int32_t errCode_{ -1 };
};
}
#endif // APP_DOMAIN_VERIFY_MANAGER_API_EVENT_REPORTER_H
@@ -104,4 +104,13 @@ void ApiEventReporter::WriteEndEvent(const int result, const int32_t errCode)
"errCode:%{public}d, ret:%{public}d",
transId_.c_str(), apiName_.c_str(), SDK_NAME.c_str(), result, errCode, ret);
}
void ApiEventReporter::SetEvent(const int result, const int errCode)
{
result_ = result;
errCode_ = errCode;
}
ApiEventReporter::~ApiEventReporter()
{
WriteEndEvent(result_, errCode_);
}
}