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

Commit f9f2220e authored by Danny Baumann's avatar Danny Baumann Committed by Gerrit Code Review
Browse files

Merge "Keyguard: remove duplicated code" into cm-10.1

parents 320186b5 f17e84fa
Loading
Loading
Loading
Loading
+1 −27
Original line number Diff line number Diff line
@@ -106,10 +106,6 @@ public class KeyguardHostView extends KeyguardViewBase {

    private boolean mSafeModeEnabled;


     // We can use the profile manager to override security
     private ProfileManager mProfileManager;

     /*package*/ interface TransportCallback {
        void onListenerDetached();
        void onListenerAttached();
@@ -142,8 +138,6 @@ public class KeyguardHostView extends KeyguardViewBase {

        mViewStateManager = new KeyguardViewStateManager(this);

        mProfileManager = (ProfileManager) context.getSystemService(Context.PROFILE_SERVICE);

        DevicePolicyManager dpm =
            (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
        if (dpm != null) {
@@ -883,31 +877,11 @@ public class KeyguardHostView extends KeyguardViewBase {
        showPrimarySecurityScreen(false);
    }

    private boolean isSecure() {
        SecurityMode mode = mSecurityModel.getSecurityMode();
        switch (mode) {
            case Pattern:
                return mLockPatternUtils.isLockPatternEnabled()
                        && mProfileManager.getActiveProfile().getScreenLockMode()!= Profile.LockMode.INSECURE;
            case Password:
            case PIN:
                return mLockPatternUtils.isLockPasswordEnabled()
                        && mProfileManager.getActiveProfile().getScreenLockMode() != Profile.LockMode.INSECURE;
            case SimPin:
            case SimPuk:
            case Account:
                return true;
            case None:
                return false;
            default:
                throw new IllegalStateException("Unknown security mode " + mode);
        }
    }

    @Override
    public void wakeWhenReadyTq(int keyCode) {
        if (DEBUG) Log.d(TAG, "onWakeKey");
        if (keyCode == KeyEvent.KEYCODE_MENU && isSecure()) {
        if (keyCode == KeyEvent.KEYCODE_MENU && mSecurityModel.getSecurityMode() != SecurityMode.None) {
            if (DEBUG) Log.d(TAG, "switching screens to unlock screen because wake key was MENU");
            showSecurityScreen(SecurityMode.None);
        } else {
+5 −17
Original line number Diff line number Diff line
@@ -88,45 +88,33 @@ public class KeyguardSecurityModel {
        } else if (simState == IccCardConstants.State.PUK_REQUIRED
                && mLockPatternUtils.isPukUnlockScreenEnable()) {
            mode = SecurityMode.SimPuk;
        } else {
        } else if (mProfileManager.getActiveProfile().getScreenLockMode() != Profile.LockMode.INSECURE) {
            final int security = mLockPatternUtils.getKeyguardStoredPasswordQuality();
            switch (security) {
                case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
                    if (mLockPatternUtils.isLockPasswordEnabled()
                            && mProfileManager.getActiveProfile().getScreenLockMode()
                               != Profile.LockMode.INSECURE) {
                    if (mLockPatternUtils.isLockPasswordEnabled()) {
                        mode = SecurityMode.PIN;
                    } else {
                        mode = SecurityMode.None;
                    }
                    break;

                case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
                case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
                case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
                    if (mLockPatternUtils.isLockPasswordEnabled()
                            && mProfileManager.getActiveProfile().getScreenLockMode()
                               != Profile.LockMode.INSECURE) {
                    if (mLockPatternUtils.isLockPasswordEnabled()) {
                        mode = SecurityMode.Password;
                    } else {
                        mode = SecurityMode.None;
                    }
                    break;

                case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
                case DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED:
                    if (mLockPatternUtils.isLockPatternEnabled()
                            && mProfileManager.getActiveProfile().getScreenLockMode()
                               != Profile.LockMode.INSECURE) {
                    if (mLockPatternUtils.isLockPatternEnabled()) {
                        mode = mLockPatternUtils.isPermanentlyLocked() ?
                            SecurityMode.Account : SecurityMode.Pattern;
                    } else {
                        mode = SecurityMode.None;
                    }
                    break;

                default:
                    throw new IllegalStateException("Unknown unlock mode:" + mode);
                    throw new IllegalStateException("Unknown unlock mode:" + security);
            }
        }
        return mode;