public static K9AlarmManager getAlarmManager(Context context) { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); DozeChecker dozeChecker = new DozeChecker(context); return new K9AlarmManager(alarmManager, dozeChecker); }
public void set(int type, long triggerAtMillis, PendingIntent operation) { if (dozeChecker.isDeviceIdleModeSupported() && dozeChecker.isAppWhitelisted()) { setAndAllowWhileIdle(type, triggerAtMillis, operation); } else { alarmManager.set(type, triggerAtMillis, operation); } }
@Test public void set_withDozeSupportAndNotWhiteListed_shouldCallSetOnAlarmManager() throws Exception { configureDozeSupport(true); alarmManager.set(TIMER_TYPE, TIMEOUT, PENDING_INTENT); verify(systemAlarmManager).set(TIMER_TYPE, TIMEOUT, PENDING_INTENT); }
@Test public void cancel_shouldCallCancelOnAlarmManager() throws Exception { configureDozeSupport(true); addAppToBatteryOptimizationWhitelist(); alarmManager.cancel(PENDING_INTENT); verify(systemAlarmManager).cancel(PENDING_INTENT); }
@Test public void set_withoutDozeSupport_shouldCallSetOnAlarmManager() throws Exception { configureDozeSupport(false); alarmManager.set(TIMER_TYPE, TIMEOUT, PENDING_INTENT); verify(systemAlarmManager).set(TIMER_TYPE, TIMEOUT, PENDING_INTENT); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); alarmManager = new K9AlarmManager(systemAlarmManager, dozeChecker); }
@Test public void set_withDozeSupportAndWhiteListed_shouldCallSetAndAllowWhileIdleOnAlarmManager() throws Exception { configureDozeSupport(true); addAppToBatteryOptimizationWhitelist(); alarmManager.set(TIMER_TYPE, TIMEOUT, PENDING_INTENT); verify(systemAlarmManager).setAndAllowWhileIdle(TIMER_TYPE, TIMEOUT, PENDING_INTENT); }