use of android.app.job.JobInfo in project android_frameworks_base by AOSPA.
the class SyncManager method getAllPendingSyncs.
private List<SyncOperation> getAllPendingSyncs() {
verifyJobScheduler();
List<JobInfo> pendingJobs = mJobSchedulerInternal.getSystemScheduledPendingJobs();
List<SyncOperation> pendingSyncs = new ArrayList<SyncOperation>(pendingJobs.size());
for (JobInfo job : pendingJobs) {
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
if (op != null) {
pendingSyncs.add(op);
}
}
return pendingSyncs;
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class SyncManager method getAllPendingSyncs.
private List<SyncOperation> getAllPendingSyncs() {
verifyJobScheduler();
List<JobInfo> pendingJobs = mJobSchedulerInternal.getSystemScheduledPendingJobs();
List<SyncOperation> pendingSyncs = new ArrayList<SyncOperation>(pendingJobs.size());
for (JobInfo job : pendingJobs) {
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
if (op != null) {
pendingSyncs.add(op);
}
}
return pendingSyncs;
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class JobSchedulerService method getRescheduleJobForFailure.
/**
* Reschedules the given job based on the job's backoff policy. It doesn't make sense to
* specify an override deadline on a failed job (the failed job will run even though it's not
* ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any
* ready job with {@link JobStatus#numFailures} > 0 will be executed.
*
* @param failureToReschedule Provided job status that we will reschedule.
* @return A newly instantiated JobStatus with the same constraints as the last job except
* with adjusted timing constraints.
*
* @see JobHandler#maybeQueueReadyJobsForExecutionLockedH
*/
private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) {
final long elapsedNowMillis = SystemClock.elapsedRealtime();
final JobInfo job = failureToReschedule.getJob();
final long initialBackoffMillis = job.getInitialBackoffMillis();
final int backoffAttempts = failureToReschedule.getNumFailures() + 1;
long delayMillis;
switch(job.getBackoffPolicy()) {
case JobInfo.BACKOFF_POLICY_LINEAR:
delayMillis = initialBackoffMillis * backoffAttempts;
break;
default:
if (DEBUG) {
Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential.");
}
case JobInfo.BACKOFF_POLICY_EXPONENTIAL:
delayMillis = (long) Math.scalb(initialBackoffMillis, backoffAttempts - 1);
break;
}
delayMillis = Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
JobStatus newJob = new JobStatus(failureToReschedule, elapsedNowMillis + delayMillis, JobStatus.NO_LATEST_RUNTIME, backoffAttempts);
for (int ic = 0; ic < mControllers.size(); ic++) {
StateController controller = mControllers.get(ic);
controller.rescheduleForFailure(newJob, failureToReschedule);
}
return newJob;
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class JobStoreTest method testMaybeWriteStatusToDisk.
public void testMaybeWriteStatusToDisk() throws Exception {
int taskId = 5;
// 20s
long runByMillis = 20000L;
// 2s
long runFromMillis = 2000L;
// 10s
long initialBackoff = 10000L;
final JobInfo task = new Builder(taskId, mComponent).setRequiresCharging(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).setBackoffCriteria(initialBackoff, JobInfo.BACKOFF_POLICY_EXPONENTIAL).setOverrideDeadline(runByMillis).setMinimumLatency(runFromMillis).setPersisted(true).build();
final JobStatus ts = JobStatus.createFromJobInfo(task, SOME_UID, null, -1, null);
mTaskStoreUnderTest.add(ts);
Thread.sleep(IO_WAIT);
// Manually load tasks from xml file.
final JobSet jobStatusSet = new JobSet();
mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
assertEquals("Didn't get expected number of persisted tasks.", 1, jobStatusSet.size());
final JobStatus loadedTaskStatus = jobStatusSet.getAllJobs().get(0);
assertTasksEqual(task, loadedTaskStatus.getJob());
assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(ts));
assertEquals("Different uids.", SOME_UID, loadedTaskStatus.getUid());
compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", ts.getEarliestRunTime(), loadedTaskStatus.getEarliestRunTime());
compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", ts.getLatestRunTimeElapsed(), loadedTaskStatus.getLatestRunTimeElapsed());
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class JobStoreTest method testWritingTaskWithExtras.
public void testWritingTaskWithExtras() throws Exception {
JobInfo.Builder b = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true);
PersistableBundle extras = new PersistableBundle();
extras.putDouble("hello", 3.2);
extras.putString("hi", "there");
extras.putInt("into", 3);
b.setExtras(extras);
final JobInfo task = b.build();
JobStatus taskStatus = JobStatus.createFromJobInfo(task, SOME_UID, null, -1, null);
mTaskStoreUnderTest.add(taskStatus);
Thread.sleep(IO_WAIT);
final JobSet jobStatusSet = new JobSet();
mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
assertEquals("Incorrect # of persisted tasks.", 1, jobStatusSet.size());
JobStatus loaded = jobStatusSet.getAllJobs().iterator().next();
assertTasksEqual(task, loaded.getJob());
}
Aggregations