Loading core/java/android/service/notification/ScheduleCalendar.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading Loading
core/java/android/service/notification/ScheduleCalendar.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -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) { Loading
services/tests/uiservicestests/src/com/android/server/notification/ScheduleCalendarTest.java +25 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading