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();
         }
  • 相关阅读:
    c++ primer 读书笔记
    如何利用c++编写不能被继承、但可以在类外定义对象的类
    为什么对多线程编程这么怕?pthread,sem,mutex,process
    死锁的理解
    动态规划--找零钱 coin change
    C++ STL中Map的按Key排序和按Value排序
    c++ STL sort struct comp
    《剑指offer》第二十五题(合并两个排序的链表)
    《剑指offer》第二十四题(反转链表)
    《剑指offer》第二十三题(链表中环的入口结点)
  • 原文地址:https://www.cnblogs.com/blogs-of-lxl/p/13360146.html
Copyright © 2011-2022 走看看