@Override public void onClick(View v) { FingerPrintUtils.openSecuritySettings(MainActivity.this); } });
@Override public void onAuthenticationFailed() { mCallback.onAuthFailed(AuthErrorCodes.CANNOT_RECOGNIZE_ERROR, null); }
@Override protected void onPause() { super.onPause(); mFingerPrintAuthHelper.stopAuth(); }
if (isScanning) stopAuth(); if (!checkFingerPrintAvailability(mContext)) return; FingerprintManager.CryptoObject cryptoObject = getCryptoObject(); if (cryptoObject == null) { mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_INIT_CHIPPER); } else { mCancellationSignal = new CancellationSignal();
/** * Check if the finger print hardware is available. * * @param context instance of the caller. * @return true if finger print authentication is supported. */ private boolean checkFingerPrintAvailability(@NonNull Context context) { // Check if we're running on Android 6.0 (M) or higher if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { //Fingerprint API only available on from Android 6.0 (M) FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.from(context); if (!fingerprintManager.isHardwareDetected()) { // Device doesn't support fingerprint authentication mCallback.onNoFingerPrintHardwareFound(); return false; } else if (!fingerprintManager.hasEnrolledFingerprints()) { // User hasn't enrolled any fingerprints to authenticate with mCallback.onNoFingerPrintRegistered(); return false; } return true; } else { mCallback.onBelowMarshmallow(); return false; } }
boolean isKeyGenerated = generateKey(); mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_GENERATE_KEY); return false; } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_GENERATE_KEY); return false; return true; } catch (KeyPermanentlyInvalidatedException e) { mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_INIT_CHIPPER); return false; } catch (KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) { mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_INIT_CHIPPER); return false;
@Override public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) { mCallback.onAuthSuccess(result.getCryptoObject()); } }, null);
@Override protected void onResume() { super.onResume(); mGoToSettingsBtn.setVisibility(View.GONE); mAuthMsgTv.setText("Scan your finger"); //start finger print authentication mFingerPrintAuthHelper.startAuth(); }
/** * Get the {@link FingerPrintAuthHelper} * * @param context instance of the caller. * @param callback {@link FingerPrintAuthCallback} to get notify whenever authentication success/fails. * @return {@link FingerPrintAuthHelper} */ @SuppressWarnings("ConstantConditions") public static FingerPrintAuthHelper getHelper(@NonNull Context context, @NonNull FingerPrintAuthCallback callback) { if (context == null) { throw new IllegalArgumentException("Context cannot be null."); } else if (callback == null) { throw new IllegalArgumentException("FingerPrintAuthCallback cannot be null."); } return new FingerPrintAuthHelper(context, callback); }
@TargetApi(23) @Nullable private FingerprintManager.CryptoObject getCryptoObject() { return cipherInit() ? new FingerprintManager.CryptoObject(mCipher) : null; }
mFingerPrintAuthHelper = FingerPrintAuthHelper.getHelper(this, this);
@Override public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { mCallback.onAuthFailed(AuthErrorCodes.RECOVERABLE_ERROR, helpString.toString()); }
@Override public void onAuthenticationError(int errMsgId, CharSequence errString) { mCallback.onAuthFailed(AuthErrorCodes.NON_RECOVERABLE_ERROR, errString.toString()); }