Skip to content

Commit 1042874

Browse files
author
Jeff Brown
committed
Prevent full wake lock from keeping device awake while dreaming.
A dream may itself hold a wake lock in order to keep the screen bright as it runs. However this wake lock also causes the device to stay awake even when it is not plugged in which is undesirable. This change makes full wake locks behave differently when napping or dreaming. The wake lock still keeps the screen bright but it does not prevent the device from falling asleep. This is similar to our policy of ignoring full wake locks completely when the device is manually put to sleep by the user. Bug: 7295909 Change-Id: Id99e82d2143ae1a81629281d6407d7527efb8137
1 parent c0c0c0e commit 1042874

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

services/java/com/android/server/power/PowerManagerService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public final class PowerManagerService extends IPowerManager.Stub
127127
private static final int WAKE_LOCK_SCREEN_DIM = 1 << 2;
128128
private static final int WAKE_LOCK_BUTTON_BRIGHT = 1 << 3;
129129
private static final int WAKE_LOCK_PROXIMITY_SCREEN_OFF = 1 << 4;
130+
private static final int WAKE_LOCK_STAY_AWAKE = 1 << 5; // only set if already awake
130131

131132
// Summarizes the user activity state.
132133
private static final int USER_ACTIVITY_SCREEN_BRIGHT = 1 << 0;
@@ -1172,16 +1173,25 @@ private void updateWakeLockSummaryLocked(int dirty) {
11721173
if (mWakefulness != WAKEFULNESS_ASLEEP) {
11731174
mWakeLockSummary |= WAKE_LOCK_CPU
11741175
| WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_BUTTON_BRIGHT;
1176+
if (mWakefulness == WAKEFULNESS_AWAKE) {
1177+
mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
1178+
}
11751179
}
11761180
break;
11771181
case PowerManager.SCREEN_BRIGHT_WAKE_LOCK:
11781182
if (mWakefulness != WAKEFULNESS_ASLEEP) {
11791183
mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_BRIGHT;
1184+
if (mWakefulness == WAKEFULNESS_AWAKE) {
1185+
mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
1186+
}
11801187
}
11811188
break;
11821189
case PowerManager.SCREEN_DIM_WAKE_LOCK:
11831190
if (mWakefulness != WAKEFULNESS_ASLEEP) {
11841191
mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_SCREEN_DIM;
1192+
if (mWakefulness == WAKEFULNESS_AWAKE) {
1193+
mWakeLockSummary |= WAKE_LOCK_STAY_AWAKE;
1194+
}
11851195
}
11861196
break;
11871197
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
@@ -1339,7 +1349,7 @@ private boolean isItBedTimeYetLocked() {
13391349
private boolean isBeingKeptAwakeLocked() {
13401350
return mStayOn
13411351
|| mProximityPositive
1342-
|| (mWakeLockSummary & (WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM)) != 0
1352+
|| (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0
13431353
|| (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
13441354
| USER_ACTIVITY_SCREEN_DIM)) != 0;
13451355
}

0 commit comments

Comments
 (0)