From 74a2395030912849dde93eb1926eb8be9a26b346 Mon Sep 17 00:00:00 2001 From: wanghang Date: Tue, 18 Oct 2022 14:09:41 +0800 Subject: [PATCH] IssueNo:#I5WB2G Description:fix tdd Sig:SIG_ApplicaitonFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: wanghang Change-Id: Iea8f5f526c0af6505e5aecdcc264cfae7d847a27 --- .../bundlemgr/include/inner_bundle_info.h | 13 +---- services/bundlemgr/src/bundle_data_mgr.cpp | 3 +- services/bundlemgr/src/inner_bundle_info.cpp | 47 +++---------------- .../bms_bundle_kit_service_test.cpp | 30 ++++++------ 4 files changed, 24 insertions(+), 69 deletions(-) diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 2d444f422d..a6dbefcc7f 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -1106,19 +1106,10 @@ public: * @param abilityName Indicates the abilityName. * @param isEnabled Indicates the ability enabled. * @param userId Indicates the user id. - * @return Return whether the application is enabled. - */ - bool SetAbilityEnabled( - const std::string &bundleName, const std::string &moduleName, const std::string &abilityName, - bool isEnabled, int32_t userId); - /** - * @brief Set ability enabled. - * @param AbilityInfo Indicates the AbilityInfo. - * @param isEnabled Indicates the ability enabled. - * @param userId Indicates the user id. * @return Returns ERR_OK if the setAbilityEnabled is successfully; returns error code otherwise. */ - ErrCode SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled, int32_t userId); + ErrCode SetAbilityEnabled(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, bool isEnabled, int32_t userId); /** * @brief Set the Application Need Recover object * @param moduleName Indicates the module name of the application. diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index a2748fdaaf..b4d305526c 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -2277,7 +2277,8 @@ ErrCode BundleDataMgr::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool is return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } InnerBundleInfo& newInfo = infoItem->second; - ErrCode ret = newInfo.SetAbilityEnabled(abilityInfo, isEnabled, userId); + ErrCode ret = newInfo.SetAbilityEnabled(abilityInfo.bundleName, abilityInfo.moduleName, + abilityInfo.name, isEnabled, userId); if (ret != ERR_OK) { return ret; } diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index eb9ed541ab..74946a105f 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -2487,11 +2487,8 @@ ErrCode InnerBundleInfo::IsAbilityEnabledV9(const AbilityInfo &abilityInfo, int3 return ERR_OK; } -bool InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName, - const std::string &moduleName, - const std::string &abilityName, - bool isEnabled, - int32_t userId) +ErrCode InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName, const std::string &moduleName, + const std::string &abilityName, bool isEnabled, int32_t userId) { APP_LOGD("SetAbilityEnabled :%{public}s, %{public}s, %{public}s, %{public}d", bundleName.c_str(), moduleName.c_str(), abilityName.c_str(), userId); @@ -2502,7 +2499,7 @@ bool InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName, auto infoItem = innerBundleUserInfos_.find(key); if (infoItem == innerBundleUserInfos_.end()) { APP_LOGE("SetAbilityEnabled find innerBundleUserInfo failed"); - return false; + return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; } auto iter = std::find(infoItem->second.bundleUserInfo.disabledAbilities.begin(), infoItem->second.bundleUserInfo.disabledAbilities.end(), @@ -2516,43 +2513,11 @@ bool InnerBundleInfo::SetAbilityEnabled(const std::string &bundleName, infoItem->second.bundleUserInfo.disabledAbilities.push_back(abilityName); } } - return true; - } - } - return false; -} - -ErrCode InnerBundleInfo::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnabled, int32_t userId) -{ - APP_LOGD("SetAbilityEnabled :%{public}s, %{public}s, %{public}s, %{public}d", - abilityInfo.bundleName.c_str(), abilityInfo.moduleName.c_str(), abilityInfo.name.c_str(), userId); - std::string keyName; - keyName.append(abilityInfo.bundleName).append(".") - .append(abilityInfo.moduleName).append(".").append(abilityInfo.name); - auto it = baseAbilityInfos_.find(keyName); - if (it == baseAbilityInfos_.end()) { - APP_LOGE("SetAbilityEnabled find abilityInfos failed"); - return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; - } - auto &key = NameAndUserIdToKey(abilityInfo.bundleName, userId); - auto infoItem = innerBundleUserInfos_.find(key); - if (infoItem == innerBundleUserInfos_.end()) { - APP_LOGE("SetAbilityEnabled can not find bundleUserInfo in userId: %{public}d", userId); - return ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST; - } - auto iter = std::find(infoItem->second.bundleUserInfo.disabledAbilities.begin(), - infoItem->second.bundleUserInfo.disabledAbilities.end(), - abilityInfo.name); - if (iter != infoItem->second.bundleUserInfo.disabledAbilities.end()) { - if (isEnabled) { - infoItem->second.bundleUserInfo.disabledAbilities.erase(iter); - } - } else { - if (!isEnabled) { - infoItem->second.bundleUserInfo.disabledAbilities.push_back(abilityInfo.name); + return ERR_OK; } } - return ERR_OK; + APP_LOGE("SetAbilityEnabled find abilityInfo failed"); + return ERR_BUNDLE_MANAGER_ABILITY_NOT_EXIST; } void InnerBundleInfo::RemoveDuplicateName(std::vector &name) const diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index f864567c54..42bfc3a4b8 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -2740,7 +2740,6 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0100, Function | Small int32_t ret = GetBundleDataMgr()->IsApplicationEnabled(BUNDLE_NAME_TEST, isEnable); EXPECT_EQ(0, ret); EXPECT_TRUE(isEnable); - MockUninstallBundle(BUNDLE_NAME_TEST); } @@ -2754,7 +2753,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0200, Function | Small { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true); + int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t ret = GetBundleDataMgr()->IsApplicationEnabled(BUNDLE_NAME_TEST, isEnable); @@ -2774,14 +2773,14 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0300, Function | Small { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, false); + int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, false, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t ret = GetBundleDataMgr()->IsApplicationEnabled(BUNDLE_NAME_TEST, isEnable); EXPECT_EQ(0, ret); EXPECT_FALSE(isEnable); - int32_t testRet2 = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true); + int32_t testRet2 = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet2); ret = GetBundleDataMgr()->IsApplicationEnabled(BUNDLE_NAME_TEST, isEnable); EXPECT_EQ(0, ret); @@ -2813,7 +2812,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0500, Function | Small { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled("", true); + int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled("", true, Constants::DEFAULT_USERID); EXPECT_NE(0, testRet); bool isEnable = false; int32_t ret = GetBundleDataMgr()->IsApplicationEnabled(BUNDLE_NAME_TEST, isEnable); @@ -2833,7 +2832,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0600, Function | Small { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true); + int32_t testRet = GetBundleDataMgr()->SetApplicationEnabled(BUNDLE_NAME_TEST, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t testRet1 = GetBundleDataMgr()->IsApplicationEnabled("", isEnable); @@ -2857,7 +2856,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckApplicationEnabled_0700, Function | Small APP_LOGE("bundle mgr proxy is nullptr."); EXPECT_EQ(bundleMgrProxy, nullptr); } - int32_t testRet = bundleMgrProxy->SetApplicationEnabled("", true); + int32_t testRet = bundleMgrProxy->SetApplicationEnabled("", true, Constants::DEFAULT_USERID); EXPECT_NE(0, testRet); bool isEnable = false; int32_t testRet1 = bundleMgrProxy->IsApplicationEnabled("", isEnable); @@ -3556,7 +3555,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0200, Function | SmallTest { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); AbilityInfo abilityInfo = MockAbilityInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_TRUE(testRet == 0); bool isEnable = false; int32_t testRet1 = GetBundleDataMgr()->IsAbilityEnabled(abilityInfo, isEnable); @@ -3576,18 +3575,17 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0300, Function | SmallTest { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); AbilityInfo abilityInfo = MockAbilityInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, false); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, false, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t testRet1 = GetBundleDataMgr()->IsAbilityEnabled(abilityInfo, isEnable); EXPECT_EQ(0, testRet1); EXPECT_FALSE(isEnable); - int32_t testRet2 = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet2 = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet2); int32_t testRet3 = GetBundleDataMgr()->IsAbilityEnabled(abilityInfo, isEnable); EXPECT_EQ(0, testRet3); EXPECT_TRUE(isEnable); - MockUninstallBundle(BUNDLE_NAME_TEST); } @@ -3616,7 +3614,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0500, Function | SmallTest MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); AbilityInfo abilityInfoEmpty; - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfoEmpty, false); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfoEmpty, false, Constants::DEFAULT_USERID); EXPECT_NE(0, testRet); AbilityInfo abilityInfo = MockAbilityInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); bool isEnable = false; @@ -3636,7 +3634,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0600, Function | SmallTest { MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); AbilityInfo abilityInfo = MockAbilityInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); AbilityInfo abilityInfoEmpty; bool isEnable = false; @@ -3659,7 +3657,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0700, Function | SmallTest AbilityInfo abilityInfo; abilityInfo.name = ABILITY_NAME_TEST; abilityInfo.bundleName = BUNDLE_NAME_TEST; - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t testRet1 = GetBundleDataMgr()->IsAbilityEnabled(abilityInfo, isEnable); @@ -3683,7 +3681,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0800, Function | SmallTest abilityInfo.name = ABILITY_NAME_TEST; abilityInfo.bundleName = BUNDLE_NAME_TEST; abilityInfo.moduleName = MODULE_NAME_TEST; - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_EQ(0, testRet); bool isEnable = false; int32_t testRet1 = GetBundleDataMgr()->IsAbilityEnabled(abilityInfo, isEnable); @@ -3707,7 +3705,7 @@ HWTEST_F(BmsBundleKitServiceTest, CheckAbilityEnabled_0900, Function | SmallTest abilityInfo.name = ABILITY_NAME_TEST; abilityInfo.bundleName = BUNDLE_NAME_TEST; abilityInfo.moduleName = MODULE_NAME_TEST_1; - int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true); + int32_t testRet = GetBundleDataMgr()->SetAbilityEnabled(abilityInfo, true, Constants::DEFAULT_USERID); EXPECT_FALSE(testRet == 0); MockUninstallBundle(BUNDLE_NAME_TEST); } -- Gitee