From de4ad8e1a3e92a779138a4afac7487b4b5951f56 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Fri, 10 Nov 2023 16:27:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=B0=8F=E5=9E=8B/=E8=BD=BB?= =?UTF-8?q?=E9=87=8F=E7=B3=BB@ohos.deviceinfo=20API=E7=9A=84=E8=A1=A5?= =?UTF-8?q?=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhongning5 Change-Id: I5d844b96cb1e853b5f7bb1d856763e68a35b6e31 --- js/builtin/deviceinfokit/BUILD.gn | 5 +- .../src/nativeapi_ohos_deviceinfo.cpp | 444 ++++++++++++++++++ js/builtin/simulator/BUILD.gn | 5 +- 3 files changed, 452 insertions(+), 2 deletions(-) create mode 100644 js/builtin/deviceinfokit/src/nativeapi_ohos_deviceinfo.cpp diff --git a/js/builtin/deviceinfokit/BUILD.gn b/js/builtin/deviceinfokit/BUILD.gn index 9745f43..dc7d7ee 100644 --- a/js/builtin/deviceinfokit/BUILD.gn +++ b/js/builtin/deviceinfokit/BUILD.gn @@ -21,7 +21,10 @@ lite_library("ace_kit_deviceinfo") { } else { target_type = "shared_library" } - sources = [ "src/nativeapi_deviceinfo.cpp" ] + sources = [ + "src/nativeapi_deviceinfo.cpp", + "src/nativeapi_ohos_deviceinfo.cpp", + ] include_dirs = [ "include", diff --git a/js/builtin/deviceinfokit/src/nativeapi_ohos_deviceinfo.cpp b/js/builtin/deviceinfokit/src/nativeapi_ohos_deviceinfo.cpp new file mode 100644 index 0000000..c028d19 --- /dev/null +++ b/js/builtin/deviceinfokit/src/nativeapi_ohos_deviceinfo.cpp @@ -0,0 +1,444 @@ +/* + * Copyright (c) 2020 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 "global.h" +#include "nativeapi_common.h" +#include "nativeapi_config.h" +#include "parameter.h" +#include "sysversion.h" + +static constexpr int MAX_BUFFER = 65; +namespace OHOS { +namespace ACELite { +JSIValue JSGetDeviceType(void) +{ + const char *value = GetDeviceType(); + if (value == nullptr) { + value = ""; + } + + JSIValue deviceType = JSI::CreateString(value); + return deviceType; +} + +JSIValue JSGetManufacture(void) +{ + const char *value = GetManufacture(); + if (value == nullptr) { + value = ""; + } + + JSIValue manfactureName = JSI::CreateString(value); + return manfactureName; +} + +JSIValue JSGetBrand(void) +{ + const char *value = GetBrand(); + if (value == nullptr) { + value = ""; + } + + JSIValue productBrand = JSI::CreateString(value); + return productBrand; +} + +JSIValue JSGetMarketName(void) +{ + const char *value = GetMarketName(); + if (value == nullptr) { + value = ""; + } + + JSIValue marketName = JSI::CreateString(value); + return marketName; +} + +JSIValue JSGetProductSeries(void) +{ + const char *value = GetProductSeries(); + if (value == nullptr) { + value = ""; + } + + JSIValue productSeries = JSI::CreateString(value); + return productSeries; +} + +JSIValue JSGetProductModel(void) +{ + const char *value = GetProductModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue productModel = JSI::CreateString(value); + return productModel; +} + +JSIValue JSGetSoftwareModel(void) +{ + const char *value = GetSoftwareModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue softwareModel = JSI::CreateString(value); + return softwareModel; +} + +JSIValue JSGetHardwareModel(void) +{ + const char *value = GetHardwareModel(); + if (value == nullptr) { + value = ""; + } + + JSIValue hardwareModel = JSI::CreateString(value); + return hardwareModel; +} + +JSIValue JSGetHardwareProfile(void) +{ + const char *value = GetHardwareProfile(); + if (value == nullptr) { + value = ""; + } + + JSIValue hardwareProfile = JSI::CreateString(value); + return hardwareProfile; +} + +JSIValue JSGetSerial(void) +{ + const char *value = GetSerial(); + if (value == nullptr) { + value = ""; + } + + JSIValue serialNumber = JSI::CreateString(value); + return serialNumber; +} + +JSIValue JSGetBootloaderVersion(void) +{ + const char *value = GetBootloaderVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue bootloaderVersion = JSI::CreateString(value); + return bootloaderVersion; +} + +JSIValue JSGetAbiList(void) +{ + const char *value = GetAbiList(); + if (value == nullptr) { + value = ""; + } + + JSIValue abiList = JSI::CreateString(value); + return abiList; +} + +JSIValue JSGetSecurityPatchTag(void) +{ + const char *value = GetSecurityPatchTag(); + if (value == nullptr) { + value = ""; + } + + JSIValue securityPatchTag = JSI::CreateString(value); + return securityPatchTag; +} + +JSIValue JSGetDisplayVersion(void) +{ + const char *value = GetDisplayVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue productVersion = JSI::CreateString(value); + return productVersion; +} + +JSIValue JSGetIncrementalVersion(void) +{ + const char *value = GetIncrementalVersion(); + if (value == nullptr) { + value = ""; + } + + JSIValue incrementalVersion = JSI::CreateString(value); + return incrementalVersion; +} + +JSIValue JSGetOsReleaseType(void) +{ + const char *value = GetOsReleaseType(); + if (value == nullptr) { + value = ""; + } + + JSIValue osReleaseType = JSI::CreateString(value); + return osReleaseType; +} + +JSIValue JSGetOSFullName(void) +{ + const char *value = GetOSFullName(); + if (value == nullptr) { + value = ""; + } + JSIValue osVersion = JSI::CreateString(value); + return osVersion; +} + +JSIValue JSGetMajorVersion(void) +{ + int value = GetMajorVersion(); + JSIValue majorVersion = JSI::CreateUndefined(); + if (value < 0) { + return majorVersion; + } + + majorVersion = JSI::CreateString(std::to_string(value).c_str()); + return majorVersion; +} + +JSIValue JSGetSeniorVersion(void) +{ + int value = GetSeniorVersion(); + JSIValue seniorVersion = JSI::CreateUndefined(); + if (value < 0) { + return seniorVersion; + } + + seniorVersion = JSI::CreateString(std::to_string(value).c_str()); + return seniorVersion; +} + +JSIValue JSGetFeatureVersion(void) +{ + int value = GetFeatureVersion(); + JSIValue featureVersion = JSI::CreateUndefined(); + if (value < 0) { + return featureVersion; + } + + featureVersion = JSI::CreateString(std::to_string(value).c_str()); + return featureVersion; +} + +JSIValue JSGetBuildVersion(void) +{ + int value = GetBuildVersion(); + JSIValue buildVersion = JSI::CreateUndefined(); + if (value < 0) { + return buildVersion; + } + + buildVersion = JSI::CreateString(std::to_string(value).c_str()); + return buildVersion; +} + +JSIValue JSGetSdkApiVersion(void) +{ + int value = GetSdkApiVersion(); + JSIValue sdkApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return sdkApiVersion; + } + + sdkApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return sdkApiVersion; +} + +JSIValue JSGetFirstApiVersion(void) +{ + int value = GetFirstApiVersion(); + JSIValue firstApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return firstApiVersion; + } + + firstApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return firstApiVersion; +} + +JSIValue JSGetVersionId(void) +{ + const char *value = GetVersionId(); + if (value == nullptr) { + value = ""; + } + + JSIValue versionId = JSI::CreateString(value); + return versionId; +} + +JSIValue JSGetBuildType(void) +{ + const char *value = GetBuildType(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildType = JSI::CreateString(value); + return buildType; +} + +JSIValue JSGetBuildUser(void) +{ + const char *value = GetBuildUser(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildUser = JSI::CreateString(value); + return buildUser; +} + +JSIValue JSGetBuildHost(void) +{ + const char *value = GetBuildHost(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildHost = JSI::CreateString(value); + return buildHost; +} + +JSIValue JSGetBuildTime(void) +{ + const char *value = GetBuildTime(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildTime = JSI::CreateString(value); + return buildTime; +} + +JSIValue JSGetBuildRootHash(void) +{ + const char *value = GetBuildRootHash(); + if (value == nullptr) { + value = ""; + } + + JSIValue buildRootHash = JSI::CreateString(value); + return buildRootHash; +} + +JSIValue JSGetDevUdid(void) +{ + char buffer[MAX_BUFFER] = { 0 }; + int value = GetDevUdid(buffer, sizeof(buffer)); + JSIValue udid = JSI::CreateUndefined(); + if (value < 0) { + return udid; + } + + udid = JSI::CreateString(std::to_string(value).c_str()); + return udid; +} + +JSIValue JSGetDistributionOSName(void) +{ + const char *value = GetDistributionOSName(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSName = JSI::CreateString(value); + return distributionOSName; +} + +JSIValue JSGetDistributionOSVersion(void) +{ + const char *value = GetDistributionOSVersion(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSVersion = JSI::CreateString(value); + return distributionOSVersion; +} + +JSIValue JSGetDistributionOSApiVersion(void) +{ + int value = GetDistributionOSApiVersion(); + JSIValue distributionOSApiVersion = JSI::CreateUndefined(); + if (value < 0) { + return distributionOSApiVersion; + } + + distributionOSApiVersion = JSI::CreateString(std::to_string(value).c_str()); + return distributionOSApiVersion; +} + +JSIValue JSGetDistributionOSReleaseType(void) +{ + const char *value = GetDistributionOSReleaseType(); + if (value == nullptr) { + value = ""; + } + JSIValue distributionOSReleaseType = JSI::CreateString(value); + return distributionOSReleaseType; +} + +void InitDeviceInfoModule(JSIValue exports) +{ + JSI::SetNamedProperty(exports, "deviceType", JSGetDeviceType()); + JSI::SetNamedProperty(exports, "manufacture", JSGetManufacture()); + JSI::SetNamedProperty(exports, "brand", JSGetBrand()); + JSI::SetNamedProperty(exports, "marketName", JSGetMarketName()); + JSI::SetNamedProperty(exports, "productSeries", JSGetProductSeries()); + JSI::SetNamedProperty(exports, "productModel", JSGetProductModel()); + JSI::SetNamedProperty(exports, "softwareModel", JSGetSoftwareModel()); + JSI::SetNamedProperty(exports, "hardwareModel", JSGetHardwareModel()); + JSI::SetNamedProperty(exports, "hardwareProfile", JSGetHardwareProfile()); + JSI::SetNamedProperty(exports, "serial", JSGetSerial()); + JSI::SetNamedProperty(exports, "bootloaderVersion", JSGetBootloaderVersion()); + JSI::SetNamedProperty(exports, "abiList", JSGetAbiList()); + JSI::SetNamedProperty(exports, "securityPatchTag", JSGetSecurityPatchTag()); + JSI::SetNamedProperty(exports, "displayVersion", JSGetDisplayVersion()); + JSI::SetNamedProperty(exports, "incrementalVersion", JSGetIncrementalVersion()); + JSI::SetNamedProperty(exports, "osReleaseType", JSGetOsReleaseType()); + JSI::SetNamedProperty(exports, "osFullName", JSGetOSFullName()); + JSI::SetNamedProperty(exports, "majorVersion", JSGetMajorVersion()); + JSI::SetNamedProperty(exports, "seniorVersion", JSGetSeniorVersion()); + JSI::SetNamedProperty(exports, "featureVersion", JSGetFeatureVersion()); + JSI::SetNamedProperty(exports, "buildVersion", JSGetBuildVersion()); + JSI::SetNamedProperty(exports, "sdkApiVersion", JSGetSdkApiVersion()); + JSI::SetNamedProperty(exports, "firstApiVersion", JSGetFirstApiVersion()); + JSI::SetNamedProperty(exports, "versionId", JSGetVersionId()); + JSI::SetNamedProperty(exports, "buildType", JSGetBuildType()); + JSI::SetNamedProperty(exports, "buildUser", JSGetBuildUser()); + JSI::SetNamedProperty(exports, "buildHost", JSGetBuildHost()); + JSI::SetNamedProperty(exports, "buildTime", JSGetBuildTime()); + JSI::SetNamedProperty(exports, "buildRootHash", JSGetBuildRootHash()); + JSI::SetNamedProperty(exports, "udid", JSGetDevUdid()); + JSI::SetNamedProperty(exports, "distributionOSName", JSGetDistributionOSName()); + JSI::SetNamedProperty(exports, "distributionOSVersion", JSGetDistributionOSVersion()); + JSI::SetNamedProperty(exports, "distributionOSApiVersion", JSGetDistributionOSApiVersion()); + JSI::SetNamedProperty(exports, "distributionOSReleaseType", JSGetDistributionOSReleaseType()); +} +} // ACELite +} // OHOS diff --git a/js/builtin/simulator/BUILD.gn b/js/builtin/simulator/BUILD.gn index 5ceb891..85975de 100644 --- a/js/builtin/simulator/BUILD.gn +++ b/js/builtin/simulator/BUILD.gn @@ -35,7 +35,10 @@ ohos_static_library("ace_kit_deviceinfo_simulator") { "//foundation/arkui/ace_engine_lite/interfaces/inner_api/builtin", "//base/global/resource_management_lite/interfaces/inner_api/include", ] - sources = [ "//commonlibrary/utils_lite/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp" ] + sources = [ + "//commonlibrary/utils_lite/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp", + "//commonlibrary/utils_lite/js/builtin/deviceinfokit/src/nativeapi_ohos_deviceinfo.cpp", + ] deps = [ "//foundation/arkui/ace_engine_lite/frameworks/targets/simulator:ace_lite", "//foundation/arkui/ui_lite/ext/ide:ui_ide", -- Gitee