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

Unverified Commit 78e834d5 authored by Adnan's avatar Adnan Committed by Michael Bestas
Browse files

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

Adapted to Lineage SDK and squashed with the following changes:

  From: Adnan Begovic <adnan@cyngn.com>
  Date: Wed, 05 Aug 2015 10:40:41 -0700

      Keyguard: Don't disable visibility when scrambling pin.

        Otherwise the first numbers text is flipped to invisible
        even though it shouldn't be.

      Change-Id: Ia2b80d594e7f11af7a60a85bdb4ea9909d0ac20b

  From: Adnan Begovic <adnan@cyngn.com>
  Date: Wed, 05 Aug 2015 16:21:27 -0700

      Keyguard: Fix scramblepin logic.

      Change-Id: I71e6d26e853fa7bfaeea4b3256902881ac7f74fc

  From: LuK1337 <priv.luk@gmail.com>
  Date: Sat Apr 24 18:14:46 2021 +0200

      Keyguard: Fix mapping mismatch between KeyEvent and NumPadKey

      Change-Id: Ida28a4f037c2f3fa843ac136779e026020d711db

  From: Tommy Webb <tommy@calyxinstitute.org>
  Date: 2023-03-20 14:15:05 -0400

      Fix issue introduced with 13 QPR2 in which the PIN layout is not
      randomized every time the PIN entry view appears.

      Issue: calyxos#1557
      Change-Id: I44247941a02c95cc2ec53fc42ddb1337b61f692e

Original-Change-Id: Ibe8611eb0b8a5bd9275bc96682d2cbafaa37d8f5
Change-Id: I6716b1c76b69d51bd1457ce07de2274541fca1e8
parent 6b0f629c
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -38,6 +38,13 @@ import com.android.settingslib.animation.DisappearAnimationUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt;

import lineageos.providers.LineageSettings;

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

/**
 * Displays a PIN pad for unlocking.
 */
@@ -54,6 +61,10 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
    private View mBouncerMessageArea;
    @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);
@@ -171,6 +182,39 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
                new View[]{
                        null, mEcaView, null
                }};
        updatePinScrambling();
    }

    private void updatePinScrambling() {
        final boolean scramblePin = LineageSettings.System.getInt(getContext().getContentResolver(),
                LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1;
        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
@@ -180,6 +224,7 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {

    @Override
    public void startAppearAnimation() {
        updatePinScrambling();
        setAlpha(1f);
        setTranslationY(0);
        if (mAppearAnimator.isRunning()) {
@@ -212,6 +257,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
@@ -135,9 +135,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();
        }
    }

+24 −11
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import androidx.annotation.Nullable;
import com.android.settingslib.Utils;
import com.android.systemui.R;

import lineageos.providers.LineageSettings;

/**
 * Viewgroup for the bouncer numpad button, specifically for digits.
 */
@@ -117,30 +119,41 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
        mDigitText.setText(Integer.toString(mDigit));
        mKlondikeText = (TextView) findViewById(R.id.klondike_text);

        updateText();
        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;
        }
    }

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

    private void updateText() {
        boolean scramblePin = (LineageSettings.System.getInt(getContext().getContentResolver(),
                LineageSettings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1);
        if (mDigit >= 0) {
            mDigitText.setText(Integer.toString(mDigit));
            if (sKlondike == null) {
                sKlondike = getResources().getStringArray(R.array.lockscreen_num_pad_klondike);
            }
            if (sKlondike != null && sKlondike.length > mDigit) {
                String klondike = sKlondike[mDigit];
                final int len = klondike.length();
                if (len > 0) {
                if (len > 0 || scramblePin) {
                    mKlondikeText.setText(klondike);
                } else if (mKlondikeText.getVisibility() != View.GONE) {
                    mKlondikeText.setVisibility(View.INVISIBLE);
                }
            }
        }

        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;
        }
    }

    @Override