From 1cedd117306782d42bd6e40ad2d9d36838d8113f Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Mon, 8 Jul 2024 19:56:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BB=E6=AD=A2=E9=BB=91=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- .../include/appexecfwk_errors.h | 1 + .../include/bms_extension_data_mgr.h | 1 + .../include/bundle_mgr_ext.h | 4 ++++ .../src/bms_extension_data_mgr.cpp | 15 ++++++++++++ interfaces/kits/js/common/common_func.cpp | 1 + .../bundlemgr/include/base_bundle_installer.h | 2 ++ .../bundlemgr/src/base_bundle_installer.cpp | 24 +++++++++++++++---- .../bundlemgr/src/status_receiver_proxy.cpp | 3 +++ 8 files changed, 47 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h index b2d6e749bb..ae6ba815b4 100644 --- a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h +++ b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h @@ -147,6 +147,7 @@ enum { ERR_APPEXECFWK_INSTALL_DEBUG_BUNDLE_NOT_ALLOWED = 8519784, ERR_APPEXECFWK_INSTALL_FAILED_CONTROLLED = 8519785, ERR_APPEXECFWK_INSTALL_MULTI_APP_MAX_COUNT_DECREASE = 8519786, + ERR_APPEXECFWK_INSTALL_APP_IN_BLOCKLIST = 8519787, // native bundle ERR_APPEXECFWK_NATIVE_INSTALL_FAILED = 8519790, diff --git a/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h b/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h index 6b6eef345b..ef10c629a9 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bms_extension_data_mgr.h @@ -52,6 +52,7 @@ public: ErrCode VerifyActivationLock(bool &res); ErrCode GetBackupUninstallList(int32_t userId, std::set &uninstallBundles); ErrCode ClearBackupUninstallFile(int32_t userId); + bool IsAppInBlocklist(const std::string &bundleName); private: bool OpenHandler(); static BmsExtension bmsExtension_; diff --git a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h index 044a471efe..7ebb0f1f81 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h @@ -91,6 +91,10 @@ public: { return ERR_BUNDLE_MANAGER_EXTENSION_DEFAULT_ERR; } + virtual bool IsAppInBlocklist(const std::string &bundleName) + { + return false; + } }; } // AppExecFwk diff --git a/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp b/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp index e643d15aeb..b8346768c6 100644 --- a/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp +++ b/interfaces/inner_api/bundlemgr_extension/src/bms_extension_data_mgr.cpp @@ -313,5 +313,20 @@ ErrCode BmsExtensionDataMgr::ClearBackupUninstallFile(int32_t userId) } return bundleMgrExtPtr->ClearBackupUninstallFile(userId); } + +bool BmsExtensionDataMgr::IsAppInBlocklist(const std::string &bundleName) +{ + if ((Init() != ERR_OK) || handler_ == nullptr) { + APP_LOGW("link failed"); + return false; + } + auto bundleMgrExtPtr = + BundleMgrExtRegister::GetInstance().GetBundleMgrExt(bmsExtension_.bmsExtensionBundleMgr.extensionName); + if (bundleMgrExtPtr == nullptr) { + APP_LOGW("GetBundleMgrExt failed"); + return false; + } + return bundleMgrExtPtr->IsAppInBlocklist(bundleName); +} } // AppExecFwk } // OHOS diff --git a/interfaces/kits/js/common/common_func.cpp b/interfaces/kits/js/common/common_func.cpp index afaca53a64..d1b896555b 100644 --- a/interfaces/kits/js/common/common_func.cpp +++ b/interfaces/kits/js/common/common_func.cpp @@ -166,6 +166,7 @@ static std::unordered_map ERR_MAP = { { ERR_APPEXECFWK_CLONE_UNINSTALL_NOT_INSTALLED_AT_SPECIFIED_USERID, ERROR_BUNDLE_NOT_EXIST }, { ERR_APPEXECFWK_CLONE_UNINSTALL_APP_NOT_CLONED, ERROR_INVALID_APPINDEX }, { ERR_APPEXECFWK_INSTALL_FAILED_CONTROLLED, ERROR_INSTALL_FAILED_CONTROLLED }, + { ERR_APPEXECFWK_INSTALL_APP_IN_BLOCKLIST, ERROR_INSTALL_FAILED_CONTROLLED }, { ERR_APPEXECFWK_CLONE_INSTALL_APP_INDEX_EXCEED_MAX_NUMBER, ERROR_INVALID_APPINDEX }, { ERR_APPEXECFWK_SANDBOX_INSTALL_INVALID_APP_INDEX, ERROR_INVALID_APPINDEX }, { ERR_APPEXECFWK_CLONE_INSTALL_APP_NOT_SUPPORTED_MULTI_TYPE, ERROR_APP_NOT_SUPPORTED_MULTI_TYPE }, diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 22009850af..82e0bf09d0 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -710,6 +710,8 @@ private: void SetInstallSourceToAppInfo(std::unordered_map &infos, const InstallParam &installParam) const; bool InitDataMgr(); + bool IsAppInBlocklist(const std::string &bundleName) const; + InstallerState state_ = InstallerState::INSTALL_START; std::shared_ptr dataMgr_ = nullptr; // this pointer will get when public functions called std::string bundleName_; diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index cc01107fa2..d542cad79e 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1056,10 +1056,15 @@ ErrCode BaseBundleInstaller::ProcessBundleInstall(const std::vector result = ParseHapFiles(bundlePaths, installParam, appType, hapVerifyResults, newInfos); CHECK_RESULT(result, "parse haps file failed %{public}d"); // washing machine judge - for (const auto &infoIter: newInfos) { - if (!infoIter.second.IsSystemApp() && !VerifyActivationLock()) { - result = ERR_APPEXECFWK_INSTALL_FAILED_CONTROLLED; - break; + if (!installParam.isPreInstallApp) { + for (const auto &infoIter: newInfos) { + if (!infoIter.second.IsSystemApp() && !VerifyActivationLock()) { + result = ERR_APPEXECFWK_INSTALL_FAILED_CONTROLLED; + break; + } + } + if (IsAppInBlocklist((newInfos.begin()->second).GetBundleName())) { + result = ERR_APPEXECFWK_INSTALL_APP_IN_BLOCKLIST; } } CHECK_RESULT(result, "check install verifyActivation failed %{public}d"); @@ -5689,5 +5694,16 @@ ErrCode BaseBundleInstaller::RollbackHmpCommonInfo(const std::string &bundleName ClearDomainVerifyStatus(oldInfo.GetAppIdentifier(), oldInfo.GetBundleName()); return ERR_OK; } + +bool BaseBundleInstaller::IsAppInBlocklist(const std::string &bundleName) const +{ + BmsExtensionDataMgr bmsExtensionDataMgr; + bool res = bmsExtensionDataMgr.IsAppInBlocklist(bundleName); + if (res) { + LOG_E(BMS_TAG_INSTALLER, "app %{public}s is in blocklist", bundleName.c_str()); + return true; + } + return false; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/status_receiver_proxy.cpp b/services/bundlemgr/src/status_receiver_proxy.cpp index c3fd30339e..a17da656f4 100644 --- a/services/bundlemgr/src/status_receiver_proxy.cpp +++ b/services/bundlemgr/src/status_receiver_proxy.cpp @@ -592,6 +592,9 @@ const std::map MAP_RECEIVED_RESULTS { {ERR_APPEXECFWK_INSTALL_MULTI_APP_MAX_COUNT_DECREASE, {IStatusReceiver::ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE, MSG_ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE}}, + {ERR_APPEXECFWK_INSTALL_APP_IN_BLOCKLIST, + {IStatusReceiver::ERR_INSTALL_CODE_APP_CONTROLLED_FAILED, + MSG_ERR_INSTALL_CODE_APP_CONTROLLED_FAILED}}, }; } // namespace -- Gitee