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

Commit 00cc4708 authored by David van Tonder's avatar David van Tonder Committed by Gerrit Code Review
Browse files

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

Merge "When DPM is updated while lock screen is inhibited, don't unconditionally enable lock screen." into cm-10.1
parents e79d05a7 b0463ae0
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);