From 3864eb1021d03b56d63d3b95d95ca7e837856751 Mon Sep 17 00:00:00 2001 From: h30045808 Date: Tue, 2 Sep 2025 14:20:40 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=95=BF=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E6=B7=BB=E5=8A=A0=E5=8F=AF=E9=80=89=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BB=BB=E5=8A=A1ID=20Signed-off-by:=20=E8=83=A1?= =?UTF-8?q?=E4=BC=9F=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/include/background_task_manager.h | 3 ++- frameworks/src/background_task_manager.cpp | 4 ++-- interfaces/innerkits/IBackgroundTaskMgr.idl | 2 +- interfaces/innerkits/include/background_task_mgr_helper.h | 4 +++- interfaces/innerkits/src/background_task_mgr_helper.cpp | 4 ++-- services/core/include/background_task_mgr_service.h | 2 +- services/core/src/background_task_mgr_service.cpp | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index 2c8f8f70..eb716adf 100644 --- a/frameworks/include/background_task_manager.h +++ b/frameworks/include/background_task_manager.h @@ -109,10 +109,11 @@ public: * @param abilityName Ability name of the requester ability. * @param abilityToken Ability token to mark an unique running ability instance. * @param abilityId Ability identity. + * @param continuousTaskId continuous task id. * @return ERR_OK if success, else fail. */ ErrCode RequestStopBackgroundRunning(const std::string &abilityName, const sptr &abilityToken, - int32_t abilityId); + int32_t abilityId, int32_t continuousTaskId = -1); /** * @brief Request service to get all continuous tasks. diff --git a/frameworks/src/background_task_manager.cpp b/frameworks/src/background_task_manager.cpp index a690fd16..ad67004f 100644 --- a/frameworks/src/background_task_manager.cpp +++ b/frameworks/src/background_task_manager.cpp @@ -190,7 +190,7 @@ ErrCode BackgroundTaskManager::RequestGetContinuousTasksByUidForInner(int32_t ui } ErrCode BackgroundTaskManager::RequestStopBackgroundRunning(const std::string &abilityName, - const sptr &abilityToken, int32_t abilityId) + const sptr &abilityToken, int32_t abilityId, int32_t continuousTaskId) { HitraceScoped traceScoped(HITRACE_TAG_OHOS, "BackgroundTaskManager::ContinuousTask::Mgr::RequestStopBackgroundRunning"); @@ -198,7 +198,7 @@ ErrCode BackgroundTaskManager::RequestStopBackgroundRunning(const std::string &a std::lock_guard lock(mutex_); GET_BACK_GROUND_TASK_MANAGER_PROXY_RETURN - return proxy_->StopBackgroundRunning(abilityName, abilityToken, abilityId); + return proxy_->StopBackgroundRunning(abilityName, abilityToken, abilityId, continuousTaskId); } ErrCode BackgroundTaskManager::RequestGetAllContinuousTasks(std::vector> &list) diff --git a/interfaces/innerkits/IBackgroundTaskMgr.idl b/interfaces/innerkits/IBackgroundTaskMgr.idl index 8c1afab2..b935e422 100644 --- a/interfaces/innerkits/IBackgroundTaskMgr.idl +++ b/interfaces/innerkits/IBackgroundTaskMgr.idl @@ -32,7 +32,7 @@ interface OHOS.BackgroundTaskMgr.IBackgroundTaskMgr { void GetAllTransientTasks([out] int remainingQuota, [out] sharedptr[] list); void StartBackgroundRunning([in] ContinuousTaskParam taskParam, [out] int notificationId, [out] int continuousTaskId); void UpdateBackgroundRunning([in] ContinuousTaskParam taskParam, [out] int notificationId, [out] int continuousTaskId); - void StopBackgroundRunning([in] String abilityName, [in] IRemoteObject abilityToken, [in] int abilityId); + void StopBackgroundRunning([in] String abilityName, [in] IRemoteObject abilityToken, [in] int abilityId, [in] int continuousTaskId); void GetAllContinuousTasks([out] ContinuousTaskInfo[] list); void GetAllContinuousTasks([out] sharedptr[] list, [in] boolean includeSuspended); void SubscribeBackgroundTask([in] IBackgroundTaskSubscriber subscriber, [in] unsigned int flag); diff --git a/interfaces/innerkits/include/background_task_mgr_helper.h b/interfaces/innerkits/include/background_task_mgr_helper.h index 4f9bde23..f4e3510c 100644 --- a/interfaces/innerkits/include/background_task_mgr_helper.h +++ b/interfaces/innerkits/include/background_task_mgr_helper.h @@ -83,10 +83,12 @@ public: * @param abilityName Ability name of the requester ability * @param abilityToken Ability token to mark an unique running ability instance * @param abilityId Ability identity + * @param continuousTaskId continuous task id * @return ERR_OK if success, else fail. */ static ErrCode RequestStopBackgroundRunning(const std::string &abilityName, - const sptr &abilityToken, int32_t abilityId = -1); + const sptr &abilityToken, int32_t abilityId = -1, + int32_t continuousTaskId = -1); /** * @brief Subscribes background task event. diff --git a/interfaces/innerkits/src/background_task_mgr_helper.cpp b/interfaces/innerkits/src/background_task_mgr_helper.cpp index cec64e69..e3b52440 100644 --- a/interfaces/innerkits/src/background_task_mgr_helper.cpp +++ b/interfaces/innerkits/src/background_task_mgr_helper.cpp @@ -34,10 +34,10 @@ ErrCode BackgroundTaskMgrHelper::RequestUpdateBackgroundRunning(ContinuousTaskPa } ErrCode BackgroundTaskMgrHelper::RequestStopBackgroundRunning(const std::string &abilityName, - const sptr &abilityToken, int32_t abilityId) + const sptr &abilityToken, int32_t abilityId, int32_t continuousTaskId) { return DelayedSingleton::GetInstance()-> - RequestStopBackgroundRunning(abilityName, abilityToken, abilityId); + RequestStopBackgroundRunning(abilityName, abilityToken, abilityId, continuousTaskId); } ErrCode BackgroundTaskMgrHelper::RequestGetAllContinuousTasks(std::vector> &list) diff --git a/services/core/include/background_task_mgr_service.h b/services/core/include/background_task_mgr_service.h index cc4d0b91..324afea0 100644 --- a/services/core/include/background_task_mgr_service.h +++ b/services/core/include/background_task_mgr_service.h @@ -73,7 +73,7 @@ public: ErrCode RequestBackgroundRunningForInner(const ContinuousTaskParamForInner &taskParam) override; ErrCode RequestGetContinuousTasksByUidForInner(int32_t uid, std::vector &list) override; ErrCode StopBackgroundRunning(const std::string &abilityName, const sptr &abilityToken, - int32_t abilityId) override; + int32_t abilityId, int32_t continuousTaskId) override; ErrCode GetAllContinuousTasks(std::vector &list) override; ErrCode GetAllContinuousTasks( std::vector> &list, bool includeSuspended) override; diff --git a/services/core/src/background_task_mgr_service.cpp b/services/core/src/background_task_mgr_service.cpp index d2d698ac..9d0d0ca0 100644 --- a/services/core/src/background_task_mgr_service.cpp +++ b/services/core/src/background_task_mgr_service.cpp @@ -271,7 +271,7 @@ ErrCode BackgroundTaskMgrService::RequestGetContinuousTasksByUidForInner(int32_t } ErrCode BackgroundTaskMgrService::StopBackgroundRunning(const std::string &abilityName, - const sptr &abilityToken, int32_t abilityId) + const sptr &abilityToken, int32_t abilityId, int32_t continuousTaskId) { return BgContinuousTaskMgr::GetInstance()->StopBackgroundRunning(abilityName, abilityId); } -- Gitee From afe2b3a034340c5a5fae4d7df1675959b06a0241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Tue, 2 Sep 2025 06:39:13 +0000 Subject: [PATCH 2/4] 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: 胡伟 --- .../unittest/bgtask_framework_abnormal_unit_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp index 0d4f3dcf..e7c4fac0 100644 --- a/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp +++ b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp @@ -233,27 +233,27 @@ HWTEST_F(BgTaskFrameworkAbnormalUnitTest, BackgroundTaskMgrProxyAbnormalTest_005 BackgroundTaskMgrProxy backgroundTaskMgrProxy = BackgroundTaskMgrProxy(nullptr); MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_VALUE); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_VALUE); MessageParcelHelper::BgTaskFwkAbnormalSetWriteInterfaceTokenFlag(true); MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_DATA); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_DATA); MessageParcelHelper::BgTaskFwkAbnormalSetWriteStringFlag(true); MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_DATA); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_DATA); MessageParcelHelper::BgTaskFwkAbnormalSetWriteRemoteObjectFlag(true); MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_DATA); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_DATA); MessageParcelHelper::BgTaskFwkAbnormalSetWriteInt32WithParamFlag(true); BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(0); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_DATA); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_DATA); BgTaskMgrProxyHelper::BgTaskFwkAbnormalSetBgTaskMgrProxyInnerTransactFlag(1); MessageParcelHelper::BgTaskFwkAbnormalSetWriteReadInt32WithParamFlag(false); - EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1), ERR_INVALID_DATA); + EXPECT_EQ(backgroundTaskMgrProxy.StopBackgroundRunning("abilityName", nullptr, -1, -1), ERR_INVALID_DATA); } /** -- Gitee From 44aa4dd50d9535501c24ade11e3625afd92443e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Tue, 2 Sep 2025 06:54:21 +0000 Subject: [PATCH 3/4] 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 | 4 +++- 1 file changed, 3 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 42986d77..c0f14f41 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 @@ -144,7 +144,9 @@ HWTEST_F(BgTaskManagerAbnormalUnitTest, BackgroundTaskMgrServiceAbnormalTest_005 EXPECT_EQ(BackgroundTaskMgrService_->UpdateBackgroundRunning( taskParam, notificationId, continuousTaskId), ERR_BGTASK_SYS_NOT_READY); int32_t abilityId = -1; - EXPECT_EQ(BackgroundTaskMgrService_->StopBackgroundRunning("test", nullptr, abilityId), ERR_BGTASK_SYS_NOT_READY); + int32_t continuousTaskId = -1; + EXPECT_EQ(BackgroundTaskMgrService_->StopBackgroundRunning("test", nullptr, abilityId, continuousTaskId), + ERR_BGTASK_SYS_NOT_READY); } /** -- Gitee From 1799a2866f58d53a0b791311fc3401eee812c9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Tue, 2 Sep 2025 07:25:18 +0000 Subject: [PATCH 4/4] 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 c0f14f41..2d116880 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 @@ -144,7 +144,6 @@ HWTEST_F(BgTaskManagerAbnormalUnitTest, BackgroundTaskMgrServiceAbnormalTest_005 EXPECT_EQ(BackgroundTaskMgrService_->UpdateBackgroundRunning( taskParam, notificationId, continuousTaskId), ERR_BGTASK_SYS_NOT_READY); int32_t abilityId = -1; - int32_t continuousTaskId = -1; EXPECT_EQ(BackgroundTaskMgrService_->StopBackgroundRunning("test", nullptr, abilityId, continuousTaskId), ERR_BGTASK_SYS_NOT_READY); } -- Gitee