diff --git a/interfaces/innerkits/include/continuous_task_suspend_reason.h b/interfaces/innerkits/include/continuous_task_suspend_reason.h index 619726433f6cabdfc71750d7e671dfabfdc9ad3d..fa629c470c2586b17889859e08457a2b479fc0e2 100644 --- a/interfaces/innerkits/include/continuous_task_suspend_reason.h +++ b/interfaces/innerkits/include/continuous_task_suspend_reason.h @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 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. @@ -31,7 +31,6 @@ public: SYSTEM_SUSPEND_MULTI_DEVICE_NOT_USED, SYSTEM_SUSPEND_USED_ILLEGALLY, SYSTEM_SUSPEND_SYSTEM_LOAD_WARNING, - ALL_MODE = 0xFF, }; static uint32_t GetSuspendReasonValue(const uint32_t mode); diff --git a/interfaces/innerkits/src/continuous_task_suspend_reason.cpp b/interfaces/innerkits/src/continuous_task_suspend_reason.cpp index ef190ebb9b9830d00a496c13dcccd11f855b1951..b2d6fafde9ed98b2576ef5305021af3af81585f6 100644 --- a/interfaces/innerkits/src/continuous_task_suspend_reason.cpp +++ b/interfaces/innerkits/src/continuous_task_suspend_reason.cpp @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 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. @@ -26,9 +26,7 @@ const std::unordered_map PARAM_SUSPEND_REASON = { {BackgroundMode::AUDIO_RECORDING, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_AUDIO_RECORDING_NOT_RUNNING}, {BackgroundMode::LOCATION, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_LOCATION_NOT_USED}, {BackgroundMode::BLUETOOTH_INTERACTION, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_BLUETOOTH_NOT_USED}, - {BackgroundMode::MULTI_DEVICE_CONNECTION, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_MULTI_DEVICE_NOT_USED}, - {BackgroundMode::VOIP, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_AUDIO_RECORDING_NOT_RUNNING}, - {ContinuousTaskSuspendReason::ALL_MODE, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_USED_ILLEGALLY} + {BackgroundMode::MULTI_DEVICE_CONNECTION, ContinuousTaskSuspendReason::SYSTEM_SUSPEND_MULTI_DEVICE_NOT_USED} }; uint32_t ContinuousTaskSuspendReason::GetSuspendReasonValue(const uint32_t mode) diff --git a/interfaces/kits/napi/src/js_backgroundtask_subscriber.cpp b/interfaces/kits/napi/src/js_backgroundtask_subscriber.cpp index db265f6aa9d331fc77fd4fd420c6282aa359680a..f4194b5fa6b926b956a6ed899a23430063d88d0d 100644 --- a/interfaces/kits/napi/src/js_backgroundtask_subscriber.cpp +++ b/interfaces/kits/napi/src/js_backgroundtask_subscriber.cpp @@ -14,9 +14,7 @@ */ #include "js_backgroundtask_subscriber.h" -#include "background_mode.h" #include "continuous_task_log.h" -#include "continuous_task_suspend_reason.h" #include "js_runtime_utils.h" #include "iservice_registry.h" #include "system_ability_definition.h" @@ -239,13 +237,9 @@ void JsBackgroundTaskSubscriber::HandleOnContinuousTaskSuspend( napi_set_named_property(env_, jsContinuousTaskSuspendInfo, "suspendState", suspendState); // set suspendReason - uint32_t mode = continuousTaskCallbackInfo->GetSuspendReason(); - if (mode < BackgroundMode::END || mode == ContinuousTaskSuspendReason::ALL_MODE) { - uint32_t reason = ContinuousTaskSuspendReason::GetSuspendReasonValue(mode); - napi_value suspendReason = nullptr; - napi_create_int32(env_, reason, &suspendReason); - napi_set_named_property(env_, jsContinuousTaskSuspendInfo, "suspendReason", suspendReason); - } + napi_value suspendReason = nullptr; + napi_create_int32(env_, continuousTaskCallbackInfo->GetSuspendReason(), &suspendReason); + napi_set_named_property(env_, jsContinuousTaskSuspendInfo, "suspendReason", suspendReason); napi_value argv[1] = { jsContinuousTaskSuspendInfo }; napi_value callResult = nullptr; diff --git a/services/continuous_task/src/bg_continuous_task_mgr.cpp b/services/continuous_task/src/bg_continuous_task_mgr.cpp index 0eff3430c9dcd532b36338bd95213855ca5a0f5a..bb9ed50e7b23984b0ee568824fb9e271c89c1a4e 100644 --- a/services/continuous_task/src/bg_continuous_task_mgr.cpp +++ b/services/continuous_task/src/bg_continuous_task_mgr.cpp @@ -53,6 +53,7 @@ #endif // SUPPORT_GRAPHICS #include "background_mode.h" #include "background_sub_mode.h" +#include "continuous_task_suspend_reason.h" namespace OHOS { namespace BackgroundTaskMgr { @@ -1190,7 +1191,7 @@ bool BgContinuousTaskMgr::IsExistCallback(int32_t uid, uint32_t type) return false; } -void BgContinuousTaskMgr::HandleSuspendContinuousTask(int32_t uid, int32_t pid, int32_t reason, const std::string &key) +void BgContinuousTaskMgr::HandleSuspendContinuousTask(int32_t uid, int32_t pid, int32_t mode, const std::string &key) { if (continuousTaskInfosMap_.find(key) == continuousTaskInfosMap_.end()) { BGTASK_LOGW("suspend TaskInfo failure, no matched task: %{public}s", key.c_str()); @@ -1202,9 +1203,16 @@ void BgContinuousTaskMgr::HandleSuspendContinuousTask(int32_t uid, int32_t pid, ++iter; continue; } - BGTASK_LOGW("SuspendContinuousTask reason: %{public}d, key %{public}s", reason, key.c_str()); + BGTASK_LOGW("SuspendContinuousTask mode: %{public}d, key %{public}s", mode, key.c_str()); iter->second->suspendState_ = true; - iter->second->suspendReason_ = reason; + if (mode < BackgroundMode::END) { + uint32_t reasonValue = ContinuousTaskSuspendReason::GetSuspendReasonValue(mode); + if (reasonValue == 0) { + iter->second->suspendReason_ = -1; + } else { + iter->second->suspendReason_ = reasonValue; + } + } OnContinuousTaskChanged(iter->second, ContinuousTaskEventTriggerType::TASK_SUSPEND); RefreshTaskRecord(); break;