Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.offlinepages; | |
| 6 | |
| 7 import android.annotation.TargetApi; | |
| 8 import android.app.job.JobInfo; | |
| 9 import android.app.job.JobScheduler; | |
| 10 import android.content.ComponentName; | |
| 11 import android.content.Context; | |
| 12 import android.os.Build; | |
| 13 import android.os.PersistableBundle; | |
| 14 | |
| 15 /** | |
| 16 * The background job scheduler class used for scheduling tasks using JobSchedul er. | |
| 17 */ | |
| 18 @TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) | |
| 19 public class BackgroundJobScheduler extends BackgroundScheduler { | |
| 20 public static final int JOB_ID = 774322033; | |
| 21 | |
| 22 public BackgroundJobScheduler(Context context) { | |
| 23 super(context); | |
| 24 } | |
| 25 | |
| 26 @Override | |
| 27 public void unschedule() { | |
| 28 // TODO(fgorski): Cancel the thing here. | |
|
Pete Williamson
2017/02/10 02:10:42
We should implement cancel and overwrite before tu
fgorski
2017/02/10 19:25:59
Done. I changed the code enabling it to not do it
| |
| 29 } | |
| 30 | |
| 31 @Override | |
| 32 protected void scheduleImpl(Context context, TriggerConditions triggerCondit ions, | |
| 33 long delayStartSeconds, long executionDeadlineSeconds, boolean overw rite) { | |
| 34 // TODO(fgorski): Handle overwrite case. | |
| 35 | |
| 36 PersistableBundle taskExtras = new PersistableBundle(); | |
| 37 TaskExtrasPacker.packTimeInBundle(taskExtras); | |
| 38 TaskExtrasPacker.packTriggerConditionsInBundle(taskExtras, triggerCondit ions); | |
| 39 | |
| 40 JobInfo jobInfo = | |
| 41 new JobInfo | |
| 42 .Builder(JOB_ID, | |
| 43 new ComponentName(context, BackgroundSchedulerJo bService.class)) | |
| 44 .setMinimumLatency(delayStartSeconds * 1000) // millisec onds | |
| 45 .setOverrideDeadline(executionDeadlineSeconds * 1000) // milliseconds | |
| 46 .setPersisted(true) // across device resets | |
| 47 .setRequiredNetworkType(triggerConditions.requireUnmeter edNetwork() | |
| 48 ? JobInfo.NETWORK_TYPE_UNMETERED | |
| 49 : JobInfo.NETWORK_TYPE_ANY) | |
| 50 .setRequiresCharging(triggerConditions.requirePowerConne cted()) | |
| 51 .setExtras(taskExtras) | |
| 52 .build(); | |
| 53 | |
| 54 ((JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE)) .schedule(jobInfo); | |
| 55 } | |
| 56 } | |
| OLD | NEW |