Android O : 系统原生锁屏密码位数限制及自动检查

摘要:
目的:修改原始锁屏密码规则。输入6位数字后,无法继续输入;输入错误的密码并给出错误提示;如果正确,将直接解锁。

目的:修改原生锁屏密码规则,输入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();
     }

免责声明:文章转载自《Android O : 系统原生锁屏密码位数限制及自动检查》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇几个Tab,滑动门,选项卡,图片切换SAP BW 例程(Routine)【开始例程、关键值或特性的例程、结束例程】下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vim修改文件锁定处理办法

vim为Linux系统下的编辑器,出现类似状态的原因是:Windows系统下我们习惯编辑文件后按下Ctrl+S来保存,然而,在Linux系统下该组合键位为锁屏键,我们可以按Ctrl+Q解锁屏 Windows Linux Ctrl+S 保存 锁屏Ctrl+Q 左对齐 解锁屏...