Delaying jobs while coming out of doze
Foreground uids can run their jobs immediately given other constraints
are met. Other jobs will be delayed by 3 seconds when coming out of
doze to ensure imminent user tasks like screen-on can use resources.
Also added an API to allow apps to indicate their job is important to
the user enough that it is allowed to run when the app is in the
foreground or on the temp whitelist regardless of the dozing state of
the device.
Test: cts-tradefed run singleCommand cts-dev -m JobScheduler -t \
android.jobscheduler.cts.DeviceIdleJobsTest
Bug: 64291952
Bug: 64071030
Change-Id: Id52cb4386e683d4f8297e873b3a68c573e5be743
diff --git a/services/core/java/com/android/server/job/JobSchedulerService.java b/services/core/java/com/android/server/job/JobSchedulerService.java
index b9777ec..4a3becb 100644
--- a/services/core/java/com/android/server/job/JobSchedulerService.java
+++ b/services/core/java/com/android/server/job/JobSchedulerService.java
@@ -151,6 +151,7 @@
StorageController mStorageController;
/** Need directly for sending uid state changes */
private BackgroundJobsController mBackgroundJobsController;
+ private DeviceIdleJobsController mDeviceIdleJobsController;
/**
* Queue of pending jobs. The JobServiceContext class will receive jobs from this list
* when ready to execute them.
@@ -622,15 +623,24 @@
if (disabled) {
cancelJobsForUid(uid, "uid gone");
}
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, false);
+ }
}
@Override public void onUidActive(int uid) throws RemoteException {
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, true);
+ }
}
@Override public void onUidIdle(int uid, boolean disabled) {
if (disabled) {
cancelJobsForUid(uid, "app uid idle");
}
+ synchronized (mLock) {
+ mDeviceIdleJobsController.setUidActiveLocked(uid, false);
+ }
}
@Override public void onUidCachedChanged(int uid, boolean cached) {
@@ -939,11 +949,11 @@
mControllers.add(mBatteryController);
mStorageController = StorageController.get(this);
mControllers.add(mStorageController);
- mBackgroundJobsController = BackgroundJobsController.get(this);
- mControllers.add(mBackgroundJobsController);
+ mControllers.add(BackgroundJobsController.get(this));
mControllers.add(AppIdleController.get(this));
mControllers.add(ContentObserverController.get(this));
- mControllers.add(DeviceIdleJobsController.get(this));
+ mDeviceIdleJobsController = DeviceIdleJobsController.get(this);
+ mControllers.add(mDeviceIdleJobsController);
// If the job store determined that it can't yet reschedule persisted jobs,
// we need to start watching the clock.