use of android.app.job.JobScheduler 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.JobScheduler in project android_frameworks_base by ResurrectionRemix.
the class BackgroundDexOptService method schedule.
public static void schedule(Context context) {
JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
// Schedule a one-off job which scans installed packages and updates
// out-of-date oat files.
js.schedule(new JobInfo.Builder(JOB_POST_BOOT_UPDATE, sDexoptServiceName).setMinimumLatency(TimeUnit.MINUTES.toMillis(1)).setOverrideDeadline(TimeUnit.MINUTES.toMillis(1)).build());
// Schedule a daily job which scans installed packages and compiles
// those with fresh profiling data.
js.schedule(new JobInfo.Builder(JOB_IDLE_OPTIMIZE, sDexoptServiceName).setRequiresDeviceIdle(true).setRequiresCharging(true).setPeriodic(TimeUnit.DAYS.toMillis(1)).build());
if (DEBUG_DEXOPT) {
Log.i(TAG, "Jobs scheduled");
}
}
use of android.app.job.JobScheduler in project android_frameworks_base by ResurrectionRemix.
the class DiskStatsLoggingService method schedule.
/**
* Schedules a DiskStats collection task. This task only runs on device idle while charging
* once every 24 hours.
* @param context Context to use to get a job scheduler.
*/
public static void schedule(Context context) {
JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
js.schedule(new JobInfo.Builder(JOB_DISKSTATS_LOGGING, sDiskStatsLoggingService).setRequiresDeviceIdle(true).setRequiresCharging(true).setPeriodic(TimeUnit.DAYS.toMillis(1)).build());
}
use of android.app.job.JobScheduler in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class TestJobService method scheduleJob.
/** Send job to the JobScheduler. */
public void scheduleJob(JobInfo job) {
Log.d(TAG, "Scheduling job " + job);
JobScheduler tm = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
tm.schedule(job);
}
Aggregations