From 5e8cc9615c932dca8a83c5fdea96483edc9a48f0 Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Wed, 9 Jul 2025 16:08:46 +0800 Subject: [PATCH 1/7] Issue:#ICL149 Description:optimize memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../bundlemgr/include/inner_bundle_info.h | 64 +++- services/bundlemgr/src/bundle_data_mgr.cpp | 10 +- .../bundlemgr/src/bundle_install_checker.cpp | 4 +- .../bundle_resource_process.cpp | 3 +- services/bundlemgr/src/inner_bundle_info.cpp | 357 +++++++++++++++++- services/bundlemgr/src/module_profile.cpp | 8 +- .../bms_bundle_aot_test/bms_data_aot_test.cpp | 2 + .../bms_bundle_data_storage_database_test.cpp | 24 +- .../bms_bundle_data_mgr_test.cpp | 2 + .../bms_bundle_data_mgr_test_three.cpp | 2 + .../bms_bundle_data_mgr_test_two.cpp | 2 + .../bms_bundle_kit_service_test.cpp | 4 + .../bms_bundle_manager_test_three.cpp | 1 + .../bms_data_mgr_test/bms_data_mgr_test.cpp | 4 + .../bmsdriverinstaller_fuzzer.cpp | 3 + 15 files changed, 426 insertions(+), 64 deletions(-) diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index ef87fc6ef0..2f9e495b96 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -48,6 +48,46 @@ namespace OHOS { namespace AppExecFwk { +struct InnerExtensionInfo { + bool visible = false; + bool enabled = true; + bool needCreateSandbox = false; + bool isolationProcess = false; + uint32_t iconId = 0; + uint32_t labelId = 0; + uint32_t descriptionId = 0; + int32_t priority = 0; + int32_t uid = -1; + int32_t appIndex = 0; + ExtensionAbilityType type = ExtensionAbilityType::UNSPECIFIED; + CompileMode compileMode = CompileMode::JS_BUNDLE; + ExtensionProcessMode extensionProcessMode = ExtensionProcessMode::UNDEFINED; + std::string bundleName; + std::string moduleName; + std::string name; + std::string srcEntrance; + std::string icon; + std::string label; + std::string description; + std::string readPermission; + std::string writePermission; + std::string uri; + std::string extensionTypeName; + std::string resourcePath; + std::string hapPath; + std::string process; + std::string customProcess; + std::string codeLanguage = Constants::CODE_LANGUAGE_1_1; + std::vector permissions; + std::vector appIdentifierAllowList; + std::vector metadata; + std::vector skillUri; + std::vector skills; + std::vector dataGroupIds; + std::vector validDataGroupIds; + std::shared_ptr appInfoPtr = nullptr; +}; + struct Distro { bool deliveryWithInstall = false; bool installationFree = false; @@ -203,6 +243,8 @@ public: InnerBundleInfo(); InnerBundleInfo &operator=(const InnerBundleInfo &info); ~InnerBundleInfo(); + + static ExtensionAbilityInfo ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo) const; /** * @brief Transform the InnerBundleInfo object to json. * @param jsonObject Indicates the obtained json object. @@ -294,12 +336,6 @@ public: */ std::optional FindExtensionInfo( const std::string &moduleName, const std::string &extensionName) const; - /** - * @brief Find extensionInfos by bundle name. - * @param bundleName Indicates the bundle name. - * @return Returns the ExtensionAbilityInfo array if find it; returns null otherwise. - */ - std::optional> FindExtensionInfos() const; /** * @brief Transform the InnerBundleInfo object to string. * @return Returns the string object @@ -317,7 +353,7 @@ public: } } - void AddModuleExtensionInfos(const std::map &extensionInfos) + void AddModuleExtensionInfos(const std::map &extensionInfos) { for (const auto &extensionInfo : extensionInfos) { baseExtensionInfos_.try_emplace(extensionInfo.first, extensionInfo.second); @@ -585,11 +621,11 @@ public: baseAbilityInfos_.emplace(key, abilityInfo); } /** - * @brief Insert ExtensionAbilityInfo. + * @brief Insert InnerExtensionInfo. * @param key bundleName.moduleName.extensionName * @param extensionInfo value. */ - void InsertExtensionInfo(const std::string &key, const ExtensionAbilityInfo &extensionInfo) + void InsertExtensionInfo(const std::string &key, const InnerExtensionInfo &extensionInfo) { baseExtensionInfos_.emplace(key, extensionInfo); } @@ -639,7 +675,7 @@ public: { for (const auto &item : baseExtensionInfos_) { if (uri == item.second.uri) { - extensionAbilityInfo = item.second; + extensionAbilityInfo = InnerBundleInfo::ConvertToExtensionInfo(item.second); APP_LOGD("find target extension, bundleName : %{public}s, moduleName : %{public}s, name : %{public}s", extensionAbilityInfo.bundleName.c_str(), extensionAbilityInfo.moduleName.c_str(), extensionAbilityInfo.name.c_str()); @@ -1323,14 +1359,14 @@ public: /** * @brief Fetch all extensionAbilityInfos, can be modify. */ - std::map &FetchInnerExtensionInfos() + std::map &FetchInnerExtensionInfos() { return baseExtensionInfos_; } /** - * @brief Obtains all extensionAbilityInfos. + * @brief Obtains all innerExtensionInfos. */ - const std::map &GetInnerExtensionInfos() const + const std::map &GetInnerExtensionInfos() const { return baseExtensionInfos_; } @@ -2437,7 +2473,7 @@ private: std::map> skillInfos_; std::map innerBundleUserInfos_; - std::map baseExtensionInfos_; + std::map baseExtensionInfos_; std::map> extensionSkillInfos_; // shared module info diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index f21b781f0e..3c8f5a39df 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -6066,7 +6066,7 @@ void BundleDataMgr::GetOneExtensionInfosByExtensionTypeName(const std::string &t if (typeName != extensionAbilityInfo.second.extensionTypeName) { continue; } - infos.emplace_back(extensionAbilityInfo.second); + infos.emplace_back(InnerBundleInfo::ConvertToExtensionInfo(extensionAbilityInfo.second)); return; } } @@ -6615,7 +6615,7 @@ void BundleDataMgr::GetMatchExtensionInfos(const Want &want, int32_t flags, cons skillInfos.first.c_str()); break; } - ExtensionAbilityInfo extensionInfo = extensionInfos[skillInfos.first]; + ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); if ((static_cast(flags) & GET_EXTENSION_INFO_WITH_APPLICATION) == GET_EXTENSION_INFO_WITH_APPLICATION) { info.GetApplicationInfo( @@ -6694,7 +6694,7 @@ void BundleDataMgr::GetMatchExtensionInfosV9(const Want &want, int32_t flags, in skillInfos.first.c_str()); continue; } - ExtensionAbilityInfo extensionInfo = extensionInfos[skillInfos.first]; + ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); EmplaceExtensionInfo(info, skillInfos.second, extensionInfo, flags, userId, infos, std::nullopt, std::nullopt, appIndex); continue; @@ -6723,7 +6723,7 @@ void BundleDataMgr::GetAllExtensionInfos(uint32_t flags, int32_t userId, { auto extensionInfos = info.GetInnerExtensionInfos(); for (const auto &extensionAbilityInfo : extensionInfos) { - ExtensionAbilityInfo extensionInfo = extensionAbilityInfo.second; + ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionAbilityInfo.second); if ((flags & static_cast(GetExtensionAbilityInfoFlag::GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION)) == static_cast(GetExtensionAbilityInfoFlag::GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION)) { @@ -6768,7 +6768,7 @@ bool BundleDataMgr::QueryExtensionAbilityInfos(const ExtensionAbilityType &exten auto innerExtensionInfos = innerBundleInfo.GetInnerExtensionInfos(); for (const auto &info : innerExtensionInfos) { if (info.second.type == extensionType) { - ExtensionAbilityInfo extensionAbilityInfo = info.second; + ExtensionAbilityInfo extensionAbilityInfo = InnerBundleInfo::ConvertToExtensionInfo(info.second); innerBundleInfo.GetApplicationInfo( ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, responseUserId, extensionAbilityInfo.applicationInfo); diff --git a/services/bundlemgr/src/bundle_install_checker.cpp b/services/bundlemgr/src/bundle_install_checker.cpp index b58ea253f9..d5152fa020 100644 --- a/services/bundlemgr/src/bundle_install_checker.cpp +++ b/services/bundlemgr/src/bundle_install_checker.cpp @@ -1386,8 +1386,8 @@ ErrCode BundleInstallChecker::ProcessBundleInfoByPrivilegeCapability( #endif } // process ExtensionAbility - auto &extensionAbilityInfos = innerBundleInfo.FetchInnerExtensionInfos(); - for (auto iter = extensionAbilityInfos.begin(); iter != extensionAbilityInfos.end(); ++iter) { + auto &innerExtensionInfos = innerBundleInfo.FetchInnerExtensionInfos(); + for (auto iter = innerExtensionInfos.begin(); iter != innerExtensionInfos.end(); ++iter) { bool privilegeType = IsPrivilegeExtensionAbilityType(iter->second.type); if (privilegeType && !appPrivilegeCapability.allowUsePrivilegeExtension) { LOG_E(BMS_TAG_INSTALLER, "not allow use privilege extension"); diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp index cfb1ace921..33b6a15dd4 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp @@ -526,7 +526,8 @@ bool BundleResourceProcess::GetAbilityResourceInfos( APP_LOGD("skip extension type %{public}d", item.second.type); continue; } - resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(item.second)); + // to do + resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(InnerBundleInfo::ConvertToExtensionInfo(item.second))); } // process overlay hap paths size_t size = resourceInfos.size(); diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index a70d67d7d6..8a21163d35 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -177,6 +177,297 @@ const std::string NameAndUserIdToKey(const std::string &bundleName, int32_t user } } // namespace +void from_json(const nlohmann::json &jsonObject, InnerExtensionInfo &extensionInfo) +{ + const auto &jsonObjectEnd = jsonObject.end(); + int32_t parseResult = ERR_OK; + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::BUNDLE_NAME, + extensionInfo.bundleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::MODULE_NAME, + extensionInfo.moduleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + NAME, + extensionInfo.name, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + SRC_ENTRANCE, + extensionInfo.srcEntrance, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + ICON, + extensionInfo.icon, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ICON_ID, + extensionInfo.iconId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + LABEL, + extensionInfo.label, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + LABEL_ID, + extensionInfo.labelId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + DESCRIPTION, + extensionInfo.description, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + DESCRIPTION_ID, + extensionInfo.descriptionId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + PRIORITY, + extensionInfo.priority, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + TYPE, + extensionInfo.type, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + EXTENSION_TYPE_NAME, + extensionInfo.extensionTypeName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + READ_PERMISSION, + extensionInfo.readPermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + WRITE_PERMISSION, + extensionInfo.writePermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + URI, + extensionInfo.uri, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + PERMISSIONS, + extensionInfo.permissions, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + APPIDENTIFIER_ALLOW_LIST, + extensionInfo.appIdentifierAllowList, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + VISIBLE, + extensionInfo.visible, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + META_DATA, + extensionInfo.metadata, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + RESOURCE_PATH, + extensionInfo.resourcePath, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::HAP_PATH, + extensionInfo.hapPath, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + ENABLED, + extensionInfo.enabled, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + PROCESS, + extensionInfo.process, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + COMPILE_MODE, + extensionInfo.compileMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + UID, + extensionInfo.uid, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + APP_INDEX, + extensionInfo.appIndex, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + EXTENSION_PROCESS_MODE, + extensionInfo.extensionProcessMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + SKILLS, + extensionInfo.skills, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + NEED_CREATE_SANDBOX, + extensionInfo.needCreateSandbox, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + DATA_GROUP_IDS, + extensionInfo.dataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + JSON_KEY_VALID_DATA_GROUP_IDS, + extensionInfo.validDataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + JSON_KEY_CUSTOM_PROCESS, + extensionInfo.customProcess, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + JSON_KEY_ISOLATION_PROCESS, + extensionInfo.isolationProcess, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::CODE_LANGUAGE, + extensionInfo.codeLanguage, + false, + parseResult); + + if (parseResult != ERR_OK) { + APP_LOGE("InnerExtensionInfo from_json error : %{public}d", parseResult); + } +} + +void to_json(nlohmann::json &jsonObject, const InnerExtensionInfo &extensionInfo) +{ + jsonObject = nlohmann::json { + {Constants::BUNDLE_NAME, extensionInfo.bundleName}, + {Constants::MODULE_NAME, extensionInfo.moduleName}, + {NAME, extensionInfo.name}, + {SRC_ENTRANCE, extensionInfo.srcEntrance}, + {ICON, extensionInfo.icon}, + {ICON_ID, extensionInfo.iconId}, + {LABEL, extensionInfo.label}, + {LABEL_ID, extensionInfo.labelId}, + {DESCRIPTION, extensionInfo.description}, + {DESCRIPTION_ID, extensionInfo.descriptionId}, + {PRIORITY, extensionInfo.priority}, + {TYPE, extensionInfo.type}, + {EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, + {READ_PERMISSION, extensionInfo.readPermission}, + {WRITE_PERMISSION, extensionInfo.writePermission}, + {URI, extensionInfo.uri}, + {PERMISSIONS, extensionInfo.permissions}, + {APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, + {VISIBLE, extensionInfo.visible}, + {META_DATA, extensionInfo.metadata}, + {RESOURCE_PATH, extensionInfo.resourcePath}, + {Constants::HAP_PATH, extensionInfo.hapPath}, + {ENABLED, extensionInfo.enabled}, + {PROCESS, extensionInfo.process}, + {COMPILE_MODE, extensionInfo.compileMode}, + {UID, extensionInfo.uid}, + {APP_INDEX, extensionInfo.appIndex}, + {EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, + {JSON_KEY_SKILLS, extensionInfo.skills}, + {NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, + {DATA_GROUP_IDS, extensionInfo.dataGroupIds}, + {JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, + {JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, + {JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, + {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} + }; +} + void from_json(const nlohmann::json &jsonObject, ExtendResourceInfo &extendResourceInfo) { const auto &jsonObjectEnd = jsonObject.end(); @@ -343,6 +634,48 @@ InnerBundleInfo::~InnerBundleInfo() APP_LOGD("inner bundle info instance is destroyed"); } +ExtensionAbilityInfo ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo) const +{ + ExtensionAbilityInfo extensionAbilityInfo; + extensionAbilityInfo.visible = innerExtensionInfo.visible; + extensionAbilityInfo.enabled = innerExtensionInfo.enabled; + extensionAbilityInfo.needCreateSandbox = innerExtensionInfo.needCreateSandbox; + extensionAbilityInfo.isolationProcess = innerExtensionInfo.isolationProcess; + extensionAbilityInfo.iconId = innerExtensionInfo.iconId; + extensionAbilityInfo.labelId = innerExtensionInfo.labelId; + extensionAbilityInfo.descriptionId = innerExtensionInfo.descriptionId; + extensionAbilityInfo.priority = innerExtensionInfo.priority; + extensionAbilityInfo.uid = innerExtensionInfo.uid; + extensionAbilityInfo.appIndex = innerExtensionInfo.appIndex; + extensionAbilityInfo.type = innerExtensionInfo.type; + extensionAbilityInfo.compileMode = innerExtensionInfo.compileMode; + extensionAbilityInfo.extensionProcessMode = innerExtensionInfo.extensionProcessMode; + extensionAbilityInfo.bundleName = innerExtensionInfo.bundleName; + extensionAbilityInfo.moduleName = innerExtensionInfo.moduleName; + extensionAbilityInfo.name = innerExtensionInfo.name; + extensionAbilityInfo.srcEntrance = innerExtensionInfo.srcEntrance; + extensionAbilityInfo.icon = innerExtensionInfo.icon; + extensionAbilityInfo.label = innerExtensionInfo.label; + extensionAbilityInfo.description = innerExtensionInfo.description; + extensionAbilityInfo.readPermission = innerExtensionInfo.readPermission; + extensionAbilityInfo.writePermission = innerExtensionInfo.writePermission; + extensionAbilityInfo.uri = innerExtensionInfo.uri; + extensionAbilityInfo.extensionTypeName = innerExtensionInfo.extensionTypeName; + extensionAbilityInfo.resourcePath = innerExtensionInfo.resourcePath; + extensionAbilityInfo.hapPath = innerExtensionInfo.hapPath; + extensionAbilityInfo.process = innerExtensionInfo.process; + extensionAbilityInfo.customProcess = innerExtensionInfo.customProcess; + extensionAbilityInfo.codeLanguage = innerExtensionInfo.codeLanguage; + extensionAbilityInfo.permissions = innerExtensionInfo.permissions; + extensionAbilityInfo.appIdentifierAllowList = innerExtensionInfo.appIdentifierAllowList; + extensionAbilityInfo.metadata = innerExtensionInfo.metadata; + extensionAbilityInfo.skillUri = innerExtensionInfo.skillUri; + extensionAbilityInfo.skills = innerExtensionInfo.skills; + extensionAbilityInfo.dataGroupIds = innerExtensionInfo.dataGroupIds; + extensionAbilityInfo.validDataGroupIds = innerExtensionInfo.validDataGroupIds; + return extensionAbilityInfo; +} + void to_json(nlohmann::json &jsonObject, const Distro &distro) { jsonObject = nlohmann::json { @@ -1418,7 +1751,7 @@ int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject) isNewVersion_, false, parseResult); - GetValueIfFindKey>(jsonObject, + GetValueIfFindKey>(jsonObject, jsonObjectEnd, BUNDLE_BASE_EXTENSION_INFOS, baseExtensionInfos_, @@ -1621,7 +1954,7 @@ std::optional InnerBundleInfo::FindHapModuleInfo( key.append(".").append(modulePackage).append("."); for (const auto &extension : baseExtensionInfos_) { if ((extension.first.find(key) != std::string::npos) && (extension.second.moduleName == hapInfo.moduleName)) { - hapInfo.extensionInfos.emplace_back(extension.second); + hapInfo.extensionInfos.emplace_back(InnerBundleInfo::ConvertToExtensionInfo(extension.second)); } } hapInfo.metadata = it->second.metadata; @@ -1773,27 +2106,13 @@ std::optional InnerBundleInfo::FindExtensionInfo( for (const auto &extension : baseExtensionInfos_) { if ((extension.second.name == extensionName) && (moduleName.empty() || (extension.second.moduleName == moduleName))) { - return extension.second; + return InnerBundleInfo::ConvertToExtensionInfo(extension.second); } } return std::nullopt; } -std::optional> InnerBundleInfo::FindExtensionInfos() const -{ - std::vector extensions; - for (const auto &extension : baseExtensionInfos_) { - extensions.emplace_back(extension.second); - } - - if (extensions.empty()) { - return std::nullopt; - } - - return extensions; -} - bool InnerBundleInfo::AddModuleInfo(const InnerBundleInfo &newInfo) { if (newInfo.currentPackage_.empty()) { @@ -2729,7 +3048,7 @@ void InnerBundleInfo::GetBundleWithExtensionAbilitiesV9( if (extensionInfo.second.moduleName != hapModuleInfo.moduleName || !extensionInfo.second.enabled) { continue; } - ExtensionAbilityInfo info = extensionInfo.second; + ExtensionAbilityInfo info = InnerBundleInfo::ConvertToExtensionInfo(extensionInfo.second); info.appIndex = appIndex; if ((static_cast(flags) & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) @@ -2778,7 +3097,7 @@ void InnerBundleInfo::GetBundleWithExtension( if (!extensionInfo.second.enabled) { continue; } - ExtensionAbilityInfo info = extensionInfo.second; + ExtensionAbilityInfo info = InnerBundleInfo::ConvertToExtensionInfo(extensionInfo.second); if ((static_cast(flags) & GET_BUNDLE_WITH_SKILL) != GET_BUNDLE_WITH_SKILL) { info.skills.clear(); } diff --git a/services/bundlemgr/src/module_profile.cpp b/services/bundlemgr/src/module_profile.cpp index 577636de6a..3c47cdf728 100644 --- a/services/bundlemgr/src/module_profile.cpp +++ b/services/bundlemgr/src/module_profile.cpp @@ -2445,7 +2445,7 @@ void ToAbilitySkills(const std::vector &skills, AbilityInfo &abilityInfo) } } -void ToExtensionAbilitySkills(const std::vector &skills, ExtensionAbilityInfo &extensionInfo) +void ToExtensionAbilitySkills(const std::vector &skills, InnerExtensionInfo &extensionInfo) { for (const Skill &skill : skills) { extensionInfo.skills.push_back(skill); @@ -2456,9 +2456,9 @@ void ToExtensionInfo( const Profile::ModuleJson &moduleJson, const Profile::Extension &extension, const TransformParam &transformParam, - ExtensionAbilityInfo &extensionInfo) + InnerExtensionInfo &extensionInfo) { - APP_LOGD("transform ModuleJson to ExtensionAbilityInfo"); + APP_LOGD("transform ModuleJson to InnerExtensionInfo"); extensionInfo.type = ConvertToExtensionAbilityType(extension.type); extensionInfo.extensionTypeName = extension.type; extensionInfo.name = extension.name; @@ -2749,7 +2749,7 @@ bool ToInnerBundleInfo( // handle extensionAbilities for (const Profile::Extension &extension : moduleJson.module.extensionAbilities) { - ExtensionAbilityInfo extensionInfo; + InnerExtensionInfo extensionInfo; ToExtensionInfo(moduleJson, extension, transformParam, extensionInfo); if (innerModuleInfo.mainAbility == extensionInfo.name) { diff --git a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp index 1967788c46..aa49d5c1d0 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp @@ -1953,6 +1953,7 @@ HWTEST_F(BmsAOTMgrTest, IsDriverForAllUser_0100, Function | SmallTest | Level0) InnerBundleInfo info; ExtensionAbilityInfo abilityInfo; abilityInfo.type = ExtensionAbilityType::DRIVER; + // to do info.InsertExtensionInfo("key", abilityInfo); installer.dataMgr_->bundleInfos_.try_emplace(AOT_BUNDLE_NAME, info); bool ret = installer.IsDriverForAllUser(AOT_BUNDLE_NAME); @@ -1975,6 +1976,7 @@ HWTEST_F(BmsAOTMgrTest, GetBundleNamesForNewUser_0100, Function | SmallTest | Le InnerBundleInfo info; ExtensionAbilityInfo abilityInfo; abilityInfo.type = ExtensionAbilityType::DRIVER; + // to do info.InsertExtensionInfo("key", abilityInfo); dataMgr->bundleInfos_.try_emplace(AOT_BUNDLE_NAME, info); OHOS::system::SetParameter(ServiceConstants::IS_DRIVER_FOR_ALL_USERS, "false"); diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index a7e33c637f..aeb38b1c55 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -2135,6 +2135,7 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0700, Function | Smal std::vector skill; innerModuleInfo.extensionKeys.emplace_back(TEST_KEY1); innerModuleInfo.extensionSkillKeys.emplace_back(TEST_KEY2); + // to do info.InsertExtensionInfo(TEST_KEY1, extensionInfo); info.InsertExtensionSkillInfo(TEST_KEY2, skill); info.InsertInnerModuleInfo(WRONG_MODULEPACKAGE, innerModuleInfo); @@ -2143,6 +2144,7 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0700, Function | Smal info.InsertCommonEvents(WRONG, commonEvent1); info.InsertCommonEvents(WRONG_MODULEPACKAGE, commonEvent2); info.RemoveModuleInfo(WRONG_MODULEPACKAGE); + // to do auto ret1 = info.GetInnerExtensionInfos(); auto ret2 = info.GetExtensionSkillInfos(); EXPECT_EQ(ret1[TEST_KEY1].name, ""); @@ -2360,6 +2362,7 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_1800, Function | Smal extensionInfo.bundleName = bundleName; extensionInfo.moduleName = moduleName; extensionInfo.name = extensionName; + // to do info.InsertExtensionInfo(TEST_KEY, extensionInfo); ret = info.FindExtensionInfo(moduleName, extensionName); EXPECT_EQ((*ret).bundleName, bundleName); @@ -2413,25 +2416,6 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_2200, Function | Smal EXPECT_EQ(ret, false); } -/** - * @tc.number: InnerBundleInfo_2300 - * @tc.name: Test FindExtensionInfos - * @tc.desc: 1.Test the FindExtensionInfos of InnerBundleInfo - */ -HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_2300, Function | SmallTest | Level1) -{ - InnerBundleInfo info; - std::string bundleName = BUNDLE_NAME; - auto ret = info.FindExtensionInfos(); - EXPECT_EQ(ret, std::nullopt); - - ExtensionAbilityInfo extensionInfo; - extensionInfo.bundleName = bundleName; - info.InsertExtensionInfo(TEST_KEY, extensionInfo); - ret = info.FindExtensionInfos(); - EXPECT_NE(ret, std::nullopt); -} - /** * @tc.number: InnerBundleInfo_2300 * @tc.name: Test ProcessBundleWithHapModuleInfoFlag @@ -2505,10 +2489,12 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_2600, Function | Smal info.GetBundleWithExtensionAbilitiesV9(FLAG, hapModuleInfo); EXPECT_EQ(hapModuleInfo.extensionInfos.empty(), true); + // to do ExtensionAbilityInfo extensionInfo; int32_t flag = 8; extensionInfo.moduleName = moduleName; extensionInfo.enabled = false; + // to do info.InsertExtensionInfo(TEST_KEY, extensionInfo); info.GetBundleWithExtensionAbilitiesV9(flag, hapModuleInfo); EXPECT_EQ(hapModuleInfo.extensionInfos.empty(), true); diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp index 8aa234da1f..ec7ce6f8d6 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp @@ -607,7 +607,9 @@ void BmsBundleDataMgrTest::MockInstallExtension(const std::string &bundleName, ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; + // to do innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); + // to do innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp index ee5a9f16ae..57577260c2 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp @@ -598,7 +598,9 @@ void BmsBundleDataMgrTest3::MockInstallExtension(const std::string &bundleName, ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; + // to do innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); + // to do innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp index 460bc7e84b..b9e97a3e50 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp @@ -604,7 +604,9 @@ void BmsBundleDataMgrTest2::MockInstallExtension(const std::string &bundleName, ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; + // to do innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); + // to do innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index 4ba0050942..715398d554 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -734,7 +734,9 @@ void BmsBundleKitServiceTest::MockInstallExtension(const std::string &bundleName ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; + // to do innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); + // to do innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; @@ -756,7 +758,9 @@ void BmsBundleKitServiceTest::MockInstallExtensionWithUri(const std::string &bun ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; + // to do innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); + // to do innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill = MockExtensionSkillInfo(); diff --git a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp index c49b8230b8..f76b6336b6 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp @@ -1714,6 +1714,7 @@ HWTEST_F(BmsBundleManagerTest3, GetBundleNamesForNewUser_0200, Function | SmallT InnerBundleInfo info; ExtensionAbilityInfo abilityInfo; abilityInfo.type = ExtensionAbilityType::DRIVER; + // to do info.InsertExtensionInfo("key", abilityInfo); dataMgr->bundleInfos_.try_emplace(BUNDLE_NAME, info); std::vector ret = dataMgr->GetBundleNamesForNewUser(); diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp index 4ff478aa0b..4c664d98ac 100644 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp @@ -2426,6 +2426,7 @@ HWTEST_F(BmsDataMgrTest, GetAllExtensionInfos_0100, Function | SmallTest | Level dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), true); ExtensionAbilityInfo extensionAbilityInfo; + // to do info.InsertExtensionInfo("", extensionAbilityInfo); dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), false); @@ -2452,6 +2453,7 @@ HWTEST_F(BmsDataMgrTest, GetOneExtensionInfosByExtensionTypeName_0100, Function dataMgr->GetOneExtensionInfosByExtensionTypeName(typeName, flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), true); ExtensionAbilityInfo extensionAbilityInfo; + // to do info.InsertExtensionInfo("", extensionAbilityInfo); dataMgr->GetOneExtensionInfosByExtensionTypeName(typeName, flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), false); @@ -4227,6 +4229,7 @@ HWTEST_F(BmsDataMgrTest, GetExtensionAbilityInfoByTypeName_0001, TestSize.Level1 ExtensionAbilityInfo extensionInfo; extensionInfo.name = "test_extensionInfo"; + // to do info.InsertExtensionInfo("test_key", extensionInfo); bundleDataMgr.GetExtensionAbilityInfoByTypeName(flags, userId, infos, typeName); EXPECT_FALSE(bundleDataMgr.bundleInfos_.empty()); @@ -6021,6 +6024,7 @@ HWTEST_F(BmsDataMgrTest, GetAllExtensionBundleNames_0002, Function | MediumTest InnerBundleInfo info; ExtensionAbilityInfo extensionInfo; extensionInfo.type = ExtensionAbilityType::INPUTMETHOD; + // to do info.InsertExtensionInfo("test.extension", extensionInfo); std::shared_lock lock(dataMgr_->bundleInfoMutex_); dataMgr_->bundleInfos_.emplace("test.bundle", info); diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp index 44ae5c6a78..92fe4cef6a 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp @@ -74,11 +74,14 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) extensionInfo.bundleName = newInfo1.GetBundleName(); std::string extensionKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); + // to do installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); extensionInfo.type = ExtensionAbilityType::DRIVER; + // to do newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); extensionInfo.metadata.push_back(metaData); + // to do newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); -- Gitee From 84ea2eab0a9a075a4cc3cad53468ab070abeb14b Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Thu, 10 Jul 2025 15:22:14 +0800 Subject: [PATCH 2/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../appexecfwk_base/include/json_serializer.h | 295 +++++++++++++++ .../src/extension_ability_info.cpp | 286 +-------------- services/bundlemgr/appexecfwk_bundlemgr.gni | 1 + .../include/data/inner_extension_info.h | 66 ++++ .../bundlemgr/include/inner_bundle_info.h | 44 +-- services/bundlemgr/src/bundle_data_mgr.cpp | 12 +- .../bundle_resource_process.cpp | 4 +- .../src/data/inner_extension_info.cpp | 62 ++++ services/bundlemgr/src/inner_bundle_info.cpp | 335 +----------------- 9 files changed, 442 insertions(+), 663 deletions(-) create mode 100644 services/bundlemgr/include/data/inner_extension_info.h create mode 100644 services/bundlemgr/src/data/inner_extension_info.cpp diff --git a/interfaces/inner_api/appexecfwk_base/include/json_serializer.h b/interfaces/inner_api/appexecfwk_base/include/json_serializer.h index be4c8ed918..38a9462bcf 100644 --- a/interfaces/inner_api/appexecfwk_base/include/json_serializer.h +++ b/interfaces/inner_api/appexecfwk_base/include/json_serializer.h @@ -166,6 +166,301 @@ void to_json(nlohmann::json &jsonObject, const PluginBundleInfo &pluginBundleInf void from_json(const nlohmann::json &jsonObject, PluginBundleInfo &pluginBundleInfo); void to_json(nlohmann::json &jsonObject, const PluginModuleInfo &pluginModuleInfo); void from_json(const nlohmann::json &jsonObject, PluginModuleInfo &pluginModuleInfo); + +template +void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) +{ + APP_LOGD("ExtensionFromJson begin"); + const auto &jsonObjectEnd = jsonObject.end(); + int32_t parseResult = ERR_OK; + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::BUNDLE_NAME, + extensionInfo.bundleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::MODULE_NAME, + extensionInfo.moduleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + NAME, + extensionInfo.name, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + SRC_ENTRANCE, + extensionInfo.srcEntrance, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + ICON, + extensionInfo.icon, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + ICON_ID, + extensionInfo.iconId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + LABEL, + extensionInfo.label, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + LABEL_ID, + extensionInfo.labelId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + DESCRIPTION, + extensionInfo.description, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + DESCRIPTION_ID, + extensionInfo.descriptionId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + PRIORITY, + extensionInfo.priority, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + TYPE, + extensionInfo.type, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + EXTENSION_TYPE_NAME, + extensionInfo.extensionTypeName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + READ_PERMISSION, + extensionInfo.readPermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + WRITE_PERMISSION, + extensionInfo.writePermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + URI, + extensionInfo.uri, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + PERMISSIONS, + extensionInfo.permissions, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + APPIDENTIFIER_ALLOW_LIST, + extensionInfo.appIdentifierAllowList, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + VISIBLE, + extensionInfo.visible, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + META_DATA, + extensionInfo.metadata, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + RESOURCE_PATH, + extensionInfo.resourcePath, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::HAP_PATH, + extensionInfo.hapPath, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + ENABLED, + extensionInfo.enabled, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + PROCESS, + extensionInfo.process, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + COMPILE_MODE, + extensionInfo.compileMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + UID, + extensionInfo.uid, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + APP_INDEX, + extensionInfo.appIndex, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + EXTENSION_PROCESS_MODE, + extensionInfo.extensionProcessMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + SKILLS, + extensionInfo.skills, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + NEED_CREATE_SANDBOX, + extensionInfo.needCreateSandbox, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + DATA_GROUP_IDS, + extensionInfo.dataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + JSON_KEY_VALID_DATA_GROUP_IDS, + extensionInfo.validDataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + JSON_KEY_CUSTOM_PROCESS, + extensionInfo.customProcess, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + JSON_KEY_ISOLATION_PROCESS, + extensionInfo.isolationProcess, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::CODE_LANGUAGE, + extensionInfo.codeLanguage, + false, + parseResult); + + if (parseResult != ERR_OK) { + APP_LOGE("ExtensionAbilityInfo from_json error : %{public}d", parseResult); + } +} + +template +void ExtensionToJson(nlohmann::json &jsonObject, const T &extensionInfo) +{ + APP_LOGD("ExtensionToJson begin"); + jsonObject = nlohmann::json { + {Constants::BUNDLE_NAME, extensionInfo.bundleName}, + {Constants::MODULE_NAME, extensionInfo.moduleName}, + {NAME, extensionInfo.name}, + {SRC_ENTRANCE, extensionInfo.srcEntrance}, + {ICON, extensionInfo.icon}, + {ICON_ID, extensionInfo.iconId}, + {LABEL, extensionInfo.label}, + {LABEL_ID, extensionInfo.labelId}, + {DESCRIPTION, extensionInfo.description}, + {DESCRIPTION_ID, extensionInfo.descriptionId}, + {PRIORITY, extensionInfo.priority}, + {TYPE, extensionInfo.type}, + {EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, + {READ_PERMISSION, extensionInfo.readPermission}, + {WRITE_PERMISSION, extensionInfo.writePermission}, + {URI, extensionInfo.uri}, + {PERMISSIONS, extensionInfo.permissions}, + {APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, + {VISIBLE, extensionInfo.visible}, + {META_DATA, extensionInfo.metadata}, + {RESOURCE_PATH, extensionInfo.resourcePath}, + {Constants::HAP_PATH, extensionInfo.hapPath}, + {ENABLED, extensionInfo.enabled}, + {PROCESS, extensionInfo.process}, + {COMPILE_MODE, extensionInfo.compileMode}, + {UID, extensionInfo.uid}, + {APP_INDEX, extensionInfo.appIndex}, + {EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, + {JSON_KEY_SKILLS, extensionInfo.skills}, + {NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, + {DATA_GROUP_IDS, extensionInfo.dataGroupIds}, + {JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, + {JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, + {JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, + {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} + }; +} } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_JSON_SERIALIZER_H diff --git a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp index 305ec044d1..299a501655 100644 --- a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp @@ -375,295 +375,13 @@ bool ExtensionAbilityInfo::Marshalling(Parcel &parcel) const void to_json(nlohmann::json &jsonObject, const ExtensionAbilityInfo &extensionInfo) { - APP_LOGD("ExtensionAbilityInfo to_json begin"); - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, extensionInfo.bundleName}, - {Constants::MODULE_NAME, extensionInfo.moduleName}, - {NAME, extensionInfo.name}, - {SRC_ENTRANCE, extensionInfo.srcEntrance}, - {ICON, extensionInfo.icon}, - {ICON_ID, extensionInfo.iconId}, - {LABEL, extensionInfo.label}, - {LABEL_ID, extensionInfo.labelId}, - {DESCRIPTION, extensionInfo.description}, - {DESCRIPTION_ID, extensionInfo.descriptionId}, - {PRIORITY, extensionInfo.priority}, - {TYPE, extensionInfo.type}, - {EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, - {READ_PERMISSION, extensionInfo.readPermission}, - {WRITE_PERMISSION, extensionInfo.writePermission}, - {URI, extensionInfo.uri}, - {PERMISSIONS, extensionInfo.permissions}, - {APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, - {VISIBLE, extensionInfo.visible}, - {META_DATA, extensionInfo.metadata}, - {RESOURCE_PATH, extensionInfo.resourcePath}, - {Constants::HAP_PATH, extensionInfo.hapPath}, - {ENABLED, extensionInfo.enabled}, - {PROCESS, extensionInfo.process}, - {COMPILE_MODE, extensionInfo.compileMode}, - {UID, extensionInfo.uid}, - {APP_INDEX, extensionInfo.appIndex}, - {EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, - {JSON_KEY_SKILLS, extensionInfo.skills}, - {NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, - {DATA_GROUP_IDS, extensionInfo.dataGroupIds}, - {JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, - {JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, - {JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, - {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} - }; + ExtensionToJson(jsonObject, extensionInfo); } void from_json(const nlohmann::json &jsonObject, ExtensionAbilityInfo &extensionInfo) { APP_LOGD("ExtensionAbilityInfo from_json begin"); - const auto &jsonObjectEnd = jsonObject.end(); - int32_t parseResult = ERR_OK; - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - extensionInfo.bundleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - extensionInfo.moduleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - NAME, - extensionInfo.name, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - extensionInfo.srcEntrance, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - extensionInfo.icon, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - extensionInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - extensionInfo.label, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - extensionInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - extensionInfo.description, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - extensionInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - extensionInfo.priority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - TYPE, - extensionInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_TYPE_NAME, - extensionInfo.extensionTypeName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - READ_PERMISSION, - extensionInfo.readPermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - WRITE_PERMISSION, - extensionInfo.writePermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - URI, - extensionInfo.uri, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - extensionInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPIDENTIFIER_ALLOW_LIST, - extensionInfo.appIdentifierAllowList, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - extensionInfo.visible, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - extensionInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - RESOURCE_PATH, - extensionInfo.resourcePath, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::HAP_PATH, - extensionInfo.hapPath, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - ENABLED, - extensionInfo.enabled, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - PROCESS, - extensionInfo.process, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_MODE, - extensionInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UID, - extensionInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_INDEX, - extensionInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_PROCESS_MODE, - extensionInfo.extensionProcessMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - SKILLS, - extensionInfo.skills, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - NEED_CREATE_SANDBOX, - extensionInfo.needCreateSandbox, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - DATA_GROUP_IDS, - extensionInfo.dataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_VALID_DATA_GROUP_IDS, - extensionInfo.validDataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_CUSTOM_PROCESS, - extensionInfo.customProcess, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ISOLATION_PROCESS, - extensionInfo.isolationProcess, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::CODE_LANGUAGE, - extensionInfo.codeLanguage, - false, - parseResult); - - if (parseResult != ERR_OK) { - APP_LOGE("ExtensionAbilityInfo from_json error : %{public}d", parseResult); - } + ExtensionFromJson(jsonObject, extensionInfo); } ExtensionAbilityType ConvertToExtensionAbilityType(const std::string &type) diff --git a/services/bundlemgr/appexecfwk_bundlemgr.gni b/services/bundlemgr/appexecfwk_bundlemgr.gni index 14d2e022bd..5e8c85cbe9 100644 --- a/services/bundlemgr/appexecfwk_bundlemgr.gni +++ b/services/bundlemgr/appexecfwk_bundlemgr.gni @@ -51,6 +51,7 @@ bundle_install_sources = [ "${services_path}/bundlemgr/src/bundle_stream_installer_host_impl.cpp", "${services_path}/bundlemgr/src/bundle_util.cpp", "${services_path}/bundlemgr/src/bundle_verify_mgr.cpp", + "${services_path}/bundlemgr/src/data/inner_extension_info.cpp", "${services_path}/bundlemgr/src/driver/driver_installer.cpp", "${services_path}/bundlemgr/src/event_report.cpp", "${services_path}/bundlemgr/src/hmp_bundle_installer.cpp", diff --git a/services/bundlemgr/include/data/inner_extension_info.h b/services/bundlemgr/include/data/inner_extension_info.h new file mode 100644 index 0000000000..a5da1d9b14 --- /dev/null +++ b/services/bundlemgr/include/data/inner_extension_info.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_BUNDLE_FRAMEWORK_INNER_EXTENSION_INFO_H +#define FOUNDATION_BUNDLE_FRAMEWORK_INNER_EXTENSION_INFO_H + +#include "extension_ability_info.h" + +namespace OHOS { +namespace AppExecFwk { +struct InnerExtensionInfo { + bool visible = false; + bool enabled = true; + bool needCreateSandbox = false; + bool isolationProcess = false; + uint32_t iconId = 0; + uint32_t labelId = 0; + uint32_t descriptionId = 0; + int32_t priority = 0; + int32_t uid = -1; + int32_t appIndex = 0; + ExtensionAbilityType type = ExtensionAbilityType::UNSPECIFIED; + CompileMode compileMode = CompileMode::JS_BUNDLE; + ExtensionProcessMode extensionProcessMode = ExtensionProcessMode::UNDEFINED; + std::string bundleName; + std::string moduleName; + std::string name; + std::string srcEntrance; + std::string icon; + std::string label; + std::string description; + std::string readPermission; + std::string writePermission; + std::string uri; + std::string extensionTypeName; + std::string resourcePath; + std::string hapPath; + std::string process; + std::string customProcess; + std::string codeLanguage = Constants::CODE_LANGUAGE_1_1; + std::vector permissions; + std::vector appIdentifierAllowList; + std::vector metadata; + std::vector skillUri; + std::vector skills; + std::vector dataGroupIds; + std::vector validDataGroupIds; + std::shared_ptr appInfoPtr = nullptr; + + static ExtensionAbilityInfo ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_BUNDLE_FRAMEWORK_INNER_EXTENSION_INFO_H diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 2f9e495b96..bd99afb895 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -35,6 +35,7 @@ #include "inner_app_quick_fix.h" #include "inner_bundle_clone_info.h" #include "inner_bundle_user_info.h" +#include "inner_extension_info.h" #include "ipc/check_encryption_param.h" #include "json_util.h" #include "plugin/plugin_bundle_info.h" @@ -48,45 +49,6 @@ namespace OHOS { namespace AppExecFwk { -struct InnerExtensionInfo { - bool visible = false; - bool enabled = true; - bool needCreateSandbox = false; - bool isolationProcess = false; - uint32_t iconId = 0; - uint32_t labelId = 0; - uint32_t descriptionId = 0; - int32_t priority = 0; - int32_t uid = -1; - int32_t appIndex = 0; - ExtensionAbilityType type = ExtensionAbilityType::UNSPECIFIED; - CompileMode compileMode = CompileMode::JS_BUNDLE; - ExtensionProcessMode extensionProcessMode = ExtensionProcessMode::UNDEFINED; - std::string bundleName; - std::string moduleName; - std::string name; - std::string srcEntrance; - std::string icon; - std::string label; - std::string description; - std::string readPermission; - std::string writePermission; - std::string uri; - std::string extensionTypeName; - std::string resourcePath; - std::string hapPath; - std::string process; - std::string customProcess; - std::string codeLanguage = Constants::CODE_LANGUAGE_1_1; - std::vector permissions; - std::vector appIdentifierAllowList; - std::vector metadata; - std::vector skillUri; - std::vector skills; - std::vector dataGroupIds; - std::vector validDataGroupIds; - std::shared_ptr appInfoPtr = nullptr; -}; struct Distro { bool deliveryWithInstall = false; @@ -243,8 +205,6 @@ public: InnerBundleInfo(); InnerBundleInfo &operator=(const InnerBundleInfo &info); ~InnerBundleInfo(); - - static ExtensionAbilityInfo ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo) const; /** * @brief Transform the InnerBundleInfo object to json. * @param jsonObject Indicates the obtained json object. @@ -675,7 +635,7 @@ public: { for (const auto &item : baseExtensionInfos_) { if (uri == item.second.uri) { - extensionAbilityInfo = InnerBundleInfo::ConvertToExtensionInfo(item.second); + extensionAbilityInfo = InnerExtensionInfo::ConvertToExtensionInfo(item.second); APP_LOGD("find target extension, bundleName : %{public}s, moduleName : %{public}s, name : %{public}s", extensionAbilityInfo.bundleName.c_str(), extensionAbilityInfo.moduleName.c_str(), extensionAbilityInfo.name.c_str()); diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 3c8f5a39df..215e676242 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -6066,7 +6066,7 @@ void BundleDataMgr::GetOneExtensionInfosByExtensionTypeName(const std::string &t if (typeName != extensionAbilityInfo.second.extensionTypeName) { continue; } - infos.emplace_back(InnerBundleInfo::ConvertToExtensionInfo(extensionAbilityInfo.second)); + infos.emplace_back(InnerExtensionInfo::ConvertToExtensionInfo(extensionAbilityInfo.second)); return; } } @@ -6615,7 +6615,7 @@ void BundleDataMgr::GetMatchExtensionInfos(const Want &want, int32_t flags, cons skillInfos.first.c_str()); break; } - ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); + ExtensionAbilityInfo extensionInfo = InnerExtensionInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); if ((static_cast(flags) & GET_EXTENSION_INFO_WITH_APPLICATION) == GET_EXTENSION_INFO_WITH_APPLICATION) { info.GetApplicationInfo( @@ -6694,7 +6694,7 @@ void BundleDataMgr::GetMatchExtensionInfosV9(const Want &want, int32_t flags, in skillInfos.first.c_str()); continue; } - ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); + ExtensionAbilityInfo extensionInfo = InnerExtensionInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); EmplaceExtensionInfo(info, skillInfos.second, extensionInfo, flags, userId, infos, std::nullopt, std::nullopt, appIndex); continue; @@ -6710,7 +6710,7 @@ void BundleDataMgr::GetMatchExtensionInfosV9(const Want &want, int32_t flags, in skillInfos.first.c_str()); break; } - ExtensionAbilityInfo extensionInfo = extensionInfos[skillInfos.first]; + ExtensionAbilityInfo extensionInfo = InnerExtensionInfo::ConvertToExtensionInfo(extensionInfos[skillInfos.first]); EmplaceExtensionInfo(info, skillInfos.second, extensionInfo, flags, userId, infos, skillIndex, matchUriIndex, appIndex); break; @@ -6723,7 +6723,7 @@ void BundleDataMgr::GetAllExtensionInfos(uint32_t flags, int32_t userId, { auto extensionInfos = info.GetInnerExtensionInfos(); for (const auto &extensionAbilityInfo : extensionInfos) { - ExtensionAbilityInfo extensionInfo = InnerBundleInfo::ConvertToExtensionInfo(extensionAbilityInfo.second); + ExtensionAbilityInfo extensionInfo = InnerExtensionInfo::ConvertToExtensionInfo(extensionAbilityInfo.second); if ((flags & static_cast(GetExtensionAbilityInfoFlag::GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION)) == static_cast(GetExtensionAbilityInfoFlag::GET_EXTENSION_ABILITY_INFO_WITH_APPLICATION)) { @@ -6768,7 +6768,7 @@ bool BundleDataMgr::QueryExtensionAbilityInfos(const ExtensionAbilityType &exten auto innerExtensionInfos = innerBundleInfo.GetInnerExtensionInfos(); for (const auto &info : innerExtensionInfos) { if (info.second.type == extensionType) { - ExtensionAbilityInfo extensionAbilityInfo = InnerBundleInfo::ConvertToExtensionInfo(info.second); + ExtensionAbilityInfo extensionAbilityInfo = InnerExtensionInfo::ConvertToExtensionInfo(info.second); innerBundleInfo.GetApplicationInfo( ApplicationFlag::GET_APPLICATION_INFO_WITH_CERTIFICATE_FINGERPRINT, responseUserId, extensionAbilityInfo.applicationInfo); diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp index 33b6a15dd4..f2e9ab2839 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp @@ -518,7 +518,7 @@ bool BundleResourceProcess::GetAbilityResourceInfos( for (const auto &item : abilityInfos) { resourceInfos.emplace_back(ConvertToLauncherAbilityResourceInfo(item.second)); } - std::map extensionAbilityInfos = innerBundleInfo.GetInnerExtensionInfos(); + std::map extensionAbilityInfos = innerBundleInfo.GetInnerExtensionInfos(); for (const auto &item : extensionAbilityInfos) { if (item.second.type != ExtensionAbilityType::INPUTMETHOD && item.second.type != ExtensionAbilityType::SHARE && @@ -527,7 +527,7 @@ bool BundleResourceProcess::GetAbilityResourceInfos( continue; } // to do - resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(InnerBundleInfo::ConvertToExtensionInfo(item.second))); + resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(InnerExtensionInfo::ConvertToExtensionInfo(item.second))); } // process overlay hap paths size_t size = resourceInfos.size(); diff --git a/services/bundlemgr/src/data/inner_extension_info.cpp b/services/bundlemgr/src/data/inner_extension_info.cpp new file mode 100644 index 0000000000..dc2abf0d71 --- /dev/null +++ b/services/bundlemgr/src/data/inner_extension_info.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "inner_extension_info.h" + +namespace OHOS { +namespace AppExecFwk { +ExtensionAbilityInfo InnerExtensionInfo::ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo) +{ + ExtensionAbilityInfo extensionAbilityInfo; + extensionAbilityInfo.visible = innerExtensionInfo.visible; + extensionAbilityInfo.enabled = innerExtensionInfo.enabled; + extensionAbilityInfo.needCreateSandbox = innerExtensionInfo.needCreateSandbox; + extensionAbilityInfo.isolationProcess = innerExtensionInfo.isolationProcess; + extensionAbilityInfo.iconId = innerExtensionInfo.iconId; + extensionAbilityInfo.labelId = innerExtensionInfo.labelId; + extensionAbilityInfo.descriptionId = innerExtensionInfo.descriptionId; + extensionAbilityInfo.priority = innerExtensionInfo.priority; + extensionAbilityInfo.uid = innerExtensionInfo.uid; + extensionAbilityInfo.appIndex = innerExtensionInfo.appIndex; + extensionAbilityInfo.type = innerExtensionInfo.type; + extensionAbilityInfo.compileMode = innerExtensionInfo.compileMode; + extensionAbilityInfo.extensionProcessMode = innerExtensionInfo.extensionProcessMode; + extensionAbilityInfo.bundleName = innerExtensionInfo.bundleName; + extensionAbilityInfo.moduleName = innerExtensionInfo.moduleName; + extensionAbilityInfo.name = innerExtensionInfo.name; + extensionAbilityInfo.srcEntrance = innerExtensionInfo.srcEntrance; + extensionAbilityInfo.icon = innerExtensionInfo.icon; + extensionAbilityInfo.label = innerExtensionInfo.label; + extensionAbilityInfo.description = innerExtensionInfo.description; + extensionAbilityInfo.readPermission = innerExtensionInfo.readPermission; + extensionAbilityInfo.writePermission = innerExtensionInfo.writePermission; + extensionAbilityInfo.uri = innerExtensionInfo.uri; + extensionAbilityInfo.extensionTypeName = innerExtensionInfo.extensionTypeName; + extensionAbilityInfo.resourcePath = innerExtensionInfo.resourcePath; + extensionAbilityInfo.hapPath = innerExtensionInfo.hapPath; + extensionAbilityInfo.process = innerExtensionInfo.process; + extensionAbilityInfo.customProcess = innerExtensionInfo.customProcess; + extensionAbilityInfo.codeLanguage = innerExtensionInfo.codeLanguage; + extensionAbilityInfo.permissions = innerExtensionInfo.permissions; + extensionAbilityInfo.appIdentifierAllowList = innerExtensionInfo.appIdentifierAllowList; + extensionAbilityInfo.metadata = innerExtensionInfo.metadata; + extensionAbilityInfo.skillUri = innerExtensionInfo.skillUri; + extensionAbilityInfo.skills = innerExtensionInfo.skills; + extensionAbilityInfo.dataGroupIds = innerExtensionInfo.dataGroupIds; + extensionAbilityInfo.validDataGroupIds = innerExtensionInfo.validDataGroupIds; + return extensionAbilityInfo; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 8a21163d35..89e06afd1f 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -179,293 +179,12 @@ const std::string NameAndUserIdToKey(const std::string &bundleName, int32_t user void from_json(const nlohmann::json &jsonObject, InnerExtensionInfo &extensionInfo) { - const auto &jsonObjectEnd = jsonObject.end(); - int32_t parseResult = ERR_OK; - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - extensionInfo.bundleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - extensionInfo.moduleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - NAME, - extensionInfo.name, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - extensionInfo.srcEntrance, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - extensionInfo.icon, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - extensionInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - extensionInfo.label, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - extensionInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - extensionInfo.description, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - extensionInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - extensionInfo.priority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - TYPE, - extensionInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_TYPE_NAME, - extensionInfo.extensionTypeName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - READ_PERMISSION, - extensionInfo.readPermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - WRITE_PERMISSION, - extensionInfo.writePermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - URI, - extensionInfo.uri, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - extensionInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPIDENTIFIER_ALLOW_LIST, - extensionInfo.appIdentifierAllowList, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - extensionInfo.visible, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - extensionInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - RESOURCE_PATH, - extensionInfo.resourcePath, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::HAP_PATH, - extensionInfo.hapPath, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - ENABLED, - extensionInfo.enabled, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - PROCESS, - extensionInfo.process, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_MODE, - extensionInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UID, - extensionInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_INDEX, - extensionInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_PROCESS_MODE, - extensionInfo.extensionProcessMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - SKILLS, - extensionInfo.skills, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - NEED_CREATE_SANDBOX, - extensionInfo.needCreateSandbox, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - DATA_GROUP_IDS, - extensionInfo.dataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_VALID_DATA_GROUP_IDS, - extensionInfo.validDataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_CUSTOM_PROCESS, - extensionInfo.customProcess, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ISOLATION_PROCESS, - extensionInfo.isolationProcess, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::CODE_LANGUAGE, - extensionInfo.codeLanguage, - false, - parseResult); - - if (parseResult != ERR_OK) { - APP_LOGE("InnerExtensionInfo from_json error : %{public}d", parseResult); - } + ExtensionFromJson(jsonObject, extensionInfo); } void to_json(nlohmann::json &jsonObject, const InnerExtensionInfo &extensionInfo) { - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, extensionInfo.bundleName}, - {Constants::MODULE_NAME, extensionInfo.moduleName}, - {NAME, extensionInfo.name}, - {SRC_ENTRANCE, extensionInfo.srcEntrance}, - {ICON, extensionInfo.icon}, - {ICON_ID, extensionInfo.iconId}, - {LABEL, extensionInfo.label}, - {LABEL_ID, extensionInfo.labelId}, - {DESCRIPTION, extensionInfo.description}, - {DESCRIPTION_ID, extensionInfo.descriptionId}, - {PRIORITY, extensionInfo.priority}, - {TYPE, extensionInfo.type}, - {EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, - {READ_PERMISSION, extensionInfo.readPermission}, - {WRITE_PERMISSION, extensionInfo.writePermission}, - {URI, extensionInfo.uri}, - {PERMISSIONS, extensionInfo.permissions}, - {APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, - {VISIBLE, extensionInfo.visible}, - {META_DATA, extensionInfo.metadata}, - {RESOURCE_PATH, extensionInfo.resourcePath}, - {Constants::HAP_PATH, extensionInfo.hapPath}, - {ENABLED, extensionInfo.enabled}, - {PROCESS, extensionInfo.process}, - {COMPILE_MODE, extensionInfo.compileMode}, - {UID, extensionInfo.uid}, - {APP_INDEX, extensionInfo.appIndex}, - {EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, - {JSON_KEY_SKILLS, extensionInfo.skills}, - {NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, - {DATA_GROUP_IDS, extensionInfo.dataGroupIds}, - {JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, - {JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, - {JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, - {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} - }; + ExtensionToJson(jsonObject, extensionInfo); } void from_json(const nlohmann::json &jsonObject, ExtendResourceInfo &extendResourceInfo) @@ -634,48 +353,6 @@ InnerBundleInfo::~InnerBundleInfo() APP_LOGD("inner bundle info instance is destroyed"); } -ExtensionAbilityInfo ConvertToExtensionInfo(const InnerExtensionInfo &innerExtensionInfo) const -{ - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.visible = innerExtensionInfo.visible; - extensionAbilityInfo.enabled = innerExtensionInfo.enabled; - extensionAbilityInfo.needCreateSandbox = innerExtensionInfo.needCreateSandbox; - extensionAbilityInfo.isolationProcess = innerExtensionInfo.isolationProcess; - extensionAbilityInfo.iconId = innerExtensionInfo.iconId; - extensionAbilityInfo.labelId = innerExtensionInfo.labelId; - extensionAbilityInfo.descriptionId = innerExtensionInfo.descriptionId; - extensionAbilityInfo.priority = innerExtensionInfo.priority; - extensionAbilityInfo.uid = innerExtensionInfo.uid; - extensionAbilityInfo.appIndex = innerExtensionInfo.appIndex; - extensionAbilityInfo.type = innerExtensionInfo.type; - extensionAbilityInfo.compileMode = innerExtensionInfo.compileMode; - extensionAbilityInfo.extensionProcessMode = innerExtensionInfo.extensionProcessMode; - extensionAbilityInfo.bundleName = innerExtensionInfo.bundleName; - extensionAbilityInfo.moduleName = innerExtensionInfo.moduleName; - extensionAbilityInfo.name = innerExtensionInfo.name; - extensionAbilityInfo.srcEntrance = innerExtensionInfo.srcEntrance; - extensionAbilityInfo.icon = innerExtensionInfo.icon; - extensionAbilityInfo.label = innerExtensionInfo.label; - extensionAbilityInfo.description = innerExtensionInfo.description; - extensionAbilityInfo.readPermission = innerExtensionInfo.readPermission; - extensionAbilityInfo.writePermission = innerExtensionInfo.writePermission; - extensionAbilityInfo.uri = innerExtensionInfo.uri; - extensionAbilityInfo.extensionTypeName = innerExtensionInfo.extensionTypeName; - extensionAbilityInfo.resourcePath = innerExtensionInfo.resourcePath; - extensionAbilityInfo.hapPath = innerExtensionInfo.hapPath; - extensionAbilityInfo.process = innerExtensionInfo.process; - extensionAbilityInfo.customProcess = innerExtensionInfo.customProcess; - extensionAbilityInfo.codeLanguage = innerExtensionInfo.codeLanguage; - extensionAbilityInfo.permissions = innerExtensionInfo.permissions; - extensionAbilityInfo.appIdentifierAllowList = innerExtensionInfo.appIdentifierAllowList; - extensionAbilityInfo.metadata = innerExtensionInfo.metadata; - extensionAbilityInfo.skillUri = innerExtensionInfo.skillUri; - extensionAbilityInfo.skills = innerExtensionInfo.skills; - extensionAbilityInfo.dataGroupIds = innerExtensionInfo.dataGroupIds; - extensionAbilityInfo.validDataGroupIds = innerExtensionInfo.validDataGroupIds; - return extensionAbilityInfo; -} - void to_json(nlohmann::json &jsonObject, const Distro &distro) { jsonObject = nlohmann::json { @@ -1954,7 +1631,7 @@ std::optional InnerBundleInfo::FindHapModuleInfo( key.append(".").append(modulePackage).append("."); for (const auto &extension : baseExtensionInfos_) { if ((extension.first.find(key) != std::string::npos) && (extension.second.moduleName == hapInfo.moduleName)) { - hapInfo.extensionInfos.emplace_back(InnerBundleInfo::ConvertToExtensionInfo(extension.second)); + hapInfo.extensionInfos.emplace_back(InnerExtensionInfo::ConvertToExtensionInfo(extension.second)); } } hapInfo.metadata = it->second.metadata; @@ -2106,7 +1783,7 @@ std::optional InnerBundleInfo::FindExtensionInfo( for (const auto &extension : baseExtensionInfos_) { if ((extension.second.name == extensionName) && (moduleName.empty() || (extension.second.moduleName == moduleName))) { - return InnerBundleInfo::ConvertToExtensionInfo(extension.second); + return InnerExtensionInfo::ConvertToExtensionInfo(extension.second); } } @@ -3048,7 +2725,7 @@ void InnerBundleInfo::GetBundleWithExtensionAbilitiesV9( if (extensionInfo.second.moduleName != hapModuleInfo.moduleName || !extensionInfo.second.enabled) { continue; } - ExtensionAbilityInfo info = InnerBundleInfo::ConvertToExtensionInfo(extensionInfo.second); + ExtensionAbilityInfo info = InnerExtensionInfo::ConvertToExtensionInfo(extensionInfo.second); info.appIndex = appIndex; if ((static_cast(flags) & static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA)) @@ -3097,7 +2774,7 @@ void InnerBundleInfo::GetBundleWithExtension( if (!extensionInfo.second.enabled) { continue; } - ExtensionAbilityInfo info = InnerBundleInfo::ConvertToExtensionInfo(extensionInfo.second); + ExtensionAbilityInfo info = InnerExtensionInfo::ConvertToExtensionInfo(extensionInfo.second); if ((static_cast(flags) & GET_BUNDLE_WITH_SKILL) != GET_BUNDLE_WITH_SKILL) { info.skills.clear(); } -- Gitee From 33579ad2ac0395390210933f3aa960a2557c02de Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Thu, 10 Jul 2025 16:18:08 +0800 Subject: [PATCH 3/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../include/bundle_constants.h | 34 +- .../include/common_json_converter.h | 320 ++++++++++++++++++ .../appexecfwk_base/include/json_serializer.h | 295 ---------------- .../src/extension_ability_info.cpp | 32 -- 4 files changed, 353 insertions(+), 328 deletions(-) create mode 100644 interfaces/inner_api/appexecfwk_base/include/common_json_converter.h diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index f797dc60aa..15cc6adedf 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -190,6 +190,38 @@ constexpr const char* ABILITY_STAGE_CODE_LANGUAGE = "abilityStageCodeLanguage"; constexpr const char* CODE_LANGUAGE_1_1 = "1.1"; constexpr const char* CODE_LANGUAGE_1_2 = "1.2"; constexpr const char* CODE_LANGUAGE_HYBRID = "hybrid"; + +inline constexpr const char* NAME = "name"; +inline constexpr const char* SRC_ENTRANCE = "srcEntrance"; +inline constexpr const char* ICON = "icon"; +inline constexpr const char* ICON_ID = "iconId"; +inline constexpr const char* LABEL = "label"; +inline constexpr const char* LABEL_ID = "labelId"; +inline constexpr const char* DESCRIPTION = "description"; +inline constexpr const char* DESCRIPTION_ID = "descriptionId"; +inline constexpr const char* PRIORITY = "priority"; +inline constexpr const char* TYPE = "type"; +inline constexpr const char* EXTENSION_TYPE_NAME = "extensionTypeName"; +inline constexpr const char* PERMISSIONS = "permissions"; +inline constexpr const char* APPIDENTIFIER_ALLOW_LIST = "appIdentifierAllowList"; +inline constexpr const char* READ_PERMISSION = "readPermission"; +inline constexpr const char* WRITE_PERMISSION = "writePermission"; +inline constexpr const char* URI = "uri"; +inline constexpr const char* VISIBLE = "visible"; +inline constexpr const char* META_DATA = "metadata"; +inline constexpr const char* RESOURCE_PATH = "resourcePath"; +inline constexpr const char* ENABLED = "enabled"; +inline constexpr const char* PROCESS = "process"; +inline constexpr const char* COMPILE_MODE = "compileMode"; +inline constexpr const char* UID = "uid"; +inline constexpr const char* APP_INDEX = "appIndex"; +inline constexpr const char* EXTENSION_PROCESS_MODE = "extensionProcessMode"; +inline constexpr const char* SKILLS = "skills"; +inline constexpr const char* NEED_CREATE_SANDBOX = "needCreateSandbox"; +inline constexpr const char* DATA_GROUP_IDS = "dataGroupIds"; +inline constexpr const char* JSON_KEY_VALID_DATA_GROUP_IDS = "validDataGroupIds"; +inline constexpr const char* JSON_KEY_CUSTOM_PROCESS = "customProcess"; +inline constexpr const char* JSON_KEY_ISOLATION_PROCESS = "isolationProcess"; } // namespace Constants } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h new file mode 100644 index 0000000000..7a0d7de131 --- /dev/null +++ b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h @@ -0,0 +1,320 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_COMMON_JSON_CONVERTER_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_COMMON_JSON_CONVERTER_H + +#include "app_log_wrapper.h" +#include "json_util.h" + +namespace OHOS { +namespace AppExecFwk { +template +void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) +{ + APP_LOGD("ExtensionFromJson begin"); + const auto &jsonObjectEnd = jsonObject.end(); + int32_t parseResult = ERR_OK; + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::BUNDLE_NAME, + extensionInfo.bundleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::MODULE_NAME, + extensionInfo.moduleName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::NAME, + extensionInfo.name, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::SRC_ENTRANCE, + extensionInfo.srcEntrance, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::ICON, + extensionInfo.icon, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::ICON_ID, + extensionInfo.iconId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::LABEL, + extensionInfo.label, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::LABEL_ID, + extensionInfo.labelId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::DESCRIPTION, + extensionInfo.description, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::DESCRIPTION_ID, + extensionInfo.descriptionId, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::PRIORITY, + extensionInfo.priority, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::TYPE, + extensionInfo.type, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::EXTENSION_TYPE_NAME, + extensionInfo.extensionTypeName, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::READ_PERMISSION, + extensionInfo.readPermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::WRITE_PERMISSION, + extensionInfo.writePermission, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::URI, + extensionInfo.uri, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::PERMISSIONS, + extensionInfo.permissions, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::APPIDENTIFIER_ALLOW_LIST, + extensionInfo.appIdentifierAllowList, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::VISIBLE, + extensionInfo.visible, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::META_DATA, + extensionInfo.metadata, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::RESOURCE_PATH, + extensionInfo.resourcePath, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::HAP_PATH, + extensionInfo.hapPath, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::ENABLED, + extensionInfo.enabled, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::PROCESS, + extensionInfo.process, + false, + parseResult); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::COMPILE_MODE, + extensionInfo.compileMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::UID, + extensionInfo.uid, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::APP_INDEX, + extensionInfo.appIndex, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::EXTENSION_PROCESS_MODE, + extensionInfo.extensionProcessMode, + JsonType::NUMBER, + false, + parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::SKILLS, + extensionInfo.skills, + JsonType::ARRAY, + false, + parseResult, + ArrayType::OBJECT); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::NEED_CREATE_SANDBOX, + extensionInfo.needCreateSandbox, + false, + parseResult); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::DATA_GROUP_IDS, + extensionInfo.dataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + GetValueIfFindKey>(jsonObject, + jsonObjectEnd, + Constants::JSON_KEY_VALID_DATA_GROUP_IDS, + extensionInfo.validDataGroupIds, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::JSON_KEY_CUSTOM_PROCESS, + extensionInfo.customProcess, + false, + parseResult); + BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::JSON_KEY_ISOLATION_PROCESS, + extensionInfo.isolationProcess, + false, + parseResult); + BMSJsonUtil::GetStrValueIfFindKey(jsonObject, + jsonObjectEnd, + Constants::CODE_LANGUAGE, + extensionInfo.codeLanguage, + false, + parseResult); + + if (parseResult != ERR_OK) { + APP_LOGE("ExtensionAbilityInfo from_json error : %{public}d", parseResult); + } +} + +template +void ExtensionToJson(nlohmann::json &jsonObject, const T &extensionInfo) +{ + APP_LOGD("ExtensionToJson begin"); + jsonObject = nlohmann::json { + {Constants::BUNDLE_NAME, extensionInfo.bundleName}, + {Constants::MODULE_NAME, extensionInfo.moduleName}, + {Constants::NAME, extensionInfo.name}, + {Constants::SRC_ENTRANCE, extensionInfo.srcEntrance}, + {Constants::ICON, extensionInfo.icon}, + {Constants::ICON_ID, extensionInfo.iconId}, + {Constants::LABEL, extensionInfo.label}, + {Constants::LABEL_ID, extensionInfo.labelId}, + {Constants::DESCRIPTION, extensionInfo.description}, + {Constants::DESCRIPTION_ID, extensionInfo.descriptionId}, + {Constants::PRIORITY, extensionInfo.priority}, + {Constants::TYPE, extensionInfo.type}, + {Constants::EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, + {Constants::READ_PERMISSION, extensionInfo.readPermission}, + {Constants::WRITE_PERMISSION, extensionInfo.writePermission}, + {Constants::URI, extensionInfo.uri}, + {Constants::PERMISSIONS, extensionInfo.permissions}, + {Constants::APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, + {Constants::VISIBLE, extensionInfo.visible}, + {Constants::META_DATA, extensionInfo.metadata}, + {Constants::RESOURCE_PATH, extensionInfo.resourcePath}, + {Constants::HAP_PATH, extensionInfo.hapPath}, + {Constants::ENABLED, extensionInfo.enabled}, + {Constants::PROCESS, extensionInfo.process}, + {Constants::COMPILE_MODE, extensionInfo.compileMode}, + {Constants::UID, extensionInfo.uid}, + {Constants::APP_INDEX, extensionInfo.appIndex}, + {Constants::EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, + {Constants::JSON_KEY_SKILLS, extensionInfo.skills}, + {Constants::NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, + {Constants::DATA_GROUP_IDS, extensionInfo.dataGroupIds}, + {Constants::JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, + {Constants::JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, + {Constants::JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, + {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} + }; +} +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_COMMON_JSON_CONVERTER_H \ No newline at end of file diff --git a/interfaces/inner_api/appexecfwk_base/include/json_serializer.h b/interfaces/inner_api/appexecfwk_base/include/json_serializer.h index 38a9462bcf..be4c8ed918 100644 --- a/interfaces/inner_api/appexecfwk_base/include/json_serializer.h +++ b/interfaces/inner_api/appexecfwk_base/include/json_serializer.h @@ -166,301 +166,6 @@ void to_json(nlohmann::json &jsonObject, const PluginBundleInfo &pluginBundleInf void from_json(const nlohmann::json &jsonObject, PluginBundleInfo &pluginBundleInfo); void to_json(nlohmann::json &jsonObject, const PluginModuleInfo &pluginModuleInfo); void from_json(const nlohmann::json &jsonObject, PluginModuleInfo &pluginModuleInfo); - -template -void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) -{ - APP_LOGD("ExtensionFromJson begin"); - const auto &jsonObjectEnd = jsonObject.end(); - int32_t parseResult = ERR_OK; - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::BUNDLE_NAME, - extensionInfo.bundleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::MODULE_NAME, - extensionInfo.moduleName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - NAME, - extensionInfo.name, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - SRC_ENTRANCE, - extensionInfo.srcEntrance, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON, - extensionInfo.icon, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - ICON_ID, - extensionInfo.iconId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL, - extensionInfo.label, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - LABEL_ID, - extensionInfo.labelId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION, - extensionInfo.description, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - DESCRIPTION_ID, - extensionInfo.descriptionId, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - PRIORITY, - extensionInfo.priority, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - TYPE, - extensionInfo.type, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_TYPE_NAME, - extensionInfo.extensionTypeName, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - READ_PERMISSION, - extensionInfo.readPermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - WRITE_PERMISSION, - extensionInfo.writePermission, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - URI, - extensionInfo.uri, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - PERMISSIONS, - extensionInfo.permissions, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - APPIDENTIFIER_ALLOW_LIST, - extensionInfo.appIdentifierAllowList, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - VISIBLE, - extensionInfo.visible, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - META_DATA, - extensionInfo.metadata, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - RESOURCE_PATH, - extensionInfo.resourcePath, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::HAP_PATH, - extensionInfo.hapPath, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - ENABLED, - extensionInfo.enabled, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - PROCESS, - extensionInfo.process, - false, - parseResult); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - COMPILE_MODE, - extensionInfo.compileMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UID, - extensionInfo.uid, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - APP_INDEX, - extensionInfo.appIndex, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - EXTENSION_PROCESS_MODE, - extensionInfo.extensionProcessMode, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - SKILLS, - extensionInfo.skills, - JsonType::ARRAY, - false, - parseResult, - ArrayType::OBJECT); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - NEED_CREATE_SANDBOX, - extensionInfo.needCreateSandbox, - false, - parseResult); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - DATA_GROUP_IDS, - extensionInfo.dataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - GetValueIfFindKey>(jsonObject, - jsonObjectEnd, - JSON_KEY_VALID_DATA_GROUP_IDS, - extensionInfo.validDataGroupIds, - JsonType::ARRAY, - false, - parseResult, - ArrayType::STRING); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_CUSTOM_PROCESS, - extensionInfo.customProcess, - false, - parseResult); - BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, - jsonObjectEnd, - JSON_KEY_ISOLATION_PROCESS, - extensionInfo.isolationProcess, - false, - parseResult); - BMSJsonUtil::GetStrValueIfFindKey(jsonObject, - jsonObjectEnd, - Constants::CODE_LANGUAGE, - extensionInfo.codeLanguage, - false, - parseResult); - - if (parseResult != ERR_OK) { - APP_LOGE("ExtensionAbilityInfo from_json error : %{public}d", parseResult); - } -} - -template -void ExtensionToJson(nlohmann::json &jsonObject, const T &extensionInfo) -{ - APP_LOGD("ExtensionToJson begin"); - jsonObject = nlohmann::json { - {Constants::BUNDLE_NAME, extensionInfo.bundleName}, - {Constants::MODULE_NAME, extensionInfo.moduleName}, - {NAME, extensionInfo.name}, - {SRC_ENTRANCE, extensionInfo.srcEntrance}, - {ICON, extensionInfo.icon}, - {ICON_ID, extensionInfo.iconId}, - {LABEL, extensionInfo.label}, - {LABEL_ID, extensionInfo.labelId}, - {DESCRIPTION, extensionInfo.description}, - {DESCRIPTION_ID, extensionInfo.descriptionId}, - {PRIORITY, extensionInfo.priority}, - {TYPE, extensionInfo.type}, - {EXTENSION_TYPE_NAME, extensionInfo.extensionTypeName}, - {READ_PERMISSION, extensionInfo.readPermission}, - {WRITE_PERMISSION, extensionInfo.writePermission}, - {URI, extensionInfo.uri}, - {PERMISSIONS, extensionInfo.permissions}, - {APPIDENTIFIER_ALLOW_LIST, extensionInfo.appIdentifierAllowList}, - {VISIBLE, extensionInfo.visible}, - {META_DATA, extensionInfo.metadata}, - {RESOURCE_PATH, extensionInfo.resourcePath}, - {Constants::HAP_PATH, extensionInfo.hapPath}, - {ENABLED, extensionInfo.enabled}, - {PROCESS, extensionInfo.process}, - {COMPILE_MODE, extensionInfo.compileMode}, - {UID, extensionInfo.uid}, - {APP_INDEX, extensionInfo.appIndex}, - {EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, - {JSON_KEY_SKILLS, extensionInfo.skills}, - {NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, - {DATA_GROUP_IDS, extensionInfo.dataGroupIds}, - {JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, - {JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, - {JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, - {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} - }; -} } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_JSON_SERIALIZER_H diff --git a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp index 299a501655..ea9d485c54 100644 --- a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp @@ -28,40 +28,8 @@ namespace OHOS { namespace AppExecFwk { -const char* JSON_KEY_SKILLS = "skills"; namespace { -const char* NAME = "name"; -const char* SRC_ENTRANCE = "srcEntrance"; -const char* ICON = "icon"; -const char* ICON_ID = "iconId"; -const char* LABEL = "label"; -const char* LABEL_ID = "labelId"; -const char* DESCRIPTION = "description"; -const char* DESCRIPTION_ID = "descriptionId"; -const char* PRIORITY = "priority"; -const char* TYPE = "type"; -const char* EXTENSION_TYPE_NAME = "extensionTypeName"; -const char* PERMISSIONS = "permissions"; -const char* APPIDENTIFIER_ALLOW_LIST = "appIdentifierAllowList"; -const char* READ_PERMISSION = "readPermission"; -const char* WRITE_PERMISSION = "writePermission"; -const char* URI = "uri"; -const char* VISIBLE = "visible"; -const char* META_DATA = "metadata"; -const char* RESOURCE_PATH = "resourcePath"; -const char* ENABLED = "enabled"; -const char* PROCESS = "process"; -const char* COMPILE_MODE = "compileMode"; -const char* UID = "uid"; -const char* APP_INDEX = "appIndex"; const uint32_t ABILITY_CAPACITY = 204800; // 200K -const char* EXTENSION_PROCESS_MODE = "extensionProcessMode"; -const char* SKILLS = "skills"; -const char* NEED_CREATE_SANDBOX = "needCreateSandbox"; -const char* DATA_GROUP_IDS = "dataGroupIds"; -const char* JSON_KEY_VALID_DATA_GROUP_IDS = "validDataGroupIds"; -const char* JSON_KEY_CUSTOM_PROCESS = "customProcess"; -const char* JSON_KEY_ISOLATION_PROCESS = "isolationProcess"; const std::unordered_map EXTENSION_TYPE_MAP = { { "form", ExtensionAbilityType::FORM }, -- Gitee From 41dca3be48506a2b6543273bb989c7b33fe6c1db Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Thu, 10 Jul 2025 16:19:43 +0800 Subject: [PATCH 4/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../inner_api/appexecfwk_base/src/extension_ability_info.cpp | 1 + services/bundlemgr/src/inner_bundle_info.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp index ea9d485c54..f4d9cecdaf 100644 --- a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp @@ -21,6 +21,7 @@ #include #include "bundle_constants.h" +#include "common_json_converter.h" #include "json_util.h" #include "nlohmann/json.hpp" #include "parcel_macro.h" diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index 89e06afd1f..50382f7455 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -27,6 +27,7 @@ #include "bundle_mgr_client.h" #include "bundle_permission_mgr.h" #include "bundle_util.h" +#include "common_json_converter.h" #include "free_install_params.h" #include "installd_client.h" -- Gitee From a789788cb27e8845371da138e3cee4831d23d0d4 Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Thu, 10 Jul 2025 17:04:14 +0800 Subject: [PATCH 5/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../include/bundle_constants.h | 2 - .../include/common_json_converter.h | 2 +- .../bundlemgr/include/inner_bundle_info.h | 2 +- .../bundle_resource_process.cpp | 4 +- .../src/data/inner_extension_info.cpp | 2 +- .../bms_bundle_aot_test/bms_data_aot_test.cpp | 14 +++---- .../bms_bundle_data_storage_database_test.cpp | 37 ++++++++----------- .../bms_bundle_data_mgr_test.cpp | 10 ++--- .../bms_bundle_data_mgr_test_three.cpp | 24 ++++++------ .../bms_bundle_data_mgr_test_two.cpp | 10 ++--- .../bms_bundle_kit_service_test.cpp | 20 ++++------ .../bms_bundle_manager_test_three.cpp | 7 ++-- .../bms_data_mgr_test/bms_data_mgr_test.cpp | 24 +++++------- .../bmsdriverinstaller_fuzzer.cpp | 25 ++++++------- 14 files changed, 78 insertions(+), 105 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index 15cc6adedf..30947ad596 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -213,8 +213,6 @@ inline constexpr const char* RESOURCE_PATH = "resourcePath"; inline constexpr const char* ENABLED = "enabled"; inline constexpr const char* PROCESS = "process"; inline constexpr const char* COMPILE_MODE = "compileMode"; -inline constexpr const char* UID = "uid"; -inline constexpr const char* APP_INDEX = "appIndex"; inline constexpr const char* EXTENSION_PROCESS_MODE = "extensionProcessMode"; inline constexpr const char* SKILLS = "skills"; inline constexpr const char* NEED_CREATE_SANDBOX = "needCreateSandbox"; diff --git a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h index 7a0d7de131..cf1de413fc 100644 --- a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h +++ b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h @@ -306,7 +306,7 @@ void ExtensionToJson(nlohmann::json &jsonObject, const T &extensionInfo) {Constants::UID, extensionInfo.uid}, {Constants::APP_INDEX, extensionInfo.appIndex}, {Constants::EXTENSION_PROCESS_MODE, extensionInfo.extensionProcessMode}, - {Constants::JSON_KEY_SKILLS, extensionInfo.skills}, + {Constants::SKILLS, extensionInfo.skills}, {Constants::NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, {Constants::DATA_GROUP_IDS, extensionInfo.dataGroupIds}, {Constants::JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index bd99afb895..a3d9f54f61 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -35,7 +35,7 @@ #include "inner_app_quick_fix.h" #include "inner_bundle_clone_info.h" #include "inner_bundle_user_info.h" -#include "inner_extension_info.h" +#include "data/inner_extension_info.h" #include "ipc/check_encryption_param.h" #include "json_util.h" #include "plugin/plugin_bundle_info.h" diff --git a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp index f2e9ab2839..4b2b723adb 100644 --- a/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp +++ b/services/bundlemgr/src/bundle_resource/bundle_resource_process.cpp @@ -526,8 +526,8 @@ bool BundleResourceProcess::GetAbilityResourceInfos( APP_LOGD("skip extension type %{public}d", item.second.type); continue; } - // to do - resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(InnerExtensionInfo::ConvertToExtensionInfo(item.second))); + ExtensionAbilityInfo extensionInfo = InnerExtensionInfo::ConvertToExtensionInfo(item.second); + resourceInfos.emplace_back(ConvertToExtensionAbilityResourceInfo(extensionInfo)); } // process overlay hap paths size_t size = resourceInfos.size(); diff --git a/services/bundlemgr/src/data/inner_extension_info.cpp b/services/bundlemgr/src/data/inner_extension_info.cpp index dc2abf0d71..78d7b9b6e1 100644 --- a/services/bundlemgr/src/data/inner_extension_info.cpp +++ b/services/bundlemgr/src/data/inner_extension_info.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "inner_extension_info.h" +#include "data/inner_extension_info.h" namespace OHOS { namespace AppExecFwk { diff --git a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp index aa49d5c1d0..018da5c381 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_aot_test/bms_data_aot_test.cpp @@ -1951,10 +1951,9 @@ HWTEST_F(BmsAOTMgrTest, IsDriverForAllUser_0100, Function | SmallTest | Level0) installer.InitDataMgr(); InnerBundleInfo info; - ExtensionAbilityInfo abilityInfo; - abilityInfo.type = ExtensionAbilityType::DRIVER; - // to do - info.InsertExtensionInfo("key", abilityInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + info.InsertExtensionInfo("key", innerExtensionInfo); installer.dataMgr_->bundleInfos_.try_emplace(AOT_BUNDLE_NAME, info); bool ret = installer.IsDriverForAllUser(AOT_BUNDLE_NAME); EXPECT_TRUE(ret); @@ -1974,10 +1973,9 @@ HWTEST_F(BmsAOTMgrTest, GetBundleNamesForNewUser_0100, Function | SmallTest | Le auto dataMgr = GetBundleDataMgr(); ASSERT_NE(dataMgr, nullptr); InnerBundleInfo info; - ExtensionAbilityInfo abilityInfo; - abilityInfo.type = ExtensionAbilityType::DRIVER; - // to do - info.InsertExtensionInfo("key", abilityInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + info.InsertExtensionInfo("key", innerExtensionInfo); dataMgr->bundleInfos_.try_emplace(AOT_BUNDLE_NAME, info); OHOS::system::SetParameter(ServiceConstants::IS_DRIVER_FOR_ALL_USERS, "false"); std::vector ret = dataMgr->GetBundleNamesForNewUser(); diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index aeb38b1c55..d575cc0900 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -2130,13 +2130,12 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0700, Function | Smal ShortcutInfo shortcutInfo2; CommonEventInfo commonEvent1; CommonEventInfo commonEvent2; - ExtensionAbilityInfo extensionInfo; - extensionInfo.name = TEST_KEY; + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.name = TEST_KEY; std::vector skill; innerModuleInfo.extensionKeys.emplace_back(TEST_KEY1); innerModuleInfo.extensionSkillKeys.emplace_back(TEST_KEY2); - // to do - info.InsertExtensionInfo(TEST_KEY1, extensionInfo); + info.InsertExtensionInfo(TEST_KEY1, innerExtensionInfo); info.InsertExtensionSkillInfo(TEST_KEY2, skill); info.InsertInnerModuleInfo(WRONG_MODULEPACKAGE, innerModuleInfo); info.InsertShortcutInfos(WRONG, shortcutInfo1); @@ -2144,7 +2143,6 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_0700, Function | Smal info.InsertCommonEvents(WRONG, commonEvent1); info.InsertCommonEvents(WRONG_MODULEPACKAGE, commonEvent2); info.RemoveModuleInfo(WRONG_MODULEPACKAGE); - // to do auto ret1 = info.GetInnerExtensionInfos(); auto ret2 = info.GetExtensionSkillInfos(); EXPECT_EQ(ret1[TEST_KEY1].name, ""); @@ -2356,14 +2354,13 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_1800, Function | Smal auto ret = info.FindExtensionInfo(moduleName, extensionName); EXPECT_EQ(ret, std::nullopt); - ExtensionAbilityInfo extensionInfo; + InnerExtensionInfo innerExtensionInfo; moduleName = MODULE_NAME; extensionName = bundleName; - extensionInfo.bundleName = bundleName; - extensionInfo.moduleName = moduleName; - extensionInfo.name = extensionName; - // to do - info.InsertExtensionInfo(TEST_KEY, extensionInfo); + innerExtensionInfo.bundleName = bundleName; + innerExtensionInfo.moduleName = moduleName; + innerExtensionInfo.name = extensionName; + info.InsertExtensionInfo(TEST_KEY, innerExtensionInfo); ret = info.FindExtensionInfo(moduleName, extensionName); EXPECT_EQ((*ret).bundleName, bundleName); } @@ -2489,20 +2486,18 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_2600, Function | Smal info.GetBundleWithExtensionAbilitiesV9(FLAG, hapModuleInfo); EXPECT_EQ(hapModuleInfo.extensionInfos.empty(), true); - // to do - ExtensionAbilityInfo extensionInfo; + InnerExtensionInfo innerExtensionInfo; int32_t flag = 8; - extensionInfo.moduleName = moduleName; - extensionInfo.enabled = false; - // to do - info.InsertExtensionInfo(TEST_KEY, extensionInfo); + innerExtensionInfo.moduleName = moduleName; + innerExtensionInfo.enabled = false; + info.InsertExtensionInfo(TEST_KEY, innerExtensionInfo); info.GetBundleWithExtensionAbilitiesV9(flag, hapModuleInfo); EXPECT_EQ(hapModuleInfo.extensionInfos.empty(), true); - std::map extensionInfos; - extensionInfo.enabled = true; - hapModuleInfo.moduleName = extensionInfo.moduleName; - extensionInfos["baseExtensionInfos_"] = extensionInfo; + std::map extensionInfos; + innerExtensionInfo.enabled = true; + hapModuleInfo.moduleName = innerExtensionInfo.moduleName; + extensionInfos["baseExtensionInfos_"] = innerExtensionInfo; info.AddModuleExtensionInfos(extensionInfos); info.GetBundleWithExtensionAbilitiesV9(flag, hapModuleInfo); EXPECT_EQ(hapModuleInfo.extensionInfos.empty(), false); diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp index ec7ce6f8d6..08a8e4f595 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp @@ -604,13 +604,11 @@ void BmsBundleDataMgrTest::MockInstallExtension(const std::string &bundleName, InnerModuleInfo moduleInfo = MockModuleInfo(moduleName); std::string keyName = bundleName + "." + moduleName + "." + extensionName; std::string keyName02 = bundleName + "." + moduleName + "." + extensionName + "02"; - ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); - ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); + InnerExtensionInfo innerExtensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); + InnerExtensionInfo innerExtensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; - // to do - innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); - // to do - innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); + innerBundleInfo.InsertExtensionInfo(keyName, innerExtensionInfo); + innerBundleInfo.InsertExtensionInfo(keyName02, innerExtensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; skill.actions = {ACTION}; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp index 57577260c2..f27792d589 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp @@ -386,7 +386,7 @@ public: void MockUninstallBundle(const std::string &bundleName) const; AbilityInfo MockAbilityInfo( const std::string &bundleName, const std::string &module, const std::string &abilityName) const; - ExtensionAbilityInfo MockExtensionInfo( + InnerExtensionInfo MockExtensionInfo( const std::string &bundleName, const std::string &module, const std::string &extensionName) const; InnerModuleInfo MockModuleInfo(const std::string &moduleName) const; FormInfo MockFormInfo( @@ -595,13 +595,11 @@ void BmsBundleDataMgrTest3::MockInstallExtension(const std::string &bundleName, InnerModuleInfo moduleInfo = MockModuleInfo(moduleName); std::string keyName = bundleName + "." + moduleName + "." + extensionName; std::string keyName02 = bundleName + "." + moduleName + "." + extensionName + "02"; - ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); - ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); + InnerExtensionInfo innerExtensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); + InnerExtensionInfo innerExtensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; - // to do - innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); - // to do - innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); + innerBundleInfo.InsertExtensionInfo(keyName, innerExtensionInfo); + innerBundleInfo.InsertExtensionInfo(keyName02, innerExtensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; skill.actions = {ACTION}; @@ -858,14 +856,14 @@ AbilityInfo BmsBundleDataMgrTest3::MockAbilityInfo( return abilityInfo; } -ExtensionAbilityInfo BmsBundleDataMgrTest3::MockExtensionInfo( +InnerExtensionInfo BmsBundleDataMgrTest3::MockExtensionInfo( const std::string &bundleName, const std::string &moduleName, const std::string &extensionName) const { - ExtensionAbilityInfo extensionInfo; - extensionInfo.name = extensionName; - extensionInfo.bundleName = bundleName; - extensionInfo.moduleName = moduleName; - return extensionInfo; + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.name = extensionName; + innerExtensionInfo.bundleName = bundleName; + innerExtensionInfo.moduleName = moduleName; + return innerExtensionInfo; } void BmsBundleDataMgrTest3::MockInnerBundleInfo(const std::string &bundleName, const std::string &moduleName, diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp index b9e97a3e50..77de58476d 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp @@ -601,13 +601,11 @@ void BmsBundleDataMgrTest2::MockInstallExtension(const std::string &bundleName, InnerModuleInfo moduleInfo = MockModuleInfo(moduleName); std::string keyName = bundleName + "." + moduleName + "." + extensionName; std::string keyName02 = bundleName + "." + moduleName + "." + extensionName + "02"; - ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); - ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); + InnerExtensionInfo innerExtensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); + InnerExtensionInfo innerExtensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; - // to do - innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); - // to do - innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); + innerBundleInfo.InsertExtensionInfo(keyName, innerExtensionInfo); + innerBundleInfo.InsertExtensionInfo(keyName02, innerExtensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; skill.actions = {ACTION}; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index 715398d554..25f620e3dc 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -731,13 +731,11 @@ void BmsBundleKitServiceTest::MockInstallExtension(const std::string &bundleName InnerModuleInfo moduleInfo = MockModuleInfo(moduleName); std::string keyName = bundleName + "." + moduleName + "." + extensionName; std::string keyName02 = bundleName + "." + moduleName + "." + extensionName + "02"; - ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); - ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); + InnerExtensionInfo innerExtensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); + InnerExtensionInfo innerExtensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; - // to do - innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); - // to do - innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); + innerBundleInfo.InsertExtensionInfo(keyName, innerExtensionInfo); + innerBundleInfo.InsertExtensionInfo(keyName02, innerExtensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill; skill.actions = {ACTION}; @@ -755,13 +753,11 @@ void BmsBundleKitServiceTest::MockInstallExtensionWithUri(const std::string &bun InnerModuleInfo moduleInfo = MockModuleInfo(moduleName); std::string keyName = bundleName + "." + moduleName + "." + extensionName; std::string keyName02 = bundleName + "." + moduleName + "." + extensionName + "02"; - ExtensionAbilityInfo extensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); - ExtensionAbilityInfo extensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); + InnerExtensionInfo innerExtensionInfo = MockExtensionInfo(bundleName, moduleName, extensionName); + InnerExtensionInfo innerExtensionInfo02 = MockExtensionInfo(bundleName, moduleName, extensionName + "02"); InnerBundleInfo innerBundleInfo; - // to do - innerBundleInfo.InsertExtensionInfo(keyName, extensionInfo); - // to do - innerBundleInfo.InsertExtensionInfo(keyName02, extensionInfo02); + innerBundleInfo.InsertExtensionInfo(keyName, innerExtensionInfo); + innerBundleInfo.InsertExtensionInfo(keyName02, innerExtensionInfo02); innerBundleInfo.InsertInnerModuleInfo(moduleName, moduleInfo); Skill skill = MockExtensionSkillInfo(); std::vector skills; diff --git a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp index f76b6336b6..c643438c47 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_manager_test/bms_bundle_manager_test_three.cpp @@ -1712,10 +1712,9 @@ HWTEST_F(BmsBundleManagerTest3, GetBundleNamesForNewUser_0200, Function | SmallT auto dataMgr = GetBundleDataMgr(); ASSERT_NE(dataMgr, nullptr); InnerBundleInfo info; - ExtensionAbilityInfo abilityInfo; - abilityInfo.type = ExtensionAbilityType::DRIVER; - // to do - info.InsertExtensionInfo("key", abilityInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + info.InsertExtensionInfo("key", innerExtensionInfo); dataMgr->bundleInfos_.try_emplace(BUNDLE_NAME, info); std::vector ret = dataMgr->GetBundleNamesForNewUser(); EXPECT_EQ(ret.size(), 1); diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp index 4c664d98ac..20bd8be226 100644 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp @@ -2425,9 +2425,8 @@ HWTEST_F(BmsDataMgrTest, GetAllExtensionInfos_0100, Function | SmallTest | Level int32_t appIndex = 0; dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), true); - ExtensionAbilityInfo extensionAbilityInfo; - // to do - info.InsertExtensionInfo("", extensionAbilityInfo); + InnerExtensionInfo innerExtensionInfo; + info.InsertExtensionInfo("", innerExtensionInfo); dataMgr->GetAllExtensionInfos(flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), false); flags = 1; @@ -2452,9 +2451,8 @@ HWTEST_F(BmsDataMgrTest, GetOneExtensionInfosByExtensionTypeName_0100, Function std::string typeName = ""; dataMgr->GetOneExtensionInfosByExtensionTypeName(typeName, flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), true); - ExtensionAbilityInfo extensionAbilityInfo; - // to do - info.InsertExtensionInfo("", extensionAbilityInfo); + InnerExtensionInfo innerExtensionInfo; + info.InsertExtensionInfo("", innerExtensionInfo); dataMgr->GetOneExtensionInfosByExtensionTypeName(typeName, flags, userId, info, infos, appIndex); EXPECT_EQ(infos.empty(), false); flags = 1; @@ -4227,10 +4225,9 @@ HWTEST_F(BmsDataMgrTest, GetExtensionAbilityInfoByTypeName_0001, TestSize.Level1 bundleDataMgr.AddInnerBundleInfo(bundleName, info); bundleDataMgr.GetExtensionAbilityInfoByTypeName(flags, userId, infos, typeName); - ExtensionAbilityInfo extensionInfo; - extensionInfo.name = "test_extensionInfo"; - // to do - info.InsertExtensionInfo("test_key", extensionInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.name = "test_innerExtensionInfo"; + info.InsertExtensionInfo("test_key", innerExtensionInfo); bundleDataMgr.GetExtensionAbilityInfoByTypeName(flags, userId, infos, typeName); EXPECT_FALSE(bundleDataMgr.bundleInfos_.empty()); } @@ -6022,10 +6019,9 @@ HWTEST_F(BmsDataMgrTest, GetAllExtensionBundleNames_0002, Function | MediumTest { // Create test data InnerBundleInfo info; - ExtensionAbilityInfo extensionInfo; - extensionInfo.type = ExtensionAbilityType::INPUTMETHOD; - // to do - info.InsertExtensionInfo("test.extension", extensionInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::INPUTMETHOD; + info.InsertExtensionInfo("test.extension", innerExtensionInfo); std::shared_lock lock(dataMgr_->bundleInfoMutex_); dataMgr_->bundleInfos_.emplace("test.bundle", info); std::vector types = { diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp index 92fe4cef6a..fdbe8461e7 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdriverinstaller_fuzzer/bmsdriverinstaller_fuzzer.cpp @@ -69,21 +69,18 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) installer.FilterDriverSoFile(newInfo1, metaData, dirMap, isModuleExisted); installer.RemoveDriverSoFile(newInfo1, newInfo1.GetCurrentModulePackage(), isModuleExisted); - ExtensionAbilityInfo extensionInfo; - extensionInfo.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - extensionInfo.bundleName = newInfo1.GetBundleName(); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + innerExtensionInfo.bundleName = newInfo1.GetBundleName(); std::string extensionKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); - // to do - installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); - extensionInfo.type = ExtensionAbilityType::DRIVER; - // to do - newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); - installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); - extensionInfo.metadata.push_back(metaData); - // to do - newInfo1.InsertExtensionInfo(extensionKey, extensionInfo); - installer.RemoveDriverSoFile(newInfo1, extensionInfo.moduleName, isModuleExisted); + newInfo1.InsertExtensionInfo(extensionKey, innerExtensionInfo); + installer.RemoveDriverSoFile(newInfo1, innerExtensionInfo.moduleName, isModuleExisted); + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + newInfo1.InsertExtensionInfo(extensionKey, innerExtensionInfo); + installer.RemoveDriverSoFile(newInfo1, innerExtensionInfo.moduleName, isModuleExisted); + innerExtensionInfo.metadata.push_back(metaData); + newInfo1.InsertExtensionInfo(extensionKey, innerExtensionInfo); + installer.RemoveDriverSoFile(newInfo1, innerExtensionInfo.moduleName, isModuleExisted); installer.CreateDriverSoDestinedDir("", "", "", "", isModuleExisted); std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); -- Gitee From 4ee0503ba11cd0aaf5a0d90c6c084670bc3d1bb8 Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Thu, 10 Jul 2025 17:31:33 +0800 Subject: [PATCH 6/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../include/common_json_converter.h | 3 +- .../bms_bundle_data_group_test.cpp | 6 +-- .../bms_bundle_data_storage_database_test.cpp | 40 +++++++------- .../bms_bundle_install_driver_test.cpp | 52 +++++++++---------- .../bms_bundle_data_mgr_test_three.cpp | 2 +- .../bms_bundle_data_mgr_test_two.cpp | 4 +- .../bms_bundle_resource_test.cpp | 20 +++---- 7 files changed, 63 insertions(+), 64 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h index cf1de413fc..91848395a9 100644 --- a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h +++ b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h @@ -267,9 +267,8 @@ void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) extensionInfo.codeLanguage, false, parseResult); - if (parseResult != ERR_OK) { - APP_LOGE("ExtensionAbilityInfo from_json error : %{public}d", parseResult); + APP_LOGE("ExtensionFromJson error : %{public}d", parseResult); } } diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_group_test/bms_bundle_data_group_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_group_test/bms_bundle_data_group_test.cpp index 1bb77fb268..1ec32222c4 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_group_test/bms_bundle_data_group_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_group_test/bms_bundle_data_group_test.cpp @@ -1483,9 +1483,9 @@ HWTEST_F(BmsBundleDataGroupTest, BaseBundleInstaller_0002, Function | SmallTest ASSERT_NE(dataMgr, nullptr); installer.dataMgr_ = dataMgr; InnerBundleInfo innerBundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.type = ExtensionAbilityType::DRIVER; - innerBundleInfo.baseExtensionInfos_["testExt"] = extensionAbilityInfo; + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + innerBundleInfo.baseExtensionInfos_["testExt"] = innerExtensionInfo; dataMgr->bundleInfos_["test.bundleName"] = innerBundleInfo; InstallParam installParam; diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index d575cc0900..0de5522ca4 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -2992,10 +2992,10 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5100, Function | Smal HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5200, Function | SmallTest | Level1) { InnerBundleInfo bundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.uri = URI; - ExtensionAbilityInfo baseExtensionInfo; - bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo)); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.uri = URI; + InnerExtensionInfo baseExtensionInfo; + bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo); EXPECT_TRUE(ret); } @@ -3009,12 +3009,12 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5300, Function | Smal { InnerBundleInfo bundleInfo; bundleInfo.baseExtensionInfos_.clear(); - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.uri = URI; - ExtensionAbilityInfo baseExtensionInfo; + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.uri = URI; + InnerExtensionInfo baseExtensionInfo; bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo); EXPECT_FALSE(ret); - bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo)); + bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); ret = bundleInfo.FindExtensionAbilityInfoByUri("URI", baseExtensionInfo); EXPECT_FALSE(ret); } @@ -3182,10 +3182,10 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6100, Function | Smal HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6200, Function | SmallTest | Level1) { InnerBundleInfo bundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.moduleName = MODULE_NAME; - extensionAbilityInfo.needCreateSandbox = true; - bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo)); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.moduleName = MODULE_NAME; + innerExtensionInfo.needCreateSandbox = true; + bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); auto ret = bundleInfo.GetAllExtensionDirsInSpecifiedModule(MODULE_NAME); EXPECT_FALSE(ret.empty()); } @@ -3198,9 +3198,9 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6200, Function | Smal HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6300, Function | SmallTest | Level1) { InnerBundleInfo bundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.needCreateSandbox = true; - bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo)); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.needCreateSandbox = true; + bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); auto ret = bundleInfo.GetAllExtensionDirs(); EXPECT_FALSE(ret.empty()); } @@ -3213,10 +3213,10 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6300, Function | Smal HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_6400, Function | SmallTest | Level1) { InnerBundleInfo bundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; + InnerExtensionInfo innerExtensionInfo; std::vector dataGroupIds; dataGroupIds.push_back(TEST_UID); - bundleInfo.baseExtensionInfos_.insert(std::make_pair(TEST_NAME, extensionAbilityInfo)); + bundleInfo.baseExtensionInfos_.insert(std::make_pair(TEST_NAME, innerExtensionInfo)); bundleInfo.UpdateExtensionDataGroupInfo("1", dataGroupIds); EXPECT_TRUE(bundleInfo.baseExtensionInfos_[TEST_NAME].validDataGroupIds.empty()); bundleInfo.UpdateExtensionDataGroupInfo(TEST_NAME, dataGroupIds); @@ -4324,9 +4324,9 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_9400, Function | Medi HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_9500, Function | MediumTest | Level1) { InnerBundleInfo info; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.enabled = false; - info.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, extensionAbilityInfo)); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.enabled = false; + info.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); BundleInfo bundleInfo; info.GetBundleWithExtension(GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, appIndex, Constants::ALL_USERID); EXPECT_EQ(bundleInfo.abilityInfos.size(), 0); diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_driver_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_driver_test.cpp index dcac481c6c..1694a26c80 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_driver_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_install_driver_test.cpp @@ -1826,25 +1826,25 @@ HWTEST_F(BmsDriverInstallerTest, InstallDriverTest_6700, Function | SmallTest | { std::shared_ptr driverInstaller = std::make_shared(); InnerBundleInfo info; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.moduleName = MODULE_NAME_FEATURE6; - info.baseExtensionInfos_.emplace("1", extensionAbilityInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.moduleName = MODULE_NAME_FEATURE6; + info.baseExtensionInfos_.emplace("1", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE10, false); - info.baseExtensionInfos_.emplace("2", extensionAbilityInfo); + info.baseExtensionInfos_.emplace("2", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE6, false); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); - extensionAbilityInfo.moduleName = EMPTY_STRING; - info.baseExtensionInfos_.emplace("3", extensionAbilityInfo); + innerExtensionInfo.moduleName = EMPTY_STRING; + info.baseExtensionInfos_.emplace("3", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); - extensionAbilityInfo.type = ExtensionAbilityType::DRIVER; - info.baseExtensionInfos_.emplace("4", extensionAbilityInfo); + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + info.baseExtensionInfos_.emplace("4", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); - extensionAbilityInfo.moduleName = MODULE_NAME_FEATURE6; - info.baseExtensionInfos_.emplace("5", extensionAbilityInfo); + innerExtensionInfo.moduleName = MODULE_NAME_FEATURE6; + info.baseExtensionInfos_.emplace("5", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE10, false); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE6, false); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); @@ -1871,32 +1871,32 @@ HWTEST_F(BmsDriverInstallerTest, InstallDriverTest_6800, Function | SmallTest | { std::shared_ptr driverInstaller = std::make_shared(); InnerBundleInfo info; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.moduleName = MODULE_NAME_FEATURE6; - extensionAbilityInfo.type = ExtensionAbilityType::DRIVER; - info.baseExtensionInfos_.emplace("1", extensionAbilityInfo); + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.moduleName = MODULE_NAME_FEATURE6; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + info.baseExtensionInfos_.emplace("1", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE10, false); driverInstaller->RenameDriverFile(info); Metadata metadata; metadata.name = "file"; - extensionAbilityInfo.metadata.push_back(metadata); - info.baseExtensionInfos_.emplace("2", extensionAbilityInfo); + innerExtensionInfo.metadata.push_back(metadata); + info.baseExtensionInfos_.emplace("2", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, MODULE_NAME_FEATURE6, false); driverInstaller->RenameDriverFile(info); metadata.name = "cupsFilter"; metadata.resource = "/"; - extensionAbilityInfo.metadata.push_back(metadata); - info.baseExtensionInfos_.emplace("3", extensionAbilityInfo); + innerExtensionInfo.metadata.push_back(metadata); + info.baseExtensionInfos_.emplace("3", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); driverInstaller->RenameDriverFile(info); metadata.name = "cupsFilter"; metadata.resource = "../test"; - extensionAbilityInfo.metadata.push_back(metadata); - extensionAbilityInfo.moduleName = EMPTY_STRING; - info.baseExtensionInfos_.emplace("4", extensionAbilityInfo); + innerExtensionInfo.metadata.push_back(metadata); + innerExtensionInfo.moduleName = EMPTY_STRING; + info.baseExtensionInfos_.emplace("4", innerExtensionInfo); driverInstaller->RemoveDriverSoFile(info, EMPTY_STRING, false); driverInstaller->RenameDriverFile(info); @@ -1993,16 +1993,16 @@ HWTEST_F(BmsDriverInstallerTest, InstallDriverTest_7200, Function | SmallTest | { std::shared_ptr driverInstaller = std::make_shared(); InnerBundleInfo info; - ExtensionAbilityInfo extensionAbilityInfo; - extensionAbilityInfo.type = ExtensionAbilityType::DRIVER; + InnerExtensionInfo innerExtensionInfo; + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; Metadata metadata; metadata.name = "cupsFilter"; metadata.resource = "./"; metadata.value = "./"; - extensionAbilityInfo.metadata.push_back(metadata); - extensionAbilityInfo.moduleName = MODULE_NAME_FEATURE6; + innerExtensionInfo.metadata.push_back(metadata); + innerExtensionInfo.moduleName = MODULE_NAME_FEATURE6; - info.baseExtensionInfos_.insert(std::make_pair("1", extensionAbilityInfo)); + info.baseExtensionInfos_.insert(std::make_pair("1", innerExtensionInfo)); auto res = driverInstaller->CopyDriverSoFile(info, RESOURCE_ROOT_PATH, false); EXPECT_EQ(res, ERR_APPEXECFWK_INSTALLD_COPY_FILE_FAILED); } diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp index f27792d589..7100490f8f 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_three.cpp @@ -3209,7 +3209,7 @@ HWTEST_F(BmsBundleDataMgrTest3, GetAdditionalBundleInfos_0100, Function | SmallT auto dataMgr = bundleUserMgrHostImpl_->GetDataMgrFromService(); ASSERT_NE(dataMgr, nullptr); InnerBundleInfo innerBundleInfo; - ExtensionAbilityInfo info; + InnerExtensionInfo info; info.type = ExtensionAbilityType::DRIVER; innerBundleInfo.baseExtensionInfos_.emplace(BUNDLE_TEST2, info); dataMgr->bundleInfos_[BUNDLE_TEST1] = innerBundleInfo; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp index 77de58476d..9a30b867b0 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test_two.cpp @@ -2245,9 +2245,9 @@ HWTEST_F(BmsBundleDataMgrTest2, RemoveModuleInfo_0500, Function | SmallTest | Le moduleInfo.extensionKeys.push_back("keys");; info.innerModuleInfos_.try_emplace(PACKAGE_NAME, moduleInfo); - ExtensionAbilityInfo extensionAbilityInfo; + InnerExtensionInfo innerExtensionInfo; std::string key = "key"; - info.baseExtensionInfos_.try_emplace(key, extensionAbilityInfo); + info.baseExtensionInfos_.try_emplace(key, innerExtensionInfo); info.RemoveModuleInfo(PACKAGE_NAME); auto extensionItem = info.baseExtensionInfos_.find("keys"); diff --git a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp index 658767d5b8..af525c91fe 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_resource_test/bms_bundle_resource_test.cpp @@ -1852,16 +1852,16 @@ HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0081, Function | SmallTest HWTEST_F(BmsBundleResourceTest, BmsBundleResourceTest_0082, Function | SmallTest | Level0) { InnerBundleInfo innerBundleInfo; - ExtensionAbilityInfo extensionAbilityInfo; - - extensionAbilityInfo.type = ExtensionAbilityType::INPUTMETHOD; - innerBundleInfo.baseExtensionInfos_.emplace("inputmethod_key", extensionAbilityInfo); - extensionAbilityInfo.type = ExtensionAbilityType::SHARE; - innerBundleInfo.baseExtensionInfos_.emplace("share_key", extensionAbilityInfo); - extensionAbilityInfo.type = ExtensionAbilityType::ACTION; - innerBundleInfo.baseExtensionInfos_.emplace("action_key", extensionAbilityInfo); - extensionAbilityInfo.type = ExtensionAbilityType::DRIVER; - innerBundleInfo.baseExtensionInfos_.emplace("driver_key", extensionAbilityInfo); + InnerExtensionInfo innerExtensionInfo; + + innerExtensionInfo.type = ExtensionAbilityType::INPUTMETHOD; + innerBundleInfo.baseExtensionInfos_.emplace("inputmethod_key", innerExtensionInfo); + innerExtensionInfo.type = ExtensionAbilityType::SHARE; + innerBundleInfo.baseExtensionInfos_.emplace("share_key", innerExtensionInfo); + innerExtensionInfo.type = ExtensionAbilityType::ACTION; + innerBundleInfo.baseExtensionInfos_.emplace("action_key", innerExtensionInfo); + innerExtensionInfo.type = ExtensionAbilityType::DRIVER; + innerBundleInfo.baseExtensionInfos_.emplace("driver_key", innerExtensionInfo); ApplicationInfo applicationInfo; applicationInfo.bundleName = BUNDLE_NAME; -- Gitee From 2f6490a4d96b41ebaf62c33fa6d4eb40de2a643e Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Fri, 18 Jul 2025 09:29:52 +0800 Subject: [PATCH 7/7] Issue:#ICL149 Description:optimize extension memory Sig: SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- .../appexecfwk_base/include/bundle_constants.h | 6 +++--- .../appexecfwk_base/include/common_json_converter.h | 12 ++++++------ .../appexecfwk_base/src/extension_ability_info.cpp | 1 + .../bms_bundle_data_storage_database_test.cpp | 10 +++++----- .../bms_bundle_data_mgr_test.cpp | 6 +++--- .../bms_bundle_kit_service_test.cpp | 6 +++--- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h index 30947ad596..a1cce36433 100644 --- a/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h +++ b/interfaces/inner_api/appexecfwk_base/include/bundle_constants.h @@ -217,9 +217,9 @@ inline constexpr const char* EXTENSION_PROCESS_MODE = "extensionProcessMode"; inline constexpr const char* SKILLS = "skills"; inline constexpr const char* NEED_CREATE_SANDBOX = "needCreateSandbox"; inline constexpr const char* DATA_GROUP_IDS = "dataGroupIds"; -inline constexpr const char* JSON_KEY_VALID_DATA_GROUP_IDS = "validDataGroupIds"; -inline constexpr const char* JSON_KEY_CUSTOM_PROCESS = "customProcess"; -inline constexpr const char* JSON_KEY_ISOLATION_PROCESS = "isolationProcess"; +inline constexpr const char* VALID_DATA_GROUP_IDS = "validDataGroupIds"; +inline constexpr const char* CUSTOM_PROCESS = "customProcess"; +inline constexpr const char* ISOLATION_PROCESS = "isolationProcess"; } // namespace Constants } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h index 91848395a9..1c0ea06ff7 100644 --- a/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h +++ b/interfaces/inner_api/appexecfwk_base/include/common_json_converter.h @@ -243,7 +243,7 @@ void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) ArrayType::STRING); GetValueIfFindKey>(jsonObject, jsonObjectEnd, - Constants::JSON_KEY_VALID_DATA_GROUP_IDS, + Constants::VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds, JsonType::ARRAY, false, @@ -251,13 +251,13 @@ void ExtensionFromJson(const nlohmann::json &jsonObject, T &extensionInfo) ArrayType::STRING); BMSJsonUtil::GetStrValueIfFindKey(jsonObject, jsonObjectEnd, - Constants::JSON_KEY_CUSTOM_PROCESS, + Constants::CUSTOM_PROCESS, extensionInfo.customProcess, false, parseResult); BMSJsonUtil::GetBoolValueIfFindKey(jsonObject, jsonObjectEnd, - Constants::JSON_KEY_ISOLATION_PROCESS, + Constants::ISOLATION_PROCESS, extensionInfo.isolationProcess, false, parseResult); @@ -308,9 +308,9 @@ void ExtensionToJson(nlohmann::json &jsonObject, const T &extensionInfo) {Constants::SKILLS, extensionInfo.skills}, {Constants::NEED_CREATE_SANDBOX, extensionInfo.needCreateSandbox}, {Constants::DATA_GROUP_IDS, extensionInfo.dataGroupIds}, - {Constants::JSON_KEY_VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, - {Constants::JSON_KEY_CUSTOM_PROCESS, extensionInfo.customProcess}, - {Constants::JSON_KEY_ISOLATION_PROCESS, extensionInfo.isolationProcess}, + {Constants::VALID_DATA_GROUP_IDS, extensionInfo.validDataGroupIds}, + {Constants::CUSTOM_PROCESS, extensionInfo.customProcess}, + {Constants::ISOLATION_PROCESS, extensionInfo.isolationProcess}, {Constants::CODE_LANGUAGE, extensionInfo.codeLanguage} }; } diff --git a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp index f4d9cecdaf..071b397040 100644 --- a/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp +++ b/interfaces/inner_api/appexecfwk_base/src/extension_ability_info.cpp @@ -344,6 +344,7 @@ bool ExtensionAbilityInfo::Marshalling(Parcel &parcel) const void to_json(nlohmann::json &jsonObject, const ExtensionAbilityInfo &extensionInfo) { + APP_LOGD("ExtensionAbilityInfo to_json begin"); ExtensionToJson(jsonObject, extensionInfo); } diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp index 0de5522ca4..0bed898511 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_database_test.cpp @@ -2994,9 +2994,9 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5200, Function | Smal InnerBundleInfo bundleInfo; InnerExtensionInfo innerExtensionInfo; innerExtensionInfo.uri = URI; - InnerExtensionInfo baseExtensionInfo; + ExtensionAbilityInfo extensionAbilityInfo; bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); - bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo); + bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, extensionAbilityInfo); EXPECT_TRUE(ret); } @@ -3011,11 +3011,11 @@ HWTEST_F(BmsBundleDataStorageDatabaseTest, InnerBundleInfo_5300, Function | Smal bundleInfo.baseExtensionInfos_.clear(); InnerExtensionInfo innerExtensionInfo; innerExtensionInfo.uri = URI; - InnerExtensionInfo baseExtensionInfo; - bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, baseExtensionInfo); + ExtensionAbilityInfo extensionAbilityInfo; + bool ret = bundleInfo.FindExtensionAbilityInfoByUri(URI, extensionAbilityInfo); EXPECT_FALSE(ret); bundleInfo.baseExtensionInfos_.insert(std::make_pair(MODULE_NAME, innerExtensionInfo)); - ret = bundleInfo.FindExtensionAbilityInfoByUri("URI", baseExtensionInfo); + ret = bundleInfo.FindExtensionAbilityInfoByUri("URI", extensionAbilityInfo); EXPECT_FALSE(ret); } diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp index 08a8e4f595..11e2d3b2d6 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_data_mgr_test.cpp @@ -394,7 +394,7 @@ public: void MockUninstallBundle(const std::string &bundleName) const; AbilityInfo MockAbilityInfo( const std::string &bundleName, const std::string &module, const std::string &abilityName) const; - ExtensionAbilityInfo MockExtensionInfo( + InnerExtensionInfo MockExtensionInfo( const std::string &bundleName, const std::string &module, const std::string &extensionName) const; InnerModuleInfo MockModuleInfo(const std::string &moduleName) const; FormInfo MockFormInfo( @@ -872,10 +872,10 @@ AbilityInfo BmsBundleDataMgrTest::MockAbilityInfo( return abilityInfo; } -ExtensionAbilityInfo BmsBundleDataMgrTest::MockExtensionInfo( +InnerExtensionInfo BmsBundleDataMgrTest::MockExtensionInfo( const std::string &bundleName, const std::string &moduleName, const std::string &extensionName) const { - ExtensionAbilityInfo extensionInfo; + InnerExtensionInfo extensionInfo; extensionInfo.name = extensionName; extensionInfo.bundleName = bundleName; extensionInfo.moduleName = moduleName; diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index 25f620e3dc..cc209df9b8 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -308,7 +308,7 @@ public: void MockUninstallBundle(const std::string &bundleName) const; AbilityInfo MockAbilityInfo( const std::string &bundleName, const std::string &module, const std::string &abilityName) const; - ExtensionAbilityInfo MockExtensionInfo( + InnerExtensionInfo MockExtensionInfo( const std::string &bundleName, const std::string &module, const std::string &extensionName) const; InnerModuleInfo MockModuleInfo(const std::string &moduleName) const; FormInfo MockFormInfo( @@ -1063,10 +1063,10 @@ AbilityInfo BmsBundleKitServiceTest::MockAbilityInfo( return abilityInfo; } -ExtensionAbilityInfo BmsBundleKitServiceTest::MockExtensionInfo( +InnerExtensionInfo BmsBundleKitServiceTest::MockExtensionInfo( const std::string &bundleName, const std::string &moduleName, const std::string &extensionName) const { - ExtensionAbilityInfo extensionInfo; + InnerExtensionInfo extensionInfo; extensionInfo.name = extensionName; extensionInfo.bundleName = bundleName; extensionInfo.moduleName = moduleName; -- Gitee