如何在Android FIngerprintManager中以编程方式告知FINGERPRINT_ERROR_LOCKOUT何时到期?

时间:2016-05-16 15:57:28

标签: android android-6.0-marshmallow android-fingerprint-api

当我的应用程序遇到" Too Many Attempts ...",身份验证错误0x7,FINGERPRINT_ERROR_LOCKOUT时,如何在循环中调用FingerprintManager.authenticate()并获取锁定错误时如何判断?条件被清除了?

1 个答案:

答案 0 :(得分:2)

查看系统FingerprintService的AOSP实现,实际上有一个广播意图在锁定期到期后发出。要查找的意图操作是com.android.server.fingerprint.ACTION_LOCKOUT_RESET

在您的活动中,您可以注册广播接收器并等待此意图,如下所示:

public class MyActivity extends Activity {
    ...
    private static final String ACTION_LOCKOUT_RESET =
        "com.android.server.fingerprint.ACTION_LOCKOUT_RESET";

    private final BroadcastReceiver mLockoutReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (ACTION_LOCKOUT_RESET.equals(intent.getAction())) {
                doWhateverYouNeedToDoAfterLockoutHasBeenReset();
            }
        }
    };

    private void registerLockoutResetReceiver() {
        Intent ret = getContext().registerReceiver(mLockoutReceiver, new IntentFilter(ACTION_LOCKOUT_RESET),
                null, null);
    }


    public void onCreate(Bundle savedInstanceState) {
        registerLockoutResetReceiver();
        ...
    }

    ...
}

警告:这不是公共API的一部分,因此,此行为可能会随后更新操作系统而更改。但我确实在Nougat上尝试过,它对我来说效果很好。

参考:

相关的AOSP代码为./frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java。在此文件中,我们可以找到PendingIntent创建ACTION_LOCKOUT_RESET意图的内容:

private PendingIntent getLockoutResetIntent() {
    return PendingIntent.getBroadcast(mContext, 0,
            new Intent(ACTION_LOCKOUT_RESET), PendingIntent.FLAG_UPDATE_CURRENT);
}

这个PendingIntent被注册为在AlarmManager经过一段时间后被设置:

private void scheduleLockoutReset() {
    mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime() + FAIL_LOCKOUT_TIMEOUT_MS, getLockoutResetIntent());
}