Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -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 | |
| 17 | package com.android.server.job.controllers; |
| 18 | |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 19 | import android.app.AppGlobals; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 20 | import android.app.job.JobInfo; |
| 21 | import android.content.ComponentName; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 22 | import android.net.Uri; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 23 | import android.os.PersistableBundle; |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 24 | import android.os.RemoteException; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 25 | import android.os.SystemClock; |
| 26 | import android.os.UserHandle; |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 27 | import android.text.format.DateUtils; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 28 | import android.util.ArraySet; |
| 29 | import android.util.TimeUtils; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 30 | |
| 31 | import java.io.PrintWriter; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Uniquely identifies a job internally. |
| 35 | * Created from the public {@link android.app.job.JobInfo} object when it lands on the scheduler. |
| 36 | * Contains current state of the requirements of the job, as well as a function to evaluate |
| 37 | * whether it's ready to run. |
| 38 | * This object is shared among the various controllers - hence why the different fields are atomic. |
| 39 | * This isn't strictly necessary because each controller is only interested in a specific field, |
| 40 | * and the receivers that are listening for global state change will all run on the main looper, |
| 41 | * but we don't enforce that so this is safer. |
| 42 | * @hide |
| 43 | */ |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 44 | public final class JobStatus { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 45 | public static final long NO_LATEST_RUNTIME = Long.MAX_VALUE; |
| 46 | public static final long NO_EARLIEST_RUNTIME = 0L; |
| 47 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 48 | static final int CONSTRAINT_CHARGING = 1<<0; |
| 49 | static final int CONSTRAINT_TIMING_DELAY = 1<<1; |
| 50 | static final int CONSTRAINT_DEADLINE = 1<<2; |
| 51 | static final int CONSTRAINT_IDLE = 1<<3; |
| 52 | static final int CONSTRAINT_UNMETERED = 1<<4; |
| 53 | static final int CONSTRAINT_CONNECTIVITY = 1<<5; |
| 54 | static final int CONSTRAINT_APP_NOT_IDLE = 1<<6; |
| 55 | static final int CONSTRAINT_CONTENT_TRIGGER = 1<<7; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 56 | static final int CONSTRAINT_DEVICE_NOT_DOZING = 1<<8; |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 57 | static final int CONSTRAINT_NOT_ROAMING = 1<<9; |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 58 | |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 59 | // Soft override: ignore constraints like time that don't affect API availability |
| 60 | public static final int OVERRIDE_SOFT = 1; |
| 61 | // Full override: ignore all constraints including API-affecting like connectivity |
| 62 | public static final int OVERRIDE_FULL = 2; |
| 63 | |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 64 | /** If not specified, trigger update delay is 10 seconds. */ |
| 65 | public static final long DEFAULT_TRIGGER_UPDATE_DELAY = 10*1000; |
| 66 | |
| 67 | /** The minimum possible update delay is 1/2 second. */ |
| 68 | public static final long MIN_TRIGGER_UPDATE_DELAY = 500; |
| 69 | |
| 70 | /** If not specified, trigger maxumum delay is 2 minutes. */ |
| 71 | public static final long DEFAULT_TRIGGER_MAX_DELAY = 2*60*1000; |
| 72 | |
| 73 | /** The minimum possible update delay is 1 second. */ |
| 74 | public static final long MIN_TRIGGER_MAX_DELAY = 1000; |
| 75 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 76 | final JobInfo job; |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 77 | /** Uid of the package requesting this job. */ |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 78 | final int callingUid; |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 79 | final String batteryName; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 80 | |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 81 | final String sourcePackageName; |
| 82 | final int sourceUserId; |
| 83 | final int sourceUid; |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 84 | final String sourceTag; |
| 85 | |
| 86 | final String tag; |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 87 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 88 | /** |
| 89 | * Earliest point in the future at which this job will be eligible to run. A value of 0 |
| 90 | * indicates there is no delay constraint. See {@link #hasTimingDelayConstraint()}. |
| 91 | */ |
| 92 | private final long earliestRunTimeElapsedMillis; |
| 93 | /** |
| 94 | * Latest point in the future at which this job must be run. A value of {@link Long#MAX_VALUE} |
| 95 | * indicates there is no deadline constraint. See {@link #hasDeadlineConstraint()}. |
| 96 | */ |
| 97 | private final long latestRunTimeElapsedMillis; |
| 98 | |
| 99 | /** How many times this job has failed, used to compute back-off. */ |
| 100 | private final int numFailures; |
| 101 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 102 | // Constraints. |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 103 | final int requiredConstraints; |
| 104 | int satisfiedConstraints = 0; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 105 | |
| 106 | // These are filled in by controllers when preparing for execution. |
| 107 | public ArraySet<Uri> changedUris; |
| 108 | public ArraySet<String> changedAuthorities; |
| 109 | |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 110 | public int lastEvaluatedPriority; |
| 111 | |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 112 | // Used by shell commands |
| 113 | public int overrideState = 0; |
| 114 | |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 115 | /** |
| 116 | * For use only by ContentObserverController: state it is maintaining about content URIs |
| 117 | * being observed. |
| 118 | */ |
| 119 | ContentObserverController.JobInstance contentObserverJobInstance; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 120 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 121 | /** Provide a handle to the service that this job will be run on. */ |
| 122 | public int getServiceToken() { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 123 | return callingUid; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 126 | private JobStatus(JobInfo job, int callingUid, String sourcePackageName, |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 127 | int sourceUserId, String tag, int numFailures, long earliestRunTimeElapsedMillis, |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 128 | long latestRunTimeElapsedMillis) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 129 | this.job = job; |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 130 | this.callingUid = callingUid; |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 131 | |
| 132 | int tempSourceUid = -1; |
| 133 | if (sourceUserId != -1 && sourcePackageName != null) { |
| 134 | try { |
| 135 | tempSourceUid = AppGlobals.getPackageManager().getPackageUid(sourcePackageName, 0, |
| 136 | sourceUserId); |
| 137 | } catch (RemoteException ex) { |
| 138 | // Can't happen, PackageManager runs in the same process. |
| 139 | } |
| 140 | } |
| 141 | if (tempSourceUid == -1) { |
| 142 | this.sourceUid = callingUid; |
| 143 | this.sourceUserId = UserHandle.getUserId(callingUid); |
| 144 | this.sourcePackageName = job.getService().getPackageName(); |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 145 | this.sourceTag = null; |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 146 | } else { |
| 147 | this.sourceUid = tempSourceUid; |
| 148 | this.sourceUserId = sourceUserId; |
| 149 | this.sourcePackageName = sourcePackageName; |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 150 | this.sourceTag = tag; |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 151 | } |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 152 | |
Shreyas Basarge | eda34e4 | 2016-04-26 00:14:02 +0100 | [diff] [blame] | 153 | this.batteryName = this.sourceTag != null |
| 154 | ? this.sourceTag + ":" + job.getService().getPackageName() |
| 155 | : job.getService().flattenToShortString(); |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 156 | this.tag = "*job*/" + this.batteryName; |
| 157 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 158 | this.earliestRunTimeElapsedMillis = earliestRunTimeElapsedMillis; |
| 159 | this.latestRunTimeElapsedMillis = latestRunTimeElapsedMillis; |
| 160 | this.numFailures = numFailures; |
| 161 | |
| 162 | int requiredConstraints = 0; |
| 163 | if (job.getNetworkType() == JobInfo.NETWORK_TYPE_ANY) { |
| 164 | requiredConstraints |= CONSTRAINT_CONNECTIVITY; |
| 165 | } |
| 166 | if (job.getNetworkType() == JobInfo.NETWORK_TYPE_UNMETERED) { |
| 167 | requiredConstraints |= CONSTRAINT_UNMETERED; |
| 168 | } |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 169 | if (job.getNetworkType() == JobInfo.NETWORK_TYPE_NOT_ROAMING) { |
| 170 | requiredConstraints |= CONSTRAINT_NOT_ROAMING; |
| 171 | } |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 172 | if (job.isRequireCharging()) { |
| 173 | requiredConstraints |= CONSTRAINT_CHARGING; |
| 174 | } |
| 175 | if (earliestRunTimeElapsedMillis != NO_EARLIEST_RUNTIME) { |
| 176 | requiredConstraints |= CONSTRAINT_TIMING_DELAY; |
| 177 | } |
| 178 | if (latestRunTimeElapsedMillis != NO_LATEST_RUNTIME) { |
| 179 | requiredConstraints |= CONSTRAINT_DEADLINE; |
| 180 | } |
| 181 | if (job.isRequireDeviceIdle()) { |
| 182 | requiredConstraints |= CONSTRAINT_IDLE; |
| 183 | } |
| 184 | if (job.getTriggerContentUris() != null) { |
| 185 | requiredConstraints |= CONSTRAINT_CONTENT_TRIGGER; |
| 186 | } |
| 187 | this.requiredConstraints = requiredConstraints; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Matthew Williams | 0cc7654 | 2015-10-16 21:04:51 -0700 | [diff] [blame] | 190 | /** Copy constructor. */ |
| 191 | public JobStatus(JobStatus jobStatus) { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 192 | this(jobStatus.getJob(), jobStatus.getUid(), |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 193 | jobStatus.getSourcePackageName(), jobStatus.getSourceUserId(), |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 194 | jobStatus.getSourceTag(), jobStatus.getNumFailures(), |
| 195 | jobStatus.getEarliestRunTime(), jobStatus.getLatestRunTimeElapsed()); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Create a new JobStatus that was loaded from disk. We ignore the provided |
| 200 | * {@link android.app.job.JobInfo} time criteria because we can load a persisted periodic job |
| 201 | * from the {@link com.android.server.job.JobStore} and still want to respect its |
| 202 | * wallclock runtime rather than resetting it on every boot. |
| 203 | * We consider a freshly loaded job to no longer be in back-off. |
| 204 | */ |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 205 | public JobStatus(JobInfo job, int callingUid, String sourcePackageName, int sourceUserId, |
| 206 | String sourceTag, long earliestRunTimeElapsedMillis, long latestRunTimeElapsedMillis) { |
| 207 | this(job, callingUid, sourcePackageName, sourceUserId, sourceTag, 0, |
| 208 | earliestRunTimeElapsedMillis, latestRunTimeElapsedMillis); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** Create a new job to be rescheduled with the provided parameters. */ |
| 212 | public JobStatus(JobStatus rescheduling, long newEarliestRuntimeElapsedMillis, |
| 213 | long newLatestRuntimeElapsedMillis, int backoffAttempt) { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 214 | this(rescheduling.job, rescheduling.getUid(), |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 215 | rescheduling.getSourcePackageName(), rescheduling.getSourceUserId(), |
| 216 | rescheduling.getSourceTag(), backoffAttempt, newEarliestRuntimeElapsedMillis, |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 217 | newLatestRuntimeElapsedMillis); |
| 218 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 219 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 220 | /** |
| 221 | * Create a newly scheduled job. |
| 222 | * @param callingUid Uid of the package that scheduled this job. |
| 223 | * @param sourcePackageName Package name on whose behalf this job is scheduled. Null indicates |
| 224 | * the calling package is the source. |
| 225 | * @param sourceUserId User id for whom this job is scheduled. -1 indicates this is same as the |
| 226 | */ |
| 227 | public static JobStatus createFromJobInfo(JobInfo job, int callingUid, String sourcePackageName, |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 228 | int sourceUserId, String tag) { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 229 | final long elapsedNow = SystemClock.elapsedRealtime(); |
| 230 | final long earliestRunTimeElapsedMillis, latestRunTimeElapsedMillis; |
| 231 | if (job.isPeriodic()) { |
| 232 | latestRunTimeElapsedMillis = elapsedNow + job.getIntervalMillis(); |
| 233 | earliestRunTimeElapsedMillis = latestRunTimeElapsedMillis - job.getFlexMillis(); |
| 234 | } else { |
| 235 | earliestRunTimeElapsedMillis = job.hasEarlyConstraint() ? |
| 236 | elapsedNow + job.getMinLatencyMillis() : NO_EARLIEST_RUNTIME; |
| 237 | latestRunTimeElapsedMillis = job.hasLateConstraint() ? |
| 238 | elapsedNow + job.getMaxExecutionDelayMillis() : NO_LATEST_RUNTIME; |
| 239 | } |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 240 | return new JobStatus(job, callingUid, sourcePackageName, sourceUserId, tag, 0, |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 241 | earliestRunTimeElapsedMillis, latestRunTimeElapsedMillis); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | public JobInfo getJob() { |
| 245 | return job; |
| 246 | } |
| 247 | |
| 248 | public int getJobId() { |
| 249 | return job.getId(); |
| 250 | } |
| 251 | |
| 252 | public int getNumFailures() { |
| 253 | return numFailures; |
| 254 | } |
| 255 | |
| 256 | public ComponentName getServiceComponent() { |
| 257 | return job.getService(); |
| 258 | } |
| 259 | |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 260 | public String getSourcePackageName() { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 261 | return sourcePackageName; |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | public int getSourceUid() { |
| 265 | return sourceUid; |
| 266 | } |
| 267 | |
| 268 | public int getSourceUserId() { |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 269 | return sourceUserId; |
| 270 | } |
| 271 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 272 | public int getUserId() { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 273 | return UserHandle.getUserId(callingUid); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 276 | public String getSourceTag() { |
| 277 | return sourceTag; |
| 278 | } |
| 279 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 280 | public int getUid() { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 281 | return callingUid; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Dianne Hackborn | 1085ff6 | 2016-02-23 17:04:58 -0800 | [diff] [blame] | 284 | public String getBatteryName() { |
| 285 | return batteryName; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | public String getTag() { |
| 289 | return tag; |
| 290 | } |
| 291 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 292 | public PersistableBundle getExtras() { |
| 293 | return job.getExtras(); |
| 294 | } |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 295 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 296 | public int getPriority() { |
| 297 | return job.getPriority(); |
| 298 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 299 | |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 300 | public int getFlags() { |
| 301 | return job.getFlags(); |
| 302 | } |
| 303 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 304 | public boolean hasConnectivityConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 305 | return (requiredConstraints&CONSTRAINT_CONNECTIVITY) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | public boolean hasUnmeteredConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 309 | return (requiredConstraints&CONSTRAINT_UNMETERED) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 312 | public boolean hasNotRoamingConstraint() { |
| 313 | return (requiredConstraints&CONSTRAINT_NOT_ROAMING) != 0; |
| 314 | } |
| 315 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 316 | public boolean hasChargingConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 317 | return (requiredConstraints&CONSTRAINT_CHARGING) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | public boolean hasTimingDelayConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 321 | return (requiredConstraints&CONSTRAINT_TIMING_DELAY) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | public boolean hasDeadlineConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 325 | return (requiredConstraints&CONSTRAINT_DEADLINE) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | public boolean hasIdleConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 329 | return (requiredConstraints&CONSTRAINT_IDLE) != 0; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 332 | public boolean hasContentTriggerConstraint() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 333 | return (requiredConstraints&CONSTRAINT_CONTENT_TRIGGER) != 0; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 334 | } |
| 335 | |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 336 | public long getTriggerContentUpdateDelay() { |
| 337 | long time = job.getTriggerContentUpdateDelay(); |
| 338 | if (time < 0) { |
| 339 | return DEFAULT_TRIGGER_UPDATE_DELAY; |
| 340 | } |
| 341 | return Math.max(time, MIN_TRIGGER_UPDATE_DELAY); |
| 342 | } |
| 343 | |
| 344 | public long getTriggerContentMaxDelay() { |
| 345 | long time = job.getTriggerContentMaxDelay(); |
| 346 | if (time < 0) { |
| 347 | return DEFAULT_TRIGGER_MAX_DELAY; |
| 348 | } |
| 349 | return Math.max(time, MIN_TRIGGER_MAX_DELAY); |
| 350 | } |
| 351 | |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 352 | public boolean isPersisted() { |
| 353 | return job.isPersisted(); |
| 354 | } |
| 355 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 356 | public long getEarliestRunTime() { |
| 357 | return earliestRunTimeElapsedMillis; |
| 358 | } |
| 359 | |
| 360 | public long getLatestRunTimeElapsed() { |
| 361 | return latestRunTimeElapsedMillis; |
| 362 | } |
| 363 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 364 | boolean setChargingConstraintSatisfied(boolean state) { |
| 365 | return setConstraintSatisfied(CONSTRAINT_CHARGING, state); |
| 366 | } |
| 367 | |
| 368 | boolean setTimingDelayConstraintSatisfied(boolean state) { |
| 369 | return setConstraintSatisfied(CONSTRAINT_TIMING_DELAY, state); |
| 370 | } |
| 371 | |
| 372 | boolean setDeadlineConstraintSatisfied(boolean state) { |
| 373 | return setConstraintSatisfied(CONSTRAINT_DEADLINE, state); |
| 374 | } |
| 375 | |
| 376 | boolean setIdleConstraintSatisfied(boolean state) { |
| 377 | return setConstraintSatisfied(CONSTRAINT_IDLE, state); |
| 378 | } |
| 379 | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 380 | boolean setConnectivityConstraintSatisfied(boolean state) { |
| 381 | return setConstraintSatisfied(CONSTRAINT_CONNECTIVITY, state); |
| 382 | } |
| 383 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 384 | boolean setUnmeteredConstraintSatisfied(boolean state) { |
| 385 | return setConstraintSatisfied(CONSTRAINT_UNMETERED, state); |
| 386 | } |
| 387 | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 388 | boolean setNotRoamingConstraintSatisfied(boolean state) { |
| 389 | return setConstraintSatisfied(CONSTRAINT_NOT_ROAMING, state); |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | boolean setAppNotIdleConstraintSatisfied(boolean state) { |
| 393 | return setConstraintSatisfied(CONSTRAINT_APP_NOT_IDLE, state); |
| 394 | } |
| 395 | |
| 396 | boolean setContentTriggerConstraintSatisfied(boolean state) { |
| 397 | return setConstraintSatisfied(CONSTRAINT_CONTENT_TRIGGER, state); |
| 398 | } |
| 399 | |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 400 | boolean setDeviceNotDozingConstraintSatisfied(boolean state) { |
| 401 | return setConstraintSatisfied(CONSTRAINT_DEVICE_NOT_DOZING, state); |
| 402 | } |
| 403 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 404 | boolean setConstraintSatisfied(int constraint, boolean state) { |
| 405 | boolean old = (satisfiedConstraints&constraint) != 0; |
| 406 | if (old == state) { |
| 407 | return false; |
| 408 | } |
| 409 | satisfiedConstraints = (satisfiedConstraints&~constraint) | (state ? constraint : 0); |
| 410 | return true; |
| 411 | } |
| 412 | |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 413 | public boolean shouldDump(int filterUid) { |
| 414 | return filterUid == -1 || UserHandle.getAppId(getUid()) == filterUid |
| 415 | || UserHandle.getAppId(getSourceUid()) == filterUid; |
| 416 | } |
| 417 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 418 | /** |
Matthew Williams | 03a4da6 | 2014-09-10 17:32:18 -0700 | [diff] [blame] | 419 | * @return Whether or not this job is ready to run, based on its requirements. This is true if |
| 420 | * the constraints are satisfied <strong>or</strong> the deadline on the job has expired. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 421 | */ |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 422 | public boolean isReady() { |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 423 | // Deadline constraint trumps other constraints (except for periodic jobs where deadline |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 424 | // is an implementation detail. A periodic job should only run if its constraints are |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 425 | // satisfied). |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 426 | // AppNotIdle implicit constraint must be satisfied |
| 427 | // DeviceNotDozing implicit constraint must be satisfied |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 428 | final boolean deadlineSatisfied = (!job.isPeriodic() && hasDeadlineConstraint() |
| 429 | && (satisfiedConstraints & CONSTRAINT_DEADLINE) != 0); |
| 430 | final boolean notIdle = (satisfiedConstraints & CONSTRAINT_APP_NOT_IDLE) != 0; |
| 431 | final boolean notDozing = (satisfiedConstraints & CONSTRAINT_DEVICE_NOT_DOZING) != 0 |
| 432 | || (job.getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) != 0; |
| 433 | return (isConstraintsSatisfied() || deadlineSatisfied) && notIdle && notDozing; |
Matthew Williams | 03a4da6 | 2014-09-10 17:32:18 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 436 | static final int CONSTRAINTS_OF_INTEREST = |
| 437 | CONSTRAINT_CHARGING | CONSTRAINT_TIMING_DELAY | |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 438 | CONSTRAINT_CONNECTIVITY | CONSTRAINT_UNMETERED | CONSTRAINT_NOT_ROAMING | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 439 | CONSTRAINT_IDLE | CONSTRAINT_CONTENT_TRIGGER; |
| 440 | |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 441 | // Soft override covers all non-"functional" constraints |
| 442 | static final int SOFT_OVERRIDE_CONSTRAINTS = |
| 443 | CONSTRAINT_CHARGING | CONSTRAINT_TIMING_DELAY | CONSTRAINT_IDLE; |
| 444 | |
Matthew Williams | 03a4da6 | 2014-09-10 17:32:18 -0700 | [diff] [blame] | 445 | /** |
| 446 | * @return Whether the constraints set on this job are satisfied. |
| 447 | */ |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 448 | public boolean isConstraintsSatisfied() { |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 449 | if (overrideState == OVERRIDE_FULL) { |
| 450 | // force override: the job is always runnable |
| 451 | return true; |
| 452 | } |
| 453 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 454 | final int req = requiredConstraints & CONSTRAINTS_OF_INTEREST; |
Christopher Tate | 5d34605 | 2016-03-08 12:56:08 -0800 | [diff] [blame] | 455 | |
| 456 | int sat = satisfiedConstraints & CONSTRAINTS_OF_INTEREST; |
| 457 | if (overrideState == OVERRIDE_SOFT) { |
| 458 | // override: pretend all 'soft' requirements are satisfied |
| 459 | sat |= (requiredConstraints & SOFT_OVERRIDE_CONSTRAINTS); |
| 460 | } |
| 461 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 462 | return (sat & req) == req; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | public boolean matches(int uid, int jobId) { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 466 | return this.job.getId() == jobId && this.callingUid == uid; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | @Override |
| 470 | public String toString() { |
| 471 | return String.valueOf(hashCode()).substring(0, 3) + ".." |
Christopher Tate | 1b8b3aa | 2014-06-20 13:17:01 -0700 | [diff] [blame] | 472 | + ":[" + job.getService() |
| 473 | + ",jId=" + job.getId() |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 474 | + ",u" + getUserId() |
| 475 | + ",R=(" + formatRunTime(earliestRunTimeElapsedMillis, NO_EARLIEST_RUNTIME) |
| 476 | + "," + formatRunTime(latestRunTimeElapsedMillis, NO_LATEST_RUNTIME) + ")" |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 477 | + ",N=" + job.getNetworkType() + ",C=" + job.isRequireCharging() |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 478 | + ",I=" + job.isRequireDeviceIdle() |
| 479 | + ",U=" + (job.getTriggerContentUris() != null) |
| 480 | + ",F=" + numFailures + ",P=" + job.isPersisted() |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 481 | + ",ANI=" + ((satisfiedConstraints&CONSTRAINT_APP_NOT_IDLE) != 0) |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 482 | + ",DND=" + ((satisfiedConstraints&CONSTRAINT_DEVICE_NOT_DOZING) != 0) |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 483 | + (isReady() ? "(READY)" : "") |
| 484 | + "]"; |
| 485 | } |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 486 | |
| 487 | private String formatRunTime(long runtime, long defaultValue) { |
| 488 | if (runtime == defaultValue) { |
| 489 | return "none"; |
| 490 | } else { |
| 491 | long elapsedNow = SystemClock.elapsedRealtime(); |
| 492 | long nextRuntime = runtime - elapsedNow; |
| 493 | if (nextRuntime > 0) { |
| 494 | return DateUtils.formatElapsedTime(nextRuntime / 1000); |
| 495 | } else { |
| 496 | return "-" + DateUtils.formatElapsedTime(nextRuntime / -1000); |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Convenience function to identify a job uniquely without pulling all the data that |
| 503 | * {@link #toString()} returns. |
| 504 | */ |
| 505 | public String toShortString() { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 506 | StringBuilder sb = new StringBuilder(); |
| 507 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 508 | sb.append(" jId="); |
| 509 | sb.append(job.getId()); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 510 | sb.append(' '); |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 511 | UserHandle.formatUid(sb, callingUid); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 512 | sb.append(' '); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 513 | sb.append(batteryName); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 514 | return sb.toString(); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 517 | void dumpConstraints(PrintWriter pw, int constraints) { |
| 518 | if ((constraints&CONSTRAINT_CHARGING) != 0) { |
| 519 | pw.print(" CHARGING"); |
| 520 | } |
| 521 | if ((constraints&CONSTRAINT_TIMING_DELAY) != 0) { |
| 522 | pw.print(" TIMING_DELAY"); |
| 523 | } |
| 524 | if ((constraints&CONSTRAINT_DEADLINE) != 0) { |
| 525 | pw.print(" DEADLINE"); |
| 526 | } |
| 527 | if ((constraints&CONSTRAINT_IDLE) != 0) { |
| 528 | pw.print(" IDLE"); |
| 529 | } |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 530 | if ((constraints&CONSTRAINT_CONNECTIVITY) != 0) { |
| 531 | pw.print(" CONNECTIVITY"); |
| 532 | } |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 533 | if ((constraints&CONSTRAINT_UNMETERED) != 0) { |
| 534 | pw.print(" UNMETERED"); |
| 535 | } |
Jeff Sharkey | f07c7b9 | 2016-04-22 09:50:16 -0600 | [diff] [blame] | 536 | if ((constraints&CONSTRAINT_NOT_ROAMING) != 0) { |
| 537 | pw.print(" NOT_ROAMING"); |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 538 | } |
| 539 | if ((constraints&CONSTRAINT_APP_NOT_IDLE) != 0) { |
| 540 | pw.print(" APP_NOT_IDLE"); |
| 541 | } |
| 542 | if ((constraints&CONSTRAINT_CONTENT_TRIGGER) != 0) { |
| 543 | pw.print(" CONTENT_TRIGGER"); |
| 544 | } |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 545 | if ((constraints&CONSTRAINT_DEVICE_NOT_DOZING) != 0) { |
| 546 | pw.print(" DEVICE_NOT_DOZING"); |
| 547 | } |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 550 | // Dumpsys infrastructure |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 551 | public void dump(PrintWriter pw, String prefix, boolean full) { |
Shreyas Basarge | 8e64e2e | 2016-02-12 15:49:31 +0000 | [diff] [blame] | 552 | pw.print(prefix); UserHandle.formatUid(pw, callingUid); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 553 | pw.print(" tag="); pw.println(tag); |
Christopher Tate | f973a7b | 2014-08-29 12:54:08 -0700 | [diff] [blame] | 554 | pw.print(prefix); |
Shreyas Basarge | d8bf6b9 | 2016-02-02 23:45:14 +0000 | [diff] [blame] | 555 | pw.print("Source: uid="); UserHandle.formatUid(pw, getSourceUid()); |
| 556 | pw.print(" user="); pw.print(getSourceUserId()); |
| 557 | pw.print(" pkg="); pw.println(getSourcePackageName()); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 558 | if (full) { |
| 559 | pw.print(prefix); pw.println("JobInfo:"); pw.print(prefix); |
| 560 | pw.print(" Service: "); pw.println(job.getService().flattenToShortString()); |
| 561 | if (job.isPeriodic()) { |
| 562 | pw.print(prefix); pw.print(" PERIODIC: interval="); |
| 563 | TimeUtils.formatDuration(job.getIntervalMillis(), pw); |
| 564 | pw.print(" flex="); TimeUtils.formatDuration(job.getFlexMillis(), pw); |
| 565 | pw.println(); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 566 | } |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 567 | if (job.isPersisted()) { |
| 568 | pw.print(prefix); pw.println(" PERSISTED"); |
| 569 | } |
| 570 | if (job.getPriority() != 0) { |
| 571 | pw.print(prefix); pw.print(" Priority: "); pw.println(job.getPriority()); |
| 572 | } |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 573 | if (job.getFlags() != 0) { |
| 574 | pw.print(prefix); pw.print(" Flags: "); |
| 575 | pw.println(Integer.toHexString(job.getFlags())); |
| 576 | } |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 577 | pw.print(prefix); pw.print(" Requires: charging="); |
| 578 | pw.print(job.isRequireCharging()); pw.print(" deviceIdle="); |
| 579 | pw.println(job.isRequireDeviceIdle()); |
| 580 | if (job.getTriggerContentUris() != null) { |
| 581 | pw.print(prefix); pw.println(" Trigger content URIs:"); |
| 582 | for (int i = 0; i < job.getTriggerContentUris().length; i++) { |
| 583 | JobInfo.TriggerContentUri trig = job.getTriggerContentUris()[i]; |
| 584 | pw.print(prefix); pw.print(" "); |
| 585 | pw.print(Integer.toHexString(trig.getFlags())); |
| 586 | pw.print(' '); pw.println(trig.getUri()); |
| 587 | } |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 588 | if (job.getTriggerContentUpdateDelay() >= 0) { |
| 589 | pw.print(prefix); pw.print(" Trigger update delay: "); |
| 590 | TimeUtils.formatDuration(job.getTriggerContentUpdateDelay(), pw); |
| 591 | pw.println(); |
| 592 | } |
| 593 | if (job.getTriggerContentMaxDelay() >= 0) { |
| 594 | pw.print(prefix); pw.print(" Trigger max delay: "); |
| 595 | TimeUtils.formatDuration(job.getTriggerContentMaxDelay(), pw); |
| 596 | pw.println(); |
| 597 | } |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 598 | } |
| 599 | if (job.getNetworkType() != JobInfo.NETWORK_TYPE_NONE) { |
| 600 | pw.print(prefix); pw.print(" Network type: "); pw.println(job.getNetworkType()); |
| 601 | } |
| 602 | if (job.getMinLatencyMillis() != 0) { |
| 603 | pw.print(prefix); pw.print(" Minimum latency: "); |
| 604 | TimeUtils.formatDuration(job.getMinLatencyMillis(), pw); |
| 605 | pw.println(); |
| 606 | } |
| 607 | if (job.getMaxExecutionDelayMillis() != 0) { |
| 608 | pw.print(prefix); pw.print(" Max execution delay: "); |
| 609 | TimeUtils.formatDuration(job.getMaxExecutionDelayMillis(), pw); |
| 610 | pw.println(); |
| 611 | } |
| 612 | pw.print(prefix); pw.print(" Backoff: policy="); pw.print(job.getBackoffPolicy()); |
| 613 | pw.print(" initial="); TimeUtils.formatDuration(job.getInitialBackoffMillis(), pw); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 614 | pw.println(); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 615 | if (job.hasEarlyConstraint()) { |
| 616 | pw.print(prefix); pw.println(" Has early constraint"); |
| 617 | } |
| 618 | if (job.hasLateConstraint()) { |
| 619 | pw.print(prefix); pw.println(" Has late constraint"); |
| 620 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 621 | } |
Dianne Hackborn | b0001f6 | 2016-02-16 10:30:33 -0800 | [diff] [blame] | 622 | pw.print(prefix); pw.print("Required constraints:"); |
| 623 | dumpConstraints(pw, requiredConstraints); |
| 624 | pw.println(); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 625 | if (full) { |
| 626 | pw.print(prefix); pw.print("Satisfied constraints:"); |
| 627 | dumpConstraints(pw, satisfiedConstraints); |
| 628 | pw.println(); |
Jeff Sharkey | 1b6519b | 2016-04-28 15:33:18 -0600 | [diff] [blame] | 629 | pw.print(prefix); pw.print("Unsatisfied constraints:"); |
| 630 | dumpConstraints(pw, (requiredConstraints & ~satisfiedConstraints)); |
| 631 | pw.println(); |
Dianne Hackborn | 970510b | 2016-02-24 16:56:42 -0800 | [diff] [blame] | 632 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 633 | if (changedAuthorities != null) { |
| 634 | pw.print(prefix); pw.println("Changed authorities:"); |
| 635 | for (int i=0; i<changedAuthorities.size(); i++) { |
| 636 | pw.print(prefix); pw.print(" "); pw.println(changedAuthorities.valueAt(i)); |
| 637 | } |
| 638 | if (changedUris != null) { |
| 639 | pw.print(prefix); pw.println("Changed URIs:"); |
| 640 | for (int i=0; i<changedUris.size(); i++) { |
| 641 | pw.print(prefix); pw.print(" "); pw.println(changedUris.valueAt(i)); |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | pw.print(prefix); pw.print("Earliest run time: "); |
| 646 | pw.println(formatRunTime(earliestRunTimeElapsedMillis, NO_EARLIEST_RUNTIME)); |
| 647 | pw.print(prefix); pw.print("Latest run time: "); |
| 648 | pw.println(formatRunTime(latestRunTimeElapsedMillis, NO_LATEST_RUNTIME)); |
| 649 | if (numFailures != 0) { |
| 650 | pw.print(prefix); pw.print("Num failures: "); pw.println(numFailures); |
| 651 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 652 | } |
| 653 | } |