From 93e164726f2d243eb75351b4e52d683573f9f802 Mon Sep 17 00:00:00 2001 From: Santos Cordon Date: Wed, 21 Aug 2019 22:25:44 +0100 Subject: [PATCH] Hold Display suspend blocker until doze starts When transitioning to DOZE, there is a race condition between the release of the display suspend blocker and calling startDream. This creates a gap where the device can suspend before the dream actually starts. In practice, this can cause gestures, which are nitialized from the Dream Service, to not function until something else temporarily wakes up the device enough for the CPU to run a few cycles. This change delays the release of the display suspend blocker if there is a pending recalculation of the sleep/doze state. Bug: 138828701 Test: Manual testing - was 1 in 5 chance of reproing. Tested up to 0 out of 50 after the fix. Test: atest PowerManagerServiceTest Change-Id: Ic6df469972dc5765a8c4507404d1dc33f13ec0c3 --- .../com/android/server/power/PowerManagerService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index aa49ba62f48b1..dc56b03bb100e 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -2735,6 +2735,17 @@ public final class PowerManagerService extends SystemService if (mScreenBrightnessBoostInProgress) { return true; } + + // Because summoning the sandman is asyncronous, there is a time-gap where + // we release the display suspend blocker before the dream service acquires + // their own wakelock. Within this gap, we can end up suspending before + // dream service has a chance to start. To avoid this, we check if we want + // to doze and the sandman is scheduled and if so, keep the display on until + // that has passed. + if (mWakefulness == WAKEFULNESS_DOZING && mSandmanScheduled) { + return true; + } + // Let the system suspend if the screen is off or dozing. return false; }