Skip to content

Commit

Permalink
Android: Document behaviour of empty grantResults in onRequestPermiss…
Browse files Browse the repository at this point in the history
…ionResult

It is possible that the permissions request interaction with the user is interrupted. In this case the permissions and grantResults array is empty, which should be treated as a cancellation.
  • Loading branch information
GitToTheHub committed Feb 15, 2025
1 parent f0f68fd commit 5240174
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Version 1.1.3-dev

### Android
- fix(crash): ArrayIndexOutOfBoundsException when checking if permission were granted PR #2058
- grantResults is an empty array on some devices
- fix(crash): `ArrayIndexOutOfBoundsException` can occur, if the user dismisses a permission request without clicking a button
- Reported by #UzverNumber47. Thanks :)

## Version 1.1.2 (08.02.2025)

Expand Down
10 changes: 6 additions & 4 deletions src/android/LocalNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,12 @@ private void requestPermission(CallbackContext callbackContext) {
}

/**
* Called by the system when the user grants permissions.
* Called by {@link CordovaActivity#onRequestPermissionsResult} when the user grants permissions, which
* was called by Android.
*
* @deprecated In the future {@link #onRequestPermissionsResult} should be used, but cordova calls still the old
* method: https://github.com/apache/cordova-android/issues/1388
* @see Android method onRequestPermissionsResult: https://developer.android.com/reference/android/app/Activity#onRequestPermissionsResult(int,%20java.lang.String[],%20int[])
*/
@Override
@Deprecated
Expand All @@ -288,9 +291,8 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int
", permissions=" + Arrays.toString(permissions) +
", grantResults=" + Arrays.toString(grantResults));

// grantResults can be empty, but it's not clear, why this can happen
// see https://github.com/katzer/cordova-plugin-local-notifications/pull/2058
// set to false, if grantResults is empty
// It is possible that the permissions request interaction with the user is interrupted.
// In this case the permissions and grantResults array is empty, which should be treated as a cancellation.
boolean permissionGranted = grantResults.length > 0 ? grantResults[0] == PackageManager.PERMISSION_GRANTED : false;
CallbackContext callbackContext = CallbackContextUtil.getCallbackContext(requestCode);

Expand Down

0 comments on commit 5240174

Please sign in to comment.