Remove unnecessary check canScheduleExactAlarms() as Settings always
has the permission. Test: make RunSettingsRoboTests Bug: 256123455 Change-Id: I5089494164581465da9533671fc414c7bee1196f
This commit is contained in:
@@ -73,10 +73,6 @@ public final class PeriodicJobManager {
|
|||||||
// Cancels the previous alert job and schedules the next one.
|
// Cancels the previous alert job and schedules the next one.
|
||||||
final PendingIntent pendingIntent = getPendingIntent();
|
final PendingIntent pendingIntent = getPendingIntent();
|
||||||
cancelJob(pendingIntent);
|
cancelJob(pendingIntent);
|
||||||
if (!canScheduleExactAlarms()) {
|
|
||||||
Log.w(TAG, "cannot schedule exact alarm job");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Uses UTC time to avoid scheduler is impacted by different timezone.
|
// Uses UTC time to avoid scheduler is impacted by different timezone.
|
||||||
final long triggerAtMillis = getTriggerAtMillis(Clock.systemUTC());
|
final long triggerAtMillis = getTriggerAtMillis(Clock.systemUTC());
|
||||||
mAlarmManager.setExactAndAllowWhileIdle(
|
mAlarmManager.setExactAndAllowWhileIdle(
|
||||||
@@ -111,13 +107,4 @@ public final class PeriodicJobManager {
|
|||||||
broadcastIntent,
|
broadcastIntent,
|
||||||
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canScheduleExactAlarms() {
|
|
||||||
return canScheduleExactAlarms(mAlarmManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Whether we can schedule exact alarm or not? */
|
|
||||||
public static boolean canScheduleExactAlarms(AlarmManager alarmManager) {
|
|
||||||
return alarmManager.canScheduleExactAlarms();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -58,7 +58,6 @@ public final class BootBroadcastReceiverTest {
|
|||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
||||||
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
||||||
ShadowAlarmManager.setCanScheduleExactAlarms(true);
|
|
||||||
mReceiver = new BootBroadcastReceiver();
|
mReceiver = new BootBroadcastReceiver();
|
||||||
|
|
||||||
// Inserts fake data into database for testing.
|
// Inserts fake data into database for testing.
|
||||||
|
@@ -48,7 +48,6 @@ public final class PeriodicJobManagerTest {
|
|||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
||||||
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
||||||
ShadowAlarmManager.setCanScheduleExactAlarms(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -68,15 +67,6 @@ public final class PeriodicJobManagerTest {
|
|||||||
assertThat(alarm.operation).isNotNull();
|
assertThat(alarm.operation).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void refreshJob_withoutPermission_notRefreshesAlarmJob() {
|
|
||||||
ShadowAlarmManager.setCanScheduleExactAlarms(false);
|
|
||||||
|
|
||||||
mPeriodicJobManager.refreshJob();
|
|
||||||
|
|
||||||
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTriggerAtMillis_withoutOffset_returnsExpectedResult() {
|
public void getTriggerAtMillis_withoutOffset_returnsExpectedResult() {
|
||||||
long timeSlotUnit = PeriodicJobManager.DATA_FETCH_INTERVAL_MINUTE;
|
long timeSlotUnit = PeriodicJobManager.DATA_FETCH_INTERVAL_MINUTE;
|
||||||
|
@@ -58,7 +58,6 @@ public final class PeriodicJobReceiverTest {
|
|||||||
mContext = ApplicationProvider.getApplicationContext();
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
mPeriodicJobManager = PeriodicJobManager.getInstance(mContext);
|
||||||
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
mShadowAlarmManager = shadowOf(mContext.getSystemService(AlarmManager.class));
|
||||||
ShadowAlarmManager.setCanScheduleExactAlarms(true);
|
|
||||||
mReceiver = new PeriodicJobReceiver();
|
mReceiver = new PeriodicJobReceiver();
|
||||||
|
|
||||||
// Inserts fake data into database for testing.
|
// Inserts fake data into database for testing.
|
||||||
|
Reference in New Issue
Block a user