/** * Start a fingerprint authentication request. * <p/> * If {@link #isHardwarePresent()} or {@link #hasFingerprintRegistered()} return false, no * authentication will take place, and the listener's {@link AuthenticationListener#onFailure(AuthenticationFailureReason, * boolean, CharSequence, int, int)} will immediately be called with the corresponding failure * reason. In this case, errorMessage will be non-null, fatal will be true, and the other values * are unspecified. * * @param listener The listener that will be notified of authentication events. * @param restartPredicate A predicate that will be called after each failure. If it returns * true, the fingerprint sensor will remain active and the listener will * not be called. If it returns false, the sensor will be turned off and * onFailure will be called. */ public static void authenticate(AuthenticationListener listener, RestartPredicate restartPredicate) { ReprintInternal.INSTANCE.authenticate(listener, restartPredicate); }
/** * 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 registered fingerprints. */ public static boolean hasFingerprintRegistered() { return ReprintInternal.INSTANCE.hasFingerprintRegistered(); }
public void initialize(Context context, Reprint.Logger logger) { this.context = context.getApplicationContext(); // The SPass module doesn't work below API 17, and the Imprint module obviously requires // Marshmallow. if (module != null || Build.VERSION.SDK_INT < 17) return; if (logger == null) logger = ReprintInternal.NULL_LOGGER; // Only use the Spass module on APIs that don't support Imprint. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { registerSpassModule(context, logger); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { MarshmallowReprintModule marshmallowModule = new MarshmallowReprintModule(context, logger); // Some phones like the Galaxy S5 run marshmallow, but only work with Spass if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M && !marshmallowModule.isHardwarePresent()) { registerSpassModule(context, logger); } else { registerModule(marshmallowModule); } } }
/** * 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); }
/** * 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); }
/** * Return true if a reprint module is registered that has a fingerprint reader. */ public static boolean isHardwarePresent() { return ReprintInternal.INSTANCE.isHardwarePresent(); }
/** * Start an authentication request. * * @param listener The listener to be notified. * @param restartPredicate The predicate that determines whether to restart or not. */ public void authenticate(final AuthenticationListener listener, Reprint.RestartPredicate restartPredicate) { if (module == null || !module.isHardwarePresent()) { listener.onFailure(AuthenticationFailureReason.NO_HARDWARE, true, getString(R.string.fingerprint_error_hw_not_available), 0, 0); return; } if (!module.hasFingerprintRegistered()) { listener.onFailure(AuthenticationFailureReason.NO_FINGERPRINTS_REGISTERED, true, getString(R.string.fingerprint_not_recognized), 0, 0); return; } cancellationSignal.set(new CancellationSignal()); module.authenticate(cancellationSignal.get(), listener, restartPredicate); }
/** * 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); }
private void registerSpassModule(Context context, Reprint.Logger logger) { try { final Class<?> spassModuleClass = Class.forName(REPRINT_SPASS_MODULE); final Constructor<?> constructor = spassModuleClass.getConstructor(Context.class, Reprint.Logger.class); ReprintModule module = (ReprintModule) constructor.newInstance(context, logger); registerModule(module); } catch (Exception ignored) { } }
/** * 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()); }