From 2988be92acbc13e4bbd4b6ab9838cf1e26b77a85 Mon Sep 17 00:00:00 2001 From: cat Date: Mon, 31 Mar 2025 10:57:07 +0800 Subject: [PATCH 1/7] add ani code Signed-off-by: cat --- BUILD.gn | 1 + bundle.json | 1 + interfaces/ani/BUILD.gn | 25 +++ interfaces/ani/deviceinfo/BUILD.gn | 60 ++++++ .../ani/deviceinfo/ets/@ohos.deviceInfo.ets | 52 +++++ .../ani/deviceinfo/src/deviceinfo_ani.cpp | 182 ++++++++++++++++++ .../ani/systemparameterenhance/BUILD.gn | 50 +++++ .../ets/@ohos.systemParameterEnhance.ets | 25 +++ .../src/systemparameter_ani.cpp | 86 +++++++++ 9 files changed, 482 insertions(+) create mode 100644 interfaces/ani/BUILD.gn create mode 100644 interfaces/ani/deviceinfo/BUILD.gn create mode 100644 interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets create mode 100644 interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp create mode 100644 interfaces/ani/systemparameterenhance/BUILD.gn create mode 100644 interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets create mode 100644 interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp diff --git a/BUILD.gn b/BUILD.gn index d77eb00b4..f135b0e57 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,6 +17,7 @@ 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", "services:startup_init", diff --git a/bundle.json b/bundle.json index d5c3b8a3e..725086788 100755 --- a/bundle.json +++ b/bundle.json @@ -65,6 +65,7 @@ "hiprofiler", "bounds_checking_function", "bundle_framework", + "runtime_core", "selinux", "selinux_adapter", "storage_service", diff --git a/interfaces/ani/BUILD.gn b/interfaces/ani/BUILD.gn new file mode 100644 index 000000000..49e5c0fb2 --- /dev/null +++ b/interfaces/ani/BUILD.gn @@ -0,0 +1,25 @@ +# 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/ohos.gni") + +group("ani_group") { + if (!defined(ohos_lite)) { + deps = [ + "deviceinfo:deviceinfo_ani", + "deviceinfo:deviceinfo_etc", + "systemparameterenhance:systemparameterenhance_ani", + "systemparameterenhance:systemparameterenhance_etc", + ] + } +} diff --git a/interfaces/ani/deviceinfo/BUILD.gn b/interfaces/ani/deviceinfo/BUILD.gn new file mode 100644 index 000000000..6c741b441 --- /dev/null +++ b/interfaces/ani/deviceinfo/BUILD.gn @@ -0,0 +1,60 @@ +# 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") + +ohos_shared_library("deviceinfo_ani") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "./src/deviceinfo_ani.cpp" ] + deps = [ + "${init_innerkits_path}:libbeget_proxy", + "${init_innerkits_path}:libbegetutil", + ] + external_deps = [ + "bounds_checking_function:libsec_shared", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog_base", + "ipc:ipc_single", + "runtime_core:ani", + "samgr:samgr_proxy", + ] + if (defined(global_parts_info) && + defined(global_parts_info.bundlemanager_bundle_framework)) { + 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" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/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" ] +} diff --git a/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets b/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets new file mode 100644 index 000000000..6428c9462 --- /dev/null +++ b/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets @@ -0,0 +1,52 @@ +/* + * 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. + */ + +class deviceInfo { + static {loadLibrary("deviceinfo_ani.z")} + readonly brand: string = ""; + readonly deviceType: string = ""; + readonly productSeries: string = ""; + readonly productModel: string = ""; + readonly ODID: string = ""; + + 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; +} +export default deviceInfo; diff --git a/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp b/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp new file mode 100644 index 000000000..1f890439f --- /dev/null +++ b/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp @@ -0,0 +1,182 @@ +/* + * 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 "parameter.h" +#include "bundlemgr/bundle_mgr_proxy.h" +#include "iservice_registry.h" +#include "if_system_ability_manager.h" +#include "system_ability_definition.h" +#include "init_error.h" +#include "securec.h" + +#ifndef DEVICEINFO_JS_DOMAIN +#define DEVICEINFO_JS_DOMAIN (BASE_DOMAIN + 8) +#endif + +#ifndef DINFO_TAG +#define DINFO_TAG "DEVICEINFO_JS" +#endif + +#define DEVINFO_LOGV(fmt, ...) STARTUP_LOGV(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) +#define DEVINFO_LOGI(fmt, ...) STARTUP_LOGI(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) +#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 ODID_LEN = 37; + +typedef enum { + DEV_INFO_OK, + DEV_INFO_ENULLPTR, + DEV_INFO_EGETODID, + DEV_INFO_ESTRCOPY +} DevInfoError; + +static ani_string getBrand([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_string brand = nullptr; + const char *value = GetBrand(); + if (value == nullptr) { + value = ""; + } + env->String_NewUTF8(value, strlen(value), &brand); + return brand; +} + +static ani_string getDeviceType([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_string devicetype = nullptr; + const char *value = GetDeviceType(); + if (value == nullptr) { + value = ""; + } + env->String_NewUTF8(value, strlen(value), &devicetype); + return devicetype; +} + +static ani_string getProductSeries([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_string productSeries = nullptr; + const char *value = GetProductSeries(); + if (value == nullptr) { + value = ""; + } + env->String_NewUTF8(value, strlen(value), &productSeries); + return productSeries; +} + +static ani_string getProductModel([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_string productModel = nullptr; + const char *value = GetProductModel(); + if (value == nullptr) { + value = ""; + } + env->String_NewUTF8(value, strlen(value), &productModel); + return productModel; +} + +static DevInfoError AclGetDevOdid(char *odid, int size) +{ + DevInfoError ret = DEV_INFO_OK; + if (odid[0] != '\0') { + return DEV_INFO_OK; + } + auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return DEV_INFO_ENULLPTR; + } + + auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + return DEV_INFO_ENULLPTR; + } + +#ifdef DEPENDENT_APPEXECFWK_BASE + auto bundleMgrProxy = OHOS::iface_cast(remoteObject); + if (!bundleMgrProxy) { + return DEV_INFO_ENULLPTR; + } + + std::string odidStr; + if (bundleMgrProxy->GetOdid(odidStr) != 0) { + return DEV_INFO_EGETODID; + } + + if (strcpy_s(odid, size, odidStr.c_str()) != EOK) { + return DEV_INFO_ESTRCOPY; + } +#else + DEVINFO_LOGE("DEPENDENT_APPEXECFWK_BASE does not exist, The ODID could not be obtained"); + ret = DEV_INFO_EGETODID; +#endif + + return ret; +} + +static ani_string getOdid([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + ani_string odid = nullptr; + static char devOdid[ODID_LEN] = {0}; + int ret = AclGetDevOdid(devOdid, ODID_LEN); + if (ret != 0) { + DEVINFO_LOGE("GetDevOdid ret:%d", ret); + } + env->String_NewUTF8(devOdid, strlen(devOdid), &odid); + return odid; +} + +static ani_int getSdkApiVersion([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) +{ + int sdkApiVersion = GetSdkApiVersion(); + return sdkApiVersion; +} + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + 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; + } + 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; + } + + 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)}, + }; + + if (ANI_OK != env->Class_BindNativeMethods(ns, methods.data(), methods.size())) { + DEVINFO_LOGE("Cannot bind native methods to %s", className); + return ANI_ERROR; + }; + + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/ani/systemparameterenhance/BUILD.gn b/interfaces/ani/systemparameterenhance/BUILD.gn new file mode 100644 index 000000000..a25919329 --- /dev/null +++ b/interfaces/ani/systemparameterenhance/BUILD.gn @@ -0,0 +1,50 @@ +# 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") + +ohos_shared_library("systemparameterenhance_ani") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ "./src/systemparameter_ani.cpp" ] + deps = [ + "${init_innerkits_path}:libbeget_proxy", + "${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" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/systemparameterenhance.abc" +} + +ohos_prebuilt_etc("systemparameterenhance_etc") { + source = "$target_out_dir/systemparameterenhance.abc" + module_install_dir = "framework" + subsystem_name = "startup" + part_name = "init" + deps = [ ":systemparameterenhance" ] +} diff --git a/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets b/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets new file mode 100644 index 000000000..7794a8f33 --- /dev/null +++ b/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets @@ -0,0 +1,25 @@ +/* + * 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 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; diff --git a/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp new file mode 100644 index 000000000..33a003b96 --- /dev/null +++ b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp @@ -0,0 +1,86 @@ +/* + * 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, [[maybe_unused]] ani_object object, + 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_class ns; + static const char *className = "L@ohos/systemParameterEnhance/systemParameterEnhance;"; + if (ANI_OK != env->FindClass(className, &ns)) { + PARAM_JS_LOGE("not found class %s", className); + 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->Class_BindNativeMethods(ns, methods.data(), methods.size())) { + PARAM_JS_LOGE("Cannot bind native methods to %s", className); + return ANI_ERROR; + }; + + *result = ANI_VERSION_1; + return ANI_OK; +} -- Gitee From 461e848e00cf0e28efaa785807c2f89f183a5b55 Mon Sep 17 00:00:00 2001 From: hlzhangaj Date: Tue, 1 Apr 2025 06:30:29 +0000 Subject: [PATCH 2/7] const.ohos.fullname=OpenHarmonyTec-1.0.5.2 Signed-off-by: hlzhangaj --- services/etc/param/ohos.para | 2 +- services/etc/param/ohos_const/ohos.para | 4 ++-- services/etc_lite/param/ohos_const/ohos.para | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 1e046f2e7..25334c7d1 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmony 5.1.0.57 +const.product.software.version=OpenHarmonyTec 1.0.5.2 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index dfea75997..5541f486d 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -10,7 +10,7 @@ # 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. -const.ohos.version.security_patch=2025/03/01 +const.ohos.version.security_patch=2025/04/01 const.ohos.releasetype=Beta1 const.ohos.apiversion=18 -const.ohos.fullname=OpenHarmony-5.1.0.57 \ No newline at end of file +const.ohos.fullname=OpenHarmonyTec-1.0.5.2 \ No newline at end of file diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index f91b27266..032330863 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -13,5 +13,5 @@ const.ohos.releasetype=Beta1 const.ohos.apiversion=18 -const.ohos.version.security_patch=2025/03/01 -const.ohos.fullname=OpenHarmony-5.1.0.57 \ No newline at end of file +const.ohos.version.security_patch=2025/04/01 +const.ohos.fullname=OpenHarmonyTec-1.0.5.2 \ No newline at end of file -- Gitee From c52b84162f0ccc37de516af17b45d88da6617e05 Mon Sep 17 00:00:00 2001 From: cat Date: Thu, 10 Apr 2025 00:11:02 +0800 Subject: [PATCH 3/7] repair class to namespace Signed-off-by: cat --- .../src/systemparameter_ani.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp index 33a003b96..db536d207 100644 --- a/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp +++ b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp @@ -41,8 +41,7 @@ static std::string ani2std(ani_env *env, const ani_string str) return std::string(buffer); } -static ani_string getSync([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object, - ani_string param, ani_string def) +static ani_string getSync([[maybe_unused]] ani_env *env, ani_string param, ani_string def) { std::string key = ani2std(env, param); std::string defValue = ""; @@ -64,10 +63,10 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) return ANI_ERROR; } - ani_class ns; - static const char *className = "L@ohos/systemParameterEnhance/systemParameterEnhance;"; - if (ANI_OK != env->FindClass(className, &ns)) { - PARAM_JS_LOGE("not found class %s", className); + 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; } @@ -76,8 +75,8 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) reinterpret_cast(getSync)}, }; - if (ANI_OK != env->Class_BindNativeMethods(ns, methods.data(), methods.size())) { - PARAM_JS_LOGE("Cannot bind native methods to %s", className); + if (ANI_OK != env->Namespace_BindNativeFunctions(ns, methods.data(), methods.size())) { + PARAM_JS_LOGE("Cannot bind native methods to %s", namespaceName); return ANI_ERROR; }; -- Gitee From 21424a031005ece43b2bde1e9a5755f6f450105b Mon Sep 17 00:00:00 2001 From: hlzhangaj Date: Thu, 17 Apr 2025 07:23:46 +0000 Subject: [PATCH 4/7] const.ohos.fullname=OpenHarmonyTec-6.0.0.28 Signed-off-by: hlzhangaj --- services/etc/param/ohos.para | 2 +- services/etc/param/ohos_const/ohos.para | 6 +++--- services/etc_lite/param/ohos_const/ohos.para | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 25334c7d1..21784c63f 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmonyTec 1.0.5.2 +const.product.software.version=OpenHarmonyTec 6.0.0.28 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index 5541f486d..1a66f06ea 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -11,6 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. const.ohos.version.security_patch=2025/04/01 -const.ohos.releasetype=Beta1 -const.ohos.apiversion=18 -const.ohos.fullname=OpenHarmonyTec-1.0.5.2 \ No newline at end of file +const.ohos.releasetype=Canary1 +const.ohos.apiversion=20 +const.ohos.fullname=OpenHarmonyTec-6.0.0.28 \ No newline at end of file diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index 032330863..c57e60c44 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -const.ohos.releasetype=Beta1 -const.ohos.apiversion=18 +const.ohos.releasetype=Canary1 +const.ohos.apiversion=20 const.ohos.version.security_patch=2025/04/01 -const.ohos.fullname=OpenHarmonyTec-1.0.5.2 \ No newline at end of file +const.ohos.fullname=OpenHarmonyTec-6.0.0.28 \ No newline at end of file -- Gitee From 75b768d403a46eb417ca02706a6e973abf57f81d Mon Sep 17 00:00:00 2001 From: hlzhangaj Date: Thu, 22 May 2025 08:26:49 +0000 Subject: [PATCH 5/7] const.ohos.fullname=OpenHarmony-1.0.6.5 Signed-off-by: hlzhangaj --- services/etc/param/ohos.para | 2 +- services/etc/param/ohos_const/ohos.para | 4 ++-- services/etc_lite/param/ohos_const/ohos.para | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 21784c63f..f44db2d18 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmonyTec 6.0.0.28 +const.product.software.version=OpenHarmony 1.0.6.5 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index 1a66f06ea..0a0beff07 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -10,7 +10,7 @@ # 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. -const.ohos.version.security_patch=2025/04/01 +const.ohos.version.security_patch=2025/05/01 const.ohos.releasetype=Canary1 const.ohos.apiversion=20 -const.ohos.fullname=OpenHarmonyTec-6.0.0.28 \ No newline at end of file +const.ohos.fullname=OpenHarmony-1.0.6.5 \ No newline at end of file diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index c57e60c44..9cac61632 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -13,5 +13,5 @@ const.ohos.releasetype=Canary1 const.ohos.apiversion=20 -const.ohos.version.security_patch=2025/04/01 -const.ohos.fullname=OpenHarmonyTec-6.0.0.28 \ No newline at end of file +const.ohos.version.security_patch=2025/05/01 +const.ohos.fullname=OpenHarmony-1.0.6.5 \ No newline at end of file -- Gitee From b5634c21d87dc5743b6a1edfd0f1496e47061bf7 Mon Sep 17 00:00:00 2001 From: hlzhangaj Date: Thu, 22 May 2025 12:03:08 +0000 Subject: [PATCH 6/7] revert Signed-off-by: hlzhangaj --- services/etc/param/ohos.para | 2 +- services/etc/param/ohos_const/ohos.para | 2 +- services/etc_lite/param/ohos_const/ohos.para | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index f44db2d18..d85c856da 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -29,7 +29,7 @@ const.build.product=default const.product.hardwareversion=default const.product.bootloader.version=bootloader const.product.cpu.abilist=default -const.product.software.version=OpenHarmony 1.0.6.5 +const.product.software.version=OpenHarmony 6.0.0.28 const.product.incremental.version=default const.product.firstapiversion=1 const.product.build.type=default diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para index 0a0beff07..73c30a24a 100755 --- a/services/etc/param/ohos_const/ohos.para +++ b/services/etc/param/ohos_const/ohos.para @@ -13,4 +13,4 @@ const.ohos.version.security_patch=2025/05/01 const.ohos.releasetype=Canary1 const.ohos.apiversion=20 -const.ohos.fullname=OpenHarmony-1.0.6.5 \ No newline at end of file +const.ohos.fullname=OpenHarmony-6.0.0.28 \ No newline at end of file diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para index 9cac61632..519f82366 100755 --- a/services/etc_lite/param/ohos_const/ohos.para +++ b/services/etc_lite/param/ohos_const/ohos.para @@ -14,4 +14,4 @@ const.ohos.releasetype=Canary1 const.ohos.apiversion=20 const.ohos.version.security_patch=2025/05/01 -const.ohos.fullname=OpenHarmony-1.0.6.5 \ No newline at end of file +const.ohos.fullname=OpenHarmony-6.0.0.28 \ No newline at end of file -- Gitee From 77eb7d4567ac11de68109be49040a0cde8b616e0 Mon Sep 17 00:00:00 2001 From: cat Date: Thu, 24 Apr 2025 16:05:51 +0800 Subject: [PATCH 7/7] api repair Signed-off-by: cat Change-Id: Ia57839806fe2921d738ad23c5cf6c0a483c9bebc --- BUILD.gn | 1 - interfaces/ani/BUILD.gn | 25 --- interfaces/ani/deviceinfo/BUILD.gn | 60 ------ .../ani/deviceinfo/ets/@ohos.deviceInfo.ets | 52 ----- .../ani/deviceinfo/src/deviceinfo_ani.cpp | 182 ------------------ .../ani/systemparameterenhance/BUILD.gn | 50 ----- .../src/systemparameter_ani.cpp | 85 -------- .../deviceInfo/idl/ohos.deviceInfo.taihe | 2 +- .../deviceInfo/src/ohos.deviceInfo.impl.cpp | 2 +- .../taihe/syscap/src/ani_constructor.cpp | 1 - ...meterEnhance.systemParameterEnhance.taihe} | 30 ++- ...terEnhance.systemParameterEnhance.impl.cpp | 90 +++++++++ 12 files changed, 112 insertions(+), 468 deletions(-) delete mode 100644 interfaces/ani/BUILD.gn delete mode 100644 interfaces/ani/deviceinfo/BUILD.gn delete mode 100644 interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets delete mode 100644 interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp delete mode 100644 interfaces/ani/systemparameterenhance/BUILD.gn delete mode 100644 interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp rename interfaces/{ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets => taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe} (52%) create mode 100644 interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp diff --git a/BUILD.gn b/BUILD.gn index 00b728847..473ca595f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,7 +17,6 @@ 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", diff --git a/interfaces/ani/BUILD.gn b/interfaces/ani/BUILD.gn deleted file mode 100644 index 49e5c0fb2..000000000 --- a/interfaces/ani/BUILD.gn +++ /dev/null @@ -1,25 +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/ohos.gni") - -group("ani_group") { - if (!defined(ohos_lite)) { - deps = [ - "deviceinfo:deviceinfo_ani", - "deviceinfo:deviceinfo_etc", - "systemparameterenhance:systemparameterenhance_ani", - "systemparameterenhance:systemparameterenhance_etc", - ] - } -} diff --git a/interfaces/ani/deviceinfo/BUILD.gn b/interfaces/ani/deviceinfo/BUILD.gn deleted file mode 100644 index 6c741b441..000000000 --- a/interfaces/ani/deviceinfo/BUILD.gn +++ /dev/null @@ -1,60 +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("//base/startup/init/begetd.gni") -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") - -ohos_shared_library("deviceinfo_ani") { - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - sources = [ "./src/deviceinfo_ani.cpp" ] - deps = [ - "${init_innerkits_path}:libbeget_proxy", - "${init_innerkits_path}:libbegetutil", - ] - external_deps = [ - "bounds_checking_function:libsec_shared", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "hilog:libhilog_base", - "ipc:ipc_single", - "runtime_core:ani", - "samgr:samgr_proxy", - ] - if (defined(global_parts_info) && - defined(global_parts_info.bundlemanager_bundle_framework)) { - 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" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/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" ] -} diff --git a/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets b/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets deleted file mode 100644 index 6428c9462..000000000 --- a/interfaces/ani/deviceinfo/ets/@ohos.deviceInfo.ets +++ /dev/null @@ -1,52 +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. - */ - -class deviceInfo { - static {loadLibrary("deviceinfo_ani.z")} - readonly brand: string = ""; - readonly deviceType: string = ""; - readonly productSeries: string = ""; - readonly productModel: string = ""; - readonly ODID: string = ""; - - 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; -} -export default deviceInfo; diff --git a/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp b/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp deleted file mode 100644 index 1f890439f..000000000 --- a/interfaces/ani/deviceinfo/src/deviceinfo_ani.cpp +++ /dev/null @@ -1,182 +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 "parameter.h" -#include "bundlemgr/bundle_mgr_proxy.h" -#include "iservice_registry.h" -#include "if_system_ability_manager.h" -#include "system_ability_definition.h" -#include "init_error.h" -#include "securec.h" - -#ifndef DEVICEINFO_JS_DOMAIN -#define DEVICEINFO_JS_DOMAIN (BASE_DOMAIN + 8) -#endif - -#ifndef DINFO_TAG -#define DINFO_TAG "DEVICEINFO_JS" -#endif - -#define DEVINFO_LOGV(fmt, ...) STARTUP_LOGV(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) -#define DEVINFO_LOGI(fmt, ...) STARTUP_LOGI(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__) -#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 ODID_LEN = 37; - -typedef enum { - DEV_INFO_OK, - DEV_INFO_ENULLPTR, - DEV_INFO_EGETODID, - DEV_INFO_ESTRCOPY -} DevInfoError; - -static ani_string getBrand([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - ani_string brand = nullptr; - const char *value = GetBrand(); - if (value == nullptr) { - value = ""; - } - env->String_NewUTF8(value, strlen(value), &brand); - return brand; -} - -static ani_string getDeviceType([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - ani_string devicetype = nullptr; - const char *value = GetDeviceType(); - if (value == nullptr) { - value = ""; - } - env->String_NewUTF8(value, strlen(value), &devicetype); - return devicetype; -} - -static ani_string getProductSeries([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - ani_string productSeries = nullptr; - const char *value = GetProductSeries(); - if (value == nullptr) { - value = ""; - } - env->String_NewUTF8(value, strlen(value), &productSeries); - return productSeries; -} - -static ani_string getProductModel([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - ani_string productModel = nullptr; - const char *value = GetProductModel(); - if (value == nullptr) { - value = ""; - } - env->String_NewUTF8(value, strlen(value), &productModel); - return productModel; -} - -static DevInfoError AclGetDevOdid(char *odid, int size) -{ - DevInfoError ret = DEV_INFO_OK; - if (odid[0] != '\0') { - return DEV_INFO_OK; - } - auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityManager) { - return DEV_INFO_ENULLPTR; - } - - auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (!remoteObject) { - return DEV_INFO_ENULLPTR; - } - -#ifdef DEPENDENT_APPEXECFWK_BASE - auto bundleMgrProxy = OHOS::iface_cast(remoteObject); - if (!bundleMgrProxy) { - return DEV_INFO_ENULLPTR; - } - - std::string odidStr; - if (bundleMgrProxy->GetOdid(odidStr) != 0) { - return DEV_INFO_EGETODID; - } - - if (strcpy_s(odid, size, odidStr.c_str()) != EOK) { - return DEV_INFO_ESTRCOPY; - } -#else - DEVINFO_LOGE("DEPENDENT_APPEXECFWK_BASE does not exist, The ODID could not be obtained"); - ret = DEV_INFO_EGETODID; -#endif - - return ret; -} - -static ani_string getOdid([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - ani_string odid = nullptr; - static char devOdid[ODID_LEN] = {0}; - int ret = AclGetDevOdid(devOdid, ODID_LEN); - if (ret != 0) { - DEVINFO_LOGE("GetDevOdid ret:%d", ret); - } - env->String_NewUTF8(devOdid, strlen(devOdid), &odid); - return odid; -} - -static ani_int getSdkApiVersion([[maybe_unused]] ani_env *env, [[maybe_unused]] ani_object object) -{ - int sdkApiVersion = GetSdkApiVersion(); - return sdkApiVersion; -} - -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - 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; - } - 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; - } - - 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)}, - }; - - if (ANI_OK != env->Class_BindNativeMethods(ns, methods.data(), methods.size())) { - DEVINFO_LOGE("Cannot bind native methods to %s", className); - return ANI_ERROR; - }; - - *result = ANI_VERSION_1; - return ANI_OK; -} diff --git a/interfaces/ani/systemparameterenhance/BUILD.gn b/interfaces/ani/systemparameterenhance/BUILD.gn deleted file mode 100644 index a25919329..000000000 --- a/interfaces/ani/systemparameterenhance/BUILD.gn +++ /dev/null @@ -1,50 +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("//base/startup/init/begetd.gni") -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") - -ohos_shared_library("systemparameterenhance_ani") { - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - sources = [ "./src/systemparameter_ani.cpp" ] - deps = [ - "${init_innerkits_path}:libbeget_proxy", - "${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" ] - is_boot_abc = "True" - device_dst_file = "/system/framework/systemparameterenhance.abc" -} - -ohos_prebuilt_etc("systemparameterenhance_etc") { - source = "$target_out_dir/systemparameterenhance.abc" - module_install_dir = "framework" - subsystem_name = "startup" - part_name = "init" - deps = [ ":systemparameterenhance" ] -} diff --git a/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp b/interfaces/ani/systemparameterenhance/src/systemparameter_ani.cpp deleted file mode 100644 index db536d207..000000000 --- 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/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index df8e87eec..f9b87a1cd 100644 --- a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -99,4 +99,4 @@ function getfirstApiVersion(): i32; @static("deviceInfo") @get function getdistributionOSApiVersion(): i32; @static("deviceInfo") @get -function getbootCount(): i32; \ No newline at end of file +function getbootCount(): i32; diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index 16bb09cbf..0cd1200b6 100644 --- a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -465,4 +465,4 @@ TH_EXPORT_CPP_API_getbuildVersion(getbuildVersion); TH_EXPORT_CPP_API_getfirstApiVersion(getfirstApiVersion); TH_EXPORT_CPP_API_getdistributionOSApiVersion(getdistributionOSApiVersion); TH_EXPORT_CPP_API_getbootCount(getbootCount); -TH_EXPORT_CPP_API_getchipType(getchipType); \ No newline at end of file +TH_EXPORT_CPP_API_getchipType(getchipType); diff --git a/interfaces/taihe/syscap/src/ani_constructor.cpp b/interfaces/taihe/syscap/src/ani_constructor.cpp index 4d73d3eaf..c6a9fad38 100644 --- a/interfaces/taihe/syscap/src/ani_constructor.cpp +++ b/interfaces/taihe/syscap/src/ani_constructor.cpp @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "taihe.platform.ani.ani.hpp" #include "internal.full.global.ani.hpp" #if __has_include() #include diff --git a/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe similarity index 52% rename from interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets rename to interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe index 7794a8f33..5237ba1c4 100644 --- a/interfaces/ani/systemparameterenhance/ets/@ohos.systemParameterEnhance.ets +++ b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.systemParameterEnhance.taihe @@ -12,14 +12,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@!namespace("@ohos.systemParameterEnhance.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; -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; diff --git a/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.systemParameterEnhance.impl.cpp new file mode 100644 index 000000000..8fd7ca1d6 --- /dev/null +++ b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.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.systemParameterEnhance.proj.hpp" +#include "ohos.systemParameterEnhance.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); -- Gitee