use of android.app.job.JobScheduler in project android-priority-jobqueue by yigit.
the class FrameworkScheduler method request.
@SuppressLint("SwitchIntDef")
@Override
public void request(SchedulerConstraint constraint) {
JobScheduler jobScheduler = getJobScheduler();
final int id = createId();
JobInfo.Builder builder = new JobInfo.Builder(id, getComponentName()).setExtras(toPersistentBundle(constraint)).setPersisted(true);
switch(constraint.getNetworkStatus()) {
case NetworkUtil.UNMETERED:
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED);
break;
case NetworkUtil.METERED:
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
break;
default:
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_NONE);
builder.setRequiresDeviceIdle(true);
break;
}
if (constraint.getDelayInMs() > 0) {
builder.setMinimumLatency(constraint.getDelayInMs());
}
if (constraint.getOverrideDeadlineInMs() != null) {
builder.setOverrideDeadline(constraint.getOverrideDeadlineInMs());
}
int scheduled = jobScheduler.schedule(builder.build());
JqLog.d("[FW Scheduler] scheduled a framework job. Success? %s id: %d" + " created id: %d", scheduled > 0, scheduled, id);
}
use of android.app.job.JobScheduler in project android_frameworks_base by AOSPA.
the class KeyValueBackupJob method cancel.
public static void cancel(Context ctx) {
synchronized (KeyValueBackupJob.class) {
JobScheduler js = (JobScheduler) ctx.getSystemService(Context.JOB_SCHEDULER_SERVICE);
js.cancel(JOB_ID);
sNextScheduled = 0;
sScheduled = false;
}
}
use of android.app.job.JobScheduler in project android_frameworks_base by AOSPA.
the class KeyValueBackupJob method schedule.
public static void schedule(Context ctx, long delay) {
synchronized (KeyValueBackupJob.class) {
if (!sScheduled) {
if (delay <= 0) {
delay = BATCH_INTERVAL + new Random().nextInt(FUZZ_MILLIS);
}
if (BackupManagerService.DEBUG_SCHEDULING) {
Slog.v(TAG, "Scheduling k/v pass in " + (delay / 1000 / 60) + " minutes");
}
JobScheduler js = (JobScheduler) ctx.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, sKeyValueJobService).setMinimumLatency(delay).setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).setRequiresCharging(true).setOverrideDeadline(MAX_DEFERRAL);
js.schedule(builder.build());
sNextScheduled = System.currentTimeMillis() + delay;
sScheduled = true;
}
}
}
use of android.app.job.JobScheduler in project android_frameworks_base by AOSPA.
the class MountServiceIdler method scheduleIdlePass.
/**
* Schedule the idle job that will ping the mount service
*/
public static void scheduleIdlePass(Context context) {
JobScheduler tm = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
Calendar calendar = tomorrowMidnight();
final long timeToMidnight = calendar.getTimeInMillis() - System.currentTimeMillis();
JobInfo.Builder builder = new JobInfo.Builder(MOUNT_JOB_ID, sIdleService);
builder.setRequiresDeviceIdle(true);
builder.setRequiresCharging(true);
builder.setMinimumLatency(timeToMidnight);
tm.schedule(builder.build());
}
use of android.app.job.JobScheduler 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);
}
}
Aggregations