diff --git a/uni_modules/uni-getSystemInfo/changelog.md b/uni_modules/uni-getSystemInfo/changelog.md new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/uni_modules/uni-getSystemInfo/package.json b/uni_modules/uni-getSystemInfo/package.json new file mode 100644 index 0000000000000000000000000000000000000000..2a56778c2aead29c1730806451efbbd0db080878 --- /dev/null +++ b/uni_modules/uni-getSystemInfo/package.json @@ -0,0 +1,109 @@ +{ + "id": "uni-getSystemInfo", + "displayName": "uni-getSystemInfo", + "version": "1.0.0", + "description": "uni-getSystemInfo", + "keywords": [ + "uni-getSystemInfo" +], + "repository": "", + "engines": { + "HBuilderX": "^3.6.8" + }, + "dcloudext": { + "type": "uts", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "", + "data": "", + "permissions": "" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "uni-ext-api": { + "uni": { + "getSystemInfo": { + "name": "getSystemInfo", + "app": { + "js": false, + "kotlin": true, + "swift": false + } + }, + "getSystemInfoSync":{ + "name": "getSystemInfoSync", + "app": { + "js": false, + "kotlin": true, + "swift": false + } + }, + "getWindowInfo":{ + "name": "getWindowInfo", + "app": { + "js": false, + "kotlin": true, + "swift": false + } + } + } + }, + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u" + }, + "client": { + "Vue": { + "vue2": "u", + "vue3": "u" + }, + "App": { + "app-android": "u", + "app-ios": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "u", + "QQ浏览器(Android)": "u" + }, + "H5-pc": { + "Chrome": "u", + "IE": "u", + "Edge": "u", + "Firefox": "u", + "Safari": "u" + }, + "小程序": { + "微信": "u", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-getSystemInfo/readme.md b/uni_modules/uni-getSystemInfo/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..0c4f58dc70b8f0e8a1cf670fd7b3554dab89b6b4 --- /dev/null +++ b/uni_modules/uni-getSystemInfo/readme.md @@ -0,0 +1,6 @@ +# uni-getSystemInfo +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts) \ No newline at end of file diff --git a/uni_modules/uni-getSystemInfo/utssdk/app-android/device/SystemInfoDeviceUtil.uts b/uni_modules/uni-getSystemInfo/utssdk/app-android/device/SystemInfoDeviceUtil.uts new file mode 100644 index 0000000000000000000000000000000000000000..6c4bc47645ae95bf5dcf77224719ac8520de67fc --- /dev/null +++ b/uni_modules/uni-getSystemInfo/utssdk/app-android/device/SystemInfoDeviceUtil.uts @@ -0,0 +1,330 @@ +import Activity from 'android.app.Activity'; +import Configuration from 'android.content.res.Configuration'; +import Context from 'android.content.Context'; +import UiModeManager from 'android.app.UiModeManager'; +import WindowManager from 'android.view.WindowManager'; +import DisplayMetrics from 'android.util.DisplayMetrics'; +import Build from 'android.os.Build'; +import File from 'java.io.File'; + +import TextUtils from 'android.text.TextUtils'; + +import { UTSAndroid as Device } from "io.dcloud.uts"; +import BufferedReader from 'java.io.BufferedReader'; +import InputStreamReader from 'java.io.InputStreamReader'; +import UTSAndroid from 'io.dcloud.uts.UTSAndroid'; + + +export class DeviceUtil { + + private static customOS : string | null = null + private static customOSVersion : string | null = null + + private static readonly rootRelatedDirs = [ + "/su", "/su/bin/su", "/sbin/su", + "/data/local/xbin/su", "/data/local/bin/su", "/data/local/su", + "/system/xbin/su", + "/system/bin/su", "/system/sd/xbin/su", "/system/bin/failsafe/su", + "/system/bin/cufsdosck", "/system/xbin/cufsdosck", "/system/bin/cufsmgr", + "/system/xbin/cufsmgr", "/system/bin/cufaevdd", "/system/xbin/cufaevdd", + "/system/bin/conbb", "/system/xbin/conbb"]; + + + /** + * HarmonyOS 系统输出的 + * 格式:2.0.0 + */ + private static KEY_HARMONYOS_VERSION_NAME = "hw_sc.build.platform.version"; + + /** + * EMUI系统输出的 + * 格式:EmotionUI_8.0.0 + */ + private static KEY_EMUI_VERSION_NAME = "ro.build.version.emui"; + + /** + * MagicUI系统输出的 + * 格式:3.1.0 + */ + private static KEY_MAGICUI_VERSION = "ro.build.version.magic"; + + /** + * MIUI系统输出的 + * 格式:V12 + */ + private static KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name"; + + /** + * OPPO手机ColorOS系统输出的 + * 格式:9 + */ + private static KEY_COLOROS_VERSION_NAME = "ro.build.version.opporom"; + + /** + * VIVO手机系统输出的 + * name格式:funtouch + * version格式: 9 + */ + private static KEY_VIVO_VERSION_NAME = "ro.vivo.os.name"; + private static KEY_VIVO_VERSION = "ro.vivo.os.version"; + + /** + * OonPlus手机系统输出的 + * 格式:Hydrogen OS 11.0.7.10.KB05 + */ + private static KEY_ONEPLUS_VERSION_NAME = "ro.rom.version"; + + /** + * 魅族手机系统输出的 + */ + private static KEY_FLYME_VERSION_NAME = "ro.build.display.id"; + + /** + * nubia手机系统输出的 + */ + private static KEY_NUBIA_VERSION_NAME = "ro.build.nubia.rom.name"; + private static KEY_NUBIA_VERSION_CODE = "ro.build.nubia.rom.code"; + + + + public static getOrientation(activity : Activity) : string { + const activityOrientation = activity.getResources().getConfiguration().orientation; + let outOrientation = "portrait"; + if (activityOrientation == Configuration.ORIENTATION_LANDSCAPE) { + outOrientation = "landscape"; + } + return outOrientation; + } + + public static getAppVersionCode():number{ + const activity = UTSAndroid.getUniActivity()!!; + const packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0); + return packageInfo.versionCode; + } + + /** + * 获取屏幕像素比 + */ + public static getScaledDensity(activity : Activity) : number { + const windowManager = activity.getSystemService(Context.WINDOW_SERVICE) as WindowManager; + const displayMetrics = new DisplayMetrics(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + windowManager.getDefaultDisplay().getRealMetrics(displayMetrics); + } else { + windowManager.getDefaultDisplay().getMetrics(displayMetrics); + } + return displayMetrics.scaledDensity; + } + + public static getScreenWidth() : number { + return UTSAndroid.getScreenInfo()["screenWidth"] as Int; + } + + public static getScreenHeight() : number { + return UTSAndroid.getScreenInfo()["screenHeight"] as Int; + } + + public static getStatusBarHeight():number { + return UTSAndroid.getStatusBarHeight(); + } + + public static getRomName():string{ + DeviceUtil.setCustomInfo(Build.MANUFACTURER); + return DeviceUtil.customOS ?? ""; + } + public static getRomVersion():string{ + DeviceUtil.setCustomInfo(Build.MANUFACTURER); + return DeviceUtil.customOSVersion ?? ""; + } + + public static getSystemUIModeType(activity : Activity) : string { + + let uiModeManager = activity.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager; + let modeType = "unknown"; + + switch (uiModeManager.getCurrentModeType()) { + case Configuration.UI_MODE_TYPE_TELEVISION: + modeType = "tv"; + break; + case Configuration.UI_MODE_TYPE_WATCH: + modeType = "watch"; + break; + case Configuration.UI_MODE_TYPE_NORMAL: + if (DeviceUtil.isTablet(activity)) { + modeType = "pad"; + } else { + modeType = "phone"; + } + break; + case Configuration.UI_MODE_TYPE_DESK: + modeType = "pc"; + break; + case Configuration.UI_MODE_TYPE_UNDEFINED: + modeType = "undefined"; + break; + case Configuration.UI_MODE_TYPE_CAR: + modeType = "car"; + break; + case Configuration.UI_MODE_TYPE_VR_HEADSET: + modeType = "vr"; + break; + case Configuration.UI_MODE_TYPE_APPLIANCE: + modeType = "appliance"; + break; + } + + return modeType; + } + + + public static getOsLanguageNormal(context : Context) : string { + const LOCALE_ZH_HANS = 'zh-Hans' + const LOCALE_ZH_HANT = 'zh-Hant' + let locale = Device.getLanguageInfo(context)["appLanguage"].toString(); + if (locale.indexOf('zh') === 0) { + if (locale.indexOf('-hans') > -1) { + return LOCALE_ZH_HANS; + } + if (locale.indexOf('-hant') > -1) { + return LOCALE_ZH_HANT; + } + if (locale.includes("-tw") || locale.includes("-hk") || locale.includes("-mo") || locale.includes("-cht")) { + return LOCALE_ZH_HANT; + } + + return LOCALE_ZH_HANS; + } else { + return locale; + } + } + + /** + * 是否为平板 不是太准确 + */ + public static isTablet(activity : Activity) : boolean { + return (activity.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; + } + + + + private static setCustomInfo(phoneBrand : string) { + try { + switch (DeviceUtil.deleteSpaceAndToUpperCase(phoneBrand)) { + case "HUAWEI": + if (DeviceUtil.isHarmonyOS()) { + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_HARMONYOS_VERSION_NAME); + DeviceUtil.customOS = "HarmonyOS"; + } else { + DeviceUtil.customOS = "EMUI"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_EMUI_VERSION_NAME);; + } + break; + case "HONOR": + if (DeviceUtil.isHarmonyOS()) { + DeviceUtil.customOS = "HarmonyOS"; + if (!TextUtils.isEmpty(DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_HARMONYOS_VERSION_NAME))) { + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_HARMONYOS_VERSION_NAME);; + } else { + DeviceUtil.customOSVersion = ""; + } + } else if (!TextUtils.isEmpty(DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_MAGICUI_VERSION))) { + DeviceUtil.customOS = "MagicUI"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_MAGICUI_VERSION); + } else { + //格式:EmotionUI_8.0.0 + DeviceUtil.customOS = "EMUI"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_EMUI_VERSION_NAME); + } + break; + case "XIAOMI": + case "REDMI": + //格式:MIUIV12 + DeviceUtil.customOS = "MIUI"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_MIUI_VERSION_NAME); + break; + case "REALME": + case "OPPO": + //格式:ColorOSV2.1 + DeviceUtil.customOS = "ColorOS"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_COLOROS_VERSION_NAME); + break; + case "VIVO": + //格式:Funtouch9 + DeviceUtil.customOS = "Funtouch"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_VIVO_VERSION); + break; + case "ONEPLUS": + //格式:Hydrogen OS 11.0.7.10.KB05 + DeviceUtil.customOS = "HydrogenOS"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_ONEPLUS_VERSION_NAME); + break; + case "MEIZU": + //格式:Flyme 6.3.5.1G + DeviceUtil.customOS = "Flyme"; + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_FLYME_VERSION_NAME); + break; + case "NUBIA": + //格式:nubiaUIV3.0 + DeviceUtil.customOS = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_NUBIA_VERSION_NAME); + DeviceUtil.customOSVersion = DeviceUtil.getSystemPropertyValue(DeviceUtil.KEY_NUBIA_VERSION_CODE); + break; + default: + DeviceUtil.customOS = "Android"; + DeviceUtil.customOSVersion = Build.VERSION.RELEASE; + break; + } + } catch (e : Exception) { + } + } + + + + /** + * 判断是否是华为鸿蒙系统,能否识别荣耀鸿蒙未知 + * + * @return + */ + private static isHarmonyOS() : boolean { + try { + let classType = Class.forName("com.huawei.system.BuildEx"); + let getMethod = classType.getMethod("getOsBrand"); + let value = getMethod.invoke(classType) as string; + return !TextUtils.isEmpty(value); + } catch (e : Exception) { + return false; + } + } + + + + + + + /** + * 删除字符串中的空格并全部转成大写 + * @param str + * @return + */ + public static deleteSpaceAndToUpperCase(str : string | null) : string { + if (TextUtils.isEmpty(str)) { + return ""; + } + return str!.replace(" ", "").toUpperCase(); + } + + private static getSystemPropertyValue(propName : string) : string | null { + let value : string | null = null; + let roSecureObj : any | null; + try { + // Class.forName("java.lang.String") + const method = Class.forName("android.os.SystemProperties").getMethod("get", Class.forName("java.lang.String")); + roSecureObj = method.invoke(null, propName); + if (roSecureObj != null) { + value = roSecureObj as string; + } + } catch (e : Exception) { + } + return value; + } +} \ No newline at end of file diff --git a/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts b/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..9ad2c57bc39f06d40bafa8968b3d5796b6a26760 --- /dev/null +++ b/uni_modules/uni-getSystemInfo/utssdk/app-android/index.uts @@ -0,0 +1,249 @@ +import { GetSystemInfoOptions, GetSystemInfo, GetSystemInfoResult, SafeArea, SafeAreaInsets, GetSystemInfoSync, GetWindowInfo, GetWindowInfoResult } from "../interface.uts"; +import UTSAndroid from 'io.dcloud.uts.UTSAndroid'; +import PackageManager from 'android.content.pm.PackageManager'; +import Build from 'android.os.Build'; +import { DeviceUtil } from './device/SystemInfoDeviceUtil.uts' +import CountDownLatch from 'java.util.concurrent.CountDownLatch'; +import Looper from 'android.os.Looper'; +import Handler from 'android.os.Handler'; + +export const getSystemInfo : GetSystemInfo = function (options : GetSystemInfoOptions) { + const result = getSystemInfoSync(); + const success = options.success; + const complete = options.complete; + success?.(result); + complete?.(result); +} + + +export const getSystemInfoSync : GetSystemInfoSync = function () : GetSystemInfoResult { + const runnable = function(): GetSystemInfoResult | null{ + try { + const activity = UTSAndroid.getUniActivity()!!; + + const appId = UTSAndroid.getAppId(); + const appLanguage = DeviceUtil.getOsLanguageNormal(activity); + const appName = UTSAndroid.getAppName(); + const appVersion = UTSAndroid.getAppVersion()["name"].toString(); + const appVersionCode = UTSAndroid.getAppVersion()["code"].toString(); + const appWgtVersion = !UTSAndroid.isUniAppX()? UTSAndroid.getAppVersion()["name"].toString() : null; + const brand = Build.MANUFACTURER.toLowerCase(); + const browserName = UTSAndroid.getWebViewInfo(activity)["kernel"].toString(); + const browserVersion = UTSAndroid.getWebViewInfo(activity)["version"].toString(); + const deviceId = UTSAndroid.getDeviceID(activity); + const deviceModel = Build.MODEL; + const deviceType = DeviceUtil.getSystemUIModeType(activity); + const devicePixelRatio = DeviceUtil.getScaledDensity(activity); + const deviceOrientation = DeviceUtil.getOrientation(activity); + const language = UTSAndroid.getLanguageInfo(activity)["osLanguage"].toString(); + const osName = "android"; + const osVersion = Build.VERSION.RELEASE; + const osLanguage = UTSAndroid.getLanguageInfo(activity)["osLanguage"].toString(); + const osTheme = UTSAndroid.getOsTheme(); + const pixelRatio = DeviceUtil.getScaledDensity(activity) + const screenWidth = DeviceUtil.getScreenWidth(); + const screenHeight = DeviceUtil.getScreenHeight(); + const statusBarHeight = DeviceUtil.getStatusBarHeight(); + const system = "Android " + Build.VERSION.RELEASE; + const ua = UTSAndroid.getWebViewInfo(activity)["ua"].toString(); + const uniCompileVersion = UTSAndroid.getUniCompileVersion(); + const uniPlatform = "app"; + const uniRuntimeVersion = UTSAndroid.getUniRuntimeVersion(); + const uniCompileVersionCode = convertVersionCode(uniCompileVersion); + const uniRuntimeVersionCode = convertVersionCode(uniRuntimeVersion); + const version = UTSAndroid.getInnerVersion(); + const romName = DeviceUtil.getRomName(); + const romVersion = DeviceUtil.getRomVersion(); + const windowWidth = screenWidth; + const windowHeight = UTSAndroid.getWindowHeight(); + const windowTop = 0; + const windowBottom = 0; + const safeAreaInsetsTop = UTSAndroid.getSafeAreaInsets()["top"].toString().toInt(); + const safeAreaInsets : SafeAreaInsets = { + left: 0, + top: safeAreaInsetsTop, + right: 0, + bottom: 0 + } + + const safeArea : SafeArea = { + left: safeAreaInsets.left, + right: windowWidth - safeAreaInsets.right, + top: safeAreaInsets.top, + bottom: windowHeight - safeAreaInsets.bottom, + width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, + height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom + } + const osAndroidAPILevel = Build.VERSION.SDK_INT; + const oaid = UTSAndroid.getOAID(); + + const result = { + SDKVersion: "", + appId: appId, + appLanguage: appLanguage, + appName: appName, + appVersion: appVersion, + appVersionCode: appVersionCode, + appWgtVersion: appWgtVersion, + brand: brand, + browserName: browserName, + browserVersion: browserVersion, + deviceId: deviceId, + deviceBrand: brand, + deviceModel: deviceModel, + deviceType: deviceType, + devicePixelRatio: devicePixelRatio, + deviceOrientation: deviceOrientation, + language: language, + model: deviceModel, + osName: osName, + osVersion: osVersion, + osLanguage: osLanguage, + osTheme: osTheme, + pixelRatio: pixelRatio, + platform: osName, + screenWidth: screenWidth, + screenHeight: screenHeight, + statusBarHeight: statusBarHeight, + system: system, + ua: ua, + uniCompileVersion: uniCompileVersion, + uniPlatform: uniPlatform, + uniRuntimeVersion: uniRuntimeVersion, + uniCompileVersionCode: uniCompileVersionCode, + uniRuntimeVersionCode: uniRuntimeVersionCode, + version: version, + romName: romName, + romVersion: romVersion, + windowWidth: windowWidth, + windowHeight: windowHeight, + windowTop: windowTop, + windowBottom: windowBottom, + safeAreaInsets: safeAreaInsets, + safeArea: safeArea, + oaid: oaid, + osAndroidAPILevel: osAndroidAPILevel, + } as GetSystemInfoResult; + return result; + } catch (e : Exception) { + return null; + } + } + + let result : GetSystemInfoResult | null = null; + if(Looper.myLooper() == Looper.getMainLooper()){ + result = runnable(); + }else{ + const latch = new CountDownLatch(1); + new RunnableTask(Looper.getMainLooper(), () => { + result = runnable(); + latch.countDown(); + }).execute(); + latch.await(); + } + + return result!!; +}; + + +export const getWindowInfo: GetWindowInfo = function(): GetWindowInfoResult { + const activity = UTSAndroid.getUniActivity()!!; + const pixelRatio = DeviceUtil.getScaledDensity(activity) + const screenWidth = DeviceUtil.getScreenWidth(); + const screenHeight = DeviceUtil.getScreenHeight(); + const statusBarHeight = DeviceUtil.getStatusBarHeight(); + const windowWidth = screenWidth; + const windowHeight = UTSAndroid.getWindowHeight(); + const windowTop = 0; + const windowBottom = 0; + const safeAreaInsetsTop = UTSAndroid.getSafeAreaInsets()["top"] as Int; + const safeAreaInsets : SafeAreaInsets = { + left: 0, + top: safeAreaInsetsTop, + right: 0, + bottom: 0 + } + const safeArea : SafeArea = { + left: safeAreaInsets.left, + right: windowWidth - safeAreaInsets.right, + top: safeAreaInsets.top, + bottom: windowHeight - safeAreaInsets.bottom, + width: windowWidth - safeAreaInsets.left - safeAreaInsets.right, + height: windowHeight - safeAreaInsets.top - safeAreaInsets.bottom + } + const screenTop = windowTop; + + let result = { + pixelRatio: pixelRatio, + screenWidth: screenWidth, + screenHeight: screenHeight, + windowWidth: windowWidth, + windowHeight: windowHeight, + statusBarHeight: statusBarHeight, + windowTop: windowTop, + windowBottom: windowBottom, + safeArea: safeArea, + safeAreaInsets: safeAreaInsets, + screenTop: screenTop + } as GetWindowInfoResult; + return result; +}; + +const convertVersionCode = function(version: string): number { + let str = ""; + let radixLength = 2; + let findDot = false; + const dotChar = ".".get(0); + for (let i = 0; i < version.length; i++) { + const char = version.get(i); + if(findDot){ + if(char.isDigit()){ + str += char; + } + radixLength --; + if(radixLength == 0){ + break; + } + }else{ + if(char.isDigit()){ + str += char; + }else{ + if(char == dotChar){ + findDot = true; + str += char; + } + } + } + } + + return parseFloat(str); +} + +const getHostVersion = function () : string { + const context = UTSAndroid.getAppContext()!!; + let packageManager = context.getPackageManager(); + let applicationInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES); + return applicationInfo.versionName; +} + +class RunnableTask extends Runnable { + private callback : () => void | null; + private looper : Looper | null = null; + constructor(looper : Looper | null, callback : () => void) { + super(); + this.looper = looper; + this.callback = callback + } + + override run() { + this.callback?.() + } + + public execute() { + if (this.looper == null) { + this.run(); + } else { + new Handler(this.looper!!).post(this); + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts b/uni_modules/uni-getSystemInfo/utssdk/app-ios/index.uts new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/uni_modules/uni-getSystemInfo/utssdk/interface.uts b/uni_modules/uni-getSystemInfo/utssdk/interface.uts new file mode 100644 index 0000000000000000000000000000000000000000..2ec4dba25098ad8699e96e46d03a767f2bdb1395 --- /dev/null +++ b/uni_modules/uni-getSystemInfo/utssdk/interface.uts @@ -0,0 +1,455 @@ +export interface Uni { + /** + * getSystemInfo() + * @description + * 异步获取系统信息 + * @param {GetSystemInfoOptions} options + * @return {void} + * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfo + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } + * @example + ```typescript + uni.getSystemInfo({ + success(e) { + console.log("success :",e); + }, + complete(e) { + console.log("complete :",e); + } + }) + ``` + */ + getSystemInfo(options: GetSystemInfoOptions): void; + + /** + * getSystemInfoSync() + * @description + * 同步获取系统信息 + * @param {void} + * @return {GetSystemInfoResult} + * @tutorial http://uniapp.dcloud.io/api/system/info?id=getsysteminfosync + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } + * @example + ```typescript + uni.getSystemInfoSync() + ``` + */ + getSystemInfoSync(): GetSystemInfoResult; + + /** + * getWindowInfo() + * @description + * 同步获取窗口信息 + * @param {void} + * @return {GetWindowInfoResult} result + * @tutorial http://uniapp.dcloud.io/api/system/getWindowInfo.html + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "3.9+" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } + * @example + ```typescript + uni.getWindowInfo() + ``` + */ + getWindowInfo(): GetWindowInfoResult; +} + +export type GetSystemInfo = (options: GetSystemInfoOptions) => void; +export type GetSystemInfoSync = () => GetSystemInfoResult; +export type GetWindowInfo = () => GetWindowInfoResult; +export type SafeArea = { + /** + * 安全区域左上角横坐标 + */ + left: number, + /** + * 安全区域右下角横坐标 + */ + right: number, + /** + * 安全区域左上角纵坐标 + */ + top: number, + /** + * 安全区域右下角纵坐标 + */ + bottom: number, + /** + * 安全区域的宽度,单位逻辑像素 + */ + width: number, + /** + * 安全区域的高度,单位逻辑像素 + */ + height: number +}; +export type SafeAreaInsets = { + /** + * 安全区域左侧插入位置 + */ + left: number, + /** + * 安全区域右侧插入位置 + */ + right: number, + /** + * 安全区顶部插入位置 + */ + top: number, + /** + * 安全区域底部插入位置 + */ + bottom: number +}; +export type GetSystemInfoResult = { + /** + * 客户端基础库版本 + */ + SDKVersion: string, + /** + * `manifest.json` 中应用appid。 + */ + appId: string, + /** + * 应用设置的语言。 + */ + appLanguage: string, + /** + * `manifest.json` 中应用名称。 + */ + appName: string, + /** + * `manifest.json` 中应用版本名称。 + */ + appVersion: string, + /** + * `manifest.json` 中应用版本名号。 + */ + appVersionCode: string, + /** + * 应用资源(wgt)的版本名称。 + * + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } + */ + appWgtVersion: string | null, + /** + * 手机品牌。 + */ + brand: string, + /** + * 浏览器名称。`App` 端是系统 webview 的名字,比如 wkwebview、chrome。小程序端为空 + */ + browserName: string, + /** + * 浏览器版本、webview 版本。 + */ + browserVersion: string, + /** + * 设备 ID + */ + deviceId: string, + /** + * 设备品牌。如:`apple`、`huawei`。 + */ + deviceBrand: string, + /** + * 设备型号 + */ + deviceModel: string, + /** + * 设备类型。`phone`、`pad`、`pc` + */ + deviceType: string, + /** + * 设备像素比 + */ + devicePixelRatio: number, + /** + * 设备方向。如:`竖屏 portrait`、`横屏 landscape` + * - portrait: 竖屏 + * - landscape: 横屏 + * @type 'portrait' | 'landscape' + */ + deviceOrientation: string, + /** + * 程序设置的语言 + */ + language: string, + /** + * 手机型号 + */ + model: string, + /** + * ios、android、windows、mac、linux + */ + osName: string, + /** + * 操作系统版本。如 ios 版本,andriod 版本 + */ + osVersion: string, + /** + * 操作系统语言 + */ + osLanguage: string, + /** + * 操作系统主题 light、dark。 + * + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "x" + * }, + * "ios": { + * "osVer": "9.0", + * "uniVer": "√", + * "unixVer": "x" + * } + * } + * } + */ + osTheme: string | null, + /** + * 设备像素比 + */ + pixelRatio: number, + /** + * 客户端平台 + */ + platform: string, + /** + * 屏幕宽度 + */ + screenWidth: number, + /** + * 屏幕高度 + */ + screenHeight: number, + /** + * 状态栏的高度 + */ + statusBarHeight: number, + /** + * 操作系统版本 + */ + system: string, + /** + * 在竖屏正方向下的安全区域 + */ + safeArea: SafeArea, + /** + * 在竖屏正方向下的安全区域插入位置 + */ + safeAreaInsets: SafeAreaInsets, + /** + * 用户标识。小程序端为空 + */ + ua: string, + /** + * uni 编译器版本 + */ + uniCompileVersion: string, + /** + * uni-app 运行平台。如:`app`、`mp-weixin`、`web` + */ + uniPlatform: string, + /** + * uni 运行时版本 + */ + uniRuntimeVersion: string, + /** + * uni 编译器版本号 + */ + uniCompileVersionCode: number, + /** + * uni 运行时版本号 + */ + uniRuntimeVersionCode: number, + /** + * 引擎版本号。已废弃,仅为了向下兼容保留 + * @deprecated 已废弃,仅为了向下兼容保留 + */ + version: string, + /** + * rom 名称。Android 部分机型获取不到值。iOS 恒为 `ios` + */ + romName: string, + /** + * rom 版本号。Android 部分机型获取不到值。iOS 恒为 `ios 版本号` + */ + romVersion: string, + /** + * 可使用窗口宽度 + */ + windowWidth: number, + /** + * 可使用窗口高度 + */ + windowHeight: number, + /** + * 可使用窗口的顶部位置 + */ + windowTop: number, + /** + * 可使用窗口的底部位置 + */ + windowBottom: number, + /** + * oaid + * + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "√" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + */ + oaid: string | null + /** + * Android 系统API库的版本。 + * + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "√", + * "unixVer": "√" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + */ + osAndroidAPILevel: number | null +}; +export type GetSystemInfoSuccessCallback = (result: GetSystemInfoResult) => void; +type GetSystemInfoFail = UniError; +type GetSystemInfoFailCallback = (result: GetSystemInfoFail) => void; +export type GetSystemInfoComplete = any; +export type GetSystemInfoCompleteCallback = (result: GetSystemInfoComplete) => void; +export type GetSystemInfoOptions = { + /** + * 接口调用成功的回调函数 + * @defaultValue null + */ + success?: GetSystemInfoSuccessCallback | null, + /** + * 接口调用失败的回调函数 + * @defaultValue null + */ + fail?: GetSystemInfoFailCallback | null, + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + * @defaultValue null + */ + complete?: GetSystemInfoCompleteCallback | null +}; + +export type GetWindowInfoResult = { + /** + * 设备像素比 + */ + pixelRatio: number, + /** + * 屏幕宽度 + */ + screenWidth: number, + /** + * 屏幕高度 + */ + screenHeight: number, + /** + * 可使用窗口宽度 + */ + windowWidth: number, + /** + * 可使用窗口高度 + */ + windowHeight: number, + /** + * 状态栏的高度 + */ + statusBarHeight: number, + /** + * 可使用窗口的顶部位置 + */ + windowTop: number, + /** + * 可使用窗口的底部位置 + */ + windowBottom: number, + /** + * 在竖屏正方向下的安全区域 + */ + safeArea: SafeArea, + /** + * 在竖屏正方向下的安全区域插入位置 + */ + safeAreaInsets: SafeAreaInsets, + /** + * 窗口上边缘的 y 值 + */ + screenTop: number +};