From 60fb33c52f359f9b0ed2fe4aeedf3fab8c6960cd Mon Sep 17 00:00:00 2001 From: zylworkhard1 Date: Thu, 12 Dec 2024 20:04:32 +0800 Subject: [PATCH] bugfix Signed-off-by: zylworkhard1 --- .../manager/core/app_details_data_mgr.h | 6 +-- .../src/manager/core/app_details_data_mgr.cpp | 38 +++++++++++-------- .../core/app_domain_verify_data_mgr.cpp | 2 +- .../core/app_domain_verify_mgr_service.cpp | 11 +++++- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/services/include/manager/core/app_details_data_mgr.h b/services/include/manager/core/app_details_data_mgr.h index 8c7b032..c7a58b0 100644 --- a/services/include/manager/core/app_details_data_mgr.h +++ b/services/include/manager/core/app_details_data_mgr.h @@ -36,10 +36,10 @@ class AppDetailsDataMgr { public: AppDetailsDataMgr(); virtual ~AppDetailsDataMgr(); - int QueryAppDetailsWant(const std::string& url, AAFwk::Want& want); + int QueryAppDetailsWant(const std::string& url, AAFwk::Want& want, std::string& bundleName); private: - bool QueryAppDetailsWantByCache(const std::string& url, AAFwk::Want& want); - bool QueryAppDetailsWantByRdb(const std::string& url, AAFwk::Want& want); + bool QueryAppDetailsWantByCache(const std::string& url, std::string& bundleName); + bool QueryAppDetailsWantByRdb(const std::string& url, std::string& bundleName); void AddInfoToWant(AAFwk::Want& want, const std::string& bundleName); std::shared_ptr> lruCache_; std::shared_ptr rdbMgr_; diff --git a/services/src/manager/core/app_details_data_mgr.cpp b/services/src/manager/core/app_details_data_mgr.cpp index 640dec2..87720b6 100644 --- a/services/src/manager/core/app_details_data_mgr.cpp +++ b/services/src/manager/core/app_details_data_mgr.cpp @@ -33,7 +33,7 @@ namespace OHOS { namespace AppDomainVerify { -const static std::string OHOS_WANT_ACTION_APPDETAILS = "ohos.want.action.appdetails"; +const static std::string OHOS_WANT_ACTION_APPDETAILS = "ohos.want.action.appdetail"; const static int64_t CACHE_TIME_S = 300; const static int MAX_CACHE_CNT = 10; AppDetailsDataMgr::AppDetailsDataMgr() @@ -45,22 +45,28 @@ AppDetailsDataMgr::AppDetailsDataMgr() AppDetailsDataMgr::~AppDetailsDataMgr() {}; -int AppDetailsDataMgr::QueryAppDetailsWant(const std::string &url, AAFwk::Want& want) +int AppDetailsDataMgr::QueryAppDetailsWant(const std::string &url, AAFwk::Want& want, std::string& bundleName) { APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "call, url:%{private}s", url.c_str()); - if (QueryAppDetailsWantByCache(url, want)) { - APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from cache"); - return QUERY_SUCC; - } - if (QueryAppDetailsWantByRdb(url, want)) { - APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from rdb"); - return QUERY_SUCC; - } - APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query fail."); - return QUERY_FAIL; + std::string bundleNameQuery; + do { + if (QueryAppDetailsWantByCache(url, bundleNameQuery)) { + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from cache"); + break; + } + if (QueryAppDetailsWantByRdb(url, bundleNameQuery)) { + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query success from rdb"); + break; + } + APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "query fail."); + return QUERY_FAIL; + } while (false); + AddInfoToWant(want, bundleNameQuery); + bundleName = bundleNameQuery; + return QUERY_SUCC; }; -bool AppDetailsDataMgr::QueryAppDetailsWantByCache(const std::string& url, AAFwk::Want& want) +bool AppDetailsDataMgr::QueryAppDetailsWantByCache(const std::string& url, std::string& bundleName) { int64_t currTime = std::chrono::time_point_cast(std::chrono::system_clock::now()) .time_since_epoch() @@ -72,13 +78,13 @@ bool AppDetailsDataMgr::QueryAppDetailsWantByCache(const std::string& url, AAFwk } std::string value; if (lruCache_->Get(url, value)) { - AddInfoToWant(want, value); + bundleName = value; return true; } return false; }; -bool AppDetailsDataMgr::QueryAppDetailsWantByRdb(const std::string& url, AAFwk::Want& want) +bool AppDetailsDataMgr::QueryAppDetailsWantByRdb(const std::string& url, std::string& bundleName) { std::vector rdbDetails; std::string domain = UrlUtil::GetHost(url); @@ -107,7 +113,7 @@ bool AppDetailsDataMgr::QueryAppDetailsWantByRdb(const std::string& url, AAFwk:: if (!detailsFilter_->Filter(appDetails, appDetailsRet, url)) { return false; } - AddInfoToWant(want, appDetailsRet.front().bundleName); + bundleName = appDetailsRet.front().bundleName; lruCache_->Put(url, appDetailsRet.front().bundleName); return true; }; diff --git a/services/src/manager/core/app_domain_verify_data_mgr.cpp b/services/src/manager/core/app_domain_verify_data_mgr.cpp index 664ca78..788468d 100644 --- a/services/src/manager/core/app_domain_verify_data_mgr.cpp +++ b/services/src/manager/core/app_domain_verify_data_mgr.cpp @@ -51,7 +51,7 @@ bool AppDomainVerifyDataMgr::GetVerifyStatus(const std::string& bundleName, Veri return true; } APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "get verify status fail, verify result can't find"); - return true; + return false; } bool AppDomainVerifyDataMgr::VerifyResultInfoToDB( const std::string bundleName, const VerifyResultInfo& verifyResultInfo) 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 9f90585..ecc4c50 100644 --- a/services/src/manager/core/app_domain_verify_mgr_service.cpp +++ b/services/src/manager/core/app_domain_verify_mgr_service.cpp @@ -231,7 +231,16 @@ int AppDomainVerifyMgrService::QueryAssociatedBundleNames( int AppDomainVerifyMgrService::QueryAppDetailsWant(const std::string& url, AAFwk::Want& want) { APP_DOMAIN_VERIFY_HILOGI(APP_DOMAIN_VERIFY_MGR_MODULE_SERVICE, "called"); - return appDetailsDataMgr_->QueryAppDetailsWant(url, want); + std::string bundleName; + auto ret = appDetailsDataMgr_->QueryAppDetailsWant(url, want, bundleName); + if (ret == AppDetailsCode::QUERY_SUCC) { + VerifyResultInfo info; + if (dataManager_->GetVerifyStatus(bundleName, info)) { + return AppDetailsCode::QUERY_FAIL; + } + return AppDetailsCode::QUERY_SUCC; + } + return AppDetailsCode::QUERY_FAIL; } bool AppDomainVerifyMgrService::IsWantImplicit(const OHOS::AAFwk::Want& want)