diff options
3 files changed, 12 insertions, 18 deletions
diff --git a/core/java/android/service/notification/ScheduleCalendar.java b/core/java/android/service/notification/ScheduleCalendar.java index 6ed966e0bbbd..314c97db4e7b 100644 --- a/core/java/android/service/notification/ScheduleCalendar.java +++ b/core/java/android/service/notification/ScheduleCalendar.java @@ -57,25 +57,18 @@ public class ScheduleCalendar { } /** - * Sets next alarm of the schedule if the saved next alarm has passed or is further - * in the future than given nextAlarm + * Sets next alarm of the schedule * @param now current time in milliseconds * @param nextAlarm time of next alarm in milliseconds */ public void maybeSetNextAlarm(long now, long nextAlarm) { if (mSchedule != null && mSchedule.exitAtAlarm) { - // alarm canceled if (nextAlarm == 0) { + // alarm canceled mSchedule.nextAlarm = 0; - } - // only allow alarms in the future - if (nextAlarm > now) { - if (mSchedule.nextAlarm == 0 || mSchedule.nextAlarm < now) { - mSchedule.nextAlarm = nextAlarm; - } else { - // store earliest alarm - mSchedule.nextAlarm = Math.min(mSchedule.nextAlarm, nextAlarm); - } + } else if (nextAlarm > now) { + // only allow alarms in the future + mSchedule.nextAlarm = nextAlarm; } else if (mSchedule.nextAlarm < now) { if (DEBUG) { Log.d(TAG, "All alarms are in the past " + mSchedule.nextAlarm); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java index 3b1537639973..11162043bb27 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java @@ -316,9 +316,10 @@ public class ScheduleCalendarTest extends UiServiceTestCase { mScheduleCalendar.setSchedule(mScheduleInfo); mScheduleInfo.nextAlarm = 2000; + // next alarm updated to 3000 (alarm for 2000 was changed to 3000) mScheduleCalendar.maybeSetNextAlarm(1000, 3000); - assertEquals(2000, mScheduleInfo.nextAlarm); + assertEquals(3000, mScheduleInfo.nextAlarm); } @Test diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java index 5a527a219055..7446e9e0bb9f 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/ScheduleConditionProviderTest.java @@ -279,17 +279,17 @@ public class ScheduleConditionProviderTest extends UiServiceTestCase { conditionId, cal, now.getTimeInMillis(), now.getTimeInMillis() + 500); assertEquals(Condition.STATE_TRUE, condition.state); - // in schedule, update with later alarm time, should be in dnd + // in schedule, update with nextAlarm = later alarm time (1000), should be in dnd condition = mService.evaluateSubscriptionLocked( conditionId, cal, now.getTimeInMillis() + 250, now.getTimeInMillis() + 1000); assertEquals(Condition.STATE_TRUE, condition.state); - // at earliest alarm fire time, should exit dnd - assertTrue(cal.isInSchedule(now.getTimeInMillis() + 500)); + // at next alarm fire time (1000), should exit dnd + assertTrue(cal.isInSchedule(now.getTimeInMillis() + 1000)); assertTrue("" + info.nextAlarm + " " + now.getTimeInMillis(), - cal.shouldExitForAlarm(now.getTimeInMillis() + 500)); + cal.shouldExitForAlarm(now.getTimeInMillis() + 1000)); condition = mService.evaluateSubscriptionLocked( - conditionId, cal, now.getTimeInMillis() + 500, 0); + conditionId, cal, now.getTimeInMillis() + 1000, 0); assertEquals(Condition.STATE_FALSE, condition.state); } |