From eefb20f80d28ba3db5d2f4d886c60f56882996c2 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Fri, 18 Jul 2025 14:31:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1=20numb?= =?UTF-8?q?er=E8=BD=ACint/double/long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- .../ohos.resourceschedule.workScheduler.taihe | 14 +++++++------- .../ets/taihe/work_scheduler/src/common.cpp | 18 +++++++++--------- ...hos.resourceschedule.workScheduler.impl.cpp | 9 ++++----- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe b/interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe index e4f4d93..f766cda 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe +++ b/interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe @@ -54,21 +54,21 @@ union ParameType { } struct WorkInfo { - workId: f64; + workId: i32; bundleName: String; abilityName: String; isPersisted: Optional; networkType: Optional; isCharging: Optional; chargerType: Optional; - batteryLevel: Optional; + batteryLevel: Optional; batteryStatus: Optional; storageRequest: Optional; - repeatCycleTime: Optional; + repeatCycleTime: Optional; isRepeat: Optional; - repeatCount: Optional; + repeatCount: Optional; isDeepIdle: Optional; - idleWaitTime: Optional; + idleWaitTime: Optional; parameters: Optional<@record Map>; } @@ -78,7 +78,7 @@ function StopWork(work: WorkInfo, needCancel: Optional): void; @gen_async("getWorkStatus") @gen_promise("getWorkStatus") -function GetWorkStatusSync(workId: f64): WorkInfo; +function GetWorkStatusSync(workId: i32): WorkInfo; @gen_async("obtainAllWorks") @gen_promise("obtainAllWorks") @@ -88,4 +88,4 @@ function StopAndClearWorks(): void; @gen_async("isLastWorkTimeOut") @gen_promise("isLastWorkTimeOut") -function IsLastWorkTimeOutSync(workId: f64): bool; \ No newline at end of file +function IsLastWorkTimeOutSync(workId: i32): bool; \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp index 4c3bbe4..1733272 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp +++ b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp @@ -169,7 +169,7 @@ bool Common::GetBatteryInfo( if (!aniWork.batteryLevel.has_value()) { WS_HILOGD("Unset batteryLevel."); } else { - auto batteryLevel = static_cast(aniWork.batteryLevel.value()); + auto batteryLevel = aniWork.batteryLevel.value(); if (batteryLevel >= BATTERY_LEVEL_MIN && batteryLevel <= BATTERY_LEVEL_MAX) { workInfo.RequestBatteryLevel(batteryLevel); hasCondition = true; @@ -228,8 +228,8 @@ bool Common::GetRepeatInfo( return false; } - auto repeatCycleTime = static_cast(aniWork.repeatCycleTime.value()); - auto repeatCount = static_cast(aniWork.repeatCount.value()); + auto repeatCycleTime = aniWork.repeatCycleTime.value(); + auto repeatCount = aniWork.repeatCount.value(); if (aniWork.isRepeat.value()) { if (repeatCount > 0) { WS_HILOGI("RepeatCount has been set , ignore isRepeat."); @@ -264,7 +264,7 @@ bool Common::GetDeepIdleInfo( bool Common::GetWorkInfo( ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) { - workInfo.SetWorkId(static_cast(aniWork.workId)); + workInfo.SetWorkId(aniWork.workId); workInfo.SetElement(std::string(aniWork.bundleName), std::string(aniWork.abilityName)); workInfo.RequestPersisted(aniWork.isPersisted.has_value() ? aniWork.isPersisted.value() : false); // Get extra parameters. @@ -365,7 +365,7 @@ void Common::ParseExtrasInfo(std::shared_ptr work WS_HILOGE("extras parameters is 0."); return; } - if (ConvertToAniParameters(extrasMap, aniWork)) { + if (!ConvertToAniParameters(extrasMap, aniWork)) { aniWork.parameters = {}; WS_HILOGE("convert extra parameters failed."); return; @@ -384,16 +384,16 @@ void Common::ParseWorkInfo(std::shared_ptr workIn aniWork.isCharging = optional(std::in_place, true); aniWork.chargerType = optional(std::in_place, ChargingType::key_t(workInfo->GetChargerType())); } - aniWork.batteryLevel = optional(std::in_place, workInfo->GetBatteryLevel()); + aniWork.batteryLevel = optional(std::in_place, workInfo->GetBatteryLevel()); aniWork.batteryStatus = optional(std::in_place, BatteryStatus::key_t(workInfo->GetBatteryStatus())); aniWork.storageRequest = optional(std::in_place, StorageRequest::key_t(workInfo->GetStorageLevel())); - aniWork.repeatCycleTime = optional(std::in_place, workInfo->GetTimeInterval()); + aniWork.repeatCycleTime = optional(std::in_place, workInfo->GetTimeInterval()); aniWork.isRepeat = optional(std::in_place, workInfo->IsRepeat()); - aniWork.repeatCount = optional(std::in_place, workInfo->GetCycleCount()); + aniWork.repeatCount = optional(std::in_place, workInfo->GetCycleCount()); aniWork.isDeepIdle = optional(std::in_place, UNSET_INT_PARAM); - aniWork.idleWaitTime = optional(std::in_place, UNSET_INT_PARAM); + aniWork.idleWaitTime = optional(std::in_place, UNSET_INT_PARAM); ParseExtrasInfo(workInfo, aniWork); } } // namespace WorkScheduler diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp index 8119597..185ce74 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp +++ b/interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp @@ -69,11 +69,10 @@ void StopWork(::ohos::resourceschedule::workScheduler::WorkInfo const &work, opt } } -::ohos::resourceschedule::workScheduler::WorkInfo GetWorkStatusSync(double workId) +::ohos::resourceschedule::workScheduler::WorkInfo GetWorkStatusSync(int32_t workId) { std::shared_ptr workInfo {nullptr}; - ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().GetWorkStatus( - static_cast(workId), workInfo); + ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().GetWorkStatus(workId, workInfo); if (errCode) { WS_HILOGE("get work status failed errCode: %{public}d", errCode); set_business_error(errCode, Common::FindErrMsg(errCode)); @@ -133,10 +132,10 @@ void StopAndClearWorks() } } -bool IsLastWorkTimeOutSync(double workId) +bool IsLastWorkTimeOutSync(int32_t workId) { AsyncCallbackIsLastWorkTimeOut asyncCallbackInfo; - asyncCallbackInfo.workId = static_cast(workId); + asyncCallbackInfo.workId = workId; ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().IsLastWorkTimeout( asyncCallbackInfo.workId, asyncCallbackInfo.result); if (errCode) { -- Gitee From 404cdb512e84fcfb887ccbd9d26d20261b350d32 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Sat, 19 Jul 2025 11:39:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1=20numb?= =?UTF-8?q?er=E8=BD=ACint/double/long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- interfaces/kits/js/napi/src/obtain_all_works.cpp | 6 ++++++ interfaces/kits/js/napi/src/stop_work.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/interfaces/kits/js/napi/src/obtain_all_works.cpp b/interfaces/kits/js/napi/src/obtain_all_works.cpp index 7ca7e33..21547a9 100644 --- a/interfaces/kits/js/napi/src/obtain_all_works.cpp +++ b/interfaces/kits/js/napi/src/obtain_all_works.cpp @@ -45,6 +45,12 @@ napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, // argv[0]: callback if (argc == OBTAIN_ALL_WORKS_MAX_PARAMS) { + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[CALLBACK_INDEX], &valuetype)); + if (valuetype != napi_function) { + Common::HandleParamErr(env, E_CALLBACK_TYPE_ERR); + return nullptr; + } napi_create_reference(env, argv[CALLBACK_INDEX], 1, &callback); } return Common::NapiGetNull(env); diff --git a/interfaces/kits/js/napi/src/stop_work.cpp b/interfaces/kits/js/napi/src/stop_work.cpp index b597422..a70d672 100644 --- a/interfaces/kits/js/napi/src/stop_work.cpp +++ b/interfaces/kits/js/napi/src/stop_work.cpp @@ -44,6 +44,10 @@ napi_value StopWork(napi_env env, napi_callback_info info) // get params bool needCancel = false; + if (!Common::MatchValueType(env, argv[NEED_CANCEL_INDEX], napi_boolean)) { + Common::HandleParamErr(env, E_WORK_INFO_TYPE_ERR); + return Common::NapiGetNull(env); + } napi_get_value_bool(env, argv[NEED_CANCEL_INDEX], &needCancel); // Check workInfo and call service. -- Gitee