use of android.app.job.JobScheduler 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());
}
}
use of android.app.job.JobScheduler 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);
}
}
use of android.app.job.JobScheduler in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
the class FullBackupJob method schedule.
public static void schedule(Context ctx, long minDelay) {
JobScheduler js = (JobScheduler) ctx.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, sIdleService).setRequiresDeviceIdle(true).setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED).setRequiresCharging(true);
if (minDelay > 0) {
builder.setMinimumLatency(minDelay);
}
js.schedule(builder.build());
}
use of android.app.job.JobScheduler in project android_frameworks_base by crdroidandroid.
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;
}
}
}
Aggregations