@capawesome/capacitor-device-info 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CapawesomeCapacitorDeviceInfo.podspec +21 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +29 -0
  4. package/README.md +264 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/DeviceInfo.java +119 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/DeviceInfoPlugin.java +106 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetIdResult.java +23 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetInfoResult.java +98 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/classes/results/GetUptimeResult.java +22 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/Callback.java +5 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/NonEmptyResultCallback.java +7 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/deviceinfo/interfaces/Result.java +7 -0
  15. package/android/src/main/res/.gitkeep +0 -0
  16. package/dist/docs.json +413 -0
  17. package/dist/esm/definitions.d.ts +203 -0
  18. package/dist/esm/definitions.js +2 -0
  19. package/dist/esm/definitions.js.map +1 -0
  20. package/dist/esm/index.d.ts +4 -0
  21. package/dist/esm/index.js +7 -0
  22. package/dist/esm/index.js.map +1 -0
  23. package/dist/esm/web.d.ts +13 -0
  24. package/dist/esm/web.js +130 -0
  25. package/dist/esm/web.js.map +1 -0
  26. package/dist/plugin.cjs.js +144 -0
  27. package/dist/plugin.cjs.js.map +1 -0
  28. package/dist/plugin.js +147 -0
  29. package/dist/plugin.js.map +1 -0
  30. package/ios/Plugin/Classes/Results/GetIdResult.swift +16 -0
  31. package/ios/Plugin/Classes/Results/GetInfoResult.swift +66 -0
  32. package/ios/Plugin/Classes/Results/GetUptimeResult.swift +16 -0
  33. package/ios/Plugin/DeviceInfo.swift +89 -0
  34. package/ios/Plugin/DeviceInfoPlugin.swift +64 -0
  35. package/ios/Plugin/Info.plist +24 -0
  36. package/ios/Plugin/PrivacyInfo.xcprivacy +23 -0
  37. package/ios/Plugin/Protocols/Result.swift +5 -0
  38. package/package.json +91 -0
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapawesomeCapacitorDeviceInfo'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.resource_bundles = {
15
+ 'CapawesomeCapacitorDeviceInfoPrivacy' => ['ios/Plugin/PrivacyInfo.xcprivacy']
16
+ }
17
+ s.ios.deployment_target = '15.0'
18
+ s.static_framework = true
19
+ s.dependency 'Capacitor'
20
+ s.swift_version = '5.1'
21
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robin Genz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Package.swift ADDED
@@ -0,0 +1,29 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapawesomeCapacitorDeviceInfo",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "CapawesomeCapacitorDeviceInfo",
10
+ targets: ["DeviceInfoPlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
14
+ ],
15
+ targets: [
16
+ .target(
17
+ name: "DeviceInfoPlugin",
18
+ dependencies: [
19
+ .product(name: "Capacitor", package: "capacitor-swift-pm"),
20
+ .product(name: "Cordova", package: "capacitor-swift-pm")
21
+ ],
22
+ path: "ios/Plugin",
23
+ resources: [.copy("PrivacyInfo.xcprivacy")]),
24
+ .testTarget(
25
+ name: "DeviceInfoPluginTests",
26
+ dependencies: ["DeviceInfoPlugin"],
27
+ path: "ios/PluginTests")
28
+ ]
29
+ )
package/README.md ADDED
@@ -0,0 +1,264 @@
1
+ # Capacitor Device Info Plugin
2
+
3
+ Capacitor plugin to read device information, such as the model, manufacturer, operating system, memory, and a per-install identifier.
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
8
+ </a>
9
+ </div>
10
+
11
+ ## Features
12
+
13
+ - 🆔 **Identifier**: Read a unique per-install identifier for the device.
14
+ - 📱 **Information**: Read the model, manufacturer, operating system, and more.
15
+ - 🧠 **Memory**: Read the total memory of the device and the memory used by the app.
16
+ - ⏱️ **Uptime**: Read how long the device has been running since its last boot.
17
+ - 🖥️ **Cross-platform**: Support for Android, iOS, and Web.
18
+ - 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
19
+ - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
20
+ - 🤝 **Compatibility**: Works alongside the [Battery](https://capawesome.io/docs/sdks/capacitor/battery/) and [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugins.
21
+
22
+ Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
23
+
24
+ ## Newsletter
25
+
26
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
27
+
28
+ ## Compatibility
29
+
30
+ | Plugin Version | Capacitor Version | Status |
31
+ | -------------- | ----------------- | -------------- |
32
+ | 0.x.x | >=8.x.x | Active support |
33
+
34
+ ## Installation
35
+
36
+ You can use our **AI-Assisted Setup** to install the plugin.
37
+ Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
38
+
39
+ ```bash
40
+ npx skills add capawesome-team/skills --skill capacitor-plugins
41
+ ```
42
+
43
+ Then use the following prompt:
44
+
45
+ ```
46
+ Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-device-info` plugin in my project.
47
+ ```
48
+
49
+ If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
50
+
51
+ ```bash
52
+ npm install @capawesome/capacitor-device-info
53
+ npx cap sync
54
+ ```
55
+
56
+ No additional permissions or configuration are required on any platform.
57
+
58
+ ## Configuration
59
+
60
+ No configuration required for this plugin.
61
+
62
+ ## Usage
63
+
64
+ ```typescript
65
+ import { DeviceInfo } from '@capawesome/capacitor-device-info';
66
+
67
+ const getId = async () => {
68
+ const { identifier } = await DeviceInfo.getId();
69
+ return identifier;
70
+ };
71
+
72
+ const getInfo = async () => {
73
+ const info = await DeviceInfo.getInfo();
74
+ return info;
75
+ };
76
+
77
+ const getUptime = async () => {
78
+ const { uptime } = await DeviceInfo.getUptime();
79
+ return uptime;
80
+ };
81
+ ```
82
+
83
+ ## API
84
+
85
+ <docgen-index>
86
+
87
+ * [`getId()`](#getid)
88
+ * [`getInfo()`](#getinfo)
89
+ * [`getUptime()`](#getuptime)
90
+ * [Interfaces](#interfaces)
91
+ * [Type Aliases](#type-aliases)
92
+
93
+ </docgen-index>
94
+
95
+ <docgen-api>
96
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
97
+
98
+ ### getId()
99
+
100
+ ```typescript
101
+ getId() => Promise<GetIdResult>
102
+ ```
103
+
104
+ Get a unique identifier for the device.
105
+
106
+ On **Android**, the identifier is the `ANDROID_ID` value, which is unique
107
+ per app-signing key, user, and device. It is reset when the app is
108
+ reinstalled after the signing key changes or the device is factory reset.
109
+
110
+ On **iOS**, the identifier is the `identifierForVendor` value, which is
111
+ unique per vendor and device. It is reset when all apps from the vendor are
112
+ uninstalled.
113
+
114
+ On **Web**, the identifier is a random UUID that is persisted in the
115
+ browser's `localStorage`. It is reset when the browser storage is cleared.
116
+
117
+ **Returns:** <code>Promise&lt;<a href="#getidresult">GetIdResult</a>&gt;</code>
118
+
119
+ **Since:** 0.1.0
120
+
121
+ --------------------
122
+
123
+
124
+ ### getInfo()
125
+
126
+ ```typescript
127
+ getInfo() => Promise<GetInfoResult>
128
+ ```
129
+
130
+ Get information about the device.
131
+
132
+ **Returns:** <code>Promise&lt;<a href="#getinforesult">GetInfoResult</a>&gt;</code>
133
+
134
+ **Since:** 0.1.0
135
+
136
+ --------------------
137
+
138
+
139
+ ### getUptime()
140
+
141
+ ```typescript
142
+ getUptime() => Promise<GetUptimeResult>
143
+ ```
144
+
145
+ Get the time the device has been running since its last boot, in
146
+ milliseconds.
147
+
148
+ Only available on Android and iOS.
149
+
150
+ **Returns:** <code>Promise&lt;<a href="#getuptimeresult">GetUptimeResult</a>&gt;</code>
151
+
152
+ **Since:** 0.1.0
153
+
154
+ --------------------
155
+
156
+
157
+ ### Interfaces
158
+
159
+
160
+ #### GetIdResult
161
+
162
+ | Prop | Type | Description | Since |
163
+ | ---------------- | ------------------- | ------------------------------------ | ----- |
164
+ | **`identifier`** | <code>string</code> | The unique identifier of the device. | 0.1.0 |
165
+
166
+
167
+ #### GetInfoResult
168
+
169
+ | Prop | Type | Description | Since |
170
+ | ----------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
171
+ | **`androidSdkVersion`** | <code>number \| null</code> | The Android SDK version number (API level). Returns `null` on platforms other than Android. Only available on Android. | 0.1.0 |
172
+ | **`deviceType`** | <code><a href="#devicetype">DeviceType</a></code> | The type of the device. | 0.1.0 |
173
+ | **`iosVersion`** | <code>number \| null</code> | The major version number of iOS. Returns `null` on platforms other than iOS. Only available on iOS. | 0.1.0 |
174
+ | **`isVirtual`** | <code>boolean</code> | Whether the app is running on a virtual device (simulator or emulator). | 0.1.0 |
175
+ | **`manufacturer`** | <code>string</code> | The manufacturer of the device. | 0.1.0 |
176
+ | **`model`** | <code>string</code> | The model identifier of the device. On **iOS**, this is the internal model identifier (e.g. `iPhone13,4`), not the marketing name. | 0.1.0 |
177
+ | **`name`** | <code>string \| null</code> | The name of the device. On **iOS 16 and newer**, a generic device name (e.g. `iPhone`) is returned unless the app has the required entitlement. Returns `null` if the name cannot be determined. | 0.1.0 |
178
+ | **`operatingSystem`** | <code><a href="#operatingsystem">OperatingSystem</a></code> | The operating system of the device. | 0.1.0 |
179
+ | **`osVersion`** | <code>string</code> | The version of the operating system. | 0.1.0 |
180
+ | **`platform`** | <code><a href="#platform">Platform</a></code> | The platform the app is running on. | 0.1.0 |
181
+ | **`totalMemory`** | <code>number \| null</code> | The total amount of memory of the device, in bytes. Returns `null` if the total memory cannot be determined. Only available on Android and iOS. | 0.1.0 |
182
+ | **`usedMemory`** | <code>number \| null</code> | The amount of memory used by the app, in bytes. Returns `null` if the used memory cannot be determined. Only available on Android and iOS. | 0.1.0 |
183
+ | **`webViewVersion`** | <code>string \| null</code> | The version of the WebView that renders the app. On **iOS**, the version of the operating system is returned, because the WebKit version is tied to it. Returns `null` if the WebView version cannot be determined. | 0.1.0 |
184
+
185
+
186
+ #### GetUptimeResult
187
+
188
+ | Prop | Type | Description | Since |
189
+ | ------------ | ------------------- | -------------------------------------------------------------------------- | ----- |
190
+ | **`uptime`** | <code>number</code> | The time the device has been running since its last boot, in milliseconds. | 0.1.0 |
191
+
192
+
193
+ ### Type Aliases
194
+
195
+
196
+ #### DeviceType
197
+
198
+ The type of a device.
199
+
200
+ - `phone`: A handheld phone-sized device.
201
+ - `tablet`: A tablet-sized device.
202
+ - `desktop`: A desktop or laptop computer.
203
+ - `tv`: A television or set-top box.
204
+ - `unknown`: The type could not be determined.
205
+
206
+ <code>'phone' | 'tablet' | 'desktop' | 'tv' | 'unknown'</code>
207
+
208
+
209
+ #### OperatingSystem
210
+
211
+ The operating system of a device.
212
+
213
+ <code>'android' | 'ios' | 'windows' | 'mac' | 'unknown'</code>
214
+
215
+
216
+ #### Platform
217
+
218
+ The platform an app is running on.
219
+
220
+ <code>'android' | 'ios' | 'web'</code>
221
+
222
+ </docgen-api>
223
+
224
+ ## Platform Support
225
+
226
+ The plugin returns `null` for any field that a platform cannot determine. The following table shows which fields of the `getInfo()` result are available on each platform:
227
+
228
+ | Property | Android | iOS | Web |
229
+ | ------------------- | ------- | --- | ---------------- |
230
+ | `androidSdkVersion` | ✅ | ❌ | ❌ |
231
+ | `deviceType` | ✅ | ✅ | ✅ (best-effort) |
232
+ | `iosVersion` | ❌ | ✅ | ❌ |
233
+ | `isVirtual` | ✅ | ✅ | ✅ |
234
+ | `manufacturer` | ✅ | ✅ | ❌ |
235
+ | `model` | ✅ | ✅ | ✅ (best-effort) |
236
+ | `name` | ✅ | ✅ | ❌ |
237
+ | `operatingSystem` | ✅ | ✅ | ✅ (best-effort) |
238
+ | `osVersion` | ✅ | ✅ | ✅ (best-effort) |
239
+ | `platform` | ✅ | ✅ | ✅ |
240
+ | `totalMemory` | ✅ | ✅ | ❌ |
241
+ | `usedMemory` | ✅ | ✅ | ❌ |
242
+ | `webViewVersion` | ✅ | ✅ | ✅ (best-effort) |
243
+
244
+ The `getUptime()` method is only available on Android and iOS.
245
+
246
+ ## Migration from `@capacitor/device`
247
+
248
+ This plugin can be used as a replacement for the official [`@capacitor/device`](https://capacitorjs.com/docs/apis/device) plugin. The following table shows how the methods map:
249
+
250
+ | `@capacitor/device` | `@capawesome/capacitor-device-info` |
251
+ | ------------------- | -------------------------------------------------------------------------------------- |
252
+ | `getId()` | `getId()` |
253
+ | `getInfo()` | `getInfo()` |
254
+ | `getBatteryInfo()` | Use the [Battery](https://capawesome.io/docs/sdks/capacitor/battery/) plugin |
255
+ | `getLanguageCode()` | Use the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin |
256
+ | `getLanguageTag()` | Use the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin |
257
+
258
+ ## Changelog
259
+
260
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/device-info/CHANGELOG.md).
261
+
262
+ ## License
263
+
264
+ See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/device-info/LICENSE).
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "io.capawesome.capacitorjs.plugins.deviceinfo"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError = false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,119 @@
1
+ package io.capawesome.capacitorjs.plugins.deviceinfo;
2
+
3
+ import android.app.ActivityManager;
4
+ import android.app.UiModeManager;
5
+ import android.content.Context;
6
+ import android.content.pm.PackageInfo;
7
+ import android.content.res.Configuration;
8
+ import android.os.Build;
9
+ import android.os.SystemClock;
10
+ import android.provider.Settings;
11
+ import android.webkit.WebView;
12
+ import androidx.annotation.NonNull;
13
+ import androidx.annotation.Nullable;
14
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetIdResult;
15
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetInfoResult;
16
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetUptimeResult;
17
+ import io.capawesome.capacitorjs.plugins.deviceinfo.interfaces.NonEmptyResultCallback;
18
+
19
+ public class DeviceInfo {
20
+
21
+ @NonNull
22
+ private final Context context;
23
+
24
+ public DeviceInfo(@NonNull Context context) {
25
+ this.context = context;
26
+ }
27
+
28
+ public void getId(@NonNull NonEmptyResultCallback<GetIdResult> callback) {
29
+ String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
30
+ String identifier = androidId == null ? "" : androidId;
31
+ callback.success(new GetIdResult(identifier));
32
+ }
33
+
34
+ public void getInfo(@NonNull NonEmptyResultCallback<GetInfoResult> callback) {
35
+ GetInfoResult result = new GetInfoResult(
36
+ Build.VERSION.SDK_INT,
37
+ determineDeviceType(),
38
+ null,
39
+ determineIsVirtual(),
40
+ Build.MANUFACTURER,
41
+ Build.MODEL,
42
+ determineName(),
43
+ "android",
44
+ Build.VERSION.RELEASE,
45
+ "android",
46
+ determineTotalMemory(),
47
+ determineUsedMemory(),
48
+ determineWebViewVersion()
49
+ );
50
+ callback.success(result);
51
+ }
52
+
53
+ public void getUptime(@NonNull NonEmptyResultCallback<GetUptimeResult> callback) {
54
+ long uptime = SystemClock.elapsedRealtime();
55
+ callback.success(new GetUptimeResult(uptime));
56
+ }
57
+
58
+ @NonNull
59
+ private String determineDeviceType() {
60
+ UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
61
+ if (uiModeManager != null && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
62
+ return "tv";
63
+ }
64
+ Configuration configuration = context.getResources().getConfiguration();
65
+ if (configuration.smallestScreenWidthDp >= 600) {
66
+ return "tablet";
67
+ }
68
+ return "phone";
69
+ }
70
+
71
+ private boolean determineIsVirtual() {
72
+ return (
73
+ Build.FINGERPRINT.startsWith("generic") ||
74
+ Build.FINGERPRINT.startsWith("unknown") ||
75
+ Build.MODEL.contains("google_sdk") ||
76
+ Build.MODEL.contains("Emulator") ||
77
+ Build.MODEL.contains("Android SDK built for x86") ||
78
+ Build.MANUFACTURER.contains("Genymotion") ||
79
+ (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) ||
80
+ "google_sdk".equals(Build.PRODUCT) ||
81
+ Build.HARDWARE.contains("goldfish") ||
82
+ Build.HARDWARE.contains("ranchu")
83
+ );
84
+ }
85
+
86
+ @Nullable
87
+ private String determineName() {
88
+ return Settings.Global.getString(context.getContentResolver(), Settings.Global.DEVICE_NAME);
89
+ }
90
+
91
+ @Nullable
92
+ private Long determineTotalMemory() {
93
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
94
+ if (activityManager == null) {
95
+ return null;
96
+ }
97
+ ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
98
+ activityManager.getMemoryInfo(memoryInfo);
99
+ return memoryInfo.totalMem;
100
+ }
101
+
102
+ @NonNull
103
+ private Long determineUsedMemory() {
104
+ Runtime runtime = Runtime.getRuntime();
105
+ return runtime.totalMemory() - runtime.freeMemory();
106
+ }
107
+
108
+ @Nullable
109
+ private String determineWebViewVersion() {
110
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
111
+ return null;
112
+ }
113
+ PackageInfo packageInfo = WebView.getCurrentWebViewPackage();
114
+ if (packageInfo == null) {
115
+ return null;
116
+ }
117
+ return packageInfo.versionName;
118
+ }
119
+ }
@@ -0,0 +1,106 @@
1
+ package io.capawesome.capacitorjs.plugins.deviceinfo;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.Logger;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetIdResult;
11
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetInfoResult;
12
+ import io.capawesome.capacitorjs.plugins.deviceinfo.classes.results.GetUptimeResult;
13
+ import io.capawesome.capacitorjs.plugins.deviceinfo.interfaces.NonEmptyResultCallback;
14
+ import io.capawesome.capacitorjs.plugins.deviceinfo.interfaces.Result;
15
+
16
+ @CapacitorPlugin(name = "DeviceInfo")
17
+ public class DeviceInfoPlugin extends Plugin {
18
+
19
+ public static final String TAG = "DeviceInfo";
20
+
21
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
22
+
23
+ private DeviceInfo implementation;
24
+
25
+ @Override
26
+ public void load() {
27
+ implementation = new DeviceInfo(getContext());
28
+ }
29
+
30
+ @PluginMethod
31
+ public void getId(PluginCall call) {
32
+ try {
33
+ NonEmptyResultCallback<GetIdResult> callback = new NonEmptyResultCallback<>() {
34
+ @Override
35
+ public void success(@NonNull GetIdResult result) {
36
+ resolveCall(call, result);
37
+ }
38
+
39
+ @Override
40
+ public void error(@NonNull Exception exception) {
41
+ rejectCall(call, exception);
42
+ }
43
+ };
44
+ implementation.getId(callback);
45
+ } catch (Exception exception) {
46
+ rejectCall(call, exception);
47
+ }
48
+ }
49
+
50
+ @PluginMethod
51
+ public void getInfo(PluginCall call) {
52
+ try {
53
+ NonEmptyResultCallback<GetInfoResult> callback = new NonEmptyResultCallback<>() {
54
+ @Override
55
+ public void success(@NonNull GetInfoResult result) {
56
+ resolveCall(call, result);
57
+ }
58
+
59
+ @Override
60
+ public void error(@NonNull Exception exception) {
61
+ rejectCall(call, exception);
62
+ }
63
+ };
64
+ implementation.getInfo(callback);
65
+ } catch (Exception exception) {
66
+ rejectCall(call, exception);
67
+ }
68
+ }
69
+
70
+ @PluginMethod
71
+ public void getUptime(PluginCall call) {
72
+ try {
73
+ NonEmptyResultCallback<GetUptimeResult> callback = new NonEmptyResultCallback<>() {
74
+ @Override
75
+ public void success(@NonNull GetUptimeResult result) {
76
+ resolveCall(call, result);
77
+ }
78
+
79
+ @Override
80
+ public void error(@NonNull Exception exception) {
81
+ rejectCall(call, exception);
82
+ }
83
+ };
84
+ implementation.getUptime(callback);
85
+ } catch (Exception exception) {
86
+ rejectCall(call, exception);
87
+ }
88
+ }
89
+
90
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
91
+ String message = exception.getMessage();
92
+ if (message == null) {
93
+ message = ERROR_UNKNOWN_ERROR;
94
+ }
95
+ Logger.error(TAG, message, exception);
96
+ call.reject(message);
97
+ }
98
+
99
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
100
+ if (result == null) {
101
+ call.resolve();
102
+ } else {
103
+ call.resolve(result.toJSObject());
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.deviceinfo.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.deviceinfo.interfaces.Result;
6
+
7
+ public class GetIdResult implements Result {
8
+
9
+ @NonNull
10
+ private final String identifier;
11
+
12
+ public GetIdResult(@NonNull String identifier) {
13
+ this.identifier = identifier;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject result = new JSObject();
20
+ result.put("identifier", identifier);
21
+ return result;
22
+ }
23
+ }