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

Commit 369dd425 authored by Beverly's avatar Beverly
Browse files

Don't exit dnd rule for old alarms

Bug: 77209521
Test: atest ScheduleCalendarTest
Change-Id: I394a6a74872f76f90b75238593197bb6c50531ef
parent f0e720ec
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -144,7 +144,8 @@ public class ScheduleCalendar {
        }
        }
        return mSchedule.exitAtAlarm
        return mSchedule.exitAtAlarm
                && mSchedule.nextAlarm != 0
                && mSchedule.nextAlarm != 0
                && time >= mSchedule.nextAlarm;
                && time >= mSchedule.nextAlarm
                && isInSchedule(mSchedule.nextAlarm);
    }
    }


    private boolean isInSchedule(int daysOffset, long time, long start, long end) {
    private boolean isInSchedule(int daysOffset, long time, long start, long end) {
+25 −0
Original line number Original line Diff line number Diff line
@@ -205,6 +205,31 @@ public class ScheduleCalendarTest extends UiServiceTestCase {
        assertTrue(mScheduleCalendar.shouldExitForAlarm(1000));
        assertTrue(mScheduleCalendar.shouldExitForAlarm(1000));
    }
    }


    @Test
    public void testShouldExitForAlarm_oldAlarm() {
        // Cal: today 2:15pm
        Calendar cal = new GregorianCalendar();
        cal.set(Calendar.HOUR_OF_DAY, 14);
        cal.set(Calendar.MINUTE, 15);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);

        // ScheduleInfo: today 12:16pm  - today 3:15pm
        mScheduleInfo.days = new int[] {getTodayDay()};
        mScheduleInfo.startHour = 12;
        mScheduleInfo.endHour = 3;
        mScheduleInfo.startMinute = 16;
        mScheduleInfo.endMinute = 15;
        mScheduleInfo.exitAtAlarm = true;
        mScheduleInfo.nextAlarm = 1000; // very old alarm

        mScheduleCalendar.setSchedule(mScheduleInfo);
        assertTrue(mScheduleCalendar.isInSchedule(cal.getTimeInMillis()));

        // don't exit for an alarm if it's an old alarm
        assertFalse(mScheduleCalendar.shouldExitForAlarm(1000));
    }

    @Test
    @Test
    public void testMaybeSetNextAlarm_settingOff() {
    public void testMaybeSetNextAlarm_settingOff() {
        mScheduleInfo.exitAtAlarm = false;
        mScheduleInfo.exitAtAlarm = false;