Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
add option to scramble PIN
Browse files Browse the repository at this point in the history
Adapted from work by Adnan <[email protected]> for CyanogenMod.

Change-Id: I416895210128cc0fc174201c29dc1e4dc9d14eb6
  • Loading branch information
thestinger committed Feb 3, 2020
1 parent d29d559 commit dea4697
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
7 changes: 7 additions & 0 deletions core/java/android/provider/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,13 @@ public boolean validate(String value) {
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 SCRAMBLE_PIN_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.
Expand Down
29 changes: 29 additions & 0 deletions packages/SystemUI/src/com/android/keyguard/KeyguardPINView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
package com.android.keyguard;

import android.content.Context;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;

import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils;
Expand Down Expand Up @@ -119,6 +126,28 @@ protected void onFinishInflate() {
mCallback.onCancelClicked();
});
}
boolean scramblePin = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.SCRAMBLE_PIN_LAYOUT, 0) == 1;

if (scramblePin) {
List<Integer> digits = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
Collections.shuffle(digits, new SecureRandom());
LinearLayout container = (LinearLayout) findViewById(R.id.container);
int finished = 0;
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) {
NumPadKey key = (NumPadKey) view;
key.setDigit(digits.get(finished));
finished++;
}
}
}
}
}
}

@Override
Expand Down
26 changes: 19 additions & 7 deletions packages/SystemUI/src/com/android/keyguard/NumPadKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.res.TypedArray;
import android.os.PowerManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.HapticFeedbackConstants;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -102,27 +103,38 @@ protected NumPadKey(Context context, AttributeSet attrs, int defStyle, int conte
mDigitText.setText(Integer.toString(mDigit));
mKlondikeText = (TextView) findViewById(R.id.klondike_text);

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

private void updateText() {
boolean scramblePin = Settings.System.getInt(getContext().getContentResolver(),
Settings.System.SCRAMBLE_PIN_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 {
mKlondikeText.setVisibility(View.INVISIBLE);
}
}
}
}

a = context.obtainStyledAttributes(attrs, android.R.styleable.View);
if (!a.hasValueOrEmpty(android.R.styleable.View_background)) {
setBackground(mContext.getDrawable(R.drawable.ripple_drawable_pin));
}
a.recycle();
setContentDescription(mDigitText.getText().toString());
public void setDigit(int digit) {
mDigit = digit;
updateText();
}

@Override
Expand Down

0 comments on commit dea4697

Please sign in to comment.