From a93d1ab5f6a6fdf2fc7a9ead0f2d50e59b95eab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:12:12 +0000 Subject: [PATCH 01/16] update frameworks/common/include/bgtaskmgr_inner_errors.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- frameworks/common/include/bgtaskmgr_inner_errors.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/common/include/bgtaskmgr_inner_errors.h b/frameworks/common/include/bgtaskmgr_inner_errors.h index e183a03e..7a6ff454 100644 --- a/frameworks/common/include/bgtaskmgr_inner_errors.h +++ b/frameworks/common/include/bgtaskmgr_inner_errors.h @@ -61,9 +61,11 @@ enum : int32_t { ERR_BGTASK_CONTINUOUS_NOT_MERGE_COMBINED_FALSE, ERR_BGTASK_CONTINUOUS_NOT_UPDATE_BECAUSE_MERGE, ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENTTASK_COMBINED_FALSE, + ERR_BGTASK_CONTINUOUS_UPDATE_FAIL_SAME_MODE_AND_MERGED, ERR_BGTASK_NOTIFICATION_VERIFY_FAILED = 980000601, ERR_BGTASK_NOTIFICATION_ERR, ERR_BGTASK_CHECK_TASK_PARAM, + ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL, ERR_BGTASK_CREATE_FILE_ERR = 980000701, ERR_BGTASK_GET_ACTUAL_FILE_ERR, ERR_BGTASK_OPEN_FILE_ERR, -- Gitee From 1af740d205f6aa3e9a7b8689cf5437a320b2fc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:13:04 +0000 Subject: [PATCH 02/16] update interfaces/kits/napi/src/common.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/kits/napi/src/common.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interfaces/kits/napi/src/common.cpp b/interfaces/kits/napi/src/common.cpp index bb7a4c64..8835d53a 100644 --- a/interfaces/kits/napi/src/common.cpp +++ b/interfaces/kits/napi/src/common.cpp @@ -115,6 +115,10 @@ const std::map SA_ERRCODE_MSG_MAP = { "Continuous Task verification failed. The continuous task not update because of merged."}, {ERR_BGTASK_CONTINUOUS_NOT_MERGE_CURRENTTASK_COMBINED_FALSE, "Continuous Task verification failed. Current continuous task do not support merged."}, + {ERR_BGTASK_CONTINUOUS_UPDATE_FAIL_SAME_MODE_AND_MERGED, + "Continuous Task verification failed. Current continuous task support merged but the modes are inconsistent."}, + {ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL, + "Notification verification failed. Current continuous task refresh notification fail."}, }; const std::map PARAM_ERRCODE_MSG_MAP = { -- Gitee From 27c7414e5613477b35f0d3f5d91cef8879789ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:14:51 +0000 Subject: [PATCH 03/16] update interfaces/innerkits/include/continuous_task_callback_info.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../include/continuous_task_callback_info.h | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/include/continuous_task_callback_info.h b/interfaces/innerkits/include/continuous_task_callback_info.h index 5f35aac8..47bcd47f 100644 --- a/interfaces/innerkits/include/continuous_task_callback_info.h +++ b/interfaces/innerkits/include/continuous_task_callback_info.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 @@ -28,10 +28,11 @@ public: ContinuousTaskCallbackInfo(); ContinuousTaskCallbackInfo(uint32_t typeId, int32_t creatorUid, pid_t creatorPid, std::string abilityName, bool isFromWebview = false, bool isBatchApi = false, - const std::vector &typeIds = {}, int32_t abilityId = -1, uint64_t tokenId = 0) + const std::vector &typeIds = {}, int32_t abilityId = -1, uint64_t tokenId = 0, + bool isByRequestObject = false) : typeId_(typeId), creatorUid_(creatorUid), creatorPid_(creatorPid), abilityName_(abilityName), isFromWebview_(isFromWebview), isBatchApi_(isBatchApi), typeIds_(typeIds), abilityId_(abilityId), - tokenId_(tokenId) {} + tokenId_(tokenId), isByRequestObject_(isByRequestObject) {} /** * @brief Get the id of type. @@ -152,6 +153,20 @@ public: */ void SetSuspendState(const bool suspendState); + /** + * @brief By new api 21 operation. + * + * @return True if success, else false. + */ + bool IsByRequestObject() const; + + /** + * @brief Set the operation new api. + * + * @param suspendState The by request operation. + */ + void SetByRequestObject(const bool isByRequestObject); + /** * @brief Marshals a purpose into a parcel. * @@ -178,6 +193,7 @@ private: int32_t cancelReason_ {-1}; bool suspendState_ {false}; int32_t suspendReason_ {-1}; + bool isByRequestObject_ {false}; }; } // namespace BackgroundTaskMgr } // namespace OHOS -- Gitee From 0cf0e19c81872a5057f46933cd362c4b9cf2487d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:15:38 +0000 Subject: [PATCH 04/16] update interfaces/innerkits/src/continuous_task_callback_info.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/continuous_task_callback_info.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/src/continuous_task_callback_info.cpp b/interfaces/innerkits/src/continuous_task_callback_info.cpp index 0c5c4f1f..d404636f 100644 --- a/interfaces/innerkits/src/continuous_task_callback_info.cpp +++ b/interfaces/innerkits/src/continuous_task_callback_info.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 @@ -107,6 +107,16 @@ bool ContinuousTaskCallbackInfo::GetSuspendState() const return suspendState_; } +bool ContinuousTaskCallbackInfo::IsByRequestObject() const +{ + return isByRequestObject_ ; +} + +void ContinuousTaskCallbackInfo::SetByRequestObject(const bool isByRequestObject) +{ + isByRequestObject_ = isByRequestObject; +} + bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const { WRITE_PARCEL_WITH_RET(parcel, Uint32, typeId_, false); @@ -123,6 +133,7 @@ bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false); WRITE_PARCEL_WITH_RET(parcel, Bool, suspendState_, false); WRITE_PARCEL_WITH_RET(parcel, Int32, suspendReason_, false); + WRITE_PARCEL_WITH_RET(parcel, Bool, isByRequestObject_, false); return true; } @@ -154,6 +165,7 @@ bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel) READ_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false); READ_PARCEL_WITH_RET(parcel, Bool, suspendState_, false); READ_PARCEL_WITH_RET(parcel, Int32, suspendReason_, false); + READ_PARCEL_WITH_RET(parcel, Bool, isByRequestObject_, false); return true; } } // namespace BackgroundTaskMgr -- Gitee From fa40f141452cfbeb7ff8084b18e4566fb77bc624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:15:59 +0000 Subject: [PATCH 05/16] update interfaces/innerkits/src/continuous_task_mode.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- interfaces/innerkits/src/continuous_task_mode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/src/continuous_task_mode.cpp b/interfaces/innerkits/src/continuous_task_mode.cpp index 04aaad3d..edc18831 100644 --- a/interfaces/innerkits/src/continuous_task_mode.cpp +++ b/interfaces/innerkits/src/continuous_task_mode.cpp @@ -71,7 +71,7 @@ std::string ContinuousTaskMode::GetContinuousTaskModeStr(uint32_t mode) { auto iter = PARAM_CONTINUOUS_TASK_MODE_STR_MAP.find(mode); if (iter != PARAM_CONTINUOUS_TASK_MODE_STR_MAP.end()) { - return iter->second.c_str(); + return iter->second; } return "default"; } -- Gitee From 03c80bb806ff19511e309996d130b38c6764db5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:17:19 +0000 Subject: [PATCH 06/16] 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 39466dfe..24c51d40 100644 --- a/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp +++ b/interfaces/kits/napi/src/bg_continuous_task_napi_module.cpp @@ -257,7 +257,7 @@ void UpdateBackgroundRunningByRequestExecuteCB(napi_env env, void *data) "", true, continuousTaskModes, asyncCallbackInfo->abilityContext->GetAbilityRecordId()); taskParam.isByRequestObject_ = true; taskParam.isCombinedTaskNotification_ = asyncCallbackInfo->request->IsCombinedTaskNotification(); - taskParam.combinedNotificationTaskId_ = asyncCallbackInfo->request->GetContinuousTaskId(); + taskParam.updateTaskId_ = asyncCallbackInfo->request->GetContinuousTaskId(); taskParam.bgSubModeIds_ = asyncCallbackInfo->request->GetContinuousTaskSubmodes(); asyncCallbackInfo->errCode = BackgroundTaskMgrHelper::RequestUpdateBackgroundRunning(taskParam); asyncCallbackInfo->bgModes = continuousTaskModes; @@ -425,7 +425,9 @@ napi_value UpdateBackgroundRunningByRequestPromise(napi_env env, AsyncCallbackIn BGTASK_LOGE("param is nullptr"); return nullptr; } - if (!CheckBackgroundMode(env, asyncCallbackInfo, isThrow)) { + if (asyncCallbackInfo->request->GetContinuousTaskId() < 0) { + Common::HandleErrCode(env, ERR_BGTASK_CONTINUOUS_TASKID_INVALID, true); + asyncCallbackInfo->errCode = ERR_BGTASK_CONTINUOUS_TASKID_INVALID; return nullptr; } napi_value resourceName; @@ -746,7 +748,9 @@ napi_value UpdateBackgroundRunning(napi_env env, napi_callback_info info, bool i ret = UpdateBackgroundRunningPromise(env, asyncCallbackInfo, isThrow); } } else { - BGTASK_LOGE("UpdateBackgroundRunningByRequestPromise"); + if (StartBackgroundRunningCheckRequest(env, argv, isThrow, asyncCallbackInfo)) { + ret = UpdateBackgroundRunningByRequestPromise(env, asyncCallbackInfo, isThrow); + } } callbackPtr.release(); if (ret == nullptr) { -- Gitee From 64eb65957422ce3feff33614f11b6945e39073bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:18:04 +0000 Subject: [PATCH 07/16] 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_manager_client_test/bgtask_client_unit_test.cpp | 2 ++ 1 file changed, 2 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 dd8e6f7a..950c0b6e 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 @@ -623,6 +623,7 @@ HWTEST_F(BgTaskClientUnitTest, ContinuousTaskCallbackInfo_001, TestSize.Level1) new ContinuousTaskCallbackInfo(1, 1, 1, "test")); info2->SetContinuousTaskId(1); info2->SetCancelReason(1); + info2->SetByRequestObject(true); Parcel parcel = Parcel(); info2->Marshalling(parcel); sptr info3 = sptr( @@ -637,6 +638,7 @@ HWTEST_F(BgTaskClientUnitTest, ContinuousTaskCallbackInfo_001, TestSize.Level1) EXPECT_EQ(info3->GetCancelReason(), 1); EXPECT_EQ(info3->GetSuspendState(), false); EXPECT_EQ(info3->GetSuspendReason(), -1); + EXPECT_EQ(info3->IsByRequestObject(), true); } /** -- Gitee From 57d8ee57606b39e4eb13837a0981135e8488c259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:18:56 +0000 Subject: [PATCH 08/16] 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 | 6 +++++- 1 file changed, 5 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 f2f43aed..921e8299 100644 --- a/services/continuous_task/include/bg_continuous_task_mgr.h +++ b/services/continuous_task/include/bg_continuous_task_mgr.h @@ -116,6 +116,10 @@ private: ErrCode StartBackgroundRunningInner(std::shared_ptr &continuousTaskRecordPtr); ErrCode UpdateBackgroundRunningInner(const std::string &taskInfoMapKey, const sptr &taskParam); + ErrCode UpdateTaskInfo(std::shared_ptr record, const sptr &taskParam); + ErrCode UpdateTaskNotification(std::shared_ptr record, + const sptr &taskParam); + ErrCode UpdateBackgroundRunningByTaskIdInner(int32_t uid, const sptr &taskParam); ErrCode StartBackgroundRunningForInner(const sptr &taskParam); ErrCode StopBackgroundRunningInner(int32_t uid, const std::string &abilityName, int32_t abilityId, int32_t continuousTaskId = -1); @@ -183,7 +187,7 @@ private: bool CanNotifyHap(const std::shared_ptr subscriberInfo, const std::shared_ptr &callbackInfo); bool IsExistCallback(int32_t uid, uint32_t type); - ErrCode CheckCombinedTaskNotifacation(std::shared_ptr &record, bool &sendNotification); + ErrCode CheckCombinedTaskNotification(std::shared_ptr &record, bool &sendNotification); bool StopContinuousTaskByUserInner(const std::string &key); ErrCode DetermineMatchCombinedTaskNotifacation(std::shared_ptr recordParam, bool &sendNotification); -- Gitee From cbb8f2ea0fc2f99d1cbc8976f04fc38e1bf1c1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:19:32 +0000 Subject: [PATCH 09/16] update services/continuous_task/include/notification_tools.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/include/notification_tools.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/continuous_task/include/notification_tools.h b/services/continuous_task/include/notification_tools.h index 529714ed..6e14182f 100644 --- a/services/continuous_task/include/notification_tools.h +++ b/services/continuous_task/include/notification_tools.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 @@ -31,6 +31,9 @@ public: void GetAllActiveNotificationsLabels(std::set ¬ificationLabels); void RefreshContinuousNotifications( const std::map> &newPromptInfos, int32_t serviceUid); + ErrCode RefreshContinuousNotificationWantAndContext(int32_t serviceUid, + const std::map> &newPromptInfos, + const std::shared_ptr continuousTaskRecord, bool updateContent = false); private: static int32_t notificationIdIndex_; -- Gitee From e13fc38bfc5197868df67ddc6d89cadcee648e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:20:42 +0000 Subject: [PATCH 10/16] update services/continuous_task/src/notification_tools.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- .../src/notification_tools.cpp | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/services/continuous_task/src/notification_tools.cpp b/services/continuous_task/src/notification_tools.cpp index 11f9a147..80e781ff 100644 --- a/services/continuous_task/src/notification_tools.cpp +++ b/services/continuous_task/src/notification_tools.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 @@ -179,5 +179,50 @@ WEAK_FUNC void NotificationTools::RefreshContinuousNotifications( } #endif } + +WEAK_FUNC ErrCode NotificationTools::RefreshContinuousNotificationWantAndContext(int32_t serviceUid, + const std::map> &newPromptInfos, + const std::shared_ptr continuousTaskRecord, bool updateContent) +{ +#ifdef DISTRIBUTED_NOTIFICATION_ENABLE + std::vector> notificationRequests; + ErrCode ret = Notification::NotificationHelper::GetActiveNotifications(notificationRequests); + if (ret != ERR_OK) { + BGTASK_LOGE("refresh task, get all active notification fail!"); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + for (Notification::NotificationRequest *var : notificationRequests) { + if (!var) { + BGTASK_LOGE("NotificationRequest is null!"); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + std::string label = var->GetLabel(); + if (newPromptInfos.count(label) == 0 || var->GetCreatorUid() != serviceUid) { + continue; + } + var->SetWantAgent(continuousTaskRecord->GetWantAgent()); + if (updateContent) { + auto &content = var->GetContent(); + if (!content) { + BGTASK_LOGE("content is null!"); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + auto const &normalContent = content->GetNotificationContent(); + if (!normalContent) { + BGTASK_LOGE("normalContent is null!"); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + normalContent->SetTitle(newPromptInfos.at(label).first); + normalContent->SetText(newPromptInfos.at(label).second); + } + ret = Notification::NotificationHelper::PublishContinuousTaskNotification(*var); + if (ret != ERR_OK) { + BGTASK_LOGE("refresh notification error, label: %{public}s", label.c_str()); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + } +#endif + return ERR_OK; +} } } -- Gitee From 50746fd7064b738c423c80b988b46e53476fb728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 00:21:38 +0000 Subject: [PATCH 11/16] update services/test/unittest/mock/mock_notification_tools.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/test/unittest/mock/mock_notification_tools.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/test/unittest/mock/mock_notification_tools.cpp b/services/test/unittest/mock/mock_notification_tools.cpp index 437a4b31..e47a4cb9 100644 --- a/services/test/unittest/mock/mock_notification_tools.cpp +++ b/services/test/unittest/mock/mock_notification_tools.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 @@ -32,5 +32,12 @@ void NotificationTools::GetAllActiveNotificationsLabels(std::set &n void NotificationTools::RefreshContinuousNotifications( const std::map> &newPromptInfos, int32_t serviceUid) {} + +ErrCode NotificationTools::RefreshContinuousNotificationWantAndContext(int32_t serviceUid, + const std::map> &newPromptInfos, + const std::shared_ptr continuousTaskRecord, bool updateContent) +{ + return ERR_OK; +} } } -- Gitee From 81984f735cc3d840e9898321dd23946b4374012e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 02:57:25 +0000 Subject: [PATCH 12/16] 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 | 184 ++++++++++++++++-- 1 file changed, 171 insertions(+), 13 deletions(-) diff --git a/services/test/unittest/bg_continuous_task_mgr_test.cpp b/services/test/unittest/bg_continuous_task_mgr_test.cpp index 57594dcb..f5605107 100644 --- a/services/test/unittest/bg_continuous_task_mgr_test.cpp +++ b/services/test/unittest/bg_continuous_task_mgr_test.cpp @@ -1434,7 +1434,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_058, TestSize.Level1) /** * @tc.name: BgTaskManagerUnitTest_059 - * @tc.desc: test CheckCombinedTaskNotifacation. + * @tc.desc: test CheckCombinedTaskNotification. * @tc.type: FUNC * @tc.require: issueICUX92 */ @@ -1448,13 +1448,13 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_059, TestSize.Level1) continuousTaskRecord->isByRequestObject_ = true; continuousTaskRecord->bgModeIds_.push_back(continuousTaskRecord->bgModeId_); // 不需要合并 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), ERR_OK); + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_OK); continuousTaskRecord->combinedNotificationTaskId_ = TEST_NUM_ONE; continuousTaskRecord->isCombinedTaskNotification_ = true; bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = nullptr; // 需要合并,但没有任务 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_TASKID_INVALID); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); @@ -1464,19 +1464,19 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_059, TestSize.Level1) continuousTaskRecord2->bgModeIds_.push_back(continuousTaskRecord->bgModeId_); bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务uid不相等 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_TASKID_INVALID); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); continuousTaskRecord2->continuousTaskId_ = TEST_NUM_ONE + 1; // 需要合并,任务id不相等 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_TASKID_INVALID); } /** * @tc.name: BgTaskManagerUnitTest_060 - * @tc.desc: test CheckCombinedTaskNotifacation. + * @tc.desc: test CheckCombinedTaskNotification. * @tc.type: FUNC * @tc.require: issueICUX92 */ @@ -1495,14 +1495,14 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_060, TestSize.Level1) continuousTaskRecord2->isCombinedTaskNotification_ = false; bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务不支持合并 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_NOT_MERGE_COMBINED_FALSE); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); continuousTaskRecord2->isCombinedTaskNotification_ = true; continuousTaskRecord2->notificationId_ = -1; bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务没有通知 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_NOT_MERGE_NOTIFICATION_NOT_EXIST); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); continuousTaskRecord->bgModeId_ = 2; @@ -1514,7 +1514,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_060, TestSize.Level1) continuousTaskRecord2->notificationId_ = 1; bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务主类型不相等 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); continuousTaskRecord->bgSubModeIds_.clear(); @@ -1523,13 +1523,13 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_060, TestSize.Level1) continuousTaskRecord2->bgSubModeIds_.push_back(3); bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务子类型不相等 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_MODE_OR_SUBMODE_TYPE_MISMATCH); } /** * @tc.name: BgTaskManagerUnitTest_061 - * @tc.desc: test CheckCombinedTaskNotifacation. + * @tc.desc: test CheckCombinedTaskNotification. * @tc.type: FUNC * @tc.require: issueICUX92 */ @@ -1560,7 +1560,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_061, TestSize.Level1) continuousTaskRecord2->notificationId_ = 1; bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; // 需要合并,任务类型包含上传下载,不能合并 - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_BGTASK_CONTINUOUS_DATA_TRANSFER_NOT_MERGE_NOTIFICATION); bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); @@ -1576,7 +1576,7 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_061, TestSize.Level1) continuousTaskRecord2->bgSubModeIds_.clear(); continuousTaskRecord2->bgSubModeIds_.push_back(1); bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord2; - EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotifacation(continuousTaskRecord, sendNotification), ERR_OK); + EXPECT_EQ(bgContinuousTaskMgr_->CheckCombinedTaskNotification(continuousTaskRecord, sendNotification), ERR_OK); } /** @@ -1589,5 +1589,163 @@ HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_062, TestSize.Level1) { EXPECT_EQ(bgContinuousTaskMgr_->StopBackgroundRunning("ability1", 1, 1), ERR_BGTASK_OBJECT_NOT_EXIST); } + +/** + * @tc.name: BgTaskManagerUnitTest_063 + * @tc.desc: update background runnging use api 21 api test. + * @tc.type: FUNC + * @tc.require: issueICWHAG + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_063, TestSize.Level1) +{ + bgContinuousTaskMgr_->isSysReady_.store(true); + sptr taskParam = new (std::nothrow) ContinuousTaskParam(true, 1, + std::make_shared(), + "ability1", nullptr, "Entry", true, {1}, 1); + taskParam->isByRequestObject_ = true; + taskParam->bgModeId_ = 1; + taskParam->updateTaskId_ = -1; + taskParam->bgModeIds_.clear(); + taskParam->bgModeIds_.push_back(1); + taskParam->bgSubModeIds_.clear(); + taskParam->bgSubModeIds_.push_back(3); + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + // 更新的任务ID为-1, 非法参数 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_BGTASK_CONTINUOUS_TASKID_INVALID); + + taskParam->updateTaskId_ = 1; + // 更新的任务ID为1, 但没有对应任务 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_BGTASK_OBJECT_NOT_EXIST); + + bgContinuousTaskMgr_->cachedBundleInfos_.clear(); + std::shared_ptr continuousTaskRecord = std::make_shared(); + continuousTaskRecord->uid_ = TEST_NUM_ONE; + continuousTaskRecord->continuousTaskId_ = TEST_NUM_ONE; + continuousTaskRecord->isByRequestObject_ = true; + continuousTaskRecord->abilityId_ = 1; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + // 更新的任务ID为1, 有对应任务,但传入的任务类型没有配置 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_BGTASK_INVALID_BGMODE); + + CachedBundleInfo info = CachedBundleInfo(); + info.abilityBgMode_["ability1"] = CONFIGURE_ALL_MODES; + info.appName_ = "Entry"; + bgContinuousTaskMgr_->cachedBundleInfos_.emplace(1, info); + + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + continuousTaskRecord->bgModeId_ = 1; + continuousTaskRecord->bgModeIds_.clear(); + continuousTaskRecord->bgModeIds_.push_back(1); + continuousTaskRecord->bgSubModeIds_.clear(); + continuousTaskRecord->bgSubModeIds_.push_back(3); + continuousTaskRecord->abilityName_ = "ability1"; + continuousTaskRecord->bundleName_ = "Entry"; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + // 前后任务包含上传下载,不做更新 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_OK); +} + +/** + * @tc.name: BgTaskManagerUnitTest_064 + * @tc.desc: update background runnging use api 21 api test. + * @tc.type: FUNC + * @tc.require: issueICWHAG + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_064, TestSize.Level1) +{ + bgContinuousTaskMgr_->isSysReady_.store(true); + sptr taskParam = new (std::nothrow) ContinuousTaskParam(true, 1, + std::make_shared(), + "ability1", nullptr, "Entry", true, {1}, 1); + taskParam->isByRequestObject_ = true; + taskParam->bgModeId_ = 1; + taskParam->bgModeIds_.clear(); + taskParam->bgModeIds_.push_back(4); + taskParam->bgSubModeIds_.clear(); + taskParam->bgSubModeIds_.push_back(1); + taskParam->updateTaskId_ = 1; + + bgContinuousTaskMgr_->cachedBundleInfos_.clear(); + std::shared_ptr continuousTaskRecord = std::make_shared(); + continuousTaskRecord->uid_ = TEST_NUM_ONE; + continuousTaskRecord->continuousTaskId_ = TEST_NUM_ONE; + continuousTaskRecord->isByRequestObject_ = true; + continuousTaskRecord->abilityId_ = 1; + CachedBundleInfo info = CachedBundleInfo(); + info.abilityBgMode_["ability1"] = CONFIGURE_ALL_MODES; + info.appName_ = "Entry"; + bgContinuousTaskMgr_->cachedBundleInfos_.emplace(1, info); + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + continuousTaskRecord->bgModeId_ = 4; + continuousTaskRecord->bgModeIds_.clear(); + continuousTaskRecord->bgModeIds_.push_back(4); + continuousTaskRecord->bgSubModeIds_.clear(); + continuousTaskRecord->bgSubModeIds_.push_back(1); + continuousTaskRecord->isCombinedTaskNotification_ = false; + std::shared_ptr wantInfo = std::make_shared(); + wantInfo->bundleName_ = "wantAgentBundleName"; + wantInfo->abilityName_ = "wantAgentAbilityName"; + continuousTaskRecord->wantAgentInfo_ = wantInfo; + continuousTaskRecord->abilityName_ = "ability1"; + continuousTaskRecord->bundleName_ = "Entry"; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + // 需要的任务没有合并,更新成功 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_OK); + + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + continuousTaskRecord->isCombinedTaskNotification_ = true; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + // 需要的任务有合并,前后类型一致,更新成功 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), ERR_OK); +} + +/** + * @tc.name: BgTaskManagerUnitTest_065 + * @tc.desc: update background runnging use api 21 api test. + * @tc.type: FUNC + * @tc.require: issueICWHAG + */ +HWTEST_F(BgContinuousTaskMgrTest, BgTaskManagerUnitTest_065, TestSize.Level1) +{ + bgContinuousTaskMgr_->isSysReady_.store(true); + sptr taskParam = new (std::nothrow) ContinuousTaskParam(true, 5, + std::make_shared(), + "ability1", nullptr, "Entry", true, {5}, 1); + taskParam->isByRequestObject_ = true; + taskParam->bgModeId_ = 5; + taskParam->bgModeIds_.clear(); + taskParam->bgModeIds_.push_back(5); + taskParam->bgSubModeIds_.clear(); + taskParam->bgSubModeIds_.push_back(1); + taskParam->updateTaskId_ = 1; + + bgContinuousTaskMgr_->cachedBundleInfos_.clear(); + std::shared_ptr continuousTaskRecord = std::make_shared(); + continuousTaskRecord->uid_ = TEST_NUM_ONE; + continuousTaskRecord->continuousTaskId_ = TEST_NUM_ONE; + continuousTaskRecord->isByRequestObject_ = true; + continuousTaskRecord->abilityId_ = 1; + CachedBundleInfo info = CachedBundleInfo(); + info.abilityBgMode_["ability1"] = CONFIGURE_ALL_MODES; + info.appName_ = "Entry"; + bgContinuousTaskMgr_->cachedBundleInfos_.emplace(1, info); + bgContinuousTaskMgr_->continuousTaskInfosMap_.clear(); + continuousTaskRecord->bgModeId_ = 4; + continuousTaskRecord->bgModeIds_.clear(); + continuousTaskRecord->bgModeIds_.push_back(4); + continuousTaskRecord->bgSubModeIds_.clear(); + continuousTaskRecord->bgSubModeIds_.push_back(1); + continuousTaskRecord->isCombinedTaskNotification_ = true; + std::shared_ptr wantInfo = std::make_shared(); + wantInfo->bundleName_ = "wantAgentBundleName"; + wantInfo->abilityName_ = "wantAgentAbilityName"; + continuousTaskRecord->wantAgentInfo_ = wantInfo; + continuousTaskRecord->abilityName_ = "ability1"; + continuousTaskRecord->bundleName_ = "Entry"; + bgContinuousTaskMgr_->continuousTaskInfosMap_["key1"] = continuousTaskRecord; + // 需要的任务有合并,前后类型不一致,返回失败 + EXPECT_EQ(bgContinuousTaskMgr_->UpdateBackgroundRunning(taskParam), + ERR_BGTASK_CONTINUOUS_UPDATE_FAIL_SAME_MODE_AND_MERGED); +} } // namespace BackgroundTaskMgr } // namespace OHOS \ No newline at end of file -- Gitee From 368575c934607f77391bf93b3bb14b64348cdd8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 03:02:03 +0000 Subject: [PATCH 13/16] 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 | 135 ++++++++++++++++-- 1 file changed, 122 insertions(+), 13 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index d2e96a7f..3d033d82 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -776,20 +776,129 @@ ErrCode BgContinuousTaskMgr::UpdateBackgroundRunning(const sptrabilityName_ + SEPARATOR + - std::to_string(taskParam->abilityId_); - auto self = shared_from_this(); - handler_->PostSyncTask([self, &taskInfoMapKey, &result, taskParam]() mutable { - if (!self) { - BGTASK_LOGE("self is null"); - result = ERR_BGTASK_SERVICE_INNER_ERROR; - return; - } - result = self->UpdateBackgroundRunningInner(taskInfoMapKey, taskParam); - }, AppExecFwk::EventQueue::Priority::HIGH); + if (taskParam->isByRequestObject_) { + // 根据任务id更新 + handler_->PostSyncTask([this, callingUid, taskParam, &result]() { + result = this->UpdateBackgroundRunningByTaskIdInner(callingUid, taskParam); + }, AppExecFwk::EventQueue::Priority::HIGH); + } else { + std::string taskInfoMapKey = std::to_string(callingUid) + SEPARATOR + taskParam->abilityName_ + SEPARATOR + + std::to_string(taskParam->abilityId_); + auto self = shared_from_this(); + handler_->PostSyncTask([self, &taskInfoMapKey, &result, taskParam]() mutable { + if (!self) { + BGTASK_LOGE("self is null"); + result = ERR_BGTASK_SERVICE_INNER_ERROR; + return; + } + result = self->UpdateBackgroundRunningInner(taskInfoMapKey, taskParam); + }, AppExecFwk::EventQueue::Priority::HIGH); + } return result; } +ErrCode BgContinuousTaskMgr::UpdateTaskInfo(std::shared_ptr record, + const sptr &taskParam) +{ + ErrCode ret = UpdateTaskNotification(record, taskParam); + if (ret != ERR_OK) { + return ret; + } + record->isCombinedTaskNotification_ = taskParam->isCombinedTaskNotification_; + if (record->suspendState_) { + std::string taskInfoMapKey = std::to_string(record->uid_) + SEPARATOR + record->abilityName_ + SEPARATOR + + std::to_string(record->abilityId_) + SEPARATOR + CommonUtils::ModesToString(record->bgModeIds_); + HandleActiveContinuousTask(record->uid_, record->pid_, taskInfoMapKey); + } + OnContinuousTaskChanged(record, ContinuousTaskEventTriggerType::TASK_UPDATE); + taskParam->notificationId_ = record->GetNotificationId(); + taskParam->continuousTaskId_ = record->GetContinuousTaskId(); + return RefreshTaskRecord(); +} + +ErrCode BgContinuousTaskMgr::UpdateTaskNotification(std::shared_ptr record, + const sptr &taskParam) +{ + auto oldModes = record->bgModeIds_; + if (CommonUtils::CheckExistMode(oldModes, BackgroundMode::DATA_TRANSFER) && + CommonUtils::CheckExistMode(taskParam->bgModeIds_, BackgroundMode::DATA_TRANSFER)) { + BGTASK_LOGI("uid: %{public}d, bundleName: %{public}s, abilityId: %{public}d have same mode: DATA_TRANSFER", + record->uid_, record->bundleName_.c_str(), record->abilityId_); + return ERR_OK; + } + std::string mainAbilityLabel = GetMainAbilityLabel(record->bundleName_, record->userId_); + if (mainAbilityLabel == "") { + BGTASK_LOGE("uid: %{public}d get main ability label or notification text fail.", record->uid_); + return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + } + if (!record->isCombinedTaskNotification_) { + record->bgModeId_ = taskParam->bgModeId_; + record->bgModeIds_ = taskParam->bgModeIds_; + record->bgSubModeIds_ = taskParam->bgSubModeIds_; + } + record->wantAgent_ = taskParam->wantAgent_; + if (record->wantAgent_ != nullptr && record->wantAgent_->GetPendingWant() != nullptr) { + auto target = record->wantAgent_->GetPendingWant()->GetTarget(); + auto want = record->wantAgent_->GetPendingWant()->GetWant(target); + if (want != nullptr) { + std::shared_ptr info = std::make_shared(); + info->bundleName_ = want->GetOperation().GetBundleName(); + info->abilityName_ = want->GetOperation().GetAbilityName(); + record->wantAgentInfo_ = info; + } + } + std::map> newPromptInfos; + if (record->isCombinedTaskNotification_) { + if (CommonUtils::CheckModesSame(oldModes, taskParam->bgModeIds_)) { + newPromptInfos.emplace(record->notificationLabel_, std::make_pair(mainAbilityLabel, "")); + return NotificationTools::GetInstance()->RefreshContinuousNotificationWantAndContext(bgTaskUid_, + newPromptInfos, record); + } else { + return ERR_BGTASK_CONTINUOUS_UPDATE_FAIL_SAME_MODE_AND_MERGED; + } + } else { + std::string notificationText = GetNotificationText(record); + if (notificationText.empty()) { + std::string modeStr = CommonUtils::ModesToString(record->bgModeIds_); + BGTASK_LOGE("notificationText is empty, bgmode : %{public}s", modeStr.c_str()); + } else { + newPromptInfos.emplace(record->notificationLabel_, std::make_pair(mainAbilityLabel, notificationText)); + return NotificationTools::GetInstance()->RefreshContinuousNotificationWantAndContext(bgTaskUid_, + newPromptInfos, record, true); + } + } + return ERR_OK; +} + +ErrCode BgContinuousTaskMgr::UpdateBackgroundRunningByTaskIdInner(int32_t uid, + const sptr &taskParam) +{ + int32_t continuousTaskId = taskParam->updateTaskId_; + if (continuousTaskId < 0) { + BGTASK_LOGE("update task fail, taskId: %{public}d", taskParam->updateTaskId_); + return ERR_BGTASK_CONTINUOUS_TASKID_INVALID; + } + auto findTask = [continuousTaskId](const auto &target) { + return continuousTaskId == target.second->continuousTaskId_ && target.second->isByRequestObject_; + }; + auto findTaskIter = find_if(continuousTaskInfosMap_.begin(), continuousTaskInfosMap_.end(), findTask); + if (findTaskIter == continuousTaskInfosMap_.end()) { + BGTASK_LOGE("uid: %{public}d not have task, taskId: %{public}d", uid, continuousTaskId); + return ERR_BGTASK_OBJECT_NOT_EXIST; + } + auto record = findTaskIter->second; + uint32_t configuredBgMode = GetBackgroundModeInfo(uid, record->abilityName_); + ErrCode ret = ERR_OK; + for (auto it = taskParam->bgModeIds_.begin(); it != taskParam->bgModeIds_.end(); it++) { + ret = CheckBgmodeType(configuredBgMode, *it, true, record); + if (ret != ERR_OK) { + BGTASK_LOGE("CheckBgmodeType error, mode: %{public}u, apply mode: %{public}u.", configuredBgMode, *it); + return ret; + } + } + return UpdateTaskInfo(record, taskParam); +} + ErrCode BgContinuousTaskMgr::UpdateBackgroundRunningInner(const std::string &taskInfoMapKey, const sptr &taskParam) { @@ -1126,8 +1235,7 @@ ErrCode BgContinuousTaskMgr::StopBackgroundRunningInner(int32_t uid, const std:: if (continuousTaskId != -1) { // 新街口取消 auto findTask = [continuousTaskId, uid, abilityName, abilityId](const auto &target) { - return continuousTaskId == target.second->continuousTaskId_ && target.second->uid_ == uid && - target.second->abilityName_ == abilityName && target.second->abilityId_ == abilityId; + return continuousTaskId == target.second->continuousTaskId_ && target.second->isByRequestObject_; }; auto findTaskIter = find_if(continuousTaskInfosMap_.begin(), continuousTaskInfosMap_.end(), findTask); @@ -2079,6 +2187,7 @@ void BgContinuousTaskMgr::OnContinuousTaskChanged(const std::shared_ptrSetCancelReason(continuousTaskInfo->reason_); continuousTaskCallbackInfo->SetSuspendState(continuousTaskInfo->suspendState_); continuousTaskCallbackInfo->SetSuspendReason(continuousTaskInfo->suspendReason_); + continuousTaskCallbackInfo->SetByRequestObject(continuousTaskInfo->isByRequestObject_); NotifySubscribers(changeEventType, continuousTaskCallbackInfo); ReportHisysEvent(changeEventType, continuousTaskInfo); } -- Gitee From e53bfaf0bd4eddd1695f43d2a7e0a3ef6a480be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 03:20:29 +0000 Subject: [PATCH 14/16] 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 | 10 +++++----- 1 file changed, 5 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 3d033d82..abb90e35 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -90,7 +90,7 @@ 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 ILLELG_NOTIFICATION_ID = -2; +static constexpr int32_t ILLEGAL_NOTIFICATION_ID = -2; static constexpr uint32_t INVALID_BGMODE = 0; static constexpr uint32_t BG_MODE_INDEX_HEAD = 1; static constexpr uint32_t BGMODE_NUMS = 10; @@ -1005,7 +1005,7 @@ ErrCode BgContinuousTaskMgr::StartBackgroundRunningSubmit(std::shared_ptr &recordParam, +ErrCode BgContinuousTaskMgr::CheckCombinedTaskNotification(std::shared_ptr &recordParam, bool &sendNotification) { // 无需合并,新申请 @@ -1518,7 +1518,7 @@ void BgContinuousTaskMgr::HandleActiveContinuousTask(int32_t uid, int32_t pid, c return; } std::string notificationLabel = "default"; - int32_t notificationId = ILLELG_NOTIFICATION_ID; + int32_t notificationId = ILLEGAL_NOTIFICATION_ID; std::vector notificationOldIds {}; auto iter = continuousTaskInfosMap_.begin(); while (iter != continuousTaskInfosMap_.end()) { @@ -1530,7 +1530,7 @@ void BgContinuousTaskMgr::HandleActiveContinuousTask(int32_t uid, int32_t pid, c iter->second->suspendState_ = false; OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_ACTIVE); if (iter->second->notificationId_ != -1) { - if (notificationId == ILLELG_NOTIFICATION_ID || + if (notificationId == ILLEGAL_NOTIFICATION_ID || CommonUtils::CheckExistNotification(notificationOldIds, iter->second->notificationId_)) { notificationOldIds.push_back(iter->second->notificationId_); SendContinuousTaskNotification(iter->second); -- Gitee From 6b78b9e8b068210fa77d04ee6421804a86cae1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 06:08:01 +0000 Subject: [PATCH 15/16] 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 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index abb90e35..14fb9657 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -822,8 +822,7 @@ ErrCode BgContinuousTaskMgr::UpdateTaskNotification(std::shared_ptrbgModeIds_; if (CommonUtils::CheckExistMode(oldModes, BackgroundMode::DATA_TRANSFER) && CommonUtils::CheckExistMode(taskParam->bgModeIds_, BackgroundMode::DATA_TRANSFER)) { - BGTASK_LOGI("uid: %{public}d, bundleName: %{public}s, abilityId: %{public}d have same mode: DATA_TRANSFER", - record->uid_, record->bundleName_.c_str(), record->abilityId_); + BGTASK_LOGI("uid: %{public}d have same mode: DATA_TRANSFER", record->uid_); return ERR_OK; } std::string mainAbilityLabel = GetMainAbilityLabel(record->bundleName_, record->userId_); @@ -859,8 +858,7 @@ ErrCode BgContinuousTaskMgr::UpdateTaskNotification(std::shared_ptrbgModeIds_); - BGTASK_LOGE("notificationText is empty, bgmode : %{public}s", modeStr.c_str()); + BGTASK_LOGE("notificationText is empty, uid: %{public}d", record->uid_); } else { newPromptInfos.emplace(record->notificationLabel_, std::make_pair(mainAbilityLabel, notificationText)); return NotificationTools::GetInstance()->RefreshContinuousNotificationWantAndContext(bgTaskUid_, -- Gitee From 189d5bad6999625c5a73725d7e77f077d487be30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E4=BC=9F?= Date: Sun, 7 Sep 2025 06:13:42 +0000 Subject: [PATCH 16/16] update services/continuous_task/src/notification_tools.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡伟 --- services/continuous_task/src/notification_tools.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/continuous_task/src/notification_tools.cpp b/services/continuous_task/src/notification_tools.cpp index 80e781ff..112df13c 100644 --- a/services/continuous_task/src/notification_tools.cpp +++ b/services/continuous_task/src/notification_tools.cpp @@ -189,12 +189,12 @@ WEAK_FUNC ErrCode NotificationTools::RefreshContinuousNotificationWantAndContext ErrCode ret = Notification::NotificationHelper::GetActiveNotifications(notificationRequests); if (ret != ERR_OK) { BGTASK_LOGE("refresh task, get all active notification fail!"); - return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + return ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL; } for (Notification::NotificationRequest *var : notificationRequests) { if (!var) { BGTASK_LOGE("NotificationRequest is null!"); - return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + return ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL; } std::string label = var->GetLabel(); if (newPromptInfos.count(label) == 0 || var->GetCreatorUid() != serviceUid) { @@ -205,12 +205,12 @@ WEAK_FUNC ErrCode NotificationTools::RefreshContinuousNotificationWantAndContext auto &content = var->GetContent(); if (!content) { BGTASK_LOGE("content is null!"); - return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + return ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL; } auto const &normalContent = content->GetNotificationContent(); if (!normalContent) { BGTASK_LOGE("normalContent is null!"); - return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + return ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL; } normalContent->SetTitle(newPromptInfos.at(label).first); normalContent->SetText(newPromptInfos.at(label).second); @@ -218,7 +218,7 @@ WEAK_FUNC ErrCode NotificationTools::RefreshContinuousNotificationWantAndContext ret = Notification::NotificationHelper::PublishContinuousTaskNotification(*var); if (ret != ERR_OK) { BGTASK_LOGE("refresh notification error, label: %{public}s", label.c_str()); - return ERR_BGTASK_NOTIFICATION_VERIFY_FAILED; + return ERR_BGTASK_CONTINUOUS_UPDATE_NOTIFICATION_FAIL; } } #endif -- Gitee