use of android.app.job.JobInfo in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class NekoService method registerJob.
public static void registerJob(Context context, long intervalMinutes) {
JobScheduler jss = context.getSystemService(JobScheduler.class);
jss.cancel(JOB_ID);
long interval = intervalMinutes * MINUTES;
long jitter = (long) (INTERVAL_JITTER_FRAC * interval);
interval += (long) (Math.random() * (2 * jitter)) - jitter;
final JobInfo jobInfo = new JobInfo.Builder(JOB_ID, new ComponentName(context, NekoService.class)).setPeriodic(interval, INTERVAL_FLEX).build();
Log.v(TAG, "A cat will visit in " + interval + "ms: " + String.valueOf(jobInfo));
jss.schedule(jobInfo);
if (NekoLand.DEBUG_NOTIFICATIONS) {
NotificationManager noman = context.getSystemService(NotificationManager.class);
noman.notify(500, new Notification.Builder(context).setSmallIcon(R.drawable.stat_icon).setContentTitle(String.format("Job scheduled in %d min", (interval / MINUTES))).setContentText(String.valueOf(jobInfo)).setPriority(Notification.PRIORITY_MIN).setCategory(Notification.CATEGORY_SERVICE).setShowWhen(true).build());
}
}
use of android.app.job.JobInfo in project android_frameworks_base by DirtyUnicorns.
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 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 crdroidandroid.
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