Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0463ae0 authored by Danny Baumann's avatar Danny Baumann
Browse files

When DPM is updated while lock screen is inhibited, don't

unconditionally enable lock screen.

Change-Id: Iab2af06eb8e41fbcfc6adfbeb5b42a9bbf446fe9
parent ba7f179c
Loading
Loading
Loading
Loading
+26 −15
Original line number Diff line number Diff line
@@ -69,13 +69,35 @@ public class KeyguardDisableHandler extends Handler {
                break;

            case KEYGUARD_POLICY_CHANGED:
                mPolicy.enableKeyguard(true);
                if (mKeyguardTokenWatcher.isAcquired()) {
                    updateAllowDisableState();
                } else {
                    // lazily evaluate this next time we're asked to disable keyguard
                    mAllowDisableKeyguard = ALLOW_DISABLE_UNKNOWN;
                }
                if (mAllowDisableKeyguard != ALLOW_DISABLE_YES) {
                    mPolicy.enableKeyguard(true);
                }
                break;
        }
    }

    private void updateAllowDisableState() {
        DevicePolicyManager dpm = (DevicePolicyManager) mContext.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
        if (dpm != null) {
            try {
                int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
                int quality = dpm.getPasswordQuality(null,  userId);

                mAllowDisableKeyguard = quality == DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED
                        ? ALLOW_DISABLE_YES : ALLOW_DISABLE_NO;
            } catch (RemoteException re) {
                // Nothing much we can do
            }
        }
    }

    class KeyguardTokenWatcher extends TokenWatcher {

        public KeyguardTokenWatcher(final Handler handler) {
@@ -87,18 +109,7 @@ public class KeyguardDisableHandler extends Handler {
            // 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
                    }
                }
                updateAllowDisableState();
            }
            if (mAllowDisableKeyguard == ALLOW_DISABLE_YES) {
                mPolicy.enableKeyguard(false);