Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 17 | package android.app.job; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 18 | |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 19 | import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; |
| 20 | import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED; |
| 21 | import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING; |
| 22 | import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; |
| 23 | import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; |
| 24 | import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 25 | import static android.util.TimeUtils.formatDuration; |
| 26 | |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 27 | import android.annotation.BytesLong; |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 28 | import android.annotation.IntDef; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
| 30 | import android.annotation.Nullable; |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 32 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 33 | import android.content.ClipData; |
Christopher Tate | fa380e9 | 2014-05-19 13:46:29 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 35 | import android.net.NetworkRequest; |
| 36 | import android.net.NetworkSpecifier; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 37 | import android.net.Uri; |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 38 | import android.os.BaseBundle; |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 39 | import android.os.Bundle; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 40 | import android.os.Parcel; |
| 41 | import android.os.Parcelable; |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 42 | import android.os.PersistableBundle; |
Shreyas Basarge | e96c3b7 | 2016-01-29 19:25:51 +0000 | [diff] [blame] | 43 | import android.util.Log; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 44 | |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 45 | import java.lang.annotation.Retention; |
| 46 | import java.lang.annotation.RetentionPolicy; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 47 | import java.util.ArrayList; |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 48 | import java.util.Arrays; |
Dianne Hackborn | 121e164 | 2016-06-21 20:39:02 -0700 | [diff] [blame] | 49 | import java.util.Objects; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 50 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 51 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 52 | * Container of data passed to the {@link android.app.job.JobScheduler} fully encapsulating the |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 53 | * parameters required to schedule work against the calling application. These are constructed |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 54 | * using the {@link JobInfo.Builder}. |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 55 | * You must specify at least one sort of constraint on the JobInfo object that you are creating. |
| 56 | * The goal here is to provide the scheduler with high-level semantics about the work you want to |
| 57 | * accomplish. Doing otherwise with throw an exception in your app. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 58 | */ |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 59 | public class JobInfo implements Parcelable { |
Shreyas Basarge | e96c3b7 | 2016-01-29 19:25:51 +0000 | [diff] [blame] | 60 | private static String TAG = "JobInfo"; |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 61 | |
| 62 | /** @hide */ |
| 63 | @IntDef(prefix = { "NETWORK_TYPE_" }, value = { |
| 64 | NETWORK_TYPE_NONE, |
| 65 | NETWORK_TYPE_ANY, |
| 66 | NETWORK_TYPE_UNMETERED, |
| 67 | NETWORK_TYPE_NOT_ROAMING, |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 68 | NETWORK_TYPE_CELLULAR, |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 69 | }) |
| 70 | @Retention(RetentionPolicy.SOURCE) |
| 71 | public @interface NetworkType {} |
| 72 | |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 73 | /** Default. */ |
| 74 | public static final int NETWORK_TYPE_NONE = 0; |
| 75 | /** This job requires network connectivity. */ |
| 76 | public static final int NETWORK_TYPE_ANY = 1; |
| 77 | /** This job requires network connectivity that is unmetered. */ |
| 78 | public static final int NETWORK_TYPE_UNMETERED = 2; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 79 | /** This job requires network connectivity that is not roaming. */ |
| 80 | public static final int NETWORK_TYPE_NOT_ROAMING = 3; |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 81 | /** This job requires network connectivity that is a cellular network. */ |
| 82 | public static final int NETWORK_TYPE_CELLULAR = 4; |
| 83 | |
| 84 | /** |
| 85 | * This job requires metered connectivity such as most cellular data |
| 86 | * networks. |
| 87 | * |
| 88 | * @deprecated Cellular networks may be unmetered, or Wi-Fi networks may be |
| 89 | * metered, so this isn't a good way of selecting a specific |
| 90 | * transport. Instead, use {@link #NETWORK_TYPE_CELLULAR} or |
| 91 | * {@link android.net.NetworkRequest.Builder#addTransportType(int)} |
| 92 | * if your job requires a specific network transport. |
| 93 | */ |
| 94 | @Deprecated |
| 95 | public static final int NETWORK_TYPE_METERED = NETWORK_TYPE_CELLULAR; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 96 | |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 97 | /** Sentinel value indicating that bytes are unknown. */ |
| 98 | public static final int NETWORK_BYTES_UNKNOWN = -1; |
| 99 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 100 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 101 | * Amount of backoff a job has initially by default, in milliseconds. |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 102 | */ |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 103 | public static final long DEFAULT_INITIAL_BACKOFF_MILLIS = 30000L; // 30 seconds. |
| 104 | |
| 105 | /** |
| 106 | * Maximum backoff we allow for a job, in milliseconds. |
| 107 | */ |
| 108 | public static final long MAX_BACKOFF_DELAY_MILLIS = 5 * 60 * 60 * 1000; // 5 hours. |
| 109 | |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 110 | /** @hide */ |
| 111 | @IntDef(prefix = { "BACKOFF_POLICY_" }, value = { |
| 112 | BACKOFF_POLICY_LINEAR, |
| 113 | BACKOFF_POLICY_EXPONENTIAL, |
| 114 | }) |
| 115 | @Retention(RetentionPolicy.SOURCE) |
| 116 | public @interface BackoffPolicy {} |
| 117 | |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 118 | /** |
| 119 | * Linearly back-off a failed job. See |
| 120 | * {@link android.app.job.JobInfo.Builder#setBackoffCriteria(long, int)} |
| 121 | * retry_time(current_time, num_failures) = |
| 122 | * current_time + initial_backoff_millis * num_failures, num_failures >= 1 |
| 123 | */ |
| 124 | public static final int BACKOFF_POLICY_LINEAR = 0; |
| 125 | |
| 126 | /** |
| 127 | * Exponentially back-off a failed job. See |
| 128 | * {@link android.app.job.JobInfo.Builder#setBackoffCriteria(long, int)} |
| 129 | * |
| 130 | * retry_time(current_time, num_failures) = |
| 131 | * current_time + initial_backoff_millis * 2 ^ (num_failures - 1), num_failures >= 1 |
| 132 | */ |
| 133 | public static final int BACKOFF_POLICY_EXPONENTIAL = 1; |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 134 | |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 135 | /* Minimum interval for a periodic job, in milliseconds. */ |
Christopher Tate | 10be4e9 | 2016-03-15 16:56:21 -0700 | [diff] [blame] | 136 | private static final long MIN_PERIOD_MILLIS = 15 * 60 * 1000L; // 15 minutes |
| 137 | |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 138 | /* Minimum flex for a periodic job, in milliseconds. */ |
Christopher Tate | 10be4e9 | 2016-03-15 16:56:21 -0700 | [diff] [blame] | 139 | private static final long MIN_FLEX_MILLIS = 5 * 60 * 1000L; // 5 minutes |
| 140 | |
Dianne Hackborn | bfc2331 | 2017-05-11 11:53:24 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Minimum backoff interval for a job, in milliseconds |
| 143 | * @hide |
| 144 | */ |
| 145 | public static final long MIN_BACKOFF_MILLIS = 10 * 1000L; // 10 seconds |
Christopher Tate | b2087f8 | 2017-03-29 17:42:39 -0700 | [diff] [blame] | 146 | |
Christopher Tate | 10be4e9 | 2016-03-15 16:56:21 -0700 | [diff] [blame] | 147 | /** |
| 148 | * Query the minimum interval allowed for periodic scheduled jobs. Attempting |
| 149 | * to declare a smaller period that this when scheduling a job will result in a |
| 150 | * job that is still periodic, but will run with this effective period. |
| 151 | * |
| 152 | * @return The minimum available interval for scheduling periodic jobs, in milliseconds. |
| 153 | */ |
Christopher Tate | a9b4f3f | 2016-05-18 13:57:37 -0700 | [diff] [blame] | 154 | public static final long getMinPeriodMillis() { |
Christopher Tate | 10be4e9 | 2016-03-15 16:56:21 -0700 | [diff] [blame] | 155 | return MIN_PERIOD_MILLIS; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Query the minimum flex time allowed for periodic scheduled jobs. Attempting |
| 160 | * to declare a shorter flex time than this when scheduling such a job will |
| 161 | * result in this amount as the effective flex time for the job. |
| 162 | * |
| 163 | * @return The minimum available flex time for scheduling periodic jobs, in milliseconds. |
| 164 | */ |
Christopher Tate | a9b4f3f | 2016-05-18 13:57:37 -0700 | [diff] [blame] | 165 | public static final long getMinFlexMillis() { |
Christopher Tate | 10be4e9 | 2016-03-15 16:56:21 -0700 | [diff] [blame] | 166 | return MIN_FLEX_MILLIS; |
| 167 | } |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 168 | |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 169 | /** |
Christopher Tate | b2087f8 | 2017-03-29 17:42:39 -0700 | [diff] [blame] | 170 | * Query the minimum automatic-reschedule backoff interval permitted for jobs. |
| 171 | * @hide |
| 172 | */ |
| 173 | public static final long getMinBackoffMillis() { |
| 174 | return MIN_BACKOFF_MILLIS; |
| 175 | } |
| 176 | |
| 177 | /** |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 178 | * Default type of backoff. |
| 179 | * @hide |
| 180 | */ |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 181 | public static final int DEFAULT_BACKOFF_POLICY = BACKOFF_POLICY_EXPONENTIAL; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 182 | |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 183 | /** |
| 184 | * Default of {@link #getPriority}. |
| 185 | * @hide |
| 186 | */ |
| 187 | public static final int PRIORITY_DEFAULT = 0; |
| 188 | |
| 189 | /** |
| 190 | * Value of {@link #getPriority} for expedited syncs. |
| 191 | * @hide |
| 192 | */ |
| 193 | public static final int PRIORITY_SYNC_EXPEDITED = 10; |
| 194 | |
| 195 | /** |
| 196 | * Value of {@link #getPriority} for first time initialization syncs. |
| 197 | * @hide |
| 198 | */ |
| 199 | public static final int PRIORITY_SYNC_INITIALIZATION = 20; |
| 200 | |
| 201 | /** |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 202 | * Value of {@link #getPriority} for a foreground app (overrides the supplied |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 203 | * JobInfo priority if it is smaller). |
| 204 | * @hide |
| 205 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 206 | @UnsupportedAppUsage |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 207 | public static final int PRIORITY_FOREGROUND_APP = 30; |
| 208 | |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 209 | /** |
| 210 | * Value of {@link #getPriority} for the current top app (overrides the supplied |
| 211 | * JobInfo priority if it is smaller). |
| 212 | * @hide |
| 213 | */ |
| 214 | public static final int PRIORITY_TOP_APP = 40; |
| 215 | |
Dianne Hackborn | 807de78 | 2016-04-07 17:54:41 -0700 | [diff] [blame] | 216 | /** |
| 217 | * Adjustment of {@link #getPriority} if the app has often (50% or more of the time) |
| 218 | * been running jobs. |
| 219 | * @hide |
| 220 | */ |
| 221 | public static final int PRIORITY_ADJ_OFTEN_RUNNING = -40; |
| 222 | |
| 223 | /** |
| 224 | * Adjustment of {@link #getPriority} if the app has always (90% or more of the time) |
| 225 | * been running jobs. |
| 226 | * @hide |
| 227 | */ |
| 228 | public static final int PRIORITY_ADJ_ALWAYS_RUNNING = -80; |
| 229 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 230 | /** |
| 231 | * Indicates that the implementation of this job will be using |
| 232 | * {@link JobService#startForeground(int, android.app.Notification)} to run |
| 233 | * in the foreground. |
| 234 | * <p> |
| 235 | * When set, the internal scheduling of this job will ignore any background |
| 236 | * network restrictions for the requesting app. Note that this flag alone |
| 237 | * doesn't actually place your {@link JobService} in the foreground; you |
| 238 | * still need to post the notification yourself. |
Jeff Sharkey | 785f494 | 2016-07-14 10:31:15 -0600 | [diff] [blame] | 239 | * <p> |
| 240 | * To use this flag, the caller must hold the |
| 241 | * {@link android.Manifest.permission#CONNECTIVITY_INTERNAL} permission. |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 242 | * |
| 243 | * @hide |
| 244 | */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 245 | @UnsupportedAppUsage |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 246 | public static final int FLAG_WILL_BE_FOREGROUND = 1 << 0; |
| 247 | |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 248 | /** |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 249 | * Allows this job to run despite doze restrictions as long as the app is in the foreground |
| 250 | * or on the temporary whitelist |
| 251 | * @hide |
| 252 | */ |
| 253 | public static final int FLAG_IMPORTANT_WHILE_FOREGROUND = 1 << 1; |
| 254 | |
| 255 | /** |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 256 | * @hide |
| 257 | */ |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 258 | public static final int FLAG_PREFETCH = 1 << 2; |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 259 | |
| 260 | /** |
Makoto Onuki | 959acb5 | 2018-01-26 14:10:03 -0800 | [diff] [blame] | 261 | * This job needs to be exempted from the app standby throttling. Only the system (UID 1000) |
| 262 | * can set it. Jobs with a time constrant must not have it. |
| 263 | * |
| 264 | * @hide |
| 265 | */ |
| 266 | public static final int FLAG_EXEMPT_FROM_APP_STANDBY = 1 << 3; |
| 267 | |
| 268 | /** |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 269 | * @hide |
| 270 | */ |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 271 | public static final int CONSTRAINT_FLAG_CHARGING = 1 << 0; |
| 272 | |
| 273 | /** |
| 274 | * @hide |
| 275 | */ |
| 276 | public static final int CONSTRAINT_FLAG_BATTERY_NOT_LOW = 1 << 1; |
| 277 | |
| 278 | /** |
| 279 | * @hide |
| 280 | */ |
| 281 | public static final int CONSTRAINT_FLAG_DEVICE_IDLE = 1 << 2; |
| 282 | |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 283 | /** |
| 284 | * @hide |
| 285 | */ |
| 286 | public static final int CONSTRAINT_FLAG_STORAGE_NOT_LOW = 1 << 3; |
| 287 | |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 288 | @UnsupportedAppUsage |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 289 | private final int jobId; |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 290 | private final PersistableBundle extras; |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 291 | private final Bundle transientExtras; |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 292 | private final ClipData clipData; |
| 293 | private final int clipGrantFlags; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 294 | @UnsupportedAppUsage |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 295 | private final ComponentName service; |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 296 | private final int constraintFlags; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 297 | private final TriggerContentUri[] triggerContentUris; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 298 | private final long triggerContentUpdateDelay; |
| 299 | private final long triggerContentMaxDelay; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 300 | private final boolean hasEarlyConstraint; |
| 301 | private final boolean hasLateConstraint; |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 302 | private final NetworkRequest networkRequest; |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 303 | private final long networkDownloadBytes; |
| 304 | private final long networkUploadBytes; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 305 | private final long minLatencyMillis; |
| 306 | private final long maxExecutionDelayMillis; |
| 307 | private final boolean isPeriodic; |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 308 | private final boolean isPersisted; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 309 | private final long intervalMillis; |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 310 | private final long flexMillis; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 311 | private final long initialBackoffMillis; |
| 312 | private final int backoffPolicy; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 313 | private final int priority; |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 314 | @UnsupportedAppUsage |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 315 | private final int flags; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 316 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 317 | /** |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 318 | * Unique job id associated with this application (uid). This is the same job ID |
| 319 | * you supplied in the {@link Builder} constructor. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 320 | */ |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 321 | public int getId() { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 322 | return jobId; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 326 | * @see JobInfo.Builder#setExtras(PersistableBundle) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 327 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 328 | public @NonNull PersistableBundle getExtras() { |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 329 | return extras; |
| 330 | } |
| 331 | |
| 332 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 333 | * @see JobInfo.Builder#setTransientExtras(Bundle) |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 334 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 335 | public @NonNull Bundle getTransientExtras() { |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 336 | return transientExtras; |
| 337 | } |
| 338 | |
| 339 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 340 | * @see JobInfo.Builder#setClipData(ClipData, int) |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 341 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 342 | public @Nullable ClipData getClipData() { |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 343 | return clipData; |
| 344 | } |
| 345 | |
| 346 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 347 | * @see JobInfo.Builder#setClipData(ClipData, int) |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 348 | */ |
| 349 | public int getClipGrantFlags() { |
| 350 | return clipGrantFlags; |
| 351 | } |
| 352 | |
| 353 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 354 | * Name of the service endpoint that will be called back into by the JobScheduler. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 355 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 356 | public @NonNull ComponentName getService() { |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 357 | return service; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 360 | /** @hide */ |
| 361 | public int getPriority() { |
| 362 | return priority; |
| 363 | } |
| 364 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 365 | /** @hide */ |
| 366 | public int getFlags() { |
| 367 | return flags; |
| 368 | } |
| 369 | |
Makoto Onuki | 959acb5 | 2018-01-26 14:10:03 -0800 | [diff] [blame] | 370 | /** @hide */ |
| 371 | public boolean isExemptedFromAppStandby() { |
Makoto Onuki | 2b5811a | 2018-02-08 11:09:42 -0800 | [diff] [blame] | 372 | return ((flags & FLAG_EXEMPT_FROM_APP_STANDBY) != 0) && !isPeriodic(); |
Makoto Onuki | 959acb5 | 2018-01-26 14:10:03 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 375 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 376 | * @see JobInfo.Builder#setRequiresCharging(boolean) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 377 | */ |
| 378 | public boolean isRequireCharging() { |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 379 | return (constraintFlags & CONSTRAINT_FLAG_CHARGING) != 0; |
| 380 | } |
| 381 | |
| 382 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 383 | * @see JobInfo.Builder#setRequiresBatteryNotLow(boolean) |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 384 | */ |
| 385 | public boolean isRequireBatteryNotLow() { |
| 386 | return (constraintFlags & CONSTRAINT_FLAG_BATTERY_NOT_LOW) != 0; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 390 | * @see JobInfo.Builder#setRequiresDeviceIdle(boolean) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 391 | */ |
| 392 | public boolean isRequireDeviceIdle() { |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 393 | return (constraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0; |
| 394 | } |
| 395 | |
| 396 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 397 | * @see JobInfo.Builder#setRequiresStorageNotLow(boolean) |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 398 | */ |
| 399 | public boolean isRequireStorageNotLow() { |
| 400 | return (constraintFlags & CONSTRAINT_FLAG_STORAGE_NOT_LOW) != 0; |
| 401 | } |
| 402 | |
| 403 | /** |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 404 | * @hide |
| 405 | */ |
| 406 | public int getConstraintFlags() { |
| 407 | return constraintFlags; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /** |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 411 | * Which content: URIs must change for the job to be scheduled. Returns null |
| 412 | * if there are none required. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 413 | * @see JobInfo.Builder#addTriggerContentUri(TriggerContentUri) |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 414 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 415 | public @Nullable TriggerContentUri[] getTriggerContentUris() { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 416 | return triggerContentUris; |
| 417 | } |
| 418 | |
| 419 | /** |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 420 | * When triggering on content URI changes, this is the delay from when a change |
| 421 | * is detected until the job is scheduled. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 422 | * @see JobInfo.Builder#setTriggerContentUpdateDelay(long) |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 423 | */ |
| 424 | public long getTriggerContentUpdateDelay() { |
| 425 | return triggerContentUpdateDelay; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * When triggering on content URI changes, this is the maximum delay we will |
| 430 | * use before scheduling the job. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 431 | * @see JobInfo.Builder#setTriggerContentMaxDelay(long) |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 432 | */ |
| 433 | public long getTriggerContentMaxDelay() { |
| 434 | return triggerContentMaxDelay; |
| 435 | } |
| 436 | |
| 437 | /** |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 438 | * Return the basic description of the kind of network this job requires. |
| 439 | * |
| 440 | * @deprecated This method attempts to map {@link #getRequiredNetwork()} |
| 441 | * into the set of simple constants, which results in a loss of |
| 442 | * fidelity. Callers should move to using |
| 443 | * {@link #getRequiredNetwork()} directly. |
| 444 | * @see Builder#setRequiredNetworkType(int) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 445 | */ |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 446 | @Deprecated |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 447 | public @NetworkType int getNetworkType() { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 448 | if (networkRequest == null) { |
| 449 | return NETWORK_TYPE_NONE; |
| 450 | } else if (networkRequest.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_METERED)) { |
| 451 | return NETWORK_TYPE_UNMETERED; |
| 452 | } else if (networkRequest.networkCapabilities.hasCapability(NET_CAPABILITY_NOT_ROAMING)) { |
| 453 | return NETWORK_TYPE_NOT_ROAMING; |
| 454 | } else if (networkRequest.networkCapabilities.hasTransport(TRANSPORT_CELLULAR)) { |
| 455 | return NETWORK_TYPE_CELLULAR; |
| 456 | } else { |
| 457 | return NETWORK_TYPE_ANY; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Return the detailed description of the kind of network this job requires, |
| 463 | * or {@code null} if no specific kind of network is required. |
| 464 | * |
| 465 | * @see Builder#setRequiredNetwork(NetworkRequest) |
| 466 | */ |
| 467 | public @Nullable NetworkRequest getRequiredNetwork() { |
| 468 | return networkRequest; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 472 | * @deprecated replaced by {@link #getEstimatedNetworkDownloadBytes()} and |
| 473 | * {@link #getEstimatedNetworkUploadBytes()}. |
| 474 | * @removed |
| 475 | */ |
| 476 | @Deprecated |
| 477 | public @BytesLong long getEstimatedNetworkBytes() { |
| 478 | if (networkDownloadBytes == NETWORK_BYTES_UNKNOWN |
| 479 | && networkUploadBytes == NETWORK_BYTES_UNKNOWN) { |
| 480 | return NETWORK_BYTES_UNKNOWN; |
| 481 | } else if (networkDownloadBytes == NETWORK_BYTES_UNKNOWN) { |
| 482 | return networkUploadBytes; |
| 483 | } else if (networkUploadBytes == NETWORK_BYTES_UNKNOWN) { |
| 484 | return networkDownloadBytes; |
| 485 | } else { |
| 486 | return networkDownloadBytes + networkUploadBytes; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Return the estimated size of download traffic that will be performed by |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 492 | * this job, in bytes. |
| 493 | * |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 494 | * @return Estimated size of download traffic, or |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 495 | * {@link #NETWORK_BYTES_UNKNOWN} when unknown. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 496 | * @see Builder#setEstimatedNetworkBytes(long, long) |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 497 | */ |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 498 | public @BytesLong long getEstimatedNetworkDownloadBytes() { |
| 499 | return networkDownloadBytes; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * Return the estimated size of upload traffic that will be performed by |
| 504 | * this job, in bytes. |
| 505 | * |
| 506 | * @return Estimated size of upload traffic, or |
| 507 | * {@link #NETWORK_BYTES_UNKNOWN} when unknown. |
| 508 | * @see Builder#setEstimatedNetworkBytes(long, long) |
| 509 | */ |
| 510 | public @BytesLong long getEstimatedNetworkUploadBytes() { |
| 511 | return networkUploadBytes; |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 515 | * Set for a job that does not recur periodically, to specify a delay after which the job |
| 516 | * will be eligible for execution. This value is not set if the job recurs periodically. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 517 | * @see JobInfo.Builder#setMinimumLatency(long) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 518 | */ |
| 519 | public long getMinLatencyMillis() { |
| 520 | return minLatencyMillis; |
| 521 | } |
| 522 | |
| 523 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 524 | * @see JobInfo.Builder#setOverrideDeadline(long) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 525 | */ |
| 526 | public long getMaxExecutionDelayMillis() { |
| 527 | return maxExecutionDelayMillis; |
| 528 | } |
| 529 | |
| 530 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 531 | * Track whether this job will repeat with a given period. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 532 | * @see JobInfo.Builder#setPeriodic(long) |
| 533 | * @see JobInfo.Builder#setPeriodic(long, long) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 534 | */ |
| 535 | public boolean isPeriodic() { |
| 536 | return isPeriodic; |
| 537 | } |
| 538 | |
| 539 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 540 | * @see JobInfo.Builder#setPersisted(boolean) |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 541 | */ |
| 542 | public boolean isPersisted() { |
| 543 | return isPersisted; |
| 544 | } |
| 545 | |
| 546 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 547 | * Set to the interval between occurrences of this job. This value is <b>not</b> set if the |
| 548 | * job does not recur periodically. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 549 | * @see JobInfo.Builder#setPeriodic(long) |
| 550 | * @see JobInfo.Builder#setPeriodic(long, long) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 551 | */ |
| 552 | public long getIntervalMillis() { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 553 | return intervalMillis; |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | /** |
Shreyas Basarge | 9e6d588 | 2016-04-12 10:59:07 +0100 | [diff] [blame] | 557 | * Flex time for this job. Only valid if this is a periodic job. The job can |
| 558 | * execute at any time in a window of flex length at the end of the period. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 559 | * @see JobInfo.Builder#setPeriodic(long) |
| 560 | * @see JobInfo.Builder#setPeriodic(long, long) |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 561 | */ |
| 562 | public long getFlexMillis() { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 563 | return flexMillis; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 567 | * The amount of time the JobScheduler will wait before rescheduling a failed job. This value |
| 568 | * will be increased depending on the backoff policy specified at job creation time. Defaults |
Dianne Hackborn | bfc2331 | 2017-05-11 11:53:24 -0700 | [diff] [blame] | 569 | * to 30 seconds, minimum is currently 10 seconds. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 570 | * @see JobInfo.Builder#setBackoffCriteria(long, int) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 571 | */ |
| 572 | public long getInitialBackoffMillis() { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 573 | return initialBackoffMillis; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 577 | * Return the backoff policy of this job. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 578 | * @see JobInfo.Builder#setBackoffCriteria(long, int) |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 579 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 580 | public @BackoffPolicy int getBackoffPolicy() { |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 581 | return backoffPolicy; |
| 582 | } |
| 583 | |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 584 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 585 | * @see JobInfo.Builder#setImportantWhileForeground(boolean) |
| 586 | */ |
| 587 | public boolean isImportantWhileForeground() { |
| 588 | return (flags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0; |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * @see JobInfo.Builder#setPrefetch(boolean) |
| 593 | */ |
| 594 | public boolean isPrefetch() { |
| 595 | return (flags & FLAG_PREFETCH) != 0; |
| 596 | } |
| 597 | |
| 598 | /** |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 599 | * User can specify an early constraint of 0L, which is valid, so we keep track of whether the |
| 600 | * function was called at all. |
| 601 | * @hide |
| 602 | */ |
| 603 | public boolean hasEarlyConstraint() { |
| 604 | return hasEarlyConstraint; |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * User can specify a late constraint of 0L, which is valid, so we keep track of whether the |
| 609 | * function was called at all. |
| 610 | * @hide |
| 611 | */ |
| 612 | public boolean hasLateConstraint() { |
| 613 | return hasLateConstraint; |
| 614 | } |
| 615 | |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 616 | private static boolean kindofEqualsBundle(BaseBundle a, BaseBundle b) { |
| 617 | return (a == b) || (a != null && a.kindofEquals(b)); |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | public boolean equals(Object o) { |
| 622 | if (!(o instanceof JobInfo)) { |
| 623 | return false; |
| 624 | } |
| 625 | JobInfo j = (JobInfo) o; |
| 626 | if (jobId != j.jobId) { |
| 627 | return false; |
| 628 | } |
| 629 | // XXX won't be correct if one is parcelled and the other not. |
| 630 | if (!kindofEqualsBundle(extras, j.extras)) { |
| 631 | return false; |
| 632 | } |
| 633 | // XXX won't be correct if one is parcelled and the other not. |
| 634 | if (!kindofEqualsBundle(transientExtras, j.transientExtras)) { |
| 635 | return false; |
| 636 | } |
| 637 | // XXX for now we consider two different clip data objects to be different, |
| 638 | // regardless of whether their contents are the same. |
| 639 | if (clipData != j.clipData) { |
| 640 | return false; |
| 641 | } |
| 642 | if (clipGrantFlags != j.clipGrantFlags) { |
| 643 | return false; |
| 644 | } |
| 645 | if (!Objects.equals(service, j.service)) { |
| 646 | return false; |
| 647 | } |
| 648 | if (constraintFlags != j.constraintFlags) { |
| 649 | return false; |
| 650 | } |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 651 | if (!Arrays.equals(triggerContentUris, j.triggerContentUris)) { |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 652 | return false; |
| 653 | } |
| 654 | if (triggerContentUpdateDelay != j.triggerContentUpdateDelay) { |
| 655 | return false; |
| 656 | } |
| 657 | if (triggerContentMaxDelay != j.triggerContentMaxDelay) { |
| 658 | return false; |
| 659 | } |
| 660 | if (hasEarlyConstraint != j.hasEarlyConstraint) { |
| 661 | return false; |
| 662 | } |
| 663 | if (hasLateConstraint != j.hasLateConstraint) { |
| 664 | return false; |
| 665 | } |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 666 | if (!Objects.equals(networkRequest, j.networkRequest)) { |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 667 | return false; |
| 668 | } |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 669 | if (networkDownloadBytes != j.networkDownloadBytes) { |
| 670 | return false; |
| 671 | } |
| 672 | if (networkUploadBytes != j.networkUploadBytes) { |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 673 | return false; |
| 674 | } |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 675 | if (minLatencyMillis != j.minLatencyMillis) { |
| 676 | return false; |
| 677 | } |
| 678 | if (maxExecutionDelayMillis != j.maxExecutionDelayMillis) { |
| 679 | return false; |
| 680 | } |
| 681 | if (isPeriodic != j.isPeriodic) { |
| 682 | return false; |
| 683 | } |
| 684 | if (isPersisted != j.isPersisted) { |
| 685 | return false; |
| 686 | } |
| 687 | if (intervalMillis != j.intervalMillis) { |
| 688 | return false; |
| 689 | } |
| 690 | if (flexMillis != j.flexMillis) { |
| 691 | return false; |
| 692 | } |
| 693 | if (initialBackoffMillis != j.initialBackoffMillis) { |
| 694 | return false; |
| 695 | } |
| 696 | if (backoffPolicy != j.backoffPolicy) { |
| 697 | return false; |
| 698 | } |
| 699 | if (priority != j.priority) { |
| 700 | return false; |
| 701 | } |
| 702 | if (flags != j.flags) { |
| 703 | return false; |
| 704 | } |
| 705 | return true; |
| 706 | } |
| 707 | |
| 708 | @Override |
| 709 | public int hashCode() { |
| 710 | int hashCode = jobId; |
| 711 | if (extras != null) { |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 712 | hashCode = 31 * hashCode + extras.hashCode(); |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 713 | } |
| 714 | if (transientExtras != null) { |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 715 | hashCode = 31 * hashCode + transientExtras.hashCode(); |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 716 | } |
| 717 | if (clipData != null) { |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 718 | hashCode = 31 * hashCode + clipData.hashCode(); |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 719 | } |
| 720 | hashCode = 31*hashCode + clipGrantFlags; |
| 721 | if (service != null) { |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 722 | hashCode = 31 * hashCode + service.hashCode(); |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 723 | } |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 724 | hashCode = 31 * hashCode + constraintFlags; |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 725 | if (triggerContentUris != null) { |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 726 | hashCode = 31 * hashCode + Arrays.hashCode(triggerContentUris); |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 727 | } |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 728 | hashCode = 31 * hashCode + Long.hashCode(triggerContentUpdateDelay); |
| 729 | hashCode = 31 * hashCode + Long.hashCode(triggerContentMaxDelay); |
| 730 | hashCode = 31 * hashCode + Boolean.hashCode(hasEarlyConstraint); |
| 731 | hashCode = 31 * hashCode + Boolean.hashCode(hasLateConstraint); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 732 | if (networkRequest != null) { |
| 733 | hashCode = 31 * hashCode + networkRequest.hashCode(); |
| 734 | } |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 735 | hashCode = 31 * hashCode + Long.hashCode(networkDownloadBytes); |
| 736 | hashCode = 31 * hashCode + Long.hashCode(networkUploadBytes); |
Paul Duffin | c67663c | 2017-05-26 09:46:48 +0100 | [diff] [blame] | 737 | hashCode = 31 * hashCode + Long.hashCode(minLatencyMillis); |
| 738 | hashCode = 31 * hashCode + Long.hashCode(maxExecutionDelayMillis); |
| 739 | hashCode = 31 * hashCode + Boolean.hashCode(isPeriodic); |
| 740 | hashCode = 31 * hashCode + Boolean.hashCode(isPersisted); |
| 741 | hashCode = 31 * hashCode + Long.hashCode(intervalMillis); |
| 742 | hashCode = 31 * hashCode + Long.hashCode(flexMillis); |
| 743 | hashCode = 31 * hashCode + Long.hashCode(initialBackoffMillis); |
| 744 | hashCode = 31 * hashCode + backoffPolicy; |
| 745 | hashCode = 31 * hashCode + priority; |
| 746 | hashCode = 31 * hashCode + flags; |
Dianne Hackborn | 7da13d7 | 2017-04-04 17:17:35 -0700 | [diff] [blame] | 747 | return hashCode; |
| 748 | } |
| 749 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 750 | private JobInfo(Parcel in) { |
| 751 | jobId = in.readInt(); |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 752 | extras = in.readPersistableBundle(); |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 753 | transientExtras = in.readBundle(); |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 754 | if (in.readInt() != 0) { |
| 755 | clipData = ClipData.CREATOR.createFromParcel(in); |
| 756 | clipGrantFlags = in.readInt(); |
| 757 | } else { |
| 758 | clipData = null; |
| 759 | clipGrantFlags = 0; |
| 760 | } |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 761 | service = in.readParcelable(null); |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 762 | constraintFlags = in.readInt(); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 763 | triggerContentUris = in.createTypedArray(TriggerContentUri.CREATOR); |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 764 | triggerContentUpdateDelay = in.readLong(); |
| 765 | triggerContentMaxDelay = in.readLong(); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 766 | if (in.readInt() != 0) { |
| 767 | networkRequest = NetworkRequest.CREATOR.createFromParcel(in); |
| 768 | } else { |
| 769 | networkRequest = null; |
| 770 | } |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 771 | networkDownloadBytes = in.readLong(); |
| 772 | networkUploadBytes = in.readLong(); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 773 | minLatencyMillis = in.readLong(); |
| 774 | maxExecutionDelayMillis = in.readLong(); |
| 775 | isPeriodic = in.readInt() == 1; |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 776 | isPersisted = in.readInt() == 1; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 777 | intervalMillis = in.readLong(); |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 778 | flexMillis = in.readLong(); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 779 | initialBackoffMillis = in.readLong(); |
| 780 | backoffPolicy = in.readInt(); |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 781 | hasEarlyConstraint = in.readInt() == 1; |
| 782 | hasLateConstraint = in.readInt() == 1; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 783 | priority = in.readInt(); |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 784 | flags = in.readInt(); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 787 | private JobInfo(JobInfo.Builder b) { |
| 788 | jobId = b.mJobId; |
Dianne Hackborn | 2510b37 | 2017-03-03 17:01:38 -0800 | [diff] [blame] | 789 | extras = b.mExtras.deepCopy(); |
| 790 | transientExtras = b.mTransientExtras.deepCopy(); |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 791 | clipData = b.mClipData; |
| 792 | clipGrantFlags = b.mClipGrantFlags; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 793 | service = b.mJobService; |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 794 | constraintFlags = b.mConstraintFlags; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 795 | triggerContentUris = b.mTriggerContentUris != null |
| 796 | ? b.mTriggerContentUris.toArray(new TriggerContentUri[b.mTriggerContentUris.size()]) |
| 797 | : null; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 798 | triggerContentUpdateDelay = b.mTriggerContentUpdateDelay; |
| 799 | triggerContentMaxDelay = b.mTriggerContentMaxDelay; |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 800 | networkRequest = b.mNetworkRequest; |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 801 | networkDownloadBytes = b.mNetworkDownloadBytes; |
| 802 | networkUploadBytes = b.mNetworkUploadBytes; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 803 | minLatencyMillis = b.mMinLatencyMillis; |
| 804 | maxExecutionDelayMillis = b.mMaxExecutionDelayMillis; |
| 805 | isPeriodic = b.mIsPeriodic; |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 806 | isPersisted = b.mIsPersisted; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 807 | intervalMillis = b.mIntervalMillis; |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 808 | flexMillis = b.mFlexMillis; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 809 | initialBackoffMillis = b.mInitialBackoffMillis; |
| 810 | backoffPolicy = b.mBackoffPolicy; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 811 | hasEarlyConstraint = b.mHasEarlyConstraint; |
| 812 | hasLateConstraint = b.mHasLateConstraint; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 813 | priority = b.mPriority; |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 814 | flags = b.mFlags; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | @Override |
| 818 | public int describeContents() { |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | @Override |
| 823 | public void writeToParcel(Parcel out, int flags) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 824 | out.writeInt(jobId); |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 825 | out.writePersistableBundle(extras); |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 826 | out.writeBundle(transientExtras); |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 827 | if (clipData != null) { |
| 828 | out.writeInt(1); |
| 829 | clipData.writeToParcel(out, flags); |
| 830 | out.writeInt(clipGrantFlags); |
| 831 | } else { |
| 832 | out.writeInt(0); |
| 833 | } |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 834 | out.writeParcelable(service, flags); |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 835 | out.writeInt(constraintFlags); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 836 | out.writeTypedArray(triggerContentUris, flags); |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 837 | out.writeLong(triggerContentUpdateDelay); |
| 838 | out.writeLong(triggerContentMaxDelay); |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 839 | if (networkRequest != null) { |
| 840 | out.writeInt(1); |
| 841 | networkRequest.writeToParcel(out, flags); |
| 842 | } else { |
| 843 | out.writeInt(0); |
| 844 | } |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 845 | out.writeLong(networkDownloadBytes); |
| 846 | out.writeLong(networkUploadBytes); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 847 | out.writeLong(minLatencyMillis); |
| 848 | out.writeLong(maxExecutionDelayMillis); |
| 849 | out.writeInt(isPeriodic ? 1 : 0); |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 850 | out.writeInt(isPersisted ? 1 : 0); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 851 | out.writeLong(intervalMillis); |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 852 | out.writeLong(flexMillis); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 853 | out.writeLong(initialBackoffMillis); |
| 854 | out.writeInt(backoffPolicy); |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 855 | out.writeInt(hasEarlyConstraint ? 1 : 0); |
| 856 | out.writeInt(hasLateConstraint ? 1 : 0); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 857 | out.writeInt(priority); |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 858 | out.writeInt(this.flags); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 861 | public static final Creator<JobInfo> CREATOR = new Creator<JobInfo>() { |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 862 | @Override |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 863 | public JobInfo createFromParcel(Parcel in) { |
| 864 | return new JobInfo(in); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | @Override |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 868 | public JobInfo[] newArray(int size) { |
| 869 | return new JobInfo[size]; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 870 | } |
| 871 | }; |
| 872 | |
Matthew Williams | ee410da | 2014-07-25 11:30:40 -0700 | [diff] [blame] | 873 | @Override |
| 874 | public String toString() { |
| 875 | return "(job:" + jobId + "/" + service.flattenToShortString() + ")"; |
| 876 | } |
| 877 | |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 878 | /** |
| 879 | * Information about a content URI modification that a job would like to |
| 880 | * trigger on. |
| 881 | */ |
| 882 | public static final class TriggerContentUri implements Parcelable { |
| 883 | private final Uri mUri; |
| 884 | private final int mFlags; |
| 885 | |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 886 | /** @hide */ |
| 887 | @Retention(RetentionPolicy.SOURCE) |
| 888 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 889 | FLAG_NOTIFY_FOR_DESCENDANTS, |
| 890 | }) |
| 891 | public @interface Flags { } |
| 892 | |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 893 | /** |
| 894 | * Flag for trigger: also trigger if any descendants of the given URI change. |
| 895 | * Corresponds to the <var>notifyForDescendants</var> of |
| 896 | * {@link android.content.ContentResolver#registerContentObserver}. |
| 897 | */ |
| 898 | public static final int FLAG_NOTIFY_FOR_DESCENDANTS = 1<<0; |
| 899 | |
| 900 | /** |
| 901 | * Create a new trigger description. |
| 902 | * @param uri The URI to observe. Must be non-null. |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 903 | * @param flags Flags for the observer. |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 904 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 905 | public TriggerContentUri(@NonNull Uri uri, @Flags int flags) { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 906 | mUri = uri; |
| 907 | mFlags = flags; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Return the Uri this trigger was created for. |
| 912 | */ |
| 913 | public Uri getUri() { |
| 914 | return mUri; |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * Return the flags supplied for the trigger. |
| 919 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 920 | public @Flags int getFlags() { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 921 | return mFlags; |
| 922 | } |
| 923 | |
Dianne Hackborn | 121e164 | 2016-06-21 20:39:02 -0700 | [diff] [blame] | 924 | @Override |
| 925 | public boolean equals(Object o) { |
| 926 | if (!(o instanceof TriggerContentUri)) { |
| 927 | return false; |
| 928 | } |
| 929 | TriggerContentUri t = (TriggerContentUri) o; |
| 930 | return Objects.equals(t.mUri, mUri) && t.mFlags == mFlags; |
| 931 | } |
| 932 | |
| 933 | @Override |
| 934 | public int hashCode() { |
| 935 | return (mUri == null ? 0 : mUri.hashCode()) ^ mFlags; |
| 936 | } |
| 937 | |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 938 | private TriggerContentUri(Parcel in) { |
| 939 | mUri = Uri.CREATOR.createFromParcel(in); |
| 940 | mFlags = in.readInt(); |
| 941 | } |
| 942 | |
| 943 | @Override |
| 944 | public int describeContents() { |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | @Override |
| 949 | public void writeToParcel(Parcel out, int flags) { |
| 950 | mUri.writeToParcel(out, flags); |
| 951 | out.writeInt(mFlags); |
| 952 | } |
| 953 | |
| 954 | public static final Creator<TriggerContentUri> CREATOR = new Creator<TriggerContentUri>() { |
| 955 | @Override |
| 956 | public TriggerContentUri createFromParcel(Parcel in) { |
| 957 | return new TriggerContentUri(in); |
| 958 | } |
| 959 | |
| 960 | @Override |
| 961 | public TriggerContentUri[] newArray(int size) { |
| 962 | return new TriggerContentUri[size]; |
| 963 | } |
| 964 | }; |
| 965 | } |
| 966 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 967 | /** Builder class for constructing {@link JobInfo} objects. */ |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 968 | public static final class Builder { |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 969 | private final int mJobId; |
| 970 | private final ComponentName mJobService; |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 971 | private PersistableBundle mExtras = PersistableBundle.EMPTY; |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 972 | private Bundle mTransientExtras = Bundle.EMPTY; |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 973 | private ClipData mClipData; |
| 974 | private int mClipGrantFlags; |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 975 | private int mPriority = PRIORITY_DEFAULT; |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 976 | private int mFlags; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 977 | // Requirements. |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 978 | private int mConstraintFlags; |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 979 | private NetworkRequest mNetworkRequest; |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 980 | private long mNetworkDownloadBytes = NETWORK_BYTES_UNKNOWN; |
| 981 | private long mNetworkUploadBytes = NETWORK_BYTES_UNKNOWN; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 982 | private ArrayList<TriggerContentUri> mTriggerContentUris; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 983 | private long mTriggerContentUpdateDelay = -1; |
| 984 | private long mTriggerContentMaxDelay = -1; |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 985 | private boolean mIsPersisted; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 986 | // One-off parameters. |
| 987 | private long mMinLatencyMillis; |
| 988 | private long mMaxExecutionDelayMillis; |
| 989 | // Periodic parameters. |
| 990 | private boolean mIsPeriodic; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 991 | private boolean mHasEarlyConstraint; |
| 992 | private boolean mHasLateConstraint; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 993 | private long mIntervalMillis; |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 994 | private long mFlexMillis; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 995 | // Back-off parameters. |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 996 | private long mInitialBackoffMillis = DEFAULT_INITIAL_BACKOFF_MILLIS; |
| 997 | private int mBackoffPolicy = DEFAULT_BACKOFF_POLICY; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 998 | /** Easy way to track whether the client has tried to set a back-off policy. */ |
| 999 | private boolean mBackoffPolicySet = false; |
| 1000 | |
| 1001 | /** |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 1002 | * Initialize a new Builder to construct a {@link JobInfo}. |
| 1003 | * |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1004 | * @param jobId Application-provided id for this job. Subsequent calls to cancel, or |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 1005 | * jobs created with the same jobId, will update the pre-existing job with |
| 1006 | * the same id. This ID must be unique across all clients of the same uid |
| 1007 | * (not just the same package). You will want to make sure this is a stable |
| 1008 | * id across app updates, so probably not based on a resource ID. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1009 | * @param jobService The endpoint that you implement that will receive the callback from the |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 1010 | * JobScheduler. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1011 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 1012 | public Builder(int jobId, @NonNull ComponentName jobService) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1013 | mJobService = jobService; |
| 1014 | mJobId = jobId; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 1017 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1018 | @UnsupportedAppUsage |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1019 | public Builder setPriority(int priority) { |
| 1020 | mPriority = priority; |
| 1021 | return this; |
| 1022 | } |
| 1023 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 1024 | /** @hide */ |
Mathew Inwood | 61e8ae6 | 2018-08-14 14:17:44 +0100 | [diff] [blame] | 1025 | @UnsupportedAppUsage |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 1026 | public Builder setFlags(int flags) { |
| 1027 | mFlags = flags; |
| 1028 | return this; |
| 1029 | } |
| 1030 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1031 | /** |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1032 | * Set optional extras. This is persisted, so we only allow primitive types. |
| 1033 | * @param extras Bundle containing extras you want the scheduler to hold on to for you. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1034 | * @see JobInfo#getExtras() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1035 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 1036 | public Builder setExtras(@NonNull PersistableBundle extras) { |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1037 | mExtras = extras; |
| 1038 | return this; |
| 1039 | } |
| 1040 | |
| 1041 | /** |
Dianne Hackborn | 28d1b66 | 2017-04-21 14:17:23 -0700 | [diff] [blame] | 1042 | * Set optional transient extras. |
| 1043 | * |
| 1044 | * <p>Because setting this property is not compatible with persisted |
| 1045 | * jobs, doing so will throw an {@link java.lang.IllegalArgumentException} when |
| 1046 | * {@link android.app.job.JobInfo.Builder#build()} is called.</p> |
| 1047 | * |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 1048 | * @param extras Bundle containing extras you want the scheduler to hold on to for you. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1049 | * @see JobInfo#getTransientExtras() |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 1050 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 1051 | public Builder setTransientExtras(@NonNull Bundle extras) { |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 1052 | mTransientExtras = extras; |
| 1053 | return this; |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1057 | * Set a {@link ClipData} associated with this Job. |
| 1058 | * |
| 1059 | * <p>The main purpose of providing a ClipData is to allow granting of |
| 1060 | * URI permissions for data associated with the clip. The exact kind |
| 1061 | * of permission grant to perform is specified through <var>grantFlags</var>. |
| 1062 | * |
| 1063 | * <p>If the ClipData contains items that are Intents, any |
| 1064 | * grant flags in those Intents will be ignored. Only flags provided as an argument |
| 1065 | * to this method are respected, and will be applied to all Uri or |
| 1066 | * Intent items in the clip (or sub-items of the clip). |
| 1067 | * |
| 1068 | * <p>Because setting this property is not compatible with persisted |
| 1069 | * jobs, doing so will throw an {@link java.lang.IllegalArgumentException} when |
| 1070 | * {@link android.app.job.JobInfo.Builder#build()} is called.</p> |
| 1071 | * |
| 1072 | * @param clip The new clip to set. May be null to clear the current clip. |
| 1073 | * @param grantFlags The desired permissions to grant for any URIs. This should be |
| 1074 | * a combination of {@link android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION}, |
| 1075 | * {@link android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION}, and |
| 1076 | * {@link android.content.Intent#FLAG_GRANT_PREFIX_URI_PERMISSION}. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1077 | * @see JobInfo#getClipData() |
| 1078 | * @see JobInfo#getClipGrantFlags() |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1079 | */ |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 1080 | public Builder setClipData(@Nullable ClipData clip, int grantFlags) { |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1081 | mClipData = clip; |
| 1082 | mClipGrantFlags = grantFlags; |
| 1083 | return this; |
| 1084 | } |
| 1085 | |
| 1086 | /** |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1087 | * Set basic description of the kind of network your job requires. If |
| 1088 | * you need more precise control over network capabilities, see |
| 1089 | * {@link #setRequiredNetwork(NetworkRequest)}. |
| 1090 | * <p> |
| 1091 | * If your job doesn't need a network connection, you don't need to call |
| 1092 | * this method, as the default value is {@link #NETWORK_TYPE_NONE}. |
| 1093 | * <p> |
| 1094 | * Calling this method defines network as a strict requirement for your |
| 1095 | * job. If the network requested is not available your job will never |
| 1096 | * run. See {@link #setOverrideDeadline(long)} to change this behavior. |
| 1097 | * Calling this method will override any requirements previously defined |
| 1098 | * by {@link #setRequiredNetwork(NetworkRequest)}; you typically only |
| 1099 | * want to call one of these methods. |
Jeff Sharkey | 76a0241 | 2017-10-24 16:55:04 -0600 | [diff] [blame] | 1100 | * <p class="note"> |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1101 | * When your job executes in |
Jeff Sharkey | 76a0241 | 2017-10-24 16:55:04 -0600 | [diff] [blame] | 1102 | * {@link JobService#onStartJob(JobParameters)}, be sure to use the |
| 1103 | * specific network returned by {@link JobParameters#getNetwork()}, |
| 1104 | * otherwise you'll use the default network which may not meet this |
| 1105 | * constraint. |
| 1106 | * |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1107 | * @see #setRequiredNetwork(NetworkRequest) |
| 1108 | * @see JobInfo#getNetworkType() |
Jeff Sharkey | 76a0241 | 2017-10-24 16:55:04 -0600 | [diff] [blame] | 1109 | * @see JobParameters#getNetwork() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1110 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 1111 | public Builder setRequiredNetworkType(@NetworkType int networkType) { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1112 | if (networkType == NETWORK_TYPE_NONE) { |
| 1113 | return setRequiredNetwork(null); |
| 1114 | } else { |
| 1115 | final NetworkRequest.Builder builder = new NetworkRequest.Builder(); |
| 1116 | |
| 1117 | // All types require validated Internet |
| 1118 | builder.addCapability(NET_CAPABILITY_INTERNET); |
| 1119 | builder.addCapability(NET_CAPABILITY_VALIDATED); |
| 1120 | builder.removeCapability(NET_CAPABILITY_NOT_VPN); |
| 1121 | |
| 1122 | if (networkType == NETWORK_TYPE_ANY) { |
| 1123 | // No other capabilities |
| 1124 | } else if (networkType == NETWORK_TYPE_UNMETERED) { |
| 1125 | builder.addCapability(NET_CAPABILITY_NOT_METERED); |
| 1126 | } else if (networkType == NETWORK_TYPE_NOT_ROAMING) { |
| 1127 | builder.addCapability(NET_CAPABILITY_NOT_ROAMING); |
| 1128 | } else if (networkType == NETWORK_TYPE_CELLULAR) { |
| 1129 | builder.addTransportType(TRANSPORT_CELLULAR); |
| 1130 | } |
| 1131 | |
| 1132 | return setRequiredNetwork(builder.build()); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Set detailed description of the kind of network your job requires. |
| 1138 | * <p> |
| 1139 | * If your job doesn't need a network connection, you don't need to call |
| 1140 | * this method, as the default is {@code null}. |
| 1141 | * <p> |
| 1142 | * Calling this method defines network as a strict requirement for your |
| 1143 | * job. If the network requested is not available your job will never |
| 1144 | * run. See {@link #setOverrideDeadline(long)} to change this behavior. |
| 1145 | * Calling this method will override any requirements previously defined |
| 1146 | * by {@link #setRequiredNetworkType(int)}; you typically only want to |
| 1147 | * call one of these methods. |
| 1148 | * <p class="note"> |
| 1149 | * When your job executes in |
| 1150 | * {@link JobService#onStartJob(JobParameters)}, be sure to use the |
| 1151 | * specific network returned by {@link JobParameters#getNetwork()}, |
| 1152 | * otherwise you'll use the default network which may not meet this |
| 1153 | * constraint. |
| 1154 | * |
| 1155 | * @param networkRequest The detailed description of the kind of network |
| 1156 | * this job requires, or {@code null} if no specific kind of |
| 1157 | * network is required. Defining a {@link NetworkSpecifier} |
| 1158 | * is only supported for jobs that aren't persisted. |
| 1159 | * @see #setRequiredNetworkType(int) |
| 1160 | * @see JobInfo#getRequiredNetwork() |
| 1161 | * @see JobParameters#getNetwork() |
| 1162 | */ |
| 1163 | public Builder setRequiredNetwork(@Nullable NetworkRequest networkRequest) { |
| 1164 | mNetworkRequest = networkRequest; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1165 | return this; |
| 1166 | } |
| 1167 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1168 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1169 | * @deprecated replaced by |
| 1170 | * {@link #setEstimatedNetworkBytes(long, long)}. |
| 1171 | * @removed |
| 1172 | */ |
| 1173 | @Deprecated |
| 1174 | public Builder setEstimatedNetworkBytes(@BytesLong long networkBytes) { |
| 1175 | return setEstimatedNetworkBytes(networkBytes, NETWORK_BYTES_UNKNOWN); |
| 1176 | } |
| 1177 | |
| 1178 | /** |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1179 | * Set the estimated size of network traffic that will be performed by |
| 1180 | * this job, in bytes. |
| 1181 | * <p> |
| 1182 | * Apps are encouraged to provide values that are as accurate as |
| 1183 | * possible, but when the exact size isn't available, an |
| 1184 | * order-of-magnitude estimate can be provided instead. Here are some |
| 1185 | * specific examples: |
| 1186 | * <ul> |
| 1187 | * <li>A job that is backing up a photo knows the exact size of that |
| 1188 | * photo, so it should provide that size as the estimate. |
| 1189 | * <li>A job that refreshes top news stories wouldn't know an exact |
| 1190 | * size, but if the size is expected to be consistently around 100KB, it |
| 1191 | * can provide that order-of-magnitude value as the estimate. |
| 1192 | * <li>A job that synchronizes email could end up using an extreme range |
| 1193 | * of data, from under 1KB when nothing has changed, to dozens of MB |
| 1194 | * when there are new emails with attachments. Jobs that cannot provide |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1195 | * reasonable estimates should use the sentinel value |
| 1196 | * {@link JobInfo#NETWORK_BYTES_UNKNOWN}. |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1197 | * </ul> |
| 1198 | * Note that the system may choose to delay jobs with large network |
| 1199 | * usage estimates when the device has a poor network connection, in |
| 1200 | * order to save battery. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1201 | * <p> |
| 1202 | * The values provided here only reflect the traffic that will be |
| 1203 | * performed by the base job; if you're using {@link JobWorkItem} then |
| 1204 | * you also need to define the network traffic used by each work item |
| 1205 | * when constructing them. |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1206 | * |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1207 | * @param downloadBytes The estimated size of network traffic that will |
| 1208 | * be downloaded by this job, in bytes. |
| 1209 | * @param uploadBytes The estimated size of network traffic that will be |
| 1210 | * uploaded by this job, in bytes. |
| 1211 | * @see JobInfo#getEstimatedNetworkDownloadBytes() |
| 1212 | * @see JobInfo#getEstimatedNetworkUploadBytes() |
| 1213 | * @see JobWorkItem#JobWorkItem(android.content.Intent, long, long) |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1214 | */ |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1215 | public Builder setEstimatedNetworkBytes(@BytesLong long downloadBytes, |
| 1216 | @BytesLong long uploadBytes) { |
| 1217 | mNetworkDownloadBytes = downloadBytes; |
| 1218 | mNetworkUploadBytes = uploadBytes; |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1219 | return this; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
Christopher Tate | 7815251 | 2017-10-02 17:07:07 -0700 | [diff] [blame] | 1223 | * Specify that to run this job, the device must be charging (or be a |
| 1224 | * non-battery-powered device connected to permanent power, such as Android TV |
| 1225 | * devices). This defaults to {@code false}. |
| 1226 | * |
| 1227 | * <p class="note">For purposes of running jobs, a battery-powered device |
| 1228 | * "charging" is not quite the same as simply being connected to power. If the |
| 1229 | * device is so busy that the battery is draining despite a power connection, jobs |
| 1230 | * with this constraint will <em>not</em> run. This can happen during some |
| 1231 | * common use cases such as video chat, particularly if the device is plugged in |
| 1232 | * to USB rather than to wall power. |
| 1233 | * |
| 1234 | * @param requiresCharging Pass {@code true} to require that the device be |
| 1235 | * charging in order to run the job. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1236 | * @see JobInfo#isRequireCharging() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1237 | */ |
| 1238 | public Builder setRequiresCharging(boolean requiresCharging) { |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 1239 | mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_CHARGING) |
| 1240 | | (requiresCharging ? CONSTRAINT_FLAG_CHARGING : 0); |
| 1241 | return this; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
| 1245 | * Specify that to run this job, the device's battery level must not be low. |
| 1246 | * This defaults to false. If true, the job will only run when the battery level |
| 1247 | * is not low, which is generally the point where the user is given a "low battery" |
| 1248 | * warning. |
| 1249 | * @param batteryNotLow Whether or not the device's battery level must not be low. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1250 | * @see JobInfo#isRequireBatteryNotLow() |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 1251 | */ |
| 1252 | public Builder setRequiresBatteryNotLow(boolean batteryNotLow) { |
| 1253 | mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_BATTERY_NOT_LOW) |
| 1254 | | (batteryNotLow ? CONSTRAINT_FLAG_BATTERY_NOT_LOW : 0); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1255 | return this; |
| 1256 | } |
| 1257 | |
| 1258 | /** |
Christopher Tate | 7815251 | 2017-10-02 17:07:07 -0700 | [diff] [blame] | 1259 | * When set {@code true}, ensure that this job will not run if the device is in active use. |
| 1260 | * The default state is {@code false}: that is, the for the job to be runnable even when |
| 1261 | * someone is interacting with the device. |
| 1262 | * |
| 1263 | * <p>This state is a loose definition provided by the system. In general, it means that |
| 1264 | * the device is not currently being used interactively, and has not been in use for some |
| 1265 | * time. As such, it is a good time to perform resource heavy jobs. Bear in mind that |
| 1266 | * battery usage will still be attributed to your application, and surfaced to the user in |
| 1267 | * battery stats.</p> |
| 1268 | * |
| 1269 | * <p class="note">Despite the similar naming, this job constraint is <em>not</em> |
| 1270 | * related to the system's "device idle" or "doze" states. This constraint only |
| 1271 | * determines whether a job is allowed to run while the device is directly in use. |
| 1272 | * |
| 1273 | * @param requiresDeviceIdle Pass {@code true} to prevent the job from running |
| 1274 | * while the device is being used interactively. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1275 | * @see JobInfo#isRequireDeviceIdle() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1276 | */ |
| 1277 | public Builder setRequiresDeviceIdle(boolean requiresDeviceIdle) { |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 1278 | mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_DEVICE_IDLE) |
| 1279 | | (requiresDeviceIdle ? CONSTRAINT_FLAG_DEVICE_IDLE : 0); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1280 | return this; |
| 1281 | } |
| 1282 | |
| 1283 | /** |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 1284 | * Specify that to run this job, the device's available storage must not be low. |
| 1285 | * This defaults to false. If true, the job will only run when the device is not |
| 1286 | * in a low storage state, which is generally the point where the user is given a |
| 1287 | * "low storage" warning. |
| 1288 | * @param storageNotLow Whether or not the device's available storage must not be low. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1289 | * @see JobInfo#isRequireStorageNotLow() |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 1290 | */ |
| 1291 | public Builder setRequiresStorageNotLow(boolean storageNotLow) { |
| 1292 | mConstraintFlags = (mConstraintFlags&~CONSTRAINT_FLAG_STORAGE_NOT_LOW) |
| 1293 | | (storageNotLow ? CONSTRAINT_FLAG_STORAGE_NOT_LOW : 0); |
| 1294 | return this; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1298 | * Add a new content: URI that will be monitored with a |
| 1299 | * {@link android.database.ContentObserver}, and will cause the job to execute if changed. |
| 1300 | * If you have any trigger content URIs associated with a job, it will not execute until |
| 1301 | * there has been a change report for one or more of them. |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 1302 | * |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1303 | * <p>Note that trigger URIs can not be used in combination with |
| 1304 | * {@link #setPeriodic(long)} or {@link #setPersisted(boolean)}. To continually monitor |
| 1305 | * for content changes, you need to schedule a new JobInfo observing the same URIs |
Dianne Hackborn | 532ea26 | 2017-03-17 17:50:55 -0700 | [diff] [blame] | 1306 | * before you finish execution of the JobService handling the most recent changes. |
| 1307 | * Following this pattern will ensure you do not lost any content changes: while your |
| 1308 | * job is running, the system will continue monitoring for content changes, and propagate |
| 1309 | * any it sees over to the next job you schedule.</p> |
| 1310 | * |
| 1311 | * <p>Because setting this property is not compatible with periodic or |
Dianne Hackborn | 46499a5 | 2016-03-09 17:57:48 -0800 | [diff] [blame] | 1312 | * persisted jobs, doing so will throw an {@link java.lang.IllegalArgumentException} when |
| 1313 | * {@link android.app.job.JobInfo.Builder#build()} is called.</p> |
Dianne Hackborn | c43a7f8 | 2016-06-01 10:48:43 -0700 | [diff] [blame] | 1314 | * |
| 1315 | * <p>The following example shows how this feature can be used to monitor for changes |
| 1316 | * in the photos on a device.</p> |
| 1317 | * |
| 1318 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/PhotosContentJob.java |
| 1319 | * job} |
| 1320 | * |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1321 | * @param uri The content: URI to monitor. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1322 | * @see JobInfo#getTriggerContentUris() |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1323 | */ |
| 1324 | public Builder addTriggerContentUri(@NonNull TriggerContentUri uri) { |
| 1325 | if (mTriggerContentUris == null) { |
| 1326 | mTriggerContentUris = new ArrayList<>(); |
| 1327 | } |
| 1328 | mTriggerContentUris.add(uri); |
| 1329 | return this; |
| 1330 | } |
| 1331 | |
| 1332 | /** |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 1333 | * Set the delay (in milliseconds) from when a content change is detected until |
| 1334 | * the job is scheduled. If there are more changes during that time, the delay |
| 1335 | * will be reset to start at the time of the most recent change. |
| 1336 | * @param durationMs Delay after most recent content change, in milliseconds. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1337 | * @see JobInfo#getTriggerContentUpdateDelay() |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 1338 | */ |
| 1339 | public Builder setTriggerContentUpdateDelay(long durationMs) { |
| 1340 | mTriggerContentUpdateDelay = durationMs; |
| 1341 | return this; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * Set the maximum total delay (in milliseconds) that is allowed from the first |
| 1346 | * time a content change is detected until the job is scheduled. |
| 1347 | * @param durationMs Delay after initial content change, in milliseconds. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1348 | * @see JobInfo#getTriggerContentMaxDelay() |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 1349 | */ |
| 1350 | public Builder setTriggerContentMaxDelay(long durationMs) { |
| 1351 | mTriggerContentMaxDelay = durationMs; |
| 1352 | return this; |
| 1353 | } |
| 1354 | |
| 1355 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1356 | * Specify that this job should recur with the provided interval, not more than once per |
| 1357 | * period. You have no control over when within this interval this job will be executed, |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1358 | * only the guarantee that it will be executed at most once within this interval. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1359 | * Setting this function on the builder with {@link #setMinimumLatency(long)} or |
| 1360 | * {@link #setOverrideDeadline(long)} will result in an error. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1361 | * @param intervalMillis Millisecond interval for which this job will repeat. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1362 | * @see JobInfo#getIntervalMillis() |
| 1363 | * @see JobInfo#getFlexMillis() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1364 | */ |
| 1365 | public Builder setPeriodic(long intervalMillis) { |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 1366 | return setPeriodic(intervalMillis, intervalMillis); |
| 1367 | } |
| 1368 | |
| 1369 | /** |
| 1370 | * Specify that this job should recur with the provided interval and flex. The job can |
| 1371 | * execute at any time in a window of flex length at the end of the period. |
Shreyas Basarge | e96c3b7 | 2016-01-29 19:25:51 +0000 | [diff] [blame] | 1372 | * @param intervalMillis Millisecond interval for which this job will repeat. A minimum |
Christopher Tate | a9b4f3f | 2016-05-18 13:57:37 -0700 | [diff] [blame] | 1373 | * value of {@link #getMinPeriodMillis()} is enforced. |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 1374 | * @param flexMillis Millisecond flex for this job. Flex is clamped to be at least |
Christopher Tate | a9b4f3f | 2016-05-18 13:57:37 -0700 | [diff] [blame] | 1375 | * {@link #getMinFlexMillis()} or 5 percent of the period, whichever is |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 1376 | * higher. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1377 | * @see JobInfo#getIntervalMillis() |
| 1378 | * @see JobInfo#getFlexMillis() |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 1379 | */ |
| 1380 | public Builder setPeriodic(long intervalMillis, long flexMillis) { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1381 | final long minPeriod = getMinPeriodMillis(); |
| 1382 | if (intervalMillis < minPeriod) { |
| 1383 | Log.w(TAG, "Requested interval " + formatDuration(intervalMillis) + " for job " |
| 1384 | + mJobId + " is too small; raising to " + formatDuration(minPeriod)); |
| 1385 | intervalMillis = minPeriod; |
| 1386 | } |
| 1387 | |
| 1388 | final long percentClamp = 5 * intervalMillis / 100; |
| 1389 | final long minFlex = Math.max(percentClamp, getMinFlexMillis()); |
| 1390 | if (flexMillis < minFlex) { |
| 1391 | Log.w(TAG, "Requested flex " + formatDuration(flexMillis) + " for job " + mJobId |
| 1392 | + " is too small; raising to " + formatDuration(minFlex)); |
| 1393 | flexMillis = minFlex; |
| 1394 | } |
| 1395 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1396 | mIsPeriodic = true; |
| 1397 | mIntervalMillis = intervalMillis; |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 1398 | mFlexMillis = flexMillis; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 1399 | mHasEarlyConstraint = mHasLateConstraint = true; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1400 | return this; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1404 | * Specify that this job should be delayed by the provided amount of time. |
| 1405 | * Because it doesn't make sense setting this property on a periodic job, doing so will |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1406 | * throw an {@link java.lang.IllegalArgumentException} when |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1407 | * {@link android.app.job.JobInfo.Builder#build()} is called. |
| 1408 | * @param minLatencyMillis Milliseconds before which this job will not be considered for |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1409 | * execution. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1410 | * @see JobInfo#getMinLatencyMillis() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1411 | */ |
| 1412 | public Builder setMinimumLatency(long minLatencyMillis) { |
| 1413 | mMinLatencyMillis = minLatencyMillis; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 1414 | mHasEarlyConstraint = true; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1415 | return this; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1419 | * Set deadline which is the maximum scheduling latency. The job will be run by this |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1420 | * deadline even if other requirements are not met. Because it doesn't make sense setting |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1421 | * this property on a periodic job, doing so will throw an |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1422 | * {@link java.lang.IllegalArgumentException} when |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1423 | * {@link android.app.job.JobInfo.Builder#build()} is called. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1424 | * @see JobInfo#getMaxExecutionDelayMillis() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1425 | */ |
| 1426 | public Builder setOverrideDeadline(long maxExecutionDelayMillis) { |
| 1427 | mMaxExecutionDelayMillis = maxExecutionDelayMillis; |
Matthew Williams | 9b9244b6 | 2014-05-14 11:06:04 -0700 | [diff] [blame] | 1428 | mHasLateConstraint = true; |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1429 | return this; |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * Set up the back-off/retry policy. |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 1434 | * This defaults to some respectable values: {30 seconds, Exponential}. We cap back-off at |
| 1435 | * 5hrs. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1436 | * Note that trying to set a backoff criteria for a job with |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1437 | * {@link #setRequiresDeviceIdle(boolean)} will throw an exception when you call build(). |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1438 | * This is because back-off typically does not make sense for these types of jobs. See |
| 1439 | * {@link android.app.job.JobService#jobFinished(android.app.job.JobParameters, boolean)} |
| 1440 | * for more description of the return value for the case of a job executing while in idle |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1441 | * mode. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1442 | * @param initialBackoffMillis Millisecond time interval to wait initially when job has |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1443 | * failed. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1444 | * @see JobInfo#getInitialBackoffMillis() |
| 1445 | * @see JobInfo#getBackoffPolicy() |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1446 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 1447 | public Builder setBackoffCriteria(long initialBackoffMillis, |
| 1448 | @BackoffPolicy int backoffPolicy) { |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1449 | final long minBackoff = getMinBackoffMillis(); |
| 1450 | if (initialBackoffMillis < minBackoff) { |
| 1451 | Log.w(TAG, "Requested backoff " + formatDuration(initialBackoffMillis) + " for job " |
| 1452 | + mJobId + " is too small; raising to " + formatDuration(minBackoff)); |
| 1453 | initialBackoffMillis = minBackoff; |
| 1454 | } |
| 1455 | |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1456 | mBackoffPolicySet = true; |
| 1457 | mInitialBackoffMillis = initialBackoffMillis; |
| 1458 | mBackoffPolicy = backoffPolicy; |
| 1459 | return this; |
| 1460 | } |
| 1461 | |
| 1462 | /** |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 1463 | * Setting this to true indicates that this job is important while the scheduling app |
| 1464 | * is in the foreground or on the temporary whitelist for background restrictions. |
| 1465 | * This means that the system will relax doze restrictions on this job during this time. |
| 1466 | * |
| 1467 | * Apps should use this flag only for short jobs that are essential for the app to function |
| 1468 | * properly in the foreground. |
| 1469 | * |
| 1470 | * Note that once the scheduling app is no longer whitelisted from background restrictions |
| 1471 | * and in the background, or the job failed due to unsatisfied constraints, |
| 1472 | * this job should be expected to behave like other jobs without this flag. |
| 1473 | * |
| 1474 | * @param importantWhileForeground whether to relax doze restrictions for this job when the |
| 1475 | * app is in the foreground. False by default. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1476 | * @see JobInfo#isImportantWhileForeground() |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 1477 | */ |
| 1478 | public Builder setImportantWhileForeground(boolean importantWhileForeground) { |
| 1479 | if (importantWhileForeground) { |
| 1480 | mFlags |= FLAG_IMPORTANT_WHILE_FOREGROUND; |
| 1481 | } else { |
| 1482 | mFlags &= (~FLAG_IMPORTANT_WHILE_FOREGROUND); |
| 1483 | } |
| 1484 | return this; |
| 1485 | } |
| 1486 | |
| 1487 | /** |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1488 | * @removed |
| 1489 | * @deprecated replaced with {@link #setPrefetch(boolean)} |
| 1490 | */ |
| 1491 | @Deprecated |
| 1492 | public Builder setIsPrefetch(boolean isPrefetch) { |
| 1493 | return setPrefetch(isPrefetch); |
| 1494 | } |
| 1495 | |
| 1496 | /** |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 1497 | * Setting this to true indicates that this job is designed to prefetch |
| 1498 | * content that will make a material improvement to the experience of |
| 1499 | * the specific user of this device. For example, fetching top headlines |
| 1500 | * of interest to the current user. |
| 1501 | * <p> |
| 1502 | * The system may use this signal to relax the network constraints you |
| 1503 | * originally requested, such as allowing a |
| 1504 | * {@link JobInfo#NETWORK_TYPE_UNMETERED} job to run over a metered |
| 1505 | * network when there is a surplus of metered data available. The system |
| 1506 | * may also use this signal in combination with end user usage patterns |
| 1507 | * to ensure data is prefetched before the user launches your app. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1508 | * @see JobInfo#isPrefetch() |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 1509 | */ |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1510 | public Builder setPrefetch(boolean prefetch) { |
| 1511 | if (prefetch) { |
| 1512 | mFlags |= FLAG_PREFETCH; |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 1513 | } else { |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1514 | mFlags &= (~FLAG_PREFETCH); |
Jeff Sharkey | 9252b34 | 2018-01-19 07:58:35 +0900 | [diff] [blame] | 1515 | } |
| 1516 | return this; |
| 1517 | } |
| 1518 | |
| 1519 | /** |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 1520 | * Set whether or not to persist this job across device reboots. |
| 1521 | * |
| 1522 | * @param isPersisted True to indicate that the job will be written to |
| 1523 | * disk and loaded at boot. |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1524 | * @see JobInfo#isPersisted() |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 1525 | */ |
Jeff Sharkey | 30e06bb | 2017-04-24 11:18:03 -0600 | [diff] [blame] | 1526 | @RequiresPermission(android.Manifest.permission.RECEIVE_BOOT_COMPLETED) |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 1527 | public Builder setPersisted(boolean isPersisted) { |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 1528 | mIsPersisted = isPersisted; |
| 1529 | return this; |
| 1530 | } |
| 1531 | |
| 1532 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1533 | * @return The job object to hand to the JobScheduler. This object is immutable. |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1534 | */ |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1535 | public JobInfo build() { |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 1536 | // Allow jobs with no constraints - What am I, a database? |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 1537 | if (!mHasEarlyConstraint && !mHasLateConstraint && mConstraintFlags == 0 && |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1538 | mNetworkRequest == null && |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1539 | mTriggerContentUris == null) { |
Matthew Williams | bafeeb9 | 2014-08-08 11:51:06 -0700 | [diff] [blame] | 1540 | throw new IllegalArgumentException("You're trying to build a job with no " + |
| 1541 | "constraints, this is not allowed."); |
| 1542 | } |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1543 | // Check that network estimates require network type |
Jeff Sharkey | 8474ca0 | 2018-03-26 19:10:02 -0600 | [diff] [blame] | 1544 | if ((mNetworkDownloadBytes > 0 || mNetworkUploadBytes > 0) && mNetworkRequest == null) { |
Jeff Sharkey | caa3f8d | 2017-10-25 16:12:00 -0600 | [diff] [blame] | 1545 | throw new IllegalArgumentException( |
| 1546 | "Can't provide estimated network usage without requiring a network"); |
| 1547 | } |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1548 | // We can't serialize network specifiers |
| 1549 | if (mIsPersisted && mNetworkRequest != null |
| 1550 | && mNetworkRequest.networkCapabilities.getNetworkSpecifier() != null) { |
| 1551 | throw new IllegalArgumentException( |
| 1552 | "Network specifiers aren't supported for persistent jobs"); |
| 1553 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1554 | // Check that a deadline was not set on a periodic job. |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1555 | if (mIsPeriodic) { |
| 1556 | if (mMaxExecutionDelayMillis != 0L) { |
| 1557 | throw new IllegalArgumentException("Can't call setOverrideDeadline() on a " + |
| 1558 | "periodic job."); |
| 1559 | } |
| 1560 | if (mMinLatencyMillis != 0L) { |
| 1561 | throw new IllegalArgumentException("Can't call setMinimumLatency() on a " + |
| 1562 | "periodic job"); |
| 1563 | } |
| 1564 | if (mTriggerContentUris != null) { |
| 1565 | throw new IllegalArgumentException("Can't call addTriggerContentUri() on a " + |
| 1566 | "periodic job"); |
| 1567 | } |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1568 | } |
Dianne Hackborn | a47223f | 2017-03-30 13:49:13 -0700 | [diff] [blame] | 1569 | if (mIsPersisted) { |
| 1570 | if (mTriggerContentUris != null) { |
| 1571 | throw new IllegalArgumentException("Can't call addTriggerContentUri() on a " + |
| 1572 | "persisted job"); |
| 1573 | } |
| 1574 | if (!mTransientExtras.isEmpty()) { |
| 1575 | throw new IllegalArgumentException("Can't call setTransientExtras() on a " + |
| 1576 | "persisted job"); |
| 1577 | } |
| 1578 | if (mClipData != null) { |
| 1579 | throw new IllegalArgumentException("Can't call setClipData() on a " + |
| 1580 | "persisted job"); |
| 1581 | } |
Dianne Hackborn | ba60473 | 2016-02-10 17:05:10 -0800 | [diff] [blame] | 1582 | } |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 1583 | if ((mFlags & FLAG_IMPORTANT_WHILE_FOREGROUND) != 0 && mHasEarlyConstraint) { |
| 1584 | throw new IllegalArgumentException("An important while foreground job cannot " |
| 1585 | + "have a time delay"); |
| 1586 | } |
Dianne Hackborn | a06ec6a | 2017-02-13 10:08:42 -0800 | [diff] [blame] | 1587 | if (mBackoffPolicySet && (mConstraintFlags & CONSTRAINT_FLAG_DEVICE_IDLE) != 0) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1588 | throw new IllegalArgumentException("An idle mode job will not respect any" + |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1589 | " back-off policy, so calling setBackoffCriteria with" + |
| 1590 | " setRequiresDeviceIdle is an error."); |
| 1591 | } |
Jeff Sharkey | d0fff2e | 2017-11-07 16:55:06 -0700 | [diff] [blame] | 1592 | return new JobInfo(this); |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1593 | } |
| 1594 | } |
Matthew Williams | 6e31c5c | 2014-04-11 15:49:16 -0700 | [diff] [blame] | 1595 | } |