Add setting to disable PIN animation and password

Test: Unit - atest SettingsRoboTests
Test: Manual - Set PIN lock and enabled/disabled the setting to observe animation change during PIN entry
Bug: b/204799468
Change-Id: I587b993ef5515a075442e82ebafae88bebdffc20
This commit is contained in:
Andreas Miko
2023-02-08 17:26:18 +00:00
parent b40869c8e2
commit d7373ac86a
6 changed files with 60 additions and 15 deletions

View File

@@ -170,6 +170,8 @@ public class LockPatternUtils {
private static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
Settings.Secure.LOCK_SCREEN_OWNER_INFO_ENABLED;
private static final String LOCK_PIN_ENHANCED_PRIVACY = "pin_enhanced_privacy";
private static final String LOCK_SCREEN_DEVICE_OWNER_INFO = "lockscreen.device_owner_info";
private static final String ENABLED_TRUST_AGENTS = "lockscreen.enabledtrustagents";
@@ -1036,6 +1038,27 @@ public class LockPatternUtils {
return getString(Settings.Secure.LOCK_PATTERN_VISIBLE, userId) != null;
}
/**
* @return Whether enhanced pin privacy is enabled.
*/
public boolean isPinEnhancedPrivacyEnabled(int userId) {
return getBoolean(LOCK_PIN_ENHANCED_PRIVACY, false, userId);
}
/**
* Set whether enhanced pin privacy is enabled.
*/
public void setPinEnhancedPrivacyEnabled(boolean enabled, int userId) {
setBoolean(LOCK_PIN_ENHANCED_PRIVACY, enabled, userId);
}
/**
* @return Whether enhanced pin privacy was ever chosen.
*/
public boolean isPinEnhancedPrivacyEverChosen(int userId) {
return getString(LOCK_PIN_ENHANCED_PRIVACY, userId) != null;
}
/**
* Set and store the lockout deadline, meaning the user can't attempt their unlock
* pattern until the deadline has passed.

View File

@@ -182,6 +182,8 @@ public class SettingsBackupAgent extends BackupAgentHelper {
"visible_pattern_enabled";
private static final String KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS =
"power_button_instantly_locks";
private static final String KEY_LOCK_SETTINGS_PIN_ENHANCED_PRIVACY =
"pin_enhanced_privacy";
// Name of the temporary file we use during full backup/restore. This is
// stored in the full-backup tarfile as well, so should not be changed.
@@ -709,6 +711,10 @@ public class SettingsBackupAgent extends BackupAgentHelper {
out.writeUTF(KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS);
out.writeUTF(powerButtonInstantlyLocks ? "1" : "0");
}
if (lockPatternUtils.isPinEnhancedPrivacyEverChosen(userId)) {
out.writeUTF(KEY_LOCK_SETTINGS_PIN_ENHANCED_PRIVACY);
out.writeUTF(lockPatternUtils.isPinEnhancedPrivacyEnabled(userId) ? "1" : "0");
}
// End marker
out.writeUTF("");
out.flush();
@@ -961,6 +967,9 @@ public class SettingsBackupAgent extends BackupAgentHelper {
case KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS:
lockPatternUtils.setPowerButtonInstantlyLocks("1".equals(value), userId);
break;
case KEY_LOCK_SETTINGS_PIN_ENHANCED_PRIVACY:
lockPatternUtils.setPinEnhancedPrivacyEnabled("1".equals(value), userId);
break;
}
}
in.close();

View File

@@ -44,7 +44,7 @@ import java.util.Map;
public abstract class KeyguardAbsKeyInputViewController<T extends KeyguardAbsKeyInputView>
extends KeyguardInputViewController<T> {
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private final LockPatternUtils mLockPatternUtils;
protected final LockPatternUtils mLockPatternUtils;
private final LatencyTracker mLatencyTracker;
private final FalsingCollector mFalsingCollector;
private final EmergencyButtonController mEmergencyButtonController;

View File

@@ -71,13 +71,17 @@ public abstract class KeyguardPinBasedInputViewController<T extends KeyguardPinB
protected void onViewAttached() {
super.onViewAttached();
for (NumPadKey button: mView.getButtons()) {
boolean showAnimations = !mLockPatternUtils
.isPinEnhancedPrivacyEnabled(KeyguardUpdateMonitor.getCurrentUser());
mPasswordEntry.setShowPassword(showAnimations);
for (NumPadKey button : mView.getButtons()) {
button.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
mFalsingCollector.avoidGesture();
}
return false;
});
button.setAnimationEnabled(showAnimations);
}
mPasswordEntry.setOnKeyListener(mOnKeyListener);
mPasswordEntry.setUserActivityListener(this::onUserInput);
@@ -102,12 +106,9 @@ public abstract class KeyguardPinBasedInputViewController<T extends KeyguardPinB
View okButton = mView.findViewById(R.id.key_enter);
if (okButton != null) {
okButton.setOnTouchListener(mActionButtonTouchListener);
okButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mPasswordEntry.isEnabled()) {
verifyPasswordAndUnlock();
}
okButton.setOnClickListener(v -> {
if (mPasswordEntry.isEnabled()) {
verifyPasswordAndUnlock();
}
});
okButton.setOnHoverListener(mLiftToActivateListener);
@@ -118,7 +119,7 @@ public abstract class KeyguardPinBasedInputViewController<T extends KeyguardPinB
protected void onViewDetached() {
super.onViewDetached();
for (NumPadKey button: mView.getButtons()) {
for (NumPadKey button : mView.getButtons()) {
button.setOnTouchListener(null);
}
}

View File

@@ -50,6 +50,7 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
private int mDigit = -1;
private int mTextViewResId;
private PasswordTextView mTextView;
private boolean mAnimationsEnabled = true;
@Nullable
private NumPadAnimator mAnimator;
@@ -164,11 +165,11 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
switch(event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
doHapticKeyClick();
if (mAnimator != null) mAnimator.expand();
if (mAnimator != null && mAnimationsEnabled) mAnimator.expand();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mAnimator != null) mAnimator.contract();
if (mAnimator != null && mAnimationsEnabled) mAnimator.contract();
break;
}
return super.onTouchEvent(event);
@@ -228,4 +229,11 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
mAnimator.setProgress(progress);
}
}
/**
* Controls the animation when a key is pressed
*/
public void setAnimationEnabled(boolean enabled) {
mAnimationsEnabled = enabled;
}
}

View File

@@ -30,7 +30,6 @@ import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.PowerManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.InputType;
import android.text.TextUtils;
import android.util.AttributeSet;
@@ -100,7 +99,7 @@ public class PasswordTextView extends FrameLayout {
private Interpolator mAppearInterpolator;
private Interpolator mDisappearInterpolator;
private Interpolator mFastOutSlowInInterpolator;
private boolean mShowPassword;
private boolean mShowPassword = true;
private UserActivityListener mUserActivityListener;
private PinShapeInput mPinShapeInput;
private boolean mUsePinShapes = false;
@@ -158,8 +157,6 @@ public class PasswordTextView extends FrameLayout {
mDrawPaint.setTypeface(Typeface.create(
context.getString(com.android.internal.R.string.config_headlineFontFamily),
0));
mShowPassword = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;
mAppearInterpolator = AnimationUtils.loadInterpolator(mContext,
android.R.interpolator.linear_out_slow_in);
mDisappearInterpolator = AnimationUtils.loadInterpolator(mContext,
@@ -441,6 +438,13 @@ public class PasswordTextView extends FrameLayout {
addView(mPinShapeInput.getView());
}
/**
* Controls whether the last entered digit is briefly shown after being entered
*/
public void setShowPassword(boolean enabled) {
mShowPassword = enabled;
}
private class CharState {
char whichChar;
ValueAnimator textAnimator;