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());
}
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;
}
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));
}
}
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();
}
}
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;
}
Aggregations