From 041efd548d3383c09767063f460115b9c54c1f36 Mon Sep 17 00:00:00 2001 From: Zhou Shihui Date: Mon, 29 Jul 2024 10:57:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=B8=E8=BD=BD=E5=BA=94=E7=94=A8=E5=89=8D?= =?UTF-8?q?=E7=BD=AE=E7=A1=AE=E8=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhou Shihui --- .../appexecfwk_base/include/appexecfwk_errors.h | 1 + .../bundlemgr/status_receiver_interface.h | 1 + .../bundlemgr/bundle_status_callback_proxy.cpp | 1 + .../include/bms_extension_data_mgr.h | 1 + .../bundlemgr_extension/include/bundle_mgr_ext.h | 4 ++++ .../src/bms_extension_data_mgr.cpp | 15 +++++++++++++++ interfaces/kits/js/installer/installer.cpp | 1 + .../bundlemgr/include/base_bundle_installer.h | 1 + services/bundlemgr/src/base_bundle_installer.cpp | 16 ++++++++++++++++ services/bundlemgr/src/status_receiver_proxy.cpp | 4 ++++ 10 files changed, 45 insertions(+) diff --git a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h index 9d0bf32508..c846b2b5e1 100644 --- a/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h +++ b/interfaces/inner_api/appexecfwk_base/include/appexecfwk_errors.h @@ -243,6 +243,7 @@ enum { ERR_APPEXECFWK_RECOVER_NOT_ALLOWED = 8520195, ERR_APPEXECFWK_UNINSTALL_AND_RECOVER_NOT_PREINSTALLED_BUNDLE = 8520300, + ERR_APPEXECFWK_UNINSTALL_CONTROLLED = 8520301, ERR_APPEXECFWK_USER_NOT_EXIST = APPEXECFWK_BUNDLEMGR_ERR_OFFSET + 0x0301, // 8520449 ERR_APPEXECFWK_USER_CREATE_FAILED = 8520450, diff --git a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/status_receiver_interface.h b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/status_receiver_interface.h index 42d94dfda4..8040348cd7 100644 --- a/interfaces/inner_api/appexecfwk_core/include/bundlemgr/status_receiver_interface.h +++ b/interfaces/inner_api/appexecfwk_core/include/bundlemgr/status_receiver_interface.h @@ -209,6 +209,7 @@ public: ERR_INSTALL_CODE_APP_CONTROLLED_FAILED = 9568410, ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE = 9568411, + ERR_UNINSTALL_CONTROLLED = 9568412, ERR_RECOVER_GET_BUNDLEPATH_ERROR = 201, ERR_RECOVER_INVALID_BUNDLE_NAME, diff --git a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_status_callback_proxy.cpp b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_status_callback_proxy.cpp index 807cee5f00..e1e84e73ac 100644 --- a/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_status_callback_proxy.cpp +++ b/interfaces/inner_api/appexecfwk_core/src/bundlemgr/bundle_status_callback_proxy.cpp @@ -131,6 +131,7 @@ void BundleStatusCallbackProxy::InitResultMap() {ERR_APPEXECFWK_RECOVER_NOT_ALLOWED, "ERR_APPEXECFWK_RECOVER_NOT_ALLOWED"}, {ERR_APPEXECFWK_UNINSTALL_AND_RECOVER_NOT_PREINSTALLED_BUNDLE, "ERR_APPEXECFWK_UNINSTALL_AND_RECOVER_NOT_PREINSTALLED_BUNDLE"}, + {ERR_APPEXECFWK_UNINSTALL_CONTROLLED, "ERR_APPEXECFWK_UNINSTALL_CONTROLLED"}, {ERR_APPEXECFWK_USER_NOT_EXIST, "ERR_APPEXECFWK_USER_NOT_EXIST"}, {ERR_APPEXECFWK_USER_CREATE_FAILED, "ERR_APPEXECFWK_USER_CREATE_FAILED"}, {ERR_APPEXECFWK_USER_REMOVE_FAILED, "ERR_APPEXECFWK_USER_REMOVE_FAILED"}, 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 94db2632e6..607669d78c 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 @@ -60,6 +60,7 @@ public: ErrCode OptimizeDisposedPredicates(const std::string &callingName, const std::string &appId, int32_t userId, int32_t appIndex, NativeRdb::AbsRdbPredicates &absRdbPredicates); bool IsAppInBlocklist(const std::string &bundleName); + bool CheckWhetherCanBeUninstalled(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 87f2838e83..5430dcf8d6 100644 --- a/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h +++ b/interfaces/inner_api/bundlemgr_extension/include/bundle_mgr_ext.h @@ -114,6 +114,10 @@ public: { return false; } + virtual bool CheckWhetherCanBeUninstalled(const std::string &bundleName) + { + return true; + } }; } // 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 f7ebc82c65..b30c0bd8cd 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 @@ -329,6 +329,21 @@ bool BmsExtensionDataMgr::IsAppInBlocklist(const std::string &bundleName) return bundleMgrExtPtr->IsAppInBlocklist(bundleName); } +bool BmsExtensionDataMgr::CheckWhetherCanBeUninstalled(const std::string &bundleName) +{ + if ((Init() != ERR_OK) || handler_ == nullptr) { + APP_LOGW("link failed"); + return true; + } + auto bundleMgrExtPtr = + BundleMgrExtRegister::GetInstance().GetBundleMgrExt(bmsExtension_.bmsExtensionBundleMgr.extensionName); + if (bundleMgrExtPtr == nullptr) { + APP_LOGW("GetBundleMgrExt failed"); + return true; + } + return bundleMgrExtPtr->CheckWhetherCanBeUninstalled(bundleName); +} + ErrCode BmsExtensionDataMgr::AddResourceInfoByBundleName(const std::string &bundleName, const int32_t userId) { if (Init() != ERR_OK || handler_ == nullptr) { diff --git a/interfaces/kits/js/installer/installer.cpp b/interfaces/kits/js/installer/installer.cpp index 8abf3a1d04..773ee12e57 100644 --- a/interfaces/kits/js/installer/installer.cpp +++ b/interfaces/kits/js/installer/installer.cpp @@ -410,6 +410,7 @@ static void CreateErrCodeMap(std::unordered_map &errCodeMap) { IStatusReceiver::ERR_UNINSTALL_NATIVE_FAILED, ERROR_UNINSTALL_NATIVE_FAILED}, { IStatusReceiver::ERR_NATIVE_HNP_EXTRACT_FAILED, ERROR_INSTALL_NATIVE_FAILED}, { IStatusReceiver::ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE, ERROR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE }, + { IStatusReceiver::ERR_UNINSTALL_CONTROLLED, ERROR_BUNDLE_CAN_NOT_BE_UNINSTALLED } }; } diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 2dc4125a92..a464de1b68 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -711,6 +711,7 @@ private: const InstallParam &installParam) const; bool InitDataMgr(); bool IsAppInBlocklist(const std::string &bundleName) const; + bool CheckWhetherCanBeUninstalled(const std::string &bundleName) const; InstallerState state_ = InstallerState::INSTALL_START; std::shared_ptr dataMgr_ = nullptr; // this pointer will get when public functions called diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 5fd5adee18..e2469d8ea8 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1426,6 +1426,10 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( return ERR_BUNDLE_MANAGER_APP_CONTROL_DISALLOWED_UNINSTALL; } + if (!CheckWhetherCanBeUninstalled(bundleName)) { + return ERR_APPEXECFWK_UNINSTALL_CONTROLLED; + } + // reboot scan case will not kill the bundle if (installParam.noSkipsKill) { // kill the bundle process during uninstall. @@ -5697,5 +5701,17 @@ bool BaseBundleInstaller::IsAppInBlocklist(const std::string &bundleName) const } return false; } + +bool BaseBundleInstaller::CheckWhetherCanBeUninstalled(const std::string &bundleName) const +{ + BmsExtensionDataMgr bmsExtensionDataMgr; + LOG_I(BMS_TAG_INSTALLER, "CheckUninstall %{public}s", bundleName.c_str()); + bool res = bmsExtensionDataMgr.CheckWhetherCanBeUninstalled(bundleName); + if (!res) { + LOG_E(BMS_TAG_INSTALLER, "uninstall %{public}s rejected", bundleName.c_str()); + return false; + } + return true; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/src/status_receiver_proxy.cpp b/services/bundlemgr/src/status_receiver_proxy.cpp index 6d327efb7a..2cb6e01c21 100644 --- a/services/bundlemgr/src/status_receiver_proxy.cpp +++ b/services/bundlemgr/src/status_receiver_proxy.cpp @@ -229,6 +229,7 @@ const char* MSG_ERR_INSTALL_CODE_SIGNATURE_REMOVE_FILE_FAILED = const char* MSG_ERR_INSTALL_CODE_APP_CONTROLLED_FAILED = "[MSG_ERR_INSTALL_CODE_APP_CONTROLLED_FAILED]"; const char* MSG_ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE = "[MSG_ERR_INSTALL_MULTI_APP_MAX_COUNT_DECREASE]"; +const char* MSG_ERR_UNINSTALL_CONTROLLED = "[MSG_ERR_UNINSTALL_CONTROLLED]"; const std::map MAP_RECEIVED_RESULTS { {ERR_OK, {IStatusReceiver::SUCCESS, MSG_SUCCESS}}, @@ -595,6 +596,9 @@ const std::map MAP_RECEIVED_RESULTS { {ERR_APPEXECFWK_INSTALL_APP_IN_BLOCKLIST, {IStatusReceiver::ERR_INSTALL_CODE_APP_CONTROLLED_FAILED, MSG_ERR_INSTALL_CODE_APP_CONTROLLED_FAILED}}, + {ERR_APPEXECFWK_UNINSTALL_CONTROLLED, + {IStatusReceiver::ERR_UNINSTALL_CONTROLLED, + MSG_ERR_UNINSTALL_CONTROLLED}}, }; } // namespace -- Gitee