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

Commit 8652e483 authored by Beverly's avatar Beverly
Browse files

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
parent 1ee4a4ec
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -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;
            }
            } else if (nextAlarm > now) {
                // 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 (mSchedule.nextAlarm < now) {
                if (DEBUG) {
                    Log.d(TAG, "All alarms are in the past " + mSchedule.nextAlarm);
+2 −1
Original line number Diff line number Diff line
@@ -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
+5 −5
Original line number Diff line number Diff line
@@ -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);
    }