diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index 5c21c9ae7deba5132ece8e3ff1bfd88a4c2eb348..f05a2ff3b3cff36fc69dd3955ac322e319541f3e 100644 --- a/frameworks/include/background_task_manager.h +++ b/frameworks/include/background_task_manager.h @@ -267,6 +267,13 @@ public: */ ErrCode SuspendContinuousAudioTask(int32_t uid); + /** + * @brief Set taskKeeping exempted processes. + * @param processSet exemption process set. + * @return Returns ERR_OK if success, else failure. + */ + ErrCode SetTaskKeepingExemptedProcesses(const std::set &processSet); + private: bool GetBackgroundTaskManagerProxy(); diff --git a/frameworks/src/background_task_manager.cpp b/frameworks/src/background_task_manager.cpp index 87a5b5aa4bee86f1fc27ea29f889f0d0274fba98..8e4707671fd0db8ec0a4ae3f692bf30ecf22eec0 100644 --- a/frameworks/src/background_task_manager.cpp +++ b/frameworks/src/background_task_manager.cpp @@ -472,6 +472,13 @@ ErrCode BackgroundTaskManager::SuspendContinuousAudioTask(int32_t uid) return proxy_->SuspendContinuousAudioTask(uid); } +ErrCode BackgroundTaskManager::SetTaskKeepingExemptedProcesses(const std::set &processSet) +{ + std::lock_guard lock(mutex_); + GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN + return proxy_->SetTaskKeepingExemptedProcesses(processSet); +} + BackgroundTaskManager::BgTaskMgrDeathRecipient::BgTaskMgrDeathRecipient(BackgroundTaskManager &backgroundTaskManager) : backgroundTaskManager_(backgroundTaskManager) {} diff --git a/interfaces/innerkits/IBackgroundTaskMgr.idl b/interfaces/innerkits/IBackgroundTaskMgr.idl index c35e02aa3d68c342fe32ba41bf1845e52b0ed4be..56dba10bc6ca07c91e6b12c016e2bb9085504c36 100644 --- a/interfaces/innerkits/IBackgroundTaskMgr.idl +++ b/interfaces/innerkits/IBackgroundTaskMgr.idl @@ -54,4 +54,5 @@ interface OHOS.BackgroundTaskMgr.IBackgroundTaskMgr { void AVSessionNotifyUpdateNotification([in] int uid, [in] int pid, [in] boolean isPublish); void SetBgTaskConfig([in] String configData, [in] int sourceType); [oneway] void SuspendContinuousAudioTask([in] int uid); + void SetTaskKeepingExemptedProcesses([in] Set processSet); } diff --git a/interfaces/innerkits/include/background_task_mgr_helper.h b/interfaces/innerkits/include/background_task_mgr_helper.h index 826e5794fb99e5f1057a4db2c6a2d6d2b5eaee9c..a5624412d06681c4043c799c7d2207dde9d52c75 100644 --- a/interfaces/innerkits/include/background_task_mgr_helper.h +++ b/interfaces/innerkits/include/background_task_mgr_helper.h @@ -211,6 +211,12 @@ public: */ static ErrCode SuspendContinuousAudioTask(int32_t uid); + /** + * @brief Set taskKeeping exempted processes. + * @param processSet exemption process set. + * @return Returns ERR_OK if success, else failure. + */ + static ErrCode SetTaskKeepingExemptedProcesses(const std::set &processSet); }; } // namespace BackgroundTaskMgr } // namespace OHOS diff --git a/interfaces/innerkits/src/background_task_mgr_helper.cpp b/interfaces/innerkits/src/background_task_mgr_helper.cpp index f0559bfd7a080b79506f36aabd917b7f51397ce8..9e34c9fc29f3d13760a5984e004cbd6e888f6abb 100644 --- a/interfaces/innerkits/src/background_task_mgr_helper.cpp +++ b/interfaces/innerkits/src/background_task_mgr_helper.cpp @@ -139,5 +139,10 @@ ErrCode BackgroundTaskMgrHelper::SuspendContinuousAudioTask(int32_t uid) { return DelayedSingleton::GetInstance()->SuspendContinuousAudioTask(uid); } + +ErrCode BackgroundTaskMgrHelper::SetTaskKeepingExemptedProcesses(const std::set &processSet) +{ + return DelayedSingleton::GetInstance()->SetTaskKeepingExemptedProcesses(processSet); +} } // namespace BackgroundTaskMgr } // namespace OHOS \ No newline at end of file diff --git a/interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp b/interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp index dd8e6f7a0a1f584c8b5d92bd83cffab498b414a8..df9f1010ecd2c179411ad28961df67fafb05c4b6 100644 --- a/interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp +++ b/interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp @@ -1007,5 +1007,17 @@ HWTEST_F(BgTaskClientUnitTest, ContinuousTaskRequest_001, TestSize.Level1) info3->SetWantAgent(std::make_shared()); EXPECT_EQ(info3->GetContinuousTaskId(), 1); } + +/** + * @tc.name: SetTaskKeepingExemptedProcesses_001 + * @tc.desc: test SetTaskKeepingExemptedProcesses. + * @tc.type: FUNC + * @tc.require: issueICVQZF + */ +HWTEST_F(BgTaskClientUnitTest, SetTaskKeepingExemptedProcesses_001, TestSize.Level1) +{ + std::set processSet; + EXPECT_EQ(BackgroundTaskMgrHelper::SetTaskKeepingExemptedProcesses(processSet), ERR_OK); +} } } \ No newline at end of file diff --git a/services/common/include/bgtask_config.h b/services/common/include/bgtask_config.h index 780ee84f57c2c8935d00bec0c15fbc5449d116f9..a28a45ba329475ee7fa29f41559473067722e331 100644 --- a/services/common/include/bgtask_config.h +++ b/services/common/include/bgtask_config.h @@ -32,6 +32,7 @@ public: bool IsTaskKeepingExemptedQuatoApp(const std::string &bundleName); int32_t GetTransientTaskExemptedQuato(); bool AddExemptedQuatoData(const std::string &configData, int32_t sourceType); + void SetTaskKeepingExemptedProcesses(const std::set &processSet); private: void LoadConfigFile(); diff --git a/services/common/src/bgtask_config.cpp b/services/common/src/bgtask_config.cpp index 2f45999cc0eca8490348e5c07ba2de5ab509187e..2388712ce14503700503c8f71ecfcc26cdd78a75 100644 --- a/services/common/src/bgtask_config.cpp +++ b/services/common/src/bgtask_config.cpp @@ -201,5 +201,14 @@ int32_t BgtaskConfig::GetTransientTaskExemptedQuato() std::lock_guard lock(configMutex_); return transientTaskExemptedQuato_; } + +void BgtaskConfig::SetTaskKeepingExemptedProcesses(const std::set &processSet) +{ + std::lock_guard lock(configMutex_); + taskKeepingExemptedQuatoList_.insert(processSet.begin(), processSet.end()); + for (const auto &item : taskKeepingExemptedQuatoList_) { + BGTASK_LOGI("taskKeeping Exemption proc: %{public}s", item.c_str()); + } +} } } \ No newline at end of file diff --git a/services/core/include/background_task_mgr_service.h b/services/core/include/background_task_mgr_service.h index 324afea0dc4465c7b6159932d72bd0531418534f..c4d024c50e5fe235a2f3d5d0cde99bee55f7b8ce 100644 --- a/services/core/include/background_task_mgr_service.h +++ b/services/core/include/background_task_mgr_service.h @@ -94,6 +94,7 @@ public: ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false) override; ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType) override; ErrCode SuspendContinuousAudioTask(int32_t uid) override; + ErrCode SetTaskKeepingExemptedProcesses(const std::set &processSet) override; int32_t Dump(int32_t fd, const std::vector &args) override; void ForceCancelSuspendDelay(int32_t requestId); diff --git a/services/core/src/background_task_mgr_service.cpp b/services/core/src/background_task_mgr_service.cpp index 3f1f5b325a975ff581b249366bf6fd55a8b40f0f..98eb4e31ab4d0ddc7f84a82e92494f0c6988d7bd 100644 --- a/services/core/src/background_task_mgr_service.cpp +++ b/services/core/src/background_task_mgr_service.cpp @@ -546,6 +546,15 @@ ErrCode BackgroundTaskMgrService::SuspendContinuousAudioTask(int32_t uid) return ERR_OK; } +ErrCode BackgroundTaskMgrService::SetTaskKeepingExemptedProcesses(const std::set &processSet) +{ + if (!CheckCallingToken() || !CheckCallingProcess()) { + return ERR_BGTASK_PERMISSION_DENIED; + } + DelayedSingleton::GetInstance()->SetTaskKeepingExemptedProcesses(processSet); + return ERR_OK; +} + bool BackgroundTaskMgrService::CheckAtomicService() { uint64_t tokenId = IPCSkeleton::GetCallingFullTokenID(); diff --git a/services/test/unittest/bgtask_manager_unit_test.cpp b/services/test/unittest/bgtask_manager_unit_test.cpp index 798f152fb4720c9d6168f34f6468b79d3a6e3b03..4344526547603185196c26ce6bf9ce0b5c8cc6d0 100644 --- a/services/test/unittest/bgtask_manager_unit_test.cpp +++ b/services/test/unittest/bgtask_manager_unit_test.cpp @@ -817,5 +817,19 @@ HWTEST_F(BgTaskManagerUnitTest, BgTaskManagerUnitTest_055, TestSize.Level0) bgTransientTaskMgr_->keyInfoMap_[1] = keyInfo; EXPECT_EQ(bgTransientTaskMgr_->GetAllTransientTasks(remainingQuota, list), ERR_OK); } + +/** + * @tc.name: BgTaskManagerUnitTest_056 + * @tc.desc: test SetTaskKeepingExemptedProcesses. + * @tc.type: FUNC + * @tc.require: issueICVQZF + */ +HWTEST_F(BgTaskManagerUnitTest, BgTaskManagerUnitTest_056, TestSize.Level1) +{ + std::set processSet; + processSet.insert("com.test.app"); + DelayedSingleton::GetInstance()->SetTaskKeepingExemptedProcesses(processSet); + EXPECT_EQ(DelayedSingleton::GetInstance()->taskKeepingExemptedQuatoList_.empty(), false); +} } }