Search in sources :

Example 31 with JobInfo

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

the class JobSchedulerService method getRescheduleJobForFailure.

/**
     * Reschedules the given job based on the job's backoff policy. It doesn't make sense to
     * specify an override deadline on a failed job (the failed job will run even though it's not
     * ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any
     * ready job with {@link JobStatus#numFailures} > 0 will be executed.
     *
     * @param failureToReschedule Provided job status that we will reschedule.
     * @return A newly instantiated JobStatus with the same constraints as the last job except
     * with adjusted timing constraints.
     *
     * @see JobHandler#maybeQueueReadyJobsForExecutionLockedH
     */
private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) {
    final long elapsedNowMillis = SystemClock.elapsedRealtime();
    final JobInfo job = failureToReschedule.getJob();
    final long initialBackoffMillis = job.getInitialBackoffMillis();
    final int backoffAttempts = failureToReschedule.getNumFailures() + 1;
    long delayMillis;
    switch(job.getBackoffPolicy()) {
        case JobInfo.BACKOFF_POLICY_LINEAR:
            delayMillis = initialBackoffMillis * backoffAttempts;
            break;
        default:
            if (DEBUG) {
                Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential.");
            }
        case JobInfo.BACKOFF_POLICY_EXPONENTIAL:
            delayMillis = (long) Math.scalb(initialBackoffMillis, backoffAttempts - 1);
            break;
    }
    delayMillis = Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
    JobStatus newJob = new JobStatus(failureToReschedule, elapsedNowMillis + delayMillis, JobStatus.NO_LATEST_RUNTIME, backoffAttempts);
    for (int ic = 0; ic < mControllers.size(); ic++) {
        StateController controller = mControllers.get(ic);
        controller.rescheduleForFailure(newJob, failureToReschedule);
    }
    return newJob;
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) JobInfo(android.app.job.JobInfo) StateController(com.android.server.job.controllers.StateController)

Example 32 with JobInfo

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

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

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

the class JobSchedulerService method getRescheduleJobForFailure.

/**
     * Reschedules the given job based on the job's backoff policy. It doesn't make sense to
     * specify an override deadline on a failed job (the failed job will run even though it's not
     * ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any
     * ready job with {@link JobStatus#numFailures} > 0 will be executed.
     *
     * @param failureToReschedule Provided job status that we will reschedule.
     * @return A newly instantiated JobStatus with the same constraints as the last job except
     * with adjusted timing constraints.
     *
     * @see JobHandler#maybeQueueReadyJobsForExecutionLockedH
     */
private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) {
    final long elapsedNowMillis = SystemClock.elapsedRealtime();
    final JobInfo job = failureToReschedule.getJob();
    final long initialBackoffMillis = job.getInitialBackoffMillis();
    final int backoffAttempts = failureToReschedule.getNumFailures() + 1;
    long delayMillis;
    switch(job.getBackoffPolicy()) {
        case JobInfo.BACKOFF_POLICY_LINEAR:
            delayMillis = initialBackoffMillis * backoffAttempts;
            break;
        default:
            if (DEBUG) {
                Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential.");
            }
        case JobInfo.BACKOFF_POLICY_EXPONENTIAL:
            delayMillis = (long) Math.scalb(initialBackoffMillis, backoffAttempts - 1);
            break;
    }
    delayMillis = Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS);
    JobStatus newJob = new JobStatus(failureToReschedule, elapsedNowMillis + delayMillis, JobStatus.NO_LATEST_RUNTIME, backoffAttempts);
    for (int ic = 0; ic < mControllers.size(); ic++) {
        StateController controller = mControllers.get(ic);
        controller.rescheduleForFailure(newJob, failureToReschedule);
    }
    return newJob;
}
Also used : JobStatus(com.android.server.job.controllers.JobStatus) JobInfo(android.app.job.JobInfo) StateController(com.android.server.job.controllers.StateController)

Example 34 with JobInfo

use of android.app.job.JobInfo in project VirtualApp by asLody.

the class VJobSchedulerService method getAllPendingJobs.

@Override
public List<JobInfo> getAllPendingJobs() throws RemoteException {
    int vuid = VBinder.getCallingUid();
    List<JobInfo> jobs = mScheduler.getAllPendingJobs();
    synchronized (mJobStore) {
        Iterator<JobInfo> iterator = jobs.listIterator();
        while (iterator.hasNext()) {
            JobInfo job = iterator.next();
            if (!StubManifest.STUB_JOB.equals(job.getService().getClassName())) {
                // Schedule by Host, invisible in VA.
                iterator.remove();
                continue;
            }
            Map.Entry<JobId, JobConfig> jobEntry = findJobByVirtualJobId(job.getId());
            if (jobEntry == null) {
                iterator.remove();
                continue;
            }
            JobId jobId = jobEntry.getKey();
            JobConfig config = jobEntry.getValue();
            if (jobId.vuid != vuid) {
                iterator.remove();
                continue;
            }
            mirror.android.app.job.JobInfo.jobId.set(job, jobId.clientJobId);
            mirror.android.app.job.JobInfo.service.set(job, new ComponentName(jobId.packageName, config.serviceName));
        }
    }
    return jobs;
}
Also used : JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with JobInfo

use of android.app.job.JobInfo in project android-job by evernote.

the class JobProxy21 method plantPeriodic.

@Override
public void plantPeriodic(JobRequest request) {
    long intervalMs = request.getIntervalMs();
    long flexMs = request.getFlexMs();
    JobInfo jobInfo = createBuilderPeriodic(createBaseBuilder(request), intervalMs, flexMs).build();
    int scheduleResult = schedule(jobInfo);
    mCat.d("Schedule periodic jobInfo %s, %s, interval %s, flex %s", scheduleResultToString(scheduleResult), request, JobUtil.timeToString(intervalMs), JobUtil.timeToString(flexMs));
}
Also used : 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