Android O : 系统原生锁屏密码位数限制及自动检查
目的:修改原生锁屏密码规则,输入6位数字后,不能继续输入;且输入错误密码,给出错误提示;正确则直接解锁。
修改文件:
①PasswordTextView中添加一个回调接口,用于检测到输入6位密码时进行回调通知密码确认:
frameworks/base/packages/SystemUI/src/com/android/keyguard/PasswordTextView.java
--- a/base/packages/SystemUI/src/com/android/keyguard/PasswordTextView.java +++ b/base/packages/SystemUI/src/com/android/keyguard/PasswordTextView.java @@ -39,6 +39,10 @@ import android.view.accessibility.AccessibilityNodeInfo; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; import android.widget.EditText; +//Sheldon add patch begin +import android.util.Log; +//Sheldon add patch end + import java.util.ArrayList; import java.util.Stack; @@ -95,6 +99,18 @@ public class PasswordTextView extends View { private boolean mShowPassword; private UserActivityListener mUserActivityListener; + //Sheldon add patch begin + private IVerifyPasswordCallBack mVerifyPasswordCB; + + public interface IVerifyPasswordCallBack { + void VerifyPassword(boolean isAuto); + } + + public void setOnClickVerifyCB(IVerifyPasswordCallBack cb){ + this.mVerifyPasswordCB = cb; + } + //Sheldon add patch end + public interface UserActivityListener { void onUserActivity(); } @@ -314,6 +330,15 @@ public class PasswordTextView extends View { event.setPassword(true); sendAccessibilityEventUnchecked(event); } + + //Sheldon add patch begin + int totalInputNum = fromIndex + addedCount; + if(totalInputNum >= 6) { + if (mVerifyPasswordCB != null){ + mVerifyPasswordCB.VerifyPassword(true); + } + } + //Sheldon add patch end }
②KeyguardPinBasedInputView中注册回调,并在回调实现中调用verifyPasswordAndUnlock()进行密码验证:
frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
--- a/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java +++ b/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java @@ -22,6 +22,9 @@ import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +//Sheldon add patch begin +import android.util.Log; +//Sheldon add patch end /** * A Pin based Keyguard input view @@ -233,6 +236,18 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView mButton8 = findViewById(R.id.key8); mButton9 = findViewById(R.id.key9); + //Sheldon add patch begin + mPasswordEntry.setOnClickVerifyCB(new PasswordTextView.IVerifyPasswordCallBack() { + @Override + public void VerifyPassword(boolean isAuto) { + if(isAuto) { + verifyPasswordAndUnlock(); + } + Log.d("KeyguardPinBasedInputView","verifyPasswordAndUnlock isAuto : " + isAuto); + } + }); + //Sheldon add patch end + mPasswordEntry.requestFocus(); super.onFinishInflate(); }
posted on 2020-07-22 13:25 sheldon_blogs 阅读(876) 评论(0) 编辑 收藏 举报