Merge "Fix issue #29371078: Foreground jobs should not count..." into nyc-dev

This commit is contained in:
Dianne Hackborn
2016-06-16 18:39:02 +00:00
committed by Android (Google) Code Review
6 changed files with 34 additions and 67 deletions

View File

@@ -38,8 +38,6 @@ interface IDeviceIdleController {
long addPowerSaveTempWhitelistAppForMms(String name, int userId, String reason);
long addPowerSaveTempWhitelistAppForSms(String name, int userId, String reason);
void exitIdle(String reason);
void downloadServiceActive(IBinder token);
void downloadServiceInactive();
boolean registerMaintenanceActivityListener(IMaintenanceActivityListener listener);
void unregisterMaintenanceActivityListener(IMaintenanceActivityListener listener);
}

View File

@@ -212,7 +212,6 @@ public class DeviceIdleController extends SystemService
private int mActiveIdleOpCount;
private PowerManager.WakeLock mActiveIdleWakeLock;
private IBinder mDownloadServiceActive;
private boolean mJobsActive;
private boolean mAlarmsActive;
private boolean mReportedMaintenanceActivity;
@@ -607,7 +606,7 @@ public class DeviceIdleController extends SystemService
* This is the minimum amount of time that we will stay in maintenance mode after
* a light doze. We have this minimum to allow various things to respond to switching
* in to maintenance mode and scheduling their work -- otherwise we may
* see there is nothing to do (no jobs or downloads pending) and go out of maintenance
* see there is nothing to do (no jobs pending) and go out of maintenance
* mode immediately.
* @see Settings.Global#DEVICE_IDLE_CONSTANTS
* @see #KEY_MIN_LIGHT_MAINTENANCE_TIME
@@ -618,7 +617,7 @@ public class DeviceIdleController extends SystemService
* This is the minimum amount of time that we will stay in maintenance mode after
* a full doze. We have this minimum to allow various things to respond to switching
* in to maintenance mode and scheduling their work -- otherwise we may
* see there is nothing to do (no jobs or downloads pending) and go out of maintenance
* see there is nothing to do (no jobs pending) and go out of maintenance
* mode immediately.
* @see Settings.Global#DEVICE_IDLE_CONSTANTS
* @see #KEY_MIN_DEEP_MAINTENANCE_TIME
@@ -1220,28 +1219,6 @@ public class DeviceIdleController extends SystemService
}
}
@Override public void downloadServiceActive(IBinder token) {
getContext().enforceCallingOrSelfPermission(
"android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS", null);
long ident = Binder.clearCallingIdentity();
try {
DeviceIdleController.this.downloadServiceActive(token);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override public void downloadServiceInactive() {
getContext().enforceCallingOrSelfPermission(
"android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS", null);
long ident = Binder.clearCallingIdentity();
try {
DeviceIdleController.this.downloadServiceInactive();
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override public boolean registerMaintenanceActivityListener(
IMaintenanceActivityListener listener) {
return DeviceIdleController.this.registerMaintenanceActivityListener(listener);
@@ -2086,30 +2063,6 @@ public class DeviceIdleController extends SystemService
}
}
void downloadServiceActive(IBinder token) {
synchronized (this) {
mDownloadServiceActive = token;
reportMaintenanceActivityIfNeededLocked();
try {
token.linkToDeath(new IBinder.DeathRecipient() {
@Override public void binderDied() {
downloadServiceInactive();
}
}, 0);
} catch (RemoteException e) {
mDownloadServiceActive = null;
}
}
}
void downloadServiceInactive() {
synchronized (this) {
mDownloadServiceActive = null;
reportMaintenanceActivityIfNeededLocked();
exitMaintenanceEarlyIfNeededLocked();
}
}
void setJobsActive(boolean active) {
synchronized (this) {
mJobsActive = active;
@@ -2143,7 +2096,7 @@ public class DeviceIdleController extends SystemService
}
void reportMaintenanceActivityIfNeededLocked() {
boolean active = mJobsActive | (mDownloadServiceActive != null);
boolean active = mJobsActive;
if (active == mReportedMaintenanceActivity) {
return;
}
@@ -2154,8 +2107,7 @@ public class DeviceIdleController extends SystemService
}
boolean isOpsInactiveLocked() {
return mActiveIdleOpCount <= 0 && mDownloadServiceActive == null
&& !mJobsActive && !mAlarmsActive;
return mActiveIdleOpCount <= 0 && !mJobsActive && !mAlarmsActive;
}
void exitMaintenanceEarlyIfNeededLocked() {
@@ -3053,9 +3005,6 @@ public class DeviceIdleController extends SystemService
if (mAlarmsActive) {
pw.print(" mAlarmsActive="); pw.println(mAlarmsActive);
}
if (mDownloadServiceActive != null) {
pw.print(" mDownloadServiceActive="); pw.println(mDownloadServiceActive);
}
}
}

View File

@@ -692,8 +692,13 @@ public final class JobSchedulerService extends com.android.server.SystemService
boolean active = mPendingJobs.size() > 0;
if (mPendingJobs.size() <= 0) {
for (int i=0; i<mActiveServices.size(); i++) {
JobServiceContext jsc = mActiveServices.get(i);
if (jsc.getRunningJob() != null) {
final JobServiceContext jsc = mActiveServices.get(i);
final JobStatus job = jsc.getRunningJob();
if (job != null
&& (job.getJob().getFlags() & JobInfo.FLAG_WILL_BE_FOREGROUND) == 0
&& !job.dozeWhitelisted) {
// We will report active if we have a job running and it is not an exception
// due to being in the foreground or whitelisted.
active = true;
break;
}

View File

@@ -142,8 +142,11 @@ public class AppIdleController extends StateController {
UserHandle.formatUid(pw, jobStatus.getSourceUid());
pw.print(": ");
pw.print(jobStatus.getSourcePackageName());
pw.print(", runnable=");
pw.println((jobStatus.satisfiedConstraints&JobStatus.CONSTRAINT_APP_NOT_IDLE) != 0);
if ((jobStatus.satisfiedConstraints&JobStatus.CONSTRAINT_APP_NOT_IDLE) != 0) {
pw.println(" RUNNABLE");
} else {
pw.println(" WAITING");
}
}
});
}

View File

@@ -157,8 +157,9 @@ public class DeviceIdleJobsController extends StateController {
}
private void updateTaskStateLocked(JobStatus task) {
boolean enableTask = !mDeviceIdleMode || isWhitelistedLocked(task);
task.setDeviceNotDozingConstraintSatisfied(enableTask);
final boolean whitelisted = isWhitelistedLocked(task);
final boolean enableTask = !mDeviceIdleMode || whitelisted;
task.setDeviceNotDozingConstraintSatisfied(enableTask, whitelisted);
}
@Override
@@ -186,9 +187,13 @@ public class DeviceIdleJobsController extends StateController {
UserHandle.formatUid(pw, jobStatus.getSourceUid());
pw.print(": ");
pw.print(jobStatus.getSourcePackageName());
pw.print(", runnable=");
pw.println((jobStatus.satisfiedConstraints
& JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0);
pw.print((jobStatus.satisfiedConstraints
& JobStatus.CONSTRAINT_DEVICE_NOT_DOZING) != 0
? " RUNNABLE" : " WAITING");
if (jobStatus.dozeWhitelisted) {
pw.print(" WHITELISTED");
}
pw.println();
}
});
}

View File

@@ -103,6 +103,9 @@ public final class JobStatus {
final int requiredConstraints;
int satisfiedConstraints = 0;
// Set to true if doze constraint was satisfied due to app being whitelisted.
public boolean dozeWhitelisted;
// These are filled in by controllers when preparing for execution.
public ArraySet<Uri> changedUris;
public ArraySet<String> changedAuthorities;
@@ -403,7 +406,8 @@ public final class JobStatus {
return setConstraintSatisfied(CONSTRAINT_CONTENT_TRIGGER, state);
}
boolean setDeviceNotDozingConstraintSatisfied(boolean state) {
boolean setDeviceNotDozingConstraintSatisfied(boolean state, boolean whitelisted) {
dozeWhitelisted = whitelisted;
return setConstraintSatisfied(CONSTRAINT_DEVICE_NOT_DOZING, state);
}
@@ -651,6 +655,9 @@ public final class JobStatus {
pw.print(prefix); pw.print("Unsatisfied constraints:");
dumpConstraints(pw, (requiredConstraints & ~satisfiedConstraints));
pw.println();
if (dozeWhitelisted) {
pw.print(prefix); pw.println("Doze whitelisted: true");
}
}
if (changedAuthorities != null) {
pw.print(prefix); pw.println("Changed authorities:");