diff --git a/services/bundlemgr/include/bundle_mgr_service_event_handler.h b/services/bundlemgr/include/bundle_mgr_service_event_handler.h index 0ba27ef79572056446ea43cdd2405937fead5ec5..bec84472f44c59b875c18fcfa6afb796efea0e5f 100644 --- a/services/bundlemgr/include/bundle_mgr_service_event_handler.h +++ b/services/bundlemgr/include/bundle_mgr_service_event_handler.h @@ -84,6 +84,13 @@ public: * @return */ static void GetPreInstallRootDirList(std::vector &rootDirList); + /** + * @brief Get different group preInstall root dir list, + * which the catalog of production has higher priority. + * @param rootDirList Indicates the root dir list. + * @return + */ + static void GetDiffGroupPreInstallRootDirList(std::vector &rootDirList); /** * @brief Load all preInstall infos from proFile. * @return Returns true if get the preInstall list successfully; returns false otherwise. @@ -393,6 +400,12 @@ private: * @return */ static void ParsePreBundleProFile(const std::string &dir); + /** + * @brief Process parse diff group pre bundle profile. + * @param dir Indicates the dir. + * @return + */ + static void ParseDiffGroupPreBundleProFile(const std::string &dir); /** * @brief Set the flag indicates that all system and vendor applications installed. * @return diff --git a/services/bundlemgr/include/bundle_parser.h b/services/bundlemgr/include/bundle_parser.h index 04babdf095abf9a0f85255a2a7a0992696b455fe..310b167a2a60c2a425b18091b92a9f6c39c9e669 100644 --- a/services/bundlemgr/include/bundle_parser.h +++ b/services/bundlemgr/include/bundle_parser.h @@ -74,6 +74,14 @@ public: ErrCode ParsePreUnInstallConfig( const std::string &configFile, std::set &uninstallList) const; + /** + * @brief Parse bundleNames by the configFile. + * @param configFile Indicates the path of configFile. + * @param uninstallPreload Indicates the uninstallPreload. + * @return Returns ERR_OK if the bundle successfully parsed; returns ErrCode otherwise. + */ + ErrCode ParsePreUnInstallPreloadConfig( + const std::string &configFile, std::set &uninstallPreload) const; /** * @brief Parse PreBundleConfigInfo by the configFile. * @param configFile Indicates the path of configFile. diff --git a/services/bundlemgr/include/pre_bundle_profile.h b/services/bundlemgr/include/pre_bundle_profile.h index 31cba191ba885444e5aad87032f80d47f4d41a53..3dff197ba1dd59d65ae83a0c9aaa4acd8de5ceae 100644 --- a/services/bundlemgr/include/pre_bundle_profile.h +++ b/services/bundlemgr/include/pre_bundle_profile.h @@ -51,6 +51,14 @@ public: ErrCode TransformTo( const nlohmann::json &jsonBuf, std::set &uninstallList) const; + /** + * @brief Transform the jsonBuf to bundleNames. + * @param jsonBuf Indicates the jsonBuf. + * @param uninstallList Indicates the uninstallPreload. + * @return Returns ERR_OK if the information transformed successfully; returns error code otherwise. + */ + ErrCode TransformToUninstallPreload( + const nlohmann::json &jsonBuf, std::set &uninstallPreload) const; /** * @brief Transform the jsonBuf to preBundleConfigInfos. * @param jsonBuf Indicates the jsonBuf. diff --git a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp index 681c15bb268db6934b2869e57116d365358fe1bb..509c1e5b4617840f023d48ae230e23fd2e7f80e9 100644 --- a/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp +++ b/services/bundlemgr/src/bundle_mgr_service_event_handler.cpp @@ -90,15 +90,18 @@ constexpr const char* HSP_VERSION_PREFIX = "v"; constexpr const char* OTA_FLAG = "otaFlag"; // pre bundle profile constexpr const char* DEFAULT_PRE_BUNDLE_ROOT_DIR = "/system"; +constexpr const char* DEFAULT_DIFF_GROUP_PRE_BUNDLE_ROOT_DIR = "/data"; constexpr const char* DEFAULT_DATA_PRE_BUNDLE_DIR = "/app_list.json"; constexpr const char* PRODUCT_SUFFIX = "/etc/app"; constexpr const char* MODULE_UPDATE_PRODUCT_SUFFIX = "/etc/app/module_update"; +constexpr const char* PRELOAD_OTA_PRODUCT_SUFFIX = "/preloadota"; constexpr const char* INSTALL_LIST_CONFIG = "/install_list.json"; constexpr const char* APP_SERVICE_FWK_INSTALL_LIST_CONFIG = "/app_service_fwk_install_list.json"; constexpr const char* UNINSTALL_LIST_CONFIG = "/uninstall_list.json"; constexpr const char* INSTALL_LIST_CAPABILITY_CONFIG = "/install_list_capability.json"; constexpr const char* EXTENSION_TYPE_LIST_CONFIG = "/extension_type_config.json"; constexpr const char* SHARED_BUNDLES_INSTALL_LIST_CONFIG = "/shared_bundles_install_list.json"; +constexpr const char* UNINSTALL_PRELOAD_CONFIG = "/UninstallPreload.json"; constexpr const char* SYSTEM_RESOURCES_APP_PATH = "/system/app/ohos.global.systemres"; constexpr const char* QUICK_FIX_APP_PATH = "/data/update/quickfix/app/temp/cold"; constexpr const char* SYSTEM_BUNDLE_PATH = "/internal"; @@ -121,6 +124,7 @@ std::set systemHspList_; std::set uninstallList_; std::set installListCapabilities_; std::set extensiontype_; +std::set uninstallPreload_; bool hasLoadPreInstallProFile_ = false; std::vector bundleNameList_; @@ -634,6 +638,30 @@ void BMSEventHandler::GetPreInstallRootDirList(std::vector &rootDir } } +void BMSEventHandler::GetDiffGroupPreInstallRootDirList(std::vector &rootDirList) +{ +// #ifdef CONFIG_POLOCY_ENABLE +// auto cfgDirList = GetCfgDirList(); +// if (cfgDirList != nullptr) { +// for (const auto &cfgDir : cfgDirList->paths) { +// if (cfgDir == nullptr) { +// continue; +// } + +// LOG_NOFUNC_I(BMS_TAG_DEFAULT, "GetPreInstallRootDirList cfgDir: %{public}s", cfgDir); +// rootDirList.emplace_back(cfgDir); +// } + +// FreeCfgDirList(cfgDirList); +// } +// #endif + bool ret = std::find( + rootDirList.begin(), rootDirList.end(), DEFAULT_DIFF_GROUP_PRE_BUNDLE_ROOT_DIR) != rootDirList.end(); + if (!ret) { + rootDirList.emplace_back(DEFAULT_DIFF_GROUP_PRE_BUNDLE_ROOT_DIR); + } +} + void BMSEventHandler::ClearPreInstallCache() { if (!hasLoadPreInstallProFile_) { @@ -666,6 +694,17 @@ bool BMSEventHandler::LoadPreInstallProFile() ParsePreBundleProFile(rootDir + MODULE_UPDATE_PRODUCT_SUFFIX); } + std::vector diffGroupRootDirList; + GetDiffGroupPreInstallRootDirList(diffGroupRootDirList); + if (diffGroupRootDirList.empty()) { + LOG_E(BMS_TAG_DEFAULT, "diffGroupDirList is empty"); + // return false; + } + + for (const auto &rootDir : diffGroupRootDirList) { + ParseDiffGroupPreBundleProFile(rootDir + PRELOAD_OTA_PRODUCT_SUFFIX); + } + hasLoadPreInstallProFile_ = true; return !installList_.empty(); } @@ -704,6 +743,17 @@ void BMSEventHandler::ParsePreBundleProFile(const std::string &dir) } } +void BMSEventHandler::ParseDiffGroupPreBundleProFile(const std::string &dir) +{ + if (!BundleUtil::IsExistDirNoLog(dir)) { + LOG_W(BMS_TAG_DEFAULT, "parse dir %{public}s not exist", dir.c_str()); + return; + } + BundleParser bundleParser; + bundleParser.ParsePreUnInstallPreloadConfig( + dir + UNINSTALL_PRELOAD_CONFIG, uninstallList_); +} + void BMSEventHandler::GetPreInstallDir(std::vector &bundleDirs) { #ifdef USE_PRE_BUNDLE_PROFILE diff --git a/services/bundlemgr/src/bundle_parser.cpp b/services/bundlemgr/src/bundle_parser.cpp index 0c7fe5f7a169dcf4c5bff61eee364c8085854879..7db6ea506dfd6bdf24c092a886e8193b4e53d1e6 100644 --- a/services/bundlemgr/src/bundle_parser.cpp +++ b/services/bundlemgr/src/bundle_parser.cpp @@ -263,6 +263,20 @@ ErrCode BundleParser::ParsePreUnInstallConfig( return preBundleProfile.TransformTo(jsonBuf, uninstallList); } +ErrCode BundleParser::ParsePreUnInstallPreloadConfig( + const std::string &configFile, std::set &uninstallPreload) const +{ + APP_LOGD("Parse PreUnInstallPreloadConfig from %{public}s", configFile.c_str()); + nlohmann::json jsonBuf; + if (!ReadFileIntoJson(configFile, jsonBuf)) { + APP_LOGE_NOFUNC("Parse file %{public}s failed", configFile.c_str()); + return ERR_APPEXECFWK_PARSE_FILE_FAILED; + } + + PreBundleProfile preBundleProfile; + return preBundleProfile.TransformToUninstallPreload(jsonBuf, uninstallPreload); +} + ErrCode BundleParser::ParsePreInstallAbilityConfig( const std::string &configFile, std::set &preBundleConfigInfos) const { diff --git a/services/bundlemgr/src/pre_bundle_profile.cpp b/services/bundlemgr/src/pre_bundle_profile.cpp index 306c5517d5cf761a6100c587a7b2ebd76c43017a..a73fdcbf129a185619bba12950595bb5551d2998 100644 --- a/services/bundlemgr/src/pre_bundle_profile.cpp +++ b/services/bundlemgr/src/pre_bundle_profile.cpp @@ -25,6 +25,7 @@ constexpr const char* APP_LIST = "app_list"; constexpr const char* UNINSTALL_LIST = "uninstall_list"; constexpr const char* EXTENSION_TYPE = "extensionType"; constexpr const char* RECOVER_LIST = "recover_list"; +constexpr const char* UNINSTALL_PRELOAD = "UninstallPreload"; constexpr const char* APP_DIR = "app_dir"; constexpr const char* REMOVABLE = "removable"; constexpr const char* APPIDENTIFIER = "appIdentifier"; @@ -221,6 +222,34 @@ ErrCode PreBundleProfile::TransformTo( return parseResult; } +ErrCode PreBundleProfile::TransformToUninstallPreload( + const nlohmann::json &jsonBuf, std::set &uninstallPreload) const +{ + APP_LOGD("transform jsonBuf to bundleNames"); + if (jsonBuf.is_discarded()) { + APP_LOGE("profile format error"); + return ERR_APPEXECFWK_PARSE_BAD_PROFILE; + } + + const auto &jsonObjectEnd = jsonBuf.end(); + int32_t parseResult = ERR_OK; + std::vector names; + GetValueIfFindKey>(jsonBuf, + jsonObjectEnd, + UNINSTALL_PRELOAD, + names, + JsonType::ARRAY, + false, + parseResult, + ArrayType::STRING); + for (const auto &name : names) { + APP_LOGD("uninstallPreload bundleName %{public}s", name.c_str()); + uninstallPreload.insert(name); + } + + return parseResult; +} + ErrCode PreBundleProfile::TransformTo( const nlohmann::json &jsonBuf, std::set &preBundleConfigInfos) const