From 746ef8d5c09ee30d81a1bc084fd900773b2dd10c Mon Sep 17 00:00:00 2001 From: OS-pedrogustavobilro Date: Mon, 25 Nov 2024 15:58:53 +0000 Subject: [PATCH 1/2] fix: Denial of notification permission by switching order with Exact alarms References: https://outsystemsrd.atlassian.net/wiki/spaces/RDME/pages/4426137659/iOS+18+Android+15+Assessment --- src/android/LocalNotification.java | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/android/LocalNotification.java b/src/android/LocalNotification.java index 197acd65f..7cece77bd 100644 --- a/src/android/LocalNotification.java +++ b/src/android/LocalNotification.java @@ -115,12 +115,10 @@ public void onResume (boolean multitasking) { super.onResume(multitasking); deviceready(); - if(!requestingNotificationsPermissions && requestingExactAlarmPermission) { + if(requestingExactAlarmPermission) { requestingExactAlarmPermission = false; onScheduleExactAlarmPermissionResult(); } - - requestingNotificationsPermissions = false; } /** @@ -172,7 +170,7 @@ public void run() { actions(args, command); } else if (action.equals("schedule")) { - schedule(args, command); + schedule(args, command, true); } else if (action.equals("update")) { update(args, command); @@ -235,8 +233,9 @@ private void launch(CallbackContext command) { @Override public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { super.onRequestPermissionResult(requestCode, permissions, grantResults); - if(requestCode == NOTIFICATION_PERMISSION_CODE){ - schedule(notificationArguments, callbackContext); + if (requestCode == NOTIFICATION_PERMISSION_CODE) { + schedule(notificationArguments, callbackContext, false); + requestingNotificationsPermissions = false; } } @@ -306,20 +305,23 @@ private void actions (JSONArray args, CallbackContext command) { * @param toasts The notifications to schedule. * @param command The callback context used when calling back into * JavaScript. + * @param requestExactAlarmPermission whether should request exact alarm permission or not + * (e.g. send false if already checked prior) */ - private void schedule (JSONArray toasts, CallbackContext command) { + private void schedule (JSONArray toasts, CallbackContext command, boolean requestExactAlarmPermission) { callbackContext = command; notificationArguments = toasts; - if(Build.VERSION.SDK_INT >= 33 - && !PermissionHelper.hasPermission(this, NOTIFICATION_PERMISSION) - && !requestingNotificationsPermissions){ + if(hasAnyExactNotification() && !getNotMgr().canScheduleExactAlarms() && requestExactAlarmPermission) { + requestScheduleExactAlarmPermission(); + } + else if(Build.VERSION.SDK_INT >= 33 + && !PermissionHelper.hasPermission(this, NOTIFICATION_PERMISSION) + && !requestingNotificationsPermissions + ){ requestingNotificationsPermissions = true; PermissionHelper.requestPermission(this, NOTIFICATION_PERMISSION_CODE, NOTIFICATION_PERMISSION); } - else if(hasAnyExactNotification() && !getNotMgr().canScheduleExactAlarms()) { - requestScheduleExactAlarmPermission(); - } else { scheduleWithPermission(); } @@ -423,7 +425,7 @@ private void onScheduleExactAlarmPermissionResult() { warning = OSLCNOWarning.EXACT_PERMISSION; } - schedule(notificationArguments, callbackContext); + schedule(notificationArguments, callbackContext, false); } /** From cd670108cd8014516fadd499b04b1ab38987c8ec Mon Sep 17 00:00:00 2001 From: OS-pedrogustavobilro Date: Mon, 25 Nov 2024 16:48:52 +0000 Subject: [PATCH 2/2] chore: Update CHANGELOG.md References: https://outsystemsrd.atlassian.net/wiki/spaces/RDME/pages/4426137659/iOS+18+Android+15+Assessment --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 139b16d1d..6df144c12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-lo #### Unreleased +### 25-11-2024 +- Android: Fix endless loop of notification permission denial when granting exact alarm permission + #### Version 0.9.13 (07.10.2024) ### 07-10-2024 - Android: Deliver notifications while app is in foreground if `foreground` option is `true`. [RMET-3699](https://outsystemsrd.atlassian.net/browse/RMET-3699)