From 09a404081a12a4afbf61b347ec8454e1d702ea1a Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Sun, 8 Nov 2009 00:33:23 -0500 Subject: [PATCH] Do not apply keyguard's short timeout when the keyguard is hidden by another window. Fixes bug b/2215852 (Music player doesn't grab screen wakelock) Change-Id: I6c402cdb460d216314ad72e37dbcdc7e19518941 Signed-off-by: Mike Lockwood --- .../policy/impl/KeyguardViewMediator.java | 26 ++++++++++++++----- .../policy/impl/PhoneWindowManager.java | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java index 0fba17b30c863..bfa48eec7d646 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -184,6 +184,9 @@ public class KeyguardViewMediator implements KeyguardViewCallback, // answer whether the input should be restricted) private boolean mShowing = false; + // true if the keyguard is hidden by another window + private boolean mHidden = false; + /** * Helps remember whether the screen has turned on since the last time * it turned off due to timeout. see {@link #onScreenTurnedOff(int)} @@ -417,6 +420,16 @@ public class KeyguardViewMediator implements KeyguardViewCallback, return mShowing; } + /** + * Notify us when the keyguard is hidden by another window + */ + public void setHidden(boolean isHidden) { + synchronized (KeyguardViewMediator.this) { + mHidden = isHidden; + adjustUserActivityLocked(); + } + } + /** * Given the state of the keyguard, is the input restricted? * Input is restricted when the keyguard is showing, or when the keyguard @@ -860,12 +873,9 @@ public class KeyguardViewMediator implements KeyguardViewCallback, if (DEBUG) Log.d(TAG, "handleShow"); if (!mSystemReady) return; - // while we're showing, we control the wake state, so ask the power - // manager not to honor request for userActivity. - mRealPowerManager.enableUserActivity(false); - mKeyguardViewManager.show(); mShowing = true; + adjustUserActivityLocked(); try { ActivityManagerNative.getDefault().closeSystemDialogs("lock"); } catch (RemoteException e) { @@ -885,14 +895,18 @@ public class KeyguardViewMediator implements KeyguardViewCallback, Log.w(TAG, "attempt to hide the keyguard while waking, ignored"); return; } - // When we go away, tell the poewr manager to honor requests from userActivity. - mRealPowerManager.enableUserActivity(true); mKeyguardViewManager.hide(); mShowing = false; + adjustUserActivityLocked(); } } + private void adjustUserActivityLocked() { + // disable user activity if we are shown and not hidden + mRealPowerManager.enableUserActivity(!mShowing || mHidden); + } + /** * Handle message sent by {@link #wakeWhenReadyLocked(int)} * @param keyCode The key that woke the device. diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java index cd06d33f4b146..e57fbe8b544b6 100755 --- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java @@ -1446,12 +1446,14 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } else if (mHideLockScreen) { if (mKeyguard.hideLw(false)) { + mKeyguardMediator.setHidden(true); changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER; } } else { if (mKeyguard.showLw(false)) { + mKeyguardMediator.setHidden(false); changes |= FINISH_LAYOUT_REDO_LAYOUT | FINISH_LAYOUT_REDO_CONFIG | FINISH_LAYOUT_REDO_WALLPAPER;