use of android.app.job.JobInfo in project android_frameworks_base by crdroidandroid.
the class PrioritySchedulingTest method testHigherPriorityJobNotPreempted.
public void testHigherPriorityJobNotPreempted() throws Exception {
JobInfo job1 = new JobInfo.Builder(111, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job2 = new JobInfo.Builder(222, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job3 = new JobInfo.Builder(333, kJobServiceComponent).setPriority(2).setOverrideDeadline(7000L).build();
JobInfo job4 = new JobInfo.Builder(444, kJobServiceComponent).setPriority(1).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 higher priority jobs
Thread.sleep(10000);
Event job4Execution = new Event(TestEnvironment.EVENT_START_JOB, 444);
boolean wasJob4Executed = kTestEnvironment.getExecutedEvents().contains(job4Execution);
assertFalse("Higher priority job was preempted.", wasJob4Executed);
}
use of android.app.job.JobInfo in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
the class NekoService method registerJobIfNeeded.
public static void registerJobIfNeeded(Context context, long intervalMinutes) {
JobScheduler jss = context.getSystemService(JobScheduler.class);
JobInfo info = jss.getPendingJob(JOB_ID);
if (info == null) {
registerJob(context, intervalMinutes);
}
}
use of android.app.job.JobInfo in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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();
}
Aggregations