Search in sources :

Example 61 with JobInfo

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);
}
Also used : JobInfo(android.app.job.JobInfo) Event(com.android.server.job.MockPriorityJobService.TestEnvironment.Event)

Example 62 with JobInfo

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());
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) NotificationManager(android.app.NotificationManager) JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName)

Example 63 with JobInfo

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);
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo)

Example 64 with JobInfo

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;
}
Also used : JobInfo(android.app.job.JobInfo) ArrayList(java.util.ArrayList)

Example 65 with JobInfo

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());
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) PersistableBundle(android.os.PersistableBundle) JobInfo(android.app.job.JobInfo) JobSet(com.android.server.job.JobStore.JobSet) Builder(android.app.job.JobInfo.Builder) Builder(android.app.job.JobInfo.Builder)

Aggregations

JobInfo (android.app.job.JobInfo)66 JobStatus (com.android.server.job.controllers.JobStatus)22 JobScheduler (android.app.job.JobScheduler)13 Builder (android.app.job.JobInfo.Builder)12 JobSet (com.android.server.job.JobStore.JobSet)12 ArrayList (java.util.ArrayList)10 ComponentName (android.content.ComponentName)8 Event (com.android.server.job.MockPriorityJobService.TestEnvironment.Event)8 Test (org.junit.Test)7 PersistableBundle (android.os.PersistableBundle)6 NotificationManager (android.app.NotificationManager)5 JobSchedulerInternal (com.android.server.job.JobSchedulerInternal)5 StateController (com.android.server.job.controllers.StateController)5 JobParameters (android.app.job.JobParameters)1 ConnectivityManager (android.net.ConnectivityManager)1 NonNull (android.support.annotation.NonNull)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1