diff --git a/src/android/Diagnostic.java b/src/android/Diagnostic.java index efba17b..54cca75 100644 --- a/src/android/Diagnostic.java +++ b/src/android/Diagnostic.java @@ -564,7 +564,7 @@ protected JSONObject _getPermissionsAuthorizationStatus(String[] permissions) th String androidPermission = permissionsMap.get(permission); Log.v(TAG, "Get authorisation status for "+androidPermission); boolean granted = hasRuntimePermission(androidPermission); - if(granted){ + if(granted || isPermissionImplicitlyGranted(permission)){ statuses.put(permission, Diagnostic.STATUS_GRANTED); }else{ boolean showRationale = shouldShowRequestPermissionRationale(this.cordova.getActivity(), androidPermission); @@ -588,7 +588,7 @@ protected void _requestRuntimePermissions(JSONArray permissions, int requestId) for(int i = 0; i= 33 && deviceRuntimeSdkVersion < 33 && ( + permission.equals("ACCESS_BACKGROUND_LOCATION") || + permission.equals("POST_NOTIFICATIONS") || + permission.equals("READ_MEDIA_AUDIO") || + permission.equals("READ_MEDIA_IMAGES") || + permission.equals("READ_MEDIA_VIDEO") || + permission.equals("BODY_SENSORS_BACKGROUND") || + permission.equals("NEARBY_WIFI_DEVICES") + + )) { + isImplicitlyGranted = true; + } + return isImplicitlyGranted; + } + protected void sendRuntimeRequestResult(int requestId){ String sRequestId = String.valueOf(requestId); CallbackContext context = callbackContexts.get(sRequestId); @@ -863,31 +883,51 @@ public boolean isAirplaneModeEnabled() { public JSONObject getDeviceOSVersion() throws Exception{ JSONObject details = new JSONObject(); details.put("version", Build.VERSION.RELEASE); - details.put("apiLevel", Build.VERSION.SDK_INT); - details.put("apiName", getNameForApiLevel(Build.VERSION.SDK_INT)); + int buildVersion = getDeviceRuntimeSdkVersion(); + details.put("apiLevel", buildVersion); + details.put("apiName", getNameForApiLevel(buildVersion)); return details; } + protected int getDeviceRuntimeSdkVersion() { + return Build.VERSION.SDK_INT; + } + public JSONObject getBuildOSVersion() throws Exception{ JSONObject details = new JSONObject(); + int targetVersion = getBuildTargetSdkVersion(); + int minVersion = getBuildMinimumSdkVersion(); + + details.put("targetApiLevel", targetVersion); + details.put("targetApiName", getNameForApiLevel(targetVersion)); + details.put("minApiLevel", minVersion); + details.put("minApiName", getNameForApiLevel(minVersion)); + return details; + } + + protected int getBuildTargetSdkVersion() throws Exception{ int targetVersion = 0; - int minVersion = 0; Activity activity = instance.cordova.getActivity(); ApplicationInfo applicationInfo = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0); if (applicationInfo != null) { targetVersion = applicationInfo.targetSdkVersion; + } + return targetVersion; + } + + protected int getBuildMinimumSdkVersion() throws Exception{ + int minVersion = 0; + Activity activity = instance.cordova.getActivity(); + ApplicationInfo applicationInfo = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0); + if (applicationInfo != null) { if(Build.VERSION.SDK_INT >= 24){ minVersion = applicationInfo.minSdkVersion; } } - - details.put("targetApiLevel", targetVersion); - details.put("targetApiName", getNameForApiLevel(targetVersion)); - details.put("minApiLevel", minVersion); - details.put("minApiName", getNameForApiLevel(minVersion)); - return details; + return minVersion; } + // https://stackoverflow.com/a/55946200/777265 protected String getNameForApiLevel(int apiLevel) throws Exception{ Field[] fields = Build.VERSION_CODES.class.getFields();