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; |
| 18 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 19 | import java.io.FileDescriptor; |
| 20 | import java.io.PrintWriter; |
| 21 | import java.util.ArrayList; |
| 22 | import java.util.Iterator; |
| 23 | import java.util.List; |
| 24 | |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 25 | import android.app.ActivityManager; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 26 | import android.app.ActivityManagerNative; |
Christopher Tate | 5568f54 | 2014-06-18 13:53:31 -0700 | [diff] [blame] | 27 | import android.app.AppGlobals; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 28 | import android.app.IUidObserver; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 29 | import android.app.job.JobInfo; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 30 | import android.app.job.JobParameters; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 31 | import android.app.job.JobScheduler; |
| 32 | import android.app.job.JobService; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 33 | import android.app.job.IJobScheduler; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
| 35 | import android.content.ComponentName; |
| 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
| 38 | import android.content.IntentFilter; |
Christopher Tate | 5568f54 | 2014-06-18 13:53:31 -0700 | [diff] [blame] | 39 | import android.content.pm.IPackageManager; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 41 | import android.content.pm.ServiceInfo; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 42 | import android.os.BatteryStats; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 43 | import android.os.Binder; |
| 44 | import android.os.Handler; |
| 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 47 | import android.os.PowerManager; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 48 | import android.os.RemoteException; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 49 | import android.os.ServiceManager; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 50 | import android.os.SystemClock; |
| 51 | import android.os.UserHandle; |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 52 | import android.os.Process; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 53 | import android.util.ArraySet; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 54 | import android.util.Slog; |
| 55 | import android.util.SparseArray; |
| 56 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 57 | import com.android.internal.app.IBatteryStats; |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 58 | import com.android.server.DeviceIdleController; |
| 59 | import com.android.server.LocalServices; |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 60 | import com.android.server.job.controllers.AppIdleController; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 61 | import com.android.server.job.controllers.BatteryController; |
| 62 | import com.android.server.job.controllers.ConnectivityController; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 63 | import com.android.server.job.controllers.ContentObserverController; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 64 | import com.android.server.job.controllers.IdleController; |
| 65 | import com.android.server.job.controllers.JobStatus; |
| 66 | import com.android.server.job.controllers.StateController; |
| 67 | import com.android.server.job.controllers.TimeController; |
| 68 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Responsible for taking jobs representing work to be performed by a client app, and determining |
| 71 | * based on the criteria specified when that job should be run against the client application's |
| 72 | * endpoint. |
| 73 | * Implements logic for scheduling, and rescheduling jobs. The JobSchedulerService knows nothing |
| 74 | * about constraints, or the state of active jobs. It receives callbacks from the various |
| 75 | * controllers and completed jobs and operates accordingly. |
| 76 | * |
| 77 | * Note on locking: Any operations that manipulate {@link #mJobs} need to lock on that object. |
| 78 | * Any function with the suffix 'Locked' also needs to lock on {@link #mJobs}. |
| 79 | * @hide |
| 80 | */ |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 81 | public final class JobSchedulerService extends com.android.server.SystemService |
Matthew Williams | 01ac45b | 2014-07-22 20:44:12 -0700 | [diff] [blame] | 82 | implements StateChangedListener, JobCompletedListener { |
Matthew Williams | aa98431 | 2015-10-15 16:08:05 -0700 | [diff] [blame] | 83 | public static final boolean DEBUG = false; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 84 | /** The number of concurrent jobs we run at one time. */ |
Dianne Hackborn | 8ad2af7 | 2015-03-17 17:00:24 -0700 | [diff] [blame] | 85 | private static final int MAX_JOB_CONTEXTS_COUNT |
Shreyas Basarge | 8c834c0 | 2016-01-07 13:53:16 +0000 | [diff] [blame] | 86 | = ActivityManager.isLowRamDeviceStatic() ? 3 : 6; |
Matthew Williams | be0c417 | 2014-08-06 18:14:16 -0700 | [diff] [blame] | 87 | static final String TAG = "JobSchedulerService"; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 88 | /** Global local for all job scheduler state. */ |
| 89 | final Object mLock = new Object(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 90 | /** Master list of jobs. */ |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 91 | final JobStore mJobs; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 92 | |
| 93 | static final int MSG_JOB_EXPIRED = 0; |
| 94 | static final int MSG_CHECK_JOB = 1; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 95 | static final int MSG_STOP_JOB = 2; |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 96 | static final int MSG_CHECK_JOB_GREEDY = 3; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 97 | |
| 98 | // Policy constants |
| 99 | /** |
| 100 | * Minimum # of idle jobs that must be ready in order to force the JMS to schedule things |
| 101 | * early. |
| 102 | */ |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 103 | static final int MIN_IDLE_COUNT = 1; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 104 | /** |
Matthew Williams | be0c417 | 2014-08-06 18:14:16 -0700 | [diff] [blame] | 105 | * Minimum # of charging jobs that must be ready in order to force the JMS to schedule things |
| 106 | * early. |
| 107 | */ |
| 108 | static final int MIN_CHARGING_COUNT = 1; |
| 109 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 110 | * Minimum # of connectivity jobs that must be ready in order to force the JMS to schedule |
| 111 | * things early. |
| 112 | */ |
Matthew Williams | aa98431 | 2015-10-15 16:08:05 -0700 | [diff] [blame] | 113 | static final int MIN_CONNECTIVITY_COUNT = 1; // Run connectivity jobs as soon as ready. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 114 | /** |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 115 | * Minimum # of content trigger jobs that must be ready in order to force the JMS to schedule |
| 116 | * things early. |
| 117 | */ |
| 118 | static final int MIN_CONTENT_COUNT = 1; |
| 119 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 120 | * Minimum # of jobs (with no particular constraints) for which the JMS will be happy running |
| 121 | * some work early. |
Matthew Williams | be0c417 | 2014-08-06 18:14:16 -0700 | [diff] [blame] | 122 | * This is correlated with the amount of batching we'll be able to do. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 123 | */ |
Matthew Williams | be0c417 | 2014-08-06 18:14:16 -0700 | [diff] [blame] | 124 | static final int MIN_READY_JOBS_COUNT = 2; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Track Services that have currently active or pending jobs. The index is provided by |
| 128 | * {@link JobStatus#getServiceToken()} |
| 129 | */ |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 130 | final List<JobServiceContext> mActiveServices = new ArrayList<>(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 131 | /** List of controllers that will notify this service of updates to jobs. */ |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 132 | List<StateController> mControllers; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 133 | /** |
| 134 | * Queue of pending jobs. The JobServiceContext class will receive jobs from this list |
| 135 | * when ready to execute them. |
| 136 | */ |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 137 | final ArrayList<JobStatus> mPendingJobs = new ArrayList<>(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 138 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 139 | final ArrayList<Integer> mStartedUsers = new ArrayList<>(); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 140 | |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 141 | final JobHandler mHandler; |
| 142 | final JobSchedulerStub mJobSchedulerStub; |
| 143 | |
| 144 | IBatteryStats mBatteryStats; |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 145 | PowerManager mPowerManager; |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 146 | DeviceIdleController.LocalService mLocalDeviceIdleController; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 147 | |
| 148 | /** |
| 149 | * Set to true once we are allowed to run third party apps. |
| 150 | */ |
| 151 | boolean mReadyToRock; |
| 152 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 153 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 154 | * True when in device idle mode, so we don't want to schedule any jobs. |
| 155 | */ |
| 156 | boolean mDeviceIdleMode; |
| 157 | |
| 158 | /** |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 159 | * What we last reported to DeviceIdleController about wheter we are active. |
| 160 | */ |
| 161 | boolean mReportedActive; |
| 162 | |
| 163 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 164 | * Cleans up outstanding jobs when a package is removed. Even if it's being replaced later we |
| 165 | * still clean up. On reinstall the package will have a new uid. |
| 166 | */ |
| 167 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 168 | @Override |
| 169 | public void onReceive(Context context, Intent intent) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 170 | Slog.d(TAG, "Receieved: " + intent.getAction()); |
| 171 | if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { |
Christopher Tate | aad67a3 | 2014-10-20 16:29:20 -0700 | [diff] [blame] | 172 | // If this is an outright uninstall rather than the first half of an |
| 173 | // app update sequence, cancel the jobs associated with the app. |
| 174 | if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) { |
| 175 | int uidRemoved = intent.getIntExtra(Intent.EXTRA_UID, -1); |
| 176 | if (DEBUG) { |
| 177 | Slog.d(TAG, "Removing jobs for uid: " + uidRemoved); |
| 178 | } |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 179 | cancelJobsForUid(uidRemoved, true); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 180 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 181 | } else if (Intent.ACTION_USER_REMOVED.equals(intent.getAction())) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 182 | final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0); |
| 183 | if (DEBUG) { |
| 184 | Slog.d(TAG, "Removing jobs for user: " + userId); |
| 185 | } |
| 186 | cancelJobsForUser(userId); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 187 | } else if (PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED.equals(intent.getAction()) |
| 188 | || PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(intent.getAction())) { |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 189 | updateIdleMode(mPowerManager != null |
| 190 | ? (mPowerManager.isDeviceIdleMode() |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 191 | || mPowerManager.isLightDeviceIdleMode()) |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 192 | : false); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | }; |
| 196 | |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 197 | final private IUidObserver mUidObserver = new IUidObserver.Stub() { |
| 198 | @Override public void onUidStateChanged(int uid, int procState) throws RemoteException { |
| 199 | } |
| 200 | |
| 201 | @Override public void onUidGone(int uid) throws RemoteException { |
| 202 | } |
| 203 | |
| 204 | @Override public void onUidActive(int uid) throws RemoteException { |
| 205 | } |
| 206 | |
| 207 | @Override public void onUidIdle(int uid) throws RemoteException { |
| 208 | cancelJobsForUid(uid, false); |
| 209 | } |
| 210 | }; |
| 211 | |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 212 | public Object getLock() { |
| 213 | return mLock; |
| 214 | } |
| 215 | |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 216 | @Override |
| 217 | public void onStartUser(int userHandle) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 218 | mStartedUsers.add(userHandle); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 219 | // Let's kick any outstanding jobs for this user. |
| 220 | mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void onStopUser(int userHandle) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 225 | mStartedUsers.remove(Integer.valueOf(userHandle)); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 228 | /** |
| 229 | * Entry point from client to schedule the provided job. |
| 230 | * This cancels the job if it's already been scheduled, and replaces it with the one provided. |
| 231 | * @param job JobInfo object containing execution parameters |
| 232 | * @param uId The package identifier of the application this job is for. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 233 | * @return Result of this operation. See <code>JobScheduler#RESULT_*</code> return codes. |
| 234 | */ |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 235 | public int schedule(JobInfo job, int uId) { |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 236 | return scheduleAsPackage(job, uId, null, -1); |
| 237 | } |
| 238 | |
| 239 | public int scheduleAsPackage(JobInfo job, int uId, String packageName, int userId) { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 240 | JobStatus jobStatus = new JobStatus(getLock(), job, uId, packageName, userId); |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 241 | try { |
| 242 | if (ActivityManagerNative.getDefault().getAppStartMode(uId, |
| 243 | job.getService().getPackageName()) == ActivityManager.APP_START_MODE_DISABLED) { |
| 244 | Slog.w(TAG, "Not scheduling job " + uId + ":" + job.toString() |
| 245 | + " -- package not allowed to start"); |
| 246 | return JobScheduler.RESULT_FAILURE; |
| 247 | } |
| 248 | } catch (RemoteException e) { |
| 249 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 250 | if (DEBUG) Slog.d(TAG, "SCHEDULE: " + jobStatus.toShortString()); |
| 251 | JobStatus toCancel; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 252 | synchronized (mLock) { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 253 | toCancel = mJobs.getJobByUidAndJobId(uId, job.getId()); |
| 254 | } |
| 255 | startTrackingJob(jobStatus, toCancel); |
| 256 | if (toCancel != null) { |
| 257 | cancelJobImpl(toCancel); |
| 258 | } |
Matthew Williams | bafeeb9 | 2014-08-08 11:51:06 -0700 | [diff] [blame] | 259 | mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 260 | return JobScheduler.RESULT_SUCCESS; |
| 261 | } |
| 262 | |
| 263 | public List<JobInfo> getPendingJobs(int uid) { |
| 264 | ArrayList<JobInfo> outList = new ArrayList<JobInfo>(); |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 265 | synchronized (mLock) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 266 | ArraySet<JobStatus> jobs = mJobs.getJobs(); |
| 267 | for (int i=0; i<jobs.size(); i++) { |
| 268 | JobStatus job = jobs.valueAt(i); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 269 | if (job.getUid() == uid) { |
| 270 | outList.add(job.getJob()); |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | return outList; |
| 275 | } |
| 276 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 277 | void cancelJobsForUser(int userHandle) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 278 | List<JobStatus> jobsForUser; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 279 | synchronized (mLock) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 280 | jobsForUser = mJobs.getJobsByUser(userHandle); |
| 281 | } |
| 282 | for (int i=0; i<jobsForUser.size(); i++) { |
| 283 | JobStatus toRemove = jobsForUser.get(i); |
| 284 | cancelJobImpl(toRemove); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * Entry point from client to cancel all jobs originating from their uid. |
| 290 | * This will remove the job from the master list, and cancel the job if it was staged for |
| 291 | * execution or being executed. |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 292 | * @param uid Uid to check against for removal of a job. |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 293 | * @param forceAll If true, all jobs for the uid will be canceled; if false, only those |
| 294 | * whose apps are stopped. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 295 | */ |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 296 | public void cancelJobsForUid(int uid, boolean forceAll) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 297 | List<JobStatus> jobsForUid; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 298 | synchronized (mLock) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 299 | jobsForUid = mJobs.getJobsByUid(uid); |
| 300 | } |
| 301 | for (int i=0; i<jobsForUid.size(); i++) { |
| 302 | JobStatus toRemove = jobsForUid.get(i); |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 303 | if (!forceAll) { |
| 304 | String packageName = toRemove.getServiceComponent().getPackageName(); |
| 305 | try { |
| 306 | if (ActivityManagerNative.getDefault().getAppStartMode(uid, packageName) |
| 307 | != ActivityManager.APP_START_MODE_DISABLED) { |
| 308 | continue; |
| 309 | } |
| 310 | } catch (RemoteException e) { |
| 311 | } |
| 312 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 313 | cancelJobImpl(toRemove); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Entry point from client to cancel the job corresponding to the jobId provided. |
| 319 | * This will remove the job from the master list, and cancel the job if it was staged for |
| 320 | * execution or being executed. |
| 321 | * @param uid Uid of the calling client. |
| 322 | * @param jobId Id of the job, provided at schedule-time. |
| 323 | */ |
| 324 | public void cancelJob(int uid, int jobId) { |
| 325 | JobStatus toCancel; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 326 | synchronized (mLock) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 327 | toCancel = mJobs.getJobByUidAndJobId(uid, jobId); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 328 | } |
| 329 | if (toCancel != null) { |
| 330 | cancelJobImpl(toCancel); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 334 | private void cancelJobImpl(JobStatus cancelled) { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 335 | if (DEBUG) Slog.d(TAG, "CANCEL: " + cancelled.toShortString()); |
Shreyas Basarge | 73f1025 | 2016-02-11 17:06:13 +0000 | [diff] [blame] | 336 | stopTrackingJob(cancelled, true /* writeBack */); |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 337 | synchronized (mLock) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 338 | // Remove from pending queue. |
| 339 | mPendingJobs.remove(cancelled); |
| 340 | // Cancel if running. |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 341 | stopJobOnServiceContextLocked(cancelled, JobParameters.REASON_CANCELED); |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 342 | reportActive(); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 343 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 346 | void updateIdleMode(boolean enabled) { |
| 347 | boolean changed = false; |
| 348 | boolean rocking; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 349 | synchronized (mLock) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 350 | if (mDeviceIdleMode != enabled) { |
| 351 | changed = true; |
| 352 | } |
| 353 | rocking = mReadyToRock; |
| 354 | } |
| 355 | if (changed) { |
| 356 | if (rocking) { |
| 357 | for (int i=0; i<mControllers.size(); i++) { |
| 358 | mControllers.get(i).deviceIdleModeChanged(enabled); |
| 359 | } |
| 360 | } |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 361 | synchronized (mLock) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 362 | mDeviceIdleMode = enabled; |
| 363 | if (enabled) { |
| 364 | // When becoming idle, make sure no jobs are actively running. |
| 365 | for (int i=0; i<mActiveServices.size(); i++) { |
| 366 | JobServiceContext jsc = mActiveServices.get(i); |
| 367 | final JobStatus executing = jsc.getRunningJob(); |
| 368 | if (executing != null) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 369 | jsc.cancelExecutingJob(JobParameters.REASON_DEVICE_IDLE); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | } else { |
| 373 | // When coming out of idle, allow thing to start back up. |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 374 | if (rocking) { |
| 375 | if (mLocalDeviceIdleController != null) { |
| 376 | if (!mReportedActive) { |
| 377 | mReportedActive = true; |
| 378 | mLocalDeviceIdleController.setJobsActive(true); |
| 379 | } |
| 380 | } |
| 381 | } |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 382 | mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 388 | void reportActive() { |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 389 | // active is true if pending queue contains jobs OR some job is running. |
| 390 | boolean active = mPendingJobs.size() > 0; |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 391 | if (mPendingJobs.size() <= 0) { |
| 392 | for (int i=0; i<mActiveServices.size(); i++) { |
| 393 | JobServiceContext jsc = mActiveServices.get(i); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 394 | if (jsc.getRunningJob() != null) { |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 395 | active = true; |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | } |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 400 | |
| 401 | if (mReportedActive != active) { |
| 402 | mReportedActive = active; |
| 403 | if (mLocalDeviceIdleController != null) { |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 404 | mLocalDeviceIdleController.setJobsActive(active); |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 409 | /** |
| 410 | * Initializes the system service. |
| 411 | * <p> |
| 412 | * Subclasses must define a single argument constructor that accepts the context |
| 413 | * and passes it to super. |
| 414 | * </p> |
| 415 | * |
| 416 | * @param context The system server context. |
| 417 | */ |
| 418 | public JobSchedulerService(Context context) { |
| 419 | super(context); |
| 420 | // Create the controllers. |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 421 | mControllers = new ArrayList<StateController>(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 422 | mControllers.add(ConnectivityController.get(this)); |
| 423 | mControllers.add(TimeController.get(this)); |
| 424 | mControllers.add(IdleController.get(this)); |
| 425 | mControllers.add(BatteryController.get(this)); |
Amith Yamasani | b0ff322 | 2015-03-04 09:56:14 -0800 | [diff] [blame] | 426 | mControllers.add(AppIdleController.get(this)); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 427 | mControllers.add(ContentObserverController.get(this)); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 428 | |
| 429 | mHandler = new JobHandler(context.getMainLooper()); |
| 430 | mJobSchedulerStub = new JobSchedulerStub(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 431 | mJobs = JobStore.initAndGet(this); |
| 432 | } |
| 433 | |
| 434 | @Override |
| 435 | public void onStart() { |
| 436 | publishBinderService(Context.JOB_SCHEDULER_SERVICE, mJobSchedulerStub); |
| 437 | } |
| 438 | |
| 439 | @Override |
| 440 | public void onBootPhase(int phase) { |
| 441 | if (PHASE_SYSTEM_SERVICES_READY == phase) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 442 | // Register br for package removals and user removals. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 443 | final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED); |
| 444 | filter.addDataScheme("package"); |
| 445 | getContext().registerReceiverAsUser( |
| 446 | mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
| 447 | final IntentFilter userFilter = new IntentFilter(Intent.ACTION_USER_REMOVED); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 448 | userFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 449 | userFilter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 450 | getContext().registerReceiverAsUser( |
| 451 | mBroadcastReceiver, UserHandle.ALL, userFilter, null, null); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 452 | mPowerManager = (PowerManager)getContext().getSystemService(Context.POWER_SERVICE); |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 453 | try { |
| 454 | ActivityManagerNative.getDefault().registerUidObserver(mUidObserver, |
| 455 | ActivityManager.UID_OBSERVER_IDLE); |
| 456 | } catch (RemoteException e) { |
| 457 | // ignored; both services live in system_server |
| 458 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 459 | } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 460 | synchronized (mLock) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 461 | // Let's go! |
| 462 | mReadyToRock = true; |
| 463 | mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService( |
| 464 | BatteryStats.SERVICE_NAME)); |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 465 | mLocalDeviceIdleController |
| 466 | = LocalServices.getService(DeviceIdleController.LocalService.class); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 467 | // Create the "runners". |
| 468 | for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) { |
| 469 | mActiveServices.add( |
| 470 | new JobServiceContext(this, mBatteryStats, |
| 471 | getContext().getMainLooper())); |
| 472 | } |
| 473 | // Attach jobs to their controllers. |
| 474 | ArraySet<JobStatus> jobs = mJobs.getJobs(); |
| 475 | for (int i=0; i<jobs.size(); i++) { |
| 476 | JobStatus job = jobs.valueAt(i); |
Christopher Tate | 4a79dae | 2014-07-18 17:01:40 -0700 | [diff] [blame] | 477 | for (int controller=0; controller<mControllers.size(); controller++) { |
Dianne Hackborn | 2bf51f4 | 2015-03-24 14:17:12 -0700 | [diff] [blame] | 478 | mControllers.get(controller).deviceIdleModeChanged(mDeviceIdleMode); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 479 | mControllers.get(controller).maybeStartTrackingJob(job, null); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | // GO GO GO! |
| 483 | mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); |
| 484 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Called when we have a job status object that we need to insert in our |
| 490 | * {@link com.android.server.job.JobStore}, and make sure all the relevant controllers know |
| 491 | * about. |
| 492 | */ |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 493 | private void startTrackingJob(JobStatus jobStatus, JobStatus lastJob) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 494 | boolean update; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 495 | boolean rocking; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 496 | synchronized (mLock) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 497 | update = mJobs.add(jobStatus); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 498 | rocking = mReadyToRock; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 499 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 500 | if (rocking) { |
| 501 | for (int i=0; i<mControllers.size(); i++) { |
| 502 | StateController controller = mControllers.get(i); |
| 503 | if (update) { |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 504 | controller.maybeStopTrackingJob(jobStatus, true); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 505 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 506 | controller.maybeStartTrackingJob(jobStatus, lastJob); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 507 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Called when we want to remove a JobStatus object that we've finished executing. Returns the |
| 513 | * object removed. |
| 514 | */ |
Shreyas Basarge | 73f1025 | 2016-02-11 17:06:13 +0000 | [diff] [blame] | 515 | private boolean stopTrackingJob(JobStatus jobStatus, boolean writeBack) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 516 | boolean removed; |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 517 | boolean rocking; |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 518 | synchronized (mLock) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 519 | // Remove from store as well as controllers. |
Shreyas Basarge | 73f1025 | 2016-02-11 17:06:13 +0000 | [diff] [blame] | 520 | removed = mJobs.remove(jobStatus, writeBack); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 521 | rocking = mReadyToRock; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 522 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 523 | if (removed && rocking) { |
| 524 | for (int i=0; i<mControllers.size(); i++) { |
| 525 | StateController controller = mControllers.get(i); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 526 | controller.maybeStopTrackingJob(jobStatus, false); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | return removed; |
| 530 | } |
| 531 | |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 532 | private boolean stopJobOnServiceContextLocked(JobStatus job, int reason) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 533 | for (int i=0; i<mActiveServices.size(); i++) { |
| 534 | JobServiceContext jsc = mActiveServices.get(i); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 535 | final JobStatus executing = jsc.getRunningJob(); |
| 536 | if (executing != null && executing.matches(job.getUid(), job.getJobId())) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 537 | jsc.cancelExecutingJob(reason); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 538 | return true; |
| 539 | } |
| 540 | } |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * @param job JobStatus we are querying against. |
| 546 | * @return Whether or not the job represented by the status object is currently being run or |
| 547 | * is pending. |
| 548 | */ |
| 549 | private boolean isCurrentlyActiveLocked(JobStatus job) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 550 | for (int i=0; i<mActiveServices.size(); i++) { |
| 551 | JobServiceContext serviceContext = mActiveServices.get(i); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 552 | final JobStatus running = serviceContext.getRunningJob(); |
| 553 | if (running != null && running.matches(job.getUid(), job.getJobId())) { |
| 554 | return true; |
| 555 | } |
| 556 | } |
| 557 | return false; |
| 558 | } |
| 559 | |
| 560 | /** |
Matthew Williams | 1bde39a | 2015-10-07 14:29:30 -0700 | [diff] [blame] | 561 | * Reschedules the given job based on the job's backoff policy. It doesn't make sense to |
| 562 | * specify an override deadline on a failed job (the failed job will run even though it's not |
| 563 | * ready), so we reschedule it with {@link JobStatus#NO_LATEST_RUNTIME}, but specify that any |
| 564 | * ready job with {@link JobStatus#numFailures} > 0 will be executed. |
| 565 | * |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 566 | * @param failureToReschedule Provided job status that we will reschedule. |
| 567 | * @return A newly instantiated JobStatus with the same constraints as the last job except |
| 568 | * with adjusted timing constraints. |
Matthew Williams | 1bde39a | 2015-10-07 14:29:30 -0700 | [diff] [blame] | 569 | * |
| 570 | * @see JobHandler#maybeQueueReadyJobsForExecutionLockedH |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 571 | */ |
| 572 | private JobStatus getRescheduleJobForFailure(JobStatus failureToReschedule) { |
| 573 | final long elapsedNowMillis = SystemClock.elapsedRealtime(); |
| 574 | final JobInfo job = failureToReschedule.getJob(); |
| 575 | |
| 576 | final long initialBackoffMillis = job.getInitialBackoffMillis(); |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 577 | final int backoffAttempts = failureToReschedule.getNumFailures() + 1; |
| 578 | long delayMillis; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 579 | |
| 580 | switch (job.getBackoffPolicy()) { |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 581 | case JobInfo.BACKOFF_POLICY_LINEAR: |
| 582 | delayMillis = initialBackoffMillis * backoffAttempts; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 583 | break; |
| 584 | default: |
| 585 | if (DEBUG) { |
| 586 | Slog.v(TAG, "Unrecognised back-off policy, defaulting to exponential."); |
| 587 | } |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 588 | case JobInfo.BACKOFF_POLICY_EXPONENTIAL: |
| 589 | delayMillis = |
| 590 | (long) Math.scalb(initialBackoffMillis, backoffAttempts - 1); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 591 | break; |
| 592 | } |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 593 | delayMillis = |
| 594 | Math.min(delayMillis, JobInfo.MAX_BACKOFF_DELAY_MILLIS); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 595 | JobStatus newJob = new JobStatus(failureToReschedule, elapsedNowMillis + delayMillis, |
Matthew Williams | d1c0675 | 2014-08-22 14:15:28 -0700 | [diff] [blame] | 596 | JobStatus.NO_LATEST_RUNTIME, backoffAttempts); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 597 | for (int ic=0; ic<mControllers.size(); ic++) { |
| 598 | StateController controller = mControllers.get(ic); |
| 599 | controller.rescheduleForFailure(newJob, failureToReschedule); |
| 600 | } |
| 601 | return newJob; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /** |
Matthew Williams | 1bde39a | 2015-10-07 14:29:30 -0700 | [diff] [blame] | 605 | * Called after a periodic has executed so we can reschedule it. We take the last execution |
| 606 | * time of the job to be the time of completion (i.e. the time at which this function is |
| 607 | * called). |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 608 | * This could be inaccurate b/c the job can run for as long as |
| 609 | * {@link com.android.server.job.JobServiceContext#EXECUTING_TIMESLICE_MILLIS}, but will lead |
| 610 | * to underscheduling at least, rather than if we had taken the last execution time to be the |
| 611 | * start of the execution. |
| 612 | * @return A new job representing the execution criteria for this instantiation of the |
| 613 | * recurring job. |
| 614 | */ |
| 615 | private JobStatus getRescheduleJobForPeriodic(JobStatus periodicToReschedule) { |
| 616 | final long elapsedNow = SystemClock.elapsedRealtime(); |
| 617 | // Compute how much of the period is remaining. |
Matthew Williams | 1bde39a | 2015-10-07 14:29:30 -0700 | [diff] [blame] | 618 | long runEarly = 0L; |
| 619 | |
| 620 | // If this periodic was rescheduled it won't have a deadline. |
| 621 | if (periodicToReschedule.hasDeadlineConstraint()) { |
| 622 | runEarly = Math.max(periodicToReschedule.getLatestRunTimeElapsed() - elapsedNow, 0L); |
| 623 | } |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 624 | long flex = periodicToReschedule.getJob().getFlexMillis(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 625 | long period = periodicToReschedule.getJob().getIntervalMillis(); |
Shreyas Basarge | 89ee618 | 2015-12-17 15:16:36 +0000 | [diff] [blame] | 626 | long newLatestRuntimeElapsed = elapsedNow + runEarly + period; |
| 627 | long newEarliestRunTimeElapsed = newLatestRuntimeElapsed - flex; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 628 | |
| 629 | if (DEBUG) { |
| 630 | Slog.v(TAG, "Rescheduling executed periodic. New execution window [" + |
| 631 | newEarliestRunTimeElapsed/1000 + ", " + newLatestRuntimeElapsed/1000 + "]s"); |
| 632 | } |
| 633 | return new JobStatus(periodicToReschedule, newEarliestRunTimeElapsed, |
| 634 | newLatestRuntimeElapsed, 0 /* backoffAttempt */); |
| 635 | } |
| 636 | |
| 637 | // JobCompletedListener implementations. |
| 638 | |
| 639 | /** |
| 640 | * A job just finished executing. We fetch the |
| 641 | * {@link com.android.server.job.controllers.JobStatus} from the store and depending on |
| 642 | * whether we want to reschedule we readd it to the controllers. |
| 643 | * @param jobStatus Completed job. |
| 644 | * @param needsReschedule Whether the implementing class should reschedule this job. |
| 645 | */ |
| 646 | @Override |
| 647 | public void onJobCompleted(JobStatus jobStatus, boolean needsReschedule) { |
| 648 | if (DEBUG) { |
| 649 | Slog.d(TAG, "Completed " + jobStatus + ", reschedule=" + needsReschedule); |
| 650 | } |
Shreyas Basarge | 73f1025 | 2016-02-11 17:06:13 +0000 | [diff] [blame] | 651 | // Do not write back immediately if this is a periodic job. The job may get lost if system |
| 652 | // shuts down before it is added back. |
| 653 | if (!stopTrackingJob(jobStatus, !jobStatus.getJob().isPeriodic())) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 654 | if (DEBUG) { |
Matthew Williams | ee410da | 2014-07-25 11:30:40 -0700 | [diff] [blame] | 655 | Slog.d(TAG, "Could not find job to remove. Was job removed while executing?"); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 656 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 657 | // We still want to check for jobs to execute, because this job may have |
| 658 | // scheduled a new job under the same job id, and now we can run it. |
| 659 | mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 660 | return; |
| 661 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 662 | // Note: there is a small window of time in here where, when rescheduling a job, |
| 663 | // we will stop monitoring its content providers. This should be fixed by stopping |
| 664 | // the old job after scheduling the new one, but since we have no lock held here |
| 665 | // that may cause ordering problems if the app removes jobStatus while in here. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 666 | if (needsReschedule) { |
| 667 | JobStatus rescheduled = getRescheduleJobForFailure(jobStatus); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 668 | startTrackingJob(rescheduled, jobStatus); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 669 | } else if (jobStatus.getJob().isPeriodic()) { |
| 670 | JobStatus rescheduledPeriodic = getRescheduleJobForPeriodic(jobStatus); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 671 | startTrackingJob(rescheduledPeriodic, jobStatus); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 672 | } |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 673 | reportActive(); |
| 674 | mHandler.obtainMessage(MSG_CHECK_JOB_GREEDY).sendToTarget(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // StateChangedListener implementations. |
| 678 | |
| 679 | /** |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 680 | * Posts a message to the {@link com.android.server.job.JobSchedulerService.JobHandler} that |
| 681 | * some controller's state has changed, so as to run through the list of jobs and start/stop |
| 682 | * any that are eligible. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 683 | */ |
| 684 | @Override |
| 685 | public void onControllerStateChanged() { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 686 | mHandler.obtainMessage(MSG_CHECK_JOB).sendToTarget(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | @Override |
| 690 | public void onRunJobNow(JobStatus jobStatus) { |
| 691 | mHandler.obtainMessage(MSG_JOB_EXPIRED, jobStatus).sendToTarget(); |
| 692 | } |
| 693 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 694 | private class JobHandler extends Handler { |
| 695 | |
| 696 | public JobHandler(Looper looper) { |
| 697 | super(looper); |
| 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public void handleMessage(Message message) { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 702 | synchronized (mLock) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 703 | if (!mReadyToRock) { |
| 704 | return; |
| 705 | } |
| 706 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 707 | switch (message.what) { |
| 708 | case MSG_JOB_EXPIRED: |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 709 | synchronized (mLock) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 710 | JobStatus runNow = (JobStatus) message.obj; |
Matthew Williams | bafeeb9 | 2014-08-08 11:51:06 -0700 | [diff] [blame] | 711 | // runNow can be null, which is a controller's way of indicating that its |
| 712 | // state is such that all ready jobs should be run immediately. |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 713 | if (runNow != null && !mPendingJobs.contains(runNow) |
| 714 | && mJobs.containsJob(runNow)) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 715 | mPendingJobs.add(runNow); |
| 716 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 717 | queueReadyJobsForExecutionLockedH(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 718 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 719 | break; |
| 720 | case MSG_CHECK_JOB: |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 721 | synchronized (mLock) { |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 722 | if (mReportedActive) { |
| 723 | // if jobs are currently being run, queue all ready jobs for execution. |
| 724 | queueReadyJobsForExecutionLockedH(); |
| 725 | } else { |
| 726 | // Check the list of jobs and run some of them if we feel inclined. |
| 727 | maybeQueueReadyJobsForExecutionLockedH(); |
| 728 | } |
| 729 | } |
| 730 | break; |
| 731 | case MSG_CHECK_JOB_GREEDY: |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 732 | synchronized (mLock) { |
Shreyas Basarge | 4cff8ac | 2015-12-10 21:32:52 +0000 | [diff] [blame] | 733 | queueReadyJobsForExecutionLockedH(); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 734 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 735 | break; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 736 | case MSG_STOP_JOB: |
| 737 | cancelJobImpl((JobStatus)message.obj); |
| 738 | break; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 739 | } |
| 740 | maybeRunPendingJobsH(); |
| 741 | // Don't remove JOB_EXPIRED in case one came along while processing the queue. |
| 742 | removeMessages(MSG_CHECK_JOB); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Run through list of jobs and execute all possible - at least one is expired so we do |
| 747 | * as many as we can. |
| 748 | */ |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 749 | private void queueReadyJobsForExecutionLockedH() { |
| 750 | ArraySet<JobStatus> jobs = mJobs.getJobs(); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 751 | mPendingJobs.clear(); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 752 | if (DEBUG) { |
| 753 | Slog.d(TAG, "queuing all ready jobs for execution:"); |
| 754 | } |
| 755 | for (int i=0; i<jobs.size(); i++) { |
| 756 | JobStatus job = jobs.valueAt(i); |
| 757 | if (isReadyToBeExecutedLocked(job)) { |
| 758 | if (DEBUG) { |
| 759 | Slog.d(TAG, " queued " + job.toShortString()); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 760 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 761 | mPendingJobs.add(job); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 762 | } else if (areJobConstraintsNotSatisfied(job)) { |
| 763 | stopJobOnServiceContextLocked(job, |
| 764 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 765 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 766 | } |
| 767 | if (DEBUG) { |
| 768 | final int queuedJobs = mPendingJobs.size(); |
| 769 | if (queuedJobs == 0) { |
| 770 | Slog.d(TAG, "No jobs pending."); |
| 771 | } else { |
| 772 | Slog.d(TAG, queuedJobs + " jobs queued."); |
Matthew Williams | 75fc525 | 2014-09-02 16:17:53 -0700 | [diff] [blame] | 773 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * The state of at least one job has changed. Here is where we could enforce various |
| 779 | * policies on when we want to execute jobs. |
| 780 | * Right now the policy is such: |
| 781 | * If >1 of the ready jobs is idle mode we send all of them off |
| 782 | * if more than 2 network connectivity jobs are ready we send them all off. |
| 783 | * If more than 4 jobs total are ready we send them all off. |
| 784 | * TODO: It would be nice to consolidate these sort of high-level policies somewhere. |
| 785 | */ |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 786 | private void maybeQueueReadyJobsForExecutionLockedH() { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 787 | mPendingJobs.clear(); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 788 | int chargingCount = 0; |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 789 | int idleCount = 0; |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 790 | int backoffCount = 0; |
| 791 | int connectivityCount = 0; |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 792 | int contentCount = 0; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 793 | List<JobStatus> runnableJobs = null; |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 794 | ArraySet<JobStatus> jobs = mJobs.getJobs(); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 795 | if (DEBUG) Slog.d(TAG, "Maybe queuing ready jobs..."); |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 796 | for (int i=0; i<jobs.size(); i++) { |
| 797 | JobStatus job = jobs.valueAt(i); |
| 798 | if (isReadyToBeExecutedLocked(job)) { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 799 | try { |
| 800 | if (ActivityManagerNative.getDefault().getAppStartMode(job.getUid(), |
| 801 | job.getJob().getService().getPackageName()) |
| 802 | == ActivityManager.APP_START_MODE_DISABLED) { |
| 803 | Slog.w(TAG, "Aborting job " + job.getUid() + ":" |
| 804 | + job.getJob().toString() + " -- package not allowed to start"); |
| 805 | mHandler.obtainMessage(MSG_STOP_JOB, job).sendToTarget(); |
| 806 | continue; |
| 807 | } |
| 808 | } catch (RemoteException e) { |
| 809 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 810 | if (job.getNumFailures() > 0) { |
| 811 | backoffCount++; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 812 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 813 | if (job.hasIdleConstraint()) { |
| 814 | idleCount++; |
| 815 | } |
| 816 | if (job.hasConnectivityConstraint() || job.hasUnmeteredConstraint()) { |
| 817 | connectivityCount++; |
| 818 | } |
| 819 | if (job.hasChargingConstraint()) { |
| 820 | chargingCount++; |
| 821 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 822 | if (job.hasContentTriggerConstraint()) { |
| 823 | contentCount++; |
| 824 | } |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 825 | if (runnableJobs == null) { |
| 826 | runnableJobs = new ArrayList<>(); |
| 827 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 828 | runnableJobs.add(job); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 829 | } else if (areJobConstraintsNotSatisfied(job)) { |
| 830 | stopJobOnServiceContextLocked(job, |
| 831 | JobParameters.REASON_CONSTRAINTS_NOT_SATISFIED); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 832 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 833 | } |
| 834 | if (backoffCount > 0 || |
| 835 | idleCount >= MIN_IDLE_COUNT || |
| 836 | connectivityCount >= MIN_CONNECTIVITY_COUNT || |
| 837 | chargingCount >= MIN_CHARGING_COUNT || |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 838 | contentCount >= MIN_CONTENT_COUNT || |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 839 | (runnableJobs != null && runnableJobs.size() >= MIN_READY_JOBS_COUNT)) { |
Matthew Williams | be0c417 | 2014-08-06 18:14:16 -0700 | [diff] [blame] | 840 | if (DEBUG) { |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 841 | Slog.d(TAG, "maybeQueueReadyJobsForExecutionLockedH: Running jobs."); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 842 | } |
Matthew Williams | 48a30db | 2014-09-23 13:39:36 -0700 | [diff] [blame] | 843 | for (int i=0; i<runnableJobs.size(); i++) { |
| 844 | mPendingJobs.add(runnableJobs.get(i)); |
| 845 | } |
| 846 | } else { |
| 847 | if (DEBUG) { |
| 848 | Slog.d(TAG, "maybeQueueReadyJobsForExecutionLockedH: Not running anything."); |
| 849 | } |
| 850 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /** |
| 854 | * Criteria for moving a job into the pending queue: |
| 855 | * - It's ready. |
| 856 | * - It's not pending. |
| 857 | * - It's not already running on a JSC. |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 858 | * - The user that requested the job is running. |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 859 | */ |
| 860 | private boolean isReadyToBeExecutedLocked(JobStatus job) { |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 861 | final boolean jobReady = job.isReady(); |
| 862 | final boolean jobPending = mPendingJobs.contains(job); |
| 863 | final boolean jobActive = isCurrentlyActiveLocked(job); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 864 | final boolean userRunning = mStartedUsers.contains(job.getUserId()); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 865 | if (DEBUG) { |
| 866 | Slog.v(TAG, "isReadyToBeExecutedLocked: " + job.toShortString() |
| 867 | + " ready=" + jobReady + " pending=" + jobPending |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 868 | + " active=" + jobActive + " userRunning=" + userRunning); |
Matthew Williams | 9ae3dbe | 2014-08-21 13:47:47 -0700 | [diff] [blame] | 869 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 870 | return userRunning && jobReady && !jobPending && !jobActive; |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | /** |
| 874 | * Criteria for cancelling an active job: |
| 875 | * - It's not ready |
| 876 | * - It's running on a JSC. |
| 877 | */ |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 878 | private boolean areJobConstraintsNotSatisfied(JobStatus job) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 879 | return !job.isReady() && isCurrentlyActiveLocked(job); |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Reconcile jobs in the pending queue against available execution contexts. |
| 884 | * A controller can force a job into the pending queue even if it's already running, but |
| 885 | * here is where we decide whether to actually execute it. |
| 886 | */ |
| 887 | private void maybeRunPendingJobsH() { |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 888 | synchronized (mLock) { |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 889 | if (mDeviceIdleMode) { |
| 890 | // If device is idle, we will not schedule jobs to run. |
| 891 | return; |
| 892 | } |
Matthew Williams | 75fc525 | 2014-09-02 16:17:53 -0700 | [diff] [blame] | 893 | if (DEBUG) { |
| 894 | Slog.d(TAG, "pending queue: " + mPendingJobs.size() + " jobs."); |
| 895 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 896 | assignJobsToContextsH(); |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 897 | reportActive(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | /** |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 903 | * Takes jobs from pending queue and runs them on available contexts. |
| 904 | * If no contexts are available, preempts lower priority jobs to |
| 905 | * run higher priority ones. |
| 906 | * Lock on mJobs before calling this function. |
| 907 | */ |
| 908 | private void assignJobsToContextsH() { |
| 909 | if (DEBUG) { |
| 910 | Slog.d(TAG, printPendingQueue()); |
| 911 | } |
| 912 | |
| 913 | // This array essentially stores the state of mActiveServices array. |
| 914 | // ith index stores the job present on the ith JobServiceContext. |
| 915 | // We manipulate this array until we arrive at what jobs should be running on |
| 916 | // what JobServiceContext. |
| 917 | JobStatus[] contextIdToJobMap = new JobStatus[MAX_JOB_CONTEXTS_COUNT]; |
| 918 | // Indicates whether we need to act on this jobContext id |
| 919 | boolean[] act = new boolean[MAX_JOB_CONTEXTS_COUNT]; |
| 920 | int[] preferredUidForContext = new int[MAX_JOB_CONTEXTS_COUNT]; |
| 921 | for (int i=0; i<mActiveServices.size(); i++) { |
| 922 | contextIdToJobMap[i] = mActiveServices.get(i).getRunningJob(); |
| 923 | preferredUidForContext[i] = mActiveServices.get(i).getPreferredUid(); |
| 924 | } |
| 925 | if (DEBUG) { |
| 926 | Slog.d(TAG, printContextIdToJobMap(contextIdToJobMap, "running jobs initial")); |
| 927 | } |
| 928 | Iterator<JobStatus> it = mPendingJobs.iterator(); |
| 929 | while (it.hasNext()) { |
| 930 | JobStatus nextPending = it.next(); |
| 931 | |
| 932 | // If job is already running, go to next job. |
| 933 | int jobRunningContext = findJobContextIdFromMap(nextPending, contextIdToJobMap); |
| 934 | if (jobRunningContext != -1) { |
| 935 | continue; |
| 936 | } |
| 937 | |
| 938 | // Find a context for nextPending. The context should be available OR |
| 939 | // it should have lowest priority among all running jobs |
| 940 | // (sharing the same Uid as nextPending) |
| 941 | int minPriority = Integer.MAX_VALUE; |
| 942 | int minPriorityContextId = -1; |
| 943 | for (int i=0; i<mActiveServices.size(); i++) { |
| 944 | JobStatus job = contextIdToJobMap[i]; |
| 945 | int preferredUid = preferredUidForContext[i]; |
| 946 | if (job == null && (preferredUid == nextPending.getUid() || |
| 947 | preferredUid == JobServiceContext.NO_PREFERRED_UID) ) { |
| 948 | minPriorityContextId = i; |
| 949 | break; |
| 950 | } |
Shreyas Basarge | 347c278 | 2016-01-15 18:24:36 +0000 | [diff] [blame] | 951 | if (job == null) { |
| 952 | // No job on this context, but nextPending can't run here because |
| 953 | // the context has a preferred Uid. |
| 954 | continue; |
| 955 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 956 | if (job.getUid() != nextPending.getUid()) { |
| 957 | continue; |
| 958 | } |
| 959 | if (job.getPriority() >= nextPending.getPriority()) { |
| 960 | continue; |
| 961 | } |
| 962 | if (minPriority > nextPending.getPriority()) { |
| 963 | minPriority = nextPending.getPriority(); |
| 964 | minPriorityContextId = i; |
| 965 | } |
| 966 | } |
| 967 | if (minPriorityContextId != -1) { |
| 968 | contextIdToJobMap[minPriorityContextId] = nextPending; |
| 969 | act[minPriorityContextId] = true; |
| 970 | } |
| 971 | } |
| 972 | if (DEBUG) { |
| 973 | Slog.d(TAG, printContextIdToJobMap(contextIdToJobMap, "running jobs final")); |
| 974 | } |
| 975 | for (int i=0; i<mActiveServices.size(); i++) { |
| 976 | boolean preservePreferredUid = false; |
| 977 | if (act[i]) { |
| 978 | JobStatus js = mActiveServices.get(i).getRunningJob(); |
| 979 | if (js != null) { |
| 980 | if (DEBUG) { |
| 981 | Slog.d(TAG, "preempting job: " + mActiveServices.get(i).getRunningJob()); |
| 982 | } |
| 983 | // preferredUid will be set to uid of currently running job. |
| 984 | mActiveServices.get(i).preemptExecutingJob(); |
| 985 | preservePreferredUid = true; |
| 986 | } else { |
| 987 | if (DEBUG) { |
| 988 | Slog.d(TAG, "About to run job on context " |
| 989 | + String.valueOf(i) + ", job: " + contextIdToJobMap[i]); |
| 990 | } |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 991 | for (int ic=0; ic<mControllers.size(); ic++) { |
| 992 | StateController controller = mControllers.get(ic); |
| 993 | controller.prepareForExecution(contextIdToJobMap[i]); |
| 994 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 995 | if (!mActiveServices.get(i).executeRunnableJob(contextIdToJobMap[i])) { |
| 996 | Slog.d(TAG, "Error executing " + contextIdToJobMap[i]); |
| 997 | } |
| 998 | mPendingJobs.remove(contextIdToJobMap[i]); |
| 999 | } |
| 1000 | } |
| 1001 | if (!preservePreferredUid) { |
| 1002 | mActiveServices.get(i).clearPreferredUid(); |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | int findJobContextIdFromMap(JobStatus jobStatus, JobStatus[] map) { |
| 1008 | for (int i=0; i<map.length; i++) { |
| 1009 | if (map[i] != null && map[i].matches(jobStatus.getUid(), jobStatus.getJobId())) { |
| 1010 | return i; |
| 1011 | } |
| 1012 | } |
| 1013 | return -1; |
| 1014 | } |
| 1015 | |
| 1016 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1017 | * Binder stub trampoline implementation |
| 1018 | */ |
| 1019 | final class JobSchedulerStub extends IJobScheduler.Stub { |
| 1020 | /** Cache determination of whether a given app can persist jobs |
| 1021 | * key is uid of the calling app; value is undetermined/true/false |
| 1022 | */ |
| 1023 | private final SparseArray<Boolean> mPersistCache = new SparseArray<Boolean>(); |
| 1024 | |
| 1025 | // Enforce that only the app itself (or shared uid participant) can schedule a |
| 1026 | // job that runs one of the app's services, as well as verifying that the |
| 1027 | // named service properly requires the BIND_JOB_SERVICE permission |
| 1028 | private void enforceValidJobRequest(int uid, JobInfo job) { |
Christopher Tate | 5568f54 | 2014-06-18 13:53:31 -0700 | [diff] [blame] | 1029 | final IPackageManager pm = AppGlobals.getPackageManager(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1030 | final ComponentName service = job.getService(); |
| 1031 | try { |
Jeff Sharkey | c7bacab | 2016-02-09 15:56:11 -0700 | [diff] [blame] | 1032 | ServiceInfo si = pm.getServiceInfo(service, |
| 1033 | PackageManager.MATCH_DEBUG_TRIAGED_MISSING, UserHandle.getUserId(uid)); |
Christopher Tate | 5568f54 | 2014-06-18 13:53:31 -0700 | [diff] [blame] | 1034 | if (si == null) { |
| 1035 | throw new IllegalArgumentException("No such service " + service); |
| 1036 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1037 | if (si.applicationInfo.uid != uid) { |
| 1038 | throw new IllegalArgumentException("uid " + uid + |
| 1039 | " cannot schedule job in " + service.getPackageName()); |
| 1040 | } |
| 1041 | if (!JobService.PERMISSION_BIND.equals(si.permission)) { |
| 1042 | throw new IllegalArgumentException("Scheduled service " + service |
| 1043 | + " does not require android.permission.BIND_JOB_SERVICE permission"); |
| 1044 | } |
Christopher Tate | 5568f54 | 2014-06-18 13:53:31 -0700 | [diff] [blame] | 1045 | } catch (RemoteException e) { |
| 1046 | // Can't happen; the Package Manager is in this same process |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | private boolean canPersistJobs(int pid, int uid) { |
| 1051 | // If we get this far we're good to go; all we need to do now is check |
| 1052 | // whether the app is allowed to persist its scheduled work. |
| 1053 | final boolean canPersist; |
| 1054 | synchronized (mPersistCache) { |
| 1055 | Boolean cached = mPersistCache.get(uid); |
| 1056 | if (cached != null) { |
| 1057 | canPersist = cached.booleanValue(); |
| 1058 | } else { |
| 1059 | // Persisting jobs is tantamount to running at boot, so we permit |
| 1060 | // it when the app has declared that it uses the RECEIVE_BOOT_COMPLETED |
| 1061 | // permission |
| 1062 | int result = getContext().checkPermission( |
| 1063 | android.Manifest.permission.RECEIVE_BOOT_COMPLETED, pid, uid); |
| 1064 | canPersist = (result == PackageManager.PERMISSION_GRANTED); |
| 1065 | mPersistCache.put(uid, canPersist); |
| 1066 | } |
| 1067 | } |
| 1068 | return canPersist; |
| 1069 | } |
| 1070 | |
| 1071 | // IJobScheduler implementation |
| 1072 | @Override |
| 1073 | public int schedule(JobInfo job) throws RemoteException { |
| 1074 | if (DEBUG) { |
Matthew Williams | ee410da | 2014-07-25 11:30:40 -0700 | [diff] [blame] | 1075 | Slog.d(TAG, "Scheduling job: " + job.toString()); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1076 | } |
| 1077 | final int pid = Binder.getCallingPid(); |
| 1078 | final int uid = Binder.getCallingUid(); |
| 1079 | |
| 1080 | enforceValidJobRequest(uid, job); |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 1081 | if (job.isPersisted()) { |
| 1082 | if (!canPersistJobs(pid, uid)) { |
| 1083 | throw new IllegalArgumentException("Error: requested job be persisted without" |
| 1084 | + " holding RECEIVE_BOOT_COMPLETED permission."); |
| 1085 | } |
| 1086 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1087 | |
| 1088 | long ident = Binder.clearCallingIdentity(); |
| 1089 | try { |
Matthew Williams | 900c67f | 2014-07-09 12:46:53 -0700 | [diff] [blame] | 1090 | return JobSchedulerService.this.schedule(job, uid); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1091 | } finally { |
| 1092 | Binder.restoreCallingIdentity(ident); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | @Override |
Shreyas Basarge | 968ac75 | 2016-01-11 23:09:26 +0000 | [diff] [blame] | 1097 | public int scheduleAsPackage(JobInfo job, String packageName, int userId) |
| 1098 | throws RemoteException { |
| 1099 | if (DEBUG) { |
| 1100 | Slog.d(TAG, "Scheduling job: " + job.toString() + " on behalf of " + packageName); |
| 1101 | } |
| 1102 | final int uid = Binder.getCallingUid(); |
| 1103 | if (uid != Process.SYSTEM_UID) { |
| 1104 | throw new IllegalArgumentException("Only system process is allowed" |
| 1105 | + "to set packageName"); |
| 1106 | } |
| 1107 | long ident = Binder.clearCallingIdentity(); |
| 1108 | try { |
| 1109 | return JobSchedulerService.this.scheduleAsPackage(job, uid, packageName, userId); |
| 1110 | } finally { |
| 1111 | Binder.restoreCallingIdentity(ident); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | @Override |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1116 | public List<JobInfo> getAllPendingJobs() throws RemoteException { |
| 1117 | final int uid = Binder.getCallingUid(); |
| 1118 | |
| 1119 | long ident = Binder.clearCallingIdentity(); |
| 1120 | try { |
| 1121 | return JobSchedulerService.this.getPendingJobs(uid); |
| 1122 | } finally { |
| 1123 | Binder.restoreCallingIdentity(ident); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | @Override |
| 1128 | public void cancelAll() throws RemoteException { |
| 1129 | final int uid = Binder.getCallingUid(); |
| 1130 | |
| 1131 | long ident = Binder.clearCallingIdentity(); |
| 1132 | try { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1133 | JobSchedulerService.this.cancelJobsForUid(uid, true); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1134 | } finally { |
| 1135 | Binder.restoreCallingIdentity(ident); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | @Override |
| 1140 | public void cancel(int jobId) throws RemoteException { |
| 1141 | final int uid = Binder.getCallingUid(); |
| 1142 | |
| 1143 | long ident = Binder.clearCallingIdentity(); |
| 1144 | try { |
| 1145 | JobSchedulerService.this.cancelJob(uid, jobId); |
| 1146 | } finally { |
| 1147 | Binder.restoreCallingIdentity(ident); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * "dumpsys" infrastructure |
| 1153 | */ |
| 1154 | @Override |
| 1155 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1156 | getContext().enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
| 1157 | |
| 1158 | long identityToken = Binder.clearCallingIdentity(); |
| 1159 | try { |
| 1160 | JobSchedulerService.this.dumpInternal(pw); |
| 1161 | } finally { |
| 1162 | Binder.restoreCallingIdentity(identityToken); |
| 1163 | } |
| 1164 | } |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1165 | }; |
| 1166 | |
| 1167 | private String printContextIdToJobMap(JobStatus[] map, String initial) { |
| 1168 | StringBuilder s = new StringBuilder(initial + ": "); |
| 1169 | for (int i=0; i<map.length; i++) { |
| 1170 | s.append("(") |
| 1171 | .append(map[i] == null? -1: map[i].getJobId()) |
| 1172 | .append(map[i] == null? -1: map[i].getUid()) |
| 1173 | .append(")" ); |
| 1174 | } |
| 1175 | return s.toString(); |
| 1176 | } |
| 1177 | |
| 1178 | private String printPendingQueue() { |
| 1179 | StringBuilder s = new StringBuilder("Pending queue: "); |
| 1180 | Iterator<JobStatus> it = mPendingJobs.iterator(); |
| 1181 | while (it.hasNext()) { |
| 1182 | JobStatus js = it.next(); |
| 1183 | s.append("(") |
| 1184 | .append(js.getJob().getId()) |
| 1185 | .append(", ") |
| 1186 | .append(js.getUid()) |
| 1187 | .append(") "); |
| 1188 | } |
| 1189 | return s.toString(); |
Jeff Sharkey | 5217cac | 2015-12-20 15:34:01 -0700 | [diff] [blame] | 1190 | } |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1191 | |
| 1192 | void dumpInternal(PrintWriter pw) { |
Christopher Tate | f973a7b | 2014-08-29 12:54:08 -0700 | [diff] [blame] | 1193 | final long now = SystemClock.elapsedRealtime(); |
Dianne Hackborn | 33d31c5 | 2016-02-16 10:30:33 -0800 | [diff] [blame^] | 1194 | synchronized (mLock) { |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1195 | pw.print("Started users: "); |
| 1196 | for (int i=0; i<mStartedUsers.size(); i++) { |
| 1197 | pw.print("u" + mStartedUsers.get(i) + " "); |
| 1198 | } |
| 1199 | pw.println(); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1200 | pw.println("Registered jobs:"); |
| 1201 | if (mJobs.size() > 0) { |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1202 | ArraySet<JobStatus> jobs = mJobs.getJobs(); |
| 1203 | for (int i=0; i<jobs.size(); i++) { |
| 1204 | JobStatus job = jobs.valueAt(i); |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 1205 | pw.print(" Job #"); pw.print(i); pw.print(": "); |
| 1206 | pw.println(job.toShortString()); |
| 1207 | job.dump(pw, " "); |
| 1208 | pw.print(" Ready: "); |
| 1209 | pw.print(mHandler.isReadyToBeExecutedLocked(job)); |
| 1210 | pw.print(" (job="); |
| 1211 | pw.print(job.isReady()); |
| 1212 | pw.print(" pending="); |
| 1213 | pw.print(mPendingJobs.contains(job)); |
| 1214 | pw.print(" active="); |
| 1215 | pw.print(isCurrentlyActiveLocked(job)); |
| 1216 | pw.print(" user="); |
| 1217 | pw.print(mStartedUsers.contains(job.getUserId())); |
| 1218 | pw.println(")"); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } else { |
Christopher Tate | f973a7b | 2014-08-29 12:54:08 -0700 | [diff] [blame] | 1221 | pw.println(" None."); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1222 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1223 | for (int i=0; i<mControllers.size(); i++) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1224 | pw.println(); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1225 | mControllers.get(i).dumpControllerState(pw); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1226 | } |
| 1227 | pw.println(); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1228 | pw.println(printPendingQueue()); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1229 | pw.println(); |
| 1230 | pw.println("Active jobs:"); |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1231 | for (int i=0; i<mActiveServices.size(); i++) { |
| 1232 | JobServiceContext jsc = mActiveServices.get(i); |
Shreyas Basarge | 5db0908 | 2016-01-07 13:38:29 +0000 | [diff] [blame] | 1233 | if (jsc.getRunningJob() == null) { |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1234 | continue; |
| 1235 | } else { |
Christopher Tate | f973a7b | 2014-08-29 12:54:08 -0700 | [diff] [blame] | 1236 | final long timeout = jsc.getTimeoutElapsed(); |
| 1237 | pw.print("Running for: "); |
| 1238 | pw.print((now - jsc.getExecutionStartTimeElapsed())/1000); |
| 1239 | pw.print("s timeout="); |
| 1240 | pw.print(timeout); |
| 1241 | pw.print(" fromnow="); |
| 1242 | pw.println(timeout-now); |
| 1243 | jsc.getRunningJob().dump(pw, " "); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
Dianne Hackborn | fdb1956 | 2014-07-11 16:03:36 -0700 | [diff] [blame] | 1246 | pw.println(); |
| 1247 | pw.print("mReadyToRock="); pw.println(mReadyToRock); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1248 | pw.print("mDeviceIdleMode="); pw.println(mDeviceIdleMode); |
Dianne Hackborn | 627dfa1 | 2015-11-11 18:10:30 -0800 | [diff] [blame] | 1249 | pw.print("mReportedActive="); pw.println(mReportedActive); |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 1250 | } |
| 1251 | pw.println(); |
| 1252 | } |
| 1253 | } |