diff --git a/services/bundlemgr/include/base_bundle_installer.h b/services/bundlemgr/include/base_bundle_installer.h index 2bba99f7eb9a5419bf6465c9155ad65fe3481906..551c11c35dc35d131509cc725a4db835ca20a792 100644 --- a/services/bundlemgr/include/base_bundle_installer.h +++ b/services/bundlemgr/include/base_bundle_installer.h @@ -812,6 +812,8 @@ private: ErrCode CheckPreAppAllowHdcInstall(const InstallParam &installParam, const std::vector &hapVerifyRes); void CheckPreBundleRecoverResult(ErrCode &result); + ErrCode UninstallBundleErrInfo(InnerBundleInfo &info, int32_t &versionCode, + const std::string &uninstallDir); bool IsAllowEnterPrise(); diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 86f4861ba3299beff5b7e5022712212022b3ecf1..4b4caac8354f98c6f1ae7f45a4a1436fd1641dc9 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -421,7 +421,6 @@ ErrCode BaseBundleInstaller::UninstallBundleByUninstallParam(const UninstallPara LOG_E(BMS_TAG_INSTALLER, "uninstall bundle name or module name empty"); return ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST; } - if (!InitDataMgr()) { return ERR_APPEXECFWK_UNINSTALL_BUNDLE_MGR_SERVICE_ERROR; } @@ -451,14 +450,7 @@ ErrCode BaseBundleInstaller::UninstallBundleByUninstallParam(const UninstallPara return ERR_APPEXECFWK_UNINSTALL_SHARE_APP_LIBRARY_IS_NOT_EXIST; } std::string uninstallDir = std::string(Constants::BUNDLE_CODE_DIR) + ServiceConstants::PATH_SEPARATOR + bundleName; - if ((versionCodes.size() > SINGLE_HSP_VERSION && versionCode == Constants::ALL_VERSIONCODE) || - versionCodes.size() == SINGLE_HSP_VERSION) { - return UninstallHspBundle(uninstallDir, info.GetBundleName()); - } else { - uninstallDir += std::string(ServiceConstants::PATH_SEPARATOR) + - HSP_VERSION_PREFIX + std::to_string(versionCode); - return UninstallHspVersion(uninstallDir, versionCode, info); - } + return UninstallBundleErrInfo(info, versionCode, uninstallDir); } ErrCode BaseBundleInstaller::UninstallHspBundle(std::string &uninstallDir, const std::string &bundleName) @@ -485,15 +477,8 @@ ErrCode BaseBundleInstaller::UninstallHspBundle(std::string &uninstallDir, const if (!DelayedSingleton::GetInstance()->DeleteAppProvisionInfo(bundleName)) { LOG_W(BMS_TAG_INSTALLER, "bundleName: %{public}s delete appProvisionInfo failed", bundleName.c_str()); } - InstallParam installParam; versionCode_ = Constants::ALL_VERSIONCODE; userId_ = Constants::ALL_USERID; - SendBundleSystemEvent( - bundleName, - BundleEventType::UNINSTALL, - installParam, - sysEventInfo_.preBundleScene, - errCode); PerfProfile::GetInstance().SetBundleUninstallEndTime(GetTickCount()); /* remove sign profile from code signature for cross-app hsp */ RemoveProfileFromCodeSign(bundleName); @@ -524,16 +509,9 @@ ErrCode BaseBundleInstaller::UninstallHspVersion(std::string &uninstallDir, int3 LOG_E(BMS_TAG_INSTALLER, "update install success failed"); return ERR_APPEXECFWK_UPDATE_BUNDLE_INSTALL_STATUS_ERROR; } - InstallParam installParam; versionCode_ = Constants::ALL_VERSIONCODE; userId_ = Constants::ALL_USERID; std::string bundleName = info.GetBundleName(); - SendBundleSystemEvent( - bundleName, - BundleEventType::UNINSTALL, - installParam, - sysEventInfo_.preBundleScene, - errCode); PerfProfile::GetInstance().SetBundleUninstallEndTime(GetTickCount()); return ERR_OK; } @@ -3702,9 +3680,9 @@ ErrCode BaseBundleInstaller::RemoveBundleDataDir( ErrCode result = InstalldClient::GetInstance()->RemoveBundleDataDir(info.GetBundleName(), userId_, info.GetApplicationBundleType() == BundleType::ATOMIC_SERVICE, async); + InstallParam installParam; if (result == ERR_APPEXECFWK_INSTALLD_REMOVE_DIR_FAILED) { LOG_W(BMS_TAG_INSTALLER, "RemoveBundleDataDir failed %{public}d", result); - InstallParam installParam; SendBundleSystemEvent( info.GetBundleName(), BundleEventType::UNINSTALL, @@ -3719,8 +3697,15 @@ ErrCode BaseBundleInstaller::RemoveBundleDataDir( auto extensionDirs = info.GetAllExtensionDirs(); result = InstalldClient::GetInstance()->RemoveExtensionDir(userId_, extensionDirs); } - if (result != ERR_OK) { + if (result == ERR_APPEXECFWK_INSTALLD_REMOVE_DIR_FAILED) { LOG_E(BMS_TAG_INSTALLER, "fail to remove bundle extension dir, error is %{public}d", result); + InstallParam installParam; + SendBundleSystemEvent( + info.GetBundleName(), + BundleEventType::UNINSTALL, + installParam, + sysEventInfo_.preBundleScene, + result); } return ERR_OK; } @@ -6556,6 +6541,29 @@ ErrCode BaseBundleInstaller::RollbackHmpCommonInfo(const std::string &bundleName return ERR_OK; } +ErrCode BaseBundleInstaller::UninstallBundleErrInfo(InnerBundleInfo &info, int32_t &versionCode, + std::string uninstallDir) +{ + std::vector versionCodes = info.GetAllHspVersion(); + InstallParam installParam; + ErrCode ret = ERR_OK; + if ((versionCodes.size() > SINGLE_HSP_VERSION && versionCode == Constants::ALL_VERSIONCODE) || + versionCodes.size() == SINGLE_HSP_VERSION) { + ErrCode ret = UninstallHspBundle(uninstallDir, info.GetBundleName()); + SendBundleSystemEvent(info.GetBundleName(), BundleEventType::UNINSTALL, installParam, + sysEventInfo_.preBundleScene, ret); + return ret; + } else { + uninstallDir += std::string(ServiceConstants::PATH_SEPARATOR) + + HSP_VERSION_PREFIX + std::to_string(versionCode); + ErrCode ret = UninstallHspVersion(uninstallDir, versionCode, info); + SendBundleSystemEvent(info.GetBundleName(), BundleEventType::UNINSTALL, installParam, + sysEventInfo_.preBundleScene, ret); + return ret; + } + return ret; +} + bool BaseBundleInstaller::IsAppInBlocklist(const std::string &bundleName, const int32_t userId) const { BmsExtensionDataMgr bmsExtensionDataMgr;