mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-21 01:45:30 -04:00
!1108 添加 syscap 查找接口到ace
Merge pull request !1108 from chenyude/commit-syscap
This commit is contained in:
@@ -50,11 +50,14 @@ template("ace_osal_ohos_source_set") {
|
||||
"system_properties.cpp",
|
||||
]
|
||||
|
||||
public_deps =
|
||||
[ "//base/startup/init_lite/interfaces/innerkits:libbegetutil" ]
|
||||
|
||||
if (is_standard_system) {
|
||||
sources += [ "resource_adapter_impl.cpp" ]
|
||||
sources += [ "resource_convertor.cpp" ]
|
||||
deps = [ "$ace_flutter_engine_root/icu:ace_libicu_ohos" ]
|
||||
public_deps =
|
||||
public_deps +=
|
||||
[ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr" ]
|
||||
external_deps += [ "multimedia_image_standard:image" ]
|
||||
if (defined(config.accessibility_support) &&
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "core/common/ace_application_info.h"
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
#include "systemcapability.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
@@ -79,6 +82,15 @@ bool IsDebugEnabled()
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool SystemProperties::IsSyscapExist(const char *cap)
|
||||
{
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
return HasSystemCapability(cap);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SystemProperties::InitDeviceType(DeviceType)
|
||||
{
|
||||
// Do nothing, no need to store type here, use system property at 'GetDeviceType' instead.
|
||||
|
||||
@@ -89,6 +89,11 @@ DeviceType SystemProperties::GetDeviceType()
|
||||
return deviceType_;
|
||||
}
|
||||
|
||||
bool SystemProperties::IsSyscapExist(const char *cap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void SystemProperties::InitDeviceTypeBySystemProperty()
|
||||
{
|
||||
deviceType_ = DeviceType::PHONE;
|
||||
@@ -150,5 +155,4 @@ bool SystemProperties::GetDebugEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
@@ -73,6 +73,11 @@ public:
|
||||
*/
|
||||
static DeviceType GetDeviceType();
|
||||
|
||||
/*
|
||||
* check SystemCapability.
|
||||
*/
|
||||
static bool IsSyscapExist(const char *cap);
|
||||
|
||||
/**
|
||||
* Set type of current device.
|
||||
* @param deviceType
|
||||
|
||||
@@ -106,6 +106,7 @@ template("declarative_js_engine_ark") {
|
||||
"modules/jsi_matrix4_module.cpp",
|
||||
"modules/jsi_module_manager.cpp",
|
||||
"modules/jsi_router_module.cpp",
|
||||
"modules/jsi_syscap_module.cpp",
|
||||
"modules/jsi_timer_module.cpp",
|
||||
]
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_types.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_module_manager.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_timer_module.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_syscap_module.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_xcomponent.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/common/js_api_perf.h"
|
||||
@@ -637,6 +638,7 @@ void JsiDeclarativeEngineInstance::InitJsNativeModuleObject()
|
||||
|
||||
if (!usingSharedRuntime_) {
|
||||
JsiTimerModule::GetInstance()->InitTimerModule(runtime_, global);
|
||||
JsiSyscapModule::GetInstance()->InitSyscapModule(runtime_, global);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_timer_module.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_syscap_module.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 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 "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_syscap_module.h"
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h"
|
||||
#include "frameworks/bridge/js_frontend/engine/common/js_constants.h"
|
||||
#include "frameworks/bridge/js_frontend/frontend_delegate.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
JsiSyscapModule* JsiSyscapModule::GetInstance()
|
||||
{
|
||||
static JsiSyscapModule instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
uint32_t JsiSyscapModule::AddCallBack(const shared_ptr<JsValue>& func, const std::vector<shared_ptr<JsValue>>& params)
|
||||
{
|
||||
++callBackId_;
|
||||
callBackFuncMap_[callBackId_] = func;
|
||||
callBackParamsMap_[callBackId_] = params;
|
||||
return callBackId_;
|
||||
}
|
||||
|
||||
void JsiSyscapModule::RemoveCallBack(uint32_t callBackId)
|
||||
{
|
||||
if (callBackFuncMap_.find(callBackId) != callBackFuncMap_.end()) {
|
||||
callBackFuncMap_.erase(callBackId);
|
||||
}
|
||||
if (callBackParamsMap_.find(callBackId) != callBackParamsMap_.end()) {
|
||||
callBackParamsMap_.erase(callBackId);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> CanIUse(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc != 1) {
|
||||
LOGE("agrc should be 1");
|
||||
return runtime->NewNull();
|
||||
}
|
||||
if (!argv[0]->IsString(runtime)) {
|
||||
LOGW("argv[0] is not IsString");
|
||||
return runtime->NewNull();
|
||||
}
|
||||
|
||||
std::string syscapString = argv[0]->ToString(runtime);
|
||||
|
||||
bool ret = Ace::SystemProperties::IsSyscapExist(syscapString.c_str());
|
||||
return runtime->NewBoolean(ret);
|
||||
}
|
||||
|
||||
bool JsiSyscapModule::GetCallBack(uint32_t callBackId, shared_ptr<JsValue>& func,
|
||||
std::vector<shared_ptr<JsValue>>& params)
|
||||
{
|
||||
auto iterFunc = callBackFuncMap_.find(callBackId);
|
||||
auto iterParams = callBackParamsMap_.find(callBackId);
|
||||
if (iterFunc == callBackFuncMap_.end()) {
|
||||
LOGE("find callback function failed, callbackId = %{public}u", callBackId);
|
||||
return false;
|
||||
}
|
||||
if (iterParams == callBackParamsMap_.end()) {
|
||||
LOGE("find callback parameters failed, callbackId = %{public}u", callBackId);
|
||||
return false;
|
||||
}
|
||||
func = iterFunc->second;
|
||||
params = iterParams->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
void JsiSyscapModule::InitSyscapModule(const shared_ptr<JsRuntime>& runtime, shared_ptr<JsValue>& moduleObj)
|
||||
{
|
||||
moduleObj->SetProperty(runtime, CAN_IUSE, runtime->NewFunction(CanIUse));
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_SYSCAP_MODULE_H
|
||||
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_SYSCAP_MODULE_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "base/utils/noncopyable.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_runtime.h"
|
||||
#include "frameworks/bridge/declarative_frontend/engine/jsi/ark/include/js_value.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
class JsiSyscapModule {
|
||||
public:
|
||||
JsiSyscapModule() = default;
|
||||
~JsiSyscapModule() = default;
|
||||
static JsiSyscapModule* GetInstance();
|
||||
void InitSyscapModule(const shared_ptr<JsRuntime>& runtime, shared_ptr<JsValue>& moduleObj);
|
||||
uint32_t AddCallBack(const shared_ptr<JsValue>& func, const std::vector<shared_ptr<JsValue>>& params);
|
||||
void RemoveCallBack(uint32_t callBackId);
|
||||
bool GetCallBack(uint32_t callBackId, shared_ptr<JsValue>& func, std::vector<shared_ptr<JsValue>>& params);
|
||||
|
||||
private:
|
||||
ACE_DISALLOW_COPY_AND_MOVE(JsiSyscapModule);
|
||||
|
||||
uint32_t callBackId_ = 0;
|
||||
std::unordered_map<uint32_t, shared_ptr<JsValue>> callBackFuncMap_;
|
||||
std::unordered_map<uint32_t, std::vector<shared_ptr<JsValue>>> callBackParamsMap_;
|
||||
};
|
||||
} // namespace OHOS::Ace::Framework
|
||||
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_MODULES_JSI_SYSCAP_MODULE_H
|
||||
+32
-2
@@ -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
|
||||
@@ -318,6 +318,29 @@ JSValue ClearInterval(JSContext* ctx, JSValueConst value, int32_t argc, JSValueC
|
||||
return ModuleManager::GetInstance()->ClearWaitTimer(ctx, argc, argv, true);
|
||||
}
|
||||
|
||||
JSValue CanIUse(JSContext* ctx, JSValueConst value, int32_t argc, JSValueConst* argv)
|
||||
{
|
||||
LOGD("CanIUse argc is %d", argc);
|
||||
|
||||
if (argc != 1) {
|
||||
LOGE("CanIUse: invalid value");
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
QJSContext::Scope scp(ctx);
|
||||
if (!JS_IsString(argv[0])) {
|
||||
LOGE("CanIUse: invalid input");
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
ScopedString targetString(ctx, argv[0]);
|
||||
std::string syscapString = targetString.get();
|
||||
|
||||
bool ret = Ace::SystemProperties::IsSyscapExist(syscapString.c_str());
|
||||
|
||||
return JS_NewBool(ctx, ret);
|
||||
}
|
||||
|
||||
JSValue ModuleManager::SetWaitTimer(JSContext* ctx, int32_t argc, JSValueConst* argv, bool isInterval)
|
||||
{
|
||||
LOGD("SetWaitTimer argc is %d", argc);
|
||||
@@ -461,4 +484,11 @@ void ModuleManager::InitTimerModule(JSContext* ctx)
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
void ModuleManager::InitSyscapModule(JSContext* ctx)
|
||||
{
|
||||
JSValue globalObj = JS_GetGlobalObject(ctx);
|
||||
JS_SetPropertyStr(ctx, globalObj, CAN_IUSE, JS_NewCFunction(ctx, CanIUse, CAN_IUSE, 1));
|
||||
JS_FreeValue(ctx, globalObj);
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -32,6 +32,7 @@ public:
|
||||
static ModuleManager* GetInstance();
|
||||
bool InitModule(JSContext* ctx, const std::string& moduleName, JSValue& jsObject);
|
||||
void InitTimerModule(JSContext* ctx);
|
||||
void InitSyscapModule(JSContext* ctx);
|
||||
|
||||
JSValue SetWaitTimer(JSContext* ctx, int32_t argc, JSValueConst* argv, bool isInterval);
|
||||
JSValue ClearWaitTimer(JSContext* ctx, int32_t argc, JSValueConst* argv, bool isInterval);
|
||||
|
||||
+1
@@ -531,6 +531,7 @@ void QJSDeclarativeEngineInstance::InitJsNativeModuleObject(JSContext* ctx)
|
||||
{
|
||||
QJSUtils::DefineGlobalFunction(ctx, RequireNativeModule, "requireNativeModule", 1);
|
||||
ModuleManager::GetInstance()->InitTimerModule(ctx);
|
||||
ModuleManager::GetInstance()->InitSyscapModule(ctx);
|
||||
}
|
||||
|
||||
void QJSDeclarativeEngineInstance::InitJsExportsUtilObject(JSContext* ctx)
|
||||
|
||||
@@ -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
|
||||
@@ -87,6 +87,7 @@ const char SET_TIMEOUT[] = "setTimeout";
|
||||
const char CLEAR_TIMEOUT[] = "clearTimeout";
|
||||
const char CLEAR_INTERVAL[] = "clearInterval";
|
||||
const char SET_INTERVAL[] = "setInterval";
|
||||
const char CAN_IUSE[] = "canIUse";
|
||||
|
||||
// for app
|
||||
const char APP_GET_INFO[] = "getInfo";
|
||||
|
||||
@@ -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
|
||||
@@ -87,6 +87,7 @@ ACE_EXPORT extern const char SET_TIMEOUT[];
|
||||
ACE_EXPORT extern const char CLEAR_TIMEOUT[];
|
||||
ACE_EXPORT extern const char CLEAR_INTERVAL[];
|
||||
ACE_EXPORT extern const char SET_INTERVAL[];
|
||||
ACE_EXPORT extern const char CAN_IUSE[];
|
||||
|
||||
// for app
|
||||
ACE_EXPORT extern const char APP_GET_INFO[];
|
||||
|
||||
@@ -2868,6 +2868,32 @@ void JsiEngineInstance::RegisterConsoleModule(ArkNativeEngine* engine)
|
||||
nativeGlobal->SetProperty("console", console);
|
||||
}
|
||||
|
||||
shared_ptr<JsValue> SyscapCanIUse(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>& thisObj,
|
||||
const std::vector<shared_ptr<JsValue>>& argv, int32_t argc)
|
||||
{
|
||||
if (argc != 1) {
|
||||
LOGE("agrc should be 1");
|
||||
return runtime->NewNull();
|
||||
}
|
||||
if (!argv[0]->IsString(runtime)) {
|
||||
LOGW("argv[0] is not IsString");
|
||||
return runtime->NewNull();
|
||||
}
|
||||
|
||||
std::string syscapString = argv[0]->ToString(runtime);
|
||||
bool ret = Ace::SystemProperties::IsSyscapExist(syscapString.c_str());
|
||||
return runtime->NewBoolean(ret);
|
||||
}
|
||||
|
||||
void JsiEngineInstance::RegisterSyscapModule()
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiEngine::RegisterSyscapModule");
|
||||
LOGD("JsiEngineInstance RegisterSyscapModule");
|
||||
shared_ptr<JsValue> global = runtime_->GetGlobal();
|
||||
|
||||
global->SetProperty(runtime_, CAN_IUSE, runtime_->NewFunction(SyscapCanIUse));
|
||||
}
|
||||
|
||||
void JsiEngineInstance::RegisterDocumentModule()
|
||||
{
|
||||
ACE_SCOPED_TRACE("JsiEngine::RegisterDocumentModule");
|
||||
@@ -2946,6 +2972,7 @@ bool JsiEngineInstance::InitJsEnv(bool debugger_mode, const std::unordered_map<s
|
||||
|
||||
RegisterAceModule();
|
||||
RegisterConsoleModule();
|
||||
RegisterSyscapModule();
|
||||
RegisterDocumentModule();
|
||||
RegisterPerfUtilModule();
|
||||
RegisterHiViewModule();
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
private:
|
||||
void RegisterAceModule(); // add ace object to global
|
||||
void RegisterConsoleModule(); // add Console object to global
|
||||
void RegisterSyscapModule(); // add Syscap object to global
|
||||
void RegisterDocumentModule(); // add dom object to global
|
||||
void RegisterPerfUtilModule(); // add perfutil object to global
|
||||
void RegisterHiViewModule(); // add hiView object to global
|
||||
|
||||
Reference in New Issue
Block a user