修改Android 12解锁失败等待时间规则详解( 三 )


其实这里就是上边说的回调接口调用的方法,来处理验证密码失败或者成功的逻辑,其中上边逻辑处理成功就是为true的时候,失败为false的时候,因此看false这边通过这句代码
long deadline = mLockPatternUtils.setLockoutAttemptDeadline(userId, timeoutMs);
设置了时间,然后返回一个终止时间(就是计时结束的时间戳),然后去实现倒计时处理的 。
来看一下,这个方法是怎么记录时间戳的?
//base/core/java/com////.java
/*** Set and store the lockout deadline, meaning the user can't attempt their unlock* pattern until the deadline has passed.* @return the chosen deadline.*/@UnsupportedAppUsagepublic long setLockoutAttemptDeadline(int userId, int timeoutMs) {final long deadline = SystemClock.elapsedRealtime() + timeoutMs;if (userId == USER_FRP) {// For secure password storage (that is required for FRP), the underlying storage also// enforces the deadline. Since we cannot store settings for the FRP user, don't.return deadline;}mLockoutDeadlines.put(userId, deadline);return deadline;}
由代码得知,其实参数是时间间隔,然后通过**.()**这个方法获取开机时间加上时间间隔,然后得到计时结束的时间戳存储起来 。
其实每次亮屏后会出现倒计时的界面是重新获取了计时结束的时间戳,如下代码:
@Overridepublic void onPause() {super.onPause();mResumed = false;if (mCountdownTimer != null) {mCountdownTimer.cancel();mCountdownTimer = null;}if (mPendingLockCheck != null) {mPendingLockCheck.cancel(false);mPendingLockCheck = null;}reset();}@Overridepublic void reset() {// start freshmDismissing = false;mView.resetPasswordText(false /* animate */, false /* announce */);// if the user is currently locked out, enforce it.long deadline = mLockPatternUtils.getLockoutAttemptDeadline(KeyguardUpdateMonitor.getCurrentUser());/* UNISOC: Modify for bug1692403, 1760268 {@ */if (shouldLockout(deadline)) {handleAttemptLockout(deadline);} else if (KeyguardSecurityContainerController.mDeadLine == 0&& mView.getVisibility() == View.VISIBLE) {resetState();}}
其中的**.dline(r.());**方法就是获取的计时结束时间戳,通过判断是否时间戳是否失效,设置界面倒计时是否显示,所以再看一下获取的计时结束时间戳的方法如下
/*** @return The elapsed time in millis in the future when the user is allowed to*attempt to enter their lock pattern, or 0 if the user is welcome to*enter a pattern.*/public long getLockoutAttemptDeadline(int userId) {final long deadline = mLockoutDeadlines.get(userId, 0L);final long now = SystemClock.elapsedRealtime();if (deadline < now && deadline != 0) {// timeout expiredmLockoutDeadlines.put(userId, 0);return 0L;}if (deadline > (now + timeoutMs)) {// device was rebooted, set new deadlinedeadline = now + timeoutMs;setLong(LOCKOUT_ATTEMPT_DEADLINE, deadline, userId);}return deadline;}
通过获取存储的计时结束时间戳,然后对比现在的时间,因为**.()**获取的是开机到现在的时间,所以只要关机重启,就会走下边的判断会根据最新的时间加上时间间隔,存储起来作为开机后的计时结束时间戳 。因此就看到开后会重新等待30秒的现象,因此我们在这里想要实现效果修改逻辑 。
添加代码接口,一个set,一个get,如下代码:
/*** Set and store the lockout deadline by SystemCurrentTime, meaning the user can't attempt his/her unlock* pattern until the deadline has passed.* @return the chosen deadline.*/public long setLockoutAttemptDeadlineBySystemCurrentTime(int userId, int timeoutMs) {final long deadline = System.currentTimeMillis() + timeoutMs;setLong(LOCKOUT_ATTEMPT_DEADLINE_CURRENTTIME, deadline, userId);setLong(LOCKOUT_ATTEMPT_TIMEOUT_MS, timeoutMs, userId);return deadline;}/*** @return The SystemCurrentTime in millis in the future when the user is allowed to*attempt to enter his/her lock pattern, or 0 if the user is welcome to*enter a pattern.*/public long getLockoutAttemptDeadlineBySystemCurrentTime(int userId) {long deadline = getLong(LOCKOUT_ATTEMPT_DEADLINE_CURRENTTIME, 0L, userId);final long now = System.currentTimeMillis();if (deadline