From dcf585ad84e63276bc70a57d047a4bd3a7f47aa1 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Tue, 17 Oct 2023 11:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8DL0=20L1=20deviceInfo=20NAPI?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhongning5 Change-Id: Ib02576eb8d89ccc99eb637adbd24d47fd2709106 --- .../include/nativeapi_deviceinfo.h | 32 ++ .../src/nativeapi_deviceinfo.cpp | 433 ++++++++++++++++-- 2 files changed, 420 insertions(+), 45 deletions(-) diff --git a/js/builtin/deviceinfokit/include/nativeapi_deviceinfo.h b/js/builtin/deviceinfokit/include/nativeapi_deviceinfo.h index 977a083..12b3a27 100644 --- a/js/builtin/deviceinfokit/include/nativeapi_deviceinfo.h +++ b/js/builtin/deviceinfokit/include/nativeapi_deviceinfo.h @@ -33,6 +33,38 @@ private: static bool GetRegion(JSIValue result); static bool GetAPILevel(JSIValue result); static bool GetDeviceType(JSIValue result); + static bool GetManufacture(JSIValue result); + static bool GetBrand(JSIValue result); + static bool GetMarketName(JSIValue result); + static bool GetProductSeries(JSIValue result); + static bool GetProductModel(JSIValue result); + static bool GetSoftwareModel(JSIValue result); + static bool GetHardwareModel(JSIValue result); + static bool GetHardwareProfile(JSIValue result); + static bool GetSerial(JSIValue result); + static bool GetBootloaderVersion(JSIValue result); + static bool GetAbiList(JSIValue result); + static bool GetSecurityPatchTag(JSIValue result); + static bool GetDisplayVersion(JSIValue result); + static bool GetIncrementalVersion(JSIValue result); + static bool GetOsReleaseType(JSIValue result); + static bool GetOSFullName(JSIValue result); + static bool GetMajorVersion(JSIValue result); + static bool GetSeniorVersion(JSIValue result); + static bool GetFeatureVersion(JSIValue result); + static bool GetBuildVersion(JSIValue result); + static bool GetFirstApiVersion(JSIValue result); + static bool GetVersionId(JSIValue result); + static bool GetBuildType(JSIValue result); + static bool GetBuildUser(JSIValue result); + static bool GetBuildHost(JSIValue result); + static bool GetBuildTime(JSIValue result); + static bool GetBuildRootHash(JSIValue result); + static bool GetDevUdid(JSIValue result); + static bool GetDistributionOSName(JSIValue result); + static bool GetDistributionOSVersion(JSIValue result); + static bool GetDistributionOSApiVersion(JSIValue result); + static bool GetDistributionOSReleaseType(JSIValue result); }; } // ACELite } // OHOS diff --git a/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp b/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp index 0291b2e..8c63919 100644 --- a/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp +++ b/js/builtin/deviceinfokit/src/nativeapi_deviceinfo.cpp @@ -21,8 +21,11 @@ #include "nativeapi_common.h" #include "nativeapi_config.h" #include "parameter.h" +#include "sysversion.h" #include "common/screen.h" + +static constexpr int MAX_BUFFER = 65; namespace OHOS { namespace ACELite { namespace { @@ -64,33 +67,402 @@ void ExecuteGetInfo(void* data) } } -void InitDeviceModule(JSIValue exports) +JSIValue NativeapiDeviceInfo::GetDeviceInfo(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) { - JSI::SetModuleAPI(exports, "getInfo", NativeapiDeviceInfo::GetDeviceInfo); + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetInfo); +} + +bool NativeapiDeviceInfo::GetProductInfo(JSIValue result) +{ + bool isSuccess = true; + if (!NativeapiDeviceInfo::GetDeviceType(result) || + !NativeapiDeviceInfo::GetManufacture(result)|| + !NativeapiDeviceInfo::GetBrand(result)|| + !NativeapiDeviceInfo::GetMarketName(result)|| + !NativeapiDeviceInfo::GetProductSeries(result)|| + !NativeapiDeviceInfo::GetProductModel(result)|| + !NativeapiDeviceInfo::GetSoftwareModel(result)|| + !NativeapiDeviceInfo::GetHardwareModel(result)|| + !NativeapiDeviceInfo::GetHardwareProfile(result)|| + !NativeapiDeviceInfo::GetSerial(result)|| + !NativeapiDeviceInfo::GetBootloaderVersion(result)|| + !NativeapiDeviceInfo::GetAbiList(result)|| + !NativeapiDeviceInfo::GetSecurityPatchTag(result)|| + !NativeapiDeviceInfo::GetDisplayVersion(result)|| + !NativeapiDeviceInfo::GetIncrementalVersion(result)|| + !NativeapiDeviceInfo::GetOsReleaseType(result)|| + !NativeapiDeviceInfo::GetOSFullName(result)|| + !NativeapiDeviceInfo::GetMajorVersion(result)|| + !NativeapiDeviceInfo::GetSeniorVersion(result)|| + !NativeapiDeviceInfo::GetFeatureVersion(result)|| + !NativeapiDeviceInfo::GetBuildVersion(result)|| + !NativeapiDeviceInfo::GetAPILevel(result)|| + !NativeapiDeviceInfo::GetFirstApiVersion(result)|| + !NativeapiDeviceInfo::GetVersionId(result)|| + !NativeapiDeviceInfo::GetBuildType(result)|| + !NativeapiDeviceInfo::GetBuildUser(result)|| + !NativeapiDeviceInfo::GetBuildHost(result)|| + !NativeapiDeviceInfo::GetBuildTime(result)|| + !NativeapiDeviceInfo::GetBuildRootHash(result)|| + !NativeapiDeviceInfo::GetDevUdid(result)|| + !NativeapiDeviceInfo::GetDistributionOSName(result)|| + !NativeapiDeviceInfo::GetDistributionOSVersion(result)|| + !NativeapiDeviceInfo::GetDistributionOSApiVersion(result)|| + !NativeapiDeviceInfo::GetDistributionOSReleaseType(result)|| + !NativeapiDeviceInfo::GetLanguage(result) || + !NativeapiDeviceInfo::GetRegion(result)) { + isSuccess = false; + } + + Screen &screen = Screen::GetInstance(); + JSI::SetNumberProperty(result, "windowWidth", static_cast(screen.GetWidth())); + JSI::SetNumberProperty(result, "windowHeight", static_cast(screen.GetHeight())); + // set default value + const uint8_t defaultScreenDensity = 195; + const char * const defaultScreenShape = "rect"; + JSI::SetNumberProperty(result, "screenDensity", static_cast(defaultScreenDensity)); + JSI::SetStringProperty(result, "screenShape", defaultScreenShape); + return isSuccess; +} + +bool NativeapiDeviceInfo::GetDeviceType(JSIValue result) +{ + const char* deviceType = ::GetDeviceType(); + if (deviceType == nullptr) { + return false; + } + JSI::SetStringProperty(result, "deviceType", deviceType); + return true; +} + +bool NativeapiDeviceInfo::GetManufacture(JSIValue result) +{ + const char* manufacture = ::GetManufacture(); + if (manufacture == nullptr) { + return false; + } + JSI::SetStringProperty(result, "manufacture", manufacture); + return true; +} + +bool NativeapiDeviceInfo::GetBrand(JSIValue result) +{ + const char* brand = ::GetBrand(); + if (brand == nullptr) { + return false; + } + JSI::SetStringProperty(result, "brand", brand); + return true; +} + +bool NativeapiDeviceInfo::GetMarketName(JSIValue result) +{ + const char* marketName = ::GetMarketName(); + if (marketName == nullptr) { + return false; + } + JSI::SetStringProperty(result, "marketName", marketName); + return true; +} + +bool NativeapiDeviceInfo::GetProductSeries(JSIValue result) +{ + const char* productSeries = ::GetProductSeries(); + if (productSeries == nullptr) { + return false; + } + JSI::SetStringProperty(result, "productSeries", productSeries); + return true; +} + +bool NativeapiDeviceInfo::GetProductModel(JSIValue result) +{ + const char* productModel = ::GetProductModel(); + if (productModel == nullptr) { + return false; + } + JSI::SetStringProperty(result, "productModel", productModel); + return true; +} + +bool NativeapiDeviceInfo::GetSoftwareModel(JSIValue result) +{ + const char* softwareModel = ::GetSoftwareModel(); + if (softwareModel == nullptr) { + return false; + } + JSI::SetStringProperty(result, "softwareModel", softwareModel); + return true; +} + +bool NativeapiDeviceInfo::GetHardwareModel(JSIValue result) +{ + const char* hardwareModel = ::GetHardwareModel(); + if (hardwareModel == nullptr) { + return false; + } + JSI::SetStringProperty(result, "hardwareModel", hardwareModel); + return true; +} + +bool NativeapiDeviceInfo::GetHardwareProfile(JSIValue result) +{ + const char* hardwareProfile = ::GetHardwareProfile(); + if (hardwareProfile == nullptr) { + return false; + } + JSI::SetStringProperty(result, "hardwareProfile", hardwareProfile); + return true; +} + +bool NativeapiDeviceInfo::GetSerial(JSIValue result) +{ + const char* serial = ::GetSerial(); + if (serial == nullptr) { + return false; + } + JSI::SetStringProperty(result, "serial", serial); + return true; +} + +bool NativeapiDeviceInfo::GetBootloaderVersion(JSIValue result) +{ + const char* bootloaderVersion = ::GetBootloaderVersion(); + if (bootloaderVersion == nullptr) { + return false; + } + JSI::SetStringProperty(result, "bootloaderVersion", bootloaderVersion); + return true; +} + +bool NativeapiDeviceInfo::GetAbiList(JSIValue result) +{ + const char* abiList = ::GetAbiList(); + if (abiList == nullptr) { + return false; + } + JSI::SetStringProperty(result, "abiList", abiList); + return true; +} + +bool NativeapiDeviceInfo::GetSecurityPatchTag(JSIValue result) +{ + const char* securityPatchTag = ::GetSecurityPatchTag(); + if (securityPatchTag == nullptr) { + return false; + } + JSI::SetStringProperty(result, "securityPatchTag", securityPatchTag); + return true; +} + +bool NativeapiDeviceInfo::GetDisplayVersion(JSIValue result) +{ + const char* displayVersion = ::GetDisplayVersion(); + if (displayVersion == nullptr) { + return false; + } + JSI::SetStringProperty(result, "displayVersion", displayVersion); + return true; +} + +bool NativeapiDeviceInfo::GetIncrementalVersion(JSIValue result) +{ + const char* incrementalVersion = ::GetIncrementalVersion(); + if (incrementalVersion == nullptr) { + return false; + } + JSI::SetStringProperty(result, "incrementalVersion", incrementalVersion); + return true; +} + +bool NativeapiDeviceInfo::GetOsReleaseType(JSIValue result) +{ + const char* osReleaseType = ::GetOsReleaseType(); + if (osReleaseType == nullptr) { + return false; + } + JSI::SetStringProperty(result, "osReleaseType", osReleaseType); + return true; +} + +bool NativeapiDeviceInfo::GetOSFullName(JSIValue result) +{ + const char* osFullName = ::GetOSFullName(); + if (osFullName == nullptr) { + return false; + } + JSI::SetStringProperty(result, "osFullName", osFullName); + return true; +} + +bool NativeapiDeviceInfo::GetMajorVersion(JSIValue result) +{ + int majorVersion = ::GetMajorVersion(); + if (majorVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "majorVersion", std::to_string(majorVersion).c_str()); + return true; +} + +bool NativeapiDeviceInfo::GetSeniorVersion(JSIValue result) +{ + int seniorVersion = ::GetSeniorVersion(); + if (seniorVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "seniorVersion", std::to_string(seniorVersion).c_str()); + return true; +} + +bool NativeapiDeviceInfo::GetFeatureVersion(JSIValue result) +{ + int featureVersion = ::GetFeatureVersion(); + if (featureVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "featureVersion", std::to_string(featureVersion).c_str()); + return true; +} + +bool NativeapiDeviceInfo::GetBuildVersion(JSIValue result) +{ + int buildVersion = ::GetBuildVersion(); + if (buildVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "buildVersion", std::to_string(buildVersion).c_str()); + return true; } bool NativeapiDeviceInfo::GetAPILevel(JSIValue result) { - int apiLevel = GetSdkApiVersion(); - if (apiLevel < 1) { + int sdkApiVersion = ::GetSdkApiVersion(); + if (sdkApiVersion < 0) { return false; } - JSI::SetStringProperty(result, "apiVersion", std::to_string(apiLevel).c_str()); + JSI::SetStringProperty(result, "apiVersion", std::to_string(sdkApiVersion).c_str()); return true; } -JSIValue NativeapiDeviceInfo::GetDeviceInfo(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) +bool NativeapiDeviceInfo::GetFirstApiVersion(JSIValue result) { - return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetInfo); + int firstApiVersion = ::GetFirstApiVersion(); + if (firstApiVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "firstApiVersion", std::to_string(firstApiVersion).c_str()); + return true; } -bool NativeapiDeviceInfo::GetDeviceType(JSIValue result) +bool NativeapiDeviceInfo::GetVersionId(JSIValue result) { - const char* deviceType = ::GetDeviceType(); - if (deviceType == nullptr) { + const char* versionId = ::GetVersionId(); + if (versionId == nullptr) { return false; } - JSI::SetStringProperty(result, "deviceType", deviceType); + JSI::SetStringProperty(result, "versionId", versionId); + return true; +} + +bool NativeapiDeviceInfo::GetBuildType(JSIValue result) +{ + const char* buildType = ::GetBuildType(); + if (buildType == nullptr) { + return false; + } + JSI::SetStringProperty(result, "buildType", buildType); + return true; +} + +bool NativeapiDeviceInfo::GetBuildUser(JSIValue result) +{ + const char* buildUser = ::GetBuildUser(); + if (buildUser == nullptr) { + return false; + } + JSI::SetStringProperty(result, "buildUser", buildUser); + return true; +} + +bool NativeapiDeviceInfo::GetBuildHost(JSIValue result) +{ + const char* buildHost = ::GetBuildHost(); + if (buildHost == nullptr) { + return false; + } + JSI::SetStringProperty(result, "buildHost", buildHost); + return true; +} + +bool NativeapiDeviceInfo::GetBuildTime(JSIValue result) +{ + const char* buildTime = ::GetBuildTime(); + if (buildTime == nullptr) { + return false; + } + JSI::SetStringProperty(result, "buildTime", buildTime); + return true; +} + +bool NativeapiDeviceInfo::GetBuildRootHash(JSIValue result) +{ + const char* buildRootHash = ::GetBuildRootHash(); + if (buildRootHash == nullptr) { + return false; + } + JSI::SetStringProperty(result, "buildRootHash", buildRootHash); + return true; +} + +bool NativeapiDeviceInfo::GetDevUdid(JSIValue result) +{ + char buffer[MAX_BUFFER] = { 0 }; + int devUdid = ::GetDevUdid(buffer, sizeof(buffer)); + if (devUdid < 0) { + return false; + } + JSI::SetStringProperty(result, "devUdid", std::to_string(devUdid).c_str()); + return true; +} + +bool NativeapiDeviceInfo::GetDistributionOSName(JSIValue result) +{ + const char* distributionOSName = ::GetDistributionOSName(); + if (distributionOSName == nullptr) { + return false; + } + JSI::SetStringProperty(result, "distributionOSName", distributionOSName); + return true; +} + +bool NativeapiDeviceInfo::GetDistributionOSVersion(JSIValue result) +{ + const char* distributionOSVersion = ::GetDistributionOSVersion(); + if (distributionOSVersion == nullptr) { + return false; + } + JSI::SetStringProperty(result, "distributionOSVersion", distributionOSVersion); + return true; +} + +bool NativeapiDeviceInfo::GetDistributionOSApiVersion(JSIValue result) +{ + int distributionOSApiVersion = ::GetDistributionOSApiVersion(); + if (distributionOSApiVersion < 0) { + return false; + } + JSI::SetStringProperty(result, "distributionOSApiVersion", std::to_string(distributionOSApiVersion).c_str()); + return true; +} + +bool NativeapiDeviceInfo::GetDistributionOSReleaseType(JSIValue result) +{ + const char* distributionOSReleaseType = ::GetDistributionOSReleaseType(); + if (distributionOSReleaseType == nullptr) { + return false; + } + JSI::SetStringProperty(result, "distributionOSReleaseType", distributionOSReleaseType); return true; } @@ -106,40 +478,6 @@ bool NativeapiDeviceInfo::GetLanguage(JSIValue result) return true; } -bool NativeapiDeviceInfo::GetProductInfo(JSIValue result) -{ - bool isSuccess = true; - const char* brand = GetBrand(); - const char* manufacture = GetManufacture(); - const char* model = GetProductModel(); - if (brand == nullptr || manufacture == nullptr || model == nullptr) { - isSuccess = false; - } else { - JSI::SetStringProperty(result, "brand", brand); - JSI::SetStringProperty(result, "manufacturer", manufacture); - JSI::SetStringProperty(result, "model", model); - JSI::SetStringProperty(result, "product", model); - } - if (isSuccess) { - if (!NativeapiDeviceInfo::GetDeviceType(result) || - !NativeapiDeviceInfo::GetLanguage(result) || - !NativeapiDeviceInfo::GetAPILevel(result) || - !NativeapiDeviceInfo::GetRegion(result)) { - isSuccess = false; - } - } - - Screen &screen = Screen::GetInstance(); - JSI::SetNumberProperty(result, "windowWidth", static_cast(screen.GetWidth())); - JSI::SetNumberProperty(result, "windowHeight", static_cast(screen.GetHeight())); - // set default value - const uint8_t defaultScreenDensity = 195; - const char * const defaultScreenShape = "rect"; - JSI::SetNumberProperty(result, "screenDensity", static_cast(defaultScreenDensity)); - JSI::SetStringProperty(result, "screenShape", defaultScreenShape); - return isSuccess; -} - bool NativeapiDeviceInfo::GetRegion(JSIValue result) { // because of MAX_REGION_LENGTH is little,we use array instead of pointer @@ -151,5 +489,10 @@ bool NativeapiDeviceInfo::GetRegion(JSIValue result) } return true; } + +void InitDeviceModule(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "getInfo", NativeapiDeviceInfo::GetDeviceInfo); +} } // ACELite } // OHOS -- Gitee