zoukankan      html  css  js  c++  java
  • 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();
         }
  • 相关阅读:
    2014-11-27-0047-Java
    js去除数组中重复值
    一个数据表更新另外一个数据表(SQL)
    《js12种设计模式》
    《可编辑td》
    《JS 隔行换色》
    用Autohotkey让Kitty命令行变得更好用
    View epub and mobi File on Linux
    DrJava试用笔记
    Notes about BSD
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/13360146.html
Copyright © 2011-2022 走看看