Skip to content

Commit

Permalink
[flutter_local_notifications] setupAlarm method: handle ScheduleMode.…
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
RuchiPurohit and MaikuB authored Jan 19, 2024
1 parent c9c769e commit 2e08451
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,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;
Expand Down Expand Up @@ -676,7 +676,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;
Expand All @@ -700,6 +700,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 {
Expand Down

0 comments on commit 2e08451

Please sign in to comment.