Next alarm is definitive info from clock

Even if the next alarm is further in the future than the alarm on the
ScheduleCalendar, update the next alarm b/c this means that our current
nextAlarm is old info

Test: atest ScheduleCalendarTest
Test: manual
  1. enable DND that ends at alarm
  2. create an alarm that goes off in 5 min
  3. change alarm to go off in 11 min
  4. in the 6 minute difference, notice that DND is still on and didn't
  end earlier than execpted.
Fixes: 181665547
Change-Id: Ieb2fc7269c4a9b1bc109941d16ce191012d338c4
This commit is contained in:
Beverly
2021-03-18 10:28:45 -04:00
parent 1ee4a4ecba
commit 8652e483b0
3 changed files with 12 additions and 18 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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);
}