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

Commit 2a9ec6e1 authored by Annie Chin's avatar Annie Chin
Browse files

Adjust how snoozed alarms are rescheduled in response to TIME_SET,

TIMEZONE_CHANGED, and BOOT_COMPLETED.

Bug: 21363078

1. Dismiss snoozed alarms after a reboot
2. Do not reschedule snoozed alarms for their next scheduled instance;
keep the snoozed firing time. AlarmManager will immediately fire alarms
that are registered for already-passed times.

Change-Id: I64aa3d2c7a257bb140c06284c038c65f673b86e7
parent 4dbc159d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ public class AlarmInitReceiver extends BroadcastReceiver {
        AlarmStateManager.updateGlobalIntentId(context);
        AsyncHandler.post(new Runnable() {
            @Override public void run() {
                // Remove the snooze alarm after a boot.
                if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
                    // Clear stopwatch and timers data
                    SharedPreferences prefs =
@@ -59,6 +58,9 @@ public class AlarmInitReceiver extends BroadcastReceiver {
                    TimerObj.resetTimersInSharedPrefs(prefs);
                    Utils.clearSwSharedPref(prefs);

                    // Dismiss snoozed alarms after boot
                    AlarmStateManager.dismissSnoozedAlarms(context);

                    if (!prefs.getBoolean(PREF_VOLUME_DEF_DONE, false)) {
                        // Fix the default
                        LogUtils.v("AlarmInitReceiver - resetting volume button default");
+20 −2
Original line number Diff line number Diff line
@@ -692,6 +692,18 @@ public final class AlarmStateManager extends BroadcastReceiver {
        updateNextAlarm(context);
    }

    /**
     * Dismiss all snoozed alarms
     */
    public static void dismissSnoozedAlarms(Context context) {
        ContentResolver contentResolver = context.getContentResolver();
        for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
            if (instance.mAlarmState == AlarmInstance.SNOOZE_STATE) {
                AlarmStateManager.setDismissState(context, instance);
            }
        }
    }

    /**
     * Fix and update all alarm instance when a time change event occurs.
     *
@@ -703,8 +715,14 @@ public final class AlarmStateManager extends BroadcastReceiver {
        ContentResolver contentResolver = context.getContentResolver();
        for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
            final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
            // If the alarm is snoozed, keep the current next alarm time; do not set the time to
            // the next scheduled alarm.
            // This means that if the time has adjusted past the originally intended fire time,
            // we will schedule for the old time. AlarmManager will then fire the alarm immediately.
            if (instance.mAlarmState != AlarmInstance.SNOOZE_STATE) {
                instance.setAlarmTime(alarm.getNextAlarmTime(Calendar.getInstance()));
                AlarmInstance.updateInstance(contentResolver, instance);
            }
            AlarmStateManager.registerInstance(context, instance, false);
        }
        AlarmStateManager.updateNextAlarm(context);