diff --git a/BUILD.gn b/BUILD.gn index d77eb00b46ea7be51e1880304711bb13cd887ed6..473ca595fd73fdbe6e8cbb6c367e28dec42d5adf 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 74433019dbd065ff61c2faca4df51814f04b56ba..8bb20df00efa94f938598d8c1337ca1936a3cf46 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 f4f87afae51cc695b604fc3f631caef562752547..6c25be5fd25209fbe6636dfc5e7b50b7828e0e07 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 435a7dcd09d0a4fb0332bc6c27955e3f2b307060..4315fe600877fd8ced910ab94a42dcd38aa886b6 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 7794a8f336a4e1362e6ec4235668d634877125b5..854bc43f6d4836717a357b77f62e8b86f5b384c6 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 ac0036282c3661c2420e81230faa0a7698219659..b4a75a590dd4d690118aa7c23e1a9009a696110b 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 0000000000000000000000000000000000000000..543e1bba6dc8e265c61fb3f5b94a71497b2bd114 --- /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 0000000000000000000000000000000000000000..4118a6476489e235fcc4826fa1f671ad88686834 --- /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 0000000000000000000000000000000000000000..a90c1c3863443f569185c05e6afbdf969a4e97bf --- /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 0000000000000000000000000000000000000000..e1f25df80cd06df681a1db8186d7d08caa700850 --- /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 bcca4938e2c6b31cb9cb8b746e2299eebdd298ec..0094822d76a4eb93a7709ac7bcce4a9e92e4d61a 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 5237ba1c4d788afec91a5e99594cc78ddf25fca9..fa60c6f39f69884621d2a13e04876e9d343f0b7b 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 2942276698d0904b386cebd7d8a3a06648028900..e9f349e52447692110bc1f01402f0d2b63e71468 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 8fd7ca1d6e3b68dd8fcbde90d1bad1d1c8e987f4..b685bfdf2dbff48faa45a3b99aded116701823fd 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"