From f3adaad6d60437b712c8c5247e12ea3cd97f8b46 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: Mon, 16 Oct 2023 16:37:53 +0200 Subject: [PATCH 1/2] Swaps calendar READ for WRITE --- permission_handler_android/CHANGELOG.md | 6 +++ .../PermissionConstants.java | 6 +-- .../permissionhandler/PermissionManager.java | 52 +++++++++---------- .../permissionhandler/PermissionUtils.java | 12 ++--- permission_handler_android/pubspec.yaml | 4 +- 5 files changed, 43 insertions(+), 37 deletions(-) diff --git a/permission_handler_android/CHANGELOG.md b/permission_handler_android/CHANGELOG.md index a56ef986f..2a1134b83 100644 --- a/permission_handler_android/CHANGELOG.md +++ b/permission_handler_android/CHANGELOG.md @@ -1,3 +1,9 @@ +## 12.0.0 + +* **BREAKING CHANGES:** + * Adds `Permission.calendarWriteOnly`. + * Removes `Permission.calendarReadOnly`. + ## 11.1.0 * Implements the `Permission.calendarReadOnly` and `PermissionCalendarFullAccess` permissions. diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java index af91dd371..27691ecbb 100644 --- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java +++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionConstants.java @@ -20,7 +20,7 @@ final class PermissionConstants { // PERMISSION_GROUP - // Deprecated in favor of PERMISSION_GROUP_CALENDAR_READ_ONLY and + // Deprecated in favor of PERMISSION_GROUP_CALENDAR_WRITE_ONLY and // PERMISSION_GROUP_CALENDAR_FULL_ACCESS. static final int PERMISSION_GROUP_CALENDAR = 0; static final int PERMISSION_GROUP_CAMERA = 1; @@ -58,7 +58,7 @@ final class PermissionConstants { static final int PERMISSION_GROUP_AUDIO = 33; static final int PERMISSION_GROUP_SCHEDULE_EXACT_ALARM = 34; static final int PERMISSION_GROUP_SENSORS_ALWAYS = 35; - static final int PERMISSION_GROUP_CALENDAR_READ_ONLY = 36; + static final int PERMISSION_GROUP_CALENDAR_WRITE_ONLY = 36; static final int PERMISSION_GROUP_CALENDAR_FULL_ACCESS = 37; @Retention(RetentionPolicy.SOURCE) @@ -96,7 +96,7 @@ final class PermissionConstants { PERMISSION_GROUP_VIDEOS, PERMISSION_GROUP_AUDIO, PERMISSION_GROUP_SCHEDULE_EXACT_ALARM, - PERMISSION_GROUP_CALENDAR_READ_ONLY, + PERMISSION_GROUP_CALENDAR_WRITE_ONLY, PERMISSION_GROUP_CALENDAR_FULL_ACCESS }) @interface PermissionGroup { diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java index 6dd54e031..ad823b165 100644 --- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java +++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java @@ -166,24 +166,24 @@ public boolean onRequestPermissionsResult( return false; } - // Calendar permissions are split between READ and WRITE in Android, and split between READ + // Calendar permissions are split between WRITE and READ in Android, and split between WRITE // and FULL ACCESS in the plugin. We need special logic for this translation. final List permissionList = Arrays.asList(permissions); - final int calendarReadIndex = permissionList.indexOf(Manifest.permission.READ_CALENDAR); final int calendarWriteIndex = permissionList.indexOf(Manifest.permission.WRITE_CALENDAR); - // READ -> READ. - if (calendarReadIndex >= 0) { - final int readGrantResult = grantResults[calendarReadIndex]; - final @PermissionConstants.PermissionStatus int readStatus = - PermissionUtils.toPermissionStatus(this.activity, Manifest.permission.READ_CALENDAR, readGrantResult); - requestResults.put(PermissionConstants.PERMISSION_GROUP_CALENDAR_READ_ONLY, readStatus); - - // READ + WRITE -> FULL ACCESS. - if (calendarWriteIndex >= 0) { - final int writeGrantResult = grantResults[calendarWriteIndex]; - final @PermissionConstants.PermissionStatus int writeStatus = - PermissionUtils.toPermissionStatus(this.activity, Manifest.permission.WRITE_CALENDAR, writeGrantResult); - final @PermissionConstants.PermissionStatus int fullAccessStatus = strictestStatus(readStatus, writeStatus); + // WRITE -> WRITE. + if (calendarWriteIndex >= 0) { + final int writeGrantResult = grantResults[calendarWriteIndex]; + final @PermissionConstants.PermissionStatus int writeStatus = + PermissionUtils.toPermissionStatus(this.activity, Manifest.permission.WRITE_CALENDAR, writeGrantResult); + requestResults.put(PermissionConstants.PERMISSION_GROUP_CALENDAR_WRITE_ONLY, writeStatus); + + // WRITE + READ -> FULL ACCESS. + final int calendarReadIndex = permissionList.indexOf(Manifest.permission.READ_CALENDAR); + if (calendarReadIndex >= 0) { + final int readGrantResult = grantResults[calendarReadIndex]; + final @PermissionConstants.PermissionStatus int readStatus = + PermissionUtils.toPermissionStatus(this.activity, Manifest.permission.READ_CALENDAR, readGrantResult); + final @PermissionConstants.PermissionStatus int fullAccessStatus = strictestStatus(writeStatus, readStatus); requestResults.put(PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS, fullAccessStatus); // Support deprecated CALENDAR permission. requestResults.put(PermissionConstants.PERMISSION_GROUP_CALENDAR, fullAccessStatus); @@ -193,8 +193,8 @@ public boolean onRequestPermissionsResult( for (int i = 0; i < permissions.length; i++) { final String permissionName = permissions[i]; - // READ_CALENDAR and WRITE_CALENDAR permission results have already been handled. - if (permissionName.equals(Manifest.permission.READ_CALENDAR) || permissionName.equals(Manifest.permission.WRITE_CALENDAR)) { + // WRITE_CALENDAR and READ_CALENDAR permission results have already been handled. + if (permissionName.equals(Manifest.permission.WRITE_CALENDAR) || permissionName.equals(Manifest.permission.READ_CALENDAR)) { continue; } @@ -409,12 +409,12 @@ void requestPermissions( Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM, PermissionConstants.PERMISSION_CODE_SCHEDULE_EXACT_ALARM); } else if (permission == PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS || permission == PermissionConstants.PERMISSION_GROUP_CALENDAR) { - // Deny CALENDAR_FULL_ACCESS permission if manifest is not listing both read- and write permissions. - // Otherwise, we will only ask for READ permission and think full access is granted. + // Deny CALENDAR_FULL_ACCESS permission if manifest is not listing both write- and read permissions. + // Otherwise, we will only ask for WRITE permission and think full access is granted. final boolean isValidManifest = isValidManifestForCalendarFullAccess(); if (isValidManifest) { - permissionsToRequest.add(Manifest.permission.READ_CALENDAR); permissionsToRequest.add(Manifest.permission.WRITE_CALENDAR); + permissionsToRequest.add(Manifest.permission.READ_CALENDAR); pendingRequestCount += 2; } else { requestResults.put(permission, PermissionConstants.PERMISSION_STATUS_DENIED); @@ -650,19 +650,19 @@ private int checkBluetoothPermissionStatus() { } /** - * Checks if the manifest contains both {@link Manifest.permission#READ_CALENDAR} and - * {@link Manifest.permission#WRITE_CALENDAR} permission declarations. + * Checks if the manifest contains both {@link Manifest.permission#WRITE_CALENDAR} and + * {@link Manifest.permission#READ_CALENDAR} permission declarations. */ private boolean isValidManifestForCalendarFullAccess() { List names = PermissionUtils.getManifestNames(context, PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS); - final boolean readInManifest = names != null && names.contains(Manifest.permission.READ_CALENDAR); final boolean writeInManifest = names != null && names.contains(Manifest.permission.WRITE_CALENDAR); - final boolean validManifest = readInManifest && writeInManifest; + final boolean readInManifest = names != null && names.contains(Manifest.permission.READ_CALENDAR); + final boolean validManifest = writeInManifest && readInManifest; if (!validManifest) { - if (!readInManifest) - Log.d(PermissionConstants.LOG_TAG, Manifest.permission.READ_CALENDAR + " missing in manifest"); if (!writeInManifest) Log.d(PermissionConstants.LOG_TAG, Manifest.permission.WRITE_CALENDAR + " missing in manifest"); + if (!readInManifest) + Log.d(PermissionConstants.LOG_TAG, Manifest.permission.READ_CALENDAR + " missing in manifest"); return false; } return true; diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java index db73cd8d3..be482b5ab 100644 --- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java +++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionUtils.java @@ -27,8 +27,8 @@ public class PermissionUtils { @PermissionConstants.PermissionGroup static int parseManifestName(String permission) { switch (permission) { - case Manifest.permission.READ_CALENDAR: case Manifest.permission.WRITE_CALENDAR: + case Manifest.permission.READ_CALENDAR: return PermissionConstants.PERMISSION_GROUP_CALENDAR; case Manifest.permission.CAMERA: return PermissionConstants.PERMISSION_GROUP_CAMERA; @@ -103,17 +103,17 @@ static List getManifestNames(Context context, @PermissionConstants.Permi final ArrayList permissionNames = new ArrayList<>(); switch (permission) { - case PermissionConstants.PERMISSION_GROUP_CALENDAR_READ_ONLY: - if (hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_CALENDAR)) - permissionNames.add(Manifest.permission.READ_CALENDAR); + case PermissionConstants.PERMISSION_GROUP_CALENDAR_WRITE_ONLY: + if (hasPermissionInManifest(context, permissionNames, Manifest.permission.WRITE_CALENDAR)) + permissionNames.add(Manifest.permission.WRITE_CALENDAR); break; case PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS: case PermissionConstants.PERMISSION_GROUP_CALENDAR: - if (hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_CALENDAR)) - permissionNames.add(Manifest.permission.READ_CALENDAR); if (hasPermissionInManifest(context, permissionNames, Manifest.permission.WRITE_CALENDAR)) permissionNames.add(Manifest.permission.WRITE_CALENDAR); + if (hasPermissionInManifest(context, permissionNames, Manifest.permission.READ_CALENDAR)) + permissionNames.add(Manifest.permission.READ_CALENDAR); break; case PermissionConstants.PERMISSION_GROUP_CAMERA: diff --git a/permission_handler_android/pubspec.yaml b/permission_handler_android/pubspec.yaml index 0cb1874a8..84580dbe2 100644 --- a/permission_handler_android/pubspec.yaml +++ b/permission_handler_android/pubspec.yaml @@ -1,7 +1,7 @@ name: permission_handler_android description: Permission plugin for Flutter. This plugin provides the Android API to request and check permissions. homepage: https://github.com/baseflow/flutter-permission-handler -version: 11.1.0 +version: 12.0.0 environment: sdk: ">=2.15.0 <4.0.0" @@ -18,7 +18,7 @@ flutter: dependencies: flutter: sdk: flutter - permission_handler_platform_interface: ^3.12.0 + permission_handler_platform_interface: ^4.0.0 dev_dependencies: flutter_lints: ^1.0.4 From 55ebee6ca752a85dc9cd42748d6aa756b2175a09 Mon Sep 17 00:00:00 2001 From: Jeroen Weener Date: Tue, 17 Oct 2023 10:23:40 +0200 Subject: [PATCH 2/2] Delete confusing doc sentence --- .../java/com/baseflow/permissionhandler/PermissionManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java index ad823b165..985b27d04 100644 --- a/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java +++ b/permission_handler_android/android/src/main/java/com/baseflow/permissionhandler/PermissionManager.java @@ -410,7 +410,6 @@ void requestPermissions( PermissionConstants.PERMISSION_CODE_SCHEDULE_EXACT_ALARM); } else if (permission == PermissionConstants.PERMISSION_GROUP_CALENDAR_FULL_ACCESS || permission == PermissionConstants.PERMISSION_GROUP_CALENDAR) { // Deny CALENDAR_FULL_ACCESS permission if manifest is not listing both write- and read permissions. - // Otherwise, we will only ask for WRITE permission and think full access is granted. final boolean isValidManifest = isValidManifestForCalendarFullAccess(); if (isValidManifest) { permissionsToRequest.add(Manifest.permission.WRITE_CALENDAR);