cordova.plugins.diagnostic 7.2.0 → 7.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ **v7.2.2**
4
+ * (ios & android) feat: add isDebugBuild()
5
+ * fix: Separate isMobileDataEnabled() for Android vs isMobileDataAuthorized() for iOS.
6
+ * Resolves [#482](https://github.com/dpa99c/cordova-diagnostic-plugin/issues/482)
7
+
8
+
9
+ **v7.2.1**
10
+ * (android) fix logic in native resolution of single combined permission status in `getCameraAuthorizationStatus()` so it handles case where storage permissions are not requested
11
+
3
12
  **v7.2.0**
4
13
  * (android) feat: direct getExternalSdCardDetails without permission request
5
14
  * Merged from PR [#501](https://github.com/dpa99c/cordova-diagnostic-plugin/pull/501)
package/README.md CHANGED
@@ -43,10 +43,12 @@ Cordova diagnostic plugin [![Latest Stable Version](https://img.shields.io/npm/v
43
43
  - [getCurrentBatteryLevel()](#getcurrentbatterylevel)
44
44
  - [isAirplaneModeEnabled()](#isairplanemodeenabled)
45
45
  - [isMobileDataEnabled()](#ismobiledataenabled)
46
+ - [isMobileDataAuthorized()](#ismobiledataauthorized)
46
47
  - [isAccessibilityModeEnabled()](#isaccessibilitymodeenabled)
47
48
  - [isTouchExplorationEnabled()](#istouchexplorationenabled)
48
49
  - [getDeviceOSVersion()](#getdeviceosversion)
49
50
  - [getBuildOSVersion()](#getbuildosversion)
51
+ - [isDebugBuild()](#isdebugbuild)
50
52
  - [Location module](#location-module)
51
53
  - [locationMode constants](#locationmode-constants)
52
54
  - [locationAuthorizationMode constants](#locationauthorizationmode-constants)
@@ -939,19 +941,17 @@ The function is passed a single string parameter containing the error message.
939
941
  #### Example usage
940
942
 
941
943
  cordova.plugins.diagnostic.isAirplaneModeEnabled(function(enabled){
942
- console.log(`Airplane mode is currently ${enabled ? 'enabled' : 'disabled'}%`);
944
+ console.log(`Airplane mode is currently ${enabled ? 'enabled' : 'disabled'}`);
943
945
  });
944
946
 
945
-
946
- =======
947
947
 
948
948
  ### isMobileDataEnabled()
949
949
 
950
- Platforms: Android and iOS
950
+ Platforms: Android
951
951
 
952
- Checks if mobile (cellular) data is currently enabled on the device.
952
+ Checks if mobile (cellular) data is currently enabled in the device settings.
953
953
 
954
- On Android this requires permission `<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`
954
+ Requires permission `<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`
955
955
 
956
956
 
957
957
  cordova.plugins.diagnostic.isMobileDataEnabled(successCallback, errorCallback);
@@ -967,7 +967,31 @@ The function is passed a single string parameter containing the error message.
967
967
  #### Example usage
968
968
 
969
969
  cordova.plugins.diagnostic.isMobileDataEnabled(function(enabled){
970
- console.log(`Mobile data is currently ${enabled ? 'enabled' : 'disabled'}%`);
970
+ console.log(`Mobile data is currently ${enabled ? 'enabled' : 'disabled'}`);
971
+ });``
972
+
973
+ ### isMobileDataAuthorized()
974
+
975
+ Platforms: iOS
976
+
977
+ Checks if mobile data is authorized for this app.
978
+
979
+ Returns true if the per-app Mobile Data setting is set to enabled (regardless of whether the device is currently connected to a cellular network)
980
+
981
+ cordova.plugins.diagnostic.isMobileDataAuthorized(successCallback, errorCallback);
982
+
983
+ #### Parameters
984
+
985
+ - {Function} successCallback - The callback which will be called when operation is successful.
986
+ The function is passed a single boolean parameter which is TRUE if mobile data is authorized.
987
+ - {Function} errorCallback - The callback which will be called when operation encounters an error.
988
+ The function is passed a single string parameter containing the error message.
989
+
990
+
991
+ #### Example usage
992
+
993
+ cordova.plugins.diagnostic.isMobileDataAuthorized(function(authorized){
994
+ console.log(`Mobile data is currently ${authorized ? 'authorized' : 'unauthorized'}`);
971
995
  });
972
996
 
973
997
  ### isAccessibilityModeEnabled()
@@ -988,7 +1012,7 @@ This callback function is passed a single boolean parameter which is TRUE if acc
988
1012
  #### Example usage
989
1013
 
990
1014
  cordova.plugins.diagnostic.isAccessibilityModeEnabled(function(enabled){
991
- console.log(`Accessibility Mode is currently ${enabled ? 'enabled' : 'disabled'}%`);
1015
+ console.log(`Accessibility Mode is currently ${enabled ? 'enabled' : 'disabled'}`);
992
1016
  });
993
1017
 
994
1018
 
@@ -1010,7 +1034,7 @@ This callback function is passed a single boolean parameter which is TRUE if tou
1010
1034
  #### Example usage
1011
1035
 
1012
1036
  cordova.plugins.diagnostic.isTouchExplorationEnabled(function(enabled){
1013
- console.log(`touch exploration is currently ${enabled ? 'enabled' : 'disabled'}%`);
1037
+ console.log(`touch exploration is currently ${enabled ? 'enabled' : 'disabled'}`);
1014
1038
  });
1015
1039
 
1016
1040
 
@@ -1037,9 +1061,9 @@ The function is passed a single string parameter containing the error message.
1037
1061
  #### Example usage
1038
1062
 
1039
1063
  cordova.plugins.diagnostic.getDeviceOSVersion(function(details){
1040
- console.log(`Version: ${details.version}%`); // "13.0"
1041
- console.log(`API level: ${details.apiLevel}%`); // 33
1042
- console.log(`API name: ${details.apiName}%`); // "TIRAMISU"
1064
+ console.log(`Version: ${details.version}`); // "13.0"
1065
+ console.log(`API level: ${details.apiLevel}`); // 33
1066
+ console.log(`API name: ${details.apiName}`); // "TIRAMISU"
1043
1067
  });
1044
1068
 
1045
1069
  ### getBuildOSVersion()
@@ -1066,13 +1090,32 @@ The function is passed a single string parameter containing the error message.
1066
1090
  #### Example usage
1067
1091
 
1068
1092
  cordova.plugins.diagnostic.getBuildOSVersion(function(details){
1069
- console.log(`Target API level: ${details.targetApiLevel}%`); // 33
1070
- console.log(`Target API name: ${details.targetApiLevel}%`); // "TIRAMISU"
1071
- console.log(`Minimum API level: ${details.targetApiLevel}%`); // 21
1072
- console.log(`Target API name: ${details.targetApiLevel}%`); // "LOLLIPOP"
1093
+ console.log(`Target API level: ${details.targetApiLevel}`); // 33
1094
+ console.log(`Target API name: ${details.targetApiLevel}`); // "TIRAMISU"
1095
+ console.log(`Minimum API level: ${details.targetApiLevel}`); // 21
1096
+ console.log(`Target API name: ${details.targetApiLevel}`); // "LOLLIPOP"
1073
1097
  });
1074
1098
 
1099
+ ### isDebugBuild()
1100
+
1101
+ Platforms: Android & iOS
1102
+
1103
+ Checks if currently running app build is a debug build.
1104
+
1105
+ cordova.plugins.diagnostic.isDebugBuild(successCallback, errorCallback);
1106
+
1107
+ #### Parameters
1108
+
1109
+ - {Function} successCallback - The callback which will be called when the operation is successful.
1110
+ This callback function is passed a single boolean parameter which is TRUE if touch exploration (in accessibility mode) is enabled.
1111
+ - {Function} errorCallback - The callback which will be called when the operation encounters an error.
1112
+ This callback function is passed a single string parameter containing the error message.
1075
1113
 
1114
+ #### Example usage
1115
+
1116
+ cordova.plugins.diagnostic.isDebugBuild(function(isDebug){
1117
+ console.log(`current app build type is: ${isDebug ? 'debug' : 'release'}`);
1118
+ });
1076
1119
 
1077
1120
  ## Location module
1078
1121
 
@@ -1625,7 +1668,7 @@ The function is passed a single string parameter containing the error message.
1625
1668
  #### Example usage
1626
1669
 
1627
1670
  cordova.plugins.diagnostic.getLocationAccuracyAuthorization(function(accuracy){
1628
- switch(status){
1671
+ switch(accuracy){
1629
1672
  case cordova.plugins.diagnostic.locationAccuracyAuthorization.FULL:
1630
1673
  console.log("Full location accuracy is authorized");
1631
1674
  break;
@@ -305,6 +305,17 @@ interface Diagnostic {
305
305
  successCallback: () => void
306
306
  ) => void;
307
307
 
308
+ /**
309
+ * Returns true if the current build is a debug build.
310
+ * @param successCallback
311
+ * @param errorCallback
312
+ */
313
+ isDebugBuild?: (
314
+ successCallback: (enabled: boolean) => void,
315
+ errorCallback: (error: string) => void
316
+ ) => void;
317
+
318
+
308
319
 
309
320
  /**
310
321
  * ANDROID ONLY
@@ -332,6 +343,19 @@ interface Diagnostic {
332
343
  errorCallback: (error: string) => void
333
344
  ) => void;
334
345
 
346
+ /**
347
+ * IOS ONLY
348
+ *
349
+ * Checks if mobile data is authorized for this app.
350
+ *
351
+ * @param successCallback
352
+ * @param errorCallback
353
+ */
354
+ isMobileDataAuthorized?: (
355
+ successCallback: () => boolean,
356
+ errorCallback: (error: string) => void
357
+ ) => void;
358
+
335
359
  /**
336
360
  *
337
361
  * Checks if accessibility mode is enabled on device.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.2.0",
2
+ "version": "7.2.2",
3
3
  "name": "cordova.plugins.diagnostic",
4
4
  "cordova_name": "Diagnostic",
5
5
  "description": "Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.",
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova.plugins.diagnostic"
5
- version="7.2.0">
5
+ version="7.2.2">
6
6
 
7
7
  <name>Diagnostic</name>
8
8
  <description>Cordova/Phonegap plugin to check the state of Location/WiFi/Camera/Bluetooth device settings.</description>
@@ -64,6 +64,8 @@ import android.view.accessibility.AccessibilityManager;
64
64
 
65
65
  import androidx.core.app.ActivityCompat;
66
66
 
67
+ import cordova.plugins.diagnostic.example.BuildConfig;
68
+
67
69
  /**
68
70
  * Diagnostic plugin implementation for Android
69
71
  */
@@ -354,6 +356,8 @@ public class Diagnostic extends CordovaPlugin{
354
356
  callbackContext.success(getDeviceOSVersion());
355
357
  } else if(action.equals("getBuildOSVersion")) {
356
358
  callbackContext.success(getBuildOSVersion());
359
+ } else if(action.equals("isDebugBuild")) {
360
+ callbackContext.success(isDebugBuild() ? 1 : 0);
357
361
  } else {
358
362
  handleError("Invalid action");
359
363
  return false;
@@ -542,6 +546,12 @@ public class Diagnostic extends CordovaPlugin{
542
546
  return result;
543
547
  }
544
548
 
549
+ private boolean isDebugBuild() {
550
+ boolean result = BuildConfig.DEBUG;
551
+ logDebug("Debug build: " + result);
552
+ return result;
553
+ }
554
+
545
555
  /************
546
556
  * Internals
547
557
  ***********/
@@ -179,47 +179,75 @@ public class Diagnostic_Camera extends CordovaPlugin{
179
179
  String[] permissions = getPermissions(storage);
180
180
  JSONObject statuses = Diagnostic.instance._getPermissionsAuthorizationStatus(permissions);
181
181
 
182
- String status;
183
- if (
184
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
185
- (
186
- getStatusForPermission(statuses, "READ_MEDIA_IMAGES").equals("GRANTED") ||
187
- getStatusForPermission(statuses, "READ_MEDIA_VIDEO").equals("GRANTED")
188
- )
189
- ) {
190
- // Full access on Android 13 (API level 33) or higher
191
- status = "GRANTED";
192
- } else if (
193
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
194
- getStatusForPermission(statuses, "READ_MEDIA_VISUAL_USER_SELECTED").equals("GRANTED")
195
- ) {
196
- // Partial access on Android 14 (API level 34) or higher
197
- status = "LIMITED";
198
- } else if (
199
- getStatusForPermission(statuses, "READ_EXTERNAL_STORAGE").equals("GRANTED")
200
- ) {
201
- // Full access up to Android 12 (API level 32)
202
- status = "GRANTED";
203
- } else {
204
- // Access denied or not requested
205
-
206
- // if any permission is not requested, return NOT_REQUESTED
207
- if (getStatusForPermission(statuses, "CAMERA").equals("NOT_REQUESTED") ||
208
- getStatusForPermission(statuses, "READ_EXTERNAL_STORAGE").equals("NOT_REQUESTED") ||
209
- getStatusForPermission(statuses, "WRITE_EXTERNAL_STORAGE").equals("NOT_REQUESTED") ||
210
- getStatusForPermission(statuses, "READ_MEDIA_IMAGES").equals("NOT_REQUESTED") ||
211
- getStatusForPermission(statuses, "READ_MEDIA_VIDEO").equals("NOT_REQUESTED") ||
212
- getStatusForPermission(statuses, "READ_MEDIA_VISUAL_USER_SELECTED").equals("NOT_REQUESTED")
182
+ String cameraStatus = getStatusForPermission(statuses, cameraPermission);
183
+
184
+ String storageStatus = "DENIED";
185
+ if(storage) {
186
+ if (
187
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
188
+ (
189
+ getStatusForPermission(statuses, "READ_MEDIA_IMAGES").equals("GRANTED") ||
190
+ getStatusForPermission(statuses, "READ_MEDIA_VIDEO").equals("GRANTED")
191
+ )
192
+ ) {
193
+ // Full access on Android 13 (API level 33) or higher
194
+ storageStatus = "GRANTED";
195
+ } else if (
196
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
197
+ getStatusForPermission(statuses, "READ_MEDIA_VISUAL_USER_SELECTED").equals("GRANTED")
213
198
  ) {
214
- status = "NOT_REQUESTED";
199
+ // Partial access on Android 14 (API level 34) or higher
200
+ storageStatus = "LIMITED";
201
+ } else if (
202
+ getStatusForPermission(statuses, "READ_EXTERNAL_STORAGE").equals("GRANTED")
203
+ ) {
204
+ // Full access up to Android 12 (API level 32)
205
+ storageStatus = "GRANTED";
215
206
  } else {
216
- status = "DENIED";
207
+ // Combination of statuses for all storage permissions for relevant API level
208
+ storageStatus = combinePermissionStatuses(statuses);
217
209
  }
218
210
  }
211
+ String status = cameraStatus;
212
+ if(storage){
213
+ status = combinePermissionStatuses(new String[]{cameraStatus, storageStatus});
214
+ }
215
+
219
216
  callbackContext.success(status);
220
217
  }
221
218
 
222
219
  private String getStatusForPermission(JSONObject statuses, String permissionName) throws JSONException {
223
220
  return statuses.has(permissionName) ? statuses.getString(permissionName) : "DENIED";
224
221
  }
222
+
223
+ private boolean anyStatusIs(String status, String[] statuses){
224
+ for(String s : statuses){
225
+ if(s.equals(status)){
226
+ return true;
227
+ }
228
+ }
229
+ return false;
230
+ }
231
+
232
+ private String combinePermissionStatuses(JSONObject permissionsStatuses) throws JSONException {
233
+ String[] statuses = new String[storagePermissions.length];
234
+ for(int i = 0; i < storagePermissions.length; i++){
235
+ statuses[i] = getStatusForPermission(permissionsStatuses, storagePermissions[i]);
236
+ }
237
+ return combinePermissionStatuses(statuses);
238
+ }
239
+
240
+ private String combinePermissionStatuses(String[] statuses){
241
+ if(anyStatusIs("DENIED_ALWAYS", statuses)){
242
+ return "DENIED_ALWAYS";
243
+ }else if(anyStatusIs("LIMITED", statuses)){
244
+ return "LIMITED";
245
+ }else if(anyStatusIs("DENIED", statuses)){
246
+ return "DENIED";
247
+ }else if(anyStatusIs("GRANTED", statuses)){
248
+ return "GRANTED";
249
+ }else{
250
+ return "NOT_REQUESTED";
251
+ }
252
+ }
225
253
  }
@@ -37,8 +37,9 @@ extern NSString*const AUTHORIZATION_LIMITED;
37
37
  - (void) getCurrentBatteryLevel: (CDVInvokedUrlCommand*)command;
38
38
  - (void) getDeviceOSVersion: (CDVInvokedUrlCommand*)command;
39
39
  - (void) getBuildOSVersion: (CDVInvokedUrlCommand*)command;
40
- - (void) isMobileDataEnabled: (CDVInvokedUrlCommand*)command;
40
+ - (void) isMobileDataAuthorized: (CDVInvokedUrlCommand*)command;
41
41
  - (void) isAccessibilityModeEnabled: (CDVInvokedUrlCommand*)command;
42
+ - (void) isDebugBuild: (CDVInvokedUrlCommand*)command;
42
43
 
43
44
  // Utilities
44
45
  + (id) getInstance;
@@ -227,7 +227,7 @@ static CTCellularData* cellularData;
227
227
  }];
228
228
  }
229
229
 
230
- - (void) isMobileDataEnabled: (CDVInvokedUrlCommand*)command
230
+ - (void) isMobileDataAuthorized: (CDVInvokedUrlCommand*)command
231
231
  {
232
232
  [self.commandDelegate runInBackground:^{
233
233
  @try {
@@ -259,6 +259,22 @@ static CTCellularData* cellularData;
259
259
  }];
260
260
  }
261
261
 
262
+ - (void) isDebugBuild: (CDVInvokedUrlCommand*)command
263
+ {
264
+ [self.commandDelegate runInBackground:^{
265
+ @try {
266
+ bool result = false;
267
+ #ifdef DEBUG
268
+ result = true;
269
+ #endif
270
+ [diagnostic sendPluginResultBool:result :command];
271
+ }
272
+ @catch (NSException *exception) {
273
+ [diagnostic handlePluginException:exception :command];
274
+ }
275
+ }];
276
+ }
277
+
262
278
  /********************************/
263
279
  #pragma mark - Send results
264
280
  /********************************/
@@ -499,7 +499,7 @@ var Diagnostic = (function(){
499
499
  };
500
500
 
501
501
  /**
502
- * Checks if mobile data is enabled on device.
502
+ * Checks if mobile data is enabled in device settings.
503
503
  *
504
504
  * @param {Function} successCallback - The callback which will be called when the operation is successful.
505
505
  * This callback function is passed a single boolean parameter which is TRUE if mobile data is enabled.
@@ -1560,6 +1560,22 @@ var Diagnostic = (function(){
1560
1560
  }
1561
1561
  };
1562
1562
 
1563
+ /**
1564
+ * Checks if the current app build is a debug build.
1565
+ *
1566
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
1567
+ * This callback function is passed a single boolean parameter which is TRUE if the app is a debug build.
1568
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
1569
+ * This callback function is passed a single string parameter containing the error message.
1570
+ */
1571
+ Diagnostic.isDebugBuild = function(successCallback, errorCallback) {
1572
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
1573
+ errorCallback,
1574
+ 'Diagnostic',
1575
+ 'isDebugBuild',
1576
+ []);
1577
+ };
1578
+
1563
1579
 
1564
1580
  return Diagnostic;
1565
1581
  });
@@ -154,18 +154,19 @@ var Diagnostic = (function(){
154
154
  };
155
155
 
156
156
  /**
157
- * Checks if mobile data is enabled on device.
157
+ * Checks if mobile data is authorized for this app.
158
+ * Returns true if the per-app Mobile Data setting is set to enabled (regardless of whether the device is currently connected to a cellular network)
158
159
  *
159
160
  * @param {Function} successCallback - The callback which will be called when the operation is successful.
160
161
  * This callback function is passed a single boolean parameter which is TRUE if mobile data is enabled.
161
162
  * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
162
163
  * This callback function is passed a single string parameter containing the error message.
163
164
  */
164
- Diagnostic.isMobileDataEnabled = function(successCallback, errorCallback) {
165
+ Diagnostic.isMobileDataAuthorized = function(successCallback, errorCallback) {
165
166
  return cordova.exec(Diagnostic._ensureBoolean(successCallback),
166
167
  errorCallback,
167
168
  'Diagnostic',
168
- 'isMobileDataEnabled',
169
+ 'isMobileDataAuthorized',
169
170
  []);
170
171
  };
171
172
 
@@ -225,6 +226,22 @@ var Diagnostic = (function(){
225
226
  []);
226
227
  };
227
228
 
229
+ /**
230
+ * Checks if the current app build is a debug build.
231
+ *
232
+ * @param {Function} successCallback - The callback which will be called when the operation is successful.
233
+ * This callback function is passed a single boolean parameter which is TRUE if the app is a debug build.
234
+ * @param {Function} errorCallback - The callback which will be called when the operation encounters an error.
235
+ * This callback function is passed a single string parameter containing the error message.
236
+ */
237
+ Diagnostic.isDebugBuild = function(successCallback, errorCallback) {
238
+ return cordova.exec(Diagnostic._ensureBoolean(successCallback),
239
+ errorCallback,
240
+ 'Diagnostic',
241
+ 'isDebugBuild',
242
+ []);
243
+ };
244
+
228
245
  /************
229
246
  * Location *
230
247
  ************/
@@ -1125,6 +1142,8 @@ var Diagnostic = (function(){
1125
1142
  }
1126
1143
  };
1127
1144
 
1145
+
1146
+
1128
1147
  return Diagnostic;
1129
1148
  })();
1130
1149
  module.exports = Diagnostic;