-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathdiagnostic.ts
574 lines (507 loc) · 21.3 KB
/
diagnostic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
import { Cordova, Plugin } from './plugin';
/**
* @name Diagnostic
* @description
* Checks whether device hardware features are enabled or available to the app, e.g. camera, GPS, wifi
*
* @usage
* ```typescript
* import { Diagnostic } from 'ionic-native';
*
* let successCallback = (isAvailable) => { console.log('Is available? ' + isAvailable); };
* let errorCallback = (e) => console.error(e);
*
* Diagnostic.isCameraAvailable().then(successCallback).catch(errorCallback);
*
* Diagnostic.isBluetoothAvailable().then(successCallback, errorCallback);
*
*
* Diagnostic.getBluetoothState()
* .then((state) => {
* if (state == Diagnostic.bluetoothStates.POWERED_ON){
* // do something
* } else {
* // do something else
* }
* }).catch(e => console.error(e));
*
* ```
*/
@Plugin({
pluginName: 'Diagnostic',
plugin: 'cordova.plugins.diagnostic',
pluginRef: 'cordova.plugins.diagnostic',
repo: 'https://github.com/dpa99c/cordova-diagnostic-plugin'
})
export class Diagnostic {
static permission = {
READ_CALENDAR: 'READ_CALENDAR',
WRITE_CALENDAR: 'WRITE_CALENDAR',
CAMERA: 'CAMERA',
READ_CONTACTS: 'READ_CONTACTS',
WRITE_CONTACTS: 'WRITE_CONTACTS',
GET_ACCOUNTS: 'GET_ACCOUNTS',
ACCESS_FINE_LOCATION: 'ACCESS_FINE_LOCATION',
ACCESS_COARSE_LOCATION: 'ACCESS_COARSE_LOCATION',
RECORD_AUDIO: 'RECORD_AUDIO',
READ_PHONE_STATE: 'READ_PHONE_STATE',
CALL_PHONE: 'CALL_PHONE',
ADD_VOICEMAIL: 'ADD_VOICEMAIL',
USE_SIP: 'USE_SIP',
PROCESS_OUTGOING_CALLS: 'PROCESS_OUTGOING_CALLS',
READ_CALL_LOG: 'READ_CALL_LOG',
WRITE_CALL_LOG: 'WRITE_CALL_LOG',
SEND_SMS: 'SEND_SMS',
RECEIVE_SMS: 'RECEIVE_SMS',
READ_SMS: 'READ_SMS',
RECEIVE_WAP_PUSH: 'RECEIVE_WAP_PUSH',
RECEIVE_MMS: 'RECEIVE_MMS',
WRITE_EXTERNAL_STORAGE: 'WRITE_EXTERNAL_STORAGE',
READ_EXTERNAL_STORAGE: 'READ_EXTERNAL_STORAGE',
BODY_SENSORS: 'BODY_SENSORS'
};
static permissionStatus = {
GRANTED: 'GRANTED',
GRANTED_WHEN_IN_USE: 'GRANTED_WHEN_IN_USE', // iOS
RESTRICTED: 'RESTRICTED', // iOS
DENIED: 'DENIED',
DENIED_ALWAYS: 'DENIED_ALWAYS', // android
NOT_REQUESTED: 'NOT_REQUESTED'
};
static locationAuthorizationMode = {
ALWAYS: 'ALWAYS',
WHEN_IN_USE: 'WHEN_IN_USE'
};
static permissionGroups = {
CALENDAR: ['READ_CALENDAR', 'WRITE_CALENDAR'],
CAMERA: ['CAMERA'],
CONTACTS: ['READ_CONTACTS', 'WRITE_CONTACTS', 'GET_ACCOUNTS'],
LOCATION: ['ACCESS_FINE_LOCATION', 'ACCESS_COARSE_LOCATION'],
MICROPHONE: ['RECORD_AUDIO'],
PHONE: ['READ_PHONE_STATE', 'CALL_PHONE', 'ADD_VOICEMAIL', 'USE_SIP', 'PROCESS_OUTGOING_CALLS', 'READ_CALL_LOG', 'WRITE_CALL_LOG'],
SENSORS: ['BODY_SENSORS'],
SMS: ['SEND_SMS', 'RECEIVE_SMS', 'READ_SMS', 'RECEIVE_WAP_PUSH', 'RECEIVE_MMS'],
STORAGE: ['READ_EXTERNAL_STORAGE', 'WRITE_EXTERNAL_STORAGE']
};
static locationMode = {
HIGH_ACCURACY: 'high_accuracy',
DEVICE_ONLY: 'device_only',
BATTERY_SAVING: 'battery_saving',
LOCATION_OFF: 'location_off'
};
static bluetoothState = {
UNKNOWN: 'unknown',
RESETTING: 'resetting', // iOS
UNSUPPORTED: 'unsupported', // iOS
UNAUTHORIZED: 'unauthorized', // iOS
POWERED_OFF: 'powered_off',
POWERED_ON: 'powered_on',
POWERING_OFF: 'powering_off',
POWERING_ON: 'powering_on'
};
/**
* Checks if app is able to access device location.
* @returns {Promise<any>}
*/
@Cordova()
static isLocationAvailable(): Promise<any> { return; }
/**
* Checks if Wifi is connected/enabled. On iOS this returns true if the device is connected to a network by WiFi. On Android and Windows 10 Mobile this returns true if the WiFi setting is set to enabled.
* On Android this requires permission. `<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />`
* @returns {Promise<any>}
*/
@Cordova()
static isWifiAvailable(): Promise<any> { return; }
/**
* Checks if the device has a camera. On Android this returns true if the device has a camera. On iOS this returns true if both the device has a camera AND the application is authorized to use it. On Windows 10 Mobile this returns true if both the device has a rear-facing camera AND the
* application is authorized to use it.
* @returns {Promise<any>}
*/
@Cordova()
static isCameraAvailable(): Promise<any> { return; }
/**
* Checks if the device has Bluetooth capabilities and if so that Bluetooth is switched on (same on Android, iOS and Windows 10 Mobile)
* On Android this requires permission <uses-permission android:name="android.permission.BLUETOOTH" />
* @returns {Promise<any>}
*/
@Cordova()
static isBluetoothAvailable(): Promise<any> { return; }
/**
* Displays the device location settings to allow user to enable location services/change location mode.
*/
@Cordova({ sync: true, platforms: ['Android', 'Windows 10'] })
static switchToLocationSettings(): void { }
/**
* Displays mobile settings to allow user to enable mobile data.
*/
@Cordova({ sync: true, platforms: ['Android', 'Windows 10'] })
static switchToMobileDataSettings(): void { }
/**
* Displays Bluetooth settings to allow user to enable Bluetooth.
*/
@Cordova({ sync: true, platforms: ['Android', 'Windows 10'] })
static switchToBluetoothSettings(): void { }
/**
* Displays WiFi settings to allow user to enable WiFi.
*/
@Cordova({ sync: true, platforms: ['Android', 'Windows 10'] })
static switchToWifiSettings(): void { }
/**
* Returns true if the WiFi setting is set to enabled, and is the same as `isWifiAvailable()`
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android', 'Windows 10'] })
static isWifiEnabled(): Promise<boolean> { return; }
/**
* Enables/disables WiFi on the device.
* Requires `ACCESS_WIFI_STATE` and `CHANGE_WIFI_STATE` permissions on Android
* @param state {boolean}
* @returns {Promise<any>}
*/
@Cordova({ callbackOrder: 'reverse', platforms: ['Android', 'Windows 10'] })
static setWifiState(state: boolean): Promise<any> { return; }
/**
* Enables/disables Bluetooth on the device.
* Requires `BLUETOOTH` and `BLUETOOTH_ADMIN` permissions on Android
* @param state {boolean}
* @returns {Promise<any>}
*/
@Cordova({ callbackOrder: 'reverse', platforms: ['Android', 'Windows 10'] })
static setBluetoothState(state: boolean): Promise<any> { return; }
/**
* Returns true if the device setting for location is on. On Android this returns true if Location Mode is switched on. On iOS this returns true if Location Services is switched on.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isLocationEnabled(): Promise<boolean> { return; }
/**
* Checks if the application is authorized to use location.
* Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
* @returns {Promise<any>}
*/
@Cordova()
static isLocationAuthorized(): Promise<any> { return; }
/**
* Returns the location authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getLocationAuthorizationStatus(): Promise<any> { return; }
/**
* Returns the location authorization status for the application.
* Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
*
* mode - (iOS-only / optional) location authorization mode: "always" or "when_in_use". If not specified, defaults to "when_in_use".
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'], callbackOrder: 'reverse' })
static requestLocationAuthorization(mode?: string): Promise<any> { return; }
/**
* Checks if camera hardware is present on device.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isCameraPresent(): Promise<any> { return; }
/**
* Checks if the application is authorized to use the camera.
* Note for Android: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isCameraAuthorized(): Promise<any> { return; }
/**
* Returns the camera authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getCameraAuthorizationStatus(): Promise<any> { return; }
/**
* Requests camera authorization for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static requestCameraAuthorization(): Promise<any> { return; }
/**
* Checks if the application is authorized to use the microphone.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isMicrophoneAuthorized(): Promise<boolean> { return; }
/**
* Returns the microphone authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getMicrophoneAuthorizationStatus(): Promise<any> { return; }
/**
* Requests microphone authorization for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static requestMicrophoneAuthorization(): Promise<any> { return; }
/**
* Checks if the application is authorized to use contacts (address book).
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isContactsAuthorized(): Promise<boolean> { return; }
/**
* Returns the contacts authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getContactsAuthorizationStatus(): Promise<any> { return; }
/**
* Requests contacts authorization for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static requestContactsAuthorization(): Promise<any> { return; }
/**
* Checks if the application is authorized to use the calendar.
*
* Notes for Android:
* - This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return TRUE as permissions are already granted at installation time.
*
* Notes for iOS:
* - This relates to Calendar Events (not Calendar Reminders)
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static isCalendarAuthorized(): Promise<boolean> { return; }
/**
* Returns the calendar authorization status for the application.
*
* Notes for Android:
* - This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return `GRANTED` status as permissions are already granted at installation time.
*
* Notes for iOS:
* - This relates to Calendar Events (not Calendar Reminders)
*
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getCalendarAuthorizationStatus(): Promise<any> { return; }
/**
* Requests calendar authorization for the application.
*
* Notes for iOS:
* - Should only be called if authorization status is NOT_DETERMINED. Calling it when in any other state will have no effect and just return the current authorization status.
* - This relates to Calendar Events (not Calendar Reminders)
*
* Notes for Android:
* - This is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time.
* - This requests permission for `READ_CALENDAR` run-time permission
* - Required permissions must be added to `AndroidManifest.xml` as appropriate - see Android permissions: `READ_CALENDAR`, `WRITE_CALENDAR`
*
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static requestCalendarAuthorization(): Promise<any> { return; }
/**
* Opens settings page for this app.
* On Android, this opens the "App Info" page in the Settings app.
* On iOS, this opens the app settings page in the Settings app. This works only on iOS 8+ - iOS 7 and below will invoke the errorCallback.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static switchToSettings(): Promise<any> { return; }
/**
* Returns the state of Bluetooth on the device.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android', 'iOS'] })
static getBluetoothState(): Promise<any> { return; }
/**
* Registers a function to be called when a change in Bluetooth state occurs.
* @param handler
*/
@Cordova({ platforms: ['Android', 'iOS'], sync: true })
static registerBluetoothStateChangeHandler(handler: Function): void { }
/**
* Registers a function to be called when a change in Location state occurs.
* @param handler
*/
@Cordova({ platforms: ['Android', 'iOS'], sync: true })
static registerLocationStateChangeHandler(handler: Function): void { }
/**
* Checks if high-accuracy locations are available to the app from GPS hardware.
* Returns true if Location mode is enabled and is set to "Device only" or "High accuracy" AND if the app is authorised to use location.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android'] })
static isGpsLocationAvailable(): Promise<boolean> { return; }
/**
* Checks if location mode is set to return high-accuracy locations from GPS hardware.
* Returns true if Location mode is enabled and is set to either:
* - Device only = GPS hardware only (high accuracy)
* - High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'] })
static isGpsLocationEnabled(): Promise<any> { return; }
/**
* Checks if low-accuracy locations are available to the app from network triangulation/WiFi access points.
* Returns true if Location mode is enabled and is set to "Battery saving" or "High accuracy" AND if the app is authorised to use location.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'] })
static isNetworkLocationAvailable(): Promise<any> { return; }
/**
* Checks if location mode is set to return low-accuracy locations from network triangulation/WiFi access points.
* Returns true if Location mode is enabled and is set to either:
* - Battery saving = network triangulation and Wifi network IDs (low accuracy)
* - High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'] })
static isNetworkLocationEnabled(): Promise<any> { return; }
/**
* Returns the current location mode setting for the device.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'] })
static getLocationMode(): Promise<any> { return; }
/**
* Returns the current authorisation status for a given permission.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
* @param permission
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'], callbackOrder: 'reverse' })
static getPermissionAuthorizationStatus(permission: any): Promise<any> { return; }
/**
* Returns the current authorisation status for multiple permissions.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
* @param permissions
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'], callbackOrder: 'reverse' })
static getPermissionsAuthorizationStatus(permissions: any[]): Promise<any> { return; }
/**
* Requests app to be granted authorisation for a runtime permission.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will have no effect as the permissions are already granted at installation time.
* @param permission
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'], callbackOrder: 'reverse' })
static requestRuntimePermission(permission: any): Promise<any> { return; }
/**
* Requests app to be granted authorisation for multiple runtime permissions.
* Note: this is intended for Android 6 / API 23 and above. Calling on Android 5 / API 22 and below will always return GRANTED status as permissions are already granted at installation time.
* @param permissions
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['Android'], callbackOrder: 'reverse' })
static requestRuntimePermissions(permissions: any[]): Promise<any> { return; }
/**
* Indicates if the plugin is currently requesting a runtime permission via the native API.
* Note that only one request can be made concurrently because the native API cannot handle concurrent requests,
* so the plugin will invoke the error callback if attempting to make more than one simultaneous request.
* Multiple permission requests should be grouped into a single call since the native API is setup to handle batch requests of multiple permission groups.
* @returns {boolean}
*/
@Cordova({ sync: true })
static isRequestingPermission(): boolean { return; }
/**
* Registers a function to be called when a runtime permission request has completed.
* Pass in a falsey value to de-register the currently registered function.
* @param handler {Function}
*/
@Cordova({ sync: true })
static registerPermissionRequestCompleteHandler(handler: Function): void { return; }
/**
* Checks if the device setting for Bluetooth is switched on.
* This requires `BLUETOOTH` permission on Android
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android'] })
static isBluetoothEnabled(): Promise<boolean> { return; }
/**
* Checks if the device has Bluetooth capabilities.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android'] })
static hasBluetoothSupport(): Promise<boolean> { return; }
/**
* Checks if the device has Bluetooth Low Energy (LE) capabilities.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android'] })
static hasBluetoothLESupport(): Promise<boolean> { return; }
/**
* Checks if the device supports Bluetooth Low Energy (LE) Peripheral mode.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['Android'] })
static hasBluetoothLEPeripheralSupport(): Promise<boolean> { return; }
/**
* Checks if the application is authorized to use the Camera Roll in Photos app.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static isCameraRollAuthorized(): Promise<boolean> { return; }
/**
* Returns the authorization status for the application to use the Camera Roll in Photos app.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static getCameraRollAuthorizationStatus(): Promise<boolean> { return; }
/**
* Requests camera roll authorization for the application.
* Should only be called if authorization status is NOT_REQUESTED.
* Calling it when in any other state will have no effect.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['iOS'] })
static requestCameraRollAuthorization(): Promise<any> { return; }
/**
* Checks if remote (push) notifications are enabled.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static isRemoteNotificationsEnabled(): Promise<boolean> { return; }
/**
* Indicates if the app is registered for remote (push) notifications on the device.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static isRegisteredForRemoteNotifications(): Promise<boolean> { return; }
/**
* Indicates the current setting of notification types for the app in the Settings app.
* Note: on iOS 8+, if "Allow Notifications" switch is OFF, all types will be returned as disabled.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['iOS'] })
static getRemoteNotificationTypes(): Promise<any> { return; }
/**
* Checks if the application is authorized to use reminders.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static isRemindersAuthorized(): Promise<boolean> { return; }
/**
* Returns the reminders authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['iOS'] })
static getRemindersAuthorizationStatus(): Promise<any> { return; }
/**
* Requests reminders authorization for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['iOS'] })
static requestRemindersAuthorization(): Promise<any> { return; }
/**
* Checks if the application is authorized for background refresh.
* @returns {Promise<boolean>}
*/
@Cordova({ platforms: ['iOS'] })
static isBackgroundRefreshAuthorized(): Promise<boolean> { return; }
/**
* Returns the background refresh authorization status for the application.
* @returns {Promise<any>}
*/
@Cordova({ platforms: ['iOS'] })
static getBackgroundRefreshStatus(): Promise<any> { return; }
}