From 951ea6907c6cc01ce3f9ec4859d65a184c7ce785 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 2 Nov 2016 10:41:53 -0700 Subject: [PATCH] Power manager always needs to allow wake locks for services, receivers The change to not allow wake locks for idle apps was a little too aggressive, since we allow apps that are currently executing services or receivers to be idle. (Idle means that it hasn't been in the foreground for X amount of time, but services and receivers don't count as being in the foreground.) So this takes in to account the actual procstate of the uid to determine if it should actually respect the current idle state. Test: manual Change-Id: I32949124b37875b13233478719abccb8369e47f6 --- .../server/power/PowerManagerService.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 6b967a291b707..d755e58c2ba28 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -2631,9 +2631,18 @@ public final class PowerManagerService extends SystemService state = new UidState(uid); mUidState.put(uid, state); } + final boolean oldShouldAllow = state.mProcState + <= ActivityManager.PROCESS_STATE_RECEIVER; state.mProcState = procState; - if (mDeviceIdleMode && state.mNumWakeLocks > 0) { - handleUidStateChangeLocked(); + if (state.mNumWakeLocks > 0) { + if (mDeviceIdleMode) { + handleUidStateChangeLocked(); + } else if (!state.mActive && oldShouldAllow != + (procState <= ActivityManager.PROCESS_STATE_RECEIVER)) { + // If this uid is not active, but the process state has changed such + // that we may still want to allow it to hold a wake lock, then take care of it. + handleUidStateChangeLocked(); + } } } } @@ -2721,7 +2730,8 @@ public final class PowerManagerService extends SystemService disabled = true; } } else { - disabled = !wakeLock.mUidState.mActive; + disabled = !wakeLock.mUidState.mActive && + wakeLock.mUidState.mProcState > ActivityManager.PROCESS_STATE_RECEIVER; } } if (wakeLock.mDisabled != disabled) {