Search in sources :

Example 31 with JobScheduler

use of android.app.job.JobScheduler in project android_frameworks_base by DirtyUnicorns.

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());
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo)

Example 32 with JobScheduler

use of android.app.job.JobScheduler in project android_frameworks_base by DirtyUnicorns.

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;
        }
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) Random(java.util.Random) JobInfo(android.app.job.JobInfo)

Example 33 with JobScheduler

use of android.app.job.JobScheduler in project android_frameworks_base by DirtyUnicorns.

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;
    }
}
Also used : JobScheduler(android.app.job.JobScheduler)

Example 34 with JobScheduler

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

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);
}
Also used : JobScheduler(android.app.job.JobScheduler)

Example 35 with JobScheduler

use of android.app.job.JobScheduler 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)

Aggregations

JobScheduler (android.app.job.JobScheduler)63 JobInfo (android.app.job.JobInfo)42 ComponentName (android.content.ComponentName)13 NotificationManager (android.app.NotificationManager)5 Calendar (java.util.Calendar)5 Random (java.util.Random)5 AlarmManager (android.app.AlarmManager)2 SharedPreferences (android.content.SharedPreferences)2 Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 SuppressLint (android.annotation.SuppressLint)1 ConnectivityManager (android.net.ConnectivityManager)1 Bundle (android.os.Bundle)1 PersistableBundle (android.os.PersistableBundle)1 UiThread (android.support.annotation.UiThread)1 Test (org.junit.Test)1