android one指纹解锁,基于android7.1.1第一次指纹设置必须安全解锁分析

环境:ubuntu14.04

基于高通的android7.1.1代码(同aosp差别不大)

1.现象:第一次直接设置指纹后,然后锁屏,不能够直接使用指纹进行解锁而是提示使用密码,pin码,图案等安全锁屏方式才能进行解锁?

分析:手机的解锁方式分为pin码,图案,密码等,从KeyguardSecurityModel类中即可看出来:

/**

* The different types of security available.

* @see KeyguardSecurityContainer#showSecurityScreen

*/

public enum SecurityMode {

Invalid, // NULL state

None, // No security enabled

Pattern, // Unlock by drawing a pattern.

Password, // Unlock by entering an alphanumeric password

PIN, // Strictly numeric password

SimPin, // Unlock by entering a sim pin.

SimPuk // Unlock by entering a sim puk

}

指纹等生物解锁密码等只是一种辅助用来解锁的手段,不能单独存在,而且指纹注册时必须要基于安全锁屏方式来获取Token才能注册成功.

查看代码ViewMediatorCallback接口为:

/**

* @return one of the reasons why the bouncer needs to be shown right now and the user can't use

* his normal unlock method like fingerprint or trust agents. See

* {@link KeyguardSecurityView#PROMPT_REASON_NONE},

* {@link KeyguardSecurityView#PROMPT_REASON_RESTART} and

* {@link KeyguardSecurityView#PROMPT_REASON_TIMEOUT}.

*/

int getBouncerPromptReason();

在KeyguardViewMediator中实现了此接口方法:

@Override

public int getBouncerPromptReason() {

int currentUser = ActivityManager.getCurrentUser();

boolean trust = mTrustManager.isTrustUsuallyManaged(currentUser);

boolean fingerprint = mUpdateMonitor.isUnlockWithFingerprintPossible(currentUser);

boolean any = trust || fingerprint;

KeyguardUpdateMonitor.StrongAuthTracker strongAuthTracker =

mUpdateMonitor.getStrongAuthTracker();

int strongAuth = strongAuthTracker.getStrongAuthForUser(currentUser);

if (any && !strongAuthTracker.hasUserAuthenticatedSinceBoot()) {

//第一次重启机器

return KeyguardSecurityView.PROMPT_REASON_RESTART;

} else if (fingerprint && mUpdateMonitor.hasFingerprintUnlockTimedOut(currentUser)) {

//所需要查看问题所在,当之前没有安全解锁方式解锁成功时,指纹第一次被设置时不能使用指纹解锁

return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;

} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) != 0) {

return KeyguardSecurityView.PROMPT_REASON_DEVICE_ADMIN;

} else if (trust && (strongAuth & SOME_AUTH_REQUIRED_AFTER_USER_REQUEST) != 0) {

//用户指纹和安全解锁方式都可以正常使用所提示的信息

return KeyguardSecurityView.PROMPT_REASON_USER_REQUEST;

} else if (any && (strongAuth & STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) != 0) {

return KeyguardSecurityView.PROMPT_REASON_AFTER_LOCKOUT;

}

return KeyguardSecurityView.PROMPT_REASON_NONE;

}

ViewMediatorCallback实例化传递给StatusBarKeyguardViewManager,然后在传递给KeyguardBouncer

mStatusBarKeyguardViewManager =

SystemUIFactory.getInstance().createStatusBarKeyguardViewManager(mContext,

mViewMediatorCallback, mLockPatternUtils);

mBouncer = SystemUIFactory.getInstance().createKeyguardBouncer(mContext,

mViewMediatorCallback, mLockPatternUtils, mStatusBarWindowManager, container);

接下来就需要查看在KeyguardBouncer中如何调用此方法了,查看代码:

有两个地方:

public void onStrongAuthStateChanged(int userId) {

//跟踪了相关代码,这个是在解锁完成之后才会调用触发

mBouncerPromptReason = mCallback.getBouncerPromptReason();

}

public void prepare() {

boolean wasInitialized = mRoot != null;

ensureView();

if (wasInitialized) {

//每次准备解锁界面时才会调用此方法,就是这个问题所需要的时机

mKeyguardView.showPrimarySecurityScreen();

}

mBouncerPromptReason = mCallback.getBouncerPromptReason();

}

锁屏准备解锁界面时会调用上述逻辑,那么还是要在具体实现看,具体实现类,为什么会走入对应分支,也就是

else if (fingerprint && mUpdateMonitor.hasFingerprintUnlockTimedOut(currentUser)) {

//所需要查看问题所在,当之前没有安全解锁方式解锁成功时,指纹第一次被设置时不能使用指纹解锁

return KeyguardSecurityView.PROMPT_REASON_TIMEOUT;

}

/**

* @return true if the user hasn't use strong authentication (pattern, PIN, password) since a

* while and thus can't unlock with fingerprint, false otherwise

*/

public boolean hasFingerprintUnlockTimedOut(int userId) {

//通过判断这个集合里面是否有当前用户ID,需要查看的就是添加到集合的时机

return !mStrongAuthNotTimedOut.contains(userId);

}

查看添加集合的时机为:

//

public void reportSuccessfulStrongAuthUnlockAttempt() {

mStrongAuthNotTimedOut.add(sCurrentUser);

scheduleStrongAuthTimeout();

if (mFpm != null) {

byte[] token = null; /* TODO: pass real auth token once fp HAL supports it */

mFpm.resetTimeout(token);

}

}

此方法是在解锁完成之后会调用的

@Override

public void keyguardDone(boolean strongAuth) {

if (!mKeyguardDonePending) {

KeyguardViewMediator.this.keyguardDone(true /* authenticated */);

}

if (strongAuth) {

mUpdateMonitor.reportSuccessfulStrongAuthUnlockAttempt();

}

}

这样我们就清楚了整个流程,只有在使用了安全的解锁方式解锁之后才会在集合中添加当前用户ID,代表之后设置指纹可以正常使用,如果在之前没有使用过安全的解锁方式,那么就不可以直接使用生物信息解锁,必须要使用安全解锁,这样在代码里会添加当前用户ID,代表用安全解锁方式认证完毕,所以可以使用指纹了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值