From 7173439ddcc1e1312299a6e24709006c162b6003 Mon Sep 17 00:00:00 2001 From: wanghang Date: Tue, 25 Oct 2022 21:18:43 +0800 Subject: [PATCH] IssueNo:#I5XOLA Description:errCode opt Sig:SIG_ApplicaitonFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: wanghang Change-Id: I93ba85f70743c35d5b5d436b9aec21657b297051 --- .../bundlemgr/include/inner_bundle_info.h | 9 ++++ services/bundlemgr/src/bundle_data_mgr.cpp | 54 ++++++++++--------- services/bundlemgr/src/inner_bundle_info.cpp | 17 ++++++ 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 7435b50568..7d6622324f 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -232,6 +232,15 @@ public: */ std::optional FindAbilityInfoV9(const std::string &bundleName, const std::string &moduleName, const std::string &abilityName) const; + /** + * @brief Find abilityInfo by bundle name module name and ability name. + * @param bundleName Indicates the bundle name. + * @param moduleName Indicates the module name + * @param abilityName Indicates the ability name. + * @return Returns ERR_OK if abilityInfo find successfully obtained; returns other ErrCode otherwise. + */ + ErrCode FindAbilityInfo(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, AbilityInfo &info) const; /** * @brief Find abilityInfo of list by bundle name. * @param bundleName Indicates the bundle name. diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 8de8e05427..23c8e78ee0 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -1791,18 +1791,22 @@ ErrCode BundleDataMgr::GetAbilityLabel(const std::string &bundleName, const std: if (ret != ERR_OK) { return ret; } - auto ability = innerBundleInfo.FindAbilityInfoV9(bundleName, moduleName, abilityName); - if (!ability) { - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - if (!moduleName.empty()) { - if ((*ability).moduleName != moduleName) { - APP_LOGE("%{public}s can not find module: %{public}s", bundleName.c_str(), moduleName.c_str()); + AbilityInfo abilityInfo; + if (moduleName.empty()) { + auto ability = innerBundleInfo.FindAbilityInfoV9(bundleName, moduleName, abilityName); + if (!ability) { return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; } + abilityInfo = *ability; + } else { + ret = innerBundleInfo.FindAbilityInfo(bundleName, moduleName, abilityName, abilityInfo); + if (ret != ERR_OK) { + APP_LOGE("%{public}s:FindAbilityInfo failed: %{public}d", bundleName.c_str(), ret); + return ret; + } } bool isEnable = false; - ret = innerBundleInfo.IsAbilityEnabledV9(*ability, GetUserId(), isEnable); + ret = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, GetUserId(), isEnable); if (ret != ERR_OK) { return ret; } @@ -1810,17 +1814,17 @@ ErrCode BundleDataMgr::GetAbilityLabel(const std::string &bundleName, const std: APP_LOGE("%{public}s ability disabled: %{public}s", bundleName.c_str(), abilityName.c_str()); return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; } - if ((*ability).labelId == 0) { - label = (*ability).label; + if (abilityInfo.labelId == 0) { + label = abilityInfo.label; return ERR_OK; } std::shared_ptr resourceManager = - GetResourceManager(bundleName, (*ability).moduleName, GetUserId()); + GetResourceManager(bundleName, abilityInfo.moduleName, GetUserId()); if (resourceManager == nullptr) { APP_LOGE("InitResourceManager failed"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } - auto state = resourceManager->GetStringById(static_cast((*ability).labelId), label); + auto state = resourceManager->GetStringById(static_cast(abilityInfo.labelId), label); if (state != OHOS::Global::Resource::RState::SUCCESS) { APP_LOGE("ResourceManager GetStringById failed"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; @@ -4101,20 +4105,22 @@ ErrCode BundleDataMgr::GetMediaData(const std::string &bundleName, const std::st if (errCode != ERR_OK) { return errCode; } - - auto ability = innerBundleInfo.FindAbilityInfoV9(bundleName, moduleName, abilityName); - if (!ability) { - APP_LOGE("abilityName:%{public}s not find", abilityName.c_str()); - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - if (!moduleName.empty()) { - if ((*ability).moduleName != moduleName) { - APP_LOGE("%{public}s can not find module: %{public}s", bundleName.c_str(), moduleName.c_str()); + AbilityInfo abilityInfo; + if (moduleName.empty()) { + auto ability = innerBundleInfo.FindAbilityInfoV9(bundleName, moduleName, abilityName); + if (!ability) { return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; } + abilityInfo = *ability; + } else { + errCode = innerBundleInfo.FindAbilityInfo(bundleName, moduleName, abilityName, abilityInfo); + if (errCode != ERR_OK) { + APP_LOGE("%{public}s:FindAbilityInfo failed: %{public}d", bundleName.c_str(), errCode); + return errCode; + } } bool isEnable; - errCode = innerBundleInfo.IsAbilityEnabledV9(*ability, GetUserId(userId), isEnable); + errCode = innerBundleInfo.IsAbilityEnabledV9(abilityInfo, GetUserId(userId), isEnable); if (errCode != ERR_OK) { return errCode; } @@ -4123,13 +4129,13 @@ ErrCode BundleDataMgr::GetMediaData(const std::string &bundleName, const std::st return ERR_BUNDLE_MANAGER_ABILITY_DISABLED; } std::shared_ptr resourceManager = - GetResourceManager(bundleName, moduleName, GetUserId(userId)); + GetResourceManager(bundleName, abilityInfo.moduleName, GetUserId(userId)); if (resourceManager == nullptr) { APP_LOGE("InitResourceManager failed"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; } OHOS::Global::Resource::RState ret = - resourceManager->GetMediaDataById(static_cast((*ability).iconId), len, mediaDataPtr); + resourceManager->GetMediaDataById(static_cast(abilityInfo.iconId), len, mediaDataPtr); if (ret != OHOS::Global::Resource::RState::SUCCESS || mediaDataPtr == nullptr || len == 0) { APP_LOGE("GetMediaDataById failed"); return ERR_BUNDLE_MANAGER_INTERNAL_ERROR; diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index c70ea31fcf..11b4d3f279 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -1540,6 +1540,23 @@ std::optional InnerBundleInfo::FindAbilityInfoV9( return std::nullopt; } +ErrCode InnerBundleInfo::FindAbilityInfo(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, AbilityInfo &info) const +{ + for (const auto &ability : baseAbilityInfos_) { + auto abilityInfo = ability.second; + if ((abilityInfo.bundleName == bundleName) && (abilityInfo.moduleName == moduleName)) { + if (abilityInfo.name == abilityName) { + info = abilityInfo; + return ERR_OK; + } else { + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; + } + } + } + return ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST; +} + std::optional> InnerBundleInfo::FindAbilityInfos( const std::string &bundleName, int32_t userId) const { -- Gitee