From 4c6f6788fd1a5597176f88f05b27dac41d84bf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=BB=E6=9D=B0?= Date: Sat, 22 Feb 2025 14:11:07 +0800 Subject: [PATCH] Issue:#IBO2GW Description: uninstall clone aysnc on 5.0.3 Sig: SIG_ApplicaitonFramework Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: renjie84 renjie84@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 任杰 --- .../include/clone/bundle_clone_installer.h | 10 +++++--- .../bundlemgr/src/base_bundle_installer.cpp | 2 +- .../bundlemgr/src/bundle_installer_host.cpp | 2 +- .../src/clone/bundle_clone_installer.cpp | 19 +++++++------- .../bms_bundle_clone_installer_test.cpp | 25 ++++++++----------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/services/bundlemgr/include/clone/bundle_clone_installer.h b/services/bundlemgr/include/clone/bundle_clone_installer.h index 81e5e4fdde..b01a4f5157 100644 --- a/services/bundlemgr/include/clone/bundle_clone_installer.h +++ b/services/bundlemgr/include/clone/bundle_clone_installer.h @@ -45,24 +45,26 @@ public: * @param userId Indicates the clone app will be uninstalled under which user id. * @return Returns ERR_OK if the clone app uninstall successfully; returns error code otherwise. */ - ErrCode UninstallCloneApp(const std::string &bundleName, const int32_t userId, const int32_t appIndex); + ErrCode UninstallCloneApp(const std::string &bundleName, + const int32_t userId, const int32_t appIndex, bool sync); /** * @brief The main function for clone app uninstalling. * @param bundleName Indicates the bundleName of the clone applications to uninstall. * @return Returns ERR_OK if the clone apps uninstall successfully; returns error code otherwise. */ - ErrCode UninstallAllCloneApps(const std::string &bundleName, int32_t userId = Constants::INVALID_USERID); + ErrCode UninstallAllCloneApps(const std::string &bundleName, bool sync, + int32_t userId = Constants::INVALID_USERID); private: ErrCode CreateCloneDataDir( InnerBundleInfo &info, const int32_t userId, const int32_t &uid, const int32_t &appIndex) const; - ErrCode RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex); + ErrCode RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex, bool sync); ErrCode GetDataMgr(); void UninstallDebugAppSandbox(const std::string &bundleName, const int32_t uid, int32_t appIndex, const InnerBundleInfo& innerBundleInfo); ErrCode ProcessCloneBundleInstall(const std::string &bundleName, const int32_t userId, int32_t &appIndex); - ErrCode ProcessCloneBundleUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex); + ErrCode ProcessCloneBundleUninstall(const std::string &bundleName, int32_t userId, int32_t appIndex, bool sync); void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType, int32_t userId, int32_t appIndex, bool isPreInstallApp, bool isFreeInstallMode, diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index e4152bc2cb..2e96d62dfe 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -1550,7 +1550,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( } std::shared_ptr cloneInstaller = std::make_shared(); - cloneInstaller->UninstallAllCloneApps(bundleName, installParam.userId); + cloneInstaller->UninstallAllCloneApps(bundleName, installParam.isRemoveUser, installParam.userId); #ifdef BUNDLE_FRAMEWORK_APP_CONTROL std::shared_ptr appControlMgr = DelayedSingleton::GetInstance(); diff --git a/services/bundlemgr/src/bundle_installer_host.cpp b/services/bundlemgr/src/bundle_installer_host.cpp index 4899181070..cb8fd22b23 100644 --- a/services/bundlemgr/src/bundle_installer_host.cpp +++ b/services/bundlemgr/src/bundle_installer_host.cpp @@ -870,7 +870,7 @@ ErrCode BundleInstallerHost::UninstallCloneApp(const std::string &bundleName, in return ERR_APPEXECFWK_UNINSTALL_DISPOSED_RULE_FAILED; } std::shared_ptr installer = std::make_shared(); - return installer->UninstallCloneApp(bundleName, userId, appIndex); + return installer->UninstallCloneApp(bundleName, userId, appIndex, false); } void BundleInstallerHost::HandleUninstallCloneApp(MessageParcel &data, MessageParcel &reply) diff --git a/services/bundlemgr/src/clone/bundle_clone_installer.cpp b/services/bundlemgr/src/clone/bundle_clone_installer.cpp index 47166a2b73..f4bd5c0552 100644 --- a/services/bundlemgr/src/clone/bundle_clone_installer.cpp +++ b/services/bundlemgr/src/clone/bundle_clone_installer.cpp @@ -77,14 +77,14 @@ ErrCode BundleCloneInstaller::InstallCloneApp(const std::string &bundleName, } ErrCode BundleCloneInstaller::UninstallCloneApp( - const std::string &bundleName, const int32_t userId, const int32_t appIndex) + const std::string &bundleName, const int32_t userId, const int32_t appIndex, bool sync) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); APP_LOGD("UninstallCloneApp %{public}s _ %{public}d begin", bundleName.c_str(), appIndex); PerfProfile::GetInstance().SetBundleUninstallStartTime(GetTickCount()); - ErrCode result = ProcessCloneBundleUninstall(bundleName, userId, appIndex); + ErrCode result = ProcessCloneBundleUninstall(bundleName, userId, appIndex, sync); NotifyBundleEvents installRes = { .bundleName = bundleName, .resultCode = result, @@ -108,7 +108,7 @@ ErrCode BundleCloneInstaller::UninstallCloneApp( return result; } -ErrCode BundleCloneInstaller::UninstallAllCloneApps(const std::string &bundleName, int32_t userId) +ErrCode BundleCloneInstaller::UninstallAllCloneApps(const std::string &bundleName, bool sync, int32_t userId) { // All clone will be uninstalled when the original application is updated or uninstalled APP_LOGI("begin"); @@ -138,7 +138,7 @@ ErrCode BundleCloneInstaller::UninstallAllCloneApps(const std::string &bundleNam } ErrCode result = ERR_OK; for (auto it = userInfo.cloneInfos.begin(); it != userInfo.cloneInfos.end(); it++) { - if (UninstallCloneApp(bundleName, userId, std::stoi(it->first)) != ERR_OK) { + if (UninstallCloneApp(bundleName, userId, atoi(it->first.c_str()), sync) != ERR_OK) { APP_LOGE("UninstallCloneApp failed, appIndex %{public}s", it->first.c_str()); result = ERR_APPEXECFWK_CLONE_UNINSTALL_INTERNAL_ERROR; } @@ -222,12 +222,12 @@ ErrCode BundleCloneInstaller::ProcessCloneBundleInstall(const std::string &bundl appId_ = info.GetAppId(); appIdentifier_ = info.GetAppIdentifier(); + ScopeGuard createCloneDataDirGuard([&] { RemoveCloneDataDir(bundleName, userId, appIndex, true); }); ErrCode result = CreateCloneDataDir(info, userId, uid, appIndex); if (result != ERR_OK) { APP_LOGE("InstallCloneApp create clone dir failed"); return result; } - ScopeGuard createCloneDataDirGuard([&] { RemoveCloneDataDir(bundleName, userId, appIndex); }); ScopeGuard addCloneBundleGuard([&] { dataMgr->RemoveCloneBundle(bundleName, userId, appIndex); }); ErrCode addRes = dataMgr->AddCloneBundle(bundleName, attr); @@ -255,7 +255,7 @@ ErrCode BundleCloneInstaller::ProcessCloneBundleInstall(const std::string &bundl } ErrCode BundleCloneInstaller::ProcessCloneBundleUninstall(const std::string &bundleName, - int32_t userId, int32_t appIndex) + int32_t userId, int32_t appIndex, bool sync) { if (bundleName.empty()) { APP_LOGE("UninstallCloneApp failed due to empty bundle name"); @@ -305,7 +305,7 @@ ErrCode BundleCloneInstaller::ProcessCloneBundleUninstall(const std::string &bun APP_LOGE("RemoveCloneBundle failed"); return ERR_APPEXECFWK_CLONE_UNINSTALL_INTERNAL_ERROR; } - if (RemoveCloneDataDir(bundleName, userId, appIndex) != ERR_OK) { + if (RemoveCloneDataDir(bundleName, userId, appIndex, sync) != ERR_OK) { APP_LOGW("RemoveCloneDataDir failed"); } // process icon and label @@ -373,10 +373,11 @@ ErrCode BundleCloneInstaller::CreateCloneDataDir(InnerBundleInfo &info, return result; } -ErrCode BundleCloneInstaller::RemoveCloneDataDir(const std::string bundleName, int32_t userId, int32_t appIndex) +ErrCode BundleCloneInstaller::RemoveCloneDataDir( + const std::string bundleName, int32_t userId, int32_t appIndex, bool sync) { std::string key = BundleCloneCommonHelper::GetCloneDataDir(bundleName, appIndex); - if (InstalldClient::GetInstance()->RemoveBundleDataDir(key, userId) != ERR_OK) { + if (InstalldClient::GetInstance()->RemoveBundleDataDir(key, userId, false, !sync) != ERR_OK) { APP_LOGW("CloneApp cannot remove the data dir"); return ERR_APPEXECFWK_CLONE_INSTALL_INTERNAL_ERROR; } diff --git a/services/bundlemgr/test/unittest/bms_bundle_clone_installer_test/bms_bundle_clone_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_clone_installer_test/bms_bundle_clone_installer_test.cpp index 7de4187b27..292374cb01 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_clone_installer_test/bms_bundle_clone_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_clone_installer_test/bms_bundle_clone_installer_test.cpp @@ -190,18 +190,14 @@ HWTEST_F(BmsBundleCloneInstallerTest, BmsBundleCloneInstallerTest_001, TestSize. SetUserIdToDataMgr(userId_); - EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleInstall(BUNDLE_NAME, userId_, appIdx_), - ERR_APPEXECFWK_CLONE_INSTALL_NOT_INSTALLED_AT_SPECIFIED_USERID); - - - EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall("", userId_, appIdx_), + EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall("", userId_, appIdx_, true), ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_BUNDLE_NAME); - - EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall(BUNDLE_NAME, userId_, 0), - ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_APP_INDEX); - - EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall(BUNDLE_NAME, userId_, 6), + + EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall(BUNDLE_NAME, userId_, 0, true), ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_APP_INDEX); + + EXPECT_EQ(bundleCloneInstall_->ProcessCloneBundleUninstall(BUNDLE_NAME, userId_, 6, true), + ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_APP_INDEX); } /** @@ -223,11 +219,11 @@ HWTEST_F(BmsBundleCloneInstallerTest, BmsBundleCloneInstallerTest_002, TestSize. HWTEST_F(BmsBundleCloneInstallerTest, BmsBundleCloneInstallerTest_003, TestSize.Level1) { std::string bundleName = "bundleName"; - EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp("", userId_, appIdx_), + EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp("", userId_, appIdx_, true), ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_BUNDLE_NAME); - EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp(bundleName, userId_, appIdx_), + EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp(bundleName, userId_, appIdx_, true), ERR_APPEXECFWK_CLONE_UNINSTALL_INVALID_APP_INDEX); - EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp(bundleName, userId_, appIdx2_), + EXPECT_EQ(bundleCloneInstall_->UninstallCloneApp(bundleName, userId_, appIdx2_, true), ERR_APPEXECFWK_CLONE_UNINSTALL_APP_NOT_EXISTED); } @@ -256,6 +252,7 @@ HWTEST_F(BmsBundleCloneInstallerTest, BmsBundleCloneInstallerTest_004, TestSize. HWTEST_F(BmsBundleCloneInstallerTest, BmsBundleCloneInstallerTest_005, TestSize.Level1) { EXPECT_EQ( - bundleCloneInstall_->RemoveCloneDataDir("", userId_, appIdx_), ERR_APPEXECFWK_CLONE_INSTALL_INTERNAL_ERROR); + bundleCloneInstall_->RemoveCloneDataDir("", userId_, appIdx_, true), + ERR_APPEXECFWK_CLONE_INSTALL_INTERNAL_ERROR); } } -- Gitee