安卓手机找回锁屏密码(android密码锁了怎么办)

由于有些设备在用户的手上,自己设置了锁屏密码,但如果长时间不使用设备,用户容易忘记自己当初设备的密码了。

像这种情况,只能强制恢复出厂设置了。但这会导致用户的数据都丢失了。所以我们在锁屏界面做了暗门,可以找回锁屏密码。

暗门操作:

1.在锁屏界面连续点击锁屏图标10次,即在锁屏图标下方显示设置的密码。

2.或在密码输入界面连续点击锁屏图标10次,即在锁屏图标下方显示设置的密码。

Android 添加找回锁屏密码的暗门

666888 为显示的密码

实现:

1.在锁屏图标下方添加个textview,用于密码的显示

frameworks/base/packages/SystemUI/res/layout/super_notification_shade.xml

@@ -92,5 +92,14 @@ android:singleLine="true" android:ellipsize="marquee" android:focusable="true" />+ <TextView+ android:id="@+id/lock_pwd"+ android:layout_width="wrap_content"+ android:layout_height="wrap_content"+ android:textColor="#FFFFFFFF"+ android:gravity="center"+ android:singleLine="true"+ android:ellipsize="marquee"+ android:focusable="true" /> </LinearLayout> </com.android.systemui.statusbar.phone.NotificationShadeWindowView> 

2.在用户第一次或重置密码时,把当前密码保存到自定义的系统属性中。用于在textview只能获取。

frameworks/base/services/core/java/com/android/server/locksettings/LockSettingsService.java

 import com.android.internal.annotations.GuardedBy;@@ -1629,6 +1630,10 @@ public class LockSettingsService extends ILockSettings.Stub { } notifySeparateProfileChallengeChanged(userId); scheduleGc();+ String pwd = new String(credential.getCredential());+ int type = credential.getStorageCryptType();+ SystemProperties.set("persist.sys.password",pwd); return true; }

3.实现连续点击10次锁屏图标,把密码显示出来的逻辑。

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

 import java.util.Optional; import java.util.concurrent.Executor;+import android.widget.LinearLayout;+import android.widget.TextView; import javax.inject.Named; import javax.inject.Provider;@@ -383,6 +385,10 @@ public class StatusBar extends SystemUI implements DemoMode, DozeServiceHost mDozeServiceHost; private boolean mWakeUpComingFromTouch; private PointF mWakeUpTouchLocation;+ private LinearLayout mLockContainer;+ private TextView mLockPwd;+ private int clickCount = 0;+ private long lastTime = 0; private final Object mQueueLock = new Object(); @@ -1212,6 +1218,9 @@ public class StatusBar extends SystemUI implements DemoMode, inflateStatusBarWindow(); mNotificationShadeWindowViewController.setService(this, mNotificationShadeWindowController); mNotificationShadeWindowView.setOnTouchListener(getStatusBarWindowTouchListener());+ mLockCOntainer= mNotificationShadeWindowView.findViewById(R.id.lock_icon_container);+ mLockContainer.setOnTouchListener(getLockIcomWindowTouchListener());+ mLockPwd = mLockContainer.findViewById(R.id.lock_pwd); // TODO: Deal with the ugliness that comes from having some of the statusbar broken out // into fragments, but the rest here, it leaves some awkward lifecycle and whatnot.@@ -1622,6 +1631,28 @@ public class StatusBar extends SystemUI implements DemoMode, return mNotificationShadeWindowView.onTouchEvent(event); }; }+ + protected View.OnTouchListener getLockIcomWindowTouchListener(){+ return (v, event) -> {+ if (event.getAction() == MotionEvent.ACTION_DOWN) {+ long newTime = System.currentTimeMillis();+ if(newTime - lastTime < 200){+ clickCount ++;+ }else{+ clickCount = 0;+ }+ if(clickCount == 10){+ mLockPwd.setText(SystemProperties.get("persist.sys.password"));+ mHandler.postDelayed(() -> {+ mLockPwd.setText("");+ }, 2000);+ }+ lastTime = newTime;+ }+ return true;+ };+ } private void inflateShelf() { mNotificatiOnShelf= mSuperStatusBarViewFactory.getNotificationShelf(mStackScroller); 

本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:dandanxi6@qq.com

(0)
上一篇 2023年1月24日 下午12:38
下一篇 2023年1月24日 下午1:23

相关推荐