From f4435b6aaa2f9d9e1a830bb9843c7a0da34c4f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 03:58:46 +0000 Subject: [PATCH 01/15] update interfaces/innerkits/include/continuous_task_param.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/include/continuous_task_param.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/include/continuous_task_param.h b/interfaces/innerkits/include/continuous_task_param.h index b0017bbe..8fa85a57 100644 --- a/interfaces/innerkits/include/continuous_task_param.h +++ b/interfaces/innerkits/include/continuous_task_param.h @@ -47,9 +47,14 @@ struct ContinuousTaskParam : public Parcelable { ContinuousTaskParam(bool isNewApi, uint32_t bgModeId, const std::shared_ptr wantAgent, const std::string &abilityName, const sptr abilityToken, const std::string &appName, bool isBatchApi = false, - const std::vector &bgModeIds = {}, int32_t abilityId = -1); + const std::vector &bgModeIds = {}, int32_t abilityId = -1) + : isNewApi_(isNewApi), bgModeId_(bgModeId), wantAgent_(wantAgent), abilityName_(abilityName), + abilityToken_(abilityToken), appName_(appName), isBatchApi_(isBatchApi), bgModeIds_(bgModeIds), + abilityId_(abilityId) {} bool ReadFromParcel(Parcel &parcel); + bool ReadFromParcelNewApi(Parcel &parcel); bool Marshalling(Parcel &parcel) const override; + bool MarshallingNewApi(Parcel &parcel) const; static ContinuousTaskParam *Unmarshalling(Parcel &parcel); }; -- Gitee From e36c069faa35e181ff78c183c6393303271b6086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 03:59:55 +0000 Subject: [PATCH 02/15] update interfaces/innerkits/src/continuous_task_param.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../innerkits/src/continuous_task_param.cpp | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/interfaces/innerkits/src/continuous_task_param.cpp b/interfaces/innerkits/src/continuous_task_param.cpp index 2b43494b..66b6d8b5 100644 --- a/interfaces/innerkits/src/continuous_task_param.cpp +++ b/interfaces/innerkits/src/continuous_task_param.cpp @@ -21,28 +21,6 @@ namespace OHOS { namespace BackgroundTaskMgr { -ContinuousTaskParam::ContinuousTaskParam(bool isNewApi, uint32_t bgModeId, - const std::shared_ptr wantAgent, const std::string &abilityName, - const sptr abilityToken, const std::string &appName, bool isBatchApi, - const std::vector &bgModeIds, int32_t abilityId) - : isNewApi_(isNewApi), bgModeId_(bgModeId), wantAgent_(wantAgent), abilityName_(abilityName), - abilityToken_(abilityToken), appName_(appName), isBatchApi_(isBatchApi), bgModeIds_(bgModeIds), - abilityId_(abilityId) { - if (isBatchApi_ && bgModeIds_.size() > 0) { - auto findNonDataTransfer = [](const auto &target) { - return target != BackgroundMode::DATA_TRANSFER; - }; - auto iter = std::find_if(bgModeIds_.begin(), bgModeIds_.end(), findNonDataTransfer); - if (iter != bgModeIds_.end()) { - bgModeId_ = *iter; - } else { - bgModeId_ = bgModeIds_[0]; - } - } else { - bgModeIds_.push_back(bgModeId); - } -} - bool ContinuousTaskParam::ReadFromParcel(Parcel &parcel) { if (!parcel.ReadBool(isNewApi_)) { @@ -93,16 +71,28 @@ bool ContinuousTaskParam::ReadFromParcel(Parcel &parcel) BGTASK_LOGE("Failed to read the abilityId"); return false; } + if (!ReadFromParcelNewApi(parcel)) { + return false; + } + return true; +} + +bool ContinuousTaskParam::ReadFromParcelNewApi(Parcel &parcel) +{ if (!parcel.ReadUInt32Vector(&bgSubModeIds_)) { + BGTASK_LOGE("Failed to read the bgSubModeIds"); return false; } if (!parcel.ReadBool(isCombinedTaskNotification_)) { + BGTASK_LOGE("Failed to read the isCombinedTaskNotification"); return false; } if (!parcel.ReadInt32(combinedNotificationTaskId_)) { + BGTASK_LOGE("Failed to read the combinedNotificationTaskId"); return false; } if (!parcel.ReadBool(isByRequestObject_)) { + BGTASK_LOGE("Failed to read the isByRequestObject"); return false; } return true; @@ -214,21 +204,34 @@ bool ContinuousTaskParam::Marshalling(Parcel &parcel) const BGTASK_LOGE("Failed to write the abilityId"); return false; } + if (!MarshallingNewApi(parcel)) { + return false; + } + return true; +} + +bool ContinuousTaskParam::MarshallingNewApi(Parcel &parcel) const +{ if (!parcel.WriteUInt32Vector(bgSubModeIds_)) { + BGTASK_LOGE("Failed to write the bgSubModeIds"); return false; } if (!parcel.WriteBool(isCombinedTaskNotification_)) { + BGTASK_LOGE("Failed to write the isCombinedTaskNotification"); return false; } if (!parcel.WriteInt32(combinedNotificationTaskId_)) { + BGTASK_LOGE("Failed to write the combinedNotificationTaskId"); return false; } if (!parcel.WriteBool(isByRequestObject_)) { + BGTASK_LOGE("Failed to write the isByRequestObject"); return false; } return true; } + bool ContinuousTaskParamForInner::Marshalling(Parcel &parcel) const { if (!parcel.WriteBool(isStart_)) { -- Gitee From 3e0f14270021566b549b565628607b9baf85cacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:07:41 +0000 Subject: [PATCH 03/15] update interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/bg_continuous_task_napi_module.cpp | 151 +++++++++++------- 1 file changed, 91 insertions(+), 60 deletions(-) diff --git a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp index 1c90be19..6107e11b 100644 --- a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp +++ b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp @@ -629,27 +629,8 @@ bool StartBackgroundRunningCheckParamBeforeSubmit(napi_env env, napi_value *argv return true; } -bool StartBackgroundRunningCheckRequest(napi_env env, napi_value *argv, bool isThrow, - AsyncCallbackInfo *asyncCallbackInfo) +bool StartBackgroundRunningCheckModes(napi_env env, bool isThrow, AsyncCallbackInfo *asyncCallbackInfo) { - if (GetAbilityContext(env, argv[0], asyncCallbackInfo->abilityContext) == nullptr) { - BGTASK_LOGE("Get ability context failed"); - Common::HandleParamErr(env, ERR_CONTEXT_NULL_OR_TYPE_ERR, isThrow); - asyncCallbackInfo->errCode = ERR_CONTEXT_NULL_OR_TYPE_ERR; - return false; - } - const std::shared_ptr info = asyncCallbackInfo->abilityContext->GetAbilityInfo(); - if (info == nullptr) { - BGTASK_LOGE("abilityInfo is null"); - Common::HandleParamErr(env, ERR_ABILITY_INFO_EMPTY, isThrow); - asyncCallbackInfo->errCode = ERR_ABILITY_INFO_EMPTY; - return false; - } - if (!Common::GetContinuousTaskRequest(env, argv[1], asyncCallbackInfo->request)) { - Common::HandleErrCode(env, ERR_BGTASK_CONTINUOUS_REQUEST_NULL_OR_TYPE, true); - asyncCallbackInfo->errCode = ERR_BGTASK_CONTINUOUS_REQUEST_NULL_OR_TYPE; - return false; - } std::vector continuousTaskModes = asyncCallbackInfo->request->GetContinuousTaskModes(); std::vector continuousTaskSubmodes = asyncCallbackInfo->request->GetContinuousTaskSubmodes(); if (continuousTaskModes.size() == 0 || continuousTaskSubmodes.size() == 0) { @@ -687,6 +668,55 @@ bool StartBackgroundRunningCheckRequest(napi_env env, napi_value *argv, bool isT return true; } +bool StartBackgroundRunningCheckRequest(napi_env env, napi_value *argv, bool isThrow, + AsyncCallbackInfo *asyncCallbackInfo) +{ + if (GetAbilityContext(env, argv[0], asyncCallbackInfo->abilityContext) == nullptr) { + BGTASK_LOGE("Get ability context failed"); + Common::HandleParamErr(env, ERR_CONTEXT_NULL_OR_TYPE_ERR, isThrow); + asyncCallbackInfo->errCode = ERR_CONTEXT_NULL_OR_TYPE_ERR; + return false; + } + const std::shared_ptr info = asyncCallbackInfo->abilityContext->GetAbilityInfo(); + if (info == nullptr) { + BGTASK_LOGE("abilityInfo is null"); + Common::HandleParamErr(env, ERR_ABILITY_INFO_EMPTY, isThrow); + asyncCallbackInfo->errCode = ERR_ABILITY_INFO_EMPTY; + return false; + } + if (!Common::GetContinuousTaskRequest(env, argv[1], asyncCallbackInfo->request)) { + Common::HandleErrCode(env, ERR_BGTASK_CONTINUOUS_REQUEST_NULL_OR_TYPE, true); + asyncCallbackInfo->errCode = ERR_BGTASK_CONTINUOUS_REQUEST_NULL_OR_TYPE; + return false; + } + if (!StartBackgroundRunningCheckModes(env, isThrow, asyncCallbackInfo)) { + BGTASK_LOGE("check continuous modes fail"); + return false; + } + return true; +} + +bool UpdateBackgroundRunningCheckParam(napi_env env, napi_value *argv, AsyncCallbackInfo *asyncCallbackInfo, + bool isThrow) +{ + // argv[0] : context : AbilityContext + if (GetAbilityContext(env, argv[0], asyncCallbackInfo->abilityContext) == nullptr) { + BGTASK_LOGE("Get ability context failed"); + Common::HandleParamErr(env, ERR_CONTEXT_NULL_OR_TYPE_ERR, isThrow); + asyncCallbackInfo->errCode = ERR_CONTEXT_NULL_OR_TYPE_ERR; + return false; + } + + // argv[1] : bgMode : BackgroundMode + if (GetBackgroundMode(env, argv[1], asyncCallbackInfo) == nullptr) { + BGTASK_LOGE("input bgmode param not number"); + Common::HandleParamErr(env, ERR_BGMODE_NULL_OR_TYPE_ERR, isThrow); + asyncCallbackInfo->errCode = ERR_BGMODE_NULL_OR_TYPE_ERR; + return false; + } + return true; +} + napi_value UpdateBackgroundRunning(napi_env env, napi_callback_info info, bool isThrow) { HitraceScoped traceScoped(HITRACE_TAG_OHOS, @@ -712,22 +742,15 @@ napi_value UpdateBackgroundRunning(napi_env env, napi_callback_info info, bool i napi_is_array(env, value, &isArray); napi_value ret {nullptr}; if (isArray) { - // argv[0] : context : AbilityContext - if (GetAbilityContext(env, argv[0], asyncCallbackInfo->abilityContext) == nullptr) { - BGTASK_LOGE("Get ability context failed"); - Common::HandleParamErr(env, ERR_CONTEXT_NULL_OR_TYPE_ERR, isThrow); - asyncCallbackInfo->errCode = ERR_CONTEXT_NULL_OR_TYPE_ERR; - return WrapVoidToJS(env); - } - - // argv[1] : bgMode : BackgroundMode - if (GetBackgroundMode(env, argv[1], asyncCallbackInfo) == nullptr) { - BGTASK_LOGE("input bgmode param not number"); - Common::HandleParamErr(env, ERR_BGMODE_NULL_OR_TYPE_ERR, isThrow); - asyncCallbackInfo->errCode = ERR_BGMODE_NULL_OR_TYPE_ERR; + if (!UpdateBackgroundRunningCheckParam(env, argv, asyncCallbackInfo, isThrow)) { + if (asyncCallbackInfo != nullptr) { + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + } return WrapVoidToJS(env); + } else { + ret = UpdateBackgroundRunningPromise(env, asyncCallbackInfo, isThrow); } - ret = UpdateBackgroundRunningPromise(env, asyncCallbackInfo, isThrow); } else { BGTASK_LOGE("UpdateBackgroundRunningByRequestPromise"); } @@ -790,6 +813,16 @@ napi_value StartBackgroundRunningByRequestPromise(napi_env env, AsyncCallbackInf return promise; } +napi_value StartBackgroundRunningSubmit(napi_env env, napi_value *argv, AsyncCallbackInfo *asyncCallbackInfo, + bool isThrow) +{ + if (!StartBackgroundRunningCheckRequest(env, argv, isThrow, asyncCallbackInfo)) { + return nullptr; + } else { + return StartBackgroundRunningByRequestPromise(env, asyncCallbackInfo, isThrow); + } +} + napi_value StartBackgroundRunning(napi_env env, napi_callback_info info, bool isThrow) { HitraceScoped traceScoped(HITRACE_TAG_OHOS, @@ -812,16 +845,7 @@ napi_value StartBackgroundRunning(napi_env env, napi_callback_info info, bool is } napi_value ret {nullptr}; if (MAX_START_BG_RUNNING_BY_RQUEST_PARAMS == argc) { - if (!StartBackgroundRunningCheckRequest(env, argv, isThrow, asyncCallbackInfo)) { - callbackPtr.release(); - if (asyncCallbackInfo != nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return WrapVoidToJS(env); - } else { - ret = StartBackgroundRunningByRequestPromise(env, asyncCallbackInfo, isThrow); - } + ret = StartBackgroundRunningSubmit(env, argv, asyncCallbackInfo, isThrow); } else { if (!StartBackgroundRunningCheckParamBeforeSubmit(env, argv, MAX_START_BG_RUNNING_PARAMS, isThrow, asyncCallbackInfo)) { @@ -998,6 +1022,28 @@ napi_value StopBackgroundRunningByTaskIdPromise(napi_env env, AsyncCallbackInfo return promise; } +napi_value StopBackgroundRunningBySubmit(napi_env env, napi_value *argv, AsyncCallbackInfo *asyncCallbackInfo, + bool isThrow) +{ + napi_valuetype valueType = napi_undefined; + napi_value value = argv[1]; + napi_typeof(env, value, &valueType); + if (valueType == napi_number) { + int32_t taskIdValue = -1; + napi_get_value_int32(env, value, &taskIdValue); + if (taskIdValue < 0) { + Common::HandleErrCode(env, ERR_BGTASK_CONTINUOUS_TASKID_INVALID, true); + asyncCallbackInfo->errCode = ERR_BGTASK_CONTINUOUS_TASKID_INVALID; + return nullptr; + } else { + asyncCallbackInfo->removeTaskId = taskIdValue; + return StopBackgroundRunningByTaskIdPromise(env, asyncCallbackInfo, isThrow); + } + } else { + return StopBackgroundRunningAsync(env, argv, MAX_STOP_BG_RUNNING_PARAMS - 1, asyncCallbackInfo, isThrow); + } +} + napi_value StopBackgroundRunning(napi_env env, napi_callback_info info, bool isThrow) { HitraceScoped traceScoped(HITRACE_TAG_OHOS, @@ -1030,22 +1076,7 @@ napi_value StopBackgroundRunning(napi_env env, napi_callback_info info, bool isT napi_value ret {nullptr}; if (argc == MAX_STOP_BG_RUNNING_PARAMS) { - napi_valuetype valueType = napi_undefined; - napi_value value = argv[1]; - napi_typeof(env, value, &valueType); - if (valueType == napi_number) { - int32_t taskIdValue = -1; - napi_get_value_int32(env, value, &taskIdValue); - if (taskIdValue < 0) { - Common::HandleErrCode(env, ERR_BGTASK_CONTINUOUS_TASKID_INVALID, true); - asyncCallbackInfo->errCode = ERR_BGTASK_CONTINUOUS_TASKID_INVALID; - } else { - asyncCallbackInfo->removeTaskId = taskIdValue; - ret = StopBackgroundRunningByTaskIdPromise(env, asyncCallbackInfo, isThrow); - } - } else { - ret = StopBackgroundRunningAsync(env, argv, MAX_STOP_BG_RUNNING_PARAMS - 1, asyncCallbackInfo, isThrow); - } + ret = StopBackgroundRunningBySubmit(env, argv, asyncCallbackInfo, isThrow); } else { ret = StopBackgroundRunningPromise(env, asyncCallbackInfo, isThrow); } -- Gitee From e530bce8fde29b5452a0733378b3de6d6de620a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:09:05 +0000 Subject: [PATCH 04/15] 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: 胡伟 --- services/test/unittest/bg_continuous_task_mgr_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/test/unittest/bg_continuous_task_mgr_test.cpp b/services/test/unittest/bg_continuous_task_mgr_test.cpp index fcd082fe..57594dcb 100644 --- a/services/test/unittest/bg_continuous_task_mgr_test.cpp +++ b/services/test/unittest/bg_continuous_task_mgr_test.cpp @@ -243,7 +243,7 @@ HWTEST_F(BgContinuousTaskMgrTest, StartAndUpdateBackgroundRunning_001, TestSize. std::make_shared(), "ability1", nullptr, "Entry", true, {}); EXPECT_NE(taskParam1, nullptr); - EXPECT_EQ((int32_t)bgContinuousTaskMgr_->StartBackgroundRunning(taskParam1), (int32_t)ERR_BGTASK_INVALID_BGMODE); + EXPECT_EQ((int32_t)bgContinuousTaskMgr_->StartBackgroundRunning(taskParam1), (int32_t)ERR_BGTASK_CHECK_TASK_PARAM); // 2 set configure mode is CONFIGURE_ALL_MODES bgContinuousTaskMgr_->cachedBundleInfos_.clear(); -- Gitee From 78a43d70286bd0814b62fa4c3434ab5102a572c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:09:43 +0000 Subject: [PATCH 05/15] 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/continuous_task/include/bg_continuous_task_mgr.h b/services/continuous_task/include/bg_continuous_task_mgr.h index d2e51506..dd167d7d 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -185,6 +185,9 @@ private: bool IsExistCallback(int32_t uid, uint32_t type); ErrCode CheckCombinedTaskNotifacation(std::shared_ptr &record, bool &sendNotification); bool StopContinuousTaskByUserInner(const std::string &key); + ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam); + ErrCode StartBackgroundRunningInner(std::shared_ptr continuousTaskRecord, + std::string &taskInfoMapKey) private: std::atomic isSysReady_ {false}; int32_t bgTaskUid_ {-1}; -- Gitee From 303c2a347145df66f378566550cf96394901d179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:14:57 +0000 Subject: [PATCH 06/15] 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 | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 8e1ef6f7..4ec96379 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -875,7 +875,12 @@ ErrCode BgContinuousTaskMgr::StartBackgroundRunningInner(std::shared_ptruid_, continuousTaskRecord->userId_, continuousTaskRecord->bundleName_, mainAbilityLabel); } + return StartBackgroundRunningSubmit(continuousTaskRecord, taskInfoMapKey); +} +ErrCode BgContinuousTaskMgr::StartBackgroundRunningSubmit(std::shared_ptr continuousTaskRecord, + std::string &taskInfoMapKey) +{ ErrCode ret; if (continuousTaskRecord->isFromWebview_) { ret = CheckBgmodeTypeForInner(continuousTaskRecord->bgModeId_); @@ -918,22 +923,35 @@ ErrCode BgContinuousTaskMgr::CheckCombinedTaskNotifacation(std::shared_ptrisCombinedTaskNotification_) { - BGTASK_LOGE("current continuous task not support merge, uid: %{public}d", recordParam->uid_); - return ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENTTASK_COMBINED_FALSE; + BGTASK_LOGE("current task not support merge, uid: %{public}d", recordParam->uid_); + return ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENT_TASK_COMBINED_FALSE; } } else { sendNotification = true; return ERR_OK; } + ErrCode ret = DetermineMatchCombinedTaskNotifacation(recordParam); + if (ret == ERR_OK) { + sendNotification = false; + recordParam->notificationId_ = record.second->GetNotificationId(); + recordParam->notificationLabel_ = record.second->GetNotificationLabel(); + record.second->combinedNotificationTaskId_ = mergeNotificationTaskId; + } + return ret; +} + +ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam) +{ + int32_t mergeNotificationTaskId = recordParam->combinedNotificationTaskId_; ErrCode ret = ERR_BGTASK_CONTINUOUS_TASKID_INVALID; for (const auto &record : continuousTaskInfosMap_) { if (!record.second) { - BGTASK_LOGE("task is null"); + BGTASK_LOGE("current task is null"); continue; } if (record.second->uid_ != recordParam->uid_) { - BGTASK_LOGE("task uid is not equal, task uid: %{public}d, param uid: %{public}d", - record.second->uid_, recordParam->uid_); + BGTASK_LOGE("current task uid not equal, task uid: %{public}d, param uid: %{public}d", record.second->uid_, + recordParam->uid_); continue; } if (record.second->GetContinuousTaskId() != mergeNotificationTaskId) { @@ -966,14 +984,8 @@ ErrCode BgContinuousTaskMgr::CheckCombinedTaskNotifacation(std::shared_ptrnotificationId_ = record.second->GetNotificationId(); - recordParam->notificationLabel_ = record.second->GetNotificationLabel(); - record.second->combinedNotificationTaskId_ = mergeNotificationTaskId; - break; } + return ERR_OK; } return ret; } -- Gitee From 2c9ca602f48e368572233de085e06f86a7f57849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:16:11 +0000 Subject: [PATCH 07/15] update interfaces/innerkits/include/continuous_task_param.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/include/continuous_task_param.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/innerkits/include/continuous_task_param.h b/interfaces/innerkits/include/continuous_task_param.h index 8fa85a57..de4c637b 100644 --- a/interfaces/innerkits/include/continuous_task_param.h +++ b/interfaces/innerkits/include/continuous_task_param.h @@ -39,6 +39,7 @@ struct ContinuousTaskParam : public Parcelable { std::vector bgSubModeIds_ {}; bool isCombinedTaskNotification_ {false}; int32_t combinedNotificationTaskId_ {-1}; + int32_t updateTaskId_ {-1}; bool isByRequestObject_ {false}; int32_t notificationId_ {-1}; // out int32_t continuousTaskId_ {-1}; // out -- Gitee From 4f5d32962562b5843f66f749c69a2a95ec0aa391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:17:18 +0000 Subject: [PATCH 08/15] update interfaces/innerkits/src/continuous_task_param.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/src/continuous_task_param.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/interfaces/innerkits/src/continuous_task_param.cpp b/interfaces/innerkits/src/continuous_task_param.cpp index 66b6d8b5..dba126ba 100644 --- a/interfaces/innerkits/src/continuous_task_param.cpp +++ b/interfaces/innerkits/src/continuous_task_param.cpp @@ -91,6 +91,10 @@ bool ContinuousTaskParam::ReadFromParcelNewApi(Parcel &parcel) BGTASK_LOGE("Failed to read the combinedNotificationTaskId"); return false; } + if (!parcel.ReadInt32(updateTaskId_)) { + BGTASK_LOGE("Failed to read the updateTaskId"); + return false; + } if (!parcel.ReadBool(isByRequestObject_)) { BGTASK_LOGE("Failed to read the isByRequestObject"); return false; @@ -224,6 +228,10 @@ bool ContinuousTaskParam::MarshallingNewApi(Parcel &parcel) const BGTASK_LOGE("Failed to write the combinedNotificationTaskId"); return false; } + if (!parcel.WriteInt32(updateTaskId_)) { + BGTASK_LOGE("Failed to write the updateTaskId"); + return false; + } if (!parcel.WriteBool(isByRequestObject_)) { BGTASK_LOGE("Failed to write the isByRequestObject"); return false; -- Gitee From 5b46d772493aa56003622e0c541b1ce33900fb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:38:59 +0000 Subject: [PATCH 09/15] 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 dd167d7d..ef7d47a7 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -187,7 +187,7 @@ private: bool StopContinuousTaskByUserInner(const std::string &key); ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam); ErrCode StartBackgroundRunningInner(std::shared_ptr continuousTaskRecord, - std::string &taskInfoMapKey) + std::string &taskInfoMapKey); private: std::atomic isSysReady_ {false}; int32_t bgTaskUid_ {-1}; -- Gitee From e97a53491336811cf9522ca4a71669867da9f149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 04:43:52 +0000 Subject: [PATCH 10/15] update interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../kits/napi/src/bg_continuous_task_napi_module.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp index 6107e11b..39466dfe 100644 --- a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp +++ b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp @@ -742,13 +742,7 @@ napi_value UpdateBackgroundRunning(napi_env env, napi_callback_info info, bool i napi_is_array(env, value, &isArray); napi_value ret {nullptr}; if (isArray) { - if (!UpdateBackgroundRunningCheckParam(env, argv, asyncCallbackInfo, isThrow)) { - if (asyncCallbackInfo != nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - return WrapVoidToJS(env); - } else { + if (UpdateBackgroundRunningCheckParam(env, argv, asyncCallbackInfo, isThrow)) { ret = UpdateBackgroundRunningPromise(env, asyncCallbackInfo, isThrow); } } else { -- Gitee From 85d87ca54ffff9c7021e185b548a4914e958faf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 05:40:28 +0000 Subject: [PATCH 11/15] 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 ef7d47a7..9a814462 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -186,7 +186,7 @@ private: ErrCode CheckCombinedTaskNotifacation(std::shared_ptr &record, bool &sendNotification); bool StopContinuousTaskByUserInner(const std::string &key); ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam); - ErrCode StartBackgroundRunningInner(std::shared_ptr continuousTaskRecord, + ErrCode StartBackgroundRunningSubmit(std::shared_ptr continuousTaskRecord, std::string &taskInfoMapKey); private: std::atomic isSysReady_ {false}; -- Gitee From be37099f41c997a64eba3184583ec3b5459bd939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 05:49:25 +0000 Subject: [PATCH 12/15] 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 | 3 ++- 1 file changed, 2 insertions(+), 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 9a814462..f2f43aed 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -185,7 +185,8 @@ private: bool IsExistCallback(int32_t uid, uint32_t type); ErrCode CheckCombinedTaskNotifacation(std::shared_ptr &record, bool &sendNotification); bool StopContinuousTaskByUserInner(const std::string &key); - ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam); + ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam, + bool &sendNotification); ErrCode StartBackgroundRunningSubmit(std::shared_ptr continuousTaskRecord, std::string &taskInfoMapKey); private: -- Gitee From b062cfd87ad39bc49db48f3a8562b85c777c5297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 05:52:08 +0000 Subject: [PATCH 13/15] 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 | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 4ec96379..744bb186 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -930,17 +930,11 @@ ErrCode BgContinuousTaskMgr::CheckCombinedTaskNotifacation(std::shared_ptrnotificationId_ = record.second->GetNotificationId(); - recordParam->notificationLabel_ = record.second->GetNotificationLabel(); - record.second->combinedNotificationTaskId_ = mergeNotificationTaskId; - } - return ret; + return DetermineMatchCombinedTaskNotifacation(recordParam); } -ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam) +ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam, + bool &sendNotification) { int32_t mergeNotificationTaskId = recordParam->combinedNotificationTaskId_; ErrCode ret = ERR_BGTASK_CONTINUOUS_TASKID_INVALID; @@ -960,32 +954,32 @@ ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ continue; } if (!record.second->isCombinedTaskNotification_) { - ret = ERR_BGTASK_CONTINUOUS_NOT_MERGE_COMBINED_FALSE; BGTASK_LOGE("continuous task not support merge, taskId: %{public}d", mergeNotificationTaskId); - return ret; + return ERR_BGTASK_CONTINUOUS_NOT_MERGE_COMBINED_FALSE; } if (record.second->GetNotificationId() == -1) { - ret = ERR_BGTASK_CONTINUOUS_NOT_MERGE_NOTIFICATION_NOT_EXIST; BGTASK_LOGE("continuous task notification not exist, taskId: %{public}d", mergeNotificationTaskId); - return ret; + return ERR_BGTASK_CONTINUOUS_NOT_MERGE_NOTIFICATION_NOT_EXIST; } if (!CommonUtils::CheckModesSame(record.second->bgModeIds_, recordParam->bgModeIds_)) { - ret = ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH; BGTASK_LOGE("continuous task modes mismatch, taskId: %{public}d", mergeNotificationTaskId); - return ret; + return ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH; } if (!CommonUtils::CheckModesSame(record.second->bgSubModeIds_, recordParam->bgSubModeIds_)) { - ret = ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH; BGTASK_LOGE("continuous task submodes mismatch, taskId: %{public}d", mergeNotificationTaskId); - return ret; + return ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH; } if (CommonUtils::CheckExistMode(recordParam->bgModeIds_, BackgroundMode::DATA_TRANSFER)) { - ret = ERR_BGTASK_CONTINUOUS_DATA_TRANSFER_NOT_MERGE_NOTIFICATION; BGTASK_LOGE("continuous task mode: DATA_TRANSFER not support merge, taskId: %{public}d", mergeNotificationTaskId); - return ret; - } - return ERR_OK; + return ERR_BGTASK_CONTINUOUS_DATA_TRANSFER_NOT_MERGE_NOTIFICATION; + } else { + sendNotification = false; + recordParam->notificationId_ = record.second->GetNotificationId(); + recordParam->notificationLabel_ = record.second->GetNotificationLabel(); + record.second->combinedNotificationTaskId_ = mergeNotificationTaskId; + return ERR_OK; + } } return ret; } -- Gitee From 1635c9fc810547967ea923c31c75fe99d071f302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 06:24:52 +0000 Subject: [PATCH 14/15] 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 744bb186..43bceb5f 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -924,13 +924,13 @@ ErrCode BgContinuousTaskMgr::CheckCombinedTaskNotifacation(std::shared_ptrisCombinedTaskNotification_) { BGTASK_LOGE("current task not support merge, uid: %{public}d", recordParam->uid_); - return ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENT_TASK_COMBINED_FALSE; + return ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENTTASK_COMBINED_FALSE; } } else { sendNotification = true; return ERR_OK; } - return DetermineMatchCombinedTaskNotifacation(recordParam); + return DetermineMatchCombinedTaskNotifacation(recordParam, sendNotification); } ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam, -- Gitee From e6afef27eead70571e288d4b539a443d761c3029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Fri, 5 Sep 2025 06:35:44 +0000 Subject: [PATCH 15/15] 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 43bceb5f..d2e96a7f 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -979,7 +979,7 @@ ErrCode BgContinuousTaskMgr::DetermineMatchCombinedTaskNotifacation(std::shared_ recordParam->notificationLabel_ = record.second->GetNotificationLabel(); record.second->combinedNotificationTaskId_ = mergeNotificationTaskId; return ERR_OK; - } + } } return ret; } -- Gitee