From c33c91d71c0f4e908d76afaa834db69efc2dc1a0 Mon Sep 17 00:00:00 2001 From: cat Date: Wed, 18 Jun 2025 14:41:36 +0800 Subject: [PATCH] add arkts1.2 code Signed-off-by: cat --- .../innerkits/include/syspara/parameter.h | 3 + .../innerkits/libbegetutil.versionscript | 1 + interfaces/innerkits/syspara/parameter.c | 14 ++++ interfaces/taihe/BUILD.gn | 2 + .../deviceInfo/idl/ohos.deviceInfo.taihe | 15 ++++ .../deviceInfo/src/ohos.deviceInfo.impl.cpp | 26 +++++++ interfaces/taihe/syscap/BUILD.gn | 69 +++++++++++++++++++ interfaces/taihe/syscap/idl/global.taihe | 18 +++++ .../taihe/syscap/src/ani_constructor.cpp | 29 ++++++++ interfaces/taihe/syscap/src/global.impl.cpp | 36 ++++++++++ 10 files changed, 213 insertions(+) create mode 100644 interfaces/taihe/syscap/BUILD.gn create mode 100644 interfaces/taihe/syscap/idl/global.taihe create mode 100644 interfaces/taihe/syscap/src/ani_constructor.cpp create mode 100644 interfaces/taihe/syscap/src/global.impl.cpp diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h index ea220351a..f7dfa61ef 100644 --- a/interfaces/innerkits/include/syspara/parameter.h +++ b/interfaces/innerkits/include/syspara/parameter.h @@ -28,6 +28,8 @@ extern "C" { #define OS_FULL_NAME_LEN 128 #define VERSION_ID_MAX_LEN 256 #define PARAM_BUFFER_MAX (0x01 << 16) +#define PERFORMANCE_CLASS_HIGH_LEVEL 0 +#define PERFORMANCE_CLASS_LOW_LEVEL 2 static const char EMPTY_STR[] = { "" }; @@ -165,6 +167,7 @@ int GetDevUdid(char *udid, int size); const char *AclGetSerial(void); int AclGetDevUdid(char *udid, int size); int AclGetDiskSN(char *diskSN, int size); +int GetPerformanceClass(void); /** * @brief Obtains a system parameter matching the specified key. diff --git a/interfaces/innerkits/libbegetutil.versionscript b/interfaces/innerkits/libbegetutil.versionscript index a6762300e..9ccd64609 100644 --- a/interfaces/innerkits/libbegetutil.versionscript +++ b/interfaces/innerkits/libbegetutil.versionscript @@ -150,6 +150,7 @@ GetDistributionOSApiVersion; GetDistributionOSApiName; GetDistributionOSReleaseType; + GetPerformanceClass; SaveParameters; OH_StrArrayGetIndex; OH_ExtendableStrArrayGetIndex; diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index 3ef6f0a12..3766f800a 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -421,3 +421,17 @@ const char *GetDistributionOSReleaseType(void) } return distributionOsReleaseType; } + +int GetPerformanceClass(void) +{ + static const char *performanceClass = NULL; + GetProperty("const.sys.performance_class", &performanceClass); + if (performanceClass == NULL) { + return PERFORMANCE_CLASS_HIGH_LEVEL; + } + int performanceClassValue = atoi(performanceClass); + if (performanceClassValue < PERFORMANCE_CLASS_HIGH_LEVEL || performanceClassValue > PERFORMANCE_CLASS_LOW_LEVEL) { + return PERFORMANCE_CLASS_HIGH_LEVEL; + } + return performanceClassValue; +} diff --git a/interfaces/taihe/BUILD.gn b/interfaces/taihe/BUILD.gn index 74433019d..8bb20df00 100644 --- a/interfaces/taihe/BUILD.gn +++ b/interfaces/taihe/BUILD.gn @@ -17,6 +17,8 @@ group("taihe_group") { deps = [ "deviceInfo:deviceInfo_etc", "deviceInfo:deviceInfo_taihe_native", + "syscap:global_etc", + "syscap:global_taihe_native", "systemParameterEnhance:systemParamterEnhance_etc", "systemParameterEnhance:systemParameterEnhance_taihe_native", ] diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index 4315fe600..4ae9f0fc3 100644 --- a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -21,6 +21,21 @@ loadLibrary("deviceInfo_taihe_native.z") @class interface deviceInfo { } +enum DeviceTypes: String { + TYPE_DEFAULT = "default", + TYPE_PHONE = "phone", + TYPE_TABLET = "tablet", + TYPE_TV = "tv", + TYPE_WEARABLE = "wearable", + TYPE_CAR = "car" +} +enum PerformanceClassLevel: i32 { + CLASS_LEVEL_HIGH, + CLASS_LEVEL_MEDIUM, + CLASS_LEVEL_LOW +} +@static("deviceInfo") @get +function getperformanceClass(): PerformanceClassLevel; @static("deviceInfo") @get function getbrand(): String; @static("deviceInfo") @get diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index b4a75a590..95a6dcf7c 100644 --- a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -51,6 +51,12 @@ typedef enum { DEV_INFO_ESTRCOPY } DevInfoError; +typedef enum { + CLASS_LEVEL_HIGH, + CLASS_LEVEL_MEDIUM, + CLASS_LEVEL_LOW +} PerformanceClassLevel; + using namespace taihe; // using namespace ohos::deviceInfo; @@ -64,6 +70,25 @@ public: } }; +using type_key_t = ohos::deviceInfo::PerformanceClassLevel::key_t; + +ohos::deviceInfo::PerformanceClassLevel getperformanceClass() +{ + ohos::deviceInfo::PerformanceClassLevel value = type_key_t::CLASS_LEVEL_HIGH; + int level = GetPerformanceClass(); + switch (level) { + case CLASS_LEVEL_MEDIUM: + value = type_key_t::CLASS_LEVEL_MEDIUM; + break; + case CLASS_LEVEL_LOW: + value = type_key_t::CLASS_LEVEL_LOW; + break; + default: + value = type_key_t::CLASS_LEVEL_HIGH; + } + return value; +} + string getbrand() { const char *value = GetBrand(); @@ -412,6 +437,7 @@ int32_t getdistributionOSApiVersion() } } // namespace +TH_EXPORT_CPP_API_getperformanceClass(getperformanceClass); TH_EXPORT_CPP_API_getbrand(getbrand); TH_EXPORT_CPP_API_getdeviceType(getdeviceType); TH_EXPORT_CPP_API_getproductSeries(getproductSeries); diff --git a/interfaces/taihe/syscap/BUILD.gn b/interfaces/taihe/syscap/BUILD.gn new file mode 100644 index 000000000..543e1bba6 --- /dev/null +++ b/interfaces/taihe/syscap/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//base/startup/init/begetd.gni") +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +copy_taihe_idl("copy_global") { + sources = [ "idl/global.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_global" ] + outputs = [ + "$taihe_generated_file_path/src/global.ani.cpp", + "$taihe_generated_file_path/src/global.abi.c", + ] +} + +taihe_shared_library("global_taihe_native") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + include_dirs = [ "//base/startup/init/interfaces/innerkits/include" ] + sources += [ + "src/ani_constructor.cpp", + "src/global.impl.cpp", + ] + deps = [ + ":run_taihe", + "${init_innerkits_path}:libbegetutil", + ] +} + +generate_static_abc("global") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/global.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/global.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("global_etc") { + source = "$target_out_dir/global.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":global" ] +} diff --git a/interfaces/taihe/syscap/idl/global.taihe b/interfaces/taihe/syscap/idl/global.taihe new file mode 100644 index 000000000..4118a6476 --- /dev/null +++ b/interfaces/taihe/syscap/idl/global.taihe @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@!sts_inject(""" +loadLibrary("global_taihe_native") +""") +function canIUse(syscap: String): bool; \ No newline at end of file diff --git a/interfaces/taihe/syscap/src/ani_constructor.cpp b/interfaces/taihe/syscap/src/ani_constructor.cpp new file mode 100644 index 000000000..a90c1c386 --- /dev/null +++ b/interfaces/taihe/syscap/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "taihe/runtime.hpp" +#include "global.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != global::ANIRegister(env)) { + std::cerr << "Error from global::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/taihe/syscap/src/global.impl.cpp b/interfaces/taihe/syscap/src/global.impl.cpp new file mode 100644 index 000000000..e1f25df80 --- /dev/null +++ b/interfaces/taihe/syscap/src/global.impl.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "global.proj.hpp" +#include "global.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "systemcapability.h" +#include "beget_ext.h" + +using namespace taihe; +namespace { +// To be implemented. + +bool canIUse(string_view syscap) +{ + bool ret = HasSystemCapability(std::string(syscap).c_str()); + return ret; +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_canIUse(canIUse); +// NOLINTEND -- Gitee