Search in sources :

Example 36 with JobScheduler

use of android.app.job.JobScheduler in project cw-omnibus by commonsguy.

the class DemoJobService method schedule.

static void schedule(Context ctxt) {
    ComponentName cn = new ComponentName(ctxt, DemoJobService.class);
    JobInfo.TriggerContentUri trigger = new JobInfo.TriggerContentUri(CONTENT_URI, JobInfo.TriggerContentUri.FLAG_NOTIFY_FOR_DESCENDANTS);
    JobInfo.Builder b = new JobInfo.Builder(ME_MYSELF_AND_I, cn).addTriggerContentUri(trigger);
    JobScheduler jobScheduler = (JobScheduler) ctxt.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    jobScheduler.schedule(b.build());
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo) ComponentName(android.content.ComponentName)

Example 37 with JobScheduler

use of android.app.job.JobScheduler in project muzei by romannurik.

the class TaskQueueService method maybeRetryDownloadDueToGainedConnectivity.

public static Intent maybeRetryDownloadDueToGainedConnectivity(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
        List<JobInfo> pendingJobs = jobScheduler.getAllPendingJobs();
        for (JobInfo pendingJob : pendingJobs) {
            if (pendingJob.getId() == LOAD_ARTWORK_JOB_ID) {
                return TaskQueueService.getDownloadCurrentArtworkIntent(context);
            }
        }
        return null;
    }
    return (PreferenceManager.getDefaultSharedPreferences(context).getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0) > 0) ? TaskQueueService.getDownloadCurrentArtworkIntent(context) : null;
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo)

Example 38 with JobScheduler

use of android.app.job.JobScheduler in project muzei by romannurik.

the class TaskQueueService method scheduleRetryArtworkDownload.

private void scheduleRetryArtworkDownload() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.schedule(new JobInfo.Builder(LOAD_ARTWORK_JOB_ID, new ComponentName(this, DownloadArtworkJobService.class)).setRequiredNetworkType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? JobInfo.NETWORK_TYPE_NOT_ROAMING : JobInfo.NETWORK_TYPE_ANY).build());
    } else {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        int reloadAttempt = sp.getInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0);
        sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, reloadAttempt + 1).commit();
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        long retryTimeMillis = SystemClock.elapsedRealtime() + (1 << reloadAttempt) * 2000;
        am.set(AlarmManager.ELAPSED_REALTIME, retryTimeMillis, TaskQueueService.getArtworkDownloadRetryPendingIntent(this));
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) JobInfo(android.app.job.JobInfo) SharedPreferences(android.content.SharedPreferences) AlarmManager(android.app.AlarmManager) ComponentName(android.content.ComponentName)

Example 39 with JobScheduler

use of android.app.job.JobScheduler in project muzei by romannurik.

the class TaskQueueService method cancelArtworkDownloadRetries.

private void cancelArtworkDownloadRetries() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
        jobScheduler.cancel(LOAD_ARTWORK_JOB_ID);
    } else {
        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        am.cancel(TaskQueueService.getArtworkDownloadRetryPendingIntent(this));
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        sp.edit().putInt(PREF_ARTWORK_DOWNLOAD_ATTEMPT, 0).commit();
    }
}
Also used : JobScheduler(android.app.job.JobScheduler) SharedPreferences(android.content.SharedPreferences) AlarmManager(android.app.AlarmManager)

Example 40 with JobScheduler

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

the class ProvisionObserver method isDeferredForProvision.

/**
     * Static utility function to schedule a job to execute upon the change of content URI
     * {@link android.provider.Settings.Global#DEVICE_PROVISIONED DEVICE_PROVISIONED}.
     * @param context The context used to retrieve the {@link ComponentName} and system services
     * @return true carrier actions are deferred due to phone provisioning process, false otherwise
     */
public static boolean isDeferredForProvision(Context context, Intent intent) {
    if (isProvisioned(context)) {
        return false;
    }
    int jobId;
    switch(intent.getAction()) {
        case TelephonyIntents.ACTION_CARRIER_SIGNAL_REDIRECTED:
            jobId = PROVISION_OBSERVER_REEVALUATION_JOB_ID;
            break;
        default:
            return false;
    }
    final JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
    final JobInfo job = new JobInfo.Builder(jobId, new ComponentName(context, ProvisionObserver.class)).addTriggerContentUri(new JobInfo.TriggerContentUri(Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), 0)).setTriggerContentUpdateDelay(CONTENT_UPDATE_DELAY_MS).setTriggerContentMaxDelay(CONTENT_MAX_DELAY_MS).build();
    jobScheduler.schedule(job);
    return true;
}
Also used : JobScheduler(android.app.job.JobScheduler) 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