Cancel data loading when hourly job happens in the first 40 minutes

after booting in AOSP.

Test: make RunSettingsRoboTests + manual
Bug: 257384343
Change-Id: I437b68719ff5ece73fa33b74cb144f4262528e8c
This commit is contained in:
Kuan Wang
2022-12-08 10:41:12 +08:00
parent 269b14fb45
commit cf7e1141df
7 changed files with 51 additions and 36 deletions

View File

@@ -124,28 +124,6 @@ public final class BootBroadcastReceiverTest {
assertThat(mShadowAlarmManager.peekNextScheduledAlarm()).isNull();
}
@Test
public void onReceive_containsExpiredData_clearsExpiredDataFromDatabase()
throws InterruptedException {
insertExpiredData(/*shiftDay=*/ DatabaseUtils.DATA_RETENTION_INTERVAL_DAY);
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
TimeUnit.MILLISECONDS.sleep(100);
assertThat(mDao.getAllAfter(0)).hasSize(1);
}
@Test
public void onReceive_withoutExpiredData_notClearsExpiredDataFromDatabase()
throws InterruptedException {
insertExpiredData(/*shiftDay=*/ DatabaseUtils.DATA_RETENTION_INTERVAL_DAY - 1);
mReceiver.onReceive(mContext, new Intent(Intent.ACTION_BOOT_COMPLETED));
TimeUnit.MILLISECONDS.sleep(100);
assertThat(mDao.getAllAfter(0)).hasSize(3);
}
@Test
public void onReceive_withTimeChangedIntent_clearsAllDataAndRefreshesJob()
throws InterruptedException {

View File

@@ -57,7 +57,7 @@ public final class PeriodicJobManagerTest {
@Test
public void refreshJob_refreshesAlarmJob() {
mPeriodicJobManager.refreshJob();
mPeriodicJobManager.refreshJob(/*fromBoot=*/ false);
final ShadowAlarmManager.ScheduledAlarm alarm =
mShadowAlarmManager.peekNextScheduledAlarm();
@@ -76,7 +76,7 @@ public final class PeriodicJobManagerTest {
FakeClock fakeClock = new FakeClock();
fakeClock.setCurrentTime(currentTimeDuration);
assertThat(PeriodicJobManager.getTriggerAtMillis(fakeClock))
assertThat(PeriodicJobManager.getTriggerAtMillis(mContext, fakeClock, /*fromBoot=*/ false))
.isEqualTo(currentTimeDuration.plusMinutes(timeSlotUnit).toMillis());
}
@@ -89,7 +89,7 @@ public final class PeriodicJobManagerTest {
fakeClock.setCurrentTime(
currentTimeDuration.plusMinutes(1L).plusMillis(51L));
assertThat(PeriodicJobManager.getTriggerAtMillis(fakeClock))
assertThat(PeriodicJobManager.getTriggerAtMillis(mContext, fakeClock, /*fromBoot=*/ true))
.isEqualTo(currentTimeDuration.plusMinutes(timeSlotUnit).toMillis());
}
}