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

Commit a57542cf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Next alarm is definitive info from clock" into sc-dev am: cfd9f239

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13919047

Change-Id: I0c48fcffbdaf1f7a1bd50449f597fa2e41987a17
parents 7dd8586d cfd9f239
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);
    }