diff --git a/frameworks/include/background_task_manager.h b/frameworks/include/background_task_manager.h index 2c8f8f7093f7c3dfc7f704fae14aeb84beec964e..eb716adf9cc8968de02a1c5f8b10ffc2bda7dc7a 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 a690fd16a2ac54e7c53aebb0f49db7239d24b330..ad67004f024e42e24bbdde5d10358800b6f9ae07 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/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp b/frameworks/test/unittest/bgtask_framework_abnormal_unit_test.cpp index 0d4f3dcff87a8a8565d3bd2d15f23cbd941020c7..e7c4fac06290c15af7447b2219dcf2f27ac46df9 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); } /** diff --git a/interfaces/innerkits/IBackgroundTaskMgr.idl b/interfaces/innerkits/IBackgroundTaskMgr.idl index 8c1afab209f7098c28b55c14d582c7b584e989a6..b935e422fbc60f78a126d2d39c59962c3109db19 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 4f9bde23a185a9ef3cdefd4556f4291275751d05..f4e3510cfb5bc768fc13f5cd92c025251cc95255 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 cec64e69f4fa15a9a7f2db9c23b035c73f066aad..e3b52440c3bc13927108e40360488b00513d3da8 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 cc4d0b9121a4df37561209b97c4a0597b59e640d..324afea0dc4465c7b6159932d72bd0531418534f 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 d2d698ac34c3e60cbaa639f18c7068e27b962348..9d0d0ca04c2ffa293f685741a68c4133386d1b22 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); } 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 42986d77779cf62d192deaef6024247932a58261..2d116880cc4ea0c7e835922ce9806d0ad0206815 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,8 @@ 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); + EXPECT_EQ(BackgroundTaskMgrService_->StopBackgroundRunning("test", nullptr, abilityId, continuousTaskId), + ERR_BGTASK_SYS_NOT_READY); } /**