diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h index ea220351a3b5addababf668d128a58804cdf3319..f7dfa61efe27c9105a5f002cb2d65e416b42be0f 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 a6762300ec8510b3f2b939742c06223f8197cdcc..9ccd6460928df9314937c39ce2ed07351114809e 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 3ef6f0a122425756c9be4909fce8b8f285dee041..3766f800a1abe2c162297acda242898e957a3a45 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 74433019dbd065ff61c2faca4df51814f04b56ba..8bb20df00efa94f938598d8c1337ca1936a3cf46 100644 --- a/interfaces/taihe/BUILD.gn +++ b/interfaces/taihe/BUILD.gn @@ -17,6 +17,8 @@ group("taihe_group") { deps = [ "deviceInfo:deviceInfo_etc", "deviceInfo:deviceInfo_taihe_native", + "syscap:global_etc", + "syscap:global_taihe_native", "systemParameterEnhance:systemParamterEnhance_etc", "systemParameterEnhance:systemParameterEnhance_taihe_native", ] diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index 4315fe600877fd8ced910ab94a42dcd38aa886b6..4ae9f0fc39e69990526ec9bc6626d7ca81964e47 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 b4a75a590dd4d690118aa7c23e1a9009a696110b..95a6dcf7c2b5a09a4b4a549d2661e3e4d58c8912 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 0000000000000000000000000000000000000000..543e1bba6dc8e265c61fb3f5b94a71497b2bd114 --- /dev/null +++ b/interfaces/taihe/syscap/BUILD.gn @@ -0,0 +1,69 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//base/startup/init/begetd.gni") +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +copy_taihe_idl("copy_global") { + sources = [ "idl/global.taihe" ] +} +subsystem_name = "startup" +part_name = "init" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_global" ] + outputs = [ + "$taihe_generated_file_path/src/global.ani.cpp", + "$taihe_generated_file_path/src/global.abi.c", + ] +} + +taihe_shared_library("global_taihe_native") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + include_dirs = [ "//base/startup/init/interfaces/innerkits/include" ] + sources += [ + "src/ani_constructor.cpp", + "src/global.impl.cpp", + ] + deps = [ + ":run_taihe", + "${init_innerkits_path}:libbegetutil", + ] +} + +generate_static_abc("global") { + base_url = "$taihe_generated_file_path" + files = [ "$taihe_generated_file_path/global.ets" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/global.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("global_etc") { + source = "$target_out_dir/global.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":global" ] +} diff --git a/interfaces/taihe/syscap/idl/global.taihe b/interfaces/taihe/syscap/idl/global.taihe new file mode 100644 index 0000000000000000000000000000000000000000..4118a6476489e235fcc4826fa1f671ad88686834 --- /dev/null +++ b/interfaces/taihe/syscap/idl/global.taihe @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +@!sts_inject(""" +loadLibrary("global_taihe_native") +""") +function canIUse(syscap: String): bool; \ No newline at end of file diff --git a/interfaces/taihe/syscap/src/ani_constructor.cpp b/interfaces/taihe/syscap/src/ani_constructor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a90c1c3863443f569185c05e6afbdf969a4e97bf --- /dev/null +++ b/interfaces/taihe/syscap/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "taihe/runtime.hpp" +#include "global.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != global::ANIRegister(env)) { + std::cerr << "Error from global::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/interfaces/taihe/syscap/src/global.impl.cpp b/interfaces/taihe/syscap/src/global.impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1f25df80cd06df681a1db8186d7d08caa700850 --- /dev/null +++ b/interfaces/taihe/syscap/src/global.impl.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "global.proj.hpp" +#include "global.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" +#include "systemcapability.h" +#include "beget_ext.h" + +using namespace taihe; +namespace { +// To be implemented. + +bool canIUse(string_view syscap) +{ + bool ret = HasSystemCapability(std::string(syscap).c_str()); + return ret; +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_canIUse(canIUse); +// NOLINTEND