From 48142abeb5b1ea7b19d7b9635569ba3a9a6507f2 Mon Sep 17 00:00:00 2001 From: cat Date: Sat, 12 Jul 2025 17:23:05 +0800 Subject: [PATCH] reset 0328 to 0702 Signed-off-by: cat --- BUILD.gn | 1 + interfaces/taihe/BUILD.gn | 2 + interfaces/taihe/deviceInfo/BUILD.gn | 10 +-- .../deviceInfo/idl/ohos.deviceInfo.taihe | 2 + .../taihe/deviceInfo/src/ani_constructor.cpp | 23 ++++--- .../deviceInfo/src/ohos.deviceInfo.impl.cpp | 13 +++- interfaces/taihe/syscap/BUILD.gn | 69 +++++++++++++++++++ interfaces/taihe/syscap/idl/global.taihe | 18 +++++ .../taihe/syscap/src/ani_constructor.cpp | 29 ++++++++ interfaces/taihe/syscap/src/global.impl.cpp | 36 ++++++++++ .../taihe/systemParameterEnhance/BUILD.gn | 18 ++--- ...aihe => ohos.systemParameterEnhance.taihe} | 2 +- .../src/ani_constructor.cpp | 8 +-- ...p => ohos.systemParameterEnhance.impl.cpp} | 4 +- 14 files changed, 202 insertions(+), 33 deletions(-) create mode 100644 interfaces/taihe/syscap/BUILD.gn create mode 100644 interfaces/taihe/syscap/idl/global.taihe create mode 100644 interfaces/taihe/syscap/src/ani_constructor.cpp create mode 100644 interfaces/taihe/syscap/src/global.impl.cpp rename interfaces/taihe/systemParameterEnhance/idl/{ohos.systemParameterEnhance.systemParameterEnhance.taihe => ohos.systemParameterEnhance.taihe} (92%) rename interfaces/taihe/systemParameterEnhance/src/{ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp => ohos.systemParameterEnhance.impl.cpp} (94%) diff --git a/BUILD.gn b/BUILD.gn index d77eb00b4..473ca595f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,6 +19,7 @@ group("init_fwk_group") { "device_info:device_info_group", "interfaces/innerkits:innergroup", "interfaces/kits:kitsgroup", + "interfaces/taihe:taihe_group", "services:startup_init", "services/begetctl:begetctl_cmd", "services/loopevent:loopeventgroup", diff --git a/interfaces/taihe/BUILD.gn b/interfaces/taihe/BUILD.gn index 74433019d..8bb20df00 100644 --- a/interfaces/taihe/BUILD.gn +++ b/interfaces/taihe/BUILD.gn @@ -17,6 +17,8 @@ group("taihe_group") { deps = [ "deviceInfo:deviceInfo_etc", "deviceInfo:deviceInfo_taihe_native", + "syscap:global_etc", + "syscap:global_taihe_native", "systemParameterEnhance:systemParamterEnhance_etc", "systemParameterEnhance:systemParameterEnhance_taihe_native", ] diff --git a/interfaces/taihe/deviceInfo/BUILD.gn b/interfaces/taihe/deviceInfo/BUILD.gn index f4f87afae..6c25be5fd 100644 --- a/interfaces/taihe/deviceInfo/BUILD.gn +++ b/interfaces/taihe/deviceInfo/BUILD.gn @@ -20,10 +20,10 @@ copy_taihe_idl("copy_deviceInfo") { } subsystem_name = "startup" part_name = "init" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" +taihe_generated_file_path_deviceInfo = "$taihe_file_path/out/$subsystem_name/$part_name/deviceInfo" ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" + taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}" deps = [ ":copy_deviceInfo" ] outputs = [ "$taihe_generated_file_path/src/ohos.deviceInfo.ani.cpp", @@ -37,7 +37,7 @@ taihe_shared_library("deviceInfo_taihe_native") { cfi_cross_dso = true debug = false } - taihe_generated_file_path = "$taihe_generated_file_path" + taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}" part_name = "$part_name" subsystem_name = "$subsystem_name" sources = get_target_outputs(":run_taihe") @@ -67,8 +67,8 @@ taihe_shared_library("deviceInfo_taihe_native") { } generate_static_abc("deviceInfo") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/@ohos.deviceInfo.ets" ] + base_url = "$taihe_generated_file_path_deviceInfo" + files = [ "$taihe_generated_file_path_deviceInfo/@ohos.deviceInfo.ets" ] is_boot_abc = "True" device_dst_file = "/system/framework/deviceInfo.abc" dependencies = [ ":run_taihe" ] diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index 435a7dcd0..4315fe600 100644 --- a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -79,6 +79,8 @@ function getdistributionOSVersion(): String; function getdistributionOSApiName(): String; @static("deviceInfo") @get function getdistributionOSReleaseType(): String; +@static("deviceInfo") @get +function getdiskSN(): String; @static("deviceInfo") @get function getsdkApiVersion(): i32; diff --git a/interfaces/taihe/deviceInfo/src/ani_constructor.cpp b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp index 7794a8f33..854bc43f6 100644 --- a/interfaces/taihe/deviceInfo/src/ani_constructor.cpp +++ b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp @@ -12,14 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -namespace systemParameterEnhance { - loadLibrary("systemparameterenhance_ani.z") - export native function getSync(key: string, def?: string): string; - export function get(key: string, def?: string): Promise { - return new Promise((resolve, reject) => { - resolve(getSync(key, def)); - }); +#include "ohos.deviceInfo.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; } -} -export default systemParameterEnhance; + if (ANI_OK != ohos::deviceInfo::ANIRegister(env)) { + std::cerr << "Error from ohos::deviceInfo::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index ac0036282..b4a75a590 100644 --- a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -40,8 +40,9 @@ #define DEVINFO_LOGW(fmt, ...) STARTUP_LOGW(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) #define DEVINFO_LOGE(fmt, ...) STARTUP_LOGE(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) -const int UDID_LEN = 65; -const int ODID_LEN = 37; +constexpr int UDID_LEN = 65; +constexpr int ODID_LEN = 37; +constexpr int DISK_SN_LEN = 20; typedef enum { DEV_INFO_OK, @@ -361,6 +362,13 @@ string getdistributionOSReleaseType() return value; } +string getdiskSN() +{ + static char value[DISK_SN_LEN] = {0}; + AclGetDiskSN(value, DISK_SN_LEN); + return value; +} + int32_t getsdkApiVersion() { int value = GetSdkApiVersion(); @@ -432,6 +440,7 @@ TH_EXPORT_CPP_API_getbuildRootHash(getbuildRootHash); TH_EXPORT_CPP_API_getdistributionOSName(getdistributionOSName); TH_EXPORT_CPP_API_getdistributionOSVersion(getdistributionOSVersion); TH_EXPORT_CPP_API_getdistributionOSApiName(getdistributionOSApiName); +TH_EXPORT_CPP_API_getdiskSN(getdiskSN); TH_EXPORT_CPP_API_getdistributionOSReleaseType(getdistributionOSReleaseType); TH_EXPORT_CPP_API_getsdkApiVersion(getsdkApiVersion); TH_EXPORT_CPP_API_getmajorVersion(getmajorVersion); diff --git a/interfaces/taihe/syscap/BUILD.gn b/interfaces/taihe/syscap/BUILD.gn new file mode 100644 index 000000000..543e1bba6 --- /dev/null +++ b/interfaces/taihe/syscap/BUILD.gn @@ -0,0 +1,69 @@ +# 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("//base/startup/init/begetd.gni") +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +copy_taihe_idl("copy_global") { + sources = [ "idl/global.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +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_global" ] + outputs = [ + "$taihe_generated_file_path/src/global.ani.cpp", + "$taihe_generated_file_path/src/global.abi.c", + ] +} + +taihe_shared_library("global_taihe_native") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + include_dirs = [ "//base/startup/init/interfaces/innerkits/include" ] + sources += [ + "src/ani_constructor.cpp", + "src/global.impl.cpp", + ] + deps = [ + ":run_taihe", + "${init_innerkits_path}:libbegetutil", + ] +} + +generate_static_abc("global") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/global.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/global.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("global_etc") { + source = "$target_out_dir/global.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":global" ] +} diff --git a/interfaces/taihe/syscap/idl/global.taihe b/interfaces/taihe/syscap/idl/global.taihe new file mode 100644 index 000000000..4118a6476 --- /dev/null +++ b/interfaces/taihe/syscap/idl/global.taihe @@ -0,0 +1,18 @@ +/* + * 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. + */ +@!sts_inject(""" +loadLibrary("global_taihe_native") +""") +function canIUse(syscap: String): bool; \ No newline at end of file diff --git a/interfaces/taihe/syscap/src/ani_constructor.cpp b/interfaces/taihe/syscap/src/ani_constructor.cpp new file mode 100644 index 000000000..a90c1c386 --- /dev/null +++ b/interfaces/taihe/syscap/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * 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 "taihe/runtime.hpp" +#include "global.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 != global::ANIRegister(env)) { + std::cerr << "Error from global::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/taihe/syscap/src/global.impl.cpp b/interfaces/taihe/syscap/src/global.impl.cpp new file mode 100644 index 000000000..e1f25df80 --- /dev/null +++ b/interfaces/taihe/syscap/src/global.impl.cpp @@ -0,0 +1,36 @@ +/* + * 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 "global.proj.hpp" +#include "global.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "systemcapability.h" +#include "beget_ext.h" + +using namespace taihe; +namespace { +// To be implemented. + +bool canIUse(string_view syscap) +{ + bool ret = HasSystemCapability(std::string(syscap).c_str()); + return ret; +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_canIUse(canIUse); +// NOLINTEND diff --git a/interfaces/taihe/systemParameterEnhance/BUILD.gn b/interfaces/taihe/systemParameterEnhance/BUILD.gn index bcca4938e..0094822d7 100644 --- a/interfaces/taihe/systemParameterEnhance/BUILD.gn +++ b/interfaces/taihe/systemParameterEnhance/BUILD.gn @@ -16,18 +16,18 @@ import("//build/ohos.gni") import("//build/ohos/taihe_idl/taihe.gni") copy_taihe_idl("copy_systemParamterEnhance") { - sources = [ "idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe" ] + sources = [ "idl/ohos.systemParameterEnhance.taihe" ] } subsystem_name = "startup" part_name = "init" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" +taihe_generated_file_path_systemParameterEnhance = "$taihe_file_path/out/$subsystem_name/$part_name/systemParameterEnhance" ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" + taihe_generated_file_path = "${taihe_generated_file_path_systemParameterEnhance}" deps = [ ":copy_systemParamterEnhance" ] outputs = [ - "$taihe_generated_file_path/src/ohos.systemParameterEnhance.systemParameterEnhance.ani.cpp", - "$taihe_generated_file_path/src/ohos.systemParameterEnhance.systemParameterEnhance.abi.c", + "$taihe_generated_file_path/src/ohos.systemParameterEnhance.ani.cpp", + "$taihe_generated_file_path/src/ohos.systemParameterEnhance.abi.c", ] } @@ -37,13 +37,13 @@ taihe_shared_library("systemParameterEnhance_taihe_native") { cfi_cross_dso = true debug = false } - taihe_generated_file_path = "$taihe_generated_file_path" + taihe_generated_file_path = "${taihe_generated_file_path_systemParameterEnhance}" part_name = "$part_name" subsystem_name = "$subsystem_name" sources = get_target_outputs(":run_taihe") sources += [ "src/ani_constructor.cpp", - "src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp", + "src/ohos.systemParameterEnhance.impl.cpp", ] deps = [ ":run_taihe", @@ -56,8 +56,8 @@ taihe_shared_library("systemParameterEnhance_taihe_native") { } generate_static_abc("systemParameterEnhance") { - base_url = "$taihe_generated_file_path" - files = [ "$taihe_generated_file_path/@ohos.systemParameterEnhance.systemParameterEnhance.ets" ] + base_url = "$taihe_generated_file_path_systemParameterEnhance" + files = [ "$taihe_generated_file_path_systemParameterEnhance/@ohos.systemParameterEnhance.ets" ] is_boot_abc = "True" device_dst_file = "/system/framework/systemParameterEnhance.abc" dependencies = [ ":run_taihe" ] diff --git a/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe similarity index 92% rename from interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe rename to interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe index 5237ba1c4..fa60c6f39 100644 --- a/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe +++ b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -@!namespace("@ohos.systemParameterEnhance.systemParameterEnhance", "systemParameterEnhance") +@!namespace("@ohos.systemParameterEnhance", "systemParameterEnhance") @!sts_inject(""" static { loadLibrary("systemParameterEnhance_taihe_native.z") } diff --git a/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp index 294227669..e9f349e52 100644 --- a/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp +++ b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp @@ -12,17 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ohos.systemParameterEnhance.systemParameterEnhance.ani.hpp" +#include "ohos.systemParameterEnhance.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::systemParameterEnhance::systemParameterEnhance::ANIRegister(env)) { - std::cerr << "Error from ohos::systemParameterEnhance::systemParameterEnhance::ANIRegister" << std::endl; + if (ANI_OK != ohos::systemParameterEnhance::ANIRegister(env)) { + std::cerr << "Error from ohos::systemParameterEnhance::ANIRegister" << std::endl; return ANI_ERROR; } *result = ANI_VERSION_1; return ANI_OK; -} +} \ No newline at end of file diff --git a/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp similarity index 94% rename from interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp rename to interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp index 8fd7ca1d6..b685bfdf2 100644 --- a/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp +++ b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ohos.systemParameterEnhance.systemParameterEnhance.proj.hpp" -#include "ohos.systemParameterEnhance.systemParameterEnhance.impl.hpp" +#include "ohos.systemParameterEnhance.proj.hpp" +#include "ohos.systemParameterEnhance.impl.hpp" #include "taihe/runtime.hpp" #include "stdexcept" -- Gitee