/** * Return an {@link Observable} that will continue to emit events as long as the fingerprint * sensor is active. * * @see Reprint#authenticate(AuthenticationListener) */ public static Observable<AuthenticationResult> authenticate() { return authenticate(RestartPredicates.defaultPredicate()); }
/** * 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()); }
/** A predicate that will retry all non-fatal failures indefinitely, and timeouts 5 times. */ public static Reprint.RestartPredicate defaultPredicate() { return restartTimeouts(5); }
/** * Return an {@link Flowable} that will continue to emit events as long as the fingerprint * sensor is active. * * @see Reprint#authenticate(AuthenticationListener) */ public static Flowable<AuthenticationResult> authenticate() { return authenticate(RestartPredicates.defaultPredicate()); }
@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)); }
@Test public void neverRestartPredicate_neverRestarts() throws Exception { Reprint.RestartPredicate predicate = RestartPredicates.neverRestart(); assertFalse(predicate.invoke(TIMEOUT, 0)); assertFalse(predicate.invoke(AUTHENTICATION_FAILED, 1)); assertFalse(predicate.invoke(HARDWARE_UNAVAILABLE, 2)); } }
/** * 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_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)); }
@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)); }
@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)); }