From 06687e4e63fdfd5e30d0096c98505508b35280b8 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 11 Jun 2026 13:24:30 +0200 Subject: [PATCH 1/2] refactor(device): remove unneeded code --- device/README.md | 32 +++++++++---------- .../capacitorjs/plugins/device/Device.java | 24 ++------------ device/src/definitions.ts | 4 +-- 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/device/README.md b/device/README.md index 39b6c154f..608476fdb 100644 --- a/device/README.md +++ b/device/README.md @@ -124,26 +124,26 @@ Get the device's current language locale tag. #### DeviceId -| Prop | Type | Description | Since | -| ---------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | -| **`identifier`** | string | The identifier of the device as available to the app. This identifier may change on modern mobile platforms that only allow per-app install ids. On iOS, the identifier is a UUID that uniquely identifies a device to the app’s vendor ([read more](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)). on Android 8+, __the identifier is a 64-bit number (expressed as a hexadecimal string)__, unique to each combination of app-signing key, user, and device ([read more](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID)). On web, a random identifier is generated and stored on localStorage for subsequent calls. If localStorage is not available a new random identifier will be generated on every call. | 1.0.0 | +| Prop | Type | Description | Since | +| ---------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | +| **`identifier`** | string | The identifier of the device as available to the app. This identifier may change on modern mobile platforms that only allow per-app install ids. On iOS, the identifier is a UUID that uniquely identifies a device to the app’s vendor ([read more](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)). on Android, __the identifier is a 64-bit number (expressed as a hexadecimal string)__, unique to each combination of app-signing key, user, and device ([read more](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID)). On web, a random identifier is generated and stored on localStorage for subsequent calls. If localStorage is not available a new random identifier will be generated on every call. | 1.0.0 | #### DeviceInfo -| Prop | Type | Description | Since | -| ----------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- | -| **`name`** | string | The name of the device. For example, "John's iPhone". This is only supported on iOS and Android 7.1 or above. On iOS 16+ this will return a generic device name without the appropriate [entitlements](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name). | 1.0.0 | -| **`model`** | string | The device model. For example, "iPhone13,4". | 1.0.0 | -| **`platform`** | 'ios' \| 'android' \| 'web' | The device platform (lowercase). | 1.0.0 | -| **`operatingSystem`** | OperatingSystem | The operating system of the device. | 1.0.0 | -| **`osVersion`** | string | The version of the device OS. | 1.0.0 | -| **`iOSVersion`** | number | The iOS version number. Only available on iOS. Multi-part version numbers are crushed down into an integer padded to two-digits, ex: `"16.3.1"` -> `160301` | 5.0.0 | -| **`androidSDKVersion`** | number | The Android SDK version number. Only available on Android. | 5.0.0 | -| **`manufacturer`** | string | The manufacturer of the device. | 1.0.0 | -| **`isVirtual`** | boolean | Whether the app is running in a simulator/emulator. | 1.0.0 | -| **`memUsed`** | number | Approximate memory used by the current app, in bytes. Divide by 1048576 to get the number of MBs used. | 1.0.0 | -| **`webViewVersion`** | string | The web view browser version | 1.0.0 | +| Prop | Type | Description | Since | +| ----------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- | +| **`name`** | string | The name of the device. For example, "John's iPhone". This is only supported on iOS and Android. On iOS 16+ this will return a generic device name without the appropriate [entitlements](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name). | 1.0.0 | +| **`model`** | string | The device model. For example, "iPhone13,4". | 1.0.0 | +| **`platform`** | 'ios' \| 'android' \| 'web' | The device platform (lowercase). | 1.0.0 | +| **`operatingSystem`** | OperatingSystem | The operating system of the device. | 1.0.0 | +| **`osVersion`** | string | The version of the device OS. | 1.0.0 | +| **`iOSVersion`** | number | The iOS version number. Only available on iOS. Multi-part version numbers are crushed down into an integer padded to two-digits, ex: `"16.3.1"` -> `160301` | 5.0.0 | +| **`androidSDKVersion`** | number | The Android SDK version number. Only available on Android. | 5.0.0 | +| **`manufacturer`** | string | The manufacturer of the device. | 1.0.0 | +| **`isVirtual`** | boolean | Whether the app is running in a simulator/emulator. | 1.0.0 | +| **`memUsed`** | number | Approximate memory used by the current app, in bytes. Divide by 1048576 to get the number of MBs used. | 1.0.0 | +| **`webViewVersion`** | string | The web view browser version | 1.0.0 | #### BatteryInfo diff --git a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java index d9cbc9c96..9cb4a6d05 100644 --- a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java +++ b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java @@ -4,7 +4,6 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; import android.os.BatteryManager; import android.os.Build; import android.provider.Settings; @@ -63,33 +62,14 @@ public boolean isVirtual() { } public String getName() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { - return Settings.Global.getString(this.context.getContentResolver(), Settings.Global.DEVICE_NAME); - } - - return null; + return Settings.Global.getString(this.context.getContentResolver(), Settings.Global.DEVICE_NAME); } public String getWebViewVersion() { - PackageInfo info = null; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - info = WebView.getCurrentWebViewPackage(); - } else { - try { - info = getWebViewVersionSubAndroid26(); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - } + PackageInfo info = WebView.getCurrentWebViewPackage();; if (info != null) { return info.versionName; } - return Build.VERSION.RELEASE; } - - private PackageInfo getWebViewVersionSubAndroid26() throws PackageManager.NameNotFoundException { - PackageManager pm = this.context.getPackageManager(); - return pm.getPackageInfo("com.android.chrome", 0); - } } diff --git a/device/src/definitions.ts b/device/src/definitions.ts index 20f4ed006..31b05b98d 100644 --- a/device/src/definitions.ts +++ b/device/src/definitions.ts @@ -7,7 +7,7 @@ export interface DeviceId { * * On iOS, the identifier is a UUID that uniquely identifies a device to the app’s vendor ([read more](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor)). * - * on Android 8+, __the identifier is a 64-bit number (expressed as a hexadecimal string)__, unique to each combination of app-signing key, user, and device ([read more](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID)). + * on Android, __the identifier is a 64-bit number (expressed as a hexadecimal string)__, unique to each combination of app-signing key, user, and device ([read more](https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID)). * * On web, a random identifier is generated and stored on localStorage for subsequent calls. * If localStorage is not available a new random identifier will be generated on every call. @@ -21,7 +21,7 @@ export interface DeviceInfo { /** * The name of the device. For example, "John's iPhone". * - * This is only supported on iOS and Android 7.1 or above. + * This is only supported on iOS and Android. * * On iOS 16+ this will return a generic device name without the appropriate [entitlements](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name). * From 4faaae36f6a329819eba19778b12647dc1bd1c39 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Thu, 11 Jun 2026 13:27:46 +0200 Subject: [PATCH 2/2] fmt --- .../src/main/java/com/capacitorjs/plugins/device/Device.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java index 9cb4a6d05..41897d9d6 100644 --- a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java +++ b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java @@ -66,7 +66,7 @@ public String getName() { } public String getWebViewVersion() { - PackageInfo info = WebView.getCurrentWebViewPackage();; + PackageInfo info = WebView.getCurrentWebViewPackage(); if (info != null) { return info.versionName; }