From d6475a8fa86d13f23d9960921b95b329cc88f19c Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Wed, 25 Jun 2025 15:42:05 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- BUILD.gn | 3 + bundle.json | 4 +- .../kits/ets/taihe/work_scheduler/BUILD.gn | 98 +++++ .../ohos.resourceschedule.workScheduler.taihe | 91 ++++ .../ets/taihe/work_scheduler/include/common.h | 54 +++ .../work_scheduler/src/ani_constructor.cpp | 30 ++ .../ets/taihe/work_scheduler/src/common.cpp | 404 ++++++++++++++++++ ...os.resourceschedule.workScheduler.impl.cpp | 155 +++++++ .../work_scheduler_extension_ability/BUILD.gn | 91 ++++ .../ohos.WorkSchedulerExtensionAbility.taihe | 32 ++ .../src/ani_constructor.cpp | 30 ++ ...hos.WorkSchedulerExtensionAbility.impl.cpp | 55 +++ .../work_scheduler_extension_context/BUILD.gn | 87 ++++ .../idl/WorkSchedulerExtensionContext.taihe | 55 +++ .../WorkSchedulerExtensionContext.impl.cpp | 53 +++ .../src/ani_constructor.cpp | 30 ++ workscheduler.gni | 2 + 17 files changed, 1272 insertions(+), 2 deletions(-) create mode 100644 interfaces/kits/ets/taihe/work_scheduler/BUILD.gn create mode 100644 interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe create mode 100644 interfaces/kits/ets/taihe/work_scheduler/include/common.h create mode 100644 interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler/src/common.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp diff --git a/BUILD.gn b/BUILD.gn index 4e781ff..72cfb95 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -20,6 +20,9 @@ group("fwk_group_work_scheduler_all") { "${worksched_frameworks_path}:workschedclient", "${worksched_frameworks_path}/extension:workschedextension", "${worksched_interfaces_path}/kits/cj:cj_work_scheduler_ffi", + "${worksched_taihe_path}/work_scheduler:work_scheduler_taihe", + "${worksched_taihe_path}/work_scheduler_extension_ability:work_scheduler_extension_ability_taihe", + "${worksched_taihe_path}/work_scheduler_extension_context:work_scheduler_extension_context_taihe", "${worksched_interfaces_path}/kits/js:workscheduler", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension:workschedulerextensionability_napi", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension_context:workschedulerextensioncontext_napi", diff --git a/bundle.json b/bundle.json index 76669aa..cd5aef8 100644 --- a/bundle.json +++ b/bundle.json @@ -44,7 +44,6 @@ "netmanager_base", "time_service", "init", - "idl_tool", "data_share", "config_policy", "hiview", @@ -52,7 +51,8 @@ "hicollie", "hitrace", "power_manager", - "resource_schedule_service" + "resource_schedule_service", + "runtime_core" ] }, "build": { diff --git a/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn new file mode 100644 index 0000000..f6c3415 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn @@ -0,0 +1,98 @@ +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") + +copy_taihe_idl("copy_workScheduler") { + sources = [ "idl/ohos.resourceschedule.workScheduler.taihe" ] +} + +subsystem_name = "resourceschedule" +part_name = "work_scheduler" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_workScheduler" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.resourceschedule.workScheduler.ani.cpp", + "$taihe_generated_file_path/src/ohos.resourceschedule.workScheduler.abi.c", + ] +} + +taihe_shared_library("work_scheduler_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + sources = get_target_outputs(":run_taihe") + + include_dirs = [ + "${worksched_utils_path}/include", + "${worksched_frameworks_path}/include", + "include", + ] + + sources += [ + "src/ani_constructor.cpp", + "src/common.cpp", + "src/ohos.resourceschedule.workScheduler.impl.cpp", + ] + + deps = [ + ":run_taihe", + "${worksched_frameworks_path}:workschedclient", + "${worksched_utils_path}:workschedutils", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +generate_static_abc("work_scheduler_abc") { + base_url = "$taihe_generated_file_path" + files = + [ "$taihe_generated_file_path/@ohos.resourceschedule.workScheduler.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/work_scheduler_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("work_scheduler_etc") { + source = "$target_out_dir/work_scheduler_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":work_scheduler_abc" ] +} + +group("work_scheduler_taihe") { + deps = [ + ":work_scheduler_ani", + ":work_scheduler_etc", + ] +} 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 new file mode 100644 index 0000000..e4f4d93 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/idl/ohos.resourceschedule.workScheduler.taihe @@ -0,0 +1,91 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.resourceschedule.workScheduler", "workScheduler") +@!sts_inject(""" +static { loadLibrary("work_scheduler_ani.z"); } +""") + +enum NetworkType : i32 { + NETWORK_TYPE_ANY = 0, + NETWORK_TYPE_MOBILE, + NETWORK_TYPE_WIFI, + NETWORK_TYPE_BLUETOOTH, + NETWORK_TYPE_WIFI_P2P, + NETWORK_TYPE_ETHERNET +} + +enum ChargingType : i32 { + CHARGING_PLUGGED_ANY = 0, + CHARGING_PLUGGED_AC, + CHARGING_PLUGGED_USB, + CHARGING_PLUGGED_WIRELESS +} + +enum BatteryStatus : i32 { + BATTERY_STATUS_LOW = 0, + BATTERY_STATUS_OKAY, + BATTERY_STATUS_LOW_OR_OKAY +} + +enum StorageRequest : i32 { + STORAGE_LEVEL_LOW = 0, + STORAGE_LEVEL_OKAY, + STORAGE_LEVEL_LOW_OR_OKAY +} + +union ParameType { + int_type : i32; + double_type : f64; + string_type : String; + bool_type : bool; +} + +struct WorkInfo { + workId: f64; + bundleName: String; + abilityName: String; + isPersisted: Optional; + networkType: Optional; + isCharging: Optional; + chargerType: Optional; + batteryLevel: Optional; + batteryStatus: Optional; + storageRequest: Optional; + repeatCycleTime: Optional; + isRepeat: Optional; + repeatCount: Optional; + isDeepIdle: Optional; + idleWaitTime: Optional; + parameters: Optional<@record Map>; +} + +function StartWork(work: WorkInfo): void; + +function StopWork(work: WorkInfo, needCancel: Optional): void; + +@gen_async("getWorkStatus") +@gen_promise("getWorkStatus") +function GetWorkStatusSync(workId: f64): WorkInfo; + +@gen_async("obtainAllWorks") +@gen_promise("obtainAllWorks") +function ObtainAllWorksSync(): Array; + +function StopAndClearWorks(): void; + +@gen_async("isLastWorkTimeOut") +@gen_promise("isLastWorkTimeOut") +function IsLastWorkTimeOutSync(workId: f64): bool; \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler/include/common.h b/interfaces/kits/ets/taihe/work_scheduler/include/common.h new file mode 100644 index 0000000..802f649 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/include/common.h @@ -0,0 +1,54 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_INTERFACES_KITS_TAIHE_INCLUDE_COMMON +#define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_INTERFACES_KITS_TAIHE_INCLUDE_COMMON + +#include +#include "ohos.resourceschedule.workScheduler.impl.hpp" +#include "work_info.h" + +namespace OHOS { +namespace WorkScheduler { +class Common { +public: + static int32_t FindErrCode(const int32_t errCodeIn); + static std::string FindErrMsg(const int32_t errCode); + static bool GetExtrasInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetNetWorkInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetChargeInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetBatteryInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetStorageInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetRepeatInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetDeepIdleInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool GetWorkInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo); + static bool ConvertToAniParameters(std::map>& extrasMap, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork); + static void ParseExtrasInfo(std::shared_ptr workInfo, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork); + static void ParseWorkInfo(std::shared_ptr workInfo, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork); +}; +} // namespace WorkScheduler +} // namespace OHOS +#endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_INTERFACES_KITS_TAIHE_INCLUDE_COMMON \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp new file mode 100644 index 0000000..1369df9 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.resourceschedule.workScheduler.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::resourceschedule::workScheduler::ANIRegister(env)) { + std::cerr << "Error from ohos::resourceschedule::workScheduler::ANI_Constructor" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ 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 new file mode 100644 index 0000000..e9568d6 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp @@ -0,0 +1,404 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "common.h" +#include "work_sched_hilog.h" +#include "want_params_wrapper.h" +#include "bool_wrapper.h" +#include "double_wrapper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" +#include "work_sched_errors.h" +#include "taihe/runtime.hpp" + +using namespace taihe; +using namespace ohos::resourceschedule::workScheduler; + +namespace OHOS { +namespace WorkScheduler { +const int32_t BATTERY_LEVEL_MIN = 0; +const int32_t BATTERY_LEVEL_MAX = 100; +const int32_t TRUE_PARAM = 1; + +// need to be same as WantParams +enum { + VALUE_TYPE_NULL = -1, + VALUE_TYPE_BOOLEAN = 1, + VALUE_TYPE_INT = 5, + VALUE_TYPE_DOUBLE = 8, + VALUE_TYPE_STRING = 9, +}; + +int32_t Common::FindErrCode(const int32_t errCodeIn) +{ + auto iter = paramErrCodeMsgMap.find(errCodeIn); + if (iter != paramErrCodeMsgMap.end()) { + return E_PARAM_ERROR; + } + return errCodeIn > THRESHOLD ? errCodeIn / OFFSET : errCodeIn; +} + +std::string Common::FindErrMsg(const int32_t errCode) +{ + if (errCode == ERR_OK) { + return ""; + } + auto iter = saErrCodeMsgMap.find(errCode); + if (iter != saErrCodeMsgMap.end()) { + std::string errMessage = "BussinessError "; + int32_t errCodeInfo = FindErrCode(errCode); + errMessage.append(std::to_string(errCodeInfo)).append(": ").append(iter->second); + return errMessage; + } + iter = paramErrCodeMsgMap.find(errCode); + if (iter != paramErrCodeMsgMap.end()) { + std::string errMessage = "BussinessError 401: Parameter error. "; + errMessage.append(iter->second); + return errMessage; + } + return "Inner error."; +} + +bool Common::GetExtrasInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.parameters.has_value()) { + return true; + } + AAFwk::WantParams extraParams; + auto aniParameters = aniWork.parameters.value(); + + for (const auto &item : aniParameters) { + std::string key = std::string(item.first); + switch (item.second.get_tag()) { + case ohos::resourceschedule::workScheduler::ParameType::tag_t::int_type: { + int32_t intVal = item.second.get_int_type_ref(); + extraParams.SetParam(key, AAFwk::Integer::Box(intVal)); + break; + } + case ohos::resourceschedule::workScheduler::ParameType::tag_t::double_type: { + double doubleVal = item.second.get_double_type_ref(); + extraParams.SetParam(key, AAFwk::Double::Box(doubleVal)); + break; + } + case ohos::resourceschedule::workScheduler::ParameType::tag_t::string_type: { + std::string strVal = std::string(item.second.get_string_type_ref()); + extraParams.SetParam(key, AAFwk::String::Box(strVal)); + break; + } + case ohos::resourceschedule::workScheduler::ParameType::tag_t::bool_type: { + bool boolVal = item.second.get_bool_type_ref(); + extraParams.SetParam(key, AAFwk::Boolean::Box(boolVal)); + break; + } + default: { + WS_HILOGE("parameters type error."); + set_business_error(E_PARAMETERS_TYPE_ERR, FindErrMsg(E_PARAMETERS_TYPE_ERR)); + return false; + } + } + } + workInfo.RequestExtras(extraParams); + WS_HILOGD("Get parameters finished."); + return true; +} + +bool Common::GetNetWorkInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.networkType.has_value()) { + WS_HILOGD("Unset networkType."); + return false; + } + auto networkType = aniWork.networkType.value().get_value(); + if (networkType >= WorkCondition::Network::NETWORK_TYPE_ANY && + networkType <= WorkCondition::Network::NETWORK_TYPE_ETHERNET) { + workInfo.RequestNetworkType(WorkCondition::Network(networkType)); + return true; + } else { + WS_HILOGE("NetworkType set is invalid, just ignore set."); + set_business_error(E_NETWORK_TYPE_ERR, FindErrMsg(E_NETWORK_TYPE_ERR)); + return false; + } +} + +bool Common::GetChargeInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.isCharging.has_value()) { + WS_HILOGD("Unset isCharging, ignore ChargerType set also."); + return false; + } + if (!aniWork.isCharging.value()) { + workInfo.RequestChargerType(false, WorkCondition::Charger::CHARGING_UNPLUGGED); + } else { + if (!aniWork.chargerType.has_value()) { + workInfo.RequestChargerType(true, WorkCondition::Charger::CHARGING_PLUGGED_ANY); + return true; + } + auto chargerType = aniWork.chargerType.value().get_value(); + if (chargerType >= WorkCondition::Charger::CHARGING_PLUGGED_ANY && + chargerType <= WorkCondition::Charger::CHARGING_PLUGGED_WIRELESS) { + workInfo.RequestChargerType(true, WorkCondition::Charger(chargerType)); + } else { + workInfo.RequestChargerType(true, WorkCondition::Charger::CHARGING_PLUGGED_ANY); + WS_HILOGE("ChargeType info is invalid, just ignore set."); + set_business_error(E_CHARGER_TYPE_ERR, FindErrMsg(E_CHARGER_TYPE_ERR)); + } + } + return true; +} + +bool Common::GetBatteryInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + bool hasCondition = false; + // Get battery level info. + if (!aniWork.batteryLevel.has_value()) { + WS_HILOGD("Unset batteryLevel."); + } else { + auto batteryLevel = static_cast(aniWork.batteryLevel.value()); + if (batteryLevel >= BATTERY_LEVEL_MIN && batteryLevel <= BATTERY_LEVEL_MAX) { + workInfo.RequestBatteryLevel(batteryLevel); + hasCondition = true; + } else { + WS_HILOGE("BatteryLevel set is invalid, just ignore set."); + set_business_error(E_BATTERY_LEVEL_ERR, FindErrMsg(E_BATTERY_LEVEL_ERR)); + } + } + + // Get battery status info. + if (!aniWork.batteryStatus.has_value()) { + WS_HILOGD("Unset batteryStatus."); + } else { + auto batteryStatus = aniWork.batteryStatus.value().get_value(); + if (batteryStatus >= WorkCondition::BatteryStatus::BATTERY_STATUS_LOW && + batteryStatus <= WorkCondition::BatteryStatus::BATTERY_STATUS_LOW_OR_OKAY) { + workInfo.RequestBatteryStatus(WorkCondition::BatteryStatus(batteryStatus)); + hasCondition = true; + } else { + WS_HILOGE("BatteryStatus set is invalid, just ignore set."); + set_business_error(E_BATTERY_STATUS_ERR, FindErrMsg(E_BATTERY_STATUS_ERR)); + } + } + return hasCondition; +} + +bool Common::GetStorageInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.storageRequest.has_value()) { + WS_HILOGD("Unset StorageRequest."); + return false; + } + auto storageRequest = aniWork.storageRequest.value().get_value(); + if (storageRequest >= WorkCondition::Storage::STORAGE_LEVEL_LOW && + storageRequest <= WorkCondition::Storage::STORAGE_LEVEL_LOW_OR_OKAY) { + workInfo.RequestStorageLevel(WorkCondition::Storage(storageRequest)); + return true; + } else { + WS_HILOGE("StorageRequest set is invalid, just ignore set."); + set_business_error(E_STORAGE_REQUEST_ERR, FindErrMsg(E_STORAGE_REQUEST_ERR)); + return false; + } +} + +bool Common::GetRepeatInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.repeatCycleTime.has_value()) { + WS_HILOGD("RepeatCycleTime not set, just ignore other repeat set."); + return false; + } + if (!aniWork.isRepeat.has_value() && !aniWork.repeatCount.has_value()) { + WS_HILOGD("Not set isRepeat or repeatCount, ignore."); + return false; + } + + auto repeatCycleTime = static_cast(aniWork.repeatCycleTime.value()); + auto repeatCount = static_cast(aniWork.repeatCount.value()); + if (aniWork.isRepeat.value()) { + if (repeatCount > 0) { + WS_HILOGI("RepeatCount has been set , ignore isRepeat."); + workInfo.RequestRepeatCycle(repeatCycleTime, repeatCount); + } else { + workInfo.RequestRepeatCycle(repeatCycleTime); + } + return true; + } else { + if (repeatCount < 0) { + WS_HILOGE("RepeatCount is invalid, ignore."); + set_business_error(E_REPEAT_COUNT_ERR, FindErrMsg(E_REPEAT_COUNT_ERR)); + return false; + } + workInfo.RequestRepeatCycle(repeatCycleTime, repeatCount); + return true; + } +} + +bool Common::GetDeepIdleInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + if (!aniWork.isDeepIdle.has_value()) { + WS_HILOGD("isDeepIdle not set"); + return false; + } + auto isDeepIdle = aniWork.isDeepIdle.value(); + workInfo.RequestDeepIdle(isDeepIdle == TRUE_PARAM); + return true; +} + +bool Common::GetWorkInfo( + ::ohos::resourceschedule::workScheduler::WorkInfo const &aniWork, OHOS::WorkScheduler::WorkInfo &workInfo) +{ + workInfo.SetWorkId(static_cast(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. + if (!GetExtrasInfo(aniWork, workInfo)) { + return false; + } + // Get condition info. + bool hasConditions = false; + if (GetNetWorkInfo(aniWork, workInfo)) { + hasConditions = true; + } + if (GetChargeInfo(aniWork, workInfo)) { + hasConditions = true; + } + if (GetBatteryInfo(aniWork, workInfo)) { + hasConditions = true; + } + if (GetStorageInfo(aniWork, workInfo)) { + hasConditions = true; + } + if (GetRepeatInfo(aniWork, workInfo)) { + hasConditions = true; + } + if (GetDeepIdleInfo(aniWork, workInfo)) { + hasConditions = true; + } + + if (!hasConditions) { + WS_HILOGE("Set none conditions, so fail to init WorkInfo."); + set_business_error(E_CONDITION_EMPTY, FindErrMsg(E_CONDITION_EMPTY)); + return false; + } + return true; +} + +bool Common::ConvertToAniParameters(std::map>& extrasMap, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork) +{ + int typeId = VALUE_TYPE_NULL; + auto aniParams = aniWork.parameters.has_value() ? aniWork.parameters.value() : map{}; + for (const auto &iter : extrasMap) { + typeId = AAFwk::WantParams::GetDataType(iter.second); + switch (typeId) { + case VALUE_TYPE_INT: { + AAFwk::IInteger *intPtr = AAFwk::IInteger::Query(iter.second); + if (intPtr == nullptr) { + return false; + } + int intVal = AAFwk::Integer::Unbox(intPtr); + aniParams.emplace(iter.first, ParameType::make_int_type(intVal)); + break; + } + case VALUE_TYPE_DOUBLE: { + AAFwk::IDouble *doublePtr = AAFwk::IDouble::Query(iter.second); + if (doublePtr == nullptr) { + return false; + } + double doubleVal = AAFwk::Double::Unbox(doublePtr); + aniParams.emplace(iter.first, ParameType::make_double_type(doubleVal)); + break; + } + case VALUE_TYPE_BOOLEAN: { + AAFwk::IBoolean *boolPtr = AAFwk::IBoolean::Query(iter.second); + if (boolPtr == nullptr) { + return false; + } + bool boolVal = AAFwk::Boolean::Unbox(boolPtr); + aniParams.emplace(iter.first, ParameType::make_bool_type(boolVal)); + break; + } + case VALUE_TYPE_STRING: { + AAFwk::IString *strPtr = AAFwk::IString::Query(iter.second); + if (strPtr == nullptr) { + return false; + } + std::string strVal = AAFwk::String::Unbox(strPtr); + aniParams.emplace(iter.first, ParameType::make_string_type(strVal)); + break; + } + default: { + WS_HILOGE("parameters type not supported."); + return false; + break; + } + } + } + aniWork.parameters = optional>(std::in_place, aniParams); + return true; +} + +void Common::ParseExtrasInfo(std::shared_ptr workInfo, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork) +{ + std::shared_ptr extras = workInfo->GetExtras(); + if (extras.get() == nullptr) { + WS_HILOGE("extras map is not initialized."); + aniWork.parameters = {}; + return; + } + auto extrasMap = extras->GetParams(); + if (extrasMap.size() == 0) { + aniWork.parameters = {}; + WS_HILOGE("extras parameters is 0."); + return; + } + if (ConvertToAniParameters(extrasMap, aniWork)) { + aniWork.parameters = {}; + WS_HILOGE("convert extra parameters failed."); + return; + } +} + +void Common::ParseWorkInfo(std::shared_ptr workInfo, + ::ohos::resourceschedule::workScheduler::WorkInfo &aniWork) +{ + aniWork.isPersisted = optional(std::in_place, workInfo->IsPersisted()); + aniWork.networkType = optional(std::in_place, NetworkType::key_t(workInfo->GetNetworkType())); + if (workInfo->GetChargerType() >= WorkCondition::Charger::CHARGING_UNPLUGGED) { + aniWork.isCharging = optional(std::in_place, false); + aniWork.chargerType = optional(std::in_place, ChargingType::key_t(-1)); + } else { + 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.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.isRepeat = optional(std::in_place, workInfo->IsRepeat()); + aniWork.repeatCount = optional(std::in_place, workInfo->GetCycleCount()); + aniWork.isDeepIdle = optional(std::in_place, -1); + aniWork.idleWaitTime = optional(std::in_place, -1); + ParseExtrasInfo(workInfo, aniWork); +} +} // namespace WorkScheduler +} // namespace OHOS \ No newline at end of file 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 new file mode 100644 index 0000000..2666afe --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler/src/ohos.resourceschedule.workScheduler.impl.cpp @@ -0,0 +1,155 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.resourceschedule.workScheduler.proj.hpp" +#include "ohos.resourceschedule.workScheduler.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "work_sched_hilog.h" +#include "workscheduler_srv_client.h" +#include "work_info.h" +#include "common.h" + +using namespace taihe; +using namespace OHOS; +using namespace ohos::resourceschedule::workScheduler; +using namespace OHOS::WorkScheduler; + +namespace { +// To be implemented. +struct AsyncCallbackIsLastWorkTimeOut { + int32_t workId {-1}; + bool result {false}; +}; + +void StartWork(::ohos::resourceschedule::workScheduler::WorkInfo const &work) +{ + WorkScheduler::WorkInfo workInfo = WorkScheduler::WorkInfo(); + if (!Common::GetWorkInfo(work, workInfo)) { + WS_HILOGE("StartWork parse parameter failed"); + return; + } + ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().StartWork(workInfo); + if (errCode) { + WS_HILOGE("StartWork failed errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + } +} + +void StopWork(::ohos::resourceschedule::workScheduler::WorkInfo const &work, optional_view needCancel) +{ + WorkScheduler::WorkInfo workInfo = WorkScheduler::WorkInfo(); + if (!Common::GetWorkInfo(work, workInfo)) { + WS_HILOGE("StartWork parse parameter failed"); + return; + } + ErrCode errCode = ERR_OK; + auto cancel = needCancel.has_value() ? needCancel.value() : false; + WS_HILOGD("cancel is: %{public}d", cancel); + if (cancel) { + errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().StopAndCancelWork(workInfo); + } else { + errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().StopWork(workInfo); + } + if (errCode) { + WS_HILOGE("StopWork failed errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + } +} + +::ohos::resourceschedule::workScheduler::WorkInfo GetWorkStatusSync(double workId) +{ + std::shared_ptr workInfo {nullptr}; + ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().GetWorkStatus( + static_cast(workId), workInfo); + if (errCode) { + WS_HILOGE("get work status failed errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + return {}; + } + if (workInfo == nullptr) { + WS_HILOGE("workInfo is null"); + return {}; + } + + ::ohos::resourceschedule::workScheduler::WorkInfo aniWork{ + .workId = workInfo->GetWorkId(), + .bundleName = workInfo->GetBundleName(), + .abilityName = workInfo->GetAbilityName(), + }; + Common::ParseWorkInfo(workInfo, aniWork); + return aniWork; +} + +array<::ohos::resourceschedule::workScheduler::WorkInfo> ObtainAllWorksSync() +{ + std::list> workInfoList; + ErrCode errCode = WorkSchedulerSrvClient::GetInstance().ObtainAllWorks(workInfoList); + if (errCode) { + WS_HILOGE("get work status failed errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + return {}; + } + if (workInfoList.empty()) { + WS_HILOGE("workInfoList is nullptr"); + return {}; + } + std::vector<::ohos::resourceschedule::workScheduler::WorkInfo> aniWorkInfoList; + for (auto &workInfo: workInfoList) { + ::ohos::resourceschedule::workScheduler::WorkInfo aniWork{ + .workId = workInfo->GetWorkId(), + .bundleName = workInfo->GetBundleName(), + .abilityName = workInfo->GetAbilityName(), + }; + Common::ParseWorkInfo(workInfo, aniWork); + aniWorkInfoList.push_back(aniWork); + } + return array<::ohos::resourceschedule::workScheduler::WorkInfo>{copy_data_t{}, + aniWorkInfoList.data(), aniWorkInfoList.size()}; +} + +void StopAndClearWorks() +{ + ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().StopAndClearWorks(); + if (errCode) { + WS_HILOGE("stop and clear works failed errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + } +} + +bool IsLastWorkTimeOutSync(double workId) +{ + AsyncCallbackIsLastWorkTimeOut asyncCallbackInfo; + asyncCallbackInfo.workId = static_cast(workId); + ErrCode errCode = WorkScheduler::WorkSchedulerSrvClient::GetInstance().IsLastWorkTimeout( + asyncCallbackInfo.workId, asyncCallbackInfo.result); + if (errCode) { + WS_HILOGE("IsLastWorkTimeOutSync errCode: %{public}d", errCode); + set_business_error(errCode, Common::FindErrMsg(errCode)); + return false; + } + return asyncCallbackInfo.result; +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_StartWork(StartWork); +TH_EXPORT_CPP_API_StopWork(StopWork); +TH_EXPORT_CPP_API_GetWorkStatusSync(GetWorkStatusSync); +TH_EXPORT_CPP_API_ObtainAllWorksSync(ObtainAllWorksSync); +TH_EXPORT_CPP_API_StopAndClearWorks(StopAndClearWorks); +TH_EXPORT_CPP_API_IsLastWorkTimeOutSync(IsLastWorkTimeOutSync); +// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn new file mode 100644 index 0000000..62277c0 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn @@ -0,0 +1,91 @@ +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") + +copy_taihe_idl("copy_WorkSchedulerExtensionAbility") { + sources = [ "idl/ohos.WorkSchedulerExtensionAbility.taihe" ] + deps = [ + "../work_scheduler:copy_workScheduler", + "../work_scheduler_extension_context:copy_WorkSchedulerExtensionContext", + ] +} + +subsystem_name = "resourceschedule" +part_name = "work_scheduler" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_WorkSchedulerExtensionAbility" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.ani.cpp", + "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.abi.c", + ] +} + +taihe_shared_library("work_scheduler_extension_ability_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.WorkSchedulerExtensionAbility.impl.cpp", + ] + + deps = [ ":run_taihe" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +generate_static_abc("work_scheduler_extension_ability_abc") { + base_url = "$taihe_generated_file_path" + files = + [ "$taihe_generated_file_path/@ohos.WorkSchedulerExtensionAbility.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/work_scheduler_extension_ability_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("work_scheduler_extension_ability_etc") { + source = "$target_out_dir/work_scheduler_extension_ability_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":work_scheduler_extension_ability_abc" ] +} + +group("work_scheduler_extension_ability_taihe") { + deps = [ + ":work_scheduler_extension_ability_ani", + ":work_scheduler_extension_ability_etc", + ] +} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe new file mode 100644 index 0000000..b8e8a54 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe @@ -0,0 +1,32 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.WorkSchedulerExtensionAbility") +@!sts_inject_into_module(" + import WorkSchedulerExtensionContext from 'application.WorkSchedulerExtensionContext'; +") +@!sts_inject(""" + loadLibrary("work_scheduler_extension_ability_ani.z"); +""") + +from ohos.resourceschedule.workScheduler use WorkInfo; + +@class +interface WorkSchedulerExtensionAbility { + @get getContext(): @sts_type("WorkSchedulerExtensionContext") Opaque; + @set setContext(param: @sts_type("WorkSchedulerExtensionContext") Opaque); + onWorkStart(work: WorkInfo): void; + onWorkStop(work: WorkInfo): void; +} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp new file mode 100644 index 0000000..ce5fb13 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.WorkSchedulerExtensionAbility.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::WorkSchedulerExtensionAbility::ANIRegister(env)) { + std::cerr << "Error from ohos::WorkSchedulerExtensionAbility::ANI_Constructor" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp new file mode 100644 index 0000000..383d48e --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp @@ -0,0 +1,55 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.WorkSchedulerExtensionAbility.proj.hpp" +#include "ohos.WorkSchedulerExtensionAbility.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace { +// To be implemented. + +class WorkSchedulerExtensionAbilityImpl { +public: + WorkSchedulerExtensionAbilityImpl() + { + // Don't forget to implement the constructor. + } + + uintptr_t getContext() + { + TH_THROW(std::runtime_error, "getContext not implemented"); + } + + void setContext(uintptr_t param) + { + TH_THROW(std::runtime_error, "setContext not implemented"); + } + + void onWorkStart(::ohos::resourceschedule::workScheduler::WorkInfo const &work) + { + TH_THROW(std::runtime_error, "onWorkStart not implemented"); + } + + void onWorkStop(::ohos::resourceschedule::workScheduler::WorkInfo const &work) + { + TH_THROW(std::runtime_error, "onWorkStop not implemented"); + } +}; +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn new file mode 100644 index 0000000..36735e2 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn @@ -0,0 +1,87 @@ +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") + +copy_taihe_idl("copy_WorkSchedulerExtensionContext") { + sources = [ "idl/WorkSchedulerExtensionContext.taihe" ] +} + +subsystem_name = "resourceschedule" +part_name = "work_scheduler" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_WorkSchedulerExtensionContext" ] + outputs = [ + "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.ani.cpp", + "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.abi.c", + ] +} + +taihe_shared_library("work_scheduler_extension_context_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + sources = get_target_outputs(":run_taihe") + + sources += [ + "src/WorkSchedulerExtensionContext.impl.cpp", + "src/ani_constructor.cpp", + ] + + deps = [ ":run_taihe" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +generate_static_abc("work_scheduler_extension_context_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/WorkSchedulerExtensionContext.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/work_scheduler_extension_context_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("work_scheduler_extension_context_etc") { + source = "$target_out_dir/work_scheduler_extension_context_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":work_scheduler_extension_context_abc" ] +} + +group("work_scheduler_extension_context_taihe") { + deps = [ + ":work_scheduler_extension_context_ani", + ":work_scheduler_extension_context_etc", + ] +} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe new file mode 100644 index 0000000..d1bba2b --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe @@ -0,0 +1,55 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("WorkSchedulerExtensionContext") +@!sts_inject_into_module(" + import type Want from '@ohos.app.ability.Want'; + import ExtensionContext from 'application.ExtensionContext'; +") +@!sts_inject(""" + { loadLibrary("work_scheduler_extension_context_ani.z"); } +""") + +@class +interface WorkSchedulerExtensionContext_inner { + @gen_promise("startServiceExtensionAbility") + StartServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; + @gen_promise("stopServiceExtensionAbility") + StopServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; +} + +function Create():WorkSchedulerExtensionContext_inner; + +@!sts_inject(""" +export class WorkSchedulerExtensionContext extends ExtensionContext { +inner: WorkSchedulerExtensionContext_inner; + +startServiceExtensionAbility(want: Want): Promise { + return this.inner.startServiceExtensionAbility(want); +} + +stopServiceExtensionAbility(want: Want): Promise { + return this.inner.stopServiceExtensionAbility(want); +} + +constructor() { + this.inner = create(); +} + +constructor(param: WorkSchedulerExtensionContext_inner) { + this.inner = param; +} +} +""") \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp new file mode 100644 index 0000000..a32696d --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp @@ -0,0 +1,53 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WorkSchedulerExtensionContext.proj.hpp" +#include "WorkSchedulerExtensionContext.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace { +// To be implemented. +class WorkSchedulerExtensionContext_innerImpl { +public: + WorkSchedulerExtensionContext_innerImpl() + { + // Don't forget to implement the constructor. + } + + void StartServiceExtensionAbilitySync(uintptr_t want) + { + TH_THROW(std::runtime_error, "StartServiceExtensionAbilitySync not implemented"); + } + + void StopServiceExtensionAbilitySync(uintptr_t want) + { + TH_THROW(std::runtime_error, "StopServiceExtensionAbilitySync not implemented"); + } +}; + +::WorkSchedulerExtensionContext::WorkSchedulerExtensionContext_inner Create() +{ + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return taihe::make_holder(); +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_Create(Create); +// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp new file mode 100644 index 0000000..b943ef5 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WorkSchedulerExtensionContext.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != WorkSchedulerExtensionContext::ANIRegister(env)) { + std::cerr << "Error from WorkSchedulerExtensionContext::ANI_Constructor" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/workscheduler.gni b/workscheduler.gni index 789d56d..67b3122 100644 --- a/workscheduler.gni +++ b/workscheduler.gni @@ -35,6 +35,8 @@ worksched_frameworks_path = "${worksched_root_path}/frameworks" worksched_test_path = "${worksched_root_path}/test" +worksched_taihe_path = "${worksched_interfaces_path}/kits/ets/taihe" + system_type = "default" declare_args() { -- Gitee From 6a95e1434c9baac5afc33443b730cc758aec120d Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Fri, 27 Jun 2025 11:29:36 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- interfaces/kits/ets/taihe/work_scheduler/src/common.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp index e9568d6..8dcba76 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp +++ b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp @@ -346,7 +346,6 @@ bool Common::ConvertToAniParameters(std::map Date: Sat, 28 Jun 2025 17:57:42 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- BUILD.gn | 2 - .../work_scheduler_extension_ability/BUILD.gn | 91 ------------------- .../ohos.WorkSchedulerExtensionAbility.taihe | 32 ------- .../src/ani_constructor.cpp | 30 ------ ...hos.WorkSchedulerExtensionAbility.impl.cpp | 55 ----------- .../work_scheduler_extension_context/BUILD.gn | 87 ------------------ .../idl/WorkSchedulerExtensionContext.taihe | 55 ----------- .../WorkSchedulerExtensionContext.impl.cpp | 53 ----------- .../src/ani_constructor.cpp | 30 ------ 9 files changed, 435 deletions(-) delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp diff --git a/BUILD.gn b/BUILD.gn index 72cfb95..01b4319 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -21,8 +21,6 @@ group("fwk_group_work_scheduler_all") { "${worksched_frameworks_path}/extension:workschedextension", "${worksched_interfaces_path}/kits/cj:cj_work_scheduler_ffi", "${worksched_taihe_path}/work_scheduler:work_scheduler_taihe", - "${worksched_taihe_path}/work_scheduler_extension_ability:work_scheduler_extension_ability_taihe", - "${worksched_taihe_path}/work_scheduler_extension_context:work_scheduler_extension_context_taihe", "${worksched_interfaces_path}/kits/js:workscheduler", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension:workschedulerextensionability_napi", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension_context:workschedulerextensioncontext_napi", diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn deleted file mode 100644 index 62277c0..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn +++ /dev/null @@ -1,91 +0,0 @@ -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") - -copy_taihe_idl("copy_WorkSchedulerExtensionAbility") { - sources = [ "idl/ohos.WorkSchedulerExtensionAbility.taihe" ] - deps = [ - "../work_scheduler:copy_workScheduler", - "../work_scheduler_extension_context:copy_WorkSchedulerExtensionContext", - ] -} - -subsystem_name = "resourceschedule" -part_name = "work_scheduler" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" - -ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" - deps = [ ":copy_WorkSchedulerExtensionAbility" ] - outputs = [ - "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.ani.cpp", - "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.abi.c", - ] -} - -taihe_shared_library("work_scheduler_extension_ability_ani") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" - - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.WorkSchedulerExtensionAbility.impl.cpp", - ] - - deps = [ ":run_taihe" ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - ] -} - -generate_static_abc("work_scheduler_extension_ability_abc") { - base_url = "$taihe_generated_file_path" - files = - [ "$taihe_generated_file_path/@ohos.WorkSchedulerExtensionAbility.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/work_scheduler_extension_ability_abc.abc" - dependencies = [ ":run_taihe" ] -} - -ohos_prebuilt_etc("work_scheduler_extension_ability_etc") { - source = "$target_out_dir/work_scheduler_extension_ability_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":work_scheduler_extension_ability_abc" ] -} - -group("work_scheduler_extension_ability_taihe") { - deps = [ - ":work_scheduler_extension_ability_ani", - ":work_scheduler_extension_ability_etc", - ] -} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe deleted file mode 100644 index b8e8a54..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("@ohos.WorkSchedulerExtensionAbility") -@!sts_inject_into_module(" - import WorkSchedulerExtensionContext from 'application.WorkSchedulerExtensionContext'; -") -@!sts_inject(""" - loadLibrary("work_scheduler_extension_ability_ani.z"); -""") - -from ohos.resourceschedule.workScheduler use WorkInfo; - -@class -interface WorkSchedulerExtensionAbility { - @get getContext(): @sts_type("WorkSchedulerExtensionContext") Opaque; - @set setContext(param: @sts_type("WorkSchedulerExtensionContext") Opaque); - onWorkStart(work: WorkInfo): void; - onWorkStop(work: WorkInfo): void; -} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp deleted file mode 100644 index ce5fb13..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.WorkSchedulerExtensionAbility.ani.hpp" - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - return ANI_ERROR; - } - if (ANI_OK != ohos::WorkSchedulerExtensionAbility::ANIRegister(env)) { - std::cerr << "Error from ohos::WorkSchedulerExtensionAbility::ANI_Constructor" << std::endl; - return ANI_ERROR; - } - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp deleted file mode 100644 index 383d48e..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.WorkSchedulerExtensionAbility.proj.hpp" -#include "ohos.WorkSchedulerExtensionAbility.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -namespace { -// To be implemented. - -class WorkSchedulerExtensionAbilityImpl { -public: - WorkSchedulerExtensionAbilityImpl() - { - // Don't forget to implement the constructor. - } - - uintptr_t getContext() - { - TH_THROW(std::runtime_error, "getContext not implemented"); - } - - void setContext(uintptr_t param) - { - TH_THROW(std::runtime_error, "setContext not implemented"); - } - - void onWorkStart(::ohos::resourceschedule::workScheduler::WorkInfo const &work) - { - TH_THROW(std::runtime_error, "onWorkStart not implemented"); - } - - void onWorkStop(::ohos::resourceschedule::workScheduler::WorkInfo const &work) - { - TH_THROW(std::runtime_error, "onWorkStop not implemented"); - } -}; -} // namespace - -// Since these macros are auto-generate, lint will cause false positive. -// NOLINTBEGIN -// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn deleted file mode 100644 index 36735e2..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn +++ /dev/null @@ -1,87 +0,0 @@ -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") - -copy_taihe_idl("copy_WorkSchedulerExtensionContext") { - sources = [ "idl/WorkSchedulerExtensionContext.taihe" ] -} - -subsystem_name = "resourceschedule" -part_name = "work_scheduler" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" - -ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" - deps = [ ":copy_WorkSchedulerExtensionContext" ] - outputs = [ - "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.ani.cpp", - "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.abi.c", - ] -} - -taihe_shared_library("work_scheduler_extension_context_ani") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" - - sources = get_target_outputs(":run_taihe") - - sources += [ - "src/WorkSchedulerExtensionContext.impl.cpp", - "src/ani_constructor.cpp", - ] - - deps = [ ":run_taihe" ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - ] -} - -generate_static_abc("work_scheduler_extension_context_abc") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/WorkSchedulerExtensionContext.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/work_scheduler_extension_context_abc.abc" - dependencies = [ ":run_taihe" ] -} - -ohos_prebuilt_etc("work_scheduler_extension_context_etc") { - source = "$target_out_dir/work_scheduler_extension_context_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":work_scheduler_extension_context_abc" ] -} - -group("work_scheduler_extension_context_taihe") { - deps = [ - ":work_scheduler_extension_context_ani", - ":work_scheduler_extension_context_etc", - ] -} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe deleted file mode 100644 index d1bba2b..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("WorkSchedulerExtensionContext") -@!sts_inject_into_module(" - import type Want from '@ohos.app.ability.Want'; - import ExtensionContext from 'application.ExtensionContext'; -") -@!sts_inject(""" - { loadLibrary("work_scheduler_extension_context_ani.z"); } -""") - -@class -interface WorkSchedulerExtensionContext_inner { - @gen_promise("startServiceExtensionAbility") - StartServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; - @gen_promise("stopServiceExtensionAbility") - StopServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; -} - -function Create():WorkSchedulerExtensionContext_inner; - -@!sts_inject(""" -export class WorkSchedulerExtensionContext extends ExtensionContext { -inner: WorkSchedulerExtensionContext_inner; - -startServiceExtensionAbility(want: Want): Promise { - return this.inner.startServiceExtensionAbility(want); -} - -stopServiceExtensionAbility(want: Want): Promise { - return this.inner.stopServiceExtensionAbility(want); -} - -constructor() { - this.inner = create(); -} - -constructor(param: WorkSchedulerExtensionContext_inner) { - this.inner = param; -} -} -""") \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp deleted file mode 100644 index a32696d..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WorkSchedulerExtensionContext.proj.hpp" -#include "WorkSchedulerExtensionContext.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -namespace { -// To be implemented. -class WorkSchedulerExtensionContext_innerImpl { -public: - WorkSchedulerExtensionContext_innerImpl() - { - // Don't forget to implement the constructor. - } - - void StartServiceExtensionAbilitySync(uintptr_t want) - { - TH_THROW(std::runtime_error, "StartServiceExtensionAbilitySync not implemented"); - } - - void StopServiceExtensionAbilitySync(uintptr_t want) - { - TH_THROW(std::runtime_error, "StopServiceExtensionAbilitySync not implemented"); - } -}; - -::WorkSchedulerExtensionContext::WorkSchedulerExtensionContext_inner Create() -{ - // The parameters in the make_holder function should be of the same type - // as the parameters in the constructor of the actual implementation class. - return taihe::make_holder(); -} -} // namespace - -// Since these macros are auto-generate, lint will cause false positive. -// NOLINTBEGIN -TH_EXPORT_CPP_API_Create(Create); -// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp deleted file mode 100644 index b943ef5..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WorkSchedulerExtensionContext.ani.hpp" - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - return ANI_ERROR; - } - if (ANI_OK != WorkSchedulerExtensionContext::ANIRegister(env)) { - std::cerr << "Error from WorkSchedulerExtensionContext::ANI_Constructor" << std::endl; - return ANI_ERROR; - } - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file -- Gitee From a46831566fbf44ead955c085844bc7bc2a33be2c Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Sat, 28 Jun 2025 18:03:46 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- .../ets/taihe/work_scheduler/src/common.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp index 8dcba76..fb451c0 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp +++ b/interfaces/kits/ets/taihe/work_scheduler/src/common.cpp @@ -31,7 +31,7 @@ namespace WorkScheduler { const int32_t BATTERY_LEVEL_MIN = 0; const int32_t BATTERY_LEVEL_MAX = 100; const int32_t TRUE_PARAM = 1; - +const int32_t UNSET_INT_PARAM = -1; // need to be same as WantParams enum { VALUE_TYPE_NULL = -1, @@ -312,8 +312,7 @@ bool Common::ConvertToAniParameters(std::map workIn aniWork.networkType = optional(std::in_place, NetworkType::key_t(workInfo->GetNetworkType())); if (workInfo->GetChargerType() >= WorkCondition::Charger::CHARGING_UNPLUGGED) { aniWork.isCharging = optional(std::in_place, false); - aniWork.chargerType = optional(std::in_place, ChargingType::key_t(-1)); + aniWork.chargerType = optional(std::in_place, ChargingType::key_t(UNSET_INT_PARAM)); } else { aniWork.isCharging = optional(std::in_place, true); aniWork.chargerType = optional(std::in_place, ChargingType::key_t(workInfo->GetChargerType())); @@ -395,8 +391,8 @@ void Common::ParseWorkInfo(std::shared_ptr workIn 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.isDeepIdle = optional(std::in_place, -1); - aniWork.idleWaitTime = optional(std::in_place, -1); + aniWork.isDeepIdle = optional(std::in_place, UNSET_INT_PARAM); + aniWork.idleWaitTime = optional(std::in_place, UNSET_INT_PARAM); ParseExtrasInfo(workInfo, aniWork); } } // namespace WorkScheduler -- Gitee From 9ca101ba5fc683798df3539e3bb842be5e4b8677 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Sat, 28 Jun 2025 18:04:43 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- .../kits/ets/taihe/work_scheduler/src/ani_constructor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp index 1369df9..4b0880d 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp +++ b/interfaces/kits/ets/taihe/work_scheduler/src/ani_constructor.cpp @@ -22,7 +22,7 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) return ANI_ERROR; } if (ANI_OK != ohos::resourceschedule::workScheduler::ANIRegister(env)) { - std::cerr << "Error from ohos::resourceschedule::workScheduler::ANI_Constructor" << std::endl; + std::cerr << "Error from ohos::resourceschedule::workScheduler::ANIRegister" << std::endl; return ANI_ERROR; } *result = ANI_VERSION_1; -- Gitee From 02ad6a34553c0ee4cf867b025cb04d31fda4c7ca Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Mon, 30 Jun 2025 10:00:49 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- interfaces/kits/ets/taihe/work_scheduler/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn index f6c3415..9e6f6bf 100644 --- a/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn +++ b/interfaces/kits/ets/taihe/work_scheduler/BUILD.gn @@ -14,7 +14,7 @@ import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/resourceschedule/work_scheduler/workScheduler.gni") +import("//foundation/resourceschedule/work_scheduler/workscheduler.gni") copy_taihe_idl("copy_workScheduler") { sources = [ "idl/ohos.resourceschedule.workScheduler.taihe" ] -- Gitee From f80e5ed0021ddb6094aeca1cf8f5db6dd850c5cc Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Mon, 30 Jun 2025 11:28:49 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- .../work_scheduler_extension_ability/BUILD.gn | 91 +++++++++++++++++++ .../ohos.WorkSchedulerExtensionAbility.taihe | 32 +++++++ .../src/ani_constructor.cpp | 30 ++++++ ...hos.WorkSchedulerExtensionAbility.impl.cpp | 55 +++++++++++ .../work_scheduler_extension_context/BUILD.gn | 87 ++++++++++++++++++ .../idl/WorkSchedulerExtensionContext.taihe | 55 +++++++++++ .../WorkSchedulerExtensionContext.impl.cpp | 53 +++++++++++ .../src/ani_constructor.cpp | 30 ++++++ 8 files changed, 433 insertions(+) create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp create mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn new file mode 100644 index 0000000..e1c098e --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn @@ -0,0 +1,91 @@ +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/resourceschedule/work_scheduler/workscheduler.gni") + +copy_taihe_idl("copy_WorkSchedulerExtensionAbility") { + sources = [ "idl/ohos.WorkSchedulerExtensionAbility.taihe" ] + deps = [ + "../work_scheduler:copy_workScheduler", + "../work_scheduler_extension_context:copy_WorkSchedulerExtensionContext", + ] +} + +subsystem_name = "resourceschedule" +part_name = "work_scheduler" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_WorkSchedulerExtensionAbility" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.ani.cpp", + "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.abi.c", + ] +} + +taihe_shared_library("work_scheduler_extension_ability_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.WorkSchedulerExtensionAbility.impl.cpp", + ] + + deps = [ ":run_taihe" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +generate_static_abc("work_scheduler_extension_ability_abc") { + base_url = "$taihe_generated_file_path" + files = + [ "$taihe_generated_file_path/@ohos.WorkSchedulerExtensionAbility.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/work_scheduler_extension_ability_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("work_scheduler_extension_ability_etc") { + source = "$target_out_dir/work_scheduler_extension_ability_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":work_scheduler_extension_ability_abc" ] +} + +group("work_scheduler_extension_ability_taihe") { + deps = [ + ":work_scheduler_extension_ability_ani", + ":work_scheduler_extension_ability_etc", + ] +} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe new file mode 100644 index 0000000..b8e8a54 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe @@ -0,0 +1,32 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.WorkSchedulerExtensionAbility") +@!sts_inject_into_module(" + import WorkSchedulerExtensionContext from 'application.WorkSchedulerExtensionContext'; +") +@!sts_inject(""" + loadLibrary("work_scheduler_extension_ability_ani.z"); +""") + +from ohos.resourceschedule.workScheduler use WorkInfo; + +@class +interface WorkSchedulerExtensionAbility { + @get getContext(): @sts_type("WorkSchedulerExtensionContext") Opaque; + @set setContext(param: @sts_type("WorkSchedulerExtensionContext") Opaque); + onWorkStart(work: WorkInfo): void; + onWorkStop(work: WorkInfo): void; +} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp new file mode 100644 index 0000000..c32bb87 --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.WorkSchedulerExtensionAbility.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::WorkSchedulerExtensionAbility::ANIRegister(env)) { + std::cerr << "Error from ohos::WorkSchedulerExtensionAbility::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp new file mode 100644 index 0000000..383d48e --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp @@ -0,0 +1,55 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.WorkSchedulerExtensionAbility.proj.hpp" +#include "ohos.WorkSchedulerExtensionAbility.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace { +// To be implemented. + +class WorkSchedulerExtensionAbilityImpl { +public: + WorkSchedulerExtensionAbilityImpl() + { + // Don't forget to implement the constructor. + } + + uintptr_t getContext() + { + TH_THROW(std::runtime_error, "getContext not implemented"); + } + + void setContext(uintptr_t param) + { + TH_THROW(std::runtime_error, "setContext not implemented"); + } + + void onWorkStart(::ohos::resourceschedule::workScheduler::WorkInfo const &work) + { + TH_THROW(std::runtime_error, "onWorkStart not implemented"); + } + + void onWorkStop(::ohos::resourceschedule::workScheduler::WorkInfo const &work) + { + TH_THROW(std::runtime_error, "onWorkStop not implemented"); + } +}; +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn new file mode 100644 index 0000000..799893c --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn @@ -0,0 +1,87 @@ +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/resourceschedule/work_scheduler/workscheduler.gni") + +copy_taihe_idl("copy_WorkSchedulerExtensionContext") { + sources = [ "idl/WorkSchedulerExtensionContext.taihe" ] +} + +subsystem_name = "resourceschedule" +part_name = "work_scheduler" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_WorkSchedulerExtensionContext" ] + outputs = [ + "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.ani.cpp", + "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.abi.c", + ] +} + +taihe_shared_library("work_scheduler_extension_context_ani") { + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + + sources = get_target_outputs(":run_taihe") + + sources += [ + "src/WorkSchedulerExtensionContext.impl.cpp", + "src/ani_constructor.cpp", + ] + + deps = [ ":run_taihe" ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +generate_static_abc("work_scheduler_extension_context_abc") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/WorkSchedulerExtensionContext.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/work_scheduler_extension_context_abc.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("work_scheduler_extension_context_etc") { + source = "$target_out_dir/work_scheduler_extension_context_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":work_scheduler_extension_context_abc" ] +} + +group("work_scheduler_extension_context_taihe") { + deps = [ + ":work_scheduler_extension_context_ani", + ":work_scheduler_extension_context_etc", + ] +} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe new file mode 100644 index 0000000..d1bba2b --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe @@ -0,0 +1,55 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("WorkSchedulerExtensionContext") +@!sts_inject_into_module(" + import type Want from '@ohos.app.ability.Want'; + import ExtensionContext from 'application.ExtensionContext'; +") +@!sts_inject(""" + { loadLibrary("work_scheduler_extension_context_ani.z"); } +""") + +@class +interface WorkSchedulerExtensionContext_inner { + @gen_promise("startServiceExtensionAbility") + StartServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; + @gen_promise("stopServiceExtensionAbility") + StopServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; +} + +function Create():WorkSchedulerExtensionContext_inner; + +@!sts_inject(""" +export class WorkSchedulerExtensionContext extends ExtensionContext { +inner: WorkSchedulerExtensionContext_inner; + +startServiceExtensionAbility(want: Want): Promise { + return this.inner.startServiceExtensionAbility(want); +} + +stopServiceExtensionAbility(want: Want): Promise { + return this.inner.stopServiceExtensionAbility(want); +} + +constructor() { + this.inner = create(); +} + +constructor(param: WorkSchedulerExtensionContext_inner) { + this.inner = param; +} +} +""") \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp new file mode 100644 index 0000000..a32696d --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp @@ -0,0 +1,53 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WorkSchedulerExtensionContext.proj.hpp" +#include "WorkSchedulerExtensionContext.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace { +// To be implemented. +class WorkSchedulerExtensionContext_innerImpl { +public: + WorkSchedulerExtensionContext_innerImpl() + { + // Don't forget to implement the constructor. + } + + void StartServiceExtensionAbilitySync(uintptr_t want) + { + TH_THROW(std::runtime_error, "StartServiceExtensionAbilitySync not implemented"); + } + + void StopServiceExtensionAbilitySync(uintptr_t want) + { + TH_THROW(std::runtime_error, "StopServiceExtensionAbilitySync not implemented"); + } +}; + +::WorkSchedulerExtensionContext::WorkSchedulerExtensionContext_inner Create() +{ + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return taihe::make_holder(); +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_Create(Create); +// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp new file mode 100644 index 0000000..d4d278e --- /dev/null +++ b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp @@ -0,0 +1,30 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "WorkSchedulerExtensionContext.ani.hpp" + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != WorkSchedulerExtensionContext::ANIRegister(env)) { + std::cerr << "Error from WorkSchedulerExtensionContext::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file -- Gitee From 02ed22c01e36cc74157dd5da41866df8da440b96 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Mon, 30 Jun 2025 11:30:48 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index 01b4319..72cfb95 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -21,6 +21,8 @@ group("fwk_group_work_scheduler_all") { "${worksched_frameworks_path}/extension:workschedextension", "${worksched_interfaces_path}/kits/cj:cj_work_scheduler_ffi", "${worksched_taihe_path}/work_scheduler:work_scheduler_taihe", + "${worksched_taihe_path}/work_scheduler_extension_ability:work_scheduler_extension_ability_taihe", + "${worksched_taihe_path}/work_scheduler_extension_context:work_scheduler_extension_context_taihe", "${worksched_interfaces_path}/kits/js:workscheduler", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension:workschedulerextensionability_napi", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension_context:workschedulerextensioncontext_napi", -- Gitee From 44e08c2939fcd797ee79ab1a3ad88821154ed568 Mon Sep 17 00:00:00 2001 From: zhushuanghong Date: Mon, 30 Jun 2025 11:59:16 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=BB=B6=E6=97=B6=E4=BB=BB=E5=8A=A1ani?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhushuanghong --- BUILD.gn | 2 - .../work_scheduler_extension_ability/BUILD.gn | 91 ------------------- .../ohos.WorkSchedulerExtensionAbility.taihe | 32 ------- .../src/ani_constructor.cpp | 30 ------ ...hos.WorkSchedulerExtensionAbility.impl.cpp | 55 ----------- .../work_scheduler_extension_context/BUILD.gn | 87 ------------------ .../idl/WorkSchedulerExtensionContext.taihe | 55 ----------- .../WorkSchedulerExtensionContext.impl.cpp | 53 ----------- .../src/ani_constructor.cpp | 30 ------ 9 files changed, 435 deletions(-) delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp delete mode 100644 interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp diff --git a/BUILD.gn b/BUILD.gn index 72cfb95..01b4319 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -21,8 +21,6 @@ group("fwk_group_work_scheduler_all") { "${worksched_frameworks_path}/extension:workschedextension", "${worksched_interfaces_path}/kits/cj:cj_work_scheduler_ffi", "${worksched_taihe_path}/work_scheduler:work_scheduler_taihe", - "${worksched_taihe_path}/work_scheduler_extension_ability:work_scheduler_extension_ability_taihe", - "${worksched_taihe_path}/work_scheduler_extension_context:work_scheduler_extension_context_taihe", "${worksched_interfaces_path}/kits/js:workscheduler", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension:workschedulerextensionability_napi", "${worksched_interfaces_path}/kits/js/napi/work_scheduler_extension_context:workschedulerextensioncontext_napi", diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn deleted file mode 100644 index e1c098e..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/BUILD.gn +++ /dev/null @@ -1,91 +0,0 @@ -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/resourceschedule/work_scheduler/workscheduler.gni") - -copy_taihe_idl("copy_WorkSchedulerExtensionAbility") { - sources = [ "idl/ohos.WorkSchedulerExtensionAbility.taihe" ] - deps = [ - "../work_scheduler:copy_workScheduler", - "../work_scheduler_extension_context:copy_WorkSchedulerExtensionContext", - ] -} - -subsystem_name = "resourceschedule" -part_name = "work_scheduler" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" - -ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" - deps = [ ":copy_WorkSchedulerExtensionAbility" ] - outputs = [ - "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.ani.cpp", - "$taihe_generated_file_path/src/ohos.WorkSchedulerExtensionAbility.abi.c", - ] -} - -taihe_shared_library("work_scheduler_extension_ability_ani") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" - - sources = get_target_outputs(":run_taihe") - sources += [ - "src/ani_constructor.cpp", - "src/ohos.WorkSchedulerExtensionAbility.impl.cpp", - ] - - deps = [ ":run_taihe" ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - ] -} - -generate_static_abc("work_scheduler_extension_ability_abc") { - base_url = "$taihe_generated_file_path" - files = - [ "$taihe_generated_file_path/@ohos.WorkSchedulerExtensionAbility.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/work_scheduler_extension_ability_abc.abc" - dependencies = [ ":run_taihe" ] -} - -ohos_prebuilt_etc("work_scheduler_extension_ability_etc") { - source = "$target_out_dir/work_scheduler_extension_ability_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":work_scheduler_extension_ability_abc" ] -} - -group("work_scheduler_extension_ability_taihe") { - deps = [ - ":work_scheduler_extension_ability_ani", - ":work_scheduler_extension_ability_etc", - ] -} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe deleted file mode 100644 index b8e8a54..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/idl/ohos.WorkSchedulerExtensionAbility.taihe +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("@ohos.WorkSchedulerExtensionAbility") -@!sts_inject_into_module(" - import WorkSchedulerExtensionContext from 'application.WorkSchedulerExtensionContext'; -") -@!sts_inject(""" - loadLibrary("work_scheduler_extension_ability_ani.z"); -""") - -from ohos.resourceschedule.workScheduler use WorkInfo; - -@class -interface WorkSchedulerExtensionAbility { - @get getContext(): @sts_type("WorkSchedulerExtensionContext") Opaque; - @set setContext(param: @sts_type("WorkSchedulerExtensionContext") Opaque); - onWorkStart(work: WorkInfo): void; - onWorkStop(work: WorkInfo): void; -} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp deleted file mode 100644 index c32bb87..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ani_constructor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.WorkSchedulerExtensionAbility.ani.hpp" - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - return ANI_ERROR; - } - if (ANI_OK != ohos::WorkSchedulerExtensionAbility::ANIRegister(env)) { - std::cerr << "Error from ohos::WorkSchedulerExtensionAbility::ANIRegister" << std::endl; - return ANI_ERROR; - } - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp deleted file mode 100644 index 383d48e..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_ability/src/ohos.WorkSchedulerExtensionAbility.impl.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.WorkSchedulerExtensionAbility.proj.hpp" -#include "ohos.WorkSchedulerExtensionAbility.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -namespace { -// To be implemented. - -class WorkSchedulerExtensionAbilityImpl { -public: - WorkSchedulerExtensionAbilityImpl() - { - // Don't forget to implement the constructor. - } - - uintptr_t getContext() - { - TH_THROW(std::runtime_error, "getContext not implemented"); - } - - void setContext(uintptr_t param) - { - TH_THROW(std::runtime_error, "setContext not implemented"); - } - - void onWorkStart(::ohos::resourceschedule::workScheduler::WorkInfo const &work) - { - TH_THROW(std::runtime_error, "onWorkStart not implemented"); - } - - void onWorkStop(::ohos::resourceschedule::workScheduler::WorkInfo const &work) - { - TH_THROW(std::runtime_error, "onWorkStop not implemented"); - } -}; -} // namespace - -// Since these macros are auto-generate, lint will cause false positive. -// NOLINTBEGIN -// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn b/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn deleted file mode 100644 index 799893c..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/BUILD.gn +++ /dev/null @@ -1,87 +0,0 @@ -# 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. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/resourceschedule/work_scheduler/workscheduler.gni") - -copy_taihe_idl("copy_WorkSchedulerExtensionContext") { - sources = [ "idl/WorkSchedulerExtensionContext.taihe" ] -} - -subsystem_name = "resourceschedule" -part_name = "work_scheduler" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" - -ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" - deps = [ ":copy_WorkSchedulerExtensionContext" ] - outputs = [ - "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.ani.cpp", - "$taihe_generated_file_path/src/WorkSchedulerExtensionContext.abi.c", - ] -} - -taihe_shared_library("work_scheduler_extension_context_ani") { - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - - taihe_generated_file_path = "$taihe_generated_file_path" - subsystem_name = "$subsystem_name" - part_name = "$part_name" - - sources = get_target_outputs(":run_taihe") - - sources += [ - "src/WorkSchedulerExtensionContext.impl.cpp", - "src/ani_constructor.cpp", - ] - - deps = [ ":run_taihe" ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - ] -} - -generate_static_abc("work_scheduler_extension_context_abc") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/WorkSchedulerExtensionContext.ets" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/work_scheduler_extension_context_abc.abc" - dependencies = [ ":run_taihe" ] -} - -ohos_prebuilt_etc("work_scheduler_extension_context_etc") { - source = "$target_out_dir/work_scheduler_extension_context_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":work_scheduler_extension_context_abc" ] -} - -group("work_scheduler_extension_context_taihe") { - deps = [ - ":work_scheduler_extension_context_ani", - ":work_scheduler_extension_context_etc", - ] -} diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe b/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe deleted file mode 100644 index d1bba2b..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/idl/WorkSchedulerExtensionContext.taihe +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("WorkSchedulerExtensionContext") -@!sts_inject_into_module(" - import type Want from '@ohos.app.ability.Want'; - import ExtensionContext from 'application.ExtensionContext'; -") -@!sts_inject(""" - { loadLibrary("work_scheduler_extension_context_ani.z"); } -""") - -@class -interface WorkSchedulerExtensionContext_inner { - @gen_promise("startServiceExtensionAbility") - StartServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; - @gen_promise("stopServiceExtensionAbility") - StopServiceExtensionAbilitySync(want: @sts_type("Want") Opaque): void; -} - -function Create():WorkSchedulerExtensionContext_inner; - -@!sts_inject(""" -export class WorkSchedulerExtensionContext extends ExtensionContext { -inner: WorkSchedulerExtensionContext_inner; - -startServiceExtensionAbility(want: Want): Promise { - return this.inner.startServiceExtensionAbility(want); -} - -stopServiceExtensionAbility(want: Want): Promise { - return this.inner.stopServiceExtensionAbility(want); -} - -constructor() { - this.inner = create(); -} - -constructor(param: WorkSchedulerExtensionContext_inner) { - this.inner = param; -} -} -""") \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp deleted file mode 100644 index a32696d..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/WorkSchedulerExtensionContext.impl.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WorkSchedulerExtensionContext.proj.hpp" -#include "WorkSchedulerExtensionContext.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -namespace { -// To be implemented. -class WorkSchedulerExtensionContext_innerImpl { -public: - WorkSchedulerExtensionContext_innerImpl() - { - // Don't forget to implement the constructor. - } - - void StartServiceExtensionAbilitySync(uintptr_t want) - { - TH_THROW(std::runtime_error, "StartServiceExtensionAbilitySync not implemented"); - } - - void StopServiceExtensionAbilitySync(uintptr_t want) - { - TH_THROW(std::runtime_error, "StopServiceExtensionAbilitySync not implemented"); - } -}; - -::WorkSchedulerExtensionContext::WorkSchedulerExtensionContext_inner Create() -{ - // The parameters in the make_holder function should be of the same type - // as the parameters in the constructor of the actual implementation class. - return taihe::make_holder(); -} -} // namespace - -// Since these macros are auto-generate, lint will cause false positive. -// NOLINTBEGIN -TH_EXPORT_CPP_API_Create(Create); -// NOLINTEND \ No newline at end of file diff --git a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp b/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp deleted file mode 100644 index d4d278e..0000000 --- a/interfaces/kits/ets/taihe/work_scheduler_extension_context/src/ani_constructor.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WorkSchedulerExtensionContext.ani.hpp" - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - return ANI_ERROR; - } - if (ANI_OK != WorkSchedulerExtensionContext::ANIRegister(env)) { - std::cerr << "Error from WorkSchedulerExtensionContext::ANIRegister" << std::endl; - return ANI_ERROR; - } - *result = ANI_VERSION_1; - return ANI_OK; -} \ No newline at end of file -- Gitee