Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3edc2020 authored by Marcos Marado's avatar Marcos Marado
Browse files

AlarmStateManager: deal with missing alarms

getAlarm(alarmId) can return null, if an alarm with alarmId isn't
found.
fixAlarmInstances has to be able to deal with missing alarms, in order
to avoid NPEs.

Issue: BUGDUMP-7996259
Change-Id: Ia3e9824812efacd0dd620789505edc88f4b5eb62
parent 958482fb
Loading
Loading
Loading
Loading
+17 −13
Original line number Diff line number Diff line
@@ -763,6 +763,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
        final Calendar currentTime = getCurrentTime();
        for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
            final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
            if (alarm != null) {
                final Calendar priorAlarmTime = alarm.getPreviousAlarmTime(instance.getAlarmTime());
                final Calendar missedTTLTime = instance.getMissedTimeToLive();
                if (currentTime.before(priorAlarmTime) || currentTime.after(missedTTLTime)) {
@@ -779,6 +780,9 @@ public final class AlarmStateManager extends BroadcastReceiver {
                } else {
                    registerInstance(context, instance, false);
                }
            } else {
                registerInstance(context, instance, false);
            }
        }
        
        updateNextAlarm(context);