Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.job.controllers; |
| 18 | |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 19 | import android.app.job.JobInfo; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.Looper; |
| 26 | import android.os.Message; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 27 | import android.os.PowerManager; |
| 28 | import android.os.UserHandle; |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 29 | import android.util.ArraySet; |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 30 | import android.util.Log; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 31 | import android.util.Slog; |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 32 | import android.util.SparseBooleanArray; |
Kweku Adams | 85f2fbc | 2017-12-18 12:04:12 -0800 | [diff] [blame] | 33 | import android.util.proto.ProtoOutputStream; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 34 | |
| 35 | import com.android.internal.util.ArrayUtils; |
| 36 | import com.android.server.DeviceIdleController; |
| 37 | import com.android.server.LocalServices; |
| 38 | import com.android.server.job.JobSchedulerService; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 39 | import com.android.server.job.JobStore; |
Kweku Adams | 85f2fbc | 2017-12-18 12:04:12 -0800 | [diff] [blame] | 40 | import com.android.server.job.StateControllerProto; |
| 41 | import com.android.server.job.StateControllerProto.DeviceIdleJobsController.TrackedJob; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 42 | |
| 43 | import java.io.PrintWriter; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 44 | import java.util.Arrays; |
| 45 | |
| 46 | /** |
| 47 | * When device is dozing, set constraint for all jobs, except whitelisted apps, as not satisfied. |
| 48 | * When device is not dozing, set constraint for all jobs as satisfied. |
| 49 | */ |
Dianne Hackborn | 6466c1c | 2017-06-13 10:33:19 -0700 | [diff] [blame] | 50 | public final class DeviceIdleJobsController extends StateController { |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 51 | private static final String TAG = "JobScheduler.DeviceIdle"; |
| 52 | private static final boolean DEBUG = JobSchedulerService.DEBUG |
| 53 | || Log.isLoggable(TAG, Log.DEBUG); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 54 | |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 55 | private static final long BACKGROUND_JOBS_DELAY = 3000; |
| 56 | |
| 57 | static final int PROCESS_BACKGROUND_JOBS = 1; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 58 | |
| 59 | // Singleton factory |
| 60 | private static Object sCreationLock = new Object(); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 61 | private static DeviceIdleJobsController sController; |
| 62 | |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 63 | /** |
| 64 | * These are jobs added with a special flag to indicate that they should be exempted from doze |
| 65 | * when the app is temp whitelisted or in the foreground. |
| 66 | */ |
| 67 | private final ArraySet<JobStatus> mAllowInIdleJobs; |
| 68 | private final SparseBooleanArray mForegroundUids; |
| 69 | private final DeviceIdleUpdateFunctor mDeviceIdleUpdateFunctor; |
| 70 | private final DeviceIdleJobsDelayHandler mHandler; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 71 | private final JobSchedulerService mJobSchedulerService; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 72 | private final PowerManager mPowerManager; |
| 73 | private final DeviceIdleController.LocalService mLocalDeviceIdleController; |
| 74 | |
| 75 | /** |
| 76 | * True when in device idle mode, so we don't want to schedule any jobs. |
| 77 | */ |
| 78 | private boolean mDeviceIdleMode; |
| 79 | private int[] mDeviceIdleWhitelistAppIds; |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 80 | private int[] mPowerSaveTempWhitelistAppIds; |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 81 | |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 82 | /** |
| 83 | * Returns a singleton for the DeviceIdleJobsController |
| 84 | */ |
| 85 | public static DeviceIdleJobsController get(JobSchedulerService service) { |
| 86 | synchronized (sCreationLock) { |
| 87 | if (sController == null) { |
| 88 | sController = new DeviceIdleJobsController(service, service.getContext(), |
| 89 | service.getLock()); |
| 90 | } |
| 91 | return sController; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // onReceive |
| 96 | private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { |
| 97 | @Override |
| 98 | public void onReceive(Context context, Intent intent) { |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 99 | switch (intent.getAction()) { |
| 100 | case PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED: |
| 101 | case PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED: |
| 102 | updateIdleMode(mPowerManager != null && (mPowerManager.isDeviceIdleMode() |
| 103 | || mPowerManager.isLightDeviceIdleMode())); |
| 104 | break; |
| 105 | case PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED: |
| 106 | synchronized (mLock) { |
| 107 | mDeviceIdleWhitelistAppIds = |
| 108 | mLocalDeviceIdleController.getPowerSaveWhitelistUserAppIds(); |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 109 | if (DEBUG) { |
| 110 | Slog.d(TAG, "Got whitelist " |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 111 | + Arrays.toString(mDeviceIdleWhitelistAppIds)); |
| 112 | } |
| 113 | } |
| 114 | break; |
| 115 | case PowerManager.ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED: |
| 116 | synchronized (mLock) { |
| 117 | mPowerSaveTempWhitelistAppIds = |
| 118 | mLocalDeviceIdleController.getPowerSaveTempWhitelistAppIds(); |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 119 | if (DEBUG) { |
| 120 | Slog.d(TAG, "Got temp whitelist " |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 121 | + Arrays.toString(mPowerSaveTempWhitelistAppIds)); |
| 122 | } |
| 123 | boolean changed = false; |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 124 | for (int i = 0; i < mAllowInIdleJobs.size(); i++) { |
| 125 | changed |= updateTaskStateLocked(mAllowInIdleJobs.valueAt(i)); |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 126 | } |
| 127 | if (changed) { |
| 128 | mStateChangedListener.onControllerStateChanged(); |
| 129 | } |
| 130 | } |
| 131 | break; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | }; |
| 135 | |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 136 | private DeviceIdleJobsController(JobSchedulerService jobSchedulerService, Context context, |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 137 | Object lock) { |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 138 | super(jobSchedulerService, context, lock); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 139 | |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 140 | mJobSchedulerService = jobSchedulerService; |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 141 | mHandler = new DeviceIdleJobsDelayHandler(context.getMainLooper()); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 142 | // Register for device idle mode changes |
| 143 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
| 144 | mLocalDeviceIdleController = |
| 145 | LocalServices.getService(DeviceIdleController.LocalService.class); |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 146 | mDeviceIdleWhitelistAppIds = mLocalDeviceIdleController.getPowerSaveWhitelistUserAppIds(); |
| 147 | mPowerSaveTempWhitelistAppIds = |
| 148 | mLocalDeviceIdleController.getPowerSaveTempWhitelistAppIds(); |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 149 | mDeviceIdleUpdateFunctor = new DeviceIdleUpdateFunctor(); |
| 150 | mAllowInIdleJobs = new ArraySet<>(); |
| 151 | mForegroundUids = new SparseBooleanArray(); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 152 | final IntentFilter filter = new IntentFilter(); |
| 153 | filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); |
| 154 | filter.addAction(PowerManager.ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED); |
| 155 | filter.addAction(PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED); |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 156 | filter.addAction(PowerManager.ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 157 | mContext.registerReceiverAsUser( |
| 158 | mBroadcastReceiver, UserHandle.ALL, filter, null, null); |
| 159 | } |
| 160 | |
| 161 | void updateIdleMode(boolean enabled) { |
| 162 | boolean changed = false; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 163 | synchronized (mLock) { |
| 164 | if (mDeviceIdleMode != enabled) { |
| 165 | changed = true; |
| 166 | } |
| 167 | mDeviceIdleMode = enabled; |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 168 | if (DEBUG) Slog.d(TAG, "mDeviceIdleMode=" + mDeviceIdleMode); |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 169 | if (enabled) { |
| 170 | mHandler.removeMessages(PROCESS_BACKGROUND_JOBS); |
| 171 | mJobSchedulerService.getJobStore().forEachJob(mDeviceIdleUpdateFunctor); |
| 172 | } else { |
| 173 | // When coming out of doze, process all foreground uids immediately, while others |
| 174 | // will be processed after a delay of 3 seconds. |
| 175 | for (int i = 0; i < mForegroundUids.size(); i++) { |
| 176 | if (mForegroundUids.valueAt(i)) { |
| 177 | mJobSchedulerService.getJobStore().forEachJobForSourceUid( |
| 178 | mForegroundUids.keyAt(i), mDeviceIdleUpdateFunctor); |
| 179 | } |
| 180 | } |
| 181 | mHandler.sendEmptyMessageDelayed(PROCESS_BACKGROUND_JOBS, BACKGROUND_JOBS_DELAY); |
| 182 | } |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 183 | } |
| 184 | // Inform the job scheduler service about idle mode changes |
| 185 | if (changed) { |
| 186 | mStateChangedListener.onDeviceIdleStateChanged(enabled); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /** |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 191 | * Called by jobscheduler service to report uid state changes between active and idle |
| 192 | */ |
| 193 | public void setUidActiveLocked(int uid, boolean active) { |
| 194 | final boolean changed = (active != mForegroundUids.get(uid)); |
| 195 | if (!changed) { |
| 196 | return; |
| 197 | } |
Jeff Sharkey | 01bb530 | 2018-02-21 20:12:40 -0700 | [diff] [blame] | 198 | if (DEBUG) { |
| 199 | Slog.d(TAG, "uid " + uid + " going " + (active ? "active" : "inactive")); |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 200 | } |
| 201 | mForegroundUids.put(uid, active); |
| 202 | mDeviceIdleUpdateFunctor.mChanged = false; |
| 203 | mJobSchedulerService.getJobStore().forEachJobForSourceUid(uid, mDeviceIdleUpdateFunctor); |
| 204 | if (mDeviceIdleUpdateFunctor.mChanged) { |
| 205 | mStateChangedListener.onControllerStateChanged(); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /** |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 210 | * Checks if the given job's scheduling app id exists in the device idle user whitelist. |
| 211 | */ |
| 212 | boolean isWhitelistedLocked(JobStatus job) { |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 213 | return Arrays.binarySearch(mDeviceIdleWhitelistAppIds, |
| 214 | UserHandle.getAppId(job.getSourceUid())) >= 0; |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 217 | /** |
| 218 | * Checks if the given job's scheduling app id exists in the device idle temp whitelist. |
| 219 | */ |
| 220 | boolean isTempWhitelistedLocked(JobStatus job) { |
| 221 | return ArrayUtils.contains(mPowerSaveTempWhitelistAppIds, |
| 222 | UserHandle.getAppId(job.getSourceUid())); |
| 223 | } |
| 224 | |
| 225 | private boolean updateTaskStateLocked(JobStatus task) { |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 226 | final boolean allowInIdle = ((task.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) |
| 227 | && (mForegroundUids.get(task.getSourceUid()) || isTempWhitelistedLocked(task)); |
| 228 | final boolean whitelisted = isWhitelistedLocked(task); |
| 229 | final boolean enableTask = !mDeviceIdleMode || whitelisted || allowInIdle; |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 230 | return task.setDeviceNotDozingConstraintSatisfied(enableTask, whitelisted); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
| 234 | public void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob) { |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 235 | if ((jobStatus.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) { |
| 236 | mAllowInIdleJobs.add(jobStatus); |
Suprabh Shukla | a78acfd | 2017-10-13 19:29:36 -0700 | [diff] [blame] | 237 | } |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 238 | updateTaskStateLocked(jobStatus); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 242 | public void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob, |
| 243 | boolean forUpdate) { |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 244 | if ((jobStatus.getFlags()&JobInfo.FLAG_IMPORTANT_WHILE_FOREGROUND) != 0) { |
| 245 | mAllowInIdleJobs.remove(jobStatus); |
| 246 | } |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | @Override |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 250 | public void dumpControllerStateLocked(final PrintWriter pw, final int filterUid) { |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 251 | pw.println("DeviceIdleJobsController"); |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 252 | pw.println("mDeviceIdleMode=" + mDeviceIdleMode); |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 253 | mJobSchedulerService.getJobStore().forEachJob(new JobStore.JobStatusFunctor() { |
| 254 | @Override public void process(JobStatus jobStatus) { |
Dianne Hackborn | ef3aa6e | 2016-04-29 18:18:08 -0700 | [diff] [blame] | 255 | if (!jobStatus.shouldDump(filterUid)) { |
| 256 | return; |
| 257 | } |
Dianne Hackborn | e9a988c | 2016-05-27 17:59:40 -0700 | [diff] [blame] | 258 | pw.print(" #"); |
| 259 | jobStatus.printUniqueId(pw); |
| 260 | pw.print(" from "); |
| 261 | UserHandle.formatUid(pw, jobStatus.getSourceUid()); |
| 262 | pw.print(": "); |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 263 | pw.print(jobStatus.getSourcePackageName()); |
Dianne Hackborn | 7ab4025 | 2016-06-15 17:30:24 -0700 | [diff] [blame] | 264 | pw.print((jobStatus.satisfiedConstraints |
| 265 | & JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0 |
| 266 | ? " RUNNABLE" : " WAITING"); |
| 267 | if (jobStatus.dozeWhitelisted) { |
| 268 | pw.print(" WHITELISTED"); |
| 269 | } |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 270 | if (mAllowInIdleJobs.contains(jobStatus)) { |
| 271 | pw.print(" ALLOWED_IN_DOZE"); |
| 272 | } |
Dianne Hackborn | 7ab4025 | 2016-06-15 17:30:24 -0700 | [diff] [blame] | 273 | pw.println(); |
Dianne Hackborn | 8db0fc1 | 2016-04-12 13:48:25 -0700 | [diff] [blame] | 274 | } |
| 275 | }); |
Amith Yamasani | cb926fc | 2016-03-14 17:15:20 -0700 | [diff] [blame] | 276 | } |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 277 | |
Kweku Adams | 85f2fbc | 2017-12-18 12:04:12 -0800 | [diff] [blame] | 278 | @Override |
| 279 | public void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId, int filterUid) { |
| 280 | final long token = proto.start(fieldId); |
| 281 | final long mToken = proto.start(StateControllerProto.DEVICE_IDLE); |
| 282 | |
| 283 | proto.write(StateControllerProto.DeviceIdleJobsController.IS_DEVICE_IDLE_MODE, |
| 284 | mDeviceIdleMode); |
| 285 | mJobSchedulerService.getJobStore().forEachJob(new JobStore.JobStatusFunctor() { |
| 286 | @Override public void process(JobStatus jobStatus) { |
| 287 | if (!jobStatus.shouldDump(filterUid)) { |
| 288 | return; |
| 289 | } |
| 290 | final long jsToken = |
| 291 | proto.start(StateControllerProto.DeviceIdleJobsController.TRACKED_JOBS); |
| 292 | |
| 293 | jobStatus.writeToShortProto(proto, TrackedJob.INFO); |
| 294 | proto.write(TrackedJob.SOURCE_UID, jobStatus.getSourceUid()); |
| 295 | proto.write(TrackedJob.SOURCE_PACKAGE_NAME, jobStatus.getSourcePackageName()); |
| 296 | proto.write(TrackedJob.ARE_CONSTRAINTS_SATISFIED, |
| 297 | (jobStatus.satisfiedConstraints & |
| 298 | JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0); |
| 299 | proto.write(TrackedJob.IS_DOZE_WHITELISTED, jobStatus.dozeWhitelisted); |
| 300 | proto.write(TrackedJob.IS_ALLOWED_IN_DOZE, mAllowInIdleJobs.contains(jobStatus)); |
| 301 | |
| 302 | proto.end(jsToken); |
| 303 | } |
| 304 | }); |
| 305 | |
| 306 | proto.end(mToken); |
| 307 | proto.end(token); |
| 308 | } |
| 309 | |
Suprabh Shukla | 106203b | 2017-11-02 21:23:44 -0700 | [diff] [blame] | 310 | final class DeviceIdleUpdateFunctor implements JobStore.JobStatusFunctor { |
| 311 | boolean mChanged; |
| 312 | |
| 313 | @Override |
| 314 | public void process(JobStatus jobStatus) { |
| 315 | mChanged |= updateTaskStateLocked(jobStatus); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | final class DeviceIdleJobsDelayHandler extends Handler { |
| 320 | public DeviceIdleJobsDelayHandler(Looper looper) { |
| 321 | super(looper); |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public void handleMessage(Message msg) { |
| 326 | switch (msg.what) { |
| 327 | case PROCESS_BACKGROUND_JOBS: |
| 328 | // Just process all the jobs, the ones in foreground should already be running. |
| 329 | synchronized (mLock) { |
| 330 | mDeviceIdleUpdateFunctor.mChanged = false; |
| 331 | mJobSchedulerService.getJobStore().forEachJob(mDeviceIdleUpdateFunctor); |
| 332 | if (mDeviceIdleUpdateFunctor.mChanged) { |
| 333 | mStateChangedListener.onControllerStateChanged(); |
| 334 | } |
| 335 | } |
| 336 | break; |
| 337 | } |
| 338 | } |
| 339 | } |
Kweku Adams | 85f2fbc | 2017-12-18 12:04:12 -0800 | [diff] [blame] | 340 | } |