From 73298fa25dbd1912c5184dfce43f3947b32a53ff Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Fri, 7 Feb 2020 16:51:49 +0100 Subject: [PATCH] Add additional dirty checks in updateWakefulnessLocked updateWakefulnessLocked is responsible for updating the wakefulness state, ie. going to sleep if sleep conditions are met. By changing the sleep timeout settings to a value that is lower than the time since last user activity, you can get into a state where the device does not go to sleep even though the sleep timeout is expired. updateWakefulnessLocked should check all dirty flags that could trigger a change in wakefulness. This CL adds checks for two dirty flags: - DIRTY_SETTINGS: As described above, changing the sleep timeout could lead to a situation in which the sleep timeout is already expired and the device should go to sleep - DIRTY_SCREEN_BRIGHTNESS_BOOST: Inattentive sleep is disabled during screen brightness boosts. As soon as the brightness boost ends, the device should go to sleep if the timeout is expired. Bug: 149008991 Test: 1. adb shell settings put secure sleep_timeout 900000 2. adb shell input keyevent HOME 3. sleep 15 4. adb shell settings put secure sleep_timeout 10000 Observe: Device goes to sleep Test: 1. adb shell settings put secure attentive_timeout -1 2. adb shell input keyevent HOME 3. sleep 40 4. adb shell settings put secure attentive_timeout 32000 Observe: Device goes to sleep Change-Id: I86be64f18f5c4d9dba43376fa608223b8c5ae6b2 --- .../java/com/android/server/power/PowerManagerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 4d13658c85b7b..885c1dde5a9e4 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -2385,7 +2385,8 @@ public final class PowerManagerService extends SystemService boolean changed = false; if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_BOOT_COMPLETED | DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE - | DIRTY_DOCK_STATE | DIRTY_ATTENTIVE)) != 0) { + | DIRTY_DOCK_STATE | DIRTY_ATTENTIVE | DIRTY_SETTINGS + | DIRTY_SCREEN_BRIGHTNESS_BOOST)) != 0) { if (mWakefulness == WAKEFULNESS_AWAKE && isItBedTimeYetLocked()) { if (DEBUG_SPEW) { Slog.d(TAG, "updateWakefulnessLocked: Bed time...");