Skip to content

Commit

Permalink
Fix rescheduling of alarms that are snoozed
Browse files Browse the repository at this point in the history
When AlarmInitReceiver recieves android.intent.action.TIME_SET, a
call is made to AlarmStateManager.fixAlarmInstances() which will
update all alarm instances based on the newly set time.  This updates
the AlarmInstance based on the Alarm time and not the current time
for the given AlarmInstance.  This causes snoozed alarms to be
scheduled the next time the Alarm is suppose to fire off, if the
alarm a repeating alarm.  This patch fixes this behavior by passing
in a Calendar instance based on the AlarmInstance's time.

Steps to repro:
1) Set an alarm for 1 minute from current time
2) Snooze alarm when it goes off
3) Go to Settings -> Date & Time and set the time to 2 minutes ahead
4) The snoozed alarm should be rescheduled to the next day the alarm
   would fire.

Change-Id: Id7e2d5c7b5d2b9d3b92eb51a2e14d70639d56761
(cherry picked from commit d815eef)
  • Loading branch information
0xD34D committed Aug 5, 2015
1 parent 657a2d2 commit 49287fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/com/android/deskclock/alarms/AlarmStateManager.java
Expand Up @@ -679,7 +679,8 @@ public static void fixAlarmInstances(Context context) {
ContentResolver contentResolver = context.getContentResolver();
for (AlarmInstance instance : AlarmInstance.getInstances(contentResolver, null)) {
final Alarm alarm = Alarm.getAlarm(contentResolver, instance.mAlarmId);
instance.setAlarmTime(alarm.getNextAlarmTime(Calendar.getInstance()));
instance.setAlarmTime(alarm.getNextAlarmTime(Calendar.getInstance(),
instance.mHour, instance.mMinute));
AlarmInstance.updateInstance(contentResolver, instance);
AlarmStateManager.registerInstance(context, instance, false);
}
Expand Down
4 changes: 4 additions & 0 deletions src/com/android/deskclock/provider/Alarm.java
Expand Up @@ -337,6 +337,10 @@ public AlarmInstance createInstanceAfter(Calendar time) {
}

public Calendar getNextAlarmTime(Calendar currentTime) {
return getNextAlarmTime(currentTime, hour, minutes);
}

public Calendar getNextAlarmTime(Calendar currentTime, int hour, int minutes) {
Calendar nextInstanceTime = Calendar.getInstance();
nextInstanceTime.set(Calendar.YEAR, currentTime.get(Calendar.YEAR));
nextInstanceTime.set(Calendar.MONTH, currentTime.get(Calendar.MONTH));
Expand Down

0 comments on commit 49287fc

Please sign in to comment.