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

Commit f8898a86 authored by Adnan's avatar Adnan Committed by Steve Kondik
Browse files

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

Change-Id: Ibe8611eb0b8a5bd9275bc96682d2cbafaa37d8f5

Add global scramble pin layout setting.

Change-Id: I87e6baf041644cdde55fef34f4032c6950ac428f

Keyguard: Fix bad merge from 12.0 on pin scramble.

Change-Id: Ia9ee6bd43c45228ec7042ef8300ff9ca6f92f60f
parent c080ee6a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2638,6 +2638,13 @@ public final class Settings {
        public static final String LOCK_PATTERN_TACTILE_FEEDBACK_ENABLED =
            "lock_pattern_tactile_feedback_enabled";

        /**
         * Whether to scramble a pin unlock layout
         * @hide
         */
        public static final String LOCKSCREEN_PIN_SCRAMBLE_LAYOUT =
                "lockscreen_scramble_pin_layout";

        /**
         * A formatted string of the next alarm that is set, or the empty string
         * if there is no alarm set.
+36 −0
Original line number Diff line number Diff line
@@ -19,12 +19,19 @@ package com.android.keyguard;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.RenderNode;
import android.view.RenderNodeAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

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

import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils;
@@ -45,6 +52,8 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
    private int mDisappearYTranslation;
    private View[][] mViews;

    private static List<Integer> sNumbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);

    public KeyguardPINView(Context context) {
        this(context, null);
    }
@@ -103,6 +112,33 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
                new View[]{
                        null, mEcaView, null
                }};

        boolean scramblePin = (Settings.System.getInt(getContext().getContentResolver(),
                Settings.System.LOCKSCREEN_PIN_SCRAMBLE_LAYOUT, 0) == 1);

        if (scramblePin) {
            Collections.shuffle(sNumbers);
            // get all children who are NumPadKey's
            LinearLayout container = (LinearLayout) findViewById(R.id.container);
            List<NumPadKey> views = new ArrayList<NumPadKey>();
            for (int i = 0; i < container.getChildCount(); i++) {
                if (container.getChildAt(i) instanceof LinearLayout) {
                    LinearLayout nestedLayout = ((LinearLayout) container.getChildAt(i));
                    for (int j = 0; j < nestedLayout.getChildCount(); j++){
                        View view = nestedLayout.getChildAt(j);
                        if (view.getClass() == NumPadKey.class) {
                            views.add((NumPadKey) view);
                        }
                    }
                }
            }

            // reset the digits in the views
            for (int i = 0; i < sNumbers.size(); i++) {
                NumPadKey view = views.get(i);
                view.setDigit(sNumbers.get(i));
            }
        }
    }

    @Override
+20 −16
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ public class NumPadKey extends ViewGroup {
    protected NumPadKey(Context context, AttributeSet attrs, int defStyle, int contentResource) {
        super(context, attrs, defStyle);
        setFocusable(true);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumPadKey);

        try {
@@ -92,7 +91,6 @@ public class NumPadKey extends ViewGroup {
        setAccessibilityDelegate(new ObscureSpeechDelegate(context));

        mEnableHaptics = new LockPatternUtils(context).isTactileFeedbackEnabled();

        mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
@@ -102,7 +100,27 @@ public class NumPadKey extends ViewGroup {
        mDigitText.setText(Integer.toString(mDigit));
        mKlondikeText = (TextView) findViewById(R.id.klondike_text);

        updateText();
        setBackground(mContext.getDrawable(R.drawable.ripple_drawable));
        setContentDescription(mDigitText.getText().toString());
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        // Reset the "announced headset" flag when detached.
        ObscureSpeechDelegate.sAnnouncedHeadset = false;
    }

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

    private void updateText() {
        if (mDigit >= 0) {
            mDigitText.setText(Integer.toString(mDigit));
            if (sKlondike == null) {
                sKlondike = getResources().getStringArray(R.array.lockscreen_num_pad_klondike);
            }
@@ -116,22 +134,8 @@ public class NumPadKey extends ViewGroup {
                }
            }
        }

        a = context.obtainStyledAttributes(attrs, android.R.styleable.View);
        if (!a.hasValueOrEmpty(android.R.styleable.View_background)) {
            setBackground(mContext.getDrawable(R.drawable.ripple_drawable));
        }
        a.recycle();
        setContentDescription(mDigitText.getText().toString());
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        // Reset the "announced headset" flag when detached.
        ObscureSpeechDelegate.sAnnouncedHeadset = false;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {