diff --git a/ace_lite.gni b/ace_lite.gni index 5b6b09a..5f193d3 100644 --- a/ace_lite.gni +++ b/ace_lite.gni @@ -1,4 +1,4 @@ -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. +#Copyright (c) 2020-2022 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 @@ -78,6 +78,7 @@ ace_lite_include_dirs += [ "//third_party/freetype/include", "//base/global/resmgr_lite/interfaces/innerkits/include", "//base/global/i18n_lite/interfaces/kits/i18n/include", + "//base/startup/init_lite/interfaces/innerkits/include", ] ace_lite_include_dirs_simulator = [ @@ -176,6 +177,7 @@ ace_lite_sources = [ "$ACE_LITE_PATH/src/core/modules/presets/profiler_module.cpp", "$ACE_LITE_PATH/src/core/modules/presets/render_module.cpp", "$ACE_LITE_PATH/src/core/modules/presets/require_module.cpp", + "$ACE_LITE_PATH/src/core/modules/presets/syscap_module.cpp", "$ACE_LITE_PATH/src/core/modules/presets/timer_module.cpp", "$ACE_LITE_PATH/src/core/modules/presets/version_module.cpp", "$ACE_LITE_PATH/src/core/modules/router_module.cpp", diff --git a/frameworks/BUILD.gn b/frameworks/BUILD.gn index 196c3a6..dceeb7e 100644 --- a/frameworks/BUILD.gn +++ b/frameworks/BUILD.gn @@ -1,4 +1,4 @@ -#Copyright (c) 2020-2021 Huawei Device Co., Ltd. +#Copyright (c) 2020-2022 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 @@ -73,6 +73,7 @@ lite_library("ace_lite") { ] } else { public_deps += [ + "//base/startup/init_lite/interfaces/innerkits/syscap:syscap", "//build/lite/config/component/cJSON:cjson_shared", "//foundation/graphic/surface:lite_surface", "//foundation/multimedia/camera_lite/frameworks:camera_lite", diff --git a/frameworks/src/core/context/js_app_environment.cpp b/frameworks/src/core/context/js_app_environment.cpp index db701d8..1670096 100644 --- a/frameworks/src/core/context/js_app_environment.cpp +++ b/frameworks/src/core/context/js_app_environment.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 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 @@ -31,6 +31,7 @@ #include "presets/profiler_module.h" #include "presets/render_module.h" #include "presets/require_module.h" +#include "presets/syscap_module.h" #include "presets/timer_module.h" #include "presets/version_module.h" #include "product_adapter.h" @@ -57,6 +58,7 @@ void JsAppEnvironment::LoadAceBuiltInModules() const FeaAbilityModule::Load(); JsTestModule::Load(); TimersModule::Load(); + SyscapsModule::Load(); PerformaceProfilerModule::Load(); AceVersionModule::Load(); IntlControlModule::Load(); diff --git a/frameworks/src/core/modules/presets/syscap_module.cpp b/frameworks/src/core/modules/presets/syscap_module.cpp new file mode 100644 index 0000000..ab5083f --- /dev/null +++ b/frameworks/src/core/modules/presets/syscap_module.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022-2022 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 "acelite_config.h" +#if (FEATURE_SYSCAP_MODULE == 1) +#include +#include "syscap_module.h" +#include "ace_mem_base.h" +#include "systemcapability.h" + +namespace OHOS { +namespace ACELite { +const uint16_t SYSCAP_BUFFER_SIZE = 128; +void SyscapModule::Init() +{ + const char * const canIUse = "canIUse"; + CreateNamedFunction(canIUse, CanIUse); +} + +jerry_value_t SyscapModule::CheckSyscap(const jerry_value_t func, + const jerry_value_t context, + const jerry_value_t *args, + const jerry_length_t argsNum, + bool repeated) +{ + (void)func; /* unused */ + (void)context; /* unused */ + (void)repeated; /* unused */ + + const uint8_t leastArguments = 1; + if ((argsNum != leastArguments)) { + return UNDEFINED; + } + + jerry_value_t strVal; + if (jerry_value_is_symbol(args[0])) { + strVal = jerry_get_symbol_descriptive_string(args[0]); + } else { + strVal = jerry_value_to_string(args[0]); + } + + if (jerry_value_is_error(strVal)) { + jerry_release_value(strVal); + return jerry_create_boolean(false); + } + + jerry_length_t length = jerry_get_utf8_string_length(strVal); + if (length >= SYSCAP_BUFFER_SIZE) { + jerry_release_value(strVal); + return jerry_create_boolean(false); + } + + jerry_char_t buffer[SYSCAP_BUFFER_SIZE] = {0}; + jerry_size_t syscapStrSize = jerry_string_to_utf8_char_buffer(strVal, buffer, length); + const char *syscapString = (char *)buffer; + bool ret = HasSystemCapability(syscapString); + + jerry_release_value(strVal); + return jerry_create_boolean(ret); +} +} // namespace ACELite +} // namespace OHOS +#endif // FEATURE_SYSCAP_MODULE diff --git a/frameworks/src/core/modules/presets/syscap_module.h b/frameworks/src/core/modules/presets/syscap_module.h new file mode 100644 index 0000000..709f7c7 --- /dev/null +++ b/frameworks/src/core/modules/presets/syscap_module.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2022-2022 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. + */ +#ifndef OHOS_ACELITE_SYSCAP_MODULE_H +#define OHOS_ACELITE_SYSCAP_MODULE_H + +#include "acelite_config.h" +#if (FEATURE_SYSCAP_MODULE == 1) +#include "presets/preset_module.h" + +namespace OHOS { +namespace ACELite { +class SyscapModule final : PresetModule { +public: + ACE_DISALLOW_COPY_AND_MOVE(SyscapModule); + static SyscapModule *GetInstance() + { + static SyscapModule instance; + return &instance; + } + void Init() override; + +private: + /** + * @fn SyscapModule::SyscapModule() + * @brief Constructor + */ + SyscapModule() : PresetModule(nullptr) + { + } + + /** + * @fn SyscapModule::~SyscapModule() + * + */ + ~SyscapModule() = default; + + /** + * @brief get the syscap. + */ + static jerry_value_t CanIUse(const jerry_value_t func, + const jerry_value_t context, + const jerry_value_t *args, + const jerry_length_t argsNum) + { + return CheckSyscap(func, context, args, argsNum, false); + } + + /** + * @brief get the syscap whether exist. + * @return the boolean of syscap + */ + static jerry_value_t CheckSyscap(const jerry_value_t func, + const jerry_value_t context, + const jerry_value_t *args, + const jerry_length_t argsNum, + bool repeated); +}; +} // namespace ACELite +} // namespace OHOS +#endif // FEATURE_SYSCAP_MODULE == 1 + +namespace OHOS { +namespace ACELite { +class SyscapsModule final { +public: + ACE_DISALLOW_COPY_AND_MOVE(SyscapsModule); + SyscapsModule() = default; + ~SyscapsModule() = default; + static void Load() + { +#if (FEATURE_SYSCAP_MODULE == 1) + SyscapModule *syscapModule = const_cast(SyscapModule::GetInstance()); + syscapModule->Init(); +#endif + } +}; +} // namespace ACELite +} // namespace OHOS +#endif // OHOS_ACELITE_SYSCAP_MODULE_H diff --git a/frameworks/targets/linux/acelite_config.h b/frameworks/targets/linux/acelite_config.h index 02d20a8..c6b32cb 100644 --- a/frameworks/targets/linux/acelite_config.h +++ b/frameworks/targets/linux/acelite_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 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 @@ -87,6 +87,11 @@ */ #define FEATURE_MODULE_DEVICE 1 +/** + * syscap module + */ +#define FEATURE_SYSCAP_MODULE 1 + /** * timer module */ diff --git a/frameworks/targets/liteos_a/acelite_config.h b/frameworks/targets/liteos_a/acelite_config.h index 981f093..7389ed0 100644 --- a/frameworks/targets/liteos_a/acelite_config.h +++ b/frameworks/targets/liteos_a/acelite_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 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 @@ -97,6 +97,13 @@ #define FEATURE_MODULE_DEVICE 1 #endif +/** + * syscap module + */ +#ifndef FEATURE_SYSCAP_MODULE +#define FEATURE_SYSCAP_MODULE 1 +#endif + /** * timer module */ diff --git a/frameworks/targets/liteos_m/acelite_config.h b/frameworks/targets/liteos_m/acelite_config.h index b33b55d..03623a8 100644 --- a/frameworks/targets/liteos_m/acelite_config.h +++ b/frameworks/targets/liteos_m/acelite_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 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 @@ -74,6 +74,13 @@ #define FEATURE_FEATURE_ABILITY_MODULE 1 #endif +/** + * enable syscap JS API + */ +#ifndef FEATURE_SYSCAP_MODULE +#define FEATURE_SYSCAP_MODULE 0 +#endif + /** * enable timer JS API */ diff --git a/frameworks/targets/simulator/acelite_config.h b/frameworks/targets/simulator/acelite_config.h index 564fd76..345f250 100644 --- a/frameworks/targets/simulator/acelite_config.h +++ b/frameworks/targets/simulator/acelite_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. + * Copyright (c) 2020-2022 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 @@ -85,6 +85,11 @@ */ #define FEATURE_TIMER_MODULE 1 +/** + * syscap module + */ +#define FEATURE_SYSCAP_MODULE 1 + /** * execute timer callback directly for previewer */ diff --git a/frameworks/tools/qt/simulator/jsfwk/jsfwk.pro b/frameworks/tools/qt/simulator/jsfwk/jsfwk.pro index 4b9ff00..31b946f 100644 --- a/frameworks/tools/qt/simulator/jsfwk/jsfwk.pro +++ b/frameworks/tools/qt/simulator/jsfwk/jsfwk.pro @@ -142,6 +142,7 @@ SOURCES += \ $${ACELITE_CORE_PATH}/modules/presets/render_module.cpp \ $${ACELITE_CORE_PATH}/modules/presets/require_module.cpp \ $${ACELITE_CORE_PATH}/modules/presets/timer_module.cpp \ + $${ACELITE_CORE_PATH}/modules/presets/syscap_module.cpp \ $${ACELITE_CORE_PATH}/modules/presets/version_module.cpp \ $${ACELITE_CORE_PATH}/modules/router_module.cpp \ $${ACELITE_CORE_PATH}/modules/sample_module.cpp \ diff --git a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h index fd9653e..22ef6df 100644 --- a/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h +++ b/frameworks/tools/qt/simulator/jsfwk/targets/simulator/acelite_config.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 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 @@ -109,6 +109,11 @@ */ #define FEATURE_TIMER_MODULE 1 +/** + * syscap module + */ +#define FEATURE_SYSCAP_MODULE 1 + #define FEATURE_CUSTOM_ENTRY_PAGE 1 /**