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

Unverified Commit 47c42b13 authored by Adnan's avatar Adnan Committed by Michael Bestas
Browse files

Keyguard: Add option to scramble pin layout when unlocking (2/2).



Co-authored-by: default avatarLuK1337 <priv.luk@gmail.com>
Co-authored-by: default avatarOliver Scott <olivercscott@gmail.com>
Co-authored-by: default avatarTommy Webb <tommy@calyxinstitute.org>
Change-Id: I6716b1c76b69d51bd1457ce07de2274541fca1e8
parent d9561672
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ import com.android.settingslib.animation.DisappearAnimationUtils;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Displays a PIN pad for unlocking.
 */
@@ -65,6 +70,10 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
    private boolean mIsSmallLockScreenLandscapeEnabled = false;
    @DevicePostureInt private int mLastDevicePosture = DEVICE_POSTURE_UNKNOWN;
    public static final long ANIMATION_DURATION = 650;
    private boolean mScramblePin;

    private List<Integer> mNumbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
    private final List<Integer> mDefaultNumbers = List.of(mNumbers.toArray(new Integer[0]));

    public KeyguardPINView(Context context) {
        this(context, null);
@@ -269,6 +278,36 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
                }};
    }

    protected void updatePinScrambling(boolean scramblePin) {
        if (scramblePin || scramblePin != mScramblePin) {
            mScramblePin = scramblePin;
            if (scramblePin) {
                Collections.shuffle(mNumbers);
            } else {
                mNumbers = new ArrayList<>(mDefaultNumbers);
            }
            // get all children who are NumPadKeys
            List<NumPadKey> views = new ArrayList<>();

            // mView contains all Views that make up the PIN pad; row0 = the entry test field, then
            // rows 1-4 contain the buttons. Iterate over all views that make up the buttons in the
            // pad
            for (int row = 1; row < 5; row++) {
                for (int column = 0; column < 3; column++) {
                    View key = mViews[row][column];
                    if (key instanceof NumPadKey) {
                        views.add((NumPadKey) key);
                    }
                }
            }
            // reset the digits in the views
            for (int i = 0; i < mNumbers.size(); i++) {
                NumPadKey view = views.get(i);
                view.setDigit(mNumbers.get(i));
            }
        }
    }

    @Override
    public int getWrongPasswordStringId() {
        return R.string.kg_wrong_pin;
@@ -308,6 +347,14 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
        return true;
    }

    @Override
    protected int getNumberIndex(int number) {
        if (mScramblePin) {
            return (mNumbers.indexOf(number) + 1) % mNumbers.size();
        }
        return super.getNumberIndex(number);
    }

    @Override
    public boolean hasOverlappingRendering() {
        return false;
+5 −1
Original line number Diff line number Diff line
@@ -149,9 +149,13 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
        }
    }

    protected int getNumberIndex(int number) {
        return number;
    }

    private void performNumberClick(int number) {
        if (number >= 0 && number <= 9) {
            mButtons[number].performClick();
            mButtons[getNumberIndex(number)].performClick();
        }
    }

+10 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.user.domain.interactor.SelectedUserInteractor;

import lineageos.providers.LineageSettings;

public class KeyguardPinViewController
        extends KeyguardPinBasedInputViewController<KeyguardPINView> {
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
@@ -97,6 +99,10 @@ public class KeyguardPinViewController
        mPostureController.addCallback(mPostureCallback);
        mPasswordEntry.setUsePinShapes(true);
        updateAutoConfirmationState();
        mView.updatePinScrambling(
                LineageSettings.System.getIntForUser(getContext().getContentResolver(),
                        LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0,
                        mSelectedUserInteractor.getSelectedUserId()) == 1);
    }

    protected void onUserInput() {
@@ -120,6 +126,10 @@ public class KeyguardPinViewController
    @Override
    public void startAppearAnimation() {
        super.startAppearAnimation();
        mView.updatePinScrambling(
                LineageSettings.System.getIntForUser(getContext().getContentResolver(),
                        LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0,
                        mSelectedUserInteractor.getSelectedUserId()) == 1);
    }

    @Override
+24 −15
Original line number Diff line number Diff line
@@ -121,7 +121,31 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
        mDigitText.setText(Integer.toString(mDigit));
        mKlondikeText = (TextView) findViewById(R.id.klondike_text);

        updateText();

        Drawable background = getBackground();
        if (background instanceof GradientDrawable) {
            mAnimator = new NumPadAnimator(context, background.mutate(),
                    R.style.NumPadKey, mDigitText, null);
        } else {
            mAnimator = null;
        }

        if (bouncerUiRevamp2()) {
            mDigitText.setTypeface(
                    Typeface.create(FontStyles.GSF_LABEL_SMALL_EMPHASIZED, Typeface.NORMAL));
        }
    }

    public void setDigit(int digit) {
        mDigit = digit;
        updateText();
    }

    private void updateText() {
        if (mDigit >= 0) {
            mDigitText.setText(Integer.toString(mDigit));
            setContentDescription(mDigitText.getText().toString());
            if (sKlondike == null) {
                sKlondike = getResources().getStringArray(R.array.lockscreen_num_pad_klondike);
            }
@@ -135,21 +159,6 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
                }
            }
        }

        setContentDescription(mDigitText.getText().toString());

        Drawable background = getBackground();
        if (background instanceof GradientDrawable) {
            mAnimator = new NumPadAnimator(context, background.mutate(),
                    R.style.NumPadKey, mDigitText, null);
        } else {
            mAnimator = null;
        }

        if (bouncerUiRevamp2()) {
            mDigitText.setTypeface(
                    Typeface.create(FontStyles.GSF_LABEL_SMALL_EMPHASIZED, Typeface.NORMAL));
        }
    }

    @Override