private void fail(AuthenticationFailureReason reason, boolean fatal, String message, int status) { listener.onFailure(reason, fatal, message, TAG, status); if ((!fatal || reason == TIMEOUT) && restartPredicate.invoke(reason, restartCount)) { authenticate(cancellationSignal, listener, restartPredicate, restartCount + 1); } }
/** * Start a fingerprint authentication request. * <p/> * This variant will not restart the fingerprint reader after any failure, including non-fatal * failures. * * @param listener The listener that will be notified of authentication events. */ public static void authenticateWithoutRestart(AuthenticationListener listener) { ReprintInternal.INSTANCE.authenticate(listener, RestartPredicates.neverRestart()); }
/** * Start a fingerprint authentication request. * <p/> * Equivalent to calling {@link #authenticate(AuthenticationListener, RestartPredicate)} with * {@link RestartPredicates#defaultPredicate()} * * @param listener The listener that will be notified of authentication events. */ public static void authenticate(AuthenticationListener listener) { authenticate(listener, RestartPredicates.defaultPredicate()); }
@Test public void defaultPredicate_passesMixedAuthFailureAndTimeout() throws Exception { Reprint.RestartPredicate predicate = RestartPredicates.defaultPredicate(); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 0)); assertTrue(predicate.invoke(TIMEOUT, 1)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 2)); assertTrue(predicate.invoke(TIMEOUT, 3)); assertTrue(predicate.invoke(TIMEOUT, 4)); assertTrue(predicate.invoke(TIMEOUT, 5)); assertTrue(predicate.invoke(TIMEOUT, 6)); assertFalse(predicate.invoke(TIMEOUT, 7)); }
private void startTraditional() { Reprint.authenticate(new AuthenticationListener() { @Override public void onSuccess(int moduleTag) { showSuccess(); } @Override public void onFailure(AuthenticationFailureReason failureReason, boolean fatal, CharSequence errorMessage, int moduleTag, int errorCode) { showError(failureReason, fatal, errorMessage, errorCode); } }); }
@Test public void restartTimeoutsPredicate_passesConfigurableTimeout() throws Exception { Reprint.RestartPredicate predicate = RestartPredicates.restartTimeouts(2); assertTrue(predicate.invoke(TIMEOUT, 0)); assertTrue(predicate.invoke(TIMEOUT, 1)); assertFalse(predicate.invoke(TIMEOUT, 2)); }
@Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { listener.onSuccess(TAG); }
public void registerModule(ReprintModule module) { if (module == null || this.module != null && module.tag() == this.module.tag()) { return; } if (module.isHardwarePresent()) { this.module = module; } }
/** A predicate that will retry all non-fatal failures indefinitely, and timeouts 5 times. */ public static Reprint.RestartPredicate defaultPredicate() { return restartTimeouts(5); }
/** * Load all available reprint modules. * <p/> * This is equivalent to calling {@link #registerModule(ReprintModule)} with the spass module, * if included, followed by the marshmallow module. * * @param logger An optional logger instance that will receive log messages from Reprint. */ public static void initialize(Context context, Logger logger) { ReprintInternal.INSTANCE.initialize(context, logger); }
/** * Return true if a reprint module is registered that has registered fingerprints. */ public static boolean hasFingerprintRegistered() { return ReprintInternal.INSTANCE.hasFingerprintRegistered(); }
/** * Cancel any active authentication requests. * <p/> * If no authentication is active, this call has no effect. */ public static void cancelAuthentication() { ReprintInternal.INSTANCE.cancelAuthentication(); } }
/** * Return true if a reprint module is registered that has a fingerprint reader. */ public static boolean isHardwarePresent() { return ReprintInternal.INSTANCE.isHardwarePresent(); }
public boolean hasFingerprintRegistered() { return module != null && module.hasFingerprintRegistered(); }
/** * Register an individual spass module. * <p/> * This is only necessary if you want to customize which modules are loaded, or the order in * which they're registered. Most use cases should just call {@link #initialize(Context, * Logger)} instead. * <p/> * Registering the same module twice will have no effect. The original module instance will * remain registered. * * @param module The module to register. */ public static void registerModule(ReprintModule module) { ReprintInternal.INSTANCE.registerModule(module); }
public boolean isHardwarePresent() { return module != null && module.isHardwarePresent(); }
@Test public void defaultPredicate_passesUnlimitedNonFatal() throws Exception { Reprint.RestartPredicate predicate = RestartPredicates.defaultPredicate(); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 0)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 1)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 2)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 3)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 4)); assertTrue(predicate.invoke(AUTHENTICATION_FAILED, 5)); }
@Override public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { if (!restartPredicate.invoke(AuthenticationFailureReason.SENSOR_FAILED, restartCount++)) { cancellationSignal.cancel(); } listener.onFailure(AuthenticationFailureReason.SENSOR_FAILED, false, helpString, TAG, helpMsgId); }
/** * Load all available reprint modules. * <p/> * This is equivalent to calling {@link #registerModule(ReprintModule)} with the spass module, * if included, followed by the marshmallow module. */ public static void initialize(Context context) { ReprintInternal.INSTANCE.initialize(context, null); }
@Test public void defaultPredicate_passesLimitedTimeout() throws Exception { Reprint.RestartPredicate predicate = RestartPredicates.defaultPredicate(); assertTrue(predicate.invoke(TIMEOUT, 0)); assertTrue(predicate.invoke(TIMEOUT, 1)); assertTrue(predicate.invoke(TIMEOUT, 2)); assertTrue(predicate.invoke(TIMEOUT, 3)); assertTrue(predicate.invoke(TIMEOUT, 4)); assertFalse(predicate.invoke(TIMEOUT, 5)); }