use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class JobSchedulerService method getPendingJobs.
public List<JobInfo> getPendingJobs(int uid) {
synchronized (mLock) {
List<JobStatus> jobs = mJobs.getJobsByUid(uid);
ArrayList<JobInfo> outList = new ArrayList<JobInfo>(jobs.size());
for (int i = jobs.size() - 1; i >= 0; i--) {
JobStatus job = jobs.get(i);
outList.add(job.getJob());
}
return outList;
}
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class SyncManager method verifyJobScheduler.
private synchronized void verifyJobScheduler() {
if (mJobScheduler != null) {
return;
}
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.d(TAG, "initializing JobScheduler object.");
}
mJobScheduler = (JobScheduler) mContext.getSystemService(Context.JOB_SCHEDULER_SERVICE);
mJobSchedulerInternal = LocalServices.getService(JobSchedulerInternal.class);
// Get all persisted syncs from JobScheduler
List<JobInfo> pendingJobs = mJobScheduler.getAllPendingJobs();
for (JobInfo job : pendingJobs) {
SyncOperation op = SyncOperation.maybeCreateFromJobExtras(job.getExtras());
if (op != null) {
if (!op.isPeriodic) {
// Set the pending status of this EndPoint to true. Pending icon is
// shown on the settings activity.
mSyncStorageEngine.markPending(op.target, true);
}
}
}
cleanupJobs();
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class JobStoreTest method testWritingTwoFilesToDisk.
public void testWritingTwoFilesToDisk() throws Exception {
final JobInfo task1 = new Builder(8, mComponent).setRequiresDeviceIdle(true).setPeriodic(10000L).setRequiresCharging(true).setPersisted(true).build();
final JobInfo task2 = new Builder(12, mComponent).setMinimumLatency(5000L).setBackoffCriteria(15000L, JobInfo.BACKOFF_POLICY_LINEAR).setOverrideDeadline(30000L).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED).setPersisted(true).build();
final JobStatus taskStatus1 = JobStatus.createFromJobInfo(task1, SOME_UID, null, -1, null);
final JobStatus taskStatus2 = JobStatus.createFromJobInfo(task2, SOME_UID, null, -1, null);
mTaskStoreUnderTest.add(taskStatus1);
mTaskStoreUnderTest.add(taskStatus2);
Thread.sleep(IO_WAIT);
final JobSet jobStatusSet = new JobSet();
mTaskStoreUnderTest.readJobMapFromDisk(jobStatusSet);
assertEquals("Incorrect # of persisted tasks.", 2, jobStatusSet.size());
Iterator<JobStatus> it = jobStatusSet.getAllJobs().iterator();
JobStatus loaded1 = it.next();
JobStatus loaded2 = it.next();
// Reverse them so we know which comparison to make.
if (loaded1.getJobId() != 8) {
JobStatus tmp = loaded1;
loaded1 = loaded2;
loaded2 = tmp;
}
assertTasksEqual(task1, loaded1.getJob());
assertTasksEqual(task2, loaded2.getJob());
assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(taskStatus1));
assertTrue("JobStore#contains invalid.", mTaskStoreUnderTest.containsJob(taskStatus2));
// Check that the loaded task has the correct runtimes.
compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", taskStatus1.getEarliestRunTime(), loaded1.getEarliestRunTime());
compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", taskStatus1.getLatestRunTimeElapsed(), loaded1.getLatestRunTimeElapsed());
compareTimestampsSubjectToIoLatency("Early run-times not the same after read.", taskStatus2.getEarliestRunTime(), loaded2.getEarliestRunTime());
compareTimestampsSubjectToIoLatency("Late run-times not the same after read.", taskStatus2.getLatestRunTimeElapsed(), loaded2.getLatestRunTimeElapsed());
}
use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
the class PrioritySchedulingTest method testLowerPriorityJobPreempted.
public void testLowerPriorityJobPreempted() throws Exception {
JobInfo job1 = new JobInfo.Builder(111, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job2 = new JobInfo.Builder(222, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job3 = new JobInfo.Builder(333, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job4 = new JobInfo.Builder(444, kJobServiceComponent).setPriority(2).setMinimumLatency(2000L).setOverrideDeadline(7000L).build();
mJobScheduler.schedule(job1);
mJobScheduler.schedule(job2);
mJobScheduler.schedule(job3);
mJobScheduler.schedule(job4);
// Wait for job 4 to preempt one of the lower priority jobs
Thread.sleep(10000);
Event job4Execution = new Event(TestEnvironment.EVENT_START_JOB, 444);
ArrayList<Event> executedEvents = kTestEnvironment.getExecutedEvents();
boolean wasJob4Executed = executedEvents.contains(job4Execution);
boolean wasSomeJobPreempted = false;
for (Event event : executedEvents) {
if (event.event == TestEnvironment.EVENT_PREEMPT_JOB) {
wasSomeJobPreempted = true;
break;
}
}
assertTrue("No job was preempted.", wasSomeJobPreempted);
assertTrue("Lower priority jobs were not preempted.", wasJob4Executed);
}
use of android.app.job.JobInfo in project android_frameworks_base by crdroidandroid.
the class PrioritySchedulingTest method testLowerPriorityJobPreempted.
public void testLowerPriorityJobPreempted() throws Exception {
JobInfo job1 = new JobInfo.Builder(111, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job2 = new JobInfo.Builder(222, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job3 = new JobInfo.Builder(333, kJobServiceComponent).setPriority(1).setOverrideDeadline(7000L).build();
JobInfo job4 = new JobInfo.Builder(444, kJobServiceComponent).setPriority(2).setMinimumLatency(2000L).setOverrideDeadline(7000L).build();
mJobScheduler.schedule(job1);
mJobScheduler.schedule(job2);
mJobScheduler.schedule(job3);
mJobScheduler.schedule(job4);
// Wait for job 4 to preempt one of the lower priority jobs
Thread.sleep(10000);
Event job4Execution = new Event(TestEnvironment.EVENT_START_JOB, 444);
ArrayList<Event> executedEvents = kTestEnvironment.getExecutedEvents();
boolean wasJob4Executed = executedEvents.contains(job4Execution);
boolean wasSomeJobPreempted = false;
for (Event event : executedEvents) {
if (event.event == TestEnvironment.EVENT_PREEMPT_JOB) {
wasSomeJobPreempted = true;
break;
}
}
assertTrue("No job was preempted.", wasSomeJobPreempted);
assertTrue("Lower priority jobs were not preempted.", wasJob4Executed);
}
Aggregations