Make anomaly jobs persistent.

Before this cl, if user turn off device everday(i.e. OTA update), the
every day jobs may never have a chance to run.

This cl make the jobs persistent and don't reschedule it if we already
have one. In this way we can make sure the jobs roughly run everyday.

Bug: 77331929
Test: RunSettingsRoboTests
Change-Id: Ib497aca6b696afd9386515464845c5b0dd3c1207
This commit is contained in:
Lei Yu
2018-03-30 13:59:38 -07:00
parent d4482339d5
commit b3087c7f1f
4 changed files with 60 additions and 9 deletions

View File

@@ -55,9 +55,14 @@ public class AnomalyConfigJobService extends JobService {
new JobInfo.Builder(R.integer.job_anomaly_config_update, component)
.setPeriodic(CONFIG_UPDATE_FREQUENCY_MS)
.setRequiresDeviceIdle(true)
.setRequiresCharging(true);
.setRequiresCharging(true)
.setPersisted(true);
final JobInfo pending = jobScheduler.getPendingJob(R.integer.job_anomaly_config_update);
if (jobScheduler.schedule(jobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
// Don't schedule it if it already exists, to make sure it runs periodically even after
// reboot
if (pending == null && jobScheduler.schedule(jobBuilder.build())
!= JobScheduler.RESULT_SUCCESS) {
Log.i(TAG, "Anomaly config update job service schedule failed.");
}
}