void authenticate(final CancellationSignal cancellationSignal, final AuthenticationListener listener, final Reprint.RestartPredicate restartPredicate, final int restartCount) throws SecurityException { final FingerprintManager fingerprintManager = fingerprintManager(); if (fingerprintManager == null) { listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, context.getString(R.string.fingerprint_error_hw_not_available), TAG, FINGERPRINT_ERROR_CANCELED); return; } final FingerprintManager.AuthenticationCallback callback = new AuthCallback(restartCount, restartPredicate, cancellationSignal, listener); // Why getCancellationSignalObject returns an Object is unexplained final android.os.CancellationSignal signalObject = cancellationSignal == null ? null : (android.os.CancellationSignal) cancellationSignal.getCancellationSignalObject(); // Occasionally, an NPE will bubble up out of FingerprintManager.authenticate try { fingerprintManager.authenticate(null, signalObject, 0, callback, null); } catch (NullPointerException e) { logger.logException(e, "MarshmallowReprintModule: authenticate failed unexpectedly"); listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, context.getString(R.string.fingerprint_error_unable_to_process), TAG, FINGERPRINT_ERROR_CANCELED); } }
private FingerprintManager fingerprintManager() { try { return context.getSystemService(FingerprintManager.class); } catch (Exception e) { logger.logException(e, "Could not get fingerprint system service on API that should support it."); } catch (NoClassDefFoundError e) { logger.log("FingerprintManager not available on this device"); } return null; }
}); } catch (Throwable t) { logger.logException(t, "SpassReprintModule: fingerprint identification would not start"); listener.onFailure(AuthenticationFailureReason.LOCKED_OUT, true, null, TAG, STATUS_LOCKED_OUT); return;
@Override public boolean isHardwarePresent() { final FingerprintManager fingerprintManager = fingerprintManager(); if (fingerprintManager == null) return false; // Normally, a security exception is only thrown if you don't have the USE_FINGERPRINT // permission in your manifest. However, some OEMs have pushed updates to M for phones // that don't have sensors at all, and for some reason decided not to implement the // USE_FINGERPRINT permission. So on those devices, a SecurityException is raised no matter // what. This has been confirmed on a number of devices, including the LG LS770, LS991, // and the HTC One M8. // // On Robolectric, FingerprintManager.isHardwareDetected raises an NPE. try { return fingerprintManager.isHardwareDetected(); } catch (SecurityException | NullPointerException e) { logger.logException(e, "MarshmallowReprintModule: isHardwareDetected failed unexpectedly"); return false; } }
@Override public boolean hasFingerprintRegistered() throws SecurityException { final FingerprintManager fingerprintManager = fingerprintManager(); if (fingerprintManager == null) return false; // Some devices with fingerprint sensors throw an IllegalStateException when trying to parse an // internal settings file during this call. See #29. try { return fingerprintManager.hasEnrolledFingerprints(); } catch (IllegalStateException e) { logger.logException(e, "MarshmallowReprintModule: hasEnrolledFingerprints failed unexpectedly"); return false; } }