From 8719376b80abb40c39be9b71e81fcfb3d98c9729 Mon Sep 17 00:00:00 2001 From: chenming Date: Mon, 14 Feb 2022 20:53:33 +0800 Subject: [PATCH 1/4] add timer info and storage info in returing work info Signed-off-by: chenming --- interfaces/kits/js/napi/src/common.cpp | 34 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/napi/src/common.cpp b/interfaces/kits/js/napi/src/common.cpp index 4fe196b..c088484 100644 --- a/interfaces/kits/js/napi/src/common.cpp +++ b/interfaces/kits/js/napi/src/common.cpp @@ -335,10 +335,19 @@ napi_value Common::GetNapiWorkInfo(napi_env env, std::shared_ptr &work } // Set charge info. - if (workInfo->GetChargerType() != WorkCondition::Charger::CHARGING_UNKNOWN) { - napi_value napiChargingType = nullptr; - napi_create_int32(env, static_cast(workInfo->GetChargerType()), &napiChargingType); - napi_set_named_property(env, napiWork, "chargingType", napiChargingType); + WorkCondition::Charger charger = workInfo.GetChargerType(); + if (charger != WorkCondition::Charger::CHARGING_UNKNOWN) { + napi_value napiIsCharging = nullptr; + if (charger == WorkCondition::Charger::CHARGING_UNPLUGGED) { + napi_get_boolean(env, false, &napiIsCharging); + napi_set_named_property(env, napiWork, "isCharging", napiIsCharging); + } else { + napi_get_boolean(env, true, &napiIsCharging); + napi_set_named_property(env, napiWork, "isCharging", napiIsCharging); + napi_value napiChargerType = nullptr; + napi_create_int32(env, static_cast(charger), &napiChargerType); + napi_set_named_property(env, napiWork, "chargerType", napiChargerType); + } } // Set batteryLevel info. @@ -362,6 +371,23 @@ napi_value Common::GetNapiWorkInfo(napi_env env, std::shared_ptr &work napi_set_named_property(env, napiWork, "storageRequest", napiStorageRequest); } + // Set timer info. + uint32_t timeInterval = workInfo.GetTimeInterval(); + if (timeInterval > 0) { + napi_value napiTimer = nullptr; + napi_create_int32(env, static_cast(timeInterval), &napiTimer); + napi_set_named_property(env, napiWork, "repeatCycleTime", napiTimer); + if (workInfo->IsRepeat()) { + napi_value napiIsRepeat = nullptr; + napi_get_boolean(env, true, &napiIsRepeat); + napi_set_named_property(env, napiWork, "isRepeat", napiIsRepeat); + } else { + napi_value napiCount = nullptr; + napi_create_int32(env, static_cast(workInfo->GetCycleCount()), &napiCount); + napi_set_named_property(env, napiWork, "repeatCount", napiCount); + } + } + return napiWork; } -- Gitee From 649f5305f06286d3d6068266d4c5d75e6d08c11a Mon Sep 17 00:00:00 2001 From: chenming Date: Mon, 14 Feb 2022 20:54:26 +0800 Subject: [PATCH 2/4] add timer info and storage info in returing work info Signed-off-by: chenming --- interfaces/kits/js/napi/src/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/napi/src/common.cpp b/interfaces/kits/js/napi/src/common.cpp index c088484..e138626 100644 --- a/interfaces/kits/js/napi/src/common.cpp +++ b/interfaces/kits/js/napi/src/common.cpp @@ -335,7 +335,7 @@ napi_value Common::GetNapiWorkInfo(napi_env env, std::shared_ptr &work } // Set charge info. - WorkCondition::Charger charger = workInfo.GetChargerType(); + WorkCondition::Charger charger = workInfo-> GetChargerType(); if (charger != WorkCondition::Charger::CHARGING_UNKNOWN) { napi_value napiIsCharging = nullptr; if (charger == WorkCondition::Charger::CHARGING_UNPLUGGED) { -- Gitee From f6d3daae74de16260c111d4f4fc032fe3c90d075 Mon Sep 17 00:00:00 2001 From: chenming Date: Mon, 14 Feb 2022 20:55:35 +0800 Subject: [PATCH 3/4] add timer info and storage info in returing work info Signed-off-by: chenming --- interfaces/kits/js/napi/src/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/napi/src/common.cpp b/interfaces/kits/js/napi/src/common.cpp index e138626..1614df8 100644 --- a/interfaces/kits/js/napi/src/common.cpp +++ b/interfaces/kits/js/napi/src/common.cpp @@ -372,7 +372,7 @@ napi_value Common::GetNapiWorkInfo(napi_env env, std::shared_ptr &work } // Set timer info. - uint32_t timeInterval = workInfo.GetTimeInterval(); + uint32_t timeInterval = workInfo->GetTimeInterval(); if (timeInterval > 0) { napi_value napiTimer = nullptr; napi_create_int32(env, static_cast(timeInterval), &napiTimer); -- Gitee From 1dc4c60aef230690e43877bc544fbc86801fcaa1 Mon Sep 17 00:00:00 2001 From: chenming Date: Mon, 14 Feb 2022 21:44:58 +0800 Subject: [PATCH 4/4] add timer info and storage info in returing work info Signed-off-by: chenming --- frameworks/extension/src/js_work_scheduler_extension.cpp | 6 +++--- frameworks/src/work_info.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frameworks/extension/src/js_work_scheduler_extension.cpp b/frameworks/extension/src/js_work_scheduler_extension.cpp index dac4eb5..345e68d 100644 --- a/frameworks/extension/src/js_work_scheduler_extension.cpp +++ b/frameworks/extension/src/js_work_scheduler_extension.cpp @@ -156,7 +156,7 @@ void JsWorkSchedulerExtension::OnWorkStart(WorkInfo& workInfo) } uint32_t timeInterval = workInfo.GetTimeInterval(); - if (timeInterval != INVALID_VALUE) { + if (timeInterval > 0) { if (workInfo.IsRepeat()) { workInfoData->SetProperty("isRepeat", nativeEngine.CreateBoolean(true)); workInfoData->SetProperty("repeatCycleTime", nativeEngine.CreateNumber(timeInterval)); @@ -168,7 +168,7 @@ void JsWorkSchedulerExtension::OnWorkStart(WorkInfo& workInfo) NativeValue* argv[] = {jworkInfoData}; if (!jsObj_) { - WS_HILOGI("WorkSchedulerExtension Not found StaticSubscriberExtension.js"); + WS_HILOGI("WorkSchedulerExtension Not found js"); return; } @@ -230,7 +230,7 @@ void JsWorkSchedulerExtension::OnWorkStop(WorkInfo& workInfo) } uint32_t timeInterval = workInfo.GetTimeInterval(); - if (timeInterval != INVALID_VALUE) { + if (timeInterval > 0) { if (workInfo.IsRepeat()) { workInfoData->SetProperty("isRepeat", nativeEngine.CreateBoolean(true)); workInfoData->SetProperty("repeatCycleTime", nativeEngine.CreateNumber(timeInterval)); diff --git a/frameworks/src/work_info.cpp b/frameworks/src/work_info.cpp index af17c10..baef0cb 100644 --- a/frameworks/src/work_info.cpp +++ b/frameworks/src/work_info.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace WorkScheduler { const int INVALID_VALUE = -1; +const int INVALID_TIME_VALUE = 0; WorkInfo::WorkInfo() {} @@ -174,7 +175,7 @@ uint32_t WorkInfo::GetTimeInterval() if (conditionMap_.count(WorkCondition::Type::TIMER) > 0) { return conditionMap_.at(WorkCondition::Type::TIMER)->uintVal; } - return INVALID_VALUE; + return INVALID_TIME_VALUE; } int32_t WorkInfo::GetCycleCount() -- Gitee