From 018319a0242dfc46a73943b739b0a16b11d66e2b Mon Sep 17 00:00:00 2001 From: Nick Vaccaro Date: Wed, 22 Apr 2015 19:16:43 -0700 Subject: [PATCH] Wait for KEY_SLEEP UP event before calling goToSleep() Calling goToSleep() on the KEY_SLEEP DOWN event causes a race condition with the touch driver when the KEY_SLEEP event is generated via a palm press if the touch controller is told to go into AMBIENT_ON mode (touch controller goes into suspend mode) while the user's palm is still on the touch panel. If touch controller gets into suspend mode before user removes their palm, the act of removing the palm from the screen will cause the touch controller to generate a wake event and the device will "wake back up" into interactive mode. Waiting for the KEY_SLEEP UP event before putting the device to sleep assures palm is off the panel and thus removes this race case. Bug: 19951365 Change-Id: Icf565177696769b8dbeeb645ac883ebe3e0acb45 --- .../policy/impl/PhoneWindowManager.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 634b57eb4c9d3..a5097066268cd 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -1063,16 +1063,19 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } - private void sleepPress(KeyEvent event) { + private void sleepPress(long eventTime) { + if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) { + launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); + } + } + + private void sleepRelease(long eventTime) { switch (mShortPressOnSleepBehavior) { case SHORT_PRESS_SLEEP_GO_TO_SLEEP: - mPowerManager.goToSleep(event.getEventTime(), - PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); - break; case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME: - launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/); - mPowerManager.goToSleep(event.getEventTime(), - PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); + Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)"); + mPowerManager.goToSleep(eventTime, + PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0); break; } } @@ -4779,7 +4782,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (!mPowerManager.isInteractive()) { useHapticFeedback = false; // suppress feedback if already non-interactive } - sleepPress(event); + if (down) { + sleepPress(event.getEventTime()); + } else { + sleepRelease(event.getEventTime()); + } break; }