From 998ff508397f433d116fed64aad184d68fa1e7bb Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Wed, 20 Aug 2025 14:39:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=92=8C=E7=8E=B0=E6=9C=89=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- interfaces/kits/ets/taihe/src/common.cpp | 22 +++++-- ...rceschedule.backgroundTaskManager.impl.cpp | 59 +++++++++++-------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/interfaces/kits/ets/taihe/src/common.cpp b/interfaces/kits/ets/taihe/src/common.cpp index 9c45ab7f..244ed766 100644 --- a/interfaces/kits/ets/taihe/src/common.cpp +++ b/interfaces/kits/ets/taihe/src/common.cpp @@ -26,7 +26,8 @@ const std::unordered_map SA_ERRCODE_MSG_MAP = { {ERR_BGTASK_NO_MEMORY, "Memory operation failed. Failed to allocate the memory."}, {ERR_BGTASK_SYS_NOT_READY, "System service operation failed. The system service is not ready."}, {ERR_BGTASK_SERVICE_NOT_CONNECTED, "System service operation failed. The system service is not connected."}, - {ERR_BGTASK_PARCELABLE_FAILED, "Parcel operation failed."}, + {ERR_BGTASK_PARCELABLE_FAILED, + "Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory."}, {ERR_BGTASK_TRANSACT_FAILED, "Internal transaction failed."}, {ERR_BGTASK_OBJECT_EXISTS, "Continuous Task verification failed. The application has applied for a continuous task."}, @@ -35,6 +36,7 @@ const std::unordered_map SA_ERRCODE_MSG_MAP = { {ERR_BGTASK_KEEPING_TASK_VERIFY_ERR, "Continuous Task verification failed. TASK_KEEPING background mode only supported in particular device."}, {ERR_BGTASK_INVALID_BGMODE, "Continuous Task verification failed. The bgMode is invalid."}, + {ERR_BGTASK_INVALID_UID, "Continuous Task verification failed. The uid is invalid."}, {ERR_BGTASK_NOTIFICATION_VERIFY_FAILED, "Notification verification failed for a continuous task." " The title or text of the notification cannot be empty."}, {ERR_BGTASK_NOTIFICATION_ERR, "Notification verification failed. Failed to send or cancel the notification."}, @@ -58,10 +60,22 @@ const std::unordered_map SA_ERRCODE_MSG_MAP = { "Transient task verification failed. The remaining time to run transient task is insufficient."}, {ERR_BGTASK_RESOURCES_EXCEEDS_MAX, "Caller information verification failed for an energy" " resource request. The number of resources applied exceeds maximun."}, + {ERR_BGTASK_RESOURCES_INVALID_PID_OR_UID, + "Caller information verification failed for an energy resource. Invalid pid or uid."}, + {ERR_BGTASK_RESOURCES_PARCELABLE_FAILED, + "Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory."}, + {ERR_BGTASK_RESOURCES_SYS_NOT_READY, "System service operation failed. The system service is not ready."}, + {ERR_BGTASK_RESOURCES_SERVICE_NOT_CONNECTED, + "System service operation failed. The system service is not connected."}, {ERR_BGTASK_SERVICE_INNER_ERROR, "Service inner error."}, - {ERR_BGTASK_NOREQUEST_TASK, "Transient task verification failed. Application no request transient task."}, - {ERR_BGTASK_FOREGROUND, "Transient task verification failed. Application is foreground."}, - {ERR_BGTASK_INVALID_PROCESS_NAME, "Transient task verification failed. Caller process name invalid."}, + {ERR_BGTASK_NOREQUEST_TASK, "Transient task verification failed. application no request transient task."}, + {ERR_BGTASK_FOREGROUND, "Transient task verification failed. application is foreground."}, + {ERR_BGTASK_TRANSIENT_PARCELABLE_FAILED, + "Failed to write data into parcel. Possible reasons: 1. Invalid parameters; 2. Failed to apply for memory."}, + {ERR_BGTASK_TRANSIENT_SYS_NOT_READY, "System service operation failed. The system service is not ready."}, + {ERR_BGTASK_TRANSIENT_SERVICE_NOT_CONNECTED, + "System service operation failed. The system service is not connected."}, + {ERR_BGTASK_INVALID_PROCESS_NAME, "Transient task verification failed. caller process name invaild."}, }; const std::unordered_map PARAM_ERRCODE_MSG_MAP = { diff --git a/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp b/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp index 0231b3ab..bc461fdc 100644 --- a/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp +++ b/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp @@ -73,8 +73,8 @@ void CancelSuspendDelay(int32_t requestId) { ErrCode errCode = DelayedSingleton::GetInstance()->CancelSuspendDelay(requestId); if (errCode != ERR_OK) { - BGTASK_LOGE("CancelSuspendDelay falied errCode: %{public}d", errCode); - set_business_error(errCode, Common::FindErrMsg(errCode)); + BGTASK_LOGE("CancelSuspendDelay falied errCode: %{public}d", Common::FindErrCode(errCode)); + set_business_error(Common::FindErrCode(errCode), Common::FindErrMsg(errCode)); } std::lock_guard lock(callbackLock_); auto findCallback = callbackInstances_.find(requestId); @@ -90,8 +90,8 @@ int32_t GetRemainingDelayTimeSync(int32_t requestId) ErrCode errCode = DelayedSingleton::GetInstance()-> GetRemainingDelayTime(callbackInfo.requestId, callbackInfo.delayTime); if (errCode) { - BGTASK_LOGE("GetRemainingDelayTime falied errCode: %{public}d", errCode); - set_business_error(errCode, Common::FindErrMsg(errCode)); + BGTASK_LOGE("GetRemainingDelayTime falied errCode: %{public}d", Common::FindErrCode(errCode)); + set_business_error(Common::FindErrCode(errCode), Common::FindErrMsg(errCode)); } return callbackInfo.delayTime; } @@ -109,8 +109,8 @@ int32_t GetRemainingDelayTimeSync(int32_t requestId) ErrCode errCode = DelayedSingleton::GetInstance()-> RequestSuspendDelay(reasonU16, *callbackPtr, delaySuspendInfo); if (errCode) { - BGTASK_LOGE("DelaySuspendInfo falied errCode: %{public}d", errCode); - set_business_error(errCode, Common::FindErrMsg(errCode)); + BGTASK_LOGE("DelaySuspendInfo falied errCode: %{public}d", Common::FindErrCode(errCode)); + set_business_error(Common::FindErrCode(errCode), Common::FindErrMsg(errCode)); } ::ohos::resourceschedule::backgroundTaskManager::DelaySuspendInfo resultInfo; @@ -135,8 +135,8 @@ void ApplyEfficiencyResources(EfficiencyResourcesRequest const& request) }; ErrCode errCode = DelayedSingleton::GetInstance()->ApplyEfficiencyResources(resourceInfo); if (errCode) { - BGTASK_LOGE("ApplyEfficiencyResources falied errCode: %{public}d", errCode); - set_business_error(errCode, Common::FindErrMsg(errCode)); + BGTASK_LOGE("ApplyEfficiencyResources falied errCode: %{public}d", Common::FindErrCode(errCode)); + set_business_error(Common::FindErrCode(errCode), Common::FindErrMsg(errCode)); } } @@ -144,8 +144,8 @@ void ResetAllEfficiencyResources() { ErrCode errCode = DelayedSingleton::GetInstance()->ResetAllEfficiencyResources(); if (errCode) { - BGTASK_LOGE("ResetAllEfficiencyResources falied errCode: %{public}d", errCode); - set_business_error(errCode, Common::FindErrMsg(errCode)); + BGTASK_LOGE("ResetAllEfficiencyResources falied errCode: %{public}d", Common::FindErrCode(errCode)); + set_business_error(Common::FindErrCode(errCode), Common::FindErrMsg(errCode)); } } @@ -195,7 +195,8 @@ bool CheckParam(ani_env *env, ContinuousTaskCallbackInfo *asyncCallbackInfo, uin if (GetAbilityContext(env, reinterpret_cast(context), asyncCallbackInfo->abilityContext) != ANI_OK) { BGTASK_LOGE("get ability failed"); asyncCallbackInfo->errCode = ERR_CONTEXT_NULL_OR_TYPE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return false; } @@ -203,7 +204,8 @@ bool CheckParam(ani_env *env, ContinuousTaskCallbackInfo *asyncCallbackInfo, uin if (info == nullptr) { BGTASK_LOGE("ability info is null"); asyncCallbackInfo->errCode = ERR_ABILITY_INFO_EMPTY; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return false; } @@ -211,7 +213,8 @@ bool CheckParam(ani_env *env, ContinuousTaskCallbackInfo *asyncCallbackInfo, uin if (!token) { BGTASK_LOGE("get ability token info failed"); asyncCallbackInfo->errCode = ERR_GET_TOKEN_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return false; } return true; @@ -226,7 +229,8 @@ ani_status GetModes(ani_env *env, const array_view &bgModes, ContinuousT if (bgModes.size() == 0) { BGTASK_LOGE("get bgModes arraylen is 0"); asyncCallbackInfo->errCode = ERR_BGMODE_NULL_OR_TYPE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return ANI_ERROR; } std::vector bgModesVector(bgModes.begin(), bgModes.end()); @@ -241,7 +245,8 @@ ani_status GetModes(ani_env *env, const array_view &bgModes, ContinuousT } else { BGTASK_LOGE("mode string is invalid"); asyncCallbackInfo->errCode = ERR_BGMODE_NULL_OR_TYPE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return ANI_ERROR; } } @@ -258,7 +263,8 @@ bool CheckBackgroundMode(ani_env *env, ContinuousTaskCallbackInfo *asyncCallback if (asyncCallbackInfo->bgMode < BG_MODE_ID_BEGIN || asyncCallbackInfo->bgMode > BG_MODE_ID_END) { BGTASK_LOGE("request background mode id: %{public}u out of range", asyncCallbackInfo->bgMode); asyncCallbackInfo->errCode = ERR_BGMODE_RANGE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return false; } } else { @@ -266,7 +272,8 @@ bool CheckBackgroundMode(ani_env *env, ContinuousTaskCallbackInfo *asyncCallback if (asyncCallbackInfo->bgModes[i] < BG_MODE_ID_BEGIN || asyncCallbackInfo->bgModes[i] > BG_MODE_ID_END) { BGTASK_LOGE("request background mode id: %{public}u out of range", asyncCallbackInfo->bgModes[i]); asyncCallbackInfo->errCode = ERR_BGMODE_RANGE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return false; } } @@ -289,7 +296,8 @@ void StopBackgroundRunningSync(uintptr_t context) asyncCallbackInfo->errCode = BackgroundTaskMgrHelper::RequestStopBackgroundRunning(info->name, token, abilityId); if (asyncCallbackInfo->errCode) { BGTASK_LOGE("StopBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); } } @@ -304,7 +312,8 @@ void StartBackgroundRunningSync(uintptr_t context, BackgroundMode bgMode, uintpt if (GetWantAgent(env, reinterpret_cast(wantAgent), asyncCallbackInfo->wantAgent) != ANI_OK) { BGTASK_LOGE("Get ability failed"); asyncCallbackInfo->errCode = ERR_WANTAGENT_NULL_OR_TYPE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return; } sptr token = asyncCallbackInfo->abilityContext->GetToken(); @@ -326,7 +335,8 @@ void StartBackgroundRunningSync(uintptr_t context, BackgroundMode bgMode, uintpt taskParam.continuousTaskId_); if (asyncCallbackInfo->errCode) { BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); } } @@ -393,7 +403,8 @@ static ani_enum_item GetContentType(ani_env *env) if (GetWantAgent(env, reinterpret_cast(wantAgent), asyncCallbackInfo->wantAgent) != ANI_OK) { BGTASK_LOGE("Get ability failed"); asyncCallbackInfo->errCode = ERR_WANTAGENT_NULL_OR_TYPE_ERR; - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return notification; } if (GetModes(env, bgModes, asyncCallbackInfo.get()) != ANI_OK) { @@ -416,7 +427,8 @@ static ani_enum_item GetContentType(ani_env *env) asyncCallbackInfo->continuousTaskId = taskParam.continuousTaskId_; if (asyncCallbackInfo->errCode) { BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return notification; } if (!GetSlotType(env) || !GetContentType(env)) { @@ -459,7 +471,8 @@ static ani_enum_item GetContentType(ani_env *env) asyncCallbackInfo->continuousTaskId = taskParam.continuousTaskId_; if (asyncCallbackInfo->errCode) { BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); - set_business_error(asyncCallbackInfo->errCode, Common::FindErrMsg(asyncCallbackInfo->errCode)); + set_business_error( + Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return notification; } if (!GetSlotType(env) || !GetContentType(env)) { -- Gitee From 721020d372f211e383209cd5ef6cadeb76bd4ab2 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Wed, 20 Aug 2025 15:55:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=92=8C=E7=8E=B0=E6=9C=89=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- .../ohos.resourceschedule.backgroundTaskManager.impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp b/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp index bc461fdc..089aee47 100644 --- a/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp +++ b/interfaces/kits/ets/taihe/src/ohos.resourceschedule.backgroundTaskManager.impl.cpp @@ -295,7 +295,7 @@ void StopBackgroundRunningSync(uintptr_t context) asyncCallbackInfo->errCode = BackgroundTaskMgrHelper::RequestStopBackgroundRunning(info->name, token, abilityId); if (asyncCallbackInfo->errCode) { - BGTASK_LOGE("StopBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); + BGTASK_LOGE("StopBackgroundRunning fail errCode: %{public}d", Common::FindErrCode(asyncCallbackInfo->errCode)); set_business_error( Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); } @@ -334,7 +334,7 @@ void StartBackgroundRunningSync(uintptr_t context, BackgroundMode bgMode, uintpt BGTASK_LOGI("notification %{public}d, continuousTaskId %{public}d", taskParam.notificationId_, taskParam.continuousTaskId_); if (asyncCallbackInfo->errCode) { - BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); + BGTASK_LOGE("StartBackgroundRunning fail errCode: %{public}d", Common::FindErrCode(asyncCallbackInfo->errCode)); set_business_error( Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); } @@ -426,7 +426,7 @@ static ani_enum_item GetContentType(ani_env *env) asyncCallbackInfo->notificationId = taskParam.notificationId_; asyncCallbackInfo->continuousTaskId = taskParam.continuousTaskId_; if (asyncCallbackInfo->errCode) { - BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); + BGTASK_LOGE("StartBackgroundRunning fail errCode: %{public}d", Common::FindErrCode(asyncCallbackInfo->errCode)); set_business_error( Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return notification; @@ -470,7 +470,7 @@ static ani_enum_item GetContentType(ani_env *env) asyncCallbackInfo->notificationId = taskParam.notificationId_; asyncCallbackInfo->continuousTaskId = taskParam.continuousTaskId_; if (asyncCallbackInfo->errCode) { - BGTASK_LOGE("StartBackgroundRunning falied errCode: %{public}d", asyncCallbackInfo->errCode); + BGTASK_LOGE("StartBackgroundRunning fail errCode: %{public}d", Common::FindErrCode(asyncCallbackInfo->errCode)); set_business_error( Common::FindErrCode(asyncCallbackInfo->errCode), Common::FindErrMsg(asyncCallbackInfo->errCode)); return notification; -- Gitee