cordova.plugins.diagnostic 6.0.4

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 (75) hide show
  1. package/.github/FUNDING.yml +6 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +123 -0
  3. package/.github/ISSUE_TEMPLATE/documentation-issue.md +36 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +41 -0
  5. package/.github/PULL_REQUEST_TEMPLATE.md +37 -0
  6. package/.github/stale.yml +17 -0
  7. package/CHANGELOG.md +390 -0
  8. package/README.md +3709 -0
  9. package/cordova.plugins.diagnostic.d.ts +1113 -0
  10. package/package.json +54 -0
  11. package/plugin.xml +496 -0
  12. package/scripts/apply-modules.js +165 -0
  13. package/scripts/logger.js +94 -0
  14. package/src/android/Diagnostic.java +856 -0
  15. package/src/android/Diagnostic_Bluetooth.java +297 -0
  16. package/src/android/Diagnostic_Camera.java +134 -0
  17. package/src/android/Diagnostic_External_Storage.java +273 -0
  18. package/src/android/Diagnostic_Location.java +319 -0
  19. package/src/android/Diagnostic_NFC.java +270 -0
  20. package/src/android/Diagnostic_Notifications.java +157 -0
  21. package/src/android/Diagnostic_Wifi.java +155 -0
  22. package/src/ios/Diagnostic.h +56 -0
  23. package/src/ios/Diagnostic.m +282 -0
  24. package/src/ios/Diagnostic_Bluetooth.h +24 -0
  25. package/src/ios/Diagnostic_Bluetooth.m +170 -0
  26. package/src/ios/Diagnostic_Calendar.h +24 -0
  27. package/src/ios/Diagnostic_Calendar.m +94 -0
  28. package/src/ios/Diagnostic_Camera.h +27 -0
  29. package/src/ios/Diagnostic_Camera.m +194 -0
  30. package/src/ios/Diagnostic_Contacts.h +24 -0
  31. package/src/ios/Diagnostic_Contacts.m +93 -0
  32. package/src/ios/Diagnostic_Location.h +31 -0
  33. package/src/ios/Diagnostic_Location.m +284 -0
  34. package/src/ios/Diagnostic_Microphone.h +21 -0
  35. package/src/ios/Diagnostic_Microphone.m +97 -0
  36. package/src/ios/Diagnostic_Motion.h +27 -0
  37. package/src/ios/Diagnostic_Motion.m +143 -0
  38. package/src/ios/Diagnostic_Notifications.h +22 -0
  39. package/src/ios/Diagnostic_Notifications.m +235 -0
  40. package/src/ios/Diagnostic_Reminders.h +24 -0
  41. package/src/ios/Diagnostic_Reminders.m +93 -0
  42. package/src/ios/Diagnostic_Wifi.h +19 -0
  43. package/src/ios/Diagnostic_Wifi.m +108 -0
  44. package/src/windows/diagnosticProxy.bluetooth.js +23 -0
  45. package/src/windows/diagnosticProxy.camera.js +35 -0
  46. package/src/windows/diagnosticProxy.js +137 -0
  47. package/src/windows/diagnosticProxy.location.js +54 -0
  48. package/src/windows/diagnosticProxy.wifi.js +18 -0
  49. package/www/android/diagnostic.bluetooth.js +211 -0
  50. package/www/android/diagnostic.calendar.js +90 -0
  51. package/www/android/diagnostic.camera.js +203 -0
  52. package/www/android/diagnostic.contacts.js +91 -0
  53. package/www/android/diagnostic.external_storage.js +102 -0
  54. package/www/android/diagnostic.js +1309 -0
  55. package/www/android/diagnostic.location.js +282 -0
  56. package/www/android/diagnostic.microphone.js +89 -0
  57. package/www/android/diagnostic.nfc.js +127 -0
  58. package/www/android/diagnostic.notifications.js +74 -0
  59. package/www/android/diagnostic.wifi.js +90 -0
  60. package/www/ios/diagnostic.bluetooth.js +127 -0
  61. package/www/ios/diagnostic.calendar.js +97 -0
  62. package/www/ios/diagnostic.camera.js +212 -0
  63. package/www/ios/diagnostic.contacts.js +98 -0
  64. package/www/ios/diagnostic.js +990 -0
  65. package/www/ios/diagnostic.location.js +236 -0
  66. package/www/ios/diagnostic.microphone.js +99 -0
  67. package/www/ios/diagnostic.motion.js +160 -0
  68. package/www/ios/diagnostic.notifications.js +189 -0
  69. package/www/ios/diagnostic.reminders.js +97 -0
  70. package/www/ios/diagnostic.wifi.js +80 -0
  71. package/www/windows/diagnostic.bluetooth.js +51 -0
  72. package/www/windows/diagnostic.camera.js +41 -0
  73. package/www/windows/diagnostic.js +169 -0
  74. package/www/windows/diagnostic.location.js +35 -0
  75. package/www/windows/diagnostic.wifi.js +51 -0
@@ -0,0 +1,1309 @@
1
+ /**
2
+ * Diagnostic plugin for Android
3
+ *
4
+ * Copyright (c) 2015 Working Edge Ltd.
5
+ * Copyright (c) 2012 AVANTIC ESTUDIO DE INGENIEROS
6
+ **/
7
+ var Diagnostic = (function(){
8
+
9
+ /***********************
10
+ *
11
+ * Internal properties
12
+ *
13
+ *********************/
14
+ var Diagnostic = {};
15
+
16
+ // Indicates if a runtime permissions request is in progress
17
+ var requestInProgress = false;
18
+
19
+ /********************
20
+ *
21
+ * Public properties
22
+ *
23
+ ********************/
24
+
25
+ /**
26
+ * "Dangerous" permissions that need to be requested at run-time (Android 6.0/API 23 and above)
27
+ * See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
28
+ * @type {Object}
29
+ */
30
+ Diagnostic.runtimePermission = // deprecated
31
+ Diagnostic.permission = {
32
+ "READ_CALENDAR": "READ_CALENDAR",
33
+ "WRITE_CALENDAR": "WRITE_CALENDAR",
34
+ "CAMERA": "CAMERA",
35
+ "READ_CONTACTS": "READ_CONTACTS",
36
+ "WRITE_CONTACTS": "WRITE_CONTACTS",
37
+ "GET_ACCOUNTS": "GET_ACCOUNTS",
38
+ "ACCESS_FINE_LOCATION": "ACCESS_FINE_LOCATION",
39
+ "ACCESS_COARSE_LOCATION": "ACCESS_COARSE_LOCATION",
40
+ "ACCESS_BACKGROUND_LOCATION": "ACCESS_BACKGROUND_LOCATION",
41
+ "RECORD_AUDIO": "RECORD_AUDIO",
42
+ "READ_PHONE_STATE": "READ_PHONE_STATE",
43
+ "CALL_PHONE": "CALL_PHONE",
44
+ "ADD_VOICEMAIL": "ADD_VOICEMAIL",
45
+ "USE_SIP": "USE_SIP",
46
+ "PROCESS_OUTGOING_CALLS": "PROCESS_OUTGOING_CALLS",
47
+ "READ_CALL_LOG": "READ_CALL_LOG",
48
+ "WRITE_CALL_LOG": "WRITE_CALL_LOG",
49
+ "SEND_SMS": "SEND_SMS",
50
+ "RECEIVE_SMS": "RECEIVE_SMS",
51
+ "READ_SMS": "READ_SMS",
52
+ "RECEIVE_WAP_PUSH": "RECEIVE_WAP_PUSH",
53
+ "RECEIVE_MMS": "RECEIVE_MMS",
54
+ "WRITE_EXTERNAL_STORAGE": "WRITE_EXTERNAL_STORAGE",
55
+ "READ_EXTERNAL_STORAGE": "READ_EXTERNAL_STORAGE",
56
+ "BODY_SENSORS": "BODY_SENSORS",
57
+ "ACTIVITY_RECOGNITION": "ACTIVITY_RECOGNITION"
58
+ };
59
+
60
+ /**
61
+ * Permission groups indicate which associated permissions will also be requested if a given permission is requested.
62
+ * See http://developer.android.com/guide/topics/security/permissions.html#perm-groups
63
+ * @type {Object}
64
+ */
65
+ Diagnostic.runtimePermissionGroups = // deprecated
66
+ Diagnostic.permissionGroups = {
67
+ "CALENDAR": ["READ_CALENDAR", "WRITE_CALENDAR"],
68
+ "CAMERA": ["CAMERA"],
69
+ "CONTACTS": ["READ_CONTACTS", "WRITE_CONTACTS", "GET_ACCOUNTS"],
70
+ "LOCATION": ["ACCESS_FINE_LOCATION", "ACCESS_COARSE_LOCATION", "ACCESS_BACKGROUND_LOCATION"],
71
+ "MICROPHONE": ["RECORD_AUDIO"],
72
+ "PHONE": ["READ_PHONE_STATE", "CALL_PHONE", "ADD_VOICEMAIL", "USE_SIP", "PROCESS_OUTGOING_CALLS", "READ_CALL_LOG", "WRITE_CALL_LOG"],
73
+ "SENSORS": ["BODY_SENSORS"],
74
+ "SMS": ["SEND_SMS", "RECEIVE_SMS", "READ_SMS", "RECEIVE_WAP_PUSH", "RECEIVE_MMS"],
75
+ "STORAGE": ["READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"],
76
+ "PHYSICAL_ACTIVITY": ["ACTIVITY_RECOGNITION"]
77
+ };
78
+
79
+ Diagnostic.runtimePermissionStatus = // deprecated
80
+ Diagnostic.permissionStatus = {
81
+ // Location permission requested and
82
+ // app build SDK/user device is Android >10 and user granted background location ("all the time") permission,
83
+ // or app build SDK/user device is Android 6-9 and user granted location permission,
84
+ // or non-location permission requested
85
+ // and app build SDK/user device is Android >=6 and user granted permission
86
+ // or app build SDK/user device is Android <6
87
+ "GRANTED": "GRANTED",
88
+ // Location permission requested
89
+ // and app build SDK/user device is Android >10
90
+ // and user granted background foreground location ("while-in-use") permission
91
+ "GRANTED_WHEN_IN_USE": "authorized_when_in_use",
92
+ // User denied access to this permission
93
+ "DENIED_ONCE": "DENIED_ONCE",
94
+ // User denied access to this permission and checked "Never Ask Again" box.
95
+ "DENIED_ALWAYS": "DENIED_ALWAYS",
96
+ // App has not yet requested access to this permission.
97
+ "NOT_REQUESTED": "NOT_REQUESTED"
98
+ };
99
+
100
+ Diagnostic.cpuArchitecture = {
101
+ UNKNOWN: "unknown",
102
+ ARMv6: "ARMv6",
103
+ ARMv7: "ARMv7",
104
+ ARMv8: "ARMv8",
105
+ X86: "X86",
106
+ X86_64: "X86_64",
107
+ MIPS: "MIPS",
108
+ MIPS_64: "MIPS_64"
109
+ };
110
+
111
+ /*****************************
112
+ *
113
+ * Protected member functions
114
+ *
115
+ ****************************/
116
+ // Placeholder listeners
117
+ Diagnostic._onNFCStateChange =
118
+ Diagnostic._onPermissionRequestComplete = function(){};
119
+
120
+ /********************
121
+ *
122
+ * Internal functions
123
+ *
124
+ ********************/
125
+
126
+ function checkForInvalidPermissions(permissions, errorCallback){
127
+ if(typeof(permissions) !== "object") permissions = [permissions];
128
+ var valid = true, invalidPermissions = [];
129
+ permissions.forEach(function(permission){
130
+ if(!Diagnostic.permission[permission]){
131
+ invalidPermissions.push(permission);
132
+ }
133
+ });
134
+ if(invalidPermissions.length > 0){
135
+ errorCallback("Invalid permissions specified: "+invalidPermissions.join(", "));
136
+ valid = false;
137
+ }
138
+ return valid;
139
+ }
140
+
141
+
142
+
143
+ /*****************************
144
+ *
145
+ * Protected member functions
146
+ *
147
+ ****************************/
148
+
149
+ Diagnostic._ensureBoolean = function (callback){
150
+ return function(result){
151
+ callback(!!result);
152
+ }
153
+ };
154
+
155
+ /**********************
156
+ *
157
+ * Public API functions
158
+ *
159
+ **********************/
160
+
161
+
162
+ /***********
163
+ * General
164
+ ***********/
165
+
166
+ /**
167
+ * Enables debug mode, which logs native debug messages to the native and JS consoles.
168
+ * Debug mode is initially disabled on plugin initialisation.
169
+ *
170
+ * @param {Function} successCallback - The callback which will be called when enabling debug is successful.
171
+ */
172
+ Diagnostic.enableDebug = function(successCallback) {
173
+ return cordova.exec(successCallback,
174
+ null,
175
+ 'Diagnostic',
176
+ 'enableDebug',
177
+ []);
178
+ };
179
+
180
+ /**
181
+ * Opens settings page for this app.
182
+ *
183
+ * @param {Function} successCallback - The callback which will be called when switch to settings is successful.
184
+ * @param {Function} errorCallback - The callback which will be called when switch to settings encounters an error.
185
+ * This callback function is passed a single string parameter containing the error message.
186
+ */
187
+ Diagnostic.switchToSettings = function(successCallback, errorCallback) {
188
+ return cordova.exec(successCallback,
189
+ errorCallback,
190
+ 'Diagnostic',
191
+ 'switchToSettings',
192
+ []);
193
+ };
194
+
195
+ /**
196
+ * Returns the current authorisation status for a given permission.
197
+ * 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.
198
+ *
199
+ * @param {Function} successCallback - function to call on successful retrieval of status.
200
+ * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
201
+ * @param {Function} errorCallback - function to call on failure to retrieve authorisation status.
202
+ * This callback function is passed a single string parameter containing the error message.
203
+ * @param {String} permission - permission to request authorisation status for, defined as a value in cordova.plugins.diagnostic.permission
204
+ */
205
+ Diagnostic.getPermissionAuthorizationStatus = function(successCallback, errorCallback, permission){
206
+ if(!checkForInvalidPermissions(permission, errorCallback)) return;
207
+
208
+ return cordova.exec(
209
+ successCallback,
210
+ errorCallback,
211
+ 'Diagnostic',
212
+ 'getPermissionAuthorizationStatus',
213
+ [permission]);
214
+ };
215
+
216
+ /**
217
+ * Returns the current authorisation status for multiple permissions.
218
+ * 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.
219
+ *
220
+ * @param {Function} successCallback - function to call on successful retrieval of status.
221
+ * This callback function is passed a single object parameter which defines a key/value map, where the key is the requested permission defined as a value in cordova.plugins.diagnostic.permission, and the value is the current authorisation status of that permission as a value in cordova.plugins.diagnostic.permissionStatus.
222
+ * @param {Function} errorCallback - function to call on failure to retrieve authorisation statuses.
223
+ * This callback function is passed a single string parameter containing the error message.
224
+ * @param {Array} permissions - list of permissions to request authorisation statuses for, defined as values in cordova.plugins.diagnostic.permission
225
+ */
226
+ Diagnostic.getPermissionsAuthorizationStatus = function(successCallback, errorCallback, permissions){
227
+ if(!checkForInvalidPermissions(permissions, errorCallback)) return;
228
+
229
+ return cordova.exec(
230
+ successCallback,
231
+ errorCallback,
232
+ 'Diagnostic',
233
+ 'getPermissionsAuthorizationStatus',
234
+ [permissions]);
235
+ };
236
+
237
+
238
+ /**
239
+ * Requests app to be granted authorisation for a runtime permission.
240
+ * 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.
241
+ *
242
+ * @param {Function} successCallback - function to call on successful request for runtime permission.
243
+ * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
244
+ * @param {Function} errorCallback - function to call on failure to request authorisation.
245
+ * This callback function is passed a single string parameter containing the error message.
246
+ * @param {String} permission - permission to request authorisation for, defined as a value in cordova.plugins.diagnostic.permission
247
+ */
248
+ Diagnostic.requestRuntimePermission = function(successCallback, errorCallback, permission) {
249
+ if(!checkForInvalidPermissions(permission, errorCallback)) return;
250
+
251
+ if(requestInProgress){
252
+ return onError("A runtime permissions request is already in progress");
253
+ }
254
+
255
+ function onSuccess(statuses){
256
+ requestInProgress = false;
257
+ successCallback(statuses[permission]);
258
+ Diagnostic._onPermissionRequestComplete(statuses);
259
+ }
260
+
261
+ function onError(error){
262
+ requestInProgress = false;
263
+ errorCallback(error);
264
+ }
265
+
266
+ requestInProgress = true;
267
+ return cordova.exec(
268
+ onSuccess,
269
+ onError,
270
+ 'Diagnostic',
271
+ 'requestRuntimePermission',
272
+ [permission]);
273
+ };
274
+
275
+ /**
276
+ * Requests app to be granted authorisation for multiple runtime permissions.
277
+ * 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.
278
+ *
279
+ * @param {Function} successCallback - function to call on successful request for runtime permissions.
280
+ * This callback function is passed a single object parameter which defines a key/value map, where the key is the permission to request defined as a value in cordova.plugins.diagnostic.permission, and the value is the resulting authorisation status of that permission as a value in cordova.plugins.diagnostic.permissionStatus.
281
+ * @param {Function} errorCallback - function to call on failure to request authorisation.
282
+ * This callback function is passed a single string parameter containing the error message.
283
+ * @param {Array} permissions - permissions to request authorisation for, defined as values in cordova.plugins.diagnostic.permission
284
+ */
285
+ Diagnostic.requestRuntimePermissions = function(successCallback, errorCallback, permissions){
286
+ if(!checkForInvalidPermissions(permissions, errorCallback)) return;
287
+
288
+ if(requestInProgress){
289
+ return onError("A runtime permissions request is already in progress");
290
+ }
291
+
292
+ function onSuccess(statuses){
293
+ requestInProgress = false;
294
+ successCallback(statuses);
295
+ Diagnostic._onPermissionRequestComplete(statuses);
296
+ }
297
+
298
+ function onError(error){
299
+ requestInProgress = false;
300
+ errorCallback(error);
301
+ }
302
+
303
+ requestInProgress = true;
304
+ return cordova.exec(
305
+ onSuccess,
306
+ onError,
307
+ 'Diagnostic',
308
+ 'requestRuntimePermissions',
309
+ [permissions]);
310
+
311
+ };
312
+
313
+ /**
314
+ * Indicates if the plugin is currently requesting a runtime permission via the native API.
315
+ * Note that only one request can be made concurrently because the native API cannot handle concurrent requests,
316
+ * so the plugin will invoke the error callback if attempting to make more than one simultaneous request.
317
+ * Multiple permission requests should be grouped into a single call since the native API is setup to handle batch requests of multiple permission groups.
318
+ *
319
+ * @return {boolean} true if a permission request is currently in progress.
320
+ */
321
+ Diagnostic.isRequestingPermission = function(){
322
+ return requestInProgress;
323
+ };
324
+
325
+ /**
326
+ * Registers a function to be called when a runtime permission request has completed.
327
+ * Pass in a falsey value to de-register the currently registered function.
328
+ *
329
+ * @param {Function} successCallback - The callback which will be called when a runtime permission request has completed.
330
+ * This callback function is passed a single object parameter which defines a key/value map, where the key is the permission requested (defined as a value in cordova.plugins.diagnostic.permission) and the value is the resulting authorisation status of that permission as a value in cordova.plugins.diagnostic.permissionStatus.
331
+ */
332
+ Diagnostic.registerPermissionRequestCompleteHandler = function(successCallback) {
333
+ Diagnostic._onPermissionRequestComplete = successCallback || function(){};
334
+ };
335
+
336
+
337
+ /**
338
+ * Switches to the wireless settings page in the Settings app.
339
+ * Allows configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks.
340
+ */
341
+ Diagnostic.switchToWirelessSettings = function() {
342
+ return cordova.exec(null,
343
+ null,
344
+ 'Diagnostic',
345
+ 'switchToWirelessSettings',
346
+ []);
347
+ };
348
+
349
+
350
+ /**
351
+ * Switches to the Mobile Data page in the Settings app
352
+ */
353
+ Diagnostic.switchToMobileDataSettings = function() {
354
+ return cordova.exec(null,
355
+ null,
356
+ 'Diagnostic',
357
+ 'switchToMobileDataSettings',
358
+ []);
359
+ };
360
+
361
+ /**
362
+ * Checks if ADB mode(debug mode) is switched on.
363
+ * Returns true if ADB mode is switched on.
364
+ *
365
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
366
+ * This callback function is passed a single boolean parameter which is TRUE if ADB mode(debug mode) is switched on.
367
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
368
+ * This callback function is passed a single string parameter containing the error message.
369
+ */
370
+ Diagnostic.isADBModeEnabled = function(successCallback, errorCallback) {
371
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
372
+ errorCallback,
373
+ 'Diagnostic',
374
+ 'isADBModeEnabled',
375
+ []);
376
+ };
377
+
378
+ /**
379
+ * Checks if the device is rooted.
380
+ * Returns true if the device is rooted.
381
+ *
382
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
383
+ * This callback function is passed a single boolean parameter which is TRUE if the device is rooted.
384
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
385
+ * This callback function is passed a single string parameter containing the error message.
386
+ */
387
+ Diagnostic.isDeviceRooted = function(successCallback, errorCallback) {
388
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
389
+ errorCallback,
390
+ 'Diagnostic',
391
+ 'isDeviceRooted',
392
+ []);
393
+ };
394
+
395
+ /**
396
+ * Restarts the application.
397
+ * By default, a "warm" restart will be performed in which the main Cordova activity is immediately restarted, causing the Webview instance to be recreated.
398
+ * However, if the `cold` parameter is set to true, then the application will be "cold" restarted, meaning a system exit will be performed, causing the entire application to be restarted.
399
+ * This is useful if you want to fully reset the native application state but will cause the application to briefly disappear and re-appear.
400
+ *
401
+ * Note: There is no successCallback() since if the operation is successful, the application will restart immediately before any success callback can be applied.
402
+ *
403
+ * @param {Function} errorCallback - function to call on failure to retrieve authorisation status.
404
+ * This callback function is passed a single string parameter containing the error message.
405
+ * @param {Boolean} cold - if true the application will be cold restarted. Defaults to false.
406
+ */
407
+ Diagnostic.restart = function(errorCallback, cold){
408
+ return cordova.exec(
409
+ null,
410
+ errorCallback,
411
+ 'Diagnostic',
412
+ 'restart',
413
+ [cold]);
414
+ };
415
+
416
+ /**
417
+ * Returns CPU architecture of the current device.
418
+ *
419
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
420
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.cpuArchitecture`.
421
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
422
+ * This callback function is passed a single string parameter containing the error message.
423
+ */
424
+ Diagnostic.getArchitecture = function(successCallback, errorCallback) {
425
+ return cordova.exec(successCallback,
426
+ errorCallback,
427
+ 'Diagnostic',
428
+ 'getArchitecture',
429
+ []);
430
+ };
431
+
432
+ /**
433
+ * Checks if the device data roaming setting is enabled.
434
+ * Returns true if data roaming is enabled.
435
+ *
436
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
437
+ * This callback function is passed a single boolean parameter which is TRUE if data roaming is enabled.
438
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
439
+ * This callback function is passed a single string parameter containing the error message.
440
+ */
441
+ Diagnostic.isDataRoamingEnabled = function(successCallback, errorCallback) {
442
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
443
+ errorCallback,
444
+ 'Diagnostic',
445
+ 'isDataRoamingEnabled',
446
+ []);
447
+ };
448
+
449
+ /************
450
+ * Location *
451
+ ************/
452
+
453
+ /**
454
+ * Checks if location is available for use by the app.
455
+ * On Android, this returns true if Location Mode is enabled and any mode is selected (e.g. Battery saving, Device only, High accuracy)
456
+ * AND if the app is authorised to use location.
457
+ *
458
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
459
+ * This callback function is passed a single boolean parameter which is TRUE if location is available for use.
460
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
461
+ * This callback function is passed a single string parameter containing the error message.
462
+ */
463
+ Diagnostic.isLocationAvailable = function(successCallback, errorCallback) {
464
+ if(cordova.plugins.diagnostic.location){
465
+ cordova.plugins.diagnostic.location.isLocationAvailable.apply(this, arguments);
466
+ }else{
467
+ throw "Diagnostic Location module is not installed";
468
+ }
469
+ };
470
+
471
+ /**
472
+ * Checks if the device location setting is enabled.
473
+ * On Android, this returns true if Location Mode is enabled and any mode is selected (e.g. Battery saving, Device only, High accuracy)
474
+ *
475
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
476
+ * This callback function is passed a single boolean parameter which is TRUE if location setting is enabled.
477
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
478
+ * This callback function is passed a single string parameter containing the error message.
479
+ */
480
+ Diagnostic.isLocationEnabled = function(successCallback, errorCallback) {
481
+ if(cordova.plugins.diagnostic.location){
482
+ cordova.plugins.diagnostic.location.isLocationEnabled.apply(this, arguments);
483
+ }else{
484
+ throw "Diagnostic Location module is not installed";
485
+ }
486
+ };
487
+
488
+ /**
489
+ * Checks if high-accuracy locations are available to the app from GPS hardware.
490
+ * Returns true if Location mode is enabled and is set to "Device only" or "High accuracy"
491
+ * AND if the app is authorised to use location.
492
+ *
493
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
494
+ * This callback function is passed a single boolean parameter which is TRUE if high-accuracy GPS-based location is available.
495
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
496
+ * This callback function is passed a single string parameter containing the error message.
497
+ */
498
+ Diagnostic.isGpsLocationAvailable = function(successCallback, errorCallback) {
499
+ if(cordova.plugins.diagnostic.location){
500
+ cordova.plugins.diagnostic.location.isGpsLocationAvailable.apply(this, arguments);
501
+ }else{
502
+ throw "Diagnostic Location module is not installed";
503
+ }
504
+ };
505
+
506
+ /**
507
+ * Checks if the device location setting is set to return high-accuracy locations from GPS hardware.
508
+ * Returns true if Location mode is enabled and is set to either:
509
+ * Device only = GPS hardware only (high accuracy)
510
+ * High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
511
+ *
512
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
513
+ * This callback function is passed a single boolean parameter which is TRUE if device setting is set to return high-accuracy GPS-based location.
514
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
515
+ * This callback function is passed a single string parameter containing the error message.
516
+ */
517
+ Diagnostic.isGpsLocationEnabled = function(successCallback, errorCallback) {
518
+ if(cordova.plugins.diagnostic.location){
519
+ cordova.plugins.diagnostic.location.isGpsLocationEnabled.apply(this, arguments);
520
+ }else{
521
+ throw "Diagnostic Location module is not installed";
522
+ }
523
+ };
524
+
525
+ /**
526
+ * Checks if low-accuracy locations are available to the app from network triangulation/WiFi access points.
527
+ * Returns true if Location mode is enabled and is set to "Battery saving" or "High accuracy"
528
+ * AND if the app is authorised to use location.
529
+ *
530
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
531
+ * This callback function is passed a single boolean parameter which is TRUE if low-accuracy network-based location is available.
532
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
533
+ * This callback function is passed a single string parameter containing the error message.
534
+ */
535
+ Diagnostic.isNetworkLocationAvailable = function(successCallback, errorCallback) {
536
+ if(cordova.plugins.diagnostic.location){
537
+ cordova.plugins.diagnostic.location.isNetworkLocationAvailable.apply(this, arguments);
538
+ }else{
539
+ throw "Diagnostic Location module is not installed";
540
+ }
541
+ };
542
+
543
+ /**
544
+ * Checks if the device location setting is set to return low-accuracy locations from network triangulation/WiFi access points.
545
+ * Returns true if Location mode is enabled and is set to either:
546
+ * Battery saving = network triangulation and Wifi network IDs (low accuracy)
547
+ * High accuracy = GPS hardware, network triangulation and Wifi network IDs (high and low accuracy)
548
+ *
549
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
550
+ * This callback function is passed a single boolean parameter which is TRUE if device setting is set to return low-accuracy network-based location.
551
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
552
+ * This callback function is passed a single string parameter containing the error message.
553
+ */
554
+ Diagnostic.isNetworkLocationEnabled = function(successCallback, errorCallback) {
555
+ if(cordova.plugins.diagnostic.location){
556
+ cordova.plugins.diagnostic.location.isNetworkLocationEnabled.apply(this, arguments);
557
+ }else{
558
+ throw "Diagnostic Location module is not installed";
559
+ }
560
+ };
561
+
562
+ /**
563
+ * Returns the current location mode setting for the device.
564
+ *
565
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
566
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.locationMode`.
567
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
568
+ * This callback function is passed a single string parameter containing the error message.
569
+ */
570
+ Diagnostic.getLocationMode = function(successCallback, errorCallback) {
571
+ if(cordova.plugins.diagnostic.location){
572
+ cordova.plugins.diagnostic.location.getLocationMode.apply(this, arguments);
573
+ }else{
574
+ throw "Diagnostic Location module is not installed";
575
+ }
576
+ };
577
+
578
+ /**
579
+ * Switches to the Location page in the Settings app
580
+ */
581
+ Diagnostic.switchToLocationSettings = function() {
582
+ if(cordova.plugins.diagnostic.location){
583
+ cordova.plugins.diagnostic.location.switchToLocationSettings.apply(this, arguments);
584
+ }else{
585
+ throw "Diagnostic Location module is not installed";
586
+ }
587
+ };
588
+
589
+ /**
590
+ * Requests location authorization for the application.
591
+ * 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.
592
+ * @param {Function} successCallback - function to call on successful request for runtime permissions.
593
+ * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
594
+ * @param {Function} errorCallback - function to call on failure to request authorisation.
595
+ */
596
+ Diagnostic.requestLocationAuthorization = function(successCallback, errorCallback){
597
+ if(cordova.plugins.diagnostic.location){
598
+ cordova.plugins.diagnostic.location.requestLocationAuthorization.apply(this, arguments);
599
+ }else{
600
+ throw "Diagnostic Location module is not installed";
601
+ }
602
+ };
603
+
604
+ /**
605
+ * Returns the location authorization status for the application.
606
+ * 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.
607
+ * @param {Function} successCallback - function to call on successful request for runtime permissions status.
608
+ * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
609
+ * @param {Function} errorCallback - function to call on failure to request authorisation status.
610
+ */
611
+ Diagnostic.getLocationAuthorizationStatus = function(successCallback, errorCallback){
612
+ if(cordova.plugins.diagnostic.location){
613
+ cordova.plugins.diagnostic.location.getLocationAuthorizationStatus.apply(this, arguments);
614
+ }else{
615
+ throw "Diagnostic Location module is not installed";
616
+ }
617
+ };
618
+
619
+ /**
620
+ * Checks if the application is authorized to use location.
621
+ * Note: 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.
622
+ * @param {Function} successCallback - function to call on successful request for runtime permissions status.
623
+ * This callback function is passed a single boolean parameter which is TRUE if the app currently has runtime authorisation to use location.
624
+ * @param {Function} errorCallback - function to call on failure to request authorisation status.
625
+ */
626
+ Diagnostic.isLocationAuthorized = function(successCallback, errorCallback){
627
+ if(cordova.plugins.diagnostic.location){
628
+ cordova.plugins.diagnostic.location.isLocationAuthorized.apply(this, arguments);
629
+ }else{
630
+ throw "Diagnostic Location module is not installed";
631
+ }
632
+ };
633
+
634
+ /**
635
+ * Registers a function to be called when a change in Location state occurs.
636
+ * On Android, this occurs when the Location Mode is changed.
637
+ * Pass in a falsey value to de-register the currently registered function.
638
+ *
639
+ * @param {Function} successCallback - The callback which will be called when the Location state changes.
640
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.locationMode`.
641
+ */
642
+ Diagnostic.registerLocationStateChangeHandler = function(successCallback) {
643
+ if(cordova.plugins.diagnostic.location){
644
+ cordova.plugins.diagnostic.location.registerLocationStateChangeHandler.apply(this, arguments);
645
+ }else{
646
+ throw "Diagnostic Location module is not installed";
647
+ }
648
+ };
649
+
650
+ /************
651
+ * WiFi *
652
+ ************/
653
+
654
+ /**
655
+ * Checks if Wifi is enabled.
656
+ * On Android this returns true if the WiFi setting is set to enabled.
657
+ *
658
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
659
+ * This callback function is passed a single boolean parameter which is TRUE if WiFi is enabled.
660
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
661
+ * This callback function is passed a single string parameter containing the error message.
662
+ */
663
+ Diagnostic.isWifiAvailable = Diagnostic.isWifiEnabled = function(successCallback, errorCallback) {
664
+ if(cordova.plugins.diagnostic.wifi){
665
+ cordova.plugins.diagnostic.wifi.isWifiAvailable.apply(this, arguments);
666
+ }else{
667
+ throw "Diagnostic Wifi module is not installed";
668
+ }
669
+ };
670
+
671
+ /**
672
+ * Switches to the WiFi page in the Settings app
673
+ */
674
+ Diagnostic.switchToWifiSettings = function() {
675
+ if(cordova.plugins.diagnostic.wifi){
676
+ cordova.plugins.diagnostic.wifi.switchToWifiSettings.apply(this, arguments);
677
+ }else{
678
+ throw "Diagnostic Wifi module is not installed";
679
+ }
680
+ };
681
+
682
+ /**
683
+ * Enables/disables WiFi on the device.
684
+ *
685
+ * @param {Function} successCallback - function to call on successful setting of WiFi state
686
+ * @param {Function} errorCallback - function to call on failure to set WiFi state.
687
+ * This callback function is passed a single string parameter containing the error message.
688
+ * @param {Boolean} state - WiFi state to set: TRUE for enabled, FALSE for disabled.
689
+ */
690
+ Diagnostic.setWifiState = function(successCallback, errorCallback, state) {
691
+ if(cordova.plugins.diagnostic.wifi){
692
+ cordova.plugins.diagnostic.wifi.setWifiState.apply(this, arguments);
693
+ }else{
694
+ throw "Diagnostic Wifi module is not installed";
695
+ }
696
+ };
697
+
698
+ /************
699
+ * Camera *
700
+ ************/
701
+
702
+ /**
703
+ * Checks if camera is usable: both present and authorised for use.
704
+ *
705
+ * @param {Object} params - (optional) parameters:
706
+ * - {Function} successCallback - The callback which will be called when the operation is successful.
707
+ * This callback function is passed a single boolean parameter which is TRUE if camera is present and authorized for use.
708
+ * - {Function} errorCallback - The callback which will be called when the operation encounters an error.
709
+ * This callback function is passed a single string parameter containing the error message.
710
+ * - {Boolean} externalStorage - (Android only) If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
711
+ * cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
712
+ */
713
+ Diagnostic.isCameraAvailable = function(params) {
714
+ if(cordova.plugins.diagnostic.camera){
715
+ cordova.plugins.diagnostic.camera.isCameraAvailable.apply(this, arguments);
716
+ }else{
717
+ throw "Diagnostic Camera module is not installed";
718
+ }
719
+ };
720
+
721
+ /**
722
+ * Checks if camera hardware is present on device.
723
+ *
724
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
725
+ * This callback function is passed a single boolean parameter which is TRUE if camera is present
726
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
727
+ * This callback function is passed a single string parameter containing the error message.
728
+ */
729
+ Diagnostic.isCameraPresent = function(successCallback, errorCallback) {
730
+ if(cordova.plugins.diagnostic.camera){
731
+ cordova.plugins.diagnostic.camera.isCameraPresent.apply(this, arguments);
732
+ }else{
733
+ throw "Diagnostic Camera module is not installed";
734
+ }
735
+ };
736
+
737
+ /**
738
+ * Requests authorisation for runtime permissions to use the camera.
739
+ * 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.
740
+ * @param {Object} params - (optional) parameters:
741
+ * - {Function} successCallback - function to call on successful request for runtime permissions.
742
+ * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
743
+ * - {Function} errorCallback - function to call on failure to request authorisation.
744
+ * - {Boolean} externalStorage - (Android only) If true, requests permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
745
+ * cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
746
+ */
747
+ Diagnostic.requestCameraAuthorization = function(params){
748
+ if(cordova.plugins.diagnostic.camera){
749
+ cordova.plugins.diagnostic.camera.requestCameraAuthorization.apply(this, arguments);
750
+ }else{
751
+ throw "Diagnostic Camera module is not installed";
752
+ }
753
+ };
754
+
755
+ /**
756
+ * Returns the authorisation status for runtime permissions to use the camera.
757
+ * 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.
758
+ * @param {Object} params - (optional) parameters:
759
+ * - {Function} successCallback - function to call on successful request for runtime permissions status.
760
+ * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
761
+ * - {Function} errorCallback - function to call on failure to request authorisation status.
762
+ * - {Boolean} externalStorage - (Android only) If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
763
+ * cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
764
+ */
765
+ Diagnostic.getCameraAuthorizationStatus = function(params){
766
+ if(cordova.plugins.diagnostic.camera){
767
+ cordova.plugins.diagnostic.camera.getCameraAuthorizationStatus.apply(this, arguments);
768
+ }else{
769
+ throw "Diagnostic Camera module is not installed";
770
+ }
771
+ };
772
+
773
+ /**
774
+ * Checks if the application is authorized to use the camera.
775
+ * Note: 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.
776
+ * @param {Object} params - (optional) parameters:
777
+ * - {Function} successCallback - function to call on successful request for runtime permissions status.
778
+ * This callback function is passed a single boolean parameter which is TRUE if the app currently has runtime authorisation to use location.
779
+ * - {Function} errorCallback - function to call on failure to request authorisation status.
780
+ * - {Boolean} externalStorage - (Android only) If true, checks permission for READ_EXTERNAL_STORAGE in addition to CAMERA run-time permission.
781
+ * cordova-plugin-camera@2.2+ requires both of these permissions. Defaults to true.
782
+ */
783
+ Diagnostic.isCameraAuthorized = function(params){
784
+ if(cordova.plugins.diagnostic.camera){
785
+ cordova.plugins.diagnostic.camera.isCameraAuthorized.apply(this, arguments);
786
+ }else{
787
+ throw "Diagnostic Camera module is not installed";
788
+ }
789
+ };
790
+
791
+ /**********************
792
+ * External storage *
793
+ **********************/
794
+ /**
795
+ * Requests authorisation for runtime permission to use the external storage.
796
+ * 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 permission is already granted at installation time.
797
+ * @param {Function} successCallback - function to call on successful request for runtime permission.
798
+ * This callback function is passed a single string parameter which defines the resulting authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
799
+ * @param {Function} errorCallback - function to call on failure to request authorisation.
800
+ */
801
+ Diagnostic.requestExternalStorageAuthorization = function(successCallback, errorCallback){
802
+ if(cordova.plugins.diagnostic.external_storage){
803
+ cordova.plugins.diagnostic.external_storage.requestExternalStorageAuthorization.apply(this, arguments);
804
+ }else{
805
+ throw "Diagnostic External Storage module is not installed";
806
+ }
807
+ };
808
+
809
+ /**
810
+ * Returns the authorisation status for runtime permission to use the external storage.
811
+ * 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 permission is already granted at installation time.
812
+ * @param {Function} successCallback - function to call on successful request for runtime permission status.
813
+ * This callback function is passed a single string parameter which defines the current authorisation status as a value in cordova.plugins.diagnostic.permissionStatus.
814
+ * @param {Function} errorCallback - function to call on failure to request authorisation status.
815
+ */
816
+ Diagnostic.getExternalStorageAuthorizationStatus = function(successCallback, errorCallback){
817
+ if(cordova.plugins.diagnostic.external_storage){
818
+ cordova.plugins.diagnostic.external_storage.getExternalStorageAuthorizationStatus.apply(this, arguments);
819
+ }else{
820
+ throw "Diagnostic External Storage module is not installed";
821
+ }
822
+ };
823
+
824
+ /**
825
+ * Checks if the application is authorized to use external storage.
826
+ * Note: 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.
827
+ * @param {Function} successCallback - function to call on successful request for runtime permissions status.
828
+ * This callback function is passed a single boolean parameter which is TRUE if the app currently has runtime authorisation to external storage.
829
+ * @param {Function} errorCallback - function to call on failure to request authorisation status.
830
+ */
831
+ Diagnostic.isExternalStorageAuthorized = function(successCallback, errorCallback){
832
+ if(cordova.plugins.diagnostic.external_storage){
833
+ cordova.plugins.diagnostic.external_storage.isExternalStorageAuthorized.apply(this, arguments);
834
+ }else{
835
+ throw "Diagnostic External Storage module is not installed";
836
+ }
837
+ };
838
+
839
+ /**
840
+ * Returns details of external SD card(s): absolute path, is writable, free space
841
+ * @param {Function} successCallback - function to call on successful request for external SD card details.
842
+ * This callback function is passed a single argument which is an array consisting of an entry for each external storage location found.
843
+ * Each array entry is an object with the following keys:
844
+ * - {String} path - absolute path to the storage location
845
+ * - {String} filePath - absolute path prefixed with file protocol for use with cordova-plugin-file
846
+ * - {Boolean} canWrite - true if the location is writable
847
+ * - {Integer} freeSpace - number of bytes of free space on the device on which the storage locaiton is mounted.
848
+ * - {String} type - indicates the type of storage location: either "application" if the path is an Android application sandbox path or "root" if the path is the device root.
849
+ * @param {Function} errorCallback - function to call on failure to request authorisation status.
850
+ */
851
+ Diagnostic.getExternalSdCardDetails = function(successCallback, errorCallback){
852
+ if(cordova.plugins.diagnostic.external_storage){
853
+ cordova.plugins.diagnostic.external_storage.getExternalSdCardDetails.apply(this, arguments);
854
+ }else{
855
+ throw "Diagnostic External Storage module is not installed";
856
+ }
857
+ };
858
+
859
+
860
+ /***************
861
+ * Bluetooth *
862
+ ***************/
863
+
864
+ /**
865
+ * Checks if Bluetooth is available to the app.
866
+ * Returns true if the device has Bluetooth capabilities and if so that Bluetooth is switched on
867
+ *
868
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
869
+ * This callback function is passed a single boolean parameter which is TRUE if Bluetooth is available.
870
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
871
+ * This callback function is passed a single string parameter containing the error message.
872
+ */
873
+ Diagnostic.isBluetoothAvailable = function(successCallback, errorCallback) {
874
+ if(cordova.plugins.diagnostic.bluetooth){
875
+ cordova.plugins.diagnostic.bluetooth.isBluetoothAvailable.apply(this, arguments);
876
+ }else{
877
+ throw "Diagnostic Bluetooth module is not installed";
878
+ }
879
+ };
880
+
881
+ /**
882
+ * Checks if the device setting for Bluetooth is switched on.
883
+ *
884
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
885
+ * This callback function is passed a single boolean parameter which is TRUE if Bluetooth is switched on.
886
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
887
+ * This callback function is passed a single string parameter containing the error message.
888
+ */
889
+ Diagnostic.isBluetoothEnabled = function(successCallback, errorCallback) {
890
+ if(cordova.plugins.diagnostic.bluetooth){
891
+ cordova.plugins.diagnostic.bluetooth.isBluetoothEnabled.apply(this, arguments);
892
+ }else{
893
+ throw "Diagnostic Bluetooth module is not installed";
894
+ }
895
+ };
896
+
897
+ /**
898
+ * Enables/disables Bluetooth on the device.
899
+ *
900
+ * @param {Function} successCallback - function to call on successful setting of Bluetooth state
901
+ * @param {Function} errorCallback - function to call on failure to set Bluetooth state.
902
+ * This callback function is passed a single string parameter containing the error message.
903
+ * @param {Boolean} state - Bluetooth state to set: TRUE for enabled, FALSE for disabled.
904
+ */
905
+ Diagnostic.setBluetoothState = function(successCallback, errorCallback, state) {
906
+ if(cordova.plugins.diagnostic.bluetooth){
907
+ cordova.plugins.diagnostic.bluetooth.setBluetoothState.apply(this, arguments);
908
+ }else{
909
+ throw "Diagnostic Bluetooth module is not installed";
910
+ }
911
+ };
912
+
913
+ /**
914
+ * Returns current state of Bluetooth hardware on the device.
915
+ *
916
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
917
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.bluetoothState`.
918
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
919
+ * This callback function is passed a single string parameter containing the error message.
920
+ */
921
+ Diagnostic.getBluetoothState = function(successCallback, errorCallback) {
922
+ if(cordova.plugins.diagnostic.bluetooth){
923
+ cordova.plugins.diagnostic.bluetooth.getBluetoothState.apply(this, arguments);
924
+ }else{
925
+ throw "Diagnostic Bluetooth module is not installed";
926
+ }
927
+ };
928
+
929
+ /**
930
+ * Registers a listener function to call when the state of Bluetooth hardware changes.
931
+ * Pass in a falsey value to de-register the currently registered function.
932
+ *
933
+ * @param {Function} successCallback - The callback which will be called when the state of Bluetooth hardware changes.
934
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.bluetoothState`.
935
+ */
936
+ Diagnostic.registerBluetoothStateChangeHandler = function(successCallback) {
937
+ if(cordova.plugins.diagnostic.bluetooth){
938
+ cordova.plugins.diagnostic.bluetooth.registerBluetoothStateChangeHandler.apply(this, arguments);
939
+ }else{
940
+ throw "Diagnostic Bluetooth module is not installed";
941
+ }
942
+ };
943
+
944
+
945
+ /**
946
+ * Checks if the device has Bluetooth capabilities.
947
+ * See http://developer.android.com/guide/topics/connectivity/bluetooth.html.
948
+ *
949
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
950
+ * This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth capabilities.
951
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
952
+ * This callback function is passed a single string parameter containing the error message.
953
+ */
954
+ Diagnostic.hasBluetoothSupport = function(successCallback, errorCallback) {
955
+ if(cordova.plugins.diagnostic.bluetooth){
956
+ cordova.plugins.diagnostic.bluetooth.hasBluetoothSupport.apply(this, arguments);
957
+ }else{
958
+ throw "Diagnostic Bluetooth module is not installed";
959
+ }
960
+ };
961
+
962
+ /**
963
+ * Checks if the device has Bluetooth Low Energy (LE) capabilities.
964
+ * See http://developer.android.com/guide/topics/connectivity/bluetooth-le.html.
965
+ *
966
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
967
+ * This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth LE capabilities.
968
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
969
+ * This callback function is passed a single string parameter containing the error message.
970
+ */
971
+ Diagnostic.hasBluetoothLESupport = function(successCallback, errorCallback) {
972
+ if(cordova.plugins.diagnostic.bluetooth){
973
+ cordova.plugins.diagnostic.bluetooth.hasBluetoothLESupport.apply(this, arguments);
974
+ }else{
975
+ throw "Diagnostic Bluetooth module is not installed";
976
+ }
977
+ };
978
+
979
+ /**
980
+ * Checks if the device has Bluetooth Low Energy (LE) capabilities.
981
+ * See http://developer.android.com/guide/topics/connectivity/bluetooth-le.html.
982
+ *
983
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
984
+ * This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth LE capabilities.
985
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
986
+ * This callback function is passed a single string parameter containing the error message.
987
+ */
988
+ Diagnostic.hasBluetoothLESupport = function(successCallback, errorCallback) {
989
+ if(cordova.plugins.diagnostic.bluetooth){
990
+ cordova.plugins.diagnostic.bluetooth.hasBluetoothLESupport.apply(this, arguments);
991
+ }else{
992
+ throw "Diagnostic Bluetooth module is not installed";
993
+ }
994
+ };
995
+
996
+ /**
997
+ * Checks if the device has Bluetooth Low Energy (LE) peripheral capabilities.
998
+ * See http://developer.android.com/guide/topics/connectivity/bluetooth-le.html#roles.
999
+ *
1000
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1001
+ * This callback function is passed a single boolean parameter which is TRUE if device has Bluetooth LE peripheral capabilities.
1002
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1003
+ * This callback function is passed a single string parameter containing the error message.
1004
+ */
1005
+ Diagnostic.hasBluetoothLEPeripheralSupport = function(successCallback, errorCallback) {
1006
+ if(cordova.plugins.diagnostic.bluetooth){
1007
+ cordova.plugins.diagnostic.bluetooth.hasBluetoothLEPeripheralSupport.apply(this, arguments);
1008
+ }else{
1009
+ throw "Diagnostic Bluetooth module is not installed";
1010
+ }
1011
+ };
1012
+
1013
+ /**
1014
+ * Switches to the Bluetooth page in the Settings app
1015
+ */
1016
+ Diagnostic.switchToBluetoothSettings = function() {
1017
+ if(cordova.plugins.diagnostic.bluetooth){
1018
+ cordova.plugins.diagnostic.bluetooth.switchToBluetoothSettings.apply(this, arguments);
1019
+ }else{
1020
+ throw "Diagnostic Bluetooth module is not installed";
1021
+ }
1022
+ };
1023
+
1024
+ /**********************
1025
+ * Remote Notifications
1026
+ **********************/
1027
+
1028
+ /**
1029
+ * Checks if remote notifications is available to the app.
1030
+ * Returns true if remote notifications are switched on.
1031
+ *
1032
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1033
+ * This callback function is passed a single boolean parameter which is TRUE if remote notifications is available.
1034
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1035
+ * This callback function is passed a single string parameter containing the error message.
1036
+ */
1037
+ Diagnostic.isRemoteNotificationsEnabled = function(successCallback, errorCallback) {
1038
+ if(cordova.plugins.diagnostic.notifications){
1039
+ cordova.plugins.diagnostic.notifications.isRemoteNotificationsEnabled.apply(this, arguments);
1040
+ }else{
1041
+ throw "Diagnostic Notifications module is not installed";
1042
+ }
1043
+ };
1044
+
1045
+ /**
1046
+ * Switches to the notification settings page in the Settings app
1047
+ */
1048
+ Diagnostic.switchToNotificationSettings = function() {
1049
+ if (cordova.plugins.diagnostic.notifications){
1050
+ cordova.plugins.diagnostic.notifications.switchToNotificationSettings.apply(this, arguments);
1051
+ } else {
1052
+ throw "Diagnostic notification module is not installed";
1053
+ }
1054
+ };
1055
+
1056
+
1057
+ /***************************
1058
+ * Microphone / Record Audio
1059
+ ***************************/
1060
+
1061
+ /**
1062
+ * Checks if the application is authorized to use the microphone for recording audio.
1063
+ *
1064
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1065
+ * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized.
1066
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1067
+ * This callback function is passed a single string parameter containing the error message.
1068
+ */
1069
+ Diagnostic.isMicrophoneAuthorized = function(successCallback, errorCallback) {
1070
+ if(cordova.plugins.diagnostic.microphone){
1071
+ cordova.plugins.diagnostic.microphone.isMicrophoneAuthorized.apply(this, arguments);
1072
+ }else{
1073
+ throw "Diagnostic Microphone module is not installed";
1074
+ }
1075
+ };
1076
+
1077
+ /**
1078
+ * Returns the authorization status for the application to use the microphone for recording audio.
1079
+ *
1080
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1081
+ * This callback function is passed a single string parameter which indicates the authorization status.
1082
+ * Possible values are:
1083
+ * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED`
1084
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE`
1085
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
1086
+ * `cordova.plugins.diagnostic.permissionStatus.GRANTED`
1087
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1088
+ * This callback function is passed a single string parameter containing the error message.
1089
+ */
1090
+ Diagnostic.getMicrophoneAuthorizationStatus = function(successCallback, errorCallback) {
1091
+ if(cordova.plugins.diagnostic.microphone){
1092
+ cordova.plugins.diagnostic.microphone.getMicrophoneAuthorizationStatus.apply(this, arguments);
1093
+ }else{
1094
+ throw "Diagnostic Microphone module is not installed";
1095
+ }
1096
+ };
1097
+
1098
+ /**
1099
+ * Requests access to microphone if authorization was never granted nor denied, will only return access status otherwise.
1100
+ *
1101
+ * @param {Function} successCallback - The callback which will be called when authorization request is successful.
1102
+ * @param {Function} errorCallback - The callback which will be called when an error occurs.
1103
+ * This callback function is passed a single string parameter containing the error message.
1104
+ */
1105
+ Diagnostic.requestMicrophoneAuthorization = function(successCallback, errorCallback) {
1106
+ if(cordova.plugins.diagnostic.microphone){
1107
+ cordova.plugins.diagnostic.microphone.requestMicrophoneAuthorization.apply(this, arguments);
1108
+ }else{
1109
+ throw "Diagnostic Microphone module is not installed";
1110
+ }
1111
+ };
1112
+
1113
+ /*************
1114
+ * Contacts
1115
+ *************/
1116
+
1117
+ /**
1118
+ *Checks if the application is authorized to use contacts (address book).
1119
+ *
1120
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1121
+ * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized.
1122
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1123
+ * This callback function is passed a single string parameter containing the error message.
1124
+ */
1125
+ Diagnostic.isContactsAuthorized = function(successCallback, errorCallback) {
1126
+ if(cordova.plugins.diagnostic.contacts){
1127
+ cordova.plugins.diagnostic.contacts.isContactsAuthorized.apply(this, arguments);
1128
+ }else{
1129
+ throw "Diagnostic Contacts module is not installed";
1130
+ }
1131
+ };
1132
+
1133
+ /**
1134
+ * Returns the contacts (address book) authorization status for the application.
1135
+ *
1136
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1137
+ * This callback function is passed a single string parameter which indicates the authorization status.
1138
+ * Possible values are:
1139
+ * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED`
1140
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE`
1141
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
1142
+ * `cordova.plugins.diagnostic.permissionStatus.GRANTED`
1143
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1144
+ * This callback function is passed a single string parameter containing the error message.
1145
+ */
1146
+ Diagnostic.getContactsAuthorizationStatus = function(successCallback, errorCallback) {
1147
+ if(cordova.plugins.diagnostic.contacts){
1148
+ cordova.plugins.diagnostic.contacts.getContactsAuthorizationStatus.apply(this, arguments);
1149
+ }else{
1150
+ throw "Diagnostic Contacts module is not installed";
1151
+ }
1152
+ };
1153
+
1154
+ /**
1155
+ * Requests contacts (address book) authorization for the application.
1156
+ * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
1157
+ *
1158
+ * @param {Function} successCallback - The callback which will be called when authorization request is successful.
1159
+ * @param {Function} errorCallback - The callback which will be called when an error occurs.
1160
+ * This callback function is passed a single string parameter containing the error message.
1161
+ */
1162
+ Diagnostic.requestContactsAuthorization = function(successCallback, errorCallback) {
1163
+ if(cordova.plugins.diagnostic.contacts){
1164
+ cordova.plugins.diagnostic.contacts.requestContactsAuthorization.apply(this, arguments);
1165
+ }else{
1166
+ throw "Diagnostic Contacts module is not installed";
1167
+ }
1168
+ };
1169
+
1170
+ /*************
1171
+ * Calendar
1172
+ *************/
1173
+
1174
+ /**
1175
+ *Checks if the application is authorized to use calendar.
1176
+ *
1177
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1178
+ * This callback function is passed a single boolean parameter which is TRUE if access to microphone is authorized.
1179
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1180
+ * This callback function is passed a single string parameter containing the error message.
1181
+ */
1182
+ Diagnostic.isCalendarAuthorized = function(successCallback, errorCallback) {
1183
+ if(cordova.plugins.diagnostic.calendar){
1184
+ cordova.plugins.diagnostic.calendar.isCalendarAuthorized.apply(this, arguments);
1185
+ }else{
1186
+ throw "Diagnostic Calendar module is not installed";
1187
+ }
1188
+ };
1189
+
1190
+ /**
1191
+ * Returns the calendar authorization status for the application.
1192
+ *
1193
+ * @param {Function} successCallback - The callback which will be called when operation is successful.
1194
+ * This callback function is passed a single string parameter which indicates the authorization status.
1195
+ * Possible values are:
1196
+ * `cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED`
1197
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE`
1198
+ * `cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS`
1199
+ * `cordova.plugins.diagnostic.permissionStatus.GRANTED`
1200
+ * @param {Function} errorCallback - The callback which will be called when operation encounters an error.
1201
+ * This callback function is passed a single string parameter containing the error message.
1202
+ */
1203
+ Diagnostic.getCalendarAuthorizationStatus = function(successCallback, errorCallback) {
1204
+ if(cordova.plugins.diagnostic.calendar){
1205
+ cordova.plugins.diagnostic.calendar.getCalendarAuthorizationStatus.apply(this, arguments);
1206
+ }else{
1207
+ throw "Diagnostic Calendar module is not installed";
1208
+ }
1209
+ };
1210
+
1211
+ /**
1212
+ * Requests calendar authorization for the application.
1213
+ * Should only be called if authorization status is NOT_REQUESTED. Calling it when in any other state will have no effect.
1214
+ *
1215
+ * @param {Function} successCallback - The callback which will be called when authorization request is successful.
1216
+ * @param {Function} errorCallback - The callback which will be called when an error occurs.
1217
+ * This callback function is passed a single string parameter containing the error message.
1218
+ */
1219
+ Diagnostic.requestCalendarAuthorization = function(successCallback, errorCallback) {
1220
+ if(cordova.plugins.diagnostic.calendar){
1221
+ cordova.plugins.diagnostic.calendar.requestCalendarAuthorization.apply(this, arguments);
1222
+ }else{
1223
+ throw "Diagnostic Calendar module is not installed";
1224
+ }
1225
+ };
1226
+
1227
+ /*************
1228
+ * NFC
1229
+ *************/
1230
+
1231
+ /**
1232
+ * Checks if NFC hardware is present on device.
1233
+ *
1234
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1235
+ * This callback function is passed a single boolean parameter which is TRUE if NFC is present
1236
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1237
+ * This callback function is passed a single string parameter containing the error message.
1238
+ */
1239
+ Diagnostic.isNFCPresent = function(successCallback, errorCallback) {
1240
+ if(cordova.plugins.diagnostic.nfc){
1241
+ cordova.plugins.diagnostic.nfc.isNFCPresent.apply(this, arguments);
1242
+ }else{
1243
+ throw "Diagnostic NFC module is not installed";
1244
+ }
1245
+ };
1246
+
1247
+ /**
1248
+ * Checks if the device setting for NFC is switched on.
1249
+ *
1250
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1251
+ * This callback function is passed a single boolean parameter which is TRUE if NFC is switched on.
1252
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1253
+ * This callback function is passed a single string parameter containing the error message.
1254
+ */
1255
+ Diagnostic.isNFCEnabled = function(successCallback, errorCallback) {
1256
+ if(cordova.plugins.diagnostic.nfc){
1257
+ cordova.plugins.diagnostic.nfc.isNFCEnabled.apply(this, arguments);
1258
+ }else{
1259
+ throw "Diagnostic NFC module is not installed";
1260
+ }
1261
+ };
1262
+
1263
+ /**
1264
+ * Checks if NFC is available to the app.
1265
+ * Returns true if the device has NFC capabilities and if so that NFC is switched on.
1266
+ *
1267
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1268
+ * This callback function is passed a single boolean parameter which is TRUE if NFC is available.
1269
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1270
+ * This callback function is passed a single string parameter containing the error message.
1271
+ */
1272
+ Diagnostic.isNFCAvailable = function(successCallback, errorCallback) {
1273
+ if(cordova.plugins.diagnostic.nfc){
1274
+ cordova.plugins.diagnostic.nfc.isNFCAvailable.apply(this, arguments);
1275
+ }else{
1276
+ throw "Diagnostic NFC module is not installed";
1277
+ }
1278
+ };
1279
+
1280
+ /**
1281
+ * Registers a function to be called when a change in NFC state occurs.
1282
+ * Pass in a falsey value to de-register the currently registered function.
1283
+ *
1284
+ * @param {Function} successCallback - The callback which will be called when the NFC state changes.
1285
+ * This callback function is passed a single string parameter defined as a constant in `cordova.plugins.diagnostic.NFCState`.
1286
+ */
1287
+ Diagnostic.registerNFCStateChangeHandler = function(successCallback) {
1288
+ if(cordova.plugins.diagnostic.nfc){
1289
+ cordova.plugins.diagnostic.nfc.registerNFCStateChangeHandler.apply(this, arguments);
1290
+ }else{
1291
+ throw "Diagnostic NFC module is not installed";
1292
+ }
1293
+ };
1294
+
1295
+
1296
+ /**
1297
+ * Switches to the nfc settings page in the Settings app
1298
+ */
1299
+ Diagnostic.switchToNFCSettings = function() {
1300
+ if(cordova.plugins.diagnostic.nfc){
1301
+ cordova.plugins.diagnostic.nfc.switchToNFCSettings.apply(this, arguments);
1302
+ }else{
1303
+ throw "Diagnostic NFC module is not installed";
1304
+ }
1305
+ };
1306
+
1307
+ return Diagnostic;
1308
+ });
1309
+ module.exports = new Diagnostic();