From 5a8b735563091cb23d6e36b4d9aaba3b36f01165 Mon Sep 17 00:00:00 2001 From: zhangxinyu Date: Thu, 3 Aug 2023 12:02:47 +0000 Subject: [PATCH] =?UTF-8?q?GetAbilityLabel=E5=8F=AF=E6=9F=A5=E8=AF=A20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=8B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangxinyu Change-Id: Iba17aeb154611b787d112284101326d29d285363 --- services/bundlemgr/include/bundle_data_mgr.h | 2 + services/bundlemgr/src/bundle_data_mgr.cpp | 72 ++++++++++++-------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index e5d6edca6e..12b351940a 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -971,6 +971,8 @@ private: void ResetExternalOverlayModuleState(const std::string &bundleName, const std::string &modulePackage); void BuildExternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); void RemoveOverlayInfoAndConnection(const InnerBundleInfo &innerBundleInfo, const std::string &bundleName); + ErrCode FindAbilityInfoInBundleInfo(const InnerBundleInfo &innerBundleInfo, const std::string &moduleName, + const std::string &abilityName, AbilityInfo &abilityInfo) const; private: mutable std::mutex bundleInfoMutex_; diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 6c90b33d32..791f6b7a5e 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -2305,28 +2305,26 @@ ErrCode BundleDataMgr::GetAbilityLabel(const std::string &bundleName, const std: { #ifdef GLOBAL_RESMGR_ENABLE std::lock_guard lock(bundleInfoMutex_); + int32_t requestUserId = GetUserId(); + if (requestUserId == Constants::INVALID_USERID) { + return ERR_BUNDLE_MANAGER_INVALID_USER_ID; + } InnerBundleInfo innerBundleInfo; ErrCode ret = - GetInnerBundleInfoWithFlagsV9(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, innerBundleInfo, GetUserId()); + GetInnerBundleInfoWithFlagsV9(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, innerBundleInfo, requestUserId); if (ret != ERR_OK) { return ret; } AbilityInfo abilityInfo; - if (moduleName.empty()) { - auto ability = innerBundleInfo.FindAbilityInfoV9(moduleName, abilityName); - if (!ability) { - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - abilityInfo = *ability; - } else { - ret = innerBundleInfo.FindAbilityInfo(moduleName, abilityName, abilityInfo); - if (ret != ERR_OK) { - APP_LOGE("%{public}s:FindAbilityInfo failed: %{public}d", bundleName.c_str(), ret); - return ret; - } + ret = FindAbilityInfoInBundleInfo(innerBundleInfo, moduleName, abilityName, abilityInfo); + if (ret != ERR_OK) { + APP_LOGE("Find ability failed. bundleName: %{public}s, moduleName: %{public}s, abilityName: %{public}s", + bundleName.c_str(), moduleName.c_str(), abilityName.c_str()); + return ret; } + int32_t responseUserId = innerBundleInfo.GetResponseUserId(requestUserId); bool isEnable = false; - ret = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, GetUserId(), isEnable); + ret = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, responseUserId, isEnable); if (ret != ERR_OK) { return ret; } @@ -2339,7 +2337,7 @@ ErrCode BundleDataMgr::GetAbilityLabel(const std::string &bundleName, const std: return ERR_OK; } std::shared_ptr resourceManager = - GetResourceManager(bundleName, abilityInfo.moduleName, GetUserId()); + GetResourceManager(bundleName, abilityInfo.moduleName, responseUserId); if (resourceManager == nullptr) { APP_LOGE("InitResourceManager failed"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; @@ -4520,27 +4518,24 @@ ErrCode BundleDataMgr::GetMediaData(const std::string &bundleName, const std::st APP_LOGI("begin to GetMediaData."); #ifdef GLOBAL_RESMGR_ENABLE std::lock_guard lock(bundleInfoMutex_); + int32_t requestUserId = GetUserId(userId); + if (requestUserId == Constants::INVALID_USERID) { + return ERR_BUNDLE_MANAGER_INVALID_USER_ID; + } InnerBundleInfo innerBundleInfo; ErrCode errCode = GetInnerBundleInfoWithFlagsV9( - bundleName, BundleFlag::GET_BUNDLE_DEFAULT, innerBundleInfo, GetUserId(userId)); + bundleName, BundleFlag::GET_BUNDLE_DEFAULT, innerBundleInfo, requestUserId); if (errCode != ERR_OK) { return errCode; } AbilityInfo abilityInfo; - if (moduleName.empty()) { - auto ability = innerBundleInfo.FindAbilityInfoV9(moduleName, abilityName); - if (!ability) { - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - abilityInfo = *ability; - } else { - errCode = innerBundleInfo.FindAbilityInfo(moduleName, abilityName, abilityInfo); - if (errCode != ERR_OK) { - return errCode; - } + errCode = FindAbilityInfoInBundleInfo(innerBundleInfo, moduleName, abilityName, abilityInfo); + if (errCode != ERR_OK) { + return errCode; } bool isEnable; - errCode = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, GetUserId(userId), isEnable); + int32_t responseUserId = innerBundleInfo.GetResponseUserId(requestUserId); + errCode = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, responseUserId, isEnable); if (errCode != ERR_OK) { return errCode; } @@ -4549,7 +4544,7 @@ ErrCode BundleDataMgr::GetMediaData(const std::string &bundleName, const std::st return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; } std::shared_ptr resourceManager = - GetResourceManager(bundleName, abilityInfo.moduleName, GetUserId(userId)); + GetResourceManager(bundleName, abilityInfo.moduleName, responseUserId); if (resourceManager == nullptr) { APP_LOGE("InitResourceManager failed, bundleName:%{public}s", bundleName.c_str()); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; @@ -5399,6 +5394,25 @@ ErrCode BundleDataMgr::GetBundleInfoFromBmsExtension(const std::string &bundleNa return ERR_OK; } +ErrCode BundleDataMgr::FindAbilityInfoInBundleInfo(const InnerBundleInfo &innerBundleInfo, + const std::string &moduleName, const std::string &abilityName, AbilityInfo &abilityInfo) const +{ + if (moduleName.empty()) { + auto ability = innerBundleInfo.FindAbilityInfoV9(moduleName, abilityName); + if (!ability) { + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + abilityInfo = *ability; + return ERR_OK; + } + + ErrCode ret = innerBundleInfo.FindAbilityInfo(moduleName, abilityName, abilityInfo); + if (ret != ERR_OK) { + APP_LOGE("%{public}s:FindAbilityInfo failed: %{public}d", innerBundleInfo.GetBundleName().c_str(), ret); + } + return ret; +} + #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION bool BundleDataMgr::UpdateOverlayInfo(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo) { -- Gitee