use of android.app.job.JobInfo in project android-priority-jobqueue by yigit.
the class FrameworkSchedulerTest method bundle.
@Test
public void bundle() throws Exception {
SchedulerConstraint constraint = mock(SchedulerConstraint.class);
when(constraint.getNetworkStatus()).thenReturn(NetworkUtil.METERED);
when(constraint.getUuid()).thenReturn("abc");
when(constraint.getDelayInMs()).thenReturn(345L);
when(constraint.getOverrideDeadlineInMs()).thenReturn(235L);
JobInfo jobInfo = schedule(constraint);
PersistableBundle extras = jobInfo.getExtras();
SchedulerConstraint fromBundle = FrameworkScheduler.fromBundle(extras);
assertThat(fromBundle.getNetworkStatus(), is(NetworkUtil.METERED));
assertThat(fromBundle.getUuid(), is("abc"));
assertThat(fromBundle.getDelayInMs(), is(345L));
assertThat(fromBundle.getOverrideDeadlineInMs(), is(235L));
}
use of android.app.job.JobInfo in project android_frameworks_base by AOSPA.
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 AOSPA.
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 AOSPA.
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 AOSPA.
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;
}
Aggregations