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

Commit 0d9f798e authored by Jim Miller's avatar Jim Miller
Browse files

Fix 2468960: Make sure unlock screen gets updated when SIM state changes.

Added code to let us lazily re-create the unlock screen when the SIM
status changes.  This fixes a bug where we sometimes show the Pattern/Password unlock
instead of the SIM PIN unlock due to an ordering issue with recent changes
to the telephony layer SIM update logic. It now correctly re-evaluates the SIM state
and updates the UI accordingly.
parent e180426c
Loading
Loading
Loading
Loading
+55 −8
Original line number Diff line number Diff line
@@ -122,7 +122,12 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        /**
         * Unlock by entering a password or PIN
         */
        Password
        Password,

        /**
         * Unknown (uninitialized) value
         */
        Unknown
    }

    /**
@@ -153,6 +158,8 @@ public class LockPatternKeyguardView extends KeyguardViewBase
    private int mNumAccounts;
    private boolean mIsPortrait;

    private UnlockMode mCurrentUnlockMode = UnlockMode.Unknown;

    /**
     * @return Whether we are stuck on the lock screen because the sim is
     *   missing.
@@ -421,7 +428,7 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        }
    }

    private void recreateScreens() {
    private void recreateLockScreen() {
        if (mLockScreen.getVisibility() == View.VISIBLE) {
            ((KeyguardScreen) mLockScreen).onPause();
        }
@@ -431,7 +438,9 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        mLockScreen = createLockScreen();
        mLockScreen.setVisibility(View.INVISIBLE);
        addView(mLockScreen);
    }

    private void recreateUnlockScreen() {
        if (mUnlockScreen.getVisibility() == View.VISIBLE) {
            ((KeyguardScreen) mUnlockScreen).onPause();
        }
@@ -443,11 +452,14 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        mUnlockScreen.setVisibility(View.INVISIBLE);
        mUnlockScreenMode = unlockMode;
        addView(mUnlockScreen);
    }

    private void recreateScreens() {
        recreateLockScreen();
        recreateUnlockScreen();
        updateScreen(mMode);
    }


    @Override
    public void wakeWhenReadyTq(int keyCode) {
        if (DEBUG) Log.d(TAG, "onWakeKey");
@@ -512,6 +524,12 @@ public class LockPatternKeyguardView extends KeyguardViewBase

        mMode = mode;

        // Re-create the unlock screen if necessary. This is primarily required to properly handle
        // SIM state changes. This typically happens when this method is called by reset()
        if (mode == Mode.UnlockScreen && mCurrentUnlockMode != getUnlockMode()) {
            recreateUnlockScreen();
        }

        final View goneScreen = (mode == Mode.LockScreen) ? mUnlockScreen : mLockScreen;
        final View visibleScreen = (mode == Mode.LockScreen) ? mLockScreen : mUnlockScreen;

@@ -551,6 +569,7 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        // Capture the orientation this layout was created in.
        mIsPortrait = getResources().getBoolean(R.bool.lockscreen_isPortrait);

        View unlockView = null;
        if (unlockMode == UnlockMode.Pattern) {
            PatternUnlockScreen view = new PatternUnlockScreen(
                    mContext,
@@ -561,16 +580,16 @@ public class LockPatternKeyguardView extends KeyguardViewBase
            if (DEBUG) Log.d(TAG,
                "createUnlockScreenFor(" + unlockMode + "): mEnableFallback=" + mEnableFallback);
            view.setEnableFallback(mEnableFallback);
            return view;
            unlockView = view;
        } else if (unlockMode == UnlockMode.SimPin) {
            return new SimUnlockScreen(
            unlockView = new SimUnlockScreen(
                    mContext,
                    mUpdateMonitor,
                    mKeyguardScreenCallback,
                    mLockPatternUtils);
        } else if (unlockMode == UnlockMode.Account) {
            try {
                return new AccountUnlockScreen(
                unlockView = new AccountUnlockScreen(
                        mContext,
                        mKeyguardScreenCallback,
                        mLockPatternUtils);
@@ -587,10 +606,10 @@ public class LockPatternKeyguardView extends KeyguardViewBase
                // regular pattern unlock UI, regardless of the value of
                // mUnlockScreenMode or whether or not we're in the
                // "permanently locked" state.)
                return createUnlockScreenFor(UnlockMode.Pattern);
                unlockView = createUnlockScreenFor(UnlockMode.Pattern);
            }
        } else if (unlockMode == UnlockMode.Password) {
            return new PasswordUnlockScreen(
            unlockView = new PasswordUnlockScreen(
                    mContext,
                    mLockPatternUtils,
                    mUpdateMonitor,
@@ -598,6 +617,34 @@ public class LockPatternKeyguardView extends KeyguardViewBase
        } else {
            throw new IllegalArgumentException("unknown unlock mode " + unlockMode);
        }
        mCurrentUnlockMode = unlockMode;
        return unlockView;
    }

    private View getUnlockScreenForCurrentUnlockMode() {
        final UnlockMode unlockMode = getUnlockMode();

        // if a screen exists for the correct mode, we're done
        if (unlockMode == mUnlockScreenMode) {
            return mUnlockScreen;
        }

        // remember the mode
        mUnlockScreenMode = unlockMode;

        // unlock mode has changed and we have an existing old unlock screen
        // to clean up
        if (mScreenOn && (mUnlockScreen.getVisibility() == View.VISIBLE)) {
            ((KeyguardScreen) mUnlockScreen).onPause();
        }
        ((KeyguardScreen) mUnlockScreen).cleanUp();
        removeViewInLayout(mUnlockScreen);

        // create the new one
        mUnlockScreen = createUnlockScreenFor(unlockMode);
        mUnlockScreen.setVisibility(View.INVISIBLE);
        addView(mUnlockScreen);
        return mUnlockScreen;
    }

    /**