diff options
author | Mike Lockwood <lockwood@android.com> | 2010-01-28 11:54:40 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-01-29 07:15:43 -0500 |
commit | faeb50a924e219df689c16c57bb1b5ff1a095d62 (patch) | |
tree | 5da92f4786b58af392feae82228fbe1ddcc5d99a | |
parent | 023f440a239fb89d9c6fc97cb50f9e45872f28be (diff) | |
download | base-faeb50a924e219df689c16c57bb1b5ff1a095d62.tar.gz |
Add implementation for ALLOW_LOCK_WHILE_SCREEN_ON flag to PhoneWindowManager
This allows the lockscreen to activate after the normal screen timeout while the
screen is on. Needed for dock apps, screen savers, etc.
Change-Id: I25c3579e4363c2b19d503fdbd45d2ff41cdd11bb
Signed-off-by: Mike Lockwood <lockwood@android.com>
3 files changed, 75 insertions, 2 deletions
diff --git a/mid/com/android/internal/policy/impl/MidWindowManager.java b/mid/com/android/internal/policy/impl/MidWindowManager.java index 3b8ce93..445abb2 100644 --- a/mid/com/android/internal/policy/impl/MidWindowManager.java +++ b/mid/com/android/internal/policy/impl/MidWindowManager.java @@ -1017,7 +1017,11 @@ public class MidWindowManager implements WindowManagerPolicy { } catch (RemoteException e) { } } - + + /** {@inheritDoc} */ + public void userActivity() { + } + /** {@inheritDoc} */ public void enableScreenAfterBoot() { updateRotation(); diff --git a/phone/com/android/internal/policy/impl/KeyguardViewMediator.java b/phone/com/android/internal/policy/impl/KeyguardViewMediator.java index c3c36b4..85afa81 100644 --- a/phone/com/android/internal/policy/impl/KeyguardViewMediator.java +++ b/phone/com/android/internal/policy/impl/KeyguardViewMediator.java @@ -107,6 +107,7 @@ public class KeyguardViewMediator implements KeyguardViewCallback, private static final int KEYGUARD_DONE_DRAWING = 10; private static final int KEYGUARD_DONE_AUTHENTICATING = 11; private static final int SET_HIDDEN = 12; + private static final int KEYGUARD_TIMEOUT = 13; /** * The default amount of time we stay awake (used for all key input) @@ -456,6 +457,16 @@ public class KeyguardViewMediator implements KeyguardViewCallback, } /** + * Used by PhoneWindowManager to enable the keyguard due to a user activity timeout. + * This must be safe to call from any thread and with any window manager locks held. + */ + public void doKeyguardTimeout() { + mHandler.removeMessages(KEYGUARD_TIMEOUT); + Message msg = mHandler.obtainMessage(KEYGUARD_TIMEOUT); + mHandler.sendMessage(msg); + } + + /** * Given the state of the keyguard, is the input restricted? * Input is restricted when the keyguard is showing, or when the keyguard * was suppressed by an app that disabled the keyguard or we haven't been provisioned yet. @@ -839,6 +850,9 @@ public class KeyguardViewMediator implements KeyguardViewCallback, case SET_HIDDEN: handleSetHidden(msg.arg1 != 0); break; + case KEYGUARD_TIMEOUT: + doKeyguard(); + break; } } }; diff --git a/phone/com/android/internal/policy/impl/PhoneWindowManager.java b/phone/com/android/internal/policy/impl/PhoneWindowManager.java index f071771..e9acc23 100755 --- a/phone/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/phone/com/android/internal/policy/impl/PhoneWindowManager.java @@ -70,6 +70,7 @@ import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; +import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; @@ -246,6 +247,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mSearchKeyPressed; boolean mConsumeSearchKeyUp; + // support for activating the lock screen while the screen is on + boolean mAllowLockscreenWhenOn; + int mLockScreenTimeout; + boolean mLockScreenTimerActive; + static final int ENDCALL_HOME = 0x1; static final int ENDCALL_SLEEPS = 0x2; static final int DEFAULT_ENDCALL_BEHAVIOR = ENDCALL_SLEEPS; @@ -272,6 +278,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { Settings.System.END_BUTTON_BEHAVIOR), false, this); resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.ACCELEROMETER_ROTATION), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.SCREEN_OFF_TIMEOUT), false, this); resolver.registerContentObserver(Settings.Secure.getUriFor( Settings.Secure.DEFAULT_INPUT_METHOD), false, this); resolver.registerContentObserver(Settings.System.getUriFor( @@ -303,6 +311,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { mAccelerometerDefault = accelerometerDefault; updateOrientationListenerLp(); } + // use screen off timeout setting as the timeout for the lockscreen + mLockScreenTimeout = Settings.System.getInt(resolver, + Settings.System.SCREEN_OFF_TIMEOUT, 0); String imId = Settings.Secure.getString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD); boolean hasSoftInput = imId != null && imId.length() > 0; @@ -1173,6 +1184,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { mTopFullscreenOpaqueWindowState = null; mForceStatusBar = false; mHideLockScreen = false; + mAllowLockscreenWhenOn = false; mDismissKeyguard = false; // decide where the status bar goes ahead of time @@ -1390,6 +1402,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win); mDismissKeyguard = true; } + if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { + mAllowLockscreenWhenOn = true; + } } // Dock windows carve out the bottom of the screen, so normal windows @@ -1483,7 +1498,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } - + + // update since mAllowLockscreenWhenOn might have changed + updateLockScreenTimeout(); return changes; } @@ -1946,6 +1963,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { synchronized (mLock) { mScreenOn = false; updateOrientationListenerLp(); + updateLockScreenTimeout(); } } @@ -1956,6 +1974,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { synchronized (mLock) { mScreenOn = true; updateOrientationListenerLp(); + updateLockScreenTimeout(); } } @@ -2090,6 +2109,42 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } + /** {@inheritDoc} */ + public void userActivity() { + synchronized (mScreenLockTimeout) { + if (mLockScreenTimerActive) { + // reset the timer + mHandler.removeCallbacks(mScreenLockTimeout); + mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); + } + } + } + + Runnable mScreenLockTimeout = new Runnable() { + public void run() { + synchronized (this) { + if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); + mKeyguardMediator.doKeyguardTimeout(); + mLockScreenTimerActive = false; + } + } + }; + + private void updateLockScreenTimeout() { + synchronized (mScreenLockTimeout) { + boolean enable = (mAllowLockscreenWhenOn && mScreenOn && mKeyguardMediator.isSecure()); + if (mLockScreenTimerActive != enable) { + if (enable) { + if (localLOGV) Log.v(TAG, "setting lockscreen timer"); + mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); + } else { + if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); + mHandler.removeCallbacks(mScreenLockTimeout); + } + mLockScreenTimerActive = enable; + } + } + } /** {@inheritDoc} */ public void enableScreenAfterBoot() { |