Signed-off-by: zylworkhard1 <zhangyongliang21@huawei.com>
This commit is contained in:
zylworkhard1 2024-12-12 20:04:32 +08:00
parent 4d9f5c7d73
commit 60fb33c52f
4 changed files with 36 additions and 21 deletions

View File

@ -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<LruCacheUtil<std::string, std::string>> lruCache_;
std::shared_ptr<AppDetailsRdbDataMgr> rdbMgr_;

View File

@ -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::seconds>(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<AppDetailsRdbItem> 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;
};

View File

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

View File

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