From d213e9c593401b7876a0d1072ab1cfcaa7de2a4a Mon Sep 17 00:00:00 2001 From: zhangrn98 Date: Tue, 17 Mar 2026 15:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8AppVerifyBaseInfo=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0isPreinstalled=E5=AD=97=E6=AE=B5=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9BundleInfoQuery=EF=BC=8C=E4=BD=BF=E7=94=A8Get?= =?UTF-8?q?AllPreinstalledApplicationInfos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangrn98 --- .../common/src/bms/bundle_info_query.cpp | 28 +++++++++++-------- frameworks/verifier/src/domain_verifier.cpp | 11 +------- frameworks/verifier/src/verify_task.cpp | 4 +++ .../common/include/app_verify_base_info.h | 1 + .../common/src/app_verify_base_info.cpp | 4 +++ .../core/app_domain_verify_mgr_service.cpp | 4 +++ 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/frameworks/common/src/bms/bundle_info_query.cpp b/frameworks/common/src/bms/bundle_info_query.cpp index 2df7cdf..f0f0bde 100644 --- a/frameworks/common/src/bms/bundle_info_query.cpp +++ b/frameworks/common/src/bms/bundle_info_query.cpp @@ -184,22 +184,28 @@ bool BundleInfoQuery::IsPreInstalledApp(const std::string& bundleName) APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "bundleMgrProxy is nullptr."); return false; } - int32_t userId = BundleInfoQuery::GetCurrentAccountId(); - if (userId < 0) { - return false; - } - OHOS::AppExecFwk::BundleInfo bundleInfo; - // use sa identity + std::vector preinstalledApplicationInfos; std::string identity = IPCSkeleton::ResetCallingIdentity(); - auto ret = bundleMgrProxy->GetBundleInfoV9(bundleName, - static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO), bundleInfo, userId); + APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetAllPreinstalledApplicationInfos called"); + auto ret = bundleMgrProxy->GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos); + APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetAllPreinstalledApplicationInfos called end"); 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_HILOGE( + APP_DOMAIN_VERIFY_MODULE_COMMON, "GetAllPreinstalledApplicationInfos failed, ret: %{public}d.", ret); + return false; + } + auto it = find_if(preinstalledApplicationInfos.begin(), preinstalledApplicationInfos.end(), + [&](const AppExecFwk::PreinstalledApplicationInfo& obj) { return obj.bundleName == bundleName; }); + if (it != preinstalledApplicationInfos.end()) { + APP_DOMAIN_VERIFY_HILOGI( + APP_DOMAIN_VERIFY_MODULE_COMMON, "bundle:%{public}s isPreInstallApp:%{public}d", bundleName.c_str(), true); + return true; + } else { + APP_DOMAIN_VERIFY_HILOGI( + APP_DOMAIN_VERIFY_MODULE_COMMON, "bundle:%{public}s isPreInstallApp:%{public}d", bundleName.c_str(), false); return false; } - // Check if the app is pre-installed (system app) - return bundleInfo.isPreInstallApp; } } } \ No newline at end of file diff --git a/frameworks/verifier/src/domain_verifier.cpp b/frameworks/verifier/src/domain_verifier.cpp index 336f073..7d902da 100644 --- a/frameworks/verifier/src/domain_verifier.cpp +++ b/frameworks/verifier/src/domain_verifier.cpp @@ -16,7 +16,6 @@ #include "domain_verifier.h" #include "app_domain_verify_hilog.h" #include "domain_json_util.h" -#include "bundle_info_query.h" namespace OHOS { namespace AppDomainVerify { @@ -25,15 +24,7 @@ InnerVerifyStatus DomainVerifier::VerifyHost(OHOS::NetStack::HttpClient::Respons { APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called"); if (responseCode != OHOS::NetStack::HttpClient::ResponseCode::OK) { - InnerVerifyStatus status = GetVerifyStatusFromHttpError(responseCode); - if (status == InnerVerifyStatus::FAILURE_HTTP_UNKNOWN && - BundleInfoQuery::IsPreInstalledApp(appVerifyBaseInfo.bundleName)) { - APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, - "pre installed app, bundleName: %{public}s", appVerifyBaseInfo.bundleName.c_str()); - return InnerVerifyStatus::PRE_INSTALLED; - } else { - return status; - } + return GetVerifyStatusFromHttpError(responseCode); } AssetJsonObj assetJsonObj; if (JsonUtil::Parse(assetJsonsStr, assetJsonObj)) { diff --git a/frameworks/verifier/src/verify_task.cpp b/frameworks/verifier/src/verify_task.cpp index 978651f..3bc6b47 100644 --- a/frameworks/verifier/src/verify_task.cpp +++ b/frameworks/verifier/src/verify_task.cpp @@ -27,6 +27,7 @@ #include "domain_url_util.h" #include "app_domain_verify_task_mgr.h" #include "verify_http_task.h" +#include "bundle_info_query.h" namespace OHOS { namespace AppDomainVerify { @@ -43,6 +44,9 @@ void VerifyTask::OnPostVerify(const std::string& uri, const OHOS::NetStack::Http (appVerifyBaseInfo_.priority < PRIORITY_MIN || appVerifyBaseInfo_.priority > PRIORITY_MAX)) { status = InnerVerifyStatus::FAILURE_CLIENT_ERROR; } + if (status == InnerVerifyStatus::FAILURE_HTTP_UNKNOWN && appVerifyBaseInfo_.isPreinstalled) { + status = InnerVerifyStatus::PRE_INSTALLED; + } APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "OnPostVerify status %{public}d appId:%{public}s, priority:%{public}d", status, appVerifyBaseInfo_.appIdentifier.c_str(), appVerifyBaseInfo_.priority); diff --git a/interfaces/inner_api/common/include/app_verify_base_info.h b/interfaces/inner_api/common/include/app_verify_base_info.h index ed5d77d..a96313f 100644 --- a/interfaces/inner_api/common/include/app_verify_base_info.h +++ b/interfaces/inner_api/common/include/app_verify_base_info.h @@ -24,6 +24,7 @@ struct AppVerifyBaseInfo : public Parcelable { std::string bundleName{}; std::string fingerprint{}; int priority{}; + bool isPreinstalled{}; AppVerifyBaseInfo(); AppVerifyBaseInfo(const AppVerifyBaseInfo &appVerifyBaseInfo); diff --git a/interfaces/inner_api/common/src/app_verify_base_info.cpp b/interfaces/inner_api/common/src/app_verify_base_info.cpp index 76d79e8..486986c 100644 --- a/interfaces/inner_api/common/src/app_verify_base_info.cpp +++ b/interfaces/inner_api/common/src/app_verify_base_info.cpp @@ -25,6 +25,7 @@ AppVerifyBaseInfo::AppVerifyBaseInfo() bundleName = ""; fingerprint = ""; priority = PRIORITY_UNSET; + isPreinstalled = false; } AppVerifyBaseInfo::AppVerifyBaseInfo(const AppVerifyBaseInfo &appVerifyBaseInfo) @@ -33,6 +34,7 @@ AppVerifyBaseInfo::AppVerifyBaseInfo(const AppVerifyBaseInfo &appVerifyBaseInfo) bundleName = appVerifyBaseInfo.bundleName; fingerprint = appVerifyBaseInfo.fingerprint; priority = appVerifyBaseInfo.priority; + isPreinstalled = appVerifyBaseInfo.isPreinstalled; } bool AppVerifyBaseInfo::Marshalling(Parcel &parcel) const { @@ -40,6 +42,7 @@ bool AppVerifyBaseInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fingerprint); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, priority); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreinstalled); return true; } bool AppVerifyBaseInfo::ReadFromParcel(Parcel &parcel) @@ -48,6 +51,7 @@ bool AppVerifyBaseInfo::ReadFromParcel(Parcel &parcel) READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName); READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, fingerprint); READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, priority); + READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isPreinstalled); return true; } 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 3f3bc9b..2b3bcb7 100644 --- a/services/src/manager/core/app_domain_verify_mgr_service.cpp +++ b/services/src/manager/core/app_domain_verify_mgr_service.cpp @@ -97,6 +97,10 @@ void AppDomainVerifyMgrService::VerifyDomain(const std::string& appIdentifier, c VerifyResultInfo verifyResultInfo; verifyResultInfo.appIdentifier = appIdentifier; + // Check if app is pre-installed + bool isPreInstalled = BundleInfoQuery::IsPreInstalledApp(bundleName); + appVerifyBaseInfo.isPreinstalled = isPreInstalled; + CollectDomains(skillUris, verifyResultInfo); DelayedSingleton::GetInstance()->InsertVerifyStatus(bundleName, verifyResultInfo); AppDomainVerifyAgentClient::GetInstance()->SingleVerify(appVerifyBaseInfo, verifyResultInfo);