From b446e9767a99b8b3ae4e91a9fd797beb70bf99df Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Sun, 20 Sep 2009 15:23:25 -0700 Subject: [PATCH] Improvements to lock screen management: - The window flag to hide the lock screen will now allow you to press home, and automatically dismiss the lock screen if it is not needed for security. - When opening the lid, if the lock screen will be shown, try to avoid turning on the screen until it is ready. There is actually still some problem with this. Change-Id: I51d769b8e6cff7b439b1ffea927c0a01376427b1 --- .../policy/impl/KeyguardViewMediator.java | 47 ++++++++++--------- .../policy/impl/PhoneWindowManager.java | 27 ++++++++--- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java index b1ce74679477e..682ea9f3102d5 100644 --- a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -84,7 +84,7 @@ import android.view.WindowManagerPolicy; * thread of the keyguard. */ public class KeyguardViewMediator implements KeyguardViewCallback, - KeyguardUpdateMonitor.ConfigurationChangeCallback, KeyguardUpdateMonitor.SimStateCallback { + KeyguardUpdateMonitor.SimStateCallback { private final static boolean DEBUG = false && Config.LOGD; private final static boolean DBG_WAKE = DEBUG || true; @@ -104,6 +104,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback, private static final int WAKE_WHEN_READY = 8; private static final int KEYGUARD_DONE = 9; private static final int KEYGUARD_DONE_DRAWING = 10; + private static final int HIDE_KEYGUARD = 11; /** * The default amount of time we stay awake (used for all key input) @@ -245,7 +246,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback, mUpdateMonitor = new KeyguardUpdateMonitor(context); - mUpdateMonitor.registerConfigurationChangeCallback(this); mUpdateMonitor.registerSimStateCallback(this); mKeyguardViewProperties = @@ -434,6 +434,21 @@ public class KeyguardViewMediator implements KeyguardViewCallback, return mShowing || mNeedToReshowWhenReenabled || !mUpdateMonitor.isDeviceProvisioned(); } + /** + * Returns true if the change is resulting in the keyguard beign dismissed, + * meaning the screen can turn on immediately. Otherwise returns false. + */ + public boolean doLidChangeTq(boolean isLidOpen) { + mKeyboardOpen = isLidOpen; + + if (mUpdateMonitor.isKeyguardBypassEnabled() && mKeyboardOpen + && !mKeyguardViewProperties.isSecure() && mKeyguardViewManager.isShowing()) { + if (DEBUG) Log.d(TAG, "bypassing keyguard on sliding open of keyboard with non-secure keyguard"); + mHandler.sendEmptyMessage(HIDE_KEYGUARD); + return true; + } + return false; + } /** * Enable the keyguard if the settings are appropriate. @@ -558,26 +573,6 @@ public class KeyguardViewMediator implements KeyguardViewCallback, mHandler.sendMessage(msg); } - /** - * {@link KeyguardUpdateMonitor} callbacks. - */ - - /** {@inheritDoc} */ - public void onOrientationChange(boolean inPortrait) { - - } - - /** {@inheritDoc} */ - public void onKeyboardChange(boolean isKeyboardOpen) { - mKeyboardOpen = isKeyboardOpen; - - if (mUpdateMonitor.isKeyguardBypassEnabled() && mKeyboardOpen - && !mKeyguardViewProperties.isSecure() && mKeyguardViewManager.isShowing()) { - if (DEBUG) Log.d(TAG, "bypassing keyguard on sliding open of keyboard with non-secure keyguard"); - keyguardDone(true); - } - } - /** {@inheritDoc} */ public void onSimStateChanged(IccCard.State simState) { if (DEBUG) Log.d(TAG, "onSimStateChanged: " + simState); @@ -615,6 +610,10 @@ public class KeyguardViewMediator implements KeyguardViewCallback, } } + public boolean isSecure() { + return mKeyguardViewProperties.isSecure(); + } + private BroadcastReceiver mBroadCastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -793,6 +792,10 @@ public class KeyguardViewMediator implements KeyguardViewCallback, return; case KEYGUARD_DONE_DRAWING: handleKeyguardDoneDrawing(); + return; + case HIDE_KEYGUARD: + keyguardDone(true); + return; } } }; diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java index 4d02a9df7757e..41d76e8b28991 100644 --- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java @@ -1050,9 +1050,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { * given the situation with the keyguard. */ void launchHomeFromHotKey() { - if (mKeyguardMediator.isShowing()) { + if (!mHideKeyguard && mKeyguardMediator.isShowing()) { // don't launch home if keyguard showing - } else if (mKeyguardMediator.isInputRestricted()) { + } else if (!mHideKeyguard && mKeyguardMediator.isInputRestricted()) { // when in keyguard restricted mode, must first verify unlock // before launching home mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() { @@ -1370,6 +1370,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (localLOGV) Log.i(TAG, "finishLayoutLw::mHideKeyguard="+mHideKeyguard); if (mHideKeyguard) { changed |= mKeyguard.hideLw(true); + if (!mKeyguardMediator.isShowing()) { + mHandler.post(new Runnable() { + public void run() { + mKeyguardMediator.keyguardDone(true); + } + }); + } } else { changed |= mKeyguard.showLw(true); } @@ -1410,12 +1417,20 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (event.keycode == RawInputEvent.SW_LID) { // lid changed state mLidOpen = event.value == 0; + boolean awakeNow = mKeyguardMediator.doLidChangeTq(mLidOpen); updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); - if (keyguardIsShowingTq()) { + if (awakeNow) { + // If the lid opening and we don't have to keep the + // keyguard up, then we can turn on the screen + // immediately. + mKeyguardMediator.pokeWakelock(); + } else if (keyguardIsShowingTq()) { if (mLidOpen) { - // only do this if it's opening -- closing the device shouldn't turn it - // off, but it also shouldn't turn it on. - mKeyguardMediator.pokeWakelock(); + // If we are opening the lid and not hiding the + // keyguard, then we need to have it turn on the + // screen once it is shown. + mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq( + KeyEvent.KEYCODE_POWER); } } else { // Light up the keyboard if we are sliding up.