From aa10f3ec66d8c7f6a535bcc592bae9f708eb5ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:42:03 +0000 Subject: [PATCH 01/47] update interfaces/innerkits/include/background_task_mgr_helper.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../innerkits/include/background_task_mgr_helper.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/interfaces/innerkits/include/background_task_mgr_helper.h b/interfaces/innerkits/include/background_task_mgr_helper.h index a5ff46ed..c6a735dd 100644 --- a/interfaces/innerkits/include/background_task_mgr_helper.h +++ b/interfaces/innerkits/include/background_task_mgr_helper.h @@ -200,6 +200,20 @@ public: * @return Returns ERR_OK if success, else failure. */ static ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType); + + /** + * @brief check register suspend callback + * @param param uid app uid. + * @return Returns ERR_OK if success, else failure. + */ + static ErrCode CheckRegisterSuspendCallback(int32_t uid); + + /** + * @brief Request suspend continuous audio playback task. + * @param uid app uid. + * @return Returns ERR_OK if success, else failure. + */ + static ErrCode SuspendContinuousAudioTask(int32_t uid); }; } // namespace BackgroundTaskMgr } // namespace OHOS -- Gitee From 1bd36b3b842caaf6d378f636059b84f1bc5f292d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:42:41 +0000 Subject: [PATCH 02/47] update interfaces/innerkits/src/background_task_mgr_helper.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../innerkits/src/background_task_mgr_helper.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/interfaces/innerkits/src/background_task_mgr_helper.cpp b/interfaces/innerkits/src/background_task_mgr_helper.cpp index 32009289..23db83ea 100644 --- a/interfaces/innerkits/src/background_task_mgr_helper.cpp +++ b/interfaces/innerkits/src/background_task_mgr_helper.cpp @@ -134,5 +134,15 @@ ErrCode BackgroundTaskMgrHelper::AVSessionNotifyUpdateNotification(int32_t uid, return DelayedSingleton::GetInstance()-> AVSessionNotifyUpdateNotification(uid, pid, isPublish); } + +ErrCode BackgroundTaskMgrHelper::CheckRegisterSuspendCallback(int32_t uid) +{ + return DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(uid); +} + +ErrCode BackgroundTaskMgrHelper::SuspendContinuousAudioTask(int32_t uid) +{ + return DelayedSingleton::GetInstance()->SuspendContinuousAudioTask(uid); +} } // namespace BackgroundTaskMgr } // namespace OHOS \ No newline at end of file -- Gitee From 7d8d142235982738a345e5409ffefc491a6d5d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:43:19 +0000 Subject: [PATCH 03/47] update interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_client_unit_test.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 05702633..be2e9feb 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 @@ -892,5 +892,29 @@ HWTEST_F(BgTaskClientUnitTest, AVSessionNotifyUpdateNotification_001, TestSize.L EXPECT_NE(BackgroundTaskMgrHelper::AVSessionNotifyUpdateNotification(uid, pid, true), ERR_OK); EXPECT_NE(BackgroundTaskMgrHelper::AVSessionNotifyUpdateNotification(uid, pid, false), ERR_OK); } + +/** + * @tc.name: CheckRegisterSuspendCallback_001 + * @tc.desc: test CheckRegisterSuspendCallback interface. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskClientUnitTest, CheckRegisterSuspendCallback_001, TestSize.Level1) +{ + int32_t uid = 1; + EXPECT_NE(BackgroundTaskMgrHelper::CheckRegisterSuspendCallback(uid), ERR_OK); +} + +/** + * @tc.name: SuspendContinuousAudioTask_001 + * @tc.desc: test SuspendContinuousAudioTask interface. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskClientUnitTest, SuspendContinuousAudioTask_001, TestSize.Level1) +{ + int32_t uid = 1; + EXPECT_EQ(BackgroundTaskMgrHelper::SuspendContinuousAudioTask(uid), ERR_OK); +} } } \ No newline at end of file -- Gitee From 13e68f48ab64a259147f597101e215f3845dfd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:44:09 +0000 Subject: [PATCH 04/47] update interfaces/innerkits/IBackgroundTaskMgr.idl. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/IBackgroundTaskMgr.idl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/innerkits/IBackgroundTaskMgr.idl b/interfaces/innerkits/IBackgroundTaskMgr.idl index e5c98131..a3beed37 100644 --- a/interfaces/innerkits/IBackgroundTaskMgr.idl +++ b/interfaces/innerkits/IBackgroundTaskMgr.idl @@ -52,4 +52,6 @@ interface OHOS.BackgroundTaskMgr.IBackgroundTaskMgr { void StartTransientTaskTimeForInner([in] int uid); void AVSessionNotifyUpdateNotification([in] int uid, [in] int pid, [in] boolean isPublish); void SetBgTaskConfig([in] String configData, [in] int sourceType); + void CheckRegisterSuspendCallback([in] int uid); + void SuspendContinuousAudioTask([in] int uid); } -- Gitee From 39f396c7c40361760a066fa2415888b8ae776ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:45:02 +0000 Subject: [PATCH 05/47] update frameworks/include/background_task_manager.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/include/background_task_manager.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index c4b7e122..61fbca03 100644 --- a/frameworks/include/background_task_manager.h +++ b/frameworks/include/background_task_manager.h @@ -258,6 +258,20 @@ public: */ ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType); + /** + * @brief check register suspend callback + * @param param uid app uid. + * @return Returns ERR_OK if success, else failure. + */ + ErrCode CheckRegisterSuspendCallback(int32_t uid); + + /** + * @brief Request suspend continuous audio playback task. + * @param uid app uid. + * @return Returns ERR_OK if success, else failure. + */ + ErrCode SuspendContinuousAudioTask(int32_t uid); + private: bool GetBackgroundTaskManagerProxy(); -- Gitee From 98f55a31c896be80daf079d861fe2b7c6fad121b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:45:33 +0000 Subject: [PATCH 06/47] update frameworks/src/background_task_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/src/background_task_manager.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/frameworks/src/background_task_manager.cpp b/frameworks/src/background_task_manager.cpp index c3ea7c8d..7395123a 100644 --- a/frameworks/src/background_task_manager.cpp +++ b/frameworks/src/background_task_manager.cpp @@ -464,6 +464,22 @@ ErrCode BackgroundTaskManager::SetBgTaskConfig(const std::string &configData, in return proxy_->SetBgTaskConfig(configData, sourceType); } +ErrCode BackgroundTaskManager::CheckRegisterSuspendCallback(int32_t uid) +{ + std::lock_guard lock(mutex_); + GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN + + return proxy_->CheckRegisterSuspendCallback(uid); +} + +ErrCode BackgroundTaskManager::SuspendContinuousAudioTask(int32_t uid) +{ + std::lock_guard lock(mutex_); + GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN + + return proxy_->SuspendContinuousAudioTask(uid); +} + BackgroundTaskManager::BgTaskMgrDeathRecipient::BgTaskMgrDeathRecipient(BackgroundTaskManager &backgroundTaskManager) : backgroundTaskManager_(backgroundTaskManager) {} -- Gitee From 12a4d5baadcbfc2965babd03ccf0472f17876d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:46:27 +0000 Subject: [PATCH 07/47] update frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_framework_abnormal_unit_test.cpp | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp index 2a46ab3d..14bff8ff 100644 --- a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp +++ b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -649,5 +649,41 @@ HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_019 MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); EXPECT_EQ(backgroundTaskMgrProxy.ActiveContinuousTask(1, 1, ""), ERR_INVALID_DATA); } + +/** + * @tc.name: BackgroundTaskMgrProxyAbnormalTest_020 + * @tc.desc: test BackgroundTaskMgrProxy abnormal. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_020, TestSize.Level2) +{ + BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); + + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); + EXPECT_EQ(backgroundTaskMgrProxy.CheckRegisterSuspendCallback(1), ERR_INVALID_VALUE); + + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); + EXPECT_EQ(backgroundTaskMgrProxy.CheckRegisterSuspendCallback(1), ERR_INVALID_DATA); +} + +/** + * @tc.name: BackgroundTaskMgrProxyAbnormalTest_021 + * @tc.desc: test BackgroundTaskMgrProxy abnormal. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_021, TestSize.Level2) +{ + BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); + + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); + EXPECT_EQ(backgroundTaskMgrProxy.SuspendContinuousAudioTask(1), ERR_INVALID_VALUE); + + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); + MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); + EXPECT_EQ(backgroundTaskMgrProxy.SuspendContinuousAudioTask(1), ERR_INVALID_DATA); +} } } -- Gitee From cd144825176bb325ba61748ace0e55002af2e1ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:46:46 +0000 Subject: [PATCH 08/47] update frameworks/test/unittest/bgtask_framework_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../unittest/bgtask_framework_unit_test.cpp | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/frameworks/test/unittest/bgtask_framework_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_unit_test.cpp index 9a771a93..c23f5cf9 100644 --- a/frameworks/test/unittest/bgtask_framework_unit_test.cpp +++ b/frameworks/test/unittest/bgtask_framework_unit_test.cpp @@ -914,5 +914,41 @@ HWTEST_F(BgTaskFrameworkUnitTest, AVSessionNotifyUpdateNotification_001, TestSiz EXPECT_EQ(DelayedSingleton::GetInstance()-> AVSessionNotifyUpdateNotification(uid, pid, true), ERR_BGTASK_CHECK_TASK_PARAM); } + +/** + * @tc.name: CheckRegisterSuspendCallback_001 + * @tc.desc: test CheckRegisterSuspendCallback. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskFrameworkUnitTest, CheckRegisterSuspendCallback_001, TestSize.Level1) +{ + DelayedSingleton::GetInstance()->proxy_ = nullptr; + SystemAbilityManagerClient::GetInstance().action_ = "set_null"; + EXPECT_EQ(DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(1), + ERR_BGTASK_SERVICE_NOT_CONNECTED); + + SystemAbilityManagerClient::GetInstance().action_ = ""; + EXPECT_EQ(DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(1), + ERR_BGTASK_PERMISSION_DENIED); +} + +/** + * @tc.name: SuspendContinuousAudioTask_001 + * @tc.desc: test SuspendContinuousAudioTask. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgTaskFrameworkUnitTest, SuspendContinuousAudioTask_001, TestSize.Level1) +{ + DelayedSingleton::GetInstance()->proxy_ = nullptr; + SystemAbilityManagerClient::GetInstance().action_ = "set_null"; + EXPECT_EQ(DelayedSingleton::GetInstance()->SuspendContinuousAudioTask(1), + ERR_BGTASK_SERVICE_NOT_CONNECTED); + + SystemAbilityManagerClient::GetInstance().action_ = ""; + EXPECT_EQ(DelayedSingleton::GetInstance()->SuspendContinuousAudioTask(1), + ERR_BGTASK_PERMISSION_DENIED); +} } } -- Gitee From a4a0a12ce221193da29a12a5640c7fd0565ba7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:48:30 +0000 Subject: [PATCH 09/47] update services/continuous_task/include/bg_continuous_task_mgr.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/bg_continuous_task_mgr.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/continuous_task/include/bg_continuous_task_mgr.h b/services/continuous_task/include/bg_continuous_task_mgr.h index 43633275..5331509c 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -89,6 +89,7 @@ public: ErrCode ShellDump(const std::vector &dumpOption, std::vector &dumpInfo); ErrCode GetContinuousTaskApps(std::vector> &list, int32_t uid = -1); ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false); + ErrCode CheckRegisterSuspendCallback(int32_t uid); bool StopContinuousTaskByUser(const std::string &mapKey); void OnAccountsStateChanged(int32_t id); void OnBundleInfoChanged(const std::string &action, const std::string &bundleName, int32_t uid); @@ -102,6 +103,7 @@ public: int32_t GetBgTaskUid(); void StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key); void SuspendContinuousTask(int32_t uid, int32_t pid, int32_t reason, const std::string &key); + void SuspendContinuousAudioTask(int32_t uid); void ActiveContinuousTask(int32_t uid, int32_t pid, const std::string &key); void OnConfigurationChanged(const AppExecFwk::Configuration &configuration); void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId); @@ -123,6 +125,7 @@ private: ErrCode SendContinuousTaskNotification(std::shared_ptr &ContinuousTaskRecordPtr); ErrCode GetContinuousTaskAppsInner(std::vector> &list, int32_t uid); ErrCode AVSessionNotifyUpdateNotificationInner(int32_t uid, int32_t pid, bool isPublish = false); + ErrCode CheckRegisterSuspendCallbackInner(int32_t uid); void HandlePersistenceData(); void CheckPersistenceData(const std::vector &allProcesses); void DumpAllTaskInfo(std::vector &dumpInfo); @@ -143,6 +146,7 @@ private: bool SetCachedBundleInfo(int32_t uid, int32_t userId, const std::string &bundleName, const std::string &appName); void HandleStopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key); void HandleSuspendContinuousTask(int32_t uid, int32_t pid, int32_t reason, const std::string &key); + void HandleSuspendContinuousAudioTask(int32_t uid); void HandleActiveContinuousTask(int32_t uid, int32_t pid, const std::string &key); void OnRemoteSubscriberDiedInner(const wptr &object); void OnContinuousTaskChanged(const std::shared_ptr continuousTaskInfo, -- Gitee From e6b19940e9660e377997bb80c694fec123c1ee0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:48:59 +0000 Subject: [PATCH 10/47] update services/core/include/background_task_mgr_service.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/core/include/background_task_mgr_service.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/core/include/background_task_mgr_service.h b/services/core/include/background_task_mgr_service.h index e631ea1c..486db889 100644 --- a/services/core/include/background_task_mgr_service.h +++ b/services/core/include/background_task_mgr_service.h @@ -93,6 +93,8 @@ public: ErrCode ActiveContinuousTask(int32_t uid, int32_t pid, const std::string &key) override; ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false) override; ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType) override; + ErrCode CheckRegisterSuspendCallback(int32_t uid) override; + ErrCode SuspendContinuousAudioTask(int32_t uid) override; int32_t Dump(int32_t fd, const std::vector &args) override; void ForceCancelSuspendDelay(int32_t requestId); -- Gitee From 2ee2e6824e5ae4a22fe8adafec103af3babdbc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:49:40 +0000 Subject: [PATCH 11/47] update services/core/src/background_task_mgr_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../core/src/background_task_mgr_service.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/services/core/src/background_task_mgr_service.cpp b/services/core/src/background_task_mgr_service.cpp index 53504310..233757d2 100644 --- a/services/core/src/background_task_mgr_service.cpp +++ b/services/core/src/background_task_mgr_service.cpp @@ -531,6 +531,23 @@ ErrCode BackgroundTaskMgrService::SetBgTaskConfig(const std::string &configData, return DelayedSingleton::GetInstance()->SetBgTaskConfig(configData, sourceType); } +ErrCode BackgroundTaskMgrService::CheckRegisterSuspendCallback(int32_t uid) +{ + if (!CheckCallingToken() || !CheckCallingProcess()) { + return ERR_BGTASK_PERMISSION_DENIED; + } + return BgContinuousTaskMgr::GetInstance()->CheckRegisterSuspendCallback(uid); +} + +ErrCode BackgroundTaskMgrService::SuspendContinuousAudioTask(int32_t uid) +{ + if (!CheckCallingToken() || !CheckCallingProcess()) { + return ERR_BGTASK_PERMISSION_DENIED; + } + BgContinuousTaskMgr::GetInstance()->SuspendContinuousAudioTask(uid); + return ERR_OK; +} + bool BackgroundTaskMgrService::CheckAtomicService() { uint64_t tokenId = IPCSkeleton::GetCallingFullTokenID(); -- Gitee From 67b92a966e87a75a25c392ea4389dab4ebbb9cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:50:24 +0000 Subject: [PATCH 12/47] update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_manager_abnormal_unit_test.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp b/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp index b6310ebb..2667172a 100644 --- a/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp +++ b/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -77,6 +77,9 @@ HWTEST_F(BgTaskManagerAbnormalUnitTest, BackgroundTaskMgrServiceAbnormalTest_002 EXPECT_EQ(BackgroundTaskMgrService_->SubscribeBackgroundTask(nullptr, 0), ERR_BGTASK_PERMISSION_DENIED); EXPECT_EQ(BackgroundTaskMgrService_->UnsubscribeBackgroundTask(nullptr), ERR_BGTASK_PERMISSION_DENIED); + + EXPECT_EQ(BackgroundTaskMgrService_->CheckRegisterSuspendCallback(1), ERR_BGTASK_PERMISSION_DENIED); + EXPECT_EQ(BackgroundTaskMgrService_->SuspendContinuousAudioTask(1), ERR_BGTASK_PERMISSION_DENIED); } /** -- Gitee From 87f148c5c325731d39560a6012ceb86f27b80ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 07:51:07 +0000 Subject: [PATCH 13/47] update services/test/unittest/bg_continuous_task_mgr_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../unittest/bg_continuous_task_mgr_test.cpp | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/services/test/unittest/bg_continuous_task_mgr_test.cpp b/services/test/unittest/bg_continuous_task_mgr_test.cpp index 319e6ac7..f14cd57f 100644 --- a/services/test/unittest/bg_continuous_task_mgr_test.cpp +++ b/services/test/unittest/bg_continuous_task_mgr_test.cpp @@ -1398,5 +1398,93 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_054, TestSize.Level1) bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; EXPECT_EQ(bgContinuousTaskMgr_->SendContinuousTaskNotification(continuousTaskRecord), ERR_OK); } + +/** + * @tc.name: BgTaskManagerUnitTest_055 + * @tc.desc: test CheckRegisterSuspendCallback. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_055, TestSize.Level1) +{ + bgContinuousTaskMgr_->bgTaskSubscribers_.clear(); + bgContinuousTaskMgr_->isSysReady_.store(false); + bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1); + bgContinuousTaskMgr_->isSysReady_.store(true); + + TestBackgroundTaskSubscriber subscriber1 = TestBackgroundTaskSubscriber(); + auto info1 = std::make_shared(subscriber1.GetImpl(), 1, 1, 1, 0); + bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info1); + EXPECT_NE((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1), (int32_t)ERR_OK); + + TestBackgroundTaskSubscriber subscriber2 = TestBackgroundTaskSubscriber(); + auto info2 = std::make_shared(subscriber2.GetImpl(), 1, 1, 1, 2); + bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info2); + EXPECT_EQ((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1), (int32_t)ERR_OK); +} + +/** + * @tc.name: BgTaskManagerUnitTest_056 + * @tc.desc: test CheckRegisterSuspendCallbackInner. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_056, TestSize.Level1) +{ + bgContinuousTaskMgr_->bgTaskSubscribers_.clear(); + TestBackgroundTaskSubscriber subscriber1 = TestBackgroundTaskSubscriber(); + auto info1 = std::make_shared(subscriber1.GetImpl(), 1, 1, 1, 0); + bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info1); + EXPECT_NE((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallbackInner(1), (int32_t)ERR_OK); + + TestBackgroundTaskSubscriber subscriber2 = TestBackgroundTaskSubscriber(); + auto info2 = std::make_shared(subscriber2.GetImpl(), 1, 1, 1, 2); + bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info2); + EXPECT_EQ((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallbackInner(1), (int32_t)ERR_OK); +} + +/** + * @tc.name: BgTaskManagerUnitTest_057 + * @tc.desc: test SuspendContinuousAudioTask. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_057, TestSize.Level1) +{ + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + + std::shared_ptr continuousTaskRecord1 = std::make_shared(); + continuousTaskRecord1->uid_ = TEST_NUM_ONE; + continuousTaskRecord1->bgModeId_ = TEST_NUM_TWO; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord1; + bgContinuousTaskMgr_->SuspendContinuousAudioTask(1); + EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 1); +} + +/** + * @tc.name: BgTaskManagerUnitTest_058 + * @tc.desc: test HandleSuspendContinuousAudioTask. + * @tc.type: FUNC + * @tc.require: issueICT1ZV + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_058, TestSize.Level1) +{ + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + bgContinuousTaskMgr_->bgTaskSubscribers_.clear(); + + std::shared_ptr continuousTaskRecord = std::make_shared(); + continuousTaskRecord->uid_ = TEST_NUM_ONE; + continuousTaskRecord->bgModeId_ = 2; + continuousTaskRecord->bgModeIds_.push_back(continuousTaskRecord->bgModeId_); + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + + TestBackgroundTaskSubscriber subscriber1 = TestBackgroundTaskSubscriber(); + auto info1 = std::make_shared(subscriber1.GetImpl(), 1, 1, 1, 2); + bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info1); + + bgContinuousTaskMgr_->HandleSuspendContinuousAudioTask(1); + bgContinuousTaskMgr_->HandleSuspendContinuousAudioTask(1); + EXPECT_EQ(bgContinuousTaskMgr_->continuousTaskInfosMap_.size(), 0); +} } // namespace BackgroundTaskMgr } // namespace OHOS \ No newline at end of file -- Gitee From fcb7510f7971a1edf1b5676ca1abf271cfe6fc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 15 Aug 2025 08:00:47 +0000 Subject: [PATCH 14/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/bg_continuous_task_mgr.cpp | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index cb01a59c..d02682c9 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -1468,6 +1468,73 @@ ErrCode BgContinuousTaskMgr::AVSessionNotifyUpdateNotificationInner(int32_t uid, return result; } +void BgContinuousTaskMgr::SuspendContinuousAudioTask(int32_t uid) +{ + if (!isSysReady_.load()) { + return; + } + auto self = shared_from_this(); + auto task = [self, uid]() { + if (self) { + self->HandleSuspendContinuousAudioTask(uid); + } + }; + handler_->PostTask(task); +} + +void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) +{ + auto iter = continuousTaskInfosMap_.begin(); + while (iter != continuousTaskInfosMap_.end()) { + if (iter->second->GetUid() == uid && + CommonUtils::CheckExistMode(iter->second->bgModeIds_, BackgroundMode::AUDIO_PLAYBACK)) { + NotificationTools::GetInstance()->CancelNotification(iter->second->GetNotificationLabel(), + iter->second->GetNotificationId()); + if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTime() == 0) { + // 注册暂停回调,第一次检测失败,不移除任务,触发暂停回调 + iter->second->suspendState_ = true; + iter->second->suspendAudioTaskTime_ = 1; + iter->second->suspendReason_ = + static_cast(ContinuousTaskSuspendReason::SYSTEM_SUSPEND_AUDIO_PLAYBACK_NOT_RUNNING); + OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_SUSPEND); + RefreshTaskRecord(); + iter++; + } else if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTime() == 1) { + OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL); + iter = continuousTaskInfosMap_.erase(iter); + RefreshTaskRecord(); + } else { + iter++; + } + } else { + iter++; + } + } + HandleAppContinuousTaskStop(uid); +} + +ErrCode BgContinuousTaskMgr::CheckRegisterSuspendCallback(int32_t uid) +{ + if (!isSysReady_.load()) { + return ERR_INVALID_VALUE; + } + ErrCode result = ERR_OK; + handler_->PostSyncTask([this, uid, &result]() mutable { + result = this->CheckRegisterSuspendCallbackInner(uid); + }, AppExecFwk::EventQueue::Priority::HIGH); + return result; +} + +ErrCode BgContinuousTaskMgr::CheckRegisterSuspendCallbackInner(int32_t uid) +{ + for (auto iter = bgTaskSubscribers_.begin(); iter != bgTaskSubscribers_.end(); ++iter) { + if ((*iter)->isHap_ && (*iter)->uid_ == uid && (((*iter)->flag_ & CONTINUOUS_TASK_SUSPEND) > 0)) { + return ERR_OK; + } + } + return ERR_INVALID_VALUE; +} + ErrCode BgContinuousTaskMgr::ShellDump(const std::vector &dumpOption, std::vector &dumpInfo) { if (!isSysReady_.load()) { -- Gitee From ec4b9cf100ef4efb1a88589239b18088278fde24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 01:30:22 +0000 Subject: [PATCH 15/47] update services/continuous_task/include/bg_continuous_task_mgr.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/bg_continuous_task_mgr.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/continuous_task/include/bg_continuous_task_mgr.h b/services/continuous_task/include/bg_continuous_task_mgr.h index 5331509c..b9d3404e 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -108,6 +108,8 @@ public: void OnConfigurationChanged(const AppExecFwk::Configuration &configuration); void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId); void HandleRemoveTaskByMode(uint32_t mode); + void SetDumperTest(const bool dumperTest); + bool GetDumperTest() const; private: ErrCode StartBackgroundRunningInner(std::shared_ptr &continuousTaskRecordPtr); @@ -130,8 +132,6 @@ private: void CheckPersistenceData(const std::vector &allProcesses); void DumpAllTaskInfo(std::vector &dumpInfo); void DumpCancelTask(const std::vector &dumpOption, bool cleanAll); - void DumpGetTask(const std::vector &dumpOption, std::vector &dumpInfo); - void DumpInnerTask(const std::vector &dumpOption, std::vector &dumpInfo); bool RemoveContinuousTaskRecord(const std::string &mapKey); bool AddAppNameInfos(const AppExecFwk::BundleInfo &bundleInfo, CachedBundleInfo &cachedBundleInfo); bool CheckProcessUidInfo(const std::vector &allProcesses, int32_t uid); @@ -200,6 +200,7 @@ private: std::vector continuousTaskText_ {}; std::vector continuousTaskSubText_ {}; int32_t continuousTaskIdIndex_ = 0; + bool dumperTest_ {false}; DECLARE_DELAYED_SINGLETON(BgContinuousTaskMgr); }; -- Gitee From c5283a358b0fbb9ff348faeec1742b482b27f42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 01:30:55 +0000 Subject: [PATCH 16/47] add services/continuous_task/include/bg_continuous_task_dumper.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../include/bg_continuous_task_dumper.h | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 services/continuous_task/include/bg_continuous_task_dumper.h diff --git a/services/continuous_task/include/bg_continuous_task_dumper.h b/services/continuous_task/include/bg_continuous_task_dumper.h new file mode 100644 index 00000000..5cfe4625 --- /dev/null +++ b/services/continuous_task/include/bg_continuous_task_dumper.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BG_CONTINUOUS_TASK_DUMPER_H +#define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BG_CONTINUOUS_TASK_DUMPER_H + +#include +#include + +#include "singleton.h" + +namespace OHOS { +namespace BackgroundTaskMgr { +class BgContinuousTaskDumper : public DelayedSingleton { +public: + void DumpInnerTask(const std::vector &dumpOption, std::vector &dumpInfo); + void DumpGetTask(const std::vector &dumpOption, + std::vector &dumpInfo); + +private: + DECLARE_DELAYED_SINGLETON(BgContinuousTaskDumper); +}; +} // namespace BackgroundTaskMgr +} // namespace OHOS +#endif \ No newline at end of file -- Gitee From 34f6e9265d7213341ba43e93a685246b4313a0c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 01:31:30 +0000 Subject: [PATCH 17/47] add services/continuous_task/src/bg_continuous_task_dumper.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/bg_continuous_task_dumper.cpp | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 services/continuous_task/src/bg_continuous_task_dumper.cpp diff --git a/services/continuous_task/src/bg_continuous_task_dumper.cpp b/services/continuous_task/src/bg_continuous_task_dumper.cpp new file mode 100644 index 00000000..8514b29b --- /dev/null +++ b/services/continuous_task/src/bg_continuous_task_dumper.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "bg_continuous_task_dumper.h" +#include "bg_continuous_task_mgr.h" + +namespace OHOS { +namespace BackgroundTaskMgr { + static constexpr int32_t MAX_DUMP_INNER_PARAM_NUMS = 4; + static constexpr int32_t MAX_DUMP_PARAM_NUMS = 3; + +BgContinuousTaskDumper::BgContinuousTaskDumper() {} + +BgContinuousTaskDumper::~BgContinuousTaskDumper() {} + +void BgContinuousTaskDumper::DumpInnerTask(const std::vector &dumpOption, + std::vector &dumpInfo) +{ + if (dumpOption.size() != MAX_DUMP_INNER_PARAM_NUMS) { + dumpInfo.emplace_back("param invaild\n"); + return; + } + std::string modeStr = dumpOption[2].c_str(); + uint32_t mode = 0; + if (modeStr == "WORKOUT") { + mode = BackgroundMode::WORKOUT; + } + if (mode == 0) { + dumpInfo.emplace_back("param invaild\n"); + return; + } + std::string operationType = dumpOption[3].c_str(); + if (operationType != "apply" && operationType != "reset") { + dumpInfo.emplace_back("param invaild\n"); + return; + } + bool isApply = (operationType == "apply"); + sptr taskParam = sptr( + new ContinuousTaskParamForInner(1, mode, isApply)); + ErrCode ret = ERR_OK; + BgContinuousTaskMgr::GetInstance()->SetDumperTest(true); + ret = BgContinuousTaskMgr::GetInstance()->RequestBackgroundRunningForInner(taskParam); + if (ret != ERR_OK) { + dumpInfo.emplace_back("dump inner continuous task fail.\n"); + } else { + dumpInfo.emplace_back("dump inner continuous task success.\n"); + } +} + +void BgContinuousTaskDumper::DumpGetTask(const std::vector &dumpOption, + std::vector &dumpInfo) +{ + if (dumpOption.size() != MAX_DUMP_PARAM_NUMS) { + dumpInfo.emplace_back("param invaild\n"); + return; + } + int32_t uid = std::atoi(dumpOption[MAX_DUMP_PARAM_NUMS - 1].c_str()); + if (uid < 0) { + dumpInfo.emplace_back("param invaild\n"); + return; + } + std::vector> list; + ErrCode ret = BgContinuousTaskMgr::GetInstance()->RequestGetContinuousTasksByUidForInner(uid, list); + if (ret != ERR_OK) { + dumpInfo.emplace_back("param invaild\n"); + return; + } + if (list.empty()) { + dumpInfo.emplace_back("No running continuous task\n"); + return; + } + std::stringstream stream; + uint32_t index = 1; + for (const auto &info : list) { + stream.str(""); + stream.clear(); + stream << "No." << index; + stream << "\t\tabilityName: " << info->GetAbilityName() << "\n"; + stream << "\t\tisFromWebview: " << (info->IsFromWebView() ? "true" : "false") << "\n"; + stream << "\t\tuid: " << info->GetUid() << "\n"; + stream << "\t\tpid: " << info->GetPid() << "\n"; + stream << "\t\tnotificationId: " << info->GetNotificationId() << "\n"; + stream << "\t\tcontinuousTaskId: " << info->GetContinuousTaskId() << "\n"; + stream << "\t\tabilityId: " << info->GetAbilityId() << "\n"; + stream << "\t\twantAgentBundleName: " << info->GetWantAgentBundleName() << "\n"; + stream << "\t\twantAgentAbilityName: " << info->GetWantAgentAbilityName() << "\n"; + stream << "\t\tbackgroundModes: " << info->ToString(info->GetBackgroundModes()) << "\n"; + stream << "\t\tbackgroundSubModes: " << info->ToString(info->GetBackgroundSubModes()) << "\n"; + stream << "\n"; + dumpInfo.emplace_back(stream.str()); + index++; + } +} +} // namespace BackgroundTaskMgr +} // namespace OHOS \ No newline at end of file -- Gitee From 3777858fe3c1f1ab8e919b7f4cbabbf5c2737b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 01:42:39 +0000 Subject: [PATCH 18/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/bg_continuous_task_mgr.cpp | 104 +++--------------- 1 file changed, 18 insertions(+), 86 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index d02682c9..dcea9aee 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -54,6 +54,7 @@ #include "background_mode.h" #include "background_sub_mode.h" #include "continuous_task_suspend_reason.h" +#include "bg_continuous_task_dumper.h" namespace OHOS { namespace BackgroundTaskMgr { @@ -89,7 +90,6 @@ static constexpr uint32_t PC_BGMODE_TASK_KEEPING = 256; static constexpr int32_t DELAY_TIME = 2000; static constexpr int32_t RECLAIM_MEMORY_DELAY_TIME = 20 * 60 * 1000; static constexpr int32_t MAX_DUMP_PARAM_NUMS = 3; -static constexpr int32_t MAX_DUMP_INNER_PARAM_NUMS = 4; static constexpr uint32_t INVALID_BGMODE = 0; static constexpr uint32_t BG_MODE_INDEX_HEAD = 1; static constexpr uint32_t BGMODE_NUMS = 10; @@ -615,7 +615,10 @@ ErrCode BgContinuousTaskMgr::RequestBackgroundRunningForInner(const sptruid_) { + if (IsDumperTest()) { + SetDumperTest(false); + BGTASK_LOGW("RequestBackgroundRunningForInner dump test"); + } else if (callingUid != VOIP_SA_UID && callingUid != HEALTHSPORT_SA_UID && callingUid != taskParam->uid_) { BGTASK_LOGE("continuous task param uid %{public}d is invalid, real %{public}d", taskParam->uid_, callingUid); return ERR_BGTASK_CHECK_TASK_PARAM; } @@ -1559,9 +1562,9 @@ ErrCode BgContinuousTaskMgr::ShellDumpInner(const std::vector &dump } else if (dumpOption[1] == DUMP_PARAM_CANCEL) { DumpCancelTask(dumpOption, false); } else if (dumpOption[1] == DUMP_PARAM_GET) { - DumpGetTask(dumpOption, dumpInfo); + BgContinuousTaskDumper::GetInstance()->DumpGetTask(dumpOption, dumpInfo); } else if (dumpOption[1] == DUMP_INNER_TASK) { - DumpInnerTask(dumpOption, dumpInfo); + BgContinuousTaskDumper::GetInstance()->DumpInnerTask(dumpOption, dumpInfo); } else { BGTASK_LOGW("invalid dump param"); } @@ -1642,88 +1645,6 @@ void BgContinuousTaskMgr::DumpCancelTask(const std::vector &dumpOpt } } -void BgContinuousTaskMgr::DumpGetTask(const std::vector &dumpOption, - std::vector &dumpInfo) -{ - if (dumpOption.size() != MAX_DUMP_PARAM_NUMS) { - dumpInfo.emplace_back("param invaild\n"); - return; - } - int32_t uid = std::atoi(dumpOption[MAX_DUMP_PARAM_NUMS - 1].c_str()); - if (uid < 0) { - dumpInfo.emplace_back("param invaild\n"); - return; - } - std::vector> list; - ErrCode ret = RequestGetContinuousTasksByUidForInner(uid, list); - if (ret != ERR_OK) { - dumpInfo.emplace_back("param invaild\n"); - return; - } - if (list.empty()) { - dumpInfo.emplace_back("No running continuous task\n"); - return; - } - std::stringstream stream; - uint32_t index = 1; - for (const auto &info : list) { - stream.str(""); - stream.clear(); - stream << "No." << index; - stream << "\t\tabilityName: " << info->GetAbilityName() << "\n"; - stream << "\t\tisFromWebview: " << (info->IsFromWebView() ? "true" : "false") << "\n"; - stream << "\t\tuid: " << info->GetUid() << "\n"; - stream << "\t\tpid: " << info->GetPid() << "\n"; - stream << "\t\tnotificationId: " << info->GetNotificationId() << "\n"; - stream << "\t\tcontinuousTaskId: " << info->GetContinuousTaskId() << "\n"; - stream << "\t\tabilityId: " << info->GetAbilityId() << "\n"; - stream << "\t\twantAgentBundleName: " << info->GetWantAgentBundleName() << "\n"; - stream << "\t\twantAgentAbilityName: " << info->GetWantAgentAbilityName() << "\n"; - stream << "\t\tbackgroundModes: " << info->ToString(info->GetBackgroundModes()) << "\n"; - stream << "\t\tbackgroundSubModes: " << info->ToString(info->GetBackgroundSubModes()) << "\n"; - stream << "\n"; - dumpInfo.emplace_back(stream.str()); - index++; - } -} - -void BgContinuousTaskMgr::DumpInnerTask(const std::vector &dumpOption, - std::vector &dumpInfo) -{ - if (dumpOption.size() != MAX_DUMP_INNER_PARAM_NUMS) { - dumpInfo.emplace_back("param invaild\n"); - return; - } - std::string modeStr = dumpOption[2].c_str(); - uint32_t mode = 0; - if (modeStr == "WORKOUT") { - mode = BackgroundMode::WORKOUT; - } - if (mode == 0) { - dumpInfo.emplace_back("param invaild\n"); - return; - } - std::string operationType = dumpOption[3].c_str(); - if (operationType != "apply" && operationType != "reset") { - dumpInfo.emplace_back("param invaild\n"); - return; - } - bool isApply = (operationType == "apply"); - sptr taskParam = sptr( - new ContinuousTaskParamForInner(1, mode, isApply)); - ErrCode ret = ERR_OK; - if (isApply) { - ret = StartBackgroundRunningForInner(taskParam); - } else { - ret = StopBackgroundRunningForInner(taskParam); - } - if (ret != ERR_OK) { - dumpInfo.emplace_back("dump inner continuous task fail.\n"); - } else { - dumpInfo.emplace_back("dump inner continuous task success.\n"); - } -} - void BgContinuousTaskMgr::SetReason(const std::string &mapKey, int32_t reason) { auto iter = continuousTaskInfosMap_.find(mapKey); @@ -2219,5 +2140,16 @@ void BgContinuousTaskMgr::OnRemoveSystemAbility(int32_t systemAbilityId, const s break; } } + +void BgContinuousTaskMgr::SetDumperTest(const bool dumperTest) +{ + dumperTest_ = dumperTest; +} + +bool BgContinuousTaskMgr::IsDumperTest() const +{ + return dumperTest_; +} +} } // namespace BackgroundTaskMgr } // namespace OHOS -- Gitee From dcd1e6149fb22fe35aaf177dac1f9d321ce4f17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 01:43:12 +0000 Subject: [PATCH 19/47] update services/continuous_task/include/bg_continuous_task_mgr.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/bg_continuous_task_mgr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/continuous_task/include/bg_continuous_task_mgr.h b/services/continuous_task/include/bg_continuous_task_mgr.h index b9d3404e..8945df88 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -109,7 +109,7 @@ public: void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId); void HandleRemoveTaskByMode(uint32_t mode); void SetDumperTest(const bool dumperTest); - bool GetDumperTest() const; + bool IsDumperTest() const; private: ErrCode StartBackgroundRunningInner(std::shared_ptr &continuousTaskRecordPtr); -- Gitee From 7d38c2abde118166fadfc4cae0eb7a7c93cb6c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 02:05:47 +0000 Subject: [PATCH 20/47] update services/continuous_task/include/continuous_task_record.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/continuous_task_record.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/continuous_task/include/continuous_task_record.h b/services/continuous_task/include/continuous_task_record.h index 70eff936..81e19eae 100644 --- a/services/continuous_task/include/continuous_task_record.h +++ b/services/continuous_task/include/continuous_task_record.h @@ -61,6 +61,7 @@ public: bool ParseFromJson(const nlohmann::json &value); std::string ToString(std::vector &bgmodes); bool IsSystem() const; + int32_t GetSuspendAudioTaskTime() const; private: std::vector ToVector(std::string &str); @@ -89,6 +90,7 @@ private: int32_t continuousTaskId_ {-1}; bool suspendState_ {false}; int32_t suspendReason_ {0}; + int32_t suspendAudioTaskTime_ {0}; friend class BgContinuousTaskMgr; friend class NotificationTools; -- Gitee From 6170399526046e5645329678f07d16d75e8d0946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 02:06:33 +0000 Subject: [PATCH 21/47] update services/continuous_task/src/continuous_task_record.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/continuous_task_record.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/continuous_task/src/continuous_task_record.cpp b/services/continuous_task/src/continuous_task_record.cpp index 23ae0d3d..744f5bfb 100644 --- a/services/continuous_task/src/continuous_task_record.cpp +++ b/services/continuous_task/src/continuous_task_record.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -147,6 +147,11 @@ bool ContinuousTaskRecord::IsSystem() const return isSystem_; } +int32_t ContinuousTaskRecord::GetSuspendAudioTaskTime() const +{ + return suspendAudioTaskTime_; +} + std::string ContinuousTaskRecord::ParseToJsonStr() { nlohmann::json root; -- Gitee From c01be60a605fdef71e25fcbbf75fb4916dc403e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 02:06:53 +0000 Subject: [PATCH 22/47] update services/continuous_task/include/continuous_task_record.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/continuous_task_record.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/continuous_task/include/continuous_task_record.h b/services/continuous_task/include/continuous_task_record.h index 81e19eae..7466fe79 100644 --- a/services/continuous_task/include/continuous_task_record.h +++ b/services/continuous_task/include/continuous_task_record.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 40cb8372680255e72104240b86d98f6122c3bd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 02:10:04 +0000 Subject: [PATCH 23/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/bg_continuous_task_mgr.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index dcea9aee..704bb43c 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -2150,6 +2150,5 @@ bool BgContinuousTaskMgr::IsDumperTest() const { return dumperTest_; } -} } // namespace BackgroundTaskMgr } // namespace OHOS -- Gitee From d9da6792ce5d2b12e5cc02f500f12e218e3b4f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 02:32:39 +0000 Subject: [PATCH 24/47] update services/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/BUILD.gn b/services/BUILD.gn index dc5a7197..ee01af71 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -34,6 +34,7 @@ BgTaskMgrServicecSrc = [ "common/src/report_hisysevent_data.cpp", "common/src/system_event_observer.cpp", "common/src/time_provider.cpp", + "continuous_task/src/bg_continuous_task_dumper.cpp", "continuous_task/src/bg_continuous_task_mgr.cpp", "continuous_task/src/config_change_observer.cpp", "continuous_task/src/continuous_task_record.cpp", -- Gitee From 17beec16f278755fe1ee294a8db8698890c6b00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:33:28 +0000 Subject: [PATCH 25/47] update frameworks/include/background_task_manager.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/include/background_task_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index 61fbca03..30fc22a8 100644 --- a/frameworks/include/background_task_manager.h +++ b/frameworks/include/background_task_manager.h @@ -260,7 +260,7 @@ public: /** * @brief check register suspend callback - * @param param uid app uid. + * @param uid app uid. * @return Returns ERR_OK if success, else failure. */ ErrCode CheckRegisterSuspendCallback(int32_t uid); -- Gitee From 43c6a8c61c2846153105dfb923c1e385ee0107a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:33:52 +0000 Subject: [PATCH 26/47] update interfaces/innerkits/include/background_task_mgr_helper.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/include/background_task_mgr_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/include/background_task_mgr_helper.h b/interfaces/innerkits/include/background_task_mgr_helper.h index c6a735dd..571742ea 100644 --- a/interfaces/innerkits/include/background_task_mgr_helper.h +++ b/interfaces/innerkits/include/background_task_mgr_helper.h @@ -203,7 +203,7 @@ public: /** * @brief check register suspend callback - * @param param uid app uid. + * @param uid app uid. * @return Returns ERR_OK if success, else failure. */ static ErrCode CheckRegisterSuspendCallback(int32_t uid); -- Gitee From 4b56cc3cee2720f1f2612615d54bfec9bb76274a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:36:11 +0000 Subject: [PATCH 27/47] update services/continuous_task/include/continuous_task_record.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/continuous_task_record.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/continuous_task/include/continuous_task_record.h b/services/continuous_task/include/continuous_task_record.h index 7466fe79..be9e1d46 100644 --- a/services/continuous_task/include/continuous_task_record.h +++ b/services/continuous_task/include/continuous_task_record.h @@ -61,7 +61,7 @@ public: bool ParseFromJson(const nlohmann::json &value); std::string ToString(std::vector &bgmodes); bool IsSystem() const; - int32_t GetSuspendAudioTaskTime() const; + int32_t GetSuspendAudioTaskTimes() const; private: std::vector ToVector(std::string &str); @@ -90,7 +90,7 @@ private: int32_t continuousTaskId_ {-1}; bool suspendState_ {false}; int32_t suspendReason_ {0}; - int32_t suspendAudioTaskTime_ {0}; + int32_t suspendAudioTaskTimes_ {0}; friend class BgContinuousTaskMgr; friend class NotificationTools; -- Gitee From 4b784b8938180036dfaf4948bb4f9b745e1b4bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:36:40 +0000 Subject: [PATCH 28/47] update services/continuous_task/src/continuous_task_record.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/continuous_task_record.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/continuous_task/src/continuous_task_record.cpp b/services/continuous_task/src/continuous_task_record.cpp index 744f5bfb..608720f9 100644 --- a/services/continuous_task/src/continuous_task_record.cpp +++ b/services/continuous_task/src/continuous_task_record.cpp @@ -147,9 +147,9 @@ bool ContinuousTaskRecord::IsSystem() const return isSystem_; } -int32_t ContinuousTaskRecord::GetSuspendAudioTaskTime() const +int32_t ContinuousTaskRecord::GetSuspendAudioTaskTimes() const { - return suspendAudioTaskTime_; + return suspendAudioTaskTimes_; } std::string ContinuousTaskRecord::ParseToJsonStr() -- Gitee From 0caa00082a19c51b8998c1139e9daac9af2d0602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:37:00 +0000 Subject: [PATCH 29/47] update services/continuous_task/include/bg_continuous_task_dumper.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/bg_continuous_task_dumper.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/continuous_task/include/bg_continuous_task_dumper.h b/services/continuous_task/include/bg_continuous_task_dumper.h index 5cfe4625..c2917eaf 100644 --- a/services/continuous_task/include/bg_continuous_task_dumper.h +++ b/services/continuous_task/include/bg_continuous_task_dumper.h @@ -17,7 +17,6 @@ #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_SERVICES_CONTINUOUS_TASK_INCLUDE_BG_CONTINUOUS_TASK_DUMPER_H #include -#include #include "singleton.h" -- Gitee From 28c0de6143bb394f2d206ea610188ae7817da7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:38:01 +0000 Subject: [PATCH 30/47] update services/continuous_task/src/bg_continuous_task_dumper.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../continuous_task/src/bg_continuous_task_dumper.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_dumper.cpp b/services/continuous_task/src/bg_continuous_task_dumper.cpp index 8514b29b..62fd81d9 100644 --- a/services/continuous_task/src/bg_continuous_task_dumper.cpp +++ b/services/continuous_task/src/bg_continuous_task_dumper.cpp @@ -18,8 +18,10 @@ namespace OHOS { namespace BackgroundTaskMgr { - static constexpr int32_t MAX_DUMP_INNER_PARAM_NUMS = 4; - static constexpr int32_t MAX_DUMP_PARAM_NUMS = 3; +namespace { +static constexpr int32_t MAX_DUMP_INNER_PARAM_NUMS = 4; +static constexpr int32_t MAX_DUMP_PARAM_NUMS = 3; +} BgContinuousTaskDumper::BgContinuousTaskDumper() {} @@ -32,7 +34,7 @@ void BgContinuousTaskDumper::DumpInnerTask(const std::vector &dumpO dumpInfo.emplace_back("param invaild\n"); return; } - std::string modeStr = dumpOption[2].c_str(); + std::string modeStr = dumpOption[MAX_DUMP_PARAM_NUMS -1].c_str(); uint32_t mode = 0; if (modeStr == "WORKOUT") { mode = BackgroundMode::WORKOUT; @@ -41,7 +43,7 @@ void BgContinuousTaskDumper::DumpInnerTask(const std::vector &dumpO dumpInfo.emplace_back("param invaild\n"); return; } - std::string operationType = dumpOption[3].c_str(); + std::string operationType = dumpOption[MAX_DUMP_PARAM_NUMS].c_str(); if (operationType != "apply" && operationType != "reset") { dumpInfo.emplace_back("param invaild\n"); return; -- Gitee From 2e2b3a819a668d283aad7cadff3fb26fff3d8a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 07:40:56 +0000 Subject: [PATCH 31/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/bg_continuous_task_mgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 704bb43c..79f394a5 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -1493,7 +1493,7 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) CommonUtils::CheckExistMode(iter->second->bgModeIds_, BackgroundMode::AUDIO_PLAYBACK)) { NotificationTools::GetInstance()->CancelNotification(iter->second->GetNotificationLabel(), iter->second->GetNotificationId()); - if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTime() == 0) { + if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTimes() == 0) { // 注册暂停回调,第一次检测失败,不移除任务,触发暂停回调 iter->second->suspendState_ = true; iter->second->suspendAudioTaskTime_ = 1; @@ -1502,7 +1502,7 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_SUSPEND); RefreshTaskRecord(); iter++; - } else if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTime() == 1) { + } else if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTimes() == 1) { OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL); iter = continuousTaskInfosMap_.erase(iter); RefreshTaskRecord(); -- Gitee From 0bdac06765cd59a81933c09cb3aa556e584cef86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:19:51 +0000 Subject: [PATCH 32/47] update frameworks/include/background_task_manager.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/include/background_task_manager.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index 30fc22a8..7f1213fc 100644 --- a/frameworks/include/background_task_manager.h +++ b/frameworks/include/background_task_manager.h @@ -258,13 +258,6 @@ public: */ ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType); - /** - * @brief check register suspend callback - * @param uid app uid. - * @return Returns ERR_OK if success, else failure. - */ - ErrCode CheckRegisterSuspendCallback(int32_t uid); - /** * @brief Request suspend continuous audio playback task. * @param uid app uid. -- Gitee From 353712620146b29eeda14aeb09a85457dc6ffbe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:20:25 +0000 Subject: [PATCH 33/47] update frameworks/src/background_task_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/src/background_task_manager.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/frameworks/src/background_task_manager.cpp b/frameworks/src/background_task_manager.cpp index 7395123a..6c7d5b2a 100644 --- a/frameworks/src/background_task_manager.cpp +++ b/frameworks/src/background_task_manager.cpp @@ -464,14 +464,6 @@ ErrCode BackgroundTaskManager::SetBgTaskConfig(const std::string &configData, in return proxy_->SetBgTaskConfig(configData, sourceType); } -ErrCode BackgroundTaskManager::CheckRegisterSuspendCallback(int32_t uid) -{ - std::lock_guard lock(mutex_); - GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN - - return proxy_->CheckRegisterSuspendCallback(uid); -} - ErrCode BackgroundTaskManager::SuspendContinuousAudioTask(int32_t uid) { std::lock_guard lock(mutex_); -- Gitee From 4f46168dd9ffd5db40a17a50b8bcd4dcff5d7fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:21:08 +0000 Subject: [PATCH 34/47] update frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_framework_abnormal_unit_test.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp index 14bff8ff..0d4f3dcf 100644 --- a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp +++ b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp @@ -660,24 +660,6 @@ HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_020 { BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); - MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.CheckRegisterSuspendCallback(1), ERR_INVALID_VALUE); - - MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); - MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.CheckRegisterSuspendCallback(1), ERR_INVALID_DATA); -} - -/** - * @tc.name: BackgroundTaskMgrProxyAbnormalTest_021 - * @tc.desc: test BackgroundTaskMgrProxy abnormal. - * @tc.type: FUNC - * @tc.require: issueICT1ZV - */ -HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_021, TestSize.Level2) -{ - BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); - MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); EXPECT_EQ(backgroundTaskMgrProxy.SuspendContinuousAudioTask(1), ERR_INVALID_VALUE); -- Gitee From d0ac6e738656f6de57c566c2f6d4f71da5511009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:21:27 +0000 Subject: [PATCH 35/47] update frameworks/test/unittest/bgtask_framework_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../unittest/bgtask_framework_unit_test.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/frameworks/test/unittest/bgtask_framework_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_unit_test.cpp index c23f5cf9..d6c71308 100644 --- a/frameworks/test/unittest/bgtask_framework_unit_test.cpp +++ b/frameworks/test/unittest/bgtask_framework_unit_test.cpp @@ -915,24 +915,6 @@ HWTEST_F(BgTaskFrameworkUnitTest, AVSessionNotifyUpdateNotification_001, TestSiz AVSessionNotifyUpdateNotification(uid, pid, true), ERR_BGTASK_CHECK_TASK_PARAM); } -/** - * @tc.name: CheckRegisterSuspendCallback_001 - * @tc.desc: test CheckRegisterSuspendCallback. - * @tc.type: FUNC - * @tc.require: issueICT1ZV - */ -HWTEST_F(BgTaskFrameworkUnitTest, CheckRegisterSuspendCallback_001, TestSize.Level1) -{ - DelayedSingleton::GetInstance()->proxy_ = nullptr; - SystemAbilityManagerClient::GetInstance().action_ = "set_null"; - EXPECT_EQ(DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(1), - ERR_BGTASK_SERVICE_NOT_CONNECTED); - - SystemAbilityManagerClient::GetInstance().action_ = ""; - EXPECT_EQ(DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(1), - ERR_BGTASK_PERMISSION_DENIED); -} - /** * @tc.name: SuspendContinuousAudioTask_001 * @tc.desc: test SuspendContinuousAudioTask. -- Gitee From a33b92ba6d78da9efcc4bf61df7d4c70445ced3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:21:49 +0000 Subject: [PATCH 36/47] update interfaces/innerkits/IBackgroundTaskMgr.idl. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/IBackgroundTaskMgr.idl | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/innerkits/IBackgroundTaskMgr.idl b/interfaces/innerkits/IBackgroundTaskMgr.idl index a3beed37..3d6b2e27 100644 --- a/interfaces/innerkits/IBackgroundTaskMgr.idl +++ b/interfaces/innerkits/IBackgroundTaskMgr.idl @@ -52,6 +52,5 @@ interface OHOS.BackgroundTaskMgr.IBackgroundTaskMgr { void StartTransientTaskTimeForInner([in] int uid); void AVSessionNotifyUpdateNotification([in] int uid, [in] int pid, [in] boolean isPublish); void SetBgTaskConfig([in] String configData, [in] int sourceType); - void CheckRegisterSuspendCallback([in] int uid); void SuspendContinuousAudioTask([in] int uid); } -- Gitee From a41d386b950d0670ec6e81358be53fe108ce8034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:22:06 +0000 Subject: [PATCH 37/47] update interfaces/innerkits/include/background_task_mgr_helper.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/include/background_task_mgr_helper.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/interfaces/innerkits/include/background_task_mgr_helper.h b/interfaces/innerkits/include/background_task_mgr_helper.h index 571742ea..9f1061fa 100644 --- a/interfaces/innerkits/include/background_task_mgr_helper.h +++ b/interfaces/innerkits/include/background_task_mgr_helper.h @@ -201,13 +201,6 @@ public: */ static ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType); - /** - * @brief check register suspend callback - * @param uid app uid. - * @return Returns ERR_OK if success, else failure. - */ - static ErrCode CheckRegisterSuspendCallback(int32_t uid); - /** * @brief Request suspend continuous audio playback task. * @param uid app uid. -- Gitee From 4d6d79250aff6a28474ff41f6c3f3ccca0479bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:22:22 +0000 Subject: [PATCH 38/47] update interfaces/innerkits/src/background_task_mgr_helper.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/src/background_task_mgr_helper.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/interfaces/innerkits/src/background_task_mgr_helper.cpp b/interfaces/innerkits/src/background_task_mgr_helper.cpp index 23db83ea..218619e6 100644 --- a/interfaces/innerkits/src/background_task_mgr_helper.cpp +++ b/interfaces/innerkits/src/background_task_mgr_helper.cpp @@ -135,11 +135,6 @@ ErrCode BackgroundTaskMgrHelper::AVSessionNotifyUpdateNotification(int32_t uid, AVSessionNotifyUpdateNotification(uid, pid, isPublish); } -ErrCode BackgroundTaskMgrHelper::CheckRegisterSuspendCallback(int32_t uid) -{ - return DelayedSingleton::GetInstance()->CheckRegisterSuspendCallback(uid); -} - ErrCode BackgroundTaskMgrHelper::SuspendContinuousAudioTask(int32_t uid) { return DelayedSingleton::GetInstance()->SuspendContinuousAudioTask(uid); -- Gitee From 6d8059509363f3753a445bba55000fd6a3406b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:22:47 +0000 Subject: [PATCH 39/47] update interfaces/test/unittest/bgtask_manager_client_test/bgtask_client_unit_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_client_unit_test.cpp | 12 ------------ 1 file changed, 12 deletions(-) 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 be2e9feb..aa48acb3 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 @@ -893,18 +893,6 @@ HWTEST_F(BgTaskClientUnitTest, AVSessionNotifyUpdateNotification_001, TestSize.L EXPECT_NE(BackgroundTaskMgrHelper::AVSessionNotifyUpdateNotification(uid, pid, false), ERR_OK); } -/** - * @tc.name: CheckRegisterSuspendCallback_001 - * @tc.desc: test CheckRegisterSuspendCallback interface. - * @tc.type: FUNC - * @tc.require: issueICT1ZV - */ -HWTEST_F(BgTaskClientUnitTest, CheckRegisterSuspendCallback_001, TestSize.Level1) -{ - int32_t uid = 1; - EXPECT_NE(BackgroundTaskMgrHelper::CheckRegisterSuspendCallback(uid), ERR_OK); -} - /** * @tc.name: SuspendContinuousAudioTask_001 * @tc.desc: test SuspendContinuousAudioTask interface. -- Gitee From 28862fcc1884c67fa5ee2fd6d607dda1a46ffd95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:23:17 +0000 Subject: [PATCH 40/47] update services/core/include/background_task_mgr_service.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/core/include/background_task_mgr_service.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/core/include/background_task_mgr_service.h b/services/core/include/background_task_mgr_service.h index 486db889..cc4d0b91 100644 --- a/services/core/include/background_task_mgr_service.h +++ b/services/core/include/background_task_mgr_service.h @@ -93,7 +93,6 @@ public: ErrCode ActiveContinuousTask(int32_t uid, int32_t pid, const std::string &key) override; ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false) override; ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType) override; - ErrCode CheckRegisterSuspendCallback(int32_t uid) override; ErrCode SuspendContinuousAudioTask(int32_t uid) override; int32_t Dump(int32_t fd, const std::vector &args) override; -- Gitee From 8cc955e1da4c4a41d54f1b51ba782d3402517fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:23:34 +0000 Subject: [PATCH 41/47] update services/core/src/background_task_mgr_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/core/src/background_task_mgr_service.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/services/core/src/background_task_mgr_service.cpp b/services/core/src/background_task_mgr_service.cpp index 233757d2..987cfafd 100644 --- a/services/core/src/background_task_mgr_service.cpp +++ b/services/core/src/background_task_mgr_service.cpp @@ -531,14 +531,6 @@ ErrCode BackgroundTaskMgrService::SetBgTaskConfig(const std::string &configData, return DelayedSingleton::GetInstance()->SetBgTaskConfig(configData, sourceType); } -ErrCode BackgroundTaskMgrService::CheckRegisterSuspendCallback(int32_t uid) -{ - if (!CheckCallingToken() || !CheckCallingProcess()) { - return ERR_BGTASK_PERMISSION_DENIED; - } - return BgContinuousTaskMgr::GetInstance()->CheckRegisterSuspendCallback(uid); -} - ErrCode BackgroundTaskMgrService::SuspendContinuousAudioTask(int32_t uid) { if (!CheckCallingToken() || !CheckCallingProcess()) { -- Gitee From 23dfe6854b6f0337a477b1093d0903ffcbe24137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:24:17 +0000 Subject: [PATCH 42/47] update services/continuous_task/include/bg_continuous_task_mgr.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/bg_continuous_task_mgr.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/continuous_task/include/bg_continuous_task_mgr.h b/services/continuous_task/include/bg_continuous_task_mgr.h index 8945df88..f6175628 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -89,7 +89,6 @@ public: ErrCode ShellDump(const std::vector &dumpOption, std::vector &dumpInfo); ErrCode GetContinuousTaskApps(std::vector> &list, int32_t uid = -1); ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false); - ErrCode CheckRegisterSuspendCallback(int32_t uid); bool StopContinuousTaskByUser(const std::string &mapKey); void OnAccountsStateChanged(int32_t id); void OnBundleInfoChanged(const std::string &action, const std::string &bundleName, int32_t uid); @@ -127,7 +126,6 @@ private: ErrCode SendContinuousTaskNotification(std::shared_ptr &ContinuousTaskRecordPtr); ErrCode GetContinuousTaskAppsInner(std::vector> &list, int32_t uid); ErrCode AVSessionNotifyUpdateNotificationInner(int32_t uid, int32_t pid, bool isPublish = false); - ErrCode CheckRegisterSuspendCallbackInner(int32_t uid); void HandlePersistenceData(); void CheckPersistenceData(const std::vector &allProcesses); void DumpAllTaskInfo(std::vector &dumpInfo); -- Gitee From 17496c091f083aaa15a21254875d8625f4a42f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:26:02 +0000 Subject: [PATCH 43/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/bg_continuous_task_mgr.cpp | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 79f394a5..df1875b1 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -1516,28 +1516,6 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) HandleAppContinuousTaskStop(uid); } -ErrCode BgContinuousTaskMgr::CheckRegisterSuspendCallback(int32_t uid) -{ - if (!isSysReady_.load()) { - return ERR_INVALID_VALUE; - } - ErrCode result = ERR_OK; - handler_->PostSyncTask([this, uid, &result]() mutable { - result = this->CheckRegisterSuspendCallbackInner(uid); - }, AppExecFwk::EventQueue::Priority::HIGH); - return result; -} - -ErrCode BgContinuousTaskMgr::CheckRegisterSuspendCallbackInner(int32_t uid) -{ - for (auto iter = bgTaskSubscribers_.begin(); iter != bgTaskSubscribers_.end(); ++iter) { - if ((*iter)->isHap_ && (*iter)->uid_ == uid && (((*iter)->flag_ & CONTINUOUS_TASK_SUSPEND) > 0)) { - return ERR_OK; - } - } - return ERR_INVALID_VALUE; -} - ErrCode BgContinuousTaskMgr::ShellDump(const std::vector &dumpOption, std::vector &dumpInfo) { if (!isSysReady_.load()) { -- Gitee From 622d425b8532f4c59fc966d83625967b975e9580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:30:10 +0000 Subject: [PATCH 44/47] update services/test/unittest/bg_continuous_task_mgr_test.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../unittest/bg_continuous_task_mgr_test.cpp | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/services/test/unittest/bg_continuous_task_mgr_test.cpp b/services/test/unittest/bg_continuous_task_mgr_test.cpp index f14cd57f..995cfa39 100644 --- a/services/test/unittest/bg_continuous_task_mgr_test.cpp +++ b/services/test/unittest/bg_continuous_task_mgr_test.cpp @@ -1399,50 +1399,6 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_054, TestSize.Level1) EXPECT_EQ(bgContinuousTaskMgr_->SendContinuousTaskNotification(continuousTaskRecord), ERR_OK); } -/** - * @tc.name: BgTaskManagerUnitTest_055 - * @tc.desc: test CheckRegisterSuspendCallback. - * @tc.type: FUNC - * @tc.require: issueICT1ZV - */ -HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_055, TestSize.Level1) -{ - bgContinuousTaskMgr_->bgTaskSubscribers_.clear(); - bgContinuousTaskMgr_->isSysReady_.store(false); - bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1); - bgContinuousTaskMgr_->isSysReady_.store(true); - - TestBackgroundTaskSubscriber subscriber1 = TestBackgroundTaskSubscriber(); - auto info1 = std::make_shared(subscriber1.GetImpl(), 1, 1, 1, 0); - bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info1); - EXPECT_NE((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1), (int32_t)ERR_OK); - - TestBackgroundTaskSubscriber subscriber2 = TestBackgroundTaskSubscriber(); - auto info2 = std::make_shared(subscriber2.GetImpl(), 1, 1, 1, 2); - bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info2); - EXPECT_EQ((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallback(1), (int32_t)ERR_OK); -} - -/** - * @tc.name: BgTaskManagerUnitTest_056 - * @tc.desc: test CheckRegisterSuspendCallbackInner. - * @tc.type: FUNC - * @tc.require: issueICT1ZV - */ -HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_056, TestSize.Level1) -{ - bgContinuousTaskMgr_->bgTaskSubscribers_.clear(); - TestBackgroundTaskSubscriber subscriber1 = TestBackgroundTaskSubscriber(); - auto info1 = std::make_shared(subscriber1.GetImpl(), 1, 1, 1, 0); - bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info1); - EXPECT_NE((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallbackInner(1), (int32_t)ERR_OK); - - TestBackgroundTaskSubscriber subscriber2 = TestBackgroundTaskSubscriber(); - auto info2 = std::make_shared(subscriber2.GetImpl(), 1, 1, 1, 2); - bgContinuousTaskMgr_->bgTaskSubscribers_.emplace_back(info2); - EXPECT_EQ((int32_t)bgContinuousTaskMgr_->CheckRegisterSuspendCallbackInner(1), (int32_t)ERR_OK); -} - /** * @tc.name: BgTaskManagerUnitTest_057 * @tc.desc: test SuspendContinuousAudioTask. -- Gitee From 13e08b7cb0f9ee2d27a517a6e9ab60169f048b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 11:30:40 +0000 Subject: [PATCH 45/47] update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../bgtask_manager_abnormal_unit_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp b/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp index 2667172a..42986d77 100644 --- a/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp +++ b/services/test/unittest/bgtask_manager_abnormal_unit_test/bgtask_manager_abnormal_unit_test.cpp @@ -78,7 +78,6 @@ HWTEST_F(BgTaskManagerAbnormalUnitTest, BackgroundTaskMgrServiceAbnormalTest_002 EXPECT_EQ(BackgroundTaskMgrService_->SubscribeBackgroundTask(nullptr, 0), ERR_BGTASK_PERMISSION_DENIED); EXPECT_EQ(BackgroundTaskMgrService_->UnsubscribeBackgroundTask(nullptr), ERR_BGTASK_PERMISSION_DENIED); - EXPECT_EQ(BackgroundTaskMgrService_->CheckRegisterSuspendCallback(1), ERR_BGTASK_PERMISSION_DENIED); EXPECT_EQ(BackgroundTaskMgrService_->SuspendContinuousAudioTask(1), ERR_BGTASK_PERMISSION_DENIED); } -- Gitee From e53688ce120f69ec13f0fd5d04d9347eb5e6e478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 12:43:01 +0000 Subject: [PATCH 46/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../continuous_task/src/bg_continuous_task_mgr.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index df1875b1..d1fe482f 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -1493,8 +1493,11 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) CommonUtils::CheckExistMode(iter->second->bgModeIds_, BackgroundMode::AUDIO_PLAYBACK)) { NotificationTools::GetInstance()->CancelNotification(iter->second->GetNotificationLabel(), iter->second->GetNotificationId()); - if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTimes() == 0) { - // 注册暂停回调,第一次检测失败,不移除任务,触发暂停回调 + if (!IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND)) { + iter++; + continue; + } + if (iter->second->GetSuspendAudioTaskTimes() == 0) { iter->second->suspendState_ = true; iter->second->suspendAudioTaskTime_ = 1; iter->second->suspendReason_ = @@ -1502,12 +1505,10 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_SUSPEND); RefreshTaskRecord(); iter++; - } else if (IsExistCallback(uid, CONTINUOUS_TASK_SUSPEND) && iter->second->GetSuspendAudioTaskTimes() == 1) { + } else { OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_CANCEL); iter = continuousTaskInfosMap_.erase(iter); RefreshTaskRecord(); - } else { - iter++; } } else { iter++; -- Gitee From d71b838bc19c7dc8a7a7727e4ff49495bf705169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Mon, 18 Aug 2025 12:55:27 +0000 Subject: [PATCH 47/47] update services/continuous_task/src/bg_continuous_task_mgr.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/bg_continuous_task_mgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index d1fe482f..4b3431f7 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -1499,7 +1499,7 @@ void BgContinuousTaskMgr::HandleSuspendContinuousAudioTask(int32_t uid) } if (iter->second->GetSuspendAudioTaskTimes() == 0) { iter->second->suspendState_ = true; - iter->second->suspendAudioTaskTime_ = 1; + iter->second->suspendAudioTaskTimes_ = 1; iter->second->suspendReason_ = static_cast(ContinuousTaskSuspendReason::SYSTEM_SUSPEND_AUDIO_PLAYBACK_NOT_RUNNING); OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_SUSPEND); -- Gitee