From 08813b21ddb1d4c41c8691466d4b735241f680a9 Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Fri, 8 Aug 2025 15:55:03 +0800 Subject: [PATCH] support appIdentifier Signed-off-by: lanhaoyu --- .../app_control_manager_host_impl.cpp | 26 ++- .../app_control/app_control_manager_rdb.cpp | 71 +++++++- .../bms_bundle_app_control_test.cpp | 167 +++++++++++++++++- .../bms_bundle_mock_app_control.cpp | 85 +++++++++ 4 files changed, 342 insertions(+), 7 deletions(-) diff --git a/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp b/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp index aca8dfaa5d..22dea965ad 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_host_impl.cpp @@ -74,7 +74,18 @@ ErrCode AppControlManagerHostImpl::AddAppInstallControlRule(const std::vector modifyAppIds = appIds; + for (auto &appId : appIds) { + if (dataMgr_ == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "dataMgr_ is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string transformAppId = dataMgr_->AppIdAndAppIdentifierTransform(appId); + if (!transformAppId.empty()) { + modifyAppIds.emplace_back(transformAppId); + } + } + UpdateAppControlledInfo(userId, modifyAppIds); } SendAppControlEvent(ControlActionType::INSTALL, ControlOperationType::ADD_RULE, callingName, userId, Constants::MAIN_APP_INDEX, appIds, ruleType); @@ -105,7 +116,18 @@ ErrCode AppControlManagerHostImpl::DeleteAppInstallControlRule(const AppInstallC return ret; } if (ruleType == AppControlConstants::APP_DISALLOWED_UNINSTALL) { - UpdateAppControlledInfo(userId, appIds); + std::vector modifyAppIds = appIds; + for (auto &appId : appIds) { + if (dataMgr_ == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "dataMgr_ is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string transformAppId = dataMgr_->AppIdAndAppIdentifierTransform(appId); + if (!transformAppId.empty()) { + modifyAppIds.emplace_back(transformAppId); + } + } + UpdateAppControlledInfo(userId, modifyAppIds); } SendAppControlEvent(ControlActionType::INSTALL, ControlOperationType::REMOVE_RULE, callingName, userId, Constants::MAIN_APP_INDEX, appIds, ruleType); diff --git a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp index e9a5f12adb..56dd28595e 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp @@ -18,6 +18,7 @@ #include "app_control_constants.h" #include "app_log_tag_wrapper.h" #include "bms_extension_client.h" +#include "bundle_mgr_service.h" #include "bundle_util.h" #include "hitrace_meter.h" #include "scope_guard.h" @@ -81,6 +82,10 @@ ErrCode AppControlManagerRdb::AddAppInstallControlRule(const std::string &callin int64_t timeStamp = BundleUtil::GetCurrentTime(); std::vector valuesBuckets; for (auto appId : appIds) { + if (appId.empty()) { + LOG_D(BMS_TAG_DEFAULT, "appId or appIdentifier is empty"); + continue; + } ErrCode result = DeleteOldControlRule(callingName, controlRuleType, appId, userId); if (result != ERR_OK) { LOG_E(BMS_TAG_DEFAULT, "DeleteOldControlRule failed"); @@ -110,12 +115,23 @@ ErrCode AppControlManagerRdb::AddAppInstallControlRule(const std::string &callin ErrCode AppControlManagerRdb::DeleteAppInstallControlRule(const std::string &callingName, const std::string &controlRuleType, const std::vector &appIds, int32_t userId) { + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } for (const auto &appId : appIds) { + if (appId.empty()) { + LOG_D(BMS_TAG_DEFAULT, "appId or appIdentifier is empty"); + continue; + } + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(appId); + std::vector appIdList { appId, transformedAppId }; NativeRdb::AbsRdbPredicates absRdbPredicates(APP_CONTROL_RDB_TABLE_NAME); absRdbPredicates.EqualTo(CALLING_NAME, callingName); absRdbPredicates.EqualTo(APP_CONTROL_LIST, controlRuleType); absRdbPredicates.EqualTo(USER_ID, std::to_string(userId)); - absRdbPredicates.EqualTo(APP_ID, appId); + absRdbPredicates.In(APP_ID, appIdList); bool ret = rdbDataManager_->DeleteData(absRdbPredicates); if (!ret) { LOG_E(BMS_TAG_DEFAULT, "Delete failed callingName:%{public}s appId:%{private}s userId:%{public}d", @@ -171,6 +187,11 @@ ErrCode AppControlManagerRdb::GetAppInstallControlRule(const std::string &callin LOG_E(BMS_TAG_DEFAULT, "GoToFirstRow failed, ret: %{public}d", ret); return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; } + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } do { std::string appId; ret = absSharedResultSet->GetString(APP_ID_INDEX, appId); @@ -178,7 +199,12 @@ ErrCode AppControlManagerRdb::GetAppInstallControlRule(const std::string &callin LOG_E(BMS_TAG_DEFAULT, "GetString appId failed, ret: %{public}d", ret); return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; } + if (std::find(appIds.begin(), appIds.end(), appId) != appIds.end()) { + continue; + } + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(appId); appIds.push_back(appId); + appIds.push_back(transformedAppId); } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); return ERR_OK; } @@ -189,6 +215,10 @@ ErrCode AppControlManagerRdb::AddAppRunningControlRule(const std::string &callin int64_t timeStamp = BundleUtil::GetCurrentTime(); std::vector valuesBuckets; for (auto &controlRule : controlRules) { + if (controlRule.appId.empty()) { + LOG_D(BMS_TAG_DEFAULT, "appId or appIdentifier is empty"); + continue; + } ErrCode result = DeleteOldControlRule(callingName, RUNNING_CONTROL, controlRule.appId, userId); if (result != ERR_OK) { LOG_E(BMS_TAG_DEFAULT, "DeleteOldControlRule failed"); @@ -220,12 +250,19 @@ ErrCode AppControlManagerRdb::AddAppRunningControlRule(const std::string &callin ErrCode AppControlManagerRdb::DeleteAppRunningControlRule(const std::string &callingName, const std::vector &controlRules, int32_t userId) { + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } for (auto &rule : controlRules) { + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(rule.appId); + std::vector appIdList { rule.appId, transformedAppId }; NativeRdb::AbsRdbPredicates absRdbPredicates(APP_CONTROL_RDB_TABLE_NAME); absRdbPredicates.EqualTo(CALLING_NAME, callingName); absRdbPredicates.EqualTo(APP_CONTROL_LIST, RUNNING_CONTROL); absRdbPredicates.EqualTo(USER_ID, std::to_string(userId)); - absRdbPredicates.EqualTo(APP_ID, rule.appId); + absRdbPredicates.In(APP_ID, appIdList); bool ret = rdbDataManager_->DeleteData(absRdbPredicates); if (!ret) { LOG_E(BMS_TAG_DEFAULT, "Delete failed callingName:%{public}s appid:%{private}s userId:%{public}d", @@ -286,7 +323,19 @@ ErrCode AppControlManagerRdb::GetAppRunningControlRule(const std::string &callin LOG_E(BMS_TAG_DEFAULT, "GetString appId failed, ret: %{public}d", ret); return ERR_APPEXECFWK_DB_RESULT_SET_OPT_ERROR; } + if (std::find(appIds.begin(), appIds.end(), appId) != appIds.end()) { + continue; + } appIds.push_back(appId); + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(appId); + if (!transformedAppId.empty()) { + appIds.push_back(transformedAppId); + } } while (absSharedResultSet->GoToNextRow() == NativeRdb::E_OK); return ERR_OK; } @@ -295,8 +344,15 @@ ErrCode AppControlManagerRdb::GetAppRunningControlRule(const std::string &appId, int32_t userId, AppRunningControlRuleResult &controlRuleResult) { HITRACE_METER_NAME_EX(HITRACE_LEVEL_INFO, HITRACE_TAG_APP, __PRETTY_FUNCTION__, nullptr); + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(appId); + std::vector appIdList { appId, transformedAppId }; NativeRdb::AbsRdbPredicates absRdbPredicates(APP_CONTROL_RDB_TABLE_NAME); - absRdbPredicates.EqualTo(APP_ID, appId); + absRdbPredicates.In(APP_ID, appIdList); absRdbPredicates.EqualTo(APP_CONTROL_LIST, RUNNING_CONTROL); absRdbPredicates.EqualTo(USER_ID, std::to_string(userId)); absRdbPredicates.OrderByAsc(PRIORITY); // ascending @@ -446,11 +502,18 @@ ErrCode AppControlManagerRdb::GetDisposedStatus(const std::string &callingName, ErrCode AppControlManagerRdb::DeleteOldControlRule(const std::string &callingName, const std::string &controlRuleType, const std::string &appId, int32_t userId) { + auto dataMgr = DelayedSingleton::GetInstance()->GetDataMgr(); + if (dataMgr == nullptr) { + LOG_E(BMS_TAG_DEFAULT, "DataMgr is nullptr"); + return ERR_APPEXECFWK_NULL_PTR; + } + std::string transformedAppId = dataMgr->AppIdAndAppIdentifierTransform(appId); + std::vector appIdList { appId, transformedAppId }; NativeRdb::AbsRdbPredicates absRdbPredicates(APP_CONTROL_RDB_TABLE_NAME); absRdbPredicates.EqualTo(CALLING_NAME, callingName); absRdbPredicates.EqualTo(APP_CONTROL_LIST, controlRuleType); absRdbPredicates.EqualTo(USER_ID, std::to_string(userId)); - absRdbPredicates.EqualTo(APP_ID, appId); + absRdbPredicates.In(APP_ID, appIdList); bool ret = rdbDataManager_->DeleteData(absRdbPredicates); if (!ret) { LOG_E(BMS_TAG_DEFAULT, "DeleteOldControlRule %{public}s, %{public}s, %{public}s, %{public}d failed", diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp index e181c7cd4c..aa1306c030 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_app_control_test.cpp @@ -66,6 +66,13 @@ const int32_t MAIN_APP_INDEX = -1; const int32_t CLONE_APP_INDEX_MAX = 6; const int32_t APP_INDEX = 1; const int32_t UNSPECIFIED_USERID = -2; +constexpr const char* DB_CALLING_NAME = "CALLING_NAME"; +constexpr const char* APP_CONTROL_LIST = "APP_CONTROL_LIST"; +constexpr const char* USER_ID = "USER_ID"; +constexpr const char* APP_ID = "APP_ID"; +constexpr const char* TIME_STAMP = "TIME_STAMP"; +constexpr const char* DB_CONTROL_MESSAGE = "CONTROL_MESSAGE"; +constexpr const char* PRIORITY = "PRIORITY"; } // namespace class BmsBundleAppControlTest : public testing::Test { @@ -263,7 +270,7 @@ HWTEST_F(BmsBundleAppControlTest, AppInstallControlRule_0100, Function | SmallTe res = appControlProxy-> GetAppInstallControlRule(AppInstallControlRuleType::DISALLOWED_UNINSTALL, USERID, resultAppIds); EXPECT_EQ(res, ERR_OK); - EXPECT_EQ(appIds.size(), resultAppIds.size()); + EXPECT_EQ(appIds.size() * 2, resultAppIds.size()); for (size_t i = 0; i < AppControlConstants::LIST_MAX_SIZE; i++) { appIds.emplace_back(APPID); } @@ -3308,4 +3315,162 @@ HWTEST_F(BmsBundleAppControlTest, DisposeRuleCacheOnlyForBms_0100, Function | Me ret = appControlManager->GetDisposedRuleOnlyForBms(appId, disposedRules); EXPECT_FALSE(ret); } + +/** + * @tc.number: AppInstallControlRule_0600 + * @tc.name: test can not add app install control rule with empty appId + * @tc.desc: 1.AppInstallControlRule test empty appId + * 2.GetAppInstallControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppInstallControlRule_0600, Function | SmallTest | Level1) +{ + std::vector appIds = {"", "appId"}; + auto res = appControlManagerDb_->AddAppInstallControlRule("callingName", appIds, "", USERID); + EXPECT_EQ(res, ERR_OK); + std::vector resultAppIds; + res = appControlManagerDb_->GetAppInstallControlRule("callingName", "", USERID, resultAppIds); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(resultAppIds.size(), 2); +} + +/** + * @tc.number: AppInstallControlRule_0700 + * @tc.name: test can not get app install control rule when dataMgr is null + * @tc.desc: 1.AddAppInstallControlRule run normally + * 2.GetAppInstallControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppInstallControlRule_0700, Function | SmallTest | Level1) +{ + std::vector appIds = {"", "appId"}; + auto res = appControlManagerDb_->AddAppInstallControlRule(CALLER_BUNDLE_NAME, appIds, "", USERID); + EXPECT_EQ(res, ERR_OK); + std::vector resultAppIds; + DelayedSingleton::GetInstance()->dataMgr_ = nullptr; + res = appControlManagerDb_->GetAppInstallControlRule(CALLER_BUNDLE_NAME, "", USERID, resultAppIds); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + DelayedSingleton::GetInstance()->dataMgr_ = std::make_shared(); +} + +/** + * @tc.number: AppInstallControlRule_0800 + * @tc.name: test get app install control rule + * @tc.desc: 1.add 2 same app install control rule + * 2.GetAppInstallControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppInstallControlRule_0800, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + ASSERT_NE(rdb->rdbDataManager_, nullptr); + std::vector appIds; + std::string appId = "testAppId"; + std::string ruleType = "testRuleType"; + appIds.emplace_back(appId); + auto res = appControlManagerDb_->AddAppInstallControlRule(CALLER_BUNDLE_NAME, appIds, ruleType, USERID); + EXPECT_EQ(res, ERR_OK); + NativeRdb::ValuesBucket valuesBucket; + valuesBucket.PutString(DB_CALLING_NAME, CALLER_BUNDLE_NAME); + valuesBucket.PutString(APP_CONTROL_LIST, ruleType); + valuesBucket.PutInt(USER_ID, static_cast(USERID)); + valuesBucket.PutString(APP_ID, appId); + valuesBucket.PutInt(TIME_STAMP, 1); + rdb->rdbDataManager_->InsertData(valuesBucket); + std::vector resultAppIds; + res = appControlManagerDb_->GetAppInstallControlRule(CALLER_BUNDLE_NAME, ruleType, USERID, resultAppIds); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(resultAppIds.size(), 2); +} + +/** + * @tc.number: AppRunningControlRule_0900 + * @tc.name: test can not get app running control rule when dataMgr is null + * @tc.desc: 1.AddAppRunningControlRule run normally + * 2.GetAppRunningControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppRunningControlRule_0900, Function | SmallTest | Level1) +{ + std::vector controlRules; + AppRunningControlRule controlRule; + controlRule.appId = "test"; + controlRules.push_back(controlRule); + auto res = appControlManagerDb_->AddAppRunningControlRule(CALLER_BUNDLE_NAME, controlRules, USERID); + EXPECT_EQ(res, ERR_OK); + std::vector resultAppIds; + DelayedSingleton::GetInstance()->dataMgr_ = nullptr; + res = appControlManagerDb_->GetAppRunningControlRule(CALLER_BUNDLE_NAME, USERID, resultAppIds); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + DelayedSingleton::GetInstance()->dataMgr_ = std::make_shared(); +} + +/** + * @tc.number: AppRunningControlRule_1000 + * @tc.name: test get app running control rule + * @tc.desc: 1.add 2 same app running control rule + * 2.GetAppRunningControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppRunningControlRule_1000, Function | SmallTest | Level1) +{ + auto rdb = std::make_shared(); + ASSERT_NE(rdb, nullptr); + ASSERT_NE(rdb->rdbDataManager_, nullptr); + std::vector controlRules; + AppRunningControlRule controlRule; + controlRule.appId = "testAppId"; + controlRule.controlMessage = "testMessage"; + controlRules.push_back(controlRule); + auto res = appControlManagerDb_->AddAppRunningControlRule(CALLER_BUNDLE_NAME, controlRules, USERID); + EXPECT_EQ(res, ERR_OK); + std::string ruleType = "RunningControl"; + NativeRdb::ValuesBucket valuesBucket; + valuesBucket.PutString(DB_CALLING_NAME, CALLER_BUNDLE_NAME); + valuesBucket.PutString(APP_CONTROL_LIST, ruleType); + valuesBucket.PutInt(USER_ID, USERID); + valuesBucket.PutString(APP_ID, controlRule.appId); + valuesBucket.PutString(DB_CONTROL_MESSAGE, controlRule.controlMessage); + valuesBucket.PutInt(PRIORITY, static_cast(100)); + valuesBucket.PutInt(TIME_STAMP, 1); + rdb->rdbDataManager_->InsertData(valuesBucket); + std::vector resultAppIds; + res = appControlManagerDb_->GetAppRunningControlRule(CALLER_BUNDLE_NAME, USERID, resultAppIds); + EXPECT_EQ(res, ERR_OK); + EXPECT_EQ(resultAppIds.size(), 2); +} + +/** + * @tc.number: AppControlManagerHostImpl_8100 + * @tc.name: test DeleteAppInstallControlRule by AppControlManagerHostImpl + * @tc.desc: 1.DeleteAppInstallControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppControlManagerHostImpl_8100, Function | SmallTest | Level1) +{ + auto impl = std::make_shared(); + impl->callingNameMap_.insert(pair(0, AppControlConstants::EDM_CALLING)); + std::vector appIds; + appIds.emplace_back(APPID); + ErrCode res = impl->DeleteAppInstallControlRule(AppInstallControlRuleType::DISALLOWED_UNINSTALL, appIds, USERID); + EXPECT_EQ(res, ERR_OK); + impl->dataMgr_ = nullptr; + res = impl->DeleteAppInstallControlRule(AppInstallControlRuleType::DISALLOWED_UNINSTALL, appIds, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + impl->dataMgr_ = std::make_shared(); +} + +/** + * @tc.number: AppControlManagerHostImpl_8200 + * @tc.name: test AddAppInstallControlRule by AppControlManagerHostImpl + * @tc.desc: 1.AddAppInstallControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AppControlManagerHostImpl_8200, Function | SmallTest | Level1) +{ + auto impl = std::make_shared(); + std::vector appIds; + appIds.emplace_back(APPID); + impl->callingNameMap_.insert(pair(0, AppControlConstants::EDM_CALLING)); + ErrCode res = impl->AddAppInstallControlRule(appIds, AppInstallControlRuleType::DISALLOWED_UNINSTALL, USERID); + EXPECT_EQ(res, ERR_OK); + impl->dataMgr_ = nullptr; + res = impl->AddAppInstallControlRule(appIds, AppInstallControlRuleType::DISALLOWED_UNINSTALL, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + impl->dataMgr_ = std::make_shared(); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp index 1d00395708..887e93dda1 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_app_control_test/bms_bundle_mock_app_control.cpp @@ -180,6 +180,7 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0060, Function | Smal AppControlManagerRdb rdb; std::vector controlRules; AppRunningControlRule appRunningControlRule; + appRunningControlRule.appId = "test"; controlRules.push_back(appRunningControlRule); ErrCode res = rdb.AddAppRunningControlRule("", controlRules, USERID); EXPECT_EQ(res, ERR_APPEXECFWK_DB_DELETE_ERROR); @@ -724,4 +725,88 @@ HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerHostImpl_0140, Function | auto ret = impl.DeleteDisposedRuleForCloneApp(APPID, Constants::MAIN_APP_INDEX, Constants::UNSPECIFIED_USERID); EXPECT_EQ(ret, ERR_APPEXECFWK_DB_DELETE_ERROR); } + +/** + * @tc.number: AppControlManagerRdb_0180 + * @tc.name: Test AddAppInstallControlRule with empty appId by AppControlManagerRdb + * @tc.desc: 1.AddAppInstallControlRule test + */ +HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0180, Function | SmallTest | Level1) +{ + AppControlManagerRdb rdb; + std::vector appIds = {"", "appId"}; + std::string targetBundleName = "bundleName"; + auto res = rdb.AddAppInstallControlRule(targetBundleName, appIds, "", USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_DB_DELETE_ERROR); +} + +/** + * @tc.number: AppControlManagerRdb_0190 + * @tc.name: Test DeleteAppInstallControlRule by AppControlManagerRdb + * @tc.desc: 1.AddAppInstallControlRule test + */ +HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0190, Function | SmallTest | Level1) +{ + AppControlManagerRdb rdb; + std::vector appIds = {"", "appId"}; + std::string targetBundleName = "bundleName"; + auto res = rdb.AddAppInstallControlRule(targetBundleName, appIds, "", USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_DB_DELETE_ERROR); + res = rdb.DeleteAppInstallControlRule(targetBundleName, "", appIds, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_DB_DELETE_ERROR); +} + +/** + * @tc.number: AppControlManagerRdb_0200 + * @tc.name: Test DeleteAppInstallControlRule when dataMgr is null + * @tc.desc: 1.AddAppInstallControlRule test + */ +HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0200, Function | SmallTest | Level1) +{ + AppControlManagerRdb rdb; + std::vector appIds = {"", "appId"}; + std::string targetBundleName = "bundleName"; + DelayedSingleton::GetInstance()->dataMgr_ = nullptr; + auto res = rdb.AddAppInstallControlRule(targetBundleName, appIds, "", USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + res = rdb.DeleteAppInstallControlRule(targetBundleName, "", appIds, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + DelayedSingleton::GetInstance()->dataMgr_ = std::make_shared(); +} + +/** + * @tc.number: AppControlManagerRdb_0210 + * @tc.name: Test AddAppRunningControlRule with empty appId by AppControlManagerRdb + * @tc.desc: 1.AddAppInstallControlRule test + */ +HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0210, Function | SmallTest | Level1) +{ + AppControlManagerRdb rdb; + std::vector controlRules; + AppRunningControlRule appRunningControlRule1; + appRunningControlRule1.appId = ""; + AppRunningControlRule appRunningControlRule2; + appRunningControlRule2.appId = "test"; + controlRules.push_back(appRunningControlRule1); + controlRules.push_back(appRunningControlRule2); + ErrCode res = rdb.AddAppRunningControlRule("", controlRules, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_DB_DELETE_ERROR); +} + +/** + * @tc.number: AppControlManagerRdb_0220 + * @tc.name: test DeleteAppRunningControlRule when dataMgr is null + * @tc.desc: 1.AddAppRunningControlRule test + */ +HWTEST_F(BmsBundleMockAppControlTest, AppControlManagerRdb_0220, Function | SmallTest | Level1) +{ + AppControlManagerRdb rdb; + DelayedSingleton::GetInstance()->dataMgr_ = nullptr; + std::vector controlRules; + AppRunningControlRule appRunningControlRule; + controlRules.push_back(appRunningControlRule); + ErrCode res = rdb.DeleteAppRunningControlRule("", controlRules, USERID); + EXPECT_EQ(res, ERR_APPEXECFWK_NULL_PTR); + DelayedSingleton::GetInstance()->dataMgr_ = std::make_shared(); +} } // OHOS \ No newline at end of file -- Gitee