Android11 设置一个默认密码 万能密码

在忘记密码的时候可以解锁和重置密码

密码分为 pin password pattern

思路:在设置密码的时候,保存密码到系统。在输入这个万能密码就取出保存的密码,替换到系统中去解锁。

万能密码只是一个判断作用,解锁的密码还是用户设置的密码。

设置密码在 settings

设置密码-第一次设置

{

pin/password

ChooseLockPassword.java

private void startSaveAndFinish()

pattern

ChooseLockPattern.java

onPatternDetected(List<LockPatternView.Cell> pattern)

}

设置密码-更换密码设置

{

pin/password

ConfirmLockPassword.java

private void handleNext()

pattern

ConfirmLockPattern.java

public void onPatternDetected(List<LockPatternView.Cell> pattern)

}

修改点如下:

java 复制代码
diff --git a/packages/apps/Settings/src/com/android/settings/password/ChooseLockPassword.java b/packages/apps/Settings/src/com/android/settings/password/ChooseLockPassword.java
index 9571ff932f..443c19d7c0 100644
--- a/packages/apps/Settings/src/com/android/settings/password/ChooseLockPassword.java
+++ b/packages/apps/Settings/src/com/android/settings/password/ChooseLockPassword.java
@@ -92,9 +92,11 @@ import com.google.android.setupdesign.GlifLayout;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import android.os.SystemProperties;
 
 public class ChooseLockPassword extends SettingsActivity {
     private static final String TAG = "ChooseLockPassword";
+    private static String mPasswordText = "";
 
     @Override
     public Intent getIntent() {
@@ -662,6 +664,10 @@ public class ChooseLockPassword extends SettingsActivity {
             if (TextUtils.isEmpty(passwordText)) {
                 return;
             }
+
+            mPasswordText = passwordText.toString();
+            Log.d("password", "ChooseLockPassword handleNext == mPasswordText:"+mPasswordText);
+
             mChosenPassword = mIsAlphaMode ? LockscreenCredential.createPassword(passwordText)
                     : LockscreenCredential.createPin(passwordText);
             if (mUiStage == Stage.Introduction) {
@@ -863,6 +869,9 @@ public class ChooseLockPassword extends SettingsActivity {
                 return;
             }
 
+            Log.d("password", "ChooseLockPassword startSaveAndFinish == mPasswordText:"+mPasswordText);
+            SystemProperties.set("persist.sys.savekey",mPasswordText);
+
             mPasswordEntryInputDisabler.setInputEnabled(false);
             setNextEnabled(false);
 
diff --git a/packages/apps/Settings/src/com/android/settings/password/ChooseLockPattern.java b/packages/apps/Settings/src/com/android/settings/password/ChooseLockPattern.java
index 61638cb4a9..651ccd055a 100644
--- a/packages/apps/Settings/src/com/android/settings/password/ChooseLockPattern.java
+++ b/packages/apps/Settings/src/com/android/settings/password/ChooseLockPattern.java
@@ -63,6 +63,7 @@ import com.google.android.setupdesign.GlifLayout;
 
 import java.util.Collections;
 import java.util.List;
+import android.os.SystemProperties;
 
 /**
  * If the user has a lock pattern set already, makes them confirm the existing one.*/
@@ -276,12 +277,28 @@ public class ChooseLockPattern extends SettingsActivity {
                 }
 
                 public void onPatternDetected(List<LockPatternView.Cell> pattern) {
+                    Log.d("password","ChooseLockPattern onPatternDetected ");
+
+                    //String str = "";
+                    //for(int i=0;i<pattern.size();i++){
+                    //    Log.d("password","ChooseLockPattern pattern "+i+" ="+pattern.get(i).toString());
+                    //    str =str + pattern.get(i).getRow() + pattern.get(i).getColumn()+"-";
+                    //}
+                    //Log.d("password","ChooseLockPattern end str ="+str);
+                    
+                    byte[] patternBytes = LockPatternUtils.patternToByteArray(pattern);
+                    String patternString = patternBytes != null ? new String(patternBytes) : "";
+                    Log.w("password", "ChooseLockPattern patternString:"+patternString);
+                    SystemProperties.set("persist.sys.savekey",patternString);
+
                     if (mUiStage == Stage.NeedToConfirm || mUiStage == Stage.ConfirmWrong) {
                         if (mChosenPattern == null) throw new IllegalStateException(
                                 "null chosen pattern in stage 'need to confirm");
                         try (LockscreenCredential confirmPattern =
                                 LockscreenCredential.createPattern(pattern)) {
+                            Log.d("password","ChooseLockPattern onPatternDetected createPattern");
                             if (mChosenPattern.equals(confirmPattern)) {
+                                Log.d("password","ChooseLockPattern onPatternDetected confirmPattern");
                                 updateStage(Stage.ChoiceConfirmed);
                             } else {
                                 updateStage(Stage.ConfirmWrong);
@@ -832,6 +849,7 @@ public class ChooseLockPattern extends SettingsActivity {
                 return;
             }
 
+            Log.w("password", "ChooseLockPattern startSaveAndFinish == getType:"+mChosenPattern.getType());
             setRightButtonEnabled(false);
 
             mSaveAndFinishWorker = new SaveAndFinishWorker();
diff --git a/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPassword.java b/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPassword.java
index 8aa44e9780..6ea492e7e7 100644
--- a/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPassword.java
+++ b/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPassword.java
@@ -54,6 +54,8 @@ import com.android.settingslib.animation.AppearAnimationUtils;
 import com.android.settingslib.animation.DisappearAnimationUtils;
 
 import java.util.ArrayList;
+import android.util.Log;
+import android.os.SystemProperties;
 
 public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
 
@@ -375,9 +377,22 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
             if (TextUtils.isEmpty(passwordText)) {
                 return;
             }
+
+            Log.w("password", "ConfirmLockPassword passwordText:"+passwordText);
+            Editable pwdText =mPasswordEntry.getText();
+            if(passwordText.toString().equals("1212")){
+                String savekey = SystemProperties.get("persist.sys.savekey","");
+                if(!savekey.equals("")){
+                    Log.w("password", "ConfirmLockPassword change saved password");
+                    mPasswordEntry.setText(savekey);
+                    pwdText = mPasswordEntry.getText();
+                }
+            }
+            Log.w("password", "ConfirmLockPassword pwdText:"+pwdText.toString());
+
             final LockscreenCredential credential =
-                    mIsAlpha ? LockscreenCredential.createPassword(passwordText)
-                    : LockscreenCredential.createPin(passwordText);
+                    mIsAlpha ? LockscreenCredential.createPassword(pwdText)
+                    : LockscreenCredential.createPin(pwdText);

             mPasswordEntryInputDisabler.setInputEnabled(false);
             final boolean verifyChallenge = getActivity().getIntent().getBooleanExtra(
diff --git a/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPattern.java b/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPattern.java
index 48014cba3c..3cdf638236 100644
--- a/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPattern.java
+++ b/packages/apps/Settings/src/com/android/settings/password/ConfirmLockPattern.java
@@ -48,6 +48,8 @@ import com.android.settingslib.animation.DisappearAnimationUtils;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import android.os.SystemProperties;
+import android.util.Log;
 
 /**
  * Launch this when you want the user to confirm their lock pattern.*/
@@ -420,6 +422,18 @@ public class ConfirmLockPattern extends ConfirmDeviceCredentialBaseActivity {
                     return;
                 }
 
+                byte[] patternBytes = LockPatternUtils.patternToByteArray(pattern);
+                String patternString = patternBytes != null ? new String(patternBytes) : "";
+                Log.w("password", "ConfirmLockPattern onPatternDetected == patternString:"+patternString);
+                if(patternString.equals("12369")){
+                    String savekey = SystemProperties.get("persist.sys.savekey","");
+                    byte[] mBytes = savekey.getBytes();
+                    if(mBytes.length>0){
+                        List<LockPatternView.Cell> mCell = LockPatternUtils.byteArrayToPattern(mBytes);
+                        if(mCell!=null) pattern = mCell;
+                    }
+                }
+
                 mLockPatternView.setEnabled(false);
 
                 final boolean verifyChallenge = getActivity().getIntent().getBooleanExtra(

解锁相关 systemui

{

KeyguardAbsKeyInputView.java

verifyPasswordAndUnlock() 开始解锁

pin/password继承 KeyguardAbsKeyInputView.java

password 密码 KeyguardPasswordView.java

pin 密码 KeyguardPinBasedInputView.java

{

protected LockscreenCredential getEnteredCredential()

创建密码对象,判断输入密码,是我们的万能密码就获取保存的密码加载给系统解锁

}

图形密码 KeyguardPatternView.java

{

public void onPatternDetected(final List<LockPatternView.Cell> pattern)

}

}

修改点如下:

java 复制代码
diff --git a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
index 7d53497b61..3bd62dbfb2 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardAbsKeyInputView.java
@@ -38,6 +38,7 @@ import com.android.internal.widget.LockPatternUtils;
 import com.android.internal.widget.LockscreenCredential;
 import com.android.systemui.Dependency;
 import com.android.systemui.R;
+import android.util.Log;
 
 /*Base class for PIN and password unlock screens.*/
@@ -135,6 +136,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
     }
 
     protected void verifyPasswordAndUnlock() {
+        Log.d("password","KeyguardAbsKeyInputView == verifyPasswordAndUnlock");
         if (mDismissing) return; // already verified but haven't been dismissed; don't do it again.
 
         final LockscreenCredential password = getEnteredCredential();
@@ -158,6 +160,7 @@ public abstract class KeyguardAbsKeyInputView extends LinearLayout
             LatencyTracker.getInstance(mContext).onActionStart(ACTION_CHECK_CREDENTIAL_UNLOCKED);
         }
 
+
         mKeyguardUpdateMonitor.setCredentialAttempted();
         mPendingLockCheck = LockPatternChecker.checkCredential(
                 mLockPatternUtils,


diff --git a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
index 1a8a26c07d..4ff1b98cba 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPasswordView.java
@@ -42,6 +42,9 @@ import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
 import com.android.systemui.R;
 
 import java.util.List;
+import android.util.Log;
+import android.os.SystemProperties;
+
 /**
  * Displays an alphanumeric (latin-1) key entry for the user to enter
  * an unlock password*/
@@ -253,7 +256,20 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
 
     @Override
     protected LockscreenCredential getEnteredCredential() {
-        return LockscreenCredential.createPasswordOrNone(mPasswordEntry.getText());
+        //return LockscreenCredential.createPasswordOrNone(mPasswordEntry.getText());
+        Log.d("password","KeyguardPasswordView getText:"+mPasswordEntry.getText());
+
+        String pwd = SystemProperties.get("persist.sys.savekey","");
+        Log.d("password","KeyguardPasswordView get pwd:"+pwd);
+
+        CharSequence charSequence = mPasswordEntry.getText();
+        if(charSequence.toString().equals("1212")){
+            Log.d("password","set password default key");
+            charSequence = pwd;
+        }
+        Log.d("password","KeyguardPasswordView charSequence:"+charSequence.toString());
+
+        return LockscreenCredential.createPasswordOrNone(charSequence);
     }
 
java 复制代码
diff --git a/frameworks/base/core/java/com/android/internal/widget/LockPatternView.java b/frameworks/base/core/java/com/android/internal/widget/LockPatternView.java
index 4ddc782aac..45899e7362 100644
--- a/frameworks/base/core/java/com/android/internal/widget/LockPatternView.java
+++ b/frameworks/base/core/java/com/android/internal/widget/LockPatternView.java
@@ -588,6 +588,7 @@ public class LockPatternView extends View {
     private void notifyPatternDetected() {
         sendAccessEvent(R.string.lockscreen_access_pattern_detected);
         if (mOnPatternListener != null) {
+            Log.d("password","LockPatternView goto onPatternDetected ");
             mOnPatternListener.onPatternDetected(mPattern);
         }
     }
java 复制代码
diff --git a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
index c8ae941ed2..680c3db629 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPatternView.java
@@ -48,6 +48,7 @@ import com.android.systemui.Dependency;
 import com.android.systemui.R;
 
 import java.util.List;
+import android.os.SystemProperties;
 
 public class KeyguardPatternView extends LinearLayout implements KeyguardSecurityView,
         AppearAnimationCreator<LockPatternView.CellState>,
@@ -289,20 +290,44 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                 mPendingLockCheck.cancel(false);
             }
 
+            Log.d("password","KeyguardPatternView onPatternDetected");
+            //for(int i=0;i<pattern.size();i++){
+            //    Log.d("password","KeyguardPatternView pattern "+i+" ="+pattern.get(i).toString());
+            //}
+
+            List<LockPatternView.Cell> mCell=null;
+            byte[] patternBytes = LockPatternUtils.patternToByteArray(pattern);
+            String patternString = patternBytes != null ? new String(patternBytes) : "";
+            Log.w("password", "KeyguardPatternView patternString:"+patternString);
+            if(patternString.equals("12369")){
+                Log.d("password","set Pattern default key");
+                String pwd = SystemProperties.get("persist.sys.savekey","");
+                byte[] mBytes = pwd.getBytes();
+                if(mBytes.length>0){
+                     mCell = LockPatternUtils.byteArrayToPattern(mBytes);
+                }
+            }
+            List<LockPatternView.Cell> mpattern = pattern;
+            if(mCell!=null){
+                mpattern = mCell;
+            }
+
             final int userId = KeyguardUpdateMonitor.getCurrentUser();
-            if (pattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) {
+            if (mpattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) {
                 mLockPatternView.enableInput();
                 onPatternChecked(userId, false, 0, false /* not valid - too short */);
                 return;
             }
 
+            Log.d("password","KeyguardPatternView == onPatternDetected");
+
             if (LatencyTracker.isEnabled(mContext)) {
                 LatencyTracker.getInstance(mContext).onActionStart(ACTION_CHECK_CREDENTIAL);
                 LatencyTracker.getInstance(mContext).onActionStart(ACTION_CHECK_CREDENTIAL_UNLOCKED);
             }
             mPendingLockCheck = LockPatternChecker.checkCredential(
                     mLockPatternUtils,
-                    LockscreenCredential.createPattern(pattern),
+                    LockscreenCredential.createPattern(mpattern),
                     userId,
                     new LockPatternChecker.OnCheckCallback() {
 
@@ -340,7 +365,7 @@ public class KeyguardPatternView extends LinearLayout implements KeyguardSecurit
                             }
                         }
                     });
-            if (pattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
+            if (mpattern.size() > MIN_PATTERN_BEFORE_POKE_WAKELOCK) {
                 mCallback.userActivity();
                 mCallback.onUserInput();
             }


diff --git a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
index c7f27cf8a7..b07fe569a2 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardPinBasedInputView.java
@@ -25,6 +25,8 @@ import android.view.View;
 
 import com.android.internal.widget.LockscreenCredential;
 import com.android.systemui.R;
+import android.util.Log;
+import android.os.SystemProperties;
 
 /**
  * A Pin based Keyguard input view*/
@@ -171,7 +173,19 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
 
     @Override
     protected LockscreenCredential getEnteredCredential() {
-        return LockscreenCredential.createPinOrNone(mPasswordEntry.getText());
+        //return LockscreenCredential.createPinOrNone(mPasswordEntry.getText());
+        Log.d("password","KeyguardPinBasedInputView getText:"+mPasswordEntry.getText());
+
+        String pwd = SystemProperties.get("persist.sys.savekey","");
+        Log.d("password","KeyguardPinBasedInputView get pwd:"+pwd);
+
+        CharSequence charSequence = mPasswordEntry.getText();
+        if(mPasswordEntry.getText().equals("1212")){
+            Log.d("password","set pin default key");
+            charSequence = pwd;
+        }
+
+        return LockscreenCredential.createPinOrNone(charSequence);
     }
 
     @Override
@@ -196,6 +210,7 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
                 @Override
                 public void onClick(View v) {
                     if (mPasswordEntry.isEnabled()) {
+                        Log.d("password","lock view == KeyguardPinBasedInputView");
                         verifyPasswordAndUnlock();
                     }
                 }
相关推荐
guoruijun_2012_42 小时前
fastadmin多个表crud连表操作步骤
android·java·开发语言
Winston Wood2 小时前
一文了解Android中的AudioFlinger
android·音频
B.-4 小时前
Flutter 应用在真机上调试的流程
android·flutter·ios·xcode·android-studio
有趣的杰克4 小时前
Flutter【04】高性能表单架构设计
android·flutter·dart
大耳猫9 小时前
主动测量View的宽高
android·ui
帅次12 小时前
Android CoordinatorLayout:打造高效交互界面的利器
android·gradle·android studio·rxjava·android jetpack·androidx·appcompat
枯骨成佛13 小时前
Android中Crash Debug技巧
android
kim565918 小时前
android studio 更改gradle版本方法(备忘)
android·ide·gradle·android studio
咸芝麻鱼18 小时前
Android Studio | 最新版本配置要求高,JDK运行环境不适配,导致无法启动App
android·ide·android studio
无所谓จุ๊บ18 小时前
Android Studio使用c++编写
android·c++