From 459d47b518e7b1075102953853dc2906a28a2ed0 Mon Sep 17 00:00:00 2001 From: lanhaoyu Date: Sat, 6 Sep 2025 17:24:23 +0800 Subject: [PATCH] fix_rule Signed-off-by: lanhaoyu --- .../src/app_control/app_control_manager.cpp | 4 +++ .../app_control/app_control_manager_rdb.cpp | 4 ++- .../bms_bundle_app_control_test.cpp | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/services/bundlemgr/src/app_control/app_control_manager.cpp b/services/bundlemgr/src/app_control/app_control_manager.cpp index 33171db939..44ba8246cf 100644 --- a/services/bundlemgr/src/app_control/app_control_manager.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager.cpp @@ -138,6 +138,10 @@ ErrCode AppControlManager::AddAppRunningControlRule(const std::string &callingNa if (ret != ERR_OK) { return ret; } + auto status = GetRunningRuleSettingStatusByUserId(userId); + if (status == RunningRuleSettingStatus::NO_SET) { + DeleteAppRunningControlRuleCacheForUserId(userId); + } if (controlRules[0].allowRunning == true) { SetRunningRuleSettingStatusByUserId(userId, RunningRuleSettingStatus::WHITE_LIST); } else { 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 79313c171e..4f7705004a 100644 --- a/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp +++ b/services/bundlemgr/src/app_control/app_control_manager_rdb.cpp @@ -64,9 +64,11 @@ AppControlManagerRdb::AppControlManagerRdb() + std::string(APP_CONTROL_RDB_TABLE_NAME) + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, CALLING_NAME TEXT NOT NULL, " + "APP_CONTROL_LIST TEXT, USER_ID INTEGER, APP_ID TEXT, CONTROL_MESSAGE TEXT, " - + "DISPOSED_STATUS TEXT, PRIORITY INTEGER, TIME_STAMP INTEGER, ALLOW_RUNNING INTEGER);"); + + "DISPOSED_STATUS TEXT, PRIORITY INTEGER, TIME_STAMP INTEGER);"); bmsRdbConfig.insertColumnSql.push_back(std::string("ALTER TABLE " + std::string(APP_CONTROL_RDB_TABLE_NAME) + " ADD APP_INDEX INTEGER DEFAULT 0;")); + bmsRdbConfig.insertColumnSql.push_back(std::string("ALTER TABLE " + std::string(APP_CONTROL_RDB_TABLE_NAME) + + " ADD ALLOW_RUNNING INTEGER;")); rdbDataManager_ = std::make_shared(bmsRdbConfig); rdbDataManager_->CreateTable(); } 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 7eb7602c09..0c1c44e6cd 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 @@ -3638,6 +3638,31 @@ HWTEST_F(BmsBundleAppControlTest, AddAppRunningControlRule_0300, Function | Smal EXPECT_EQ(res, ERR_OK); } +/** + * @tc.number: AddAppRunningControlRule_0400 + * @tc.name: Test AddAppRunningControlRule by AppControlManager + * @tc.desc: 1.AddAppRunningControlRule test + */ +HWTEST_F(BmsBundleAppControlTest, AddAppRunningControlRule_0400, Function | SmallTest | Level1) +{ + auto appControlManager = DelayedSingleton::GetInstance(); + ASSERT_NE(appControlManager, nullptr); + std::vector controlRules; + AppRunningControlRule ruleParam; + ruleParam.appId = APPID; + ruleParam.controlMessage = CONTROL_MESSAGE; + ruleParam.allowRunning = false; + for (int i = 0; i < 1024; i++) { + ruleParam.appId = APPID + "_" + std::to_string(i); + controlRules.clear(); + controlRules.emplace_back(ruleParam); + auto res = appControlManager->AddAppRunningControlRule(AppControlConstants::EDM_CALLING, controlRules, USERID); + EXPECT_EQ(res, ERR_OK); + } + auto res = appControlManager->DeleteAppRunningControlRule(AppControlConstants::EDM_CALLING, USERID); + EXPECT_EQ(res, ERR_OK); +} + /** * @tc.number: CheckControlRules_0100 * @tc.name: Test CheckControlRules by AppControlManager -- Gitee