When my app hits the "Too Many Attempts...", authentication error 0x7, FINGERPRINT_ERROR_LOCKOUT, how can I tell without calling FingerprintManager.authenticate() in a loop and getting the error that the lockout condition is cleared?
Looking at the AOSP implementation of the system FingerprintService, there is actually a broadcast intent that gets sent out after the lockout period has expired. The intent action to look for is com.android.server.fingerprint.ACTION_LOCKOUT_RESET
.
In your Activity, you can register a broadcast receiver and wait for this intent, like so:
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();
...
}
...
}
WARNING: this is not part of the public API and so, this behavior may change with any later OS update. But I did try it on Nougat and it works quite well for me.
Reference:
The relevant AOSP code is ./frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java. In this file, we can find a PendingIntent
with an ACTION_LOCKOUT_RESET
intent being created:
private PendingIntent getLockoutResetIntent() {
return PendingIntent.getBroadcast(mContext, 0,
new Intent(ACTION_LOCKOUT_RESET), PendingIntent.FLAG_UPDATE_CURRENT);
}
This PendingIntent is registered to be set off after some elapsed time by the AlarmManager:
private void scheduleLockoutReset() {
mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + FAIL_LOCKOUT_TIMEOUT_MS, getLockoutResetIntent());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With