From e581d40017d2b3e9c3cab554389aa63ddc101d59 Mon Sep 17 00:00:00 2001 From: chenwei Date: Tue, 28 May 2024 10:55:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A9=E5=B1=95=E8=8E=B7=E5=8F=96appIndex?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E9=9D=9E=E5=8A=A0=E9=94=81=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenwei --- services/bundlemgr/include/bundle_data_mgr.h | 1 + services/bundlemgr/src/bundle_data_mgr.cpp | 44 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index 64c1b2126..4faa8b586 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -1005,6 +1005,7 @@ private: bool MatchUtd(const Skill &skill, const std::string &utd, int32_t count) const; bool MatchUtd(const std::string &skillUtd, const std::string &wantUtd) const; bool MatchTypeWithUtd(const std::string &mimeType, const std::string &wantUtd) const; + std::vector GetCloneAppIndexesUnLock(const std::string &bundleName, int32_t userId) const; #ifdef GLOBAL_RESMGR_ENABLE std::shared_ptr GetResourceManager(const std::string &bundleName, const std::string &moduleName, int32_t userId, const std::string &localeInfo = Constants::EMPTY_STRING) const; diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 4b35ed67f..2bc6c0fcb 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -1211,7 +1211,7 @@ bool BundleDataMgr::ImplicitQueryCurCloneAbilityInfos(const Want &want, int32_t { LOG_D(BMS_TAG_QUERY_ABILITY, "begin ImplicitQueryCurCloneAbilityInfos."); std::string bundleName = want.GetElement().GetBundleName(); - std::vector cloneAppIndexes = GetCloneAppIndexes(bundleName, userId); + std::vector cloneAppIndexes = GetCloneAppIndexesUnLock(bundleName, userId); if (cloneAppIndexes.empty()) { return false; } @@ -1266,7 +1266,7 @@ bool BundleDataMgr::ImplicitQueryCurCloneAbilityInfosV9(const Want &want, int32_ LOG_D(BMS_TAG_QUERY_ABILITY, "begin ImplicitQueryCurCloneAbilityInfosV9."); std::string bundleName = want.GetElement().GetBundleName(); - std::vector cloneAppIndexes = GetCloneAppIndexes(bundleName, userId); + std::vector cloneAppIndexes = GetCloneAppIndexesUnLock(bundleName, userId); if (cloneAppIndexes.empty()) { return false; } @@ -1349,7 +1349,7 @@ void BundleDataMgr::ImplicitQueryAllCloneAbilityInfos(const Want &want, int32_t for (const auto &item : bundleInfos_) { const InnerBundleInfo &innerBundleInfo = item.second; - std::vector cloneAppIndexes = GetCloneAppIndexes(innerBundleInfo.GetBundleName(), userId); + std::vector cloneAppIndexes = GetCloneAppIndexesUnLock(innerBundleInfo.GetBundleName(), userId); if (cloneAppIndexes.empty()) { continue; } @@ -1416,7 +1416,7 @@ void BundleDataMgr::ImplicitQueryAllCloneAbilityInfosV9(const Want &want, int32_ { LOG_D(BMS_TAG_QUERY_ABILITY, "begin ImplicitQueryAllCloneAbilityInfosV9."); for (const auto &item : bundleInfos_) { - std::vector cloneAppIndexes = GetCloneAppIndexes(item.second.GetBundleName(), userId); + std::vector cloneAppIndexes = GetCloneAppIndexesUnLock(item.second.GetBundleName(), userId); if (cloneAppIndexes.empty()) { continue; } @@ -1922,6 +1922,42 @@ std::vector BundleDataMgr::GetCloneAppIndexes(const std::string &bundle return cloneAppIndexes; } +std::vector BundleDataMgr::GetCloneAppIndexesUnLock(const std::string &bundleName, int32_t userId) const +{ + std::vector cloneAppIndexes; + std::vector innerBundleUserInfos; + if (userId == Constants::UNSPECIFIED_USERID) { + if (!GetInnerBundleUserInfos(bundleName, innerBundleUserInfos)) { + LOG_W(BMS_TAG_QUERY_BUNDLE, "no userInfos for this bundle(%{public}s)", bundleName.c_str()); + return cloneAppIndexes; + } + userId = innerBundleUserInfos.begin()->bundleUserInfo.userId; + } + int32_t requestUserId = GetUserId(userId); + if (requestUserId == Constants::INVALID_USERID) { + return cloneAppIndexes; + } + auto infoItem = bundleInfos_.find(bundleName); + if (infoItem == bundleInfos_.end()) { + LOG_W(BMS_TAG_QUERY_ABILITY, "no bundleName %{public}s found", bundleName.c_str()); + return cloneAppIndexes; + } + const InnerBundleInfo &bundleInfo = infoItem->second; + InnerBundleUserInfo innerBundleUserInfo; + if (!bundleInfo.GetInnerBundleUserInfo(requestUserId, innerBundleUserInfo)) { + return cloneAppIndexes; + } + const std::map &cloneInfos = innerBundleUserInfo.cloneInfos; + if (cloneInfos.empty()) { + return cloneAppIndexes; + } + for (const auto &cloneInfo : cloneInfos) { + LOG_I(BMS_TAG_QUERY_ABILITY, "get cloneAppIndexes unLock: %{public}d", cloneInfo.second.appIndex); + cloneAppIndexes.emplace_back(cloneInfo.second.appIndex); + } + return cloneAppIndexes; +} + void BundleDataMgr::AddAppDetailAbilityInfo(InnerBundleInfo &info) const { AbilityInfo appDetailAbility;