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
Merged-In: I587b993ef5515a075442e82ebafae88bebdffc20
Change-Id: I587b993ef5515a075442e82ebafae88bebdffc20
This commit is contained in:
Andreas Miko
2023-02-08 17:26:18 +00:00
parent d4793dbb2c
commit 12ca3f4622
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 = private static final String LOCK_SCREEN_OWNER_INFO_ENABLED =
Settings.Secure.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 LOCK_SCREEN_DEVICE_OWNER_INFO = "lockscreen.device_owner_info";
private static final String ENABLED_TRUST_AGENTS = "lockscreen.enabledtrustagents"; 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 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 whether the visible password is enabled for cryptkeeper screen. * Set whether the visible password is enabled for cryptkeeper screen.
*/ */

View File

@@ -182,6 +182,8 @@ public class SettingsBackupAgent extends BackupAgentHelper {
"visible_pattern_enabled"; "visible_pattern_enabled";
private static final String KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS = private static final String KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS =
"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 // 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. // 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(KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS);
out.writeUTF(powerButtonInstantlyLocks ? "1" : "0"); 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 // End marker
out.writeUTF(""); out.writeUTF("");
out.flush(); out.flush();
@@ -961,6 +967,9 @@ public class SettingsBackupAgent extends BackupAgentHelper {
case KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS: case KEY_LOCK_SETTINGS_POWER_BUTTON_INSTANTLY_LOCKS:
lockPatternUtils.setPowerButtonInstantlyLocks("1".equals(value), userId); lockPatternUtils.setPowerButtonInstantlyLocks("1".equals(value), userId);
break; break;
case KEY_LOCK_SETTINGS_PIN_ENHANCED_PRIVACY:
lockPatternUtils.setPinEnhancedPrivacyEnabled("1".equals(value), userId);
break;
} }
} }
in.close(); in.close();

View File

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

View File

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

View File

@@ -50,6 +50,7 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
private int mDigit = -1; private int mDigit = -1;
private int mTextViewResId; private int mTextViewResId;
private PasswordTextView mTextView; private PasswordTextView mTextView;
private boolean mAnimationsEnabled = true;
@Nullable @Nullable
private NumPadAnimator mAnimator; private NumPadAnimator mAnimator;
@@ -164,11 +165,11 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
switch(event.getActionMasked()) { switch(event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
doHapticKeyClick(); doHapticKeyClick();
if (mAnimator != null) mAnimator.expand(); if (mAnimator != null && mAnimationsEnabled) mAnimator.expand();
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_CANCEL:
if (mAnimator != null) mAnimator.contract(); if (mAnimator != null && mAnimationsEnabled) mAnimator.contract();
break; break;
} }
return super.onTouchEvent(event); return super.onTouchEvent(event);
@@ -228,4 +229,11 @@ public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
mAnimator.setProgress(progress); 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.graphics.Typeface;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.Settings;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@@ -100,7 +99,7 @@ public class PasswordTextView extends FrameLayout {
private Interpolator mAppearInterpolator; private Interpolator mAppearInterpolator;
private Interpolator mDisappearInterpolator; private Interpolator mDisappearInterpolator;
private Interpolator mFastOutSlowInInterpolator; private Interpolator mFastOutSlowInInterpolator;
private boolean mShowPassword; private boolean mShowPassword = true;
private UserActivityListener mUserActivityListener; private UserActivityListener mUserActivityListener;
private PinShapeInput mPinShapeInput; private PinShapeInput mPinShapeInput;
private boolean mUsePinShapes = false; private boolean mUsePinShapes = false;
@@ -158,8 +157,6 @@ public class PasswordTextView extends FrameLayout {
mDrawPaint.setTypeface(Typeface.create( mDrawPaint.setTypeface(Typeface.create(
context.getString(com.android.internal.R.string.config_headlineFontFamily), context.getString(com.android.internal.R.string.config_headlineFontFamily),
0)); 0));
mShowPassword = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) == 1;
mAppearInterpolator = AnimationUtils.loadInterpolator(mContext, mAppearInterpolator = AnimationUtils.loadInterpolator(mContext,
android.R.interpolator.linear_out_slow_in); android.R.interpolator.linear_out_slow_in);
mDisappearInterpolator = AnimationUtils.loadInterpolator(mContext, mDisappearInterpolator = AnimationUtils.loadInterpolator(mContext,
@@ -441,6 +438,13 @@ public class PasswordTextView extends FrameLayout {
addView(mPinShapeInput.getView()); 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 { private class CharState {
char whichChar; char whichChar;
ValueAnimator textAnimator; ValueAnimator textAnimator;