diff --git a/BUILD.gn b/BUILD.gn index f135b0e576cb6af0427fbfe00baf6c5b4eb22425..473ca595fd73fdbe6e8cbb6c367e28dec42d5adf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,9 +17,9 @@ group("init_fwk_group") { if (init_feature_group_type) { deps += [ "device_info:device_info_group", - "interfaces/ani:ani_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/ani/systemparameterenhance/src/systemparameter_ani.cpp b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp deleted file mode 100644 index db536d2079b9578aff7842f6cd937d62a29400b0..0000000000000000000000000000000000000000 --- a/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp +++ /dev/null @@ -1,85 +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 -#include -#include - -#include "beget_ext.h" -#include "parameters.h" - -#define PARAM_JS_DOMAIN (BASE_DOMAIN + 0xc) -#define PARAM_JS_LOGI(fmt, ...) STARTUP_LOGI(PARAM_JS_DOMAIN, "PARAM_JS", fmt, ##__VA_ARGS__) -#define PARAM_JS_LOGE(fmt, ...) STARTUP_LOGE(PARAM_JS_DOMAIN, "PARAM_JS", fmt, ##__VA_ARGS__) -#define PARAM_JS_LOGV(fmt, ...) STARTUP_LOGV(PARAM_JS_DOMAIN, "PARAM_JS", fmt, ##__VA_ARGS__) -#define PARAM_JS_LOGW(fmt, ...) STARTUP_LOGW(PARAM_JS_DOMAIN, "PARAM_JS", fmt, ##__VA_ARGS__) - -static std::string ani2std(ani_env *env, const ani_string str) -{ - ani_size strSize; - env->String_GetUTF8Size(str, &strSize); - - std::vector tmp_str(strSize + 1); - char *buffer = tmp_str.data(); - - ani_size str_bytes_written = 0; - env->String_GetUTF8(str, buffer, strSize + 1, &str_bytes_written); - - buffer[str_bytes_written] = '\0'; - return std::string(buffer); -} - -static ani_string getSync([[maybe_unused]] ani_env *env, ani_string param, ani_string def) -{ - std::string key = ani2std(env, param); - std::string defValue = ""; - if (def != nullptr) { - defValue = ani2std(env, def); - } - std::string value = OHOS::system::GetParameter(key, defValue); - ani_string ret; - env->String_NewUTF8(value.c_str(), value.size(), &ret); - return ret; -} - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - PARAM_JS_LOGI("Enter systemparameter ANI_Constructor"); - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - PARAM_JS_LOGE("Unsupported ANI_VERSION_1"); - return ANI_ERROR; - } - - ani_namespace ns; - static const char *namespaceName = "L@ohos/systemParameterEnhance/systemParameterEnhance;"; - if (ANI_OK != env->FindNamespace(namespaceName, &ns)) { - PARAM_JS_LOGE("not found namespace %s", namespaceName); - return ANI_ERROR; - } - - std::array methods = { - ani_native_function {"getSync", "Lstd/core/String;Lstd/core/String;:Lstd/core/String;", - reinterpret_cast(getSync)}, - }; - - if (ANI_OK != env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size())) { - PARAM_JS_LOGE("Cannot bind native methods to %s", namespaceName); - return ANI_ERROR; - }; - - *result = ANI_VERSION_1; - return ANI_OK; -} diff --git a/interfaces/ani/BUILD.gn b/interfaces/taihe/BUILD.gn similarity index 64% rename from interfaces/ani/BUILD.gn rename to interfaces/taihe/BUILD.gn index 49e5c0fb2754bf2d625a959a0ee9a1345ee30165..8bb20df00efa94f938598d8c1337ca1936a3cf46 100644 --- a/interfaces/ani/BUILD.gn +++ b/interfaces/taihe/BUILD.gn @@ -3,23 +3,24 @@ # 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 +# 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/ohos.gni") -group("ani_group") { +group("taihe_group") { if (!defined(ohos_lite)) { deps = [ - "deviceinfo:deviceinfo_ani", - "deviceinfo:deviceinfo_etc", - "systemparameterenhance:systemparameterenhance_ani", - "systemparameterenhance:systemparameterenhance_etc", + "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/ani/deviceinfo/BUILD.gn b/interfaces/taihe/deviceInfo/BUILD.gn similarity index 50% rename from interfaces/ani/deviceinfo/BUILD.gn rename to interfaces/taihe/deviceInfo/BUILD.gn index 6c741b441f2010f6118d1cb1900227257de97de0..6c25be5fd25209fbe6636dfc5e7b50b7828e0e07 100644 --- a/interfaces/ani/deviceinfo/BUILD.gn +++ b/interfaces/taihe/deviceInfo/BUILD.gn @@ -3,26 +3,50 @@ # 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 +# 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_deviceInfo") { + sources = [ "idl/ohos.deviceInfo.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +taihe_generated_file_path_deviceInfo = "$taihe_file_path/out/$subsystem_name/$part_name/deviceInfo" -ohos_shared_library("deviceinfo_ani") { +ohos_taihe("run_taihe") { + taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}" + deps = [ ":copy_deviceInfo" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.deviceInfo.ani.cpp", + "$taihe_generated_file_path/src/ohos.deviceInfo.abi.c", + ] +} + +taihe_shared_library("deviceInfo_taihe_native") { sanitize = { cfi = true cfi_cross_dso = true debug = false } - sources = [ "./src/deviceinfo_ani.cpp" ] + taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + sources += [ + "src/ani_constructor.cpp", + "src/ohos.deviceInfo.impl.cpp", + ] deps = [ + ":run_taihe", "${init_innerkits_path}:libbeget_proxy", "${init_innerkits_path}:libbegetutil", ] @@ -40,21 +64,20 @@ ohos_shared_library("deviceinfo_ani") { external_deps += [ "bundle_framework:appexecfwk_base" ] defines = [ "DEPENDENT_APPEXECFWK_BASE" ] } - part_name = "init" - subsystem_name = "startup" } -generate_static_abc("deviceinfo") { - base_url = "./ets" - files = [ "./ets/@ohos.deviceInfo.ets" ] +generate_static_abc("deviceInfo") { + 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" + device_dst_file = "/system/framework/deviceInfo.abc" + dependencies = [ ":run_taihe" ] } -ohos_prebuilt_etc("deviceinfo_etc") { - source = "$target_out_dir/deviceinfo.abc" +ohos_prebuilt_etc("deviceInfo_etc") { + source = "$target_out_dir/deviceInfo.abc" module_install_dir = "framework" - subsystem_name = "startup" - part_name = "init" - deps = [ ":deviceinfo" ] + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":deviceInfo" ] } diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe new file mode 100644 index 0000000000000000000000000000000000000000..4315fe600877fd8ced910ab94a42dcd38aa886b6 --- /dev/null +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -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. + */ +@!namespace("@ohos.deviceInfo") + +@!sts_inject(""" +loadLibrary("deviceInfo_taihe_native.z") +""") + +@class +interface deviceInfo { +} +@static("deviceInfo") @get +function getbrand(): String; +@static("deviceInfo") @get +function getdeviceType(): String; +@static("deviceInfo") @get +function getproductSeries(): String; +@static("deviceInfo") @get +function getproductModel(): String; +@static("deviceInfo") @get("ODID") +function getODID(): String; +@static("deviceInfo") @get +function getudid(): String; +@static("deviceInfo") @get +function getserial(): String; +@static("deviceInfo") @get +function getmanufacture(): String; +@static("deviceInfo") @get +function getmarketName(): String; +@static("deviceInfo") @get +function getproductModelAlias(): String; +@static("deviceInfo") @get +function getsoftwareModel(): String; +@static("deviceInfo") @get +function gethardwareModel(): String; +@static("deviceInfo") @get +function getbootloaderVersion(): String; +@static("deviceInfo") @get +function getabiList(): String; +@static("deviceInfo") @get +function getsecurityPatchTag(): String; +@static("deviceInfo") @get +function getdisplayVersion(): String; +@static("deviceInfo") @get +function getincrementalVersion(): String; +@static("deviceInfo") @get +function getosReleaseType(): String; +@static("deviceInfo") @get +function getosFullName(): String; +@static("deviceInfo") @get +function getversionId(): String; +@static("deviceInfo") @get +function getbuildType(): String; +@static("deviceInfo") @get +function getbuildUser(): String; +@static("deviceInfo") @get +function getbuildHost(): String; +@static("deviceInfo") @get +function getbuildTime(): String; +@static("deviceInfo") @get +function getbuildRootHash(): String; +@static("deviceInfo") @get +function getdistributionOSName(): String; +@static("deviceInfo") @get +function getdistributionOSVersion(): String; +@static("deviceInfo") @get +function getdistributionOSApiName(): String; +@static("deviceInfo") @get +function getdistributionOSReleaseType(): String; +@static("deviceInfo") @get +function getdiskSN(): String; + +@static("deviceInfo") @get +function getsdkApiVersion(): i32; +@static("deviceInfo") @get +function getmajorVersion(): i32; +@static("deviceInfo") @get +function getseniorVersion(): i32; +@static("deviceInfo") @get +function getfeatureVersion(): i32; +@static("deviceInfo") @get +function getbuildVersion(): i32; +@static("deviceInfo") @get +function getfirstApiVersion(): i32; +@static("deviceInfo") @get +function getdistributionOSApiVersion(): i32; \ No newline at end of file diff --git a/interfaces/taihe/deviceInfo/src/ani_constructor.cpp b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d44aac15ddebe14ae2b193eaf1b80622864fae0 --- /dev/null +++ b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp @@ -0,0 +1,28 @@ +/* + * 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.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; + } + 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; +} diff --git a/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp similarity index 30% rename from interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp rename to interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index 1f890439f39165de99b0e256b066e0cfc22880fe..b4a75a590dd4d690118aa7c23e1a9009a696110b 100644 --- a/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include -#include -#include +#include "ohos.deviceInfo.proj.hpp" +#include "ohos.deviceInfo.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" #include "beget_ext.h" #include "parameter.h" +#include "sysversion.h" #include "bundlemgr/bundle_mgr_proxy.h" #include "iservice_registry.h" #include "if_system_ability_manager.h" @@ -39,7 +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__) +constexpr int UDID_LEN = 65; constexpr int ODID_LEN = 37; +constexpr int DISK_SN_LEN = 20; typedef enum { DEV_INFO_OK, @@ -48,48 +51,53 @@ typedef enum { DEV_INFO_ESTRCOPY } DevInfoError; -static ani_string getBrand([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +using namespace taihe; +// using namespace ohos::deviceInfo; + +namespace { +// To be implemented. + +class deviceInfoImpl { +public: + deviceInfoImpl() { + // Don't forget to implement the constructor. + } +}; + +string getbrand() { - ani_string brand = nullptr; const char *value = GetBrand(); if (value == nullptr) { value = ""; } - env->String_NewUTF8(value, strlen(value), &brand); - return brand; + return value; } -static ani_string getDeviceType([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +string getdeviceType() { - ani_string devicetype = nullptr; const char *value = GetDeviceType(); if (value == nullptr) { value = ""; } - env->String_NewUTF8(value, strlen(value), &devicetype); - return devicetype; + return value; } -static ani_string getProductSeries([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +string getproductSeries() { - ani_string productSeries = nullptr; const char *value = GetProductSeries(); if (value == nullptr) { value = ""; } - env->String_NewUTF8(value, strlen(value), &productSeries); - return productSeries; + return value; } -static ani_string getProductModel([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +string getproductModel() { - ani_string productModel = nullptr; const char *value = GetProductModel(); if (value == nullptr) { value = ""; } - env->String_NewUTF8(value, strlen(value), &productModel); - return productModel; + return value; } static DevInfoError AclGetDevOdid(char *odid, int size) @@ -130,53 +138,314 @@ static DevInfoError AclGetDevOdid(char *odid, int size) return ret; } -static ani_string getOdid([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +string getODID() { - ani_string odid = nullptr; - static char devOdid[ODID_LEN] = {0}; - int ret = AclGetDevOdid(devOdid, ODID_LEN); - if (ret != 0) { + static char value[ODID_LEN] = {0}; + DevInfoError ret = AclGetDevOdid(value, ODID_LEN); + if (ret != DEV_INFO_OK) { DEVINFO_LOGE("GetDevOdid ret:%d", ret); } - env->String_NewUTF8(devOdid, strlen(devOdid), &odid); - return odid; + return value; +} + +string getudid() +{ + char value[UDID_LEN] = {0}; + AclGetDevUdid(value, UDID_LEN); + return value; +} + +string getserial() +{ + const char *value = AclGetSerial(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getmanufacture() +{ + const char *value = GetManufacture(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getmarketName() +{ + const char *value = GetMarketName(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getproductModelAlias() +{ + const char *value = GetProductModelAlias(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getsoftwareModel() +{ + const char *value = GetSoftwareModel(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string gethardwareModel() +{ + const char *value = GetHardwareModel(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbootloaderVersion() +{ + const char *value = GetBootloaderVersion(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getabiList() +{ + const char *value = GetAbiList(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getsecurityPatchTag() +{ + const char *value = GetSecurityPatchTag(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getdisplayVersion() +{ + const char *value = GetDisplayVersion(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getincrementalVersion() +{ + const char *value = GetIncrementalVersion(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getosReleaseType() +{ + const char *value = GetOsReleaseType(); + if (value == nullptr) { + value = ""; + } + return value; } -static ani_int getSdkApiVersion([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +string getosFullName() { - int sdkApiVersion = GetSdkApiVersion(); - return sdkApiVersion; + const char *value = GetOSFullName(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getversionId() +{ + const char *value = GetVersionId(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbuildType() +{ + const char *value = GetBuildType(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbuildUser() +{ + const char *value = GetBuildUser(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbuildHost() +{ + const char *value = GetBuildHost(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbuildTime() +{ + const char *value = GetBuildTime(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getbuildRootHash() +{ + const char *value = GetBuildRootHash(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getdistributionOSName() +{ + const char *value = GetDistributionOSName(); + if (value == nullptr) { + value = ""; + } + return value; +} + +string getdistributionOSVersion() +{ + const char *value = GetDistributionOSVersion(); + if (value == nullptr) { + value = ""; + } + return value; } -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +string getdistributionOSApiName() { - DEVINFO_LOGI("Enter deviceinfo ANI_Constructor"); - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - DEVINFO_LOGE("Unsupported ANI_VERSION_1"); - return ANI_ERROR; + const char *value = GetDistributionOSApiName(); + if (value == nullptr) { + value = ""; } - ani_class ns; - static const char *className = "L@ohos/deviceInfo/deviceInfo;"; - if (ANI_OK != env->FindClass(className, &ns)) { - DEVINFO_LOGE("not found class"); - return ANI_ERROR; + return value; +} + +string getdistributionOSReleaseType() +{ + const char *value = GetDistributionOSReleaseType(); + if (value == nullptr) { + value = ""; } + return value; +} + +string getdiskSN() +{ + static char value[DISK_SN_LEN] = {0}; + AclGetDiskSN(value, DISK_SN_LEN); + return value; +} + +int32_t getsdkApiVersion() +{ + int value = GetSdkApiVersion(); + return value; +} + +int32_t getmajorVersion() +{ + int value = GetMajorVersion(); + return value; +} + +int32_t getseniorVersion() +{ + int value = GetSeniorVersion(); + return value; +} - std::array methods = { - ani_native_function {"GetBrand", ":Lstd/core/String;", reinterpret_cast(getBrand)}, - ani_native_function {"GetDeviceType", ":Lstd/core/String;", reinterpret_cast(getDeviceType)}, - ani_native_function {"GetProductSeries", ":Lstd/core/String;", reinterpret_cast(getProductSeries)}, - ani_native_function {"GetProductModel", ":Lstd/core/String;", reinterpret_cast(getProductModel)}, - ani_native_function {"GetOdid", ":Lstd/core/String;", reinterpret_cast(getOdid)}, - ani_native_function {"GetSdkApiVersion", ":I", reinterpret_cast(getSdkApiVersion)}, - }; +int32_t getfeatureVersion() +{ + int value = GetFeatureVersion(); + return value; +} + +int32_t getbuildVersion() +{ + int value = GetBuildVersion(); + return value; +} - if (ANI_OK != env->Class_BindNativeMethods(ns, methods.data(), methods.size())) { - DEVINFO_LOGE("Cannot bind native methods to %s", className); - return ANI_ERROR; - }; +int32_t getfirstApiVersion() +{ + int value = GetFirstApiVersion(); + return value; +} - *result = ANI_VERSION_1; - return ANI_OK; +int32_t getdistributionOSApiVersion() +{ + int value = GetDistributionOSApiVersion(); + return value; } +} // namespace + +TH_EXPORT_CPP_API_getbrand(getbrand); +TH_EXPORT_CPP_API_getdeviceType(getdeviceType); +TH_EXPORT_CPP_API_getproductSeries(getproductSeries); +TH_EXPORT_CPP_API_getproductModel(getproductModel); +TH_EXPORT_CPP_API_getODID(getODID); +TH_EXPORT_CPP_API_getudid(getudid); +TH_EXPORT_CPP_API_getserial(getserial); +TH_EXPORT_CPP_API_getmanufacture(getmanufacture); +TH_EXPORT_CPP_API_getmarketName(getmarketName); +TH_EXPORT_CPP_API_getproductModelAlias(getproductModelAlias); +TH_EXPORT_CPP_API_getsoftwareModel(getsoftwareModel); +TH_EXPORT_CPP_API_gethardwareModel(gethardwareModel); +TH_EXPORT_CPP_API_getbootloaderVersion(getbootloaderVersion); +TH_EXPORT_CPP_API_getabiList(getabiList); +TH_EXPORT_CPP_API_getsecurityPatchTag(getsecurityPatchTag); +TH_EXPORT_CPP_API_getdisplayVersion(getdisplayVersion); +TH_EXPORT_CPP_API_getincrementalVersion(getincrementalVersion); +TH_EXPORT_CPP_API_getosReleaseType(getosReleaseType); +TH_EXPORT_CPP_API_getosFullName(getosFullName); +TH_EXPORT_CPP_API_getversionId(getversionId); +TH_EXPORT_CPP_API_getbuildType(getbuildType); +TH_EXPORT_CPP_API_getbuildUser(getbuildUser); +TH_EXPORT_CPP_API_getbuildHost(getbuildHost); +TH_EXPORT_CPP_API_getbuildTime(getbuildTime); +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); +TH_EXPORT_CPP_API_getseniorVersion(getseniorVersion); +TH_EXPORT_CPP_API_getfeatureVersion(getfeatureVersion); +TH_EXPORT_CPP_API_getbuildVersion(getbuildVersion); +TH_EXPORT_CPP_API_getfirstApiVersion(getfirstApiVersion); +TH_EXPORT_CPP_API_getdistributionOSApiVersion(getdistributionOSApiVersion); diff --git a/interfaces/ani/systemparameterenhance/BUILD.gn b/interfaces/taihe/syscap/BUILD.gn similarity index 40% rename from interfaces/ani/systemparameterenhance/BUILD.gn rename to interfaces/taihe/syscap/BUILD.gn index a2591932920e0063213c49819d6bd37e8f46f578..543e1bba6dc8e265c61fb3f5b94a71497b2bd114 100644 --- a/interfaces/ani/systemparameterenhance/BUILD.gn +++ b/interfaces/taihe/syscap/BUILD.gn @@ -3,48 +3,67 @@ # 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 +# 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", + ] +} -ohos_shared_library("systemparameterenhance_ani") { +taihe_shared_library("global_taihe_native") { sanitize = { cfi = true cfi_cross_dso = true debug = false } - sources = [ "./src/systemparameter_ani.cpp" ] + 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 = [ - "${init_innerkits_path}:libbeget_proxy", + ":run_taihe", "${init_innerkits_path}:libbegetutil", ] - external_deps = [ - "bounds_checking_function:libsec_shared", - "runtime_core:ani", - ] - part_name = "init" - subsystem_name = "startup" } -generate_static_abc("systemparameterenhance") { - base_url = "./ets" - files = [ "./ets/@ohos.systemParameterEnhance.ets" ] +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/systemparameterenhance.abc" + device_dst_file = "/system/framework/global.abc" + dependencies = [ ":run_taihe" ] } -ohos_prebuilt_etc("systemparameterenhance_etc") { - source = "$target_out_dir/systemparameterenhance.abc" +ohos_prebuilt_etc("global_etc") { + source = "$target_out_dir/global.abc" module_install_dir = "framework" - subsystem_name = "startup" - part_name = "init" - deps = [ ":systemparameterenhance" ] + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":global" ] } diff --git a/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets b/interfaces/taihe/syscap/idl/global.taihe similarity index 61% rename from interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets rename to interfaces/taihe/syscap/idl/global.taihe index 7794a8f336a4e1362e6ec4235668d634877125b5..4118a6476489e235fcc4826fa1f671ad88686834 100644 --- a/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets +++ b/interfaces/taihe/syscap/idl/global.taihe @@ -12,14 +12,7 @@ * 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)); - }); - } -} -export default systemParameterEnhance; +@!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/ani/deviceinfo/ets/@ohos.deviceInfo.ets b/interfaces/taihe/syscap/src/global.impl.cpp similarity index 38% rename from interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets rename to interfaces/taihe/syscap/src/global.impl.cpp index 6428c9462c6d2fc1ec13040483a7f69c8f601254..e1f25df80cd06df681a1db8186d7d08caa700850 100644 --- a/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets +++ b/interfaces/taihe/syscap/src/global.impl.cpp @@ -12,41 +12,25 @@ * 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" -class deviceInfo { - static {loadLibrary("deviceinfo_ani.z")} - readonly brand: string = ""; - readonly deviceType: string = ""; - readonly productSeries: string = ""; - readonly productModel: string = ""; - readonly ODID: string = ""; +using namespace taihe; +namespace { +// To be implemented. - readonly sdkApiVersion: int; - - static get brand():string { - return deviceInfo.GetBrand(); - } - static get deviceType():string { - return deviceInfo.GetDeviceType(); - } - static get productSeries():string { - return deviceInfo.GetProductSeries(); - } - static get productModel():string { - return deviceInfo.GetProductModel(); - } - static get ODID():string { - return deviceInfo.GetOdid(); - } - static get sdkApiVersion():int { - return deviceInfo.GetSdkApiVersion(); - } - - static native GetBrand(): string; - static native GetDeviceType(): string; - static native GetProductSeries(): string; - static native GetProductModel(): string; - static native GetOdid(): string; - static native GetSdkApiVersion(): int; +bool canIUse(string_view syscap) +{ + bool ret = HasSystemCapability(std::string(syscap).c_str()); + return ret; } -export default deviceInfo; +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..0094822d76a4eb93a7709ac7bcce4a9e92e4d61a --- /dev/null +++ b/interfaces/taihe/systemParameterEnhance/BUILD.gn @@ -0,0 +1,72 @@ +# 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_systemParamterEnhance") { + sources = [ "idl/ohos.systemParameterEnhance.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +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_systemParameterEnhance}" + deps = [ ":copy_systemParamterEnhance" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.systemParameterEnhance.ani.cpp", + "$taihe_generated_file_path/src/ohos.systemParameterEnhance.abi.c", + ] +} + +taihe_shared_library("systemParameterEnhance_taihe_native") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + 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.impl.cpp", + ] + deps = [ + ":run_taihe", + "${init_innerkits_path}:libbeget_proxy", + "${init_innerkits_path}:libbegetutil", + ] + external_deps = [ + "bounds_checking_function:libsec_shared", + ] +} + +generate_static_abc("systemParameterEnhance") { + 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" ] +} + +ohos_prebuilt_etc("systemParamterEnhance_etc") { + source = "$target_out_dir/systemParameterEnhance.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":systemParameterEnhance" ] +} diff --git a/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe new file mode 100644 index 0000000000000000000000000000000000000000..fa60c6f39f69884621d2a13e04876e9d343f0b7b --- /dev/null +++ b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe @@ -0,0 +1,35 @@ +/* + * 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.systemParameterEnhance", "systemParameterEnhance") + +@!sts_inject(""" +static { loadLibrary("systemParameterEnhance_taihe_native.z") } +""") + +function getSync(key: String, def: Optional): String; + +@gen_async("get") +@gen_promise("get") +function getParam(key: String, def: Optional): String; + +@gen_async("get") +function getParamNodef(key: String): String; + +function setSync(key: String, value: String): void; + +@gen_async("set") +@gen_promise("set") +function setParam(key: String, value: String): void; + diff --git a/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f20e14f07dd70071a1e65d5db2aa7aa70fa958ef --- /dev/null +++ b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp @@ -0,0 +1,28 @@ +/* + * 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.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::ANIRegister(env)) { + std::cerr << "Error from ohos::systemParameterEnhance::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b685bfdf2dbff48faa45a3b99aded116701823fd --- /dev/null +++ b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp @@ -0,0 +1,90 @@ +/* + * 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.systemParameterEnhance.proj.hpp" +#include "ohos.systemParameterEnhance.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "beget_ext.h" +#include "parameter.h" +#include "sysparam_errno.h" + +static constexpr int MAX_VALUE_LENGTH = PARAM_CONST_VALUE_LEN_MAX; + +using namespace taihe; +// using namespace ohos::systemParameterEnhance::systemParameterEnhance; + +namespace { +// To be implemented. +string GetParam(std::string key, std::string def) +{ + if (key.empty()) { + taihe::set_business_error(SYSPARAM_INVALID_INPUT, "input is invalid"); + } + char value[MAX_VALUE_LENGTH] = {0}; + int result = GetParameter(key.c_str(), def.c_str(), value, MAX_VALUE_LENGTH); + if (result < 0) { + taihe::set_business_error(result, "getSync failed"); + } + return value; +} + +string getSync(string_view key, optional_view def) +{ + string defValue = def.value_or(""); + return GetParam(std::string(key), std::string(defValue)); +} + +string getParam(string_view key, optional_view def) +{ + string defValue = def.value_or(""); + return GetParam(std::string(key), std::string(defValue)); +} + +string getParamNodef(string_view key) +{ + return GetParam(std::string(key), nullptr); +} + +void SetParam(std::string key, std::string value) +{ + if (key.empty() || value.empty()) { + taihe::set_business_error(SYSPARAM_INVALID_INPUT, "input is invalid"); + } + if (value.size() >= MAX_VALUE_LENGTH) { + taihe::set_business_error(SYSPARAM_INVALID_VALUE, "input value is invalid"); + } + int result = SetParameter(key.c_str(), value.c_str()); + if (result < 0) { + taihe::set_business_error(result, "set failed"); + } + return; +} +void setSync(string_view key, string_view value) +{ + SetParam(std::string(key), std::string(value)); +} + +void setParam(string_view key, string_view value) +{ + SetParam(std::string(key), std::string(value)); +} +} // namespace + +TH_EXPORT_CPP_API_getSync(getSync); +TH_EXPORT_CPP_API_getParam(getParam); +TH_EXPORT_CPP_API_getParamNodef(getParamNodef); +TH_EXPORT_CPP_API_setSync(setSync); +TH_EXPORT_CPP_API_setParam(setParam);