@unvired/cordova-plugin-unvired-device 1.0.5
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.
- package/README.md +332 -0
- package/package.json +52 -0
- package/plugin.xml +85 -0
- package/src/android/Device.java +134 -0
- package/src/browser/DeviceProxy.js +84 -0
- package/src/electron/index.js +42 -0
- package/src/electron/package.json +20 -0
- package/src/ios/CDVDevice.bundle/PrivacyInfo.xcprivacy +41 -0
- package/src/ios/CDVDevice.h +30 -0
- package/src/ios/CDVDevice.m +130 -0
- package/www/device.js +96 -0
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Device
|
|
3
|
+
description: Get device information.
|
|
4
|
+
---
|
|
5
|
+
<!--
|
|
6
|
+
# license: Licensed to the Apache Software Foundation (ASF) under one
|
|
7
|
+
# or more contributor license agreements. See the NOTICE file
|
|
8
|
+
# distributed with this work for additional information
|
|
9
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
10
|
+
# to you under the Apache License, Version 2.0 (the
|
|
11
|
+
# "License"); you may not use this file except in compliance
|
|
12
|
+
# with the License. You may obtain a copy of the License at
|
|
13
|
+
#
|
|
14
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
#
|
|
16
|
+
# Unless required by applicable law or agreed to in writing,
|
|
17
|
+
# software distributed under the License is distributed on an
|
|
18
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
19
|
+
# KIND, either express or implied. See the License for the
|
|
20
|
+
# specific language governing permissions and limitations
|
|
21
|
+
# under the License.
|
|
22
|
+
-->
|
|
23
|
+
|
|
24
|
+
# cordova-plugin-unvired-device
|
|
25
|
+
|
|
26
|
+
[](https://github.com/apache/cordova-plugin-unvired-device/actions/workflows/android.yml) [](https://github.com/apache/cordova-plugin-unvired-device/actions/workflows/chrome.yml) [](https://github.com/apache/cordova-plugin-unvired-device/actions/workflows/ios.yml) [](https://github.com/apache/cordova-plugin-unvired-device/actions/workflows/lint.yml)
|
|
27
|
+
|
|
28
|
+
This plugin defines a global `device` object, which describes the device's hardware and software.
|
|
29
|
+
Although the object is in the global scope, it is not available until after the `deviceready` event.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
document.addEventListener("deviceready", onDeviceReady, false);
|
|
33
|
+
function onDeviceReady() {
|
|
34
|
+
console.log(device.cordova);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
cordova plugin add cordova-plugin-unvired-device
|
|
41
|
+
|
|
42
|
+
## Properties
|
|
43
|
+
|
|
44
|
+
- device.cordova
|
|
45
|
+
- device.model
|
|
46
|
+
- device.platform
|
|
47
|
+
- device.uuid
|
|
48
|
+
- device.version
|
|
49
|
+
- device.manufacturer
|
|
50
|
+
- device.isVirtual
|
|
51
|
+
- device.serial
|
|
52
|
+
- device.sdkVersion (Android only)
|
|
53
|
+
|
|
54
|
+
## device.cordova
|
|
55
|
+
|
|
56
|
+
Returns the Cordova platform's version that is bundled in the application.
|
|
57
|
+
|
|
58
|
+
The version information comes from the `cordova.js` file.
|
|
59
|
+
|
|
60
|
+
This property does not display other installed platforms' version information. Only the respective running platform's version is displayed.
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
|
|
64
|
+
If Cordova Android 10.1.1 is installed on the Cordova project, the `cordova.js` file, in the Android application, will contain `10.1.1`.
|
|
65
|
+
|
|
66
|
+
The `device.cordova` property will display `10.1.1`.
|
|
67
|
+
|
|
68
|
+
### Supported Platforms
|
|
69
|
+
|
|
70
|
+
- Android
|
|
71
|
+
- Browser
|
|
72
|
+
- iOS
|
|
73
|
+
|
|
74
|
+
## device.model
|
|
75
|
+
|
|
76
|
+
The `device.model` returns the name of the device's model or
|
|
77
|
+
product. The value is set by the device manufacturer and may be
|
|
78
|
+
different across versions of the same product.
|
|
79
|
+
|
|
80
|
+
### Supported Platforms
|
|
81
|
+
|
|
82
|
+
- Android
|
|
83
|
+
- Browser
|
|
84
|
+
- iOS
|
|
85
|
+
|
|
86
|
+
### Quick Example
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
// Android: Pixel 4 returns "Pixel 4"
|
|
90
|
+
// Motorola Moto G3 returns "MotoG3"
|
|
91
|
+
// Browser: Google Chrome returns "Chrome"
|
|
92
|
+
// Safari returns "Safari"
|
|
93
|
+
// iOS: iPad Mini returns "iPad2,5"
|
|
94
|
+
// iPhone 5 returns "iPhone5,1"
|
|
95
|
+
// See https://www.theiphonewiki.com/wiki/Models
|
|
96
|
+
// OS X: returns "x86_64"
|
|
97
|
+
//
|
|
98
|
+
var model = device.model;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Android Quirks
|
|
102
|
+
|
|
103
|
+
- Gets the [model name](https://developer.android.com/reference/android/os/Build.html#MODEL).
|
|
104
|
+
|
|
105
|
+
### iOS Quirks
|
|
106
|
+
|
|
107
|
+
The model value is based on the identifier that Apple supplies.
|
|
108
|
+
|
|
109
|
+
If you need the exact device name, e.g. iPhone 13 Pro Max, a mapper needs to be created to convert the known identifiers to the associated device name.
|
|
110
|
+
|
|
111
|
+
Example: The identifier `iPhone14,3` is associated to the device `iPhone 13 Pro Max`.
|
|
112
|
+
|
|
113
|
+
For the full list of all identifiers to device names, see [here](https://www.theiphonewiki.com/wiki/Models)
|
|
114
|
+
|
|
115
|
+
## device.platform
|
|
116
|
+
|
|
117
|
+
Get the device's operating system name.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
var string = device.platform;
|
|
121
|
+
```
|
|
122
|
+
### Supported Platforms
|
|
123
|
+
|
|
124
|
+
- Android
|
|
125
|
+
- Browser
|
|
126
|
+
- iOS
|
|
127
|
+
|
|
128
|
+
### Quick Example
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
// Depending on the device, a few examples are:
|
|
132
|
+
// - "Android"
|
|
133
|
+
// - "browser"
|
|
134
|
+
// - "iOS"
|
|
135
|
+
//
|
|
136
|
+
var devicePlatform = device.platform;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## device.uuid
|
|
140
|
+
|
|
141
|
+
Get the device's Universally Unique Identifier ([UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier)).
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
var string = device.uuid;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Description
|
|
148
|
+
|
|
149
|
+
The details of how a UUID is generated are determined by the device manufacturer and are specific to the device's platform or model.
|
|
150
|
+
|
|
151
|
+
### Supported Platforms
|
|
152
|
+
|
|
153
|
+
- Android
|
|
154
|
+
- iOS
|
|
155
|
+
|
|
156
|
+
### Quick Example
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
// Android: Returns a random 64-bit integer (as a string, again!)
|
|
160
|
+
//
|
|
161
|
+
// iOS: (Paraphrased from the UIDevice Class documentation)
|
|
162
|
+
// Returns the [UIDevice identifierForVendor] UUID which is unique and the same for all apps installed by the same vendor. However the UUID can be different if the user deletes all apps from the vendor and then reinstalls it.
|
|
163
|
+
//
|
|
164
|
+
var deviceID = device.uuid;
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Android Quirk
|
|
168
|
+
|
|
169
|
+
The `uuid` on Android is a 64-bit integer (expressed as a hexadecimal string). The behaviour of this `uuid` is different on two different OS versions-
|
|
170
|
+
|
|
171
|
+
**For < Android 8.0 (API level 26)**
|
|
172
|
+
|
|
173
|
+
In versions of the platform lower than Android 8.0, the `uuid` is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device.
|
|
174
|
+
|
|
175
|
+
**For Android 8.0 or higher**
|
|
176
|
+
|
|
177
|
+
The above behaviour was changed in Android 8.0. Read it in detail [here](https://developer.android.com/about/versions/oreo/android-8.0-changes#privacy-all).
|
|
178
|
+
|
|
179
|
+
On Android 8.0 and higher versions, the `uuid` will be unique to each combination of app-signing key, user, and device. The value is scoped by signing key and user. The value may change if a factory reset is performed on the device or if an APK signing key changes.
|
|
180
|
+
|
|
181
|
+
Read more here https://developer.android.com/reference/android/provider/Settings.Secure#ANDROID_ID.
|
|
182
|
+
|
|
183
|
+
### iOS Quirk
|
|
184
|
+
|
|
185
|
+
The `uuid` on iOS uses the identifierForVendor property. It is unique to the device across the same vendor, but will be different for different vendors and will change if all apps from the vendor are deleted and then reinstalled.
|
|
186
|
+
Refer [here](https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor) for details.
|
|
187
|
+
The UUID will be the same if app is restored from a backup or iCloud as it is saved in preferences. Users using older versions of this plugin will still receive the same previous UUID generated by another means as it will be retrieved from preferences.
|
|
188
|
+
|
|
189
|
+
### OS X Quirk
|
|
190
|
+
|
|
191
|
+
The `uuid` on OS X is generated automatically if it does not exist yet and is stored in the `standardUserDefaults` in the `CDVUUID` property.
|
|
192
|
+
|
|
193
|
+
## device.version
|
|
194
|
+
|
|
195
|
+
Get the operating system version.
|
|
196
|
+
|
|
197
|
+
var string = device.version;
|
|
198
|
+
|
|
199
|
+
### Supported Platforms
|
|
200
|
+
|
|
201
|
+
- Android
|
|
202
|
+
- Browser
|
|
203
|
+
- iOS
|
|
204
|
+
|
|
205
|
+
### Quick Example
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
// Android: Froyo OS would return "2.2"
|
|
209
|
+
// Eclair OS would return "2.1", "2.0.1", or "2.0"
|
|
210
|
+
// Version can also return update level "2.1-update1"
|
|
211
|
+
//
|
|
212
|
+
// Browser: Returns version number for the browser
|
|
213
|
+
//
|
|
214
|
+
// iOS: iOS 3.2 returns "3.2"
|
|
215
|
+
//
|
|
216
|
+
var deviceVersion = device.version;
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## device.manufacturer
|
|
220
|
+
|
|
221
|
+
Get the device's manufacturer.
|
|
222
|
+
|
|
223
|
+
var string = device.manufacturer;
|
|
224
|
+
|
|
225
|
+
### Supported Platforms
|
|
226
|
+
|
|
227
|
+
- Android
|
|
228
|
+
- iOS
|
|
229
|
+
|
|
230
|
+
### Quick Example
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
// Android: Motorola XT1032 would return "motorola"
|
|
234
|
+
// iOS: returns "Apple"
|
|
235
|
+
//
|
|
236
|
+
var deviceManufacturer = device.manufacturer;
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## device.isVirtual
|
|
240
|
+
|
|
241
|
+
whether the device is running on a simulator.
|
|
242
|
+
|
|
243
|
+
```js
|
|
244
|
+
var isSim = device.isVirtual;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## device.sdkVersion (Android only)
|
|
248
|
+
|
|
249
|
+
Get the Android device's SDK version ([SDK_INT](https://developer.android.com/reference/android/os/Build.VERSION#SDK_INT)).
|
|
250
|
+
|
|
251
|
+
### Supported Platforms
|
|
252
|
+
|
|
253
|
+
- Android
|
|
254
|
+
|
|
255
|
+
### OS X and Browser Quirk
|
|
256
|
+
|
|
257
|
+
The `isVirtual` property on OS X and Browser always returns false.
|
|
258
|
+
|
|
259
|
+
## device.serial
|
|
260
|
+
|
|
261
|
+
Get the device hardware serial number ([SERIAL](https://developer.android.com/reference/android/os/Build.html#SERIAL)).
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
var string = device.serial;
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Supported Platforms
|
|
268
|
+
|
|
269
|
+
- Android
|
|
270
|
+
- OS X
|
|
271
|
+
|
|
272
|
+
### Android Quirk
|
|
273
|
+
|
|
274
|
+
As of Android 9, the underlying native API that powered the `uuid` property is deprecated and will always return `UNKNOWN` without proper permissions. Cordova have never implemented handling the required permissions. As of Android 10, **all** non-resettable device identifiers are no longer readable by normal applications and will always return `UNKNOWN`. More information can be [read here](https://developer.android.com/about/versions/10/privacy/changes#non-resettable-device-ids).
|
|
275
|
+
|
|
276
|
+
## device.isiOSAppOnMac
|
|
277
|
+
|
|
278
|
+
The iOS app is running on the Mac desktop (Apple Silicon ARM64 processor, M1 or newer).
|
|
279
|
+
This parameter is only returned for iOS V14.0 or later, and is not returned for Android devices.
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
var boolean = device.isiOSAppOnMac;
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Supported Platforms
|
|
286
|
+
|
|
287
|
+
- iOS
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## iOS Privacy Manifest
|
|
292
|
+
|
|
293
|
+
As of May 1, 2024, Apple requires a privacy manifest file to be created for apps and third-party SDKs. The purpose of the privacy manifest file is to explain the data being collected and the reasons for the required APIs it uses. Starting with `cordova-ios@7.1.0`, APIs are available for configuring the privacy manifest file from `config.xml`.
|
|
294
|
+
|
|
295
|
+
This plugin comes pre-bundled with a `PrivacyInfo.xcprivacy` file that contains the list of APIs it uses and the reasons for using them.
|
|
296
|
+
|
|
297
|
+
However, as an app developer, it will be your responsibility to identify additional information explaining what your app does with that data.
|
|
298
|
+
|
|
299
|
+
In this case, you will need to review the "[Describing data use in privacy manifests](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_data_use_in_privacy_manifests)" to understand the list of known `NSPrivacyCollectedDataTypes` and `NSPrivacyCollectedDataTypePurposes`.
|
|
300
|
+
|
|
301
|
+
For example, if you collected the device ID for app functionality and analytics, you would write the following in `config.xml`:
|
|
302
|
+
|
|
303
|
+
```xml
|
|
304
|
+
<platform name="ios">
|
|
305
|
+
<privacy-manifest>
|
|
306
|
+
<key>NSPrivacyTracking</key>
|
|
307
|
+
<false/>
|
|
308
|
+
<key>NSPrivacyTrackingDomains</key>
|
|
309
|
+
<array/>
|
|
310
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
311
|
+
<array/>
|
|
312
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
313
|
+
<array>
|
|
314
|
+
<dict>
|
|
315
|
+
<key>NSPrivacyCollectedDataType</key>
|
|
316
|
+
<string>NSPrivacyCollectedDataTypeDeviceID</string>
|
|
317
|
+
<key>NSPrivacyCollectedDataTypeLinked</key>
|
|
318
|
+
<false/>
|
|
319
|
+
<key>NSPrivacyCollectedDataTypeTracking</key>
|
|
320
|
+
<false/>
|
|
321
|
+
<key>NSPrivacyCollectedDataTypePurposes</key>
|
|
322
|
+
<array>
|
|
323
|
+
<string>NSPrivacyCollectedDataTypePurposeAnalytics</string>
|
|
324
|
+
<string>NSPrivacyCollectedDataTypePurposeAppFunctionality</string>
|
|
325
|
+
</array>
|
|
326
|
+
</dict>
|
|
327
|
+
</array>
|
|
328
|
+
</privacy-manifest>
|
|
329
|
+
</platform>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Also, ensure all four keys—`NSPrivacyTracking`, `NSPrivacyTrackingDomains`, `NSPrivacyAccessedAPITypes`, and `NSPrivacyCollectedDataTypes`—are defined, even if you are not making an addition to the other items. Apple requires all to be defined.
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unvired/cordova-plugin-unvired-device",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Cordova Device Plugin",
|
|
5
|
+
"types": "./types/index.d.ts",
|
|
6
|
+
"cordova": {
|
|
7
|
+
"id": "cordova-plugin-unvired-device",
|
|
8
|
+
"platforms": [
|
|
9
|
+
"android",
|
|
10
|
+
"electron",
|
|
11
|
+
"ios",
|
|
12
|
+
"browser"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"repository": "github:apache/cordova-plugin-unvired-device",
|
|
16
|
+
"bugs": "https://github.com/apache/cordova-plugin-unvired-device/issues",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"cordova",
|
|
19
|
+
"device",
|
|
20
|
+
"ecosystem:cordova",
|
|
21
|
+
"cordova-android",
|
|
22
|
+
"cordova-electron",
|
|
23
|
+
"cordova-ios",
|
|
24
|
+
"cordova-browser"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "npm run lint",
|
|
28
|
+
"lint": "eslint ."
|
|
29
|
+
},
|
|
30
|
+
"author": "Unvired Inc.",
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"engines": {
|
|
33
|
+
"cordovaDependencies": {
|
|
34
|
+
"2.1.0": {
|
|
35
|
+
"cordova-electron": ">=3.0.0"
|
|
36
|
+
},
|
|
37
|
+
"3.0.0": {
|
|
38
|
+
"cordova-electron": ">=3.0.0",
|
|
39
|
+
"cordova-android": ">=7.0.0"
|
|
40
|
+
},
|
|
41
|
+
"4.0.0": {
|
|
42
|
+
"cordova": ">100"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@cordova/eslint-config": "^5.1.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
or more contributor license agreements. See the NOTICE file
|
|
5
|
+
distributed with this work for additional information
|
|
6
|
+
regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
to you under the Apache License, Version 2.0 (the
|
|
8
|
+
"License"); you may not use this file except in compliance
|
|
9
|
+
with the License. You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing,
|
|
14
|
+
software distributed under the License is distributed on an
|
|
15
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
KIND, either express or implied. See the License for the
|
|
17
|
+
specific language governing permissions and limitations
|
|
18
|
+
under the License.
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
22
|
+
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
|
23
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
24
|
+
id="cordova-plugin-unvired-device"
|
|
25
|
+
version="1.0.5">
|
|
26
|
+
<name>Device</name>
|
|
27
|
+
<description>Cordova Device Plugin</description>
|
|
28
|
+
<license>Apache 2.0</license>
|
|
29
|
+
<keywords>cordova,device</keywords>
|
|
30
|
+
<repo>https://github.com/apache/cordova-plugin-unvired-device</repo>
|
|
31
|
+
<issue>https://github.com/apache/cordova-plugin-unvired-device/issues</issue>
|
|
32
|
+
|
|
33
|
+
<engines>
|
|
34
|
+
<engine name="cordova-electron" version=">=3.0.0" />
|
|
35
|
+
<engine name="cordova-android" version=">=7.0.0" />
|
|
36
|
+
</engines>
|
|
37
|
+
|
|
38
|
+
<js-module src="www/device.js" name="device">
|
|
39
|
+
<clobbers target="device" />
|
|
40
|
+
</js-module>
|
|
41
|
+
|
|
42
|
+
<!-- android -->
|
|
43
|
+
<platform name="android">
|
|
44
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
45
|
+
<feature name="Device" >
|
|
46
|
+
<param name="android-package" value="org.apache.cordova.device.Device"/>
|
|
47
|
+
</feature>
|
|
48
|
+
</config-file>
|
|
49
|
+
|
|
50
|
+
<source-file src="src/android/Device.java" target-dir="src/org/apache/cordova/device" />
|
|
51
|
+
</platform>
|
|
52
|
+
|
|
53
|
+
<!-- ios -->
|
|
54
|
+
<platform name="ios">
|
|
55
|
+
<config-file target="config.xml" parent="/*">
|
|
56
|
+
<feature name="Device">
|
|
57
|
+
<param name="ios-package" value="CDVDevice"/>
|
|
58
|
+
</feature>
|
|
59
|
+
</config-file>
|
|
60
|
+
|
|
61
|
+
<header-file src="src/ios/CDVDevice.h" />
|
|
62
|
+
<source-file src="src/ios/CDVDevice.m" />
|
|
63
|
+
|
|
64
|
+
<resource-file src="src/ios/CDVDevice.bundle" target="CDVDevice.bundle" />
|
|
65
|
+
</platform>
|
|
66
|
+
|
|
67
|
+
<!-- electron -->
|
|
68
|
+
<platform name="electron">
|
|
69
|
+
<framework src="src/electron" />
|
|
70
|
+
</platform>
|
|
71
|
+
|
|
72
|
+
<!-- browser -->
|
|
73
|
+
<platform name="browser">
|
|
74
|
+
<config-file target="config.xml" parent="/*">
|
|
75
|
+
<feature name="Device">
|
|
76
|
+
<param name="browser-package" value="Device" />
|
|
77
|
+
</feature>
|
|
78
|
+
</config-file>
|
|
79
|
+
|
|
80
|
+
<js-module src="src/browser/DeviceProxy.js" name="DeviceProxy">
|
|
81
|
+
<runs />
|
|
82
|
+
</js-module>
|
|
83
|
+
</platform>
|
|
84
|
+
|
|
85
|
+
</plugin>
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
package org.apache.cordova.device;
|
|
20
|
+
|
|
21
|
+
import org.apache.cordova.CordovaWebView;
|
|
22
|
+
import org.apache.cordova.CallbackContext;
|
|
23
|
+
import org.apache.cordova.CordovaPlugin;
|
|
24
|
+
import org.apache.cordova.CordovaInterface;
|
|
25
|
+
import org.json.JSONArray;
|
|
26
|
+
import org.json.JSONException;
|
|
27
|
+
import org.json.JSONObject;
|
|
28
|
+
|
|
29
|
+
import android.provider.Settings;
|
|
30
|
+
|
|
31
|
+
public class Device extends CordovaPlugin {
|
|
32
|
+
|
|
33
|
+
public static String uuid; // Device UUID
|
|
34
|
+
|
|
35
|
+
private static final String ANDROID_PLATFORM = "Android";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Constructor.
|
|
39
|
+
*/
|
|
40
|
+
public Device() {
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Sets the context of the Command. This can then be used to do things like
|
|
45
|
+
* get file paths associated with the Activity.
|
|
46
|
+
*
|
|
47
|
+
* @param cordova The context of the main Activity.
|
|
48
|
+
* @param webView The CordovaWebView Cordova is running in.
|
|
49
|
+
*/
|
|
50
|
+
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
51
|
+
super.initialize(cordova, webView);
|
|
52
|
+
Device.uuid = getUuid();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Executes the request and returns PluginResult.
|
|
57
|
+
*
|
|
58
|
+
* @param action The action to execute.
|
|
59
|
+
* @param args JSONArray of arguments for the plugin.
|
|
60
|
+
* @param callbackContext The callback id used when calling back into JavaScript.
|
|
61
|
+
* @return True if the action was valid, false if not.
|
|
62
|
+
*/
|
|
63
|
+
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
|
64
|
+
if ("getDeviceInfo".equals(action)) {
|
|
65
|
+
JSONObject r = new JSONObject();
|
|
66
|
+
r.put("uuid", Device.uuid);
|
|
67
|
+
r.put("version", this.getOSVersion());
|
|
68
|
+
r.put("platform", this.getPlatform());
|
|
69
|
+
r.put("model", this.getModel());
|
|
70
|
+
r.put("manufacturer", this.getManufacturer());
|
|
71
|
+
r.put("isVirtual", this.isVirtual());
|
|
72
|
+
r.put("serial", this.getSerialNumber());
|
|
73
|
+
r.put("sdkVersion", this.getSDKVersion());
|
|
74
|
+
callbackContext.success(r);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//--------------------------------------------------------------------------
|
|
83
|
+
// LOCAL METHODS
|
|
84
|
+
//--------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get the OS name.
|
|
88
|
+
*
|
|
89
|
+
* @return "Android"
|
|
90
|
+
*/
|
|
91
|
+
public String getPlatform() {
|
|
92
|
+
return ANDROID_PLATFORM;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get the device's Universally Unique Identifier (UUID).
|
|
97
|
+
*
|
|
98
|
+
* @return android.provider.Settings.Secure.ANDROID_ID
|
|
99
|
+
*/
|
|
100
|
+
public String getUuid() {
|
|
101
|
+
return Settings.Secure.getString(this.cordova.getContext().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public String getModel() {
|
|
105
|
+
return android.os.Build.MODEL;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public String getManufacturer() {
|
|
109
|
+
return android.os.Build.MANUFACTURER;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public String getSerialNumber() {
|
|
113
|
+
return android.os.Build.SERIAL;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get the OS version.
|
|
118
|
+
*
|
|
119
|
+
* @return android.os.Build.VERSION.RELEASE
|
|
120
|
+
*/
|
|
121
|
+
public String getOSVersion() {
|
|
122
|
+
return android.os.Build.VERSION.RELEASE;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public String getSDKVersion() {
|
|
126
|
+
return String.valueOf(android.os.Build.VERSION.SDK_INT);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public boolean isVirtual() {
|
|
130
|
+
return android.os.Build.FINGERPRINT.contains("generic") ||
|
|
131
|
+
android.os.Build.PRODUCT.contains("sdk");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var browser = require('cordova/platform');
|
|
22
|
+
|
|
23
|
+
function getPlatform () {
|
|
24
|
+
return 'browser';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getModel () {
|
|
28
|
+
return getBrowserInfo(true);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getVersion () {
|
|
32
|
+
return getBrowserInfo(false);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getBrowserInfo (getModel) {
|
|
36
|
+
var userAgent = navigator.userAgent;
|
|
37
|
+
var returnVal = '';
|
|
38
|
+
var offset;
|
|
39
|
+
|
|
40
|
+
if ((offset = userAgent.indexOf('Edge')) !== -1) {
|
|
41
|
+
returnVal = getModel ? 'Edge' : userAgent.substring(offset + 5);
|
|
42
|
+
} else if ((offset = userAgent.indexOf('Chrome')) !== -1) {
|
|
43
|
+
returnVal = getModel ? 'Chrome' : userAgent.substring(offset + 7);
|
|
44
|
+
} else if ((offset = userAgent.indexOf('Safari')) !== -1) {
|
|
45
|
+
if (getModel) {
|
|
46
|
+
returnVal = 'Safari';
|
|
47
|
+
} else {
|
|
48
|
+
returnVal = userAgent.substring(offset + 7);
|
|
49
|
+
|
|
50
|
+
if ((offset = userAgent.indexOf('Version')) !== -1) {
|
|
51
|
+
returnVal = userAgent.substring(offset + 8);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else if ((offset = userAgent.indexOf('Firefox')) !== -1) {
|
|
55
|
+
returnVal = getModel ? 'Firefox' : userAgent.substring(offset + 8);
|
|
56
|
+
} else if ((offset = userAgent.indexOf('MSIE')) !== -1) {
|
|
57
|
+
returnVal = getModel ? 'MSIE' : userAgent.substring(offset + 5);
|
|
58
|
+
} else if ((offset = userAgent.indexOf('Trident')) !== -1) {
|
|
59
|
+
returnVal = getModel ? 'MSIE' : '11';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if ((offset = returnVal.indexOf(';')) !== -1 || (offset = returnVal.indexOf(' ')) !== -1) {
|
|
63
|
+
returnVal = returnVal.substring(0, offset);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return returnVal;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
getDeviceInfo: function (success, error) {
|
|
71
|
+
setTimeout(function () {
|
|
72
|
+
success({
|
|
73
|
+
cordova: browser.cordovaVersion,
|
|
74
|
+
platform: getPlatform(),
|
|
75
|
+
model: getModel(),
|
|
76
|
+
version: getVersion(),
|
|
77
|
+
uuid: null,
|
|
78
|
+
isVirtual: false
|
|
79
|
+
});
|
|
80
|
+
}, 0);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
require('cordova/exec/proxy').add('Device', module.exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const { system, osInfo } = require('systeminformation');
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
getDeviceInfo: async () => {
|
|
26
|
+
try {
|
|
27
|
+
const { manufacturer, model, uuid } = await system();
|
|
28
|
+
const { platform, distro, codename, build: version } = await osInfo();
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
manufacturer,
|
|
32
|
+
model,
|
|
33
|
+
platform: platform === 'darwin' ? codename : distro,
|
|
34
|
+
version,
|
|
35
|
+
uuid,
|
|
36
|
+
isVirtual: false
|
|
37
|
+
};
|
|
38
|
+
} catch (e) {
|
|
39
|
+
console.log(e);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cordova-plugin-unvired-device",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Electron Native Support for Cordova Device Plugin",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cordova",
|
|
8
|
+
"electron",
|
|
9
|
+
"device",
|
|
10
|
+
"native"
|
|
11
|
+
],
|
|
12
|
+
"author": "Apache Software Foundation",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"systeminformation": "^5.11.9"
|
|
16
|
+
},
|
|
17
|
+
"cordova": {
|
|
18
|
+
"serviceName": "Device"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
or more contributor license agreements. See the NOTICE file
|
|
5
|
+
distributed with this work for additional information
|
|
6
|
+
regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
to you under the Apache License, Version 2.0 (the
|
|
8
|
+
"License"); you may not use this file except in compliance
|
|
9
|
+
with the License. You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing,
|
|
14
|
+
software distributed under the License is distributed on an
|
|
15
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
KIND, either express or implied. See the License for the
|
|
17
|
+
specific language governing permissions and limitations
|
|
18
|
+
under the License.
|
|
19
|
+
-->
|
|
20
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
21
|
+
<plist version="1.0">
|
|
22
|
+
<dict>
|
|
23
|
+
<key>NSPrivacyTracking</key>
|
|
24
|
+
<false/>
|
|
25
|
+
<key>NSPrivacyTrackingDomains</key>
|
|
26
|
+
<array/>
|
|
27
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
28
|
+
<array>
|
|
29
|
+
<dict>
|
|
30
|
+
<key>NSPrivacyAccessedAPIType</key>
|
|
31
|
+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
|
|
32
|
+
<key>NSPrivacyAccessedAPITypeReasons</key>
|
|
33
|
+
<array>
|
|
34
|
+
<string>CA92.1</string>
|
|
35
|
+
</array>
|
|
36
|
+
</dict>
|
|
37
|
+
</array>
|
|
38
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
39
|
+
<array/>
|
|
40
|
+
</dict>
|
|
41
|
+
</plist>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#import <UIKit/UIKit.h>
|
|
21
|
+
#import <Cordova/CDVPlugin.h>
|
|
22
|
+
|
|
23
|
+
@interface CDVDevice : CDVPlugin
|
|
24
|
+
{}
|
|
25
|
+
|
|
26
|
+
+ (NSString*)cordovaVersion;
|
|
27
|
+
|
|
28
|
+
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command;
|
|
29
|
+
|
|
30
|
+
@end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
|
4
|
+
distributed with this work for additional information
|
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
|
7
|
+
"License"); you may not use this file except in compliance
|
|
8
|
+
with the License. You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
|
13
|
+
software distributed under the License is distributed on an
|
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
KIND, either express or implied. See the License for the
|
|
16
|
+
specific language governing permissions and limitations
|
|
17
|
+
under the License.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#include <sys/types.h>
|
|
21
|
+
#include <sys/sysctl.h>
|
|
22
|
+
#include "TargetConditionals.h"
|
|
23
|
+
|
|
24
|
+
#import <Availability.h>
|
|
25
|
+
|
|
26
|
+
#import <Cordova/CDV.h>
|
|
27
|
+
#import "CDVDevice.h"
|
|
28
|
+
|
|
29
|
+
@implementation UIDevice (ModelVersion)
|
|
30
|
+
|
|
31
|
+
- (NSString*)modelVersion
|
|
32
|
+
{
|
|
33
|
+
#if TARGET_IPHONE_SIMULATOR
|
|
34
|
+
NSString* platform = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
|
|
35
|
+
#else
|
|
36
|
+
size_t size;
|
|
37
|
+
|
|
38
|
+
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
|
|
39
|
+
char* machine = malloc(size);
|
|
40
|
+
sysctlbyname("hw.machine", machine, &size, NULL, 0);
|
|
41
|
+
NSString* platform = [NSString stringWithUTF8String:machine];
|
|
42
|
+
free(machine);
|
|
43
|
+
#endif
|
|
44
|
+
return platform;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@end
|
|
48
|
+
|
|
49
|
+
@interface CDVDevice () {}
|
|
50
|
+
@end
|
|
51
|
+
|
|
52
|
+
@implementation CDVDevice
|
|
53
|
+
|
|
54
|
+
- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
|
|
55
|
+
{
|
|
56
|
+
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
|
|
57
|
+
static NSString* UUID_KEY = @"CDVUUID";
|
|
58
|
+
|
|
59
|
+
// Check user defaults first to maintain backwards compaitibility with previous versions
|
|
60
|
+
// which didn't user identifierForVendor
|
|
61
|
+
NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
|
|
62
|
+
if (app_uuid == nil) {
|
|
63
|
+
if ([device respondsToSelector:@selector(identifierForVendor)]) {
|
|
64
|
+
app_uuid = [[device identifierForVendor] UUIDString];
|
|
65
|
+
} else {
|
|
66
|
+
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
|
67
|
+
app_uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid);
|
|
68
|
+
CFRelease(uuid);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[userDefaults setObject:app_uuid forKey:UUID_KEY];
|
|
72
|
+
[userDefaults synchronize];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return app_uuid;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
|
|
79
|
+
{
|
|
80
|
+
NSDictionary* deviceProperties = [self deviceProperties];
|
|
81
|
+
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
|
|
82
|
+
|
|
83
|
+
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
- (NSDictionary*)deviceProperties
|
|
87
|
+
{
|
|
88
|
+
UIDevice* device = [UIDevice currentDevice];
|
|
89
|
+
|
|
90
|
+
return @{
|
|
91
|
+
@"manufacturer": @"Apple",
|
|
92
|
+
@"model": [device modelVersion],
|
|
93
|
+
@"platform": @"iOS",
|
|
94
|
+
@"version": [device systemVersion],
|
|
95
|
+
@"uuid": [self uniqueAppInstanceIdentifier:device],
|
|
96
|
+
@"cordova": [[self class] cordovaVersion],
|
|
97
|
+
@"isVirtual": @([self isVirtual]),
|
|
98
|
+
@"isiOSAppOnMac": @([self isiOSAppOnMac])
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
+ (NSString*)cordovaVersion
|
|
103
|
+
{
|
|
104
|
+
return CDV_VERSION;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (BOOL)isVirtual
|
|
108
|
+
{
|
|
109
|
+
#if TARGET_OS_SIMULATOR
|
|
110
|
+
return true;
|
|
111
|
+
#elif TARGET_IPHONE_SIMULATOR
|
|
112
|
+
return true;
|
|
113
|
+
#else
|
|
114
|
+
return false;
|
|
115
|
+
#endif
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
- (BOOL) isiOSAppOnMac
|
|
120
|
+
{
|
|
121
|
+
#if __IPHONE_14_0
|
|
122
|
+
if (@available(iOS 14.0, *)) {
|
|
123
|
+
return [[NSProcessInfo processInfo] isiOSAppOnMac];
|
|
124
|
+
}
|
|
125
|
+
#endif
|
|
126
|
+
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@end
|
package/www/device.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
var argscheck = require('cordova/argscheck');
|
|
23
|
+
var channel = require('cordova/channel');
|
|
24
|
+
var exec = require('cordova/exec');
|
|
25
|
+
var cordova = require('cordova');
|
|
26
|
+
|
|
27
|
+
channel.createSticky('onCordovaInfoReady');
|
|
28
|
+
// Tell cordova channel to wait on the CordovaInfoReady event
|
|
29
|
+
channel.waitForInitialization('onCordovaInfoReady');
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
|
|
33
|
+
* phone, etc.
|
|
34
|
+
* @constructor
|
|
35
|
+
*/
|
|
36
|
+
function Device () {
|
|
37
|
+
this.available = false;
|
|
38
|
+
this.platform = null;
|
|
39
|
+
this.version = null;
|
|
40
|
+
this.uuid = null;
|
|
41
|
+
this.cordova = null;
|
|
42
|
+
this.model = null;
|
|
43
|
+
this.manufacturer = null;
|
|
44
|
+
this.isVirtual = null;
|
|
45
|
+
this.serial = null;
|
|
46
|
+
this.isiOSAppOnMac = null;
|
|
47
|
+
|
|
48
|
+
var me = this;
|
|
49
|
+
|
|
50
|
+
channel.onCordovaReady.subscribe(function () {
|
|
51
|
+
me.getInfo(
|
|
52
|
+
function (info) {
|
|
53
|
+
// ignoring info.cordova returning from native, we should use value from cordova.version defined in cordova.js
|
|
54
|
+
// TODO: CB-5105 native implementations should not return info.cordova
|
|
55
|
+
var buildLabel = cordova.version;
|
|
56
|
+
me.available = true;
|
|
57
|
+
me.platform = info.platform;
|
|
58
|
+
me.version = info.version;
|
|
59
|
+
me.uuid = info.uuid;
|
|
60
|
+
me.cordova = buildLabel;
|
|
61
|
+
me.model = info.model;
|
|
62
|
+
me.isVirtual = info.isVirtual;
|
|
63
|
+
// isiOSAppOnMac is iOS specific. If defined, it will be appended.
|
|
64
|
+
if (info.isiOSAppOnMac !== undefined) {
|
|
65
|
+
me.isiOSAppOnMac = info.isiOSAppOnMac;
|
|
66
|
+
}
|
|
67
|
+
me.manufacturer = info.manufacturer || 'unknown';
|
|
68
|
+
me.serial = info.serial || 'unknown';
|
|
69
|
+
|
|
70
|
+
// SDK Version is Android specific. If defined, it will be appended.
|
|
71
|
+
if (info.sdkVersion !== undefined) {
|
|
72
|
+
me.sdkVersion = info.sdkVersion;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
channel.onCordovaInfoReady.fire();
|
|
76
|
+
},
|
|
77
|
+
function (e) {
|
|
78
|
+
me.available = false;
|
|
79
|
+
console.error('[ERROR] Error initializing cordova-plugin-unvired-device: ' + e);
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get device info
|
|
87
|
+
*
|
|
88
|
+
* @param {Function} successCallback The function to call when the heading data is available
|
|
89
|
+
* @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
|
|
90
|
+
*/
|
|
91
|
+
Device.prototype.getInfo = function (successCallback, errorCallback) {
|
|
92
|
+
argscheck.checkArgs('fF', 'Device.getInfo', arguments);
|
|
93
|
+
exec(successCallback, errorCallback, 'Device', 'getDeviceInfo', []);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
module.exports = new Device();
|