Search in sources :

Example 41 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

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 42 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

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 43 with JobInfo

use of android.app.job.JobInfo in project platform_frameworks_base by android.

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

Example 44 with JobInfo

use of android.app.job.JobInfo in project android_frameworks_base by DirtyUnicorns.

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

Example 45 with JobInfo

use of android.app.job.JobInfo in project android_frameworks_base by DirtyUnicorns.

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

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