How to program when FINGERPRINT_ERROR_LOCKOUT expired in Android FIngerprintManager?

When my application falls into "Too many attempts ...", 0x7 authentication error, FINGERPRINT_ERROR_LOCKOUT, how can I say without calling FingerprintManager.authenticate () in a loop and getting an error that the lock condition is cleared?

+5
source share
1 answer

Looking at the FingerprintService AOSP implementation, there is actually a broadcast intent that is sent after the expiration of the blocking period. The action taken to search is com.android.server.fingerprint.ACTION_LOCKOUT_RESET .

In your activity, you can register a broadcast receiver and wait for this intention, for example:

 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 therefore this behavior may change with any subsequent OS update. But I tried it on Nougat, and it works fine for me.

Link:

The corresponding AOSP ./frameworks/base/services/core/java/com/android/server/fingerprint/FingerprintService.java code. In this file, we can find PendingIntent with the created intent ACTION_LOCKOUT_RESET :

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

This PendingIntent is registered to be set after some elapsed AlarmManager time:

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

All Articles