blob: cb9e43a13684c41d804cdc6cd258440f5b10004a [file] [log] [blame]
Matthew Williams6de79e22014-05-01 10:47:00 -07001/*
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 Tate7060b042014-06-09 19:50:00 -070017package com.android.server.job.controllers;
Matthew Williams6de79e22014-05-01 10:47:00 -070018
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -070019import static com.android.server.job.JobSchedulerService.sElapsedRealtimeClock;
20
Matthew Williams6de79e22014-05-01 10:47:00 -070021import android.app.AlarmManager;
Christopher Tate2fcbe212015-12-09 16:00:37 -080022import android.app.AlarmManager.OnAlarmListener;
Matthew Williams6de79e22014-05-01 10:47:00 -070023import android.content.Context;
Dianne Hackborne9a988c2016-05-27 17:59:40 -070024import android.os.UserHandle;
25import android.os.WorkSource;
Matthew Williamseffacfa2014-06-05 20:56:40 -070026import android.util.Slog;
Dianne Hackborne9a988c2016-05-27 17:59:40 -070027import android.util.TimeUtils;
Matthew Williams6de79e22014-05-01 10:47:00 -070028
Christopher Tate7060b042014-06-09 19:50:00 -070029import com.android.server.job.JobSchedulerService;
30import com.android.server.job.StateChangedListener;
Matthew Williams6de79e22014-05-01 10:47:00 -070031
Matthew Williamseffacfa2014-06-05 20:56:40 -070032import java.io.PrintWriter;
Matthew Williams6de79e22014-05-01 10:47:00 -070033import java.util.Iterator;
34import java.util.LinkedList;
35import java.util.List;
36import java.util.ListIterator;
37
38/**
Christopher Tate7060b042014-06-09 19:50:00 -070039 * This class sets an alarm for the next expiring job, and determines whether a job's minimum
Matthew Williams6de79e22014-05-01 10:47:00 -070040 * delay has been satisfied.
41 */
Dianne Hackborn6466c1c2017-06-13 10:33:19 -070042public final class TimeController extends StateController {
Christopher Tate7060b042014-06-09 19:50:00 -070043 private static final String TAG = "JobScheduler.Time";
Matthew Williams6de79e22014-05-01 10:47:00 -070044
Christopher Tate2fcbe212015-12-09 16:00:37 -080045 /** Deadline alarm tag for logging purposes */
Dianne Hackborne9a988c2016-05-27 17:59:40 -070046 private final String DEADLINE_TAG = "*job.deadline*";
Christopher Tate2fcbe212015-12-09 16:00:37 -080047 /** Delay alarm tag for logging purposes */
Dianne Hackborne9a988c2016-05-27 17:59:40 -070048 private final String DELAY_TAG = "*job.delay*";
Matthew Williams6de79e22014-05-01 10:47:00 -070049
Christopher Tate7060b042014-06-09 19:50:00 -070050 private long mNextJobExpiredElapsedMillis;
Matthew Williams6de79e22014-05-01 10:47:00 -070051 private long mNextDelayExpiredElapsedMillis;
52
53 private AlarmManager mAlarmService = null;
Christopher Tate7060b042014-06-09 19:50:00 -070054 /** List of tracked jobs, sorted asc. by deadline */
Dianne Hackbornf9bac162017-04-20 17:17:48 -070055 private final List<JobStatus> mTrackedJobs = new LinkedList<>();
Matthew Williams9b9244b62014-05-14 11:06:04 -070056 /** Singleton. */
57 private static TimeController mSingleton;
Matthew Williams6de79e22014-05-01 10:47:00 -070058
Christopher Tate7060b042014-06-09 19:50:00 -070059 public static synchronized TimeController get(JobSchedulerService jms) {
Matthew Williams9b9244b62014-05-14 11:06:04 -070060 if (mSingleton == null) {
Dianne Hackborn33d31c52016-02-16 10:30:33 -080061 mSingleton = new TimeController(jms, jms.getContext(), jms.getLock());
Matthew Williams9b9244b62014-05-14 11:06:04 -070062 }
63 return mSingleton;
64 }
65
Dianne Hackborn33d31c52016-02-16 10:30:33 -080066 private TimeController(StateChangedListener stateChangedListener, Context context,
67 Object lock) {
68 super(stateChangedListener, context, lock);
Christopher Tate2fcbe212015-12-09 16:00:37 -080069
Christopher Tate7060b042014-06-09 19:50:00 -070070 mNextJobExpiredElapsedMillis = Long.MAX_VALUE;
Matthew Williamseffacfa2014-06-05 20:56:40 -070071 mNextDelayExpiredElapsedMillis = Long.MAX_VALUE;
Matthew Williams6de79e22014-05-01 10:47:00 -070072 }
73
74 /**
Christopher Tate7060b042014-06-09 19:50:00 -070075 * Check if the job has a timing constraint, and if so determine where to insert it in our
Matthew Williams6de79e22014-05-01 10:47:00 -070076 * list.
77 */
78 @Override
Dianne Hackbornb0001f62016-02-16 10:30:33 -080079 public void maybeStartTrackingJobLocked(JobStatus job, JobStatus lastJob) {
80 if (job.hasTimingDelayConstraint() || job.hasDeadlineConstraint()) {
Dianne Hackborn141f11c2016-04-05 15:46:12 -070081 maybeStopTrackingJobLocked(job, null, false);
Dianne Hackbornf9bac162017-04-20 17:17:48 -070082
83 // First: check the constraints now, because if they are already satisfied
84 // then there is no need to track it. This gives us a fast path for a common
85 // pattern of having a job with a 0 deadline constraint ("run immediately").
86 // Unlike most controllers, once one of our constraints has been satisfied, it
87 // will never be unsatisfied (our time base can not go backwards).
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -070088 final long nowElapsedMillis = sElapsedRealtimeClock.millis();
Dianne Hackbornf9bac162017-04-20 17:17:48 -070089 if (job.hasDeadlineConstraint() && evaluateDeadlineConstraint(job, nowElapsedMillis)) {
90 return;
91 } else if (job.hasTimingDelayConstraint() && evaluateTimingDelayConstraint(job,
92 nowElapsedMillis)) {
93 return;
94 }
95
Dianne Hackbornb0001f62016-02-16 10:30:33 -080096 boolean isInsert = false;
97 ListIterator<JobStatus> it = mTrackedJobs.listIterator(mTrackedJobs.size());
98 while (it.hasPrevious()) {
99 JobStatus ts = it.previous();
100 if (ts.getLatestRunTimeElapsed() < job.getLatestRunTimeElapsed()) {
101 // Insert
102 isInsert = true;
103 break;
Matthew Williams6de79e22014-05-01 10:47:00 -0700104 }
105 }
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800106 if (isInsert) {
107 it.next();
108 }
109 it.add(job);
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700110 job.setTrackingController(JobStatus.TRACKING_TIME);
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800111 maybeUpdateAlarmsLocked(
112 job.hasTimingDelayConstraint() ? job.getEarliestRunTime() : Long.MAX_VALUE,
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700113 job.hasDeadlineConstraint() ? job.getLatestRunTimeElapsed() : Long.MAX_VALUE,
Adam Lesinskic746b382017-10-13 14:31:08 -0700114 new WorkSource(job.getSourceUid(), job.getSourcePackageName()));
Matthew Williams6de79e22014-05-01 10:47:00 -0700115 }
116 }
117
118 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700119 * When we stop tracking a job, we only need to update our alarms if the job we're no longer
Matthew Williamseffacfa2014-06-05 20:56:40 -0700120 * tracking was the one our alarms were based off of.
Matthew Williams6de79e22014-05-01 10:47:00 -0700121 */
122 @Override
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700123 public void maybeStopTrackingJobLocked(JobStatus job, JobStatus incomingJob,
124 boolean forUpdate) {
125 if (job.clearTrackingController(JobStatus.TRACKING_TIME)) {
126 if (mTrackedJobs.remove(job)) {
127 checkExpiredDelaysAndResetAlarm();
128 checkExpiredDeadlinesAndResetAlarm();
129 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700130 }
131 }
132
133 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700134 * Determines whether this controller can stop tracking the given job.
135 * The controller is no longer interested in a job once its time constraint is satisfied, and
136 * the job's deadline is fulfilled - unlike other controllers a time constraint can't toggle
Matthew Williams6de79e22014-05-01 10:47:00 -0700137 * back and forth.
138 */
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800139 private boolean canStopTrackingJobLocked(JobStatus job) {
Christopher Tate7060b042014-06-09 19:50:00 -0700140 return (!job.hasTimingDelayConstraint() ||
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800141 (job.satisfiedConstraints&JobStatus.CONSTRAINT_TIMING_DELAY) != 0) &&
Christopher Tate7060b042014-06-09 19:50:00 -0700142 (!job.hasDeadlineConstraint() ||
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800143 (job.satisfiedConstraints&JobStatus.CONSTRAINT_DEADLINE) != 0);
Matthew Williams6de79e22014-05-01 10:47:00 -0700144 }
145
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800146 private void ensureAlarmServiceLocked() {
Matthew Williams6de79e22014-05-01 10:47:00 -0700147 if (mAlarmService == null) {
148 mAlarmService = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
149 }
150 }
151
152 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700153 * Checks list of jobs for ones that have an expired deadline, sending them to the JobScheduler
Matthew Williamseffacfa2014-06-05 20:56:40 -0700154 * if so, removing them from this list, and updating the alarm for the next expiry time.
Matthew Williams6de79e22014-05-01 10:47:00 -0700155 */
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800156 private void checkExpiredDeadlinesAndResetAlarm() {
157 synchronized (mLock) {
158 long nextExpiryTime = Long.MAX_VALUE;
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700159 int nextExpiryUid = 0;
Adam Lesinskic746b382017-10-13 14:31:08 -0700160 String nextExpiryPackageName = null;
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700161 final long nowElapsedMillis = sElapsedRealtimeClock.millis();
Matthew Williams6de79e22014-05-01 10:47:00 -0700162
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800163 Iterator<JobStatus> it = mTrackedJobs.iterator();
164 while (it.hasNext()) {
165 JobStatus job = it.next();
166 if (!job.hasDeadlineConstraint()) {
167 continue;
168 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700169
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700170 if (evaluateDeadlineConstraint(job, nowElapsedMillis)) {
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800171 mStateChangedListener.onRunJobNow(job);
172 it.remove();
173 } else { // Sorted by expiry time, so take the next one and stop.
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700174 nextExpiryTime = job.getLatestRunTimeElapsed();
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700175 nextExpiryUid = job.getSourceUid();
Adam Lesinskic746b382017-10-13 14:31:08 -0700176 nextExpiryPackageName = job.getSourcePackageName();
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800177 break;
178 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700179 }
Adam Lesinskic746b382017-10-13 14:31:08 -0700180 setDeadlineExpiredAlarmLocked(nextExpiryTime, nextExpiryPackageName != null
181 ? new WorkSource(nextExpiryUid, nextExpiryPackageName)
182 : new WorkSource(nextExpiryUid));
Matthew Williams6de79e22014-05-01 10:47:00 -0700183 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700184 }
185
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700186 private boolean evaluateDeadlineConstraint(JobStatus job, long nowElapsedMillis) {
187 final long jobDeadline = job.getLatestRunTimeElapsed();
188
189 if (jobDeadline <= nowElapsedMillis) {
190 if (job.hasTimingDelayConstraint()) {
191 job.setTimingDelayConstraintSatisfied(true);
192 }
193 job.setDeadlineConstraintSatisfied(true);
194 return true;
195 }
196 return false;
197 }
198
Matthew Williams6de79e22014-05-01 10:47:00 -0700199 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700200 * Handles alarm that notifies us that a job's delay has expired. Iterates through the list of
201 * tracked jobs and marks them as ready as appropriate.
Matthew Williams6de79e22014-05-01 10:47:00 -0700202 */
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800203 private void checkExpiredDelaysAndResetAlarm() {
204 synchronized (mLock) {
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700205 final long nowElapsedMillis = sElapsedRealtimeClock.millis();
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800206 long nextDelayTime = Long.MAX_VALUE;
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700207 int nextDelayUid = 0;
Adam Lesinskic746b382017-10-13 14:31:08 -0700208 String nextDelayPackageName = null;
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800209 boolean ready = false;
210 Iterator<JobStatus> it = mTrackedJobs.iterator();
211 while (it.hasNext()) {
212 final JobStatus job = it.next();
213 if (!job.hasTimingDelayConstraint()) {
214 continue;
Matthew Williams6de79e22014-05-01 10:47:00 -0700215 }
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700216 if (evaluateTimingDelayConstraint(job, nowElapsedMillis)) {
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800217 if (canStopTrackingJobLocked(job)) {
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800218 it.remove();
219 }
220 if (job.isReady()) {
221 ready = true;
222 }
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700223 } else if (!job.isConstraintSatisfied(JobStatus.CONSTRAINT_TIMING_DELAY)) {
224 // If this job still doesn't have its delay constraint satisfied,
225 // then see if it is the next upcoming delay time for the alarm.
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700226 final long jobDelayTime = job.getEarliestRunTime();
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800227 if (nextDelayTime > jobDelayTime) {
228 nextDelayTime = jobDelayTime;
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700229 nextDelayUid = job.getSourceUid();
Adam Lesinskic746b382017-10-13 14:31:08 -0700230 nextDelayPackageName = job.getSourcePackageName();
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800231 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700232 }
233 }
Dianne Hackborn33d31c52016-02-16 10:30:33 -0800234 if (ready) {
235 mStateChangedListener.onControllerStateChanged();
236 }
Adam Lesinskic746b382017-10-13 14:31:08 -0700237 setDelayExpiredAlarmLocked(nextDelayTime, nextDelayPackageName != null
238 ? new WorkSource(nextDelayUid, nextDelayPackageName)
239 : new WorkSource(nextDelayUid));
Matthew Williams6de79e22014-05-01 10:47:00 -0700240 }
Matthew Williamseffacfa2014-06-05 20:56:40 -0700241 }
242
Dianne Hackbornf9bac162017-04-20 17:17:48 -0700243 private boolean evaluateTimingDelayConstraint(JobStatus job, long nowElapsedMillis) {
244 final long jobDelayTime = job.getEarliestRunTime();
245 if (jobDelayTime <= nowElapsedMillis) {
246 job.setTimingDelayConstraintSatisfied(true);
247 return true;
248 }
249 return false;
250 }
251
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700252 private void maybeUpdateAlarmsLocked(long delayExpiredElapsed, long deadlineExpiredElapsed,
Adam Lesinskic746b382017-10-13 14:31:08 -0700253 WorkSource ws) {
Matthew Williamseffacfa2014-06-05 20:56:40 -0700254 if (delayExpiredElapsed < mNextDelayExpiredElapsedMillis) {
Adam Lesinskic746b382017-10-13 14:31:08 -0700255 setDelayExpiredAlarmLocked(delayExpiredElapsed, ws);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700256 }
Christopher Tate7060b042014-06-09 19:50:00 -0700257 if (deadlineExpiredElapsed < mNextJobExpiredElapsedMillis) {
Adam Lesinskic746b382017-10-13 14:31:08 -0700258 setDeadlineExpiredAlarmLocked(deadlineExpiredElapsed, ws);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700259 }
260 }
261
262 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700263 * Set an alarm with the {@link android.app.AlarmManager} for the next time at which a job's
Matthew Williamseffacfa2014-06-05 20:56:40 -0700264 * delay will expire.
Shreyas Basarge4b7e339c2016-01-20 16:25:07 +0000265 * This alarm <b>will</b> wake up the phone.
Matthew Williamseffacfa2014-06-05 20:56:40 -0700266 */
Adam Lesinskic746b382017-10-13 14:31:08 -0700267 private void setDelayExpiredAlarmLocked(long alarmTimeElapsedMillis, WorkSource ws) {
Matthew Williamsa9f993c2014-09-11 11:31:05 -0700268 alarmTimeElapsedMillis = maybeAdjustAlarmTime(alarmTimeElapsedMillis);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700269 mNextDelayExpiredElapsedMillis = alarmTimeElapsedMillis;
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800270 updateAlarmWithListenerLocked(DELAY_TAG, mNextDelayExpiredListener,
Adam Lesinskic746b382017-10-13 14:31:08 -0700271 mNextDelayExpiredElapsedMillis, ws);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700272 }
273
274 /**
Christopher Tate7060b042014-06-09 19:50:00 -0700275 * Set an alarm with the {@link android.app.AlarmManager} for the next time at which a job's
Matthew Williamseffacfa2014-06-05 20:56:40 -0700276 * deadline will expire.
277 * This alarm <b>will</b> wake up the phone.
278 */
Adam Lesinskic746b382017-10-13 14:31:08 -0700279 private void setDeadlineExpiredAlarmLocked(long alarmTimeElapsedMillis, WorkSource ws) {
Matthew Williamsa9f993c2014-09-11 11:31:05 -0700280 alarmTimeElapsedMillis = maybeAdjustAlarmTime(alarmTimeElapsedMillis);
Christopher Tate7060b042014-06-09 19:50:00 -0700281 mNextJobExpiredElapsedMillis = alarmTimeElapsedMillis;
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800282 updateAlarmWithListenerLocked(DEADLINE_TAG, mDeadlineExpiredListener,
Adam Lesinskic746b382017-10-13 14:31:08 -0700283 mNextJobExpiredElapsedMillis, ws);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700284 }
285
Matthew Williamsa9f993c2014-09-11 11:31:05 -0700286 private long maybeAdjustAlarmTime(long proposedAlarmTimeElapsedMillis) {
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700287 final long earliestWakeupTimeElapsed = sElapsedRealtimeClock.millis();
Matthew Williamsa9f993c2014-09-11 11:31:05 -0700288 if (proposedAlarmTimeElapsedMillis < earliestWakeupTimeElapsed) {
289 return earliestWakeupTimeElapsed;
290 }
291 return proposedAlarmTimeElapsedMillis;
292 }
293
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800294 private void updateAlarmWithListenerLocked(String tag, OnAlarmListener listener,
Adam Lesinskic746b382017-10-13 14:31:08 -0700295 long alarmTimeElapsed, WorkSource ws) {
Dianne Hackbornb0001f62016-02-16 10:30:33 -0800296 ensureAlarmServiceLocked();
Matthew Williamseffacfa2014-06-05 20:56:40 -0700297 if (alarmTimeElapsed == Long.MAX_VALUE) {
Christopher Tate2fcbe212015-12-09 16:00:37 -0800298 mAlarmService.cancel(listener);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700299 } else {
300 if (DEBUG) {
Christopher Tate2fcbe212015-12-09 16:00:37 -0800301 Slog.d(TAG, "Setting " + tag + " for: " + alarmTimeElapsed);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700302 }
Shreyas Basarge4b7e339c2016-01-20 16:25:07 +0000303 mAlarmService.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, alarmTimeElapsed,
Adam Lesinskic746b382017-10-13 14:31:08 -0700304 AlarmManager.WINDOW_HEURISTIC, 0, tag, listener, null, ws);
Matthew Williamseffacfa2014-06-05 20:56:40 -0700305 }
Matthew Williams6de79e22014-05-01 10:47:00 -0700306 }
307
Christopher Tate2fcbe212015-12-09 16:00:37 -0800308 // Job/delay expiration alarm handling
309
310 private final OnAlarmListener mDeadlineExpiredListener = new OnAlarmListener() {
Matthew Williams6de79e22014-05-01 10:47:00 -0700311 @Override
Christopher Tate2fcbe212015-12-09 16:00:37 -0800312 public void onAlarm() {
Matthew Williamseffacfa2014-06-05 20:56:40 -0700313 if (DEBUG) {
Christopher Tate2fcbe212015-12-09 16:00:37 -0800314 Slog.d(TAG, "Deadline-expired alarm fired");
Matthew Williamseffacfa2014-06-05 20:56:40 -0700315 }
Christopher Tate2fcbe212015-12-09 16:00:37 -0800316 checkExpiredDeadlinesAndResetAlarm();
317 }
318 };
319
320 private final OnAlarmListener mNextDelayExpiredListener = new OnAlarmListener() {
321 @Override
322 public void onAlarm() {
323 if (DEBUG) {
324 Slog.d(TAG, "Delay-expired alarm fired");
Matthew Williams6de79e22014-05-01 10:47:00 -0700325 }
Christopher Tate2fcbe212015-12-09 16:00:37 -0800326 checkExpiredDelaysAndResetAlarm();
Matthew Williams6de79e22014-05-01 10:47:00 -0700327 }
328 };
Matthew Williamseffacfa2014-06-05 20:56:40 -0700329
330 @Override
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -0700331 public void dumpControllerStateLocked(PrintWriter pw, int filterUid) {
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700332 final long nowElapsed = sElapsedRealtimeClock.millis();
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700333 pw.print("Alarms: now=");
Jeff Sharkeyd0fff2e2017-11-07 16:55:06 -0700334 pw.print(sElapsedRealtimeClock.millis());
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700335 pw.println();
336 pw.print("Next delay alarm in ");
337 TimeUtils.formatDuration(mNextDelayExpiredElapsedMillis, nowElapsed, pw);
338 pw.println();
339 pw.print("Next deadline alarm in ");
340 TimeUtils.formatDuration(mNextJobExpiredElapsedMillis, nowElapsed, pw);
341 pw.println();
342 pw.print("Tracking ");
343 pw.print(mTrackedJobs.size());
344 pw.println(":");
Christopher Tate7060b042014-06-09 19:50:00 -0700345 for (JobStatus ts : mTrackedJobs) {
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -0700346 if (!ts.shouldDump(filterUid)) {
347 continue;
348 }
Dianne Hackborne9a988c2016-05-27 17:59:40 -0700349 pw.print(" #");
350 ts.printUniqueId(pw);
351 pw.print(" from ");
352 UserHandle.formatUid(pw, ts.getSourceUid());
353 pw.print(": Delay=");
354 if (ts.hasTimingDelayConstraint()) {
355 TimeUtils.formatDuration(ts.getEarliestRunTime(), nowElapsed, pw);
356 } else {
357 pw.print("N/A");
358 }
359 pw.print(", Deadline=");
360 if (ts.hasDeadlineConstraint()) {
361 TimeUtils.formatDuration(ts.getLatestRunTimeElapsed(), nowElapsed, pw);
362 } else {
363 pw.print("N/A");
364 }
365 pw.println();
Matthew Williamseffacfa2014-06-05 20:56:40 -0700366 }
367 }
368}