From 4a3daac72b327e3f400581541f4044311ce103dc Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Tue, 9 Dec 2014 14:32:02 -0500 Subject: [PATCH] Handle policy change while keyguard disabled Previously the policy change would always re-enable the keyguard, but that would break the current state. Instead, when the keyguard is disabled, we need to recalculate the allow state immediately and only re-enable it if necessary. Bug: 18430385 Change-Id: Id9e701df2db765031e177c8bc8d3730cfb7f162a --- .../server/wm/KeyguardDisableHandler.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/wm/KeyguardDisableHandler.java b/services/core/java/com/android/server/wm/KeyguardDisableHandler.java index c1420a86c3dc7..37d811f3f2e31 100644 --- a/services/core/java/com/android/server/wm/KeyguardDisableHandler.java +++ b/services/core/java/com/android/server/wm/KeyguardDisableHandler.java @@ -68,9 +68,18 @@ public class KeyguardDisableHandler extends Handler { break; case KEYGUARD_POLICY_CHANGED: - mPolicy.enableKeyguard(true); - // lazily evaluate this next time we're asked to disable keyguard mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN; + if (mKeyguardTokenWatcher.isAcquired()) { + // If we are currently disabled we need to know if the keyguard + // should be re-enabled, so determine the allow state immediately. + mKeyguardTokenWatcher.updateAllowState(); + if (mAllowDisableKeyguard != ALLOW_DISABLE_YES) { + mPolicy.enableKeyguard(true); + } + } else { + // lazily evaluate this next time we're asked to disable keyguard + mPolicy.enableKeyguard(true); + } break; } } @@ -81,24 +90,28 @@ public class KeyguardDisableHandler extends Handler { super(handler, TAG); } - @Override - public void acquired() { + public void updateAllowState() { // We fail safe and prevent disabling keyguard in the unlikely event this gets // called before DevicePolicyManagerService has started. - if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { - DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( - Context.DEVICE_POLICY_SERVICE); - if (dpm != null) { - try { - mAllowDisableKeyguard = dpm.getPasswordQuality(null, - ActivityManagerNative.getDefault().getCurrentUser().id) - == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? - ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; - } catch (RemoteException re) { - // Nothing much we can do - } + DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService( + Context.DEVICE_POLICY_SERVICE); + if (dpm != null) { + try { + mAllowDisableKeyguard = dpm.getPasswordQuality(null, + ActivityManagerNative.getDefault().getCurrentUser().id) + == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED ? + ALLOW_DISABLE_YES : ALLOW_DISABLE_NO; + } catch (RemoteException re) { + // Nothing much we can do } } + } + + @Override + public void acquired() { + if (mAllowDisableKeyguard == ALLOW_DISABLE_UNKNOWN) { + updateAllowState(); + } if (mAllowDisableKeyguard == ALLOW_DISABLE_YES) { mPolicy.enableKeyguard(false); } else {