Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programatically tell when FINGERPRINT_ERROR_LOCKOUT has expired in the Android FIngerprintManager?

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?

like image 603
neuman8 Avatar asked May 16 '16 15:05

neuman8


1 Answers

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());
}
like image 168
hopia Avatar answered Nov 03 '22 23:11

hopia