From 3a82d633e9323f752f47e027183588ec0a40a760 Mon Sep 17 00:00:00 2001 From: Ruchi Purohit <30714929+RuchiPurohit@users.noreply.github.com> Date: Fri, 19 Jan 2024 02:53:13 -0800 Subject: [PATCH] [flutter_local_notifications] setupAlarm method: handle ScheduleMode.useAllowWhileIdle() called on null (#2199) * Handle ScheduleMode.useAllowWhileIdle() called on a null object reference * handle null: added scheduleMode = ScheduleMode.exact * added semicolon * fixed typo in comments --------- Co-authored-by: Michael Bui <25263378+MaikuB@users.noreply.github.com> --- .../FlutterLocalNotificationsPlugin.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java index 69320b992..1db03f7a1 100644 --- a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java +++ b/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java @@ -586,7 +586,7 @@ private static void scheduleNextRepeatingNotification( AlarmManager alarmManager = getAlarmManager(context); if (notificationDetails.scheduleMode == null) { // This is to account for notifications created in older versions prior to allowWhileIdle - // being added so the deserialiser. + // being added to the deserialiser. // Reference to old behaviour: // https://github.com/MaikuB/flutter_local_notifications/blob/4b723e750d1371206520b10a122a444c4bba7475/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L569C37-L569C37 notificationDetails.scheduleMode = ScheduleMode.exactAllowWhileIdle; @@ -664,7 +664,7 @@ private static void repeatNotification( if (notificationDetails.scheduleMode == null) { // This is to account for notifications created in older versions prior to allowWhileIdle - // being added so the deserialiser. + // being added to the deserialiser. // Reference to old behaviour: // https://github.com/MaikuB/flutter_local_notifications/blob/4b723e750d1371206520b10a122a444c4bba7475/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L642 notificationDetails.scheduleMode = ScheduleMode.inexact; @@ -688,6 +688,15 @@ private static void setupAlarm( AlarmManager alarmManager, long epochMilli, PendingIntent pendingIntent) { + + if (notificationDetails.scheduleMode == null) { + // This is to account for notifications created in older versions prior to allowWhileIdle + // being added to the deserialiser. + // Reference to old behaviour: + // https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L735 + notificationDetails.scheduleMode = ScheduleMode.exact; + } + if (notificationDetails.scheduleMode.useAllowWhileIdle()) { setupAllowWhileIdleAlarm(notificationDetails, alarmManager, epochMilli, pendingIntent); } else {