Java Code Examples for android.hardware.fingerprint.FingerprintManager#authenticate()

The following examples show how to use android.hardware.fingerprint.FingerprintManager#authenticate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeFingerprint.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private void authenticate(final CancellationSignal cancellationSignal,
                  final AuthenticationListener listener,
                  final Fingerprint.KeepSensorActive keepSensorActive,
                  final int retryCount) {

    // Get the FingerPrint Manager, authentication callback, and cancellation signal object (for authentication)
    final FingerprintManager fingerprintManager = getFingerprintManager();
    final FingerprintManager.AuthenticationCallback callback = new AuthenticationCallback(retryCount, keepSensorActive, cancellationSignal, listener);


    if(fingerprintManager == null){
        listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, getString(R.string.hardware_unavailable), TAG, HARDWARE_UNAVAILABLE);
        return;
    }

    try{
        fingerprintManager.authenticate(null, cancellationSignal, 0, callback, null);
    } catch (NullPointerException npe){
        listener.onFailure(AuthenticationFailureReason.UNKNOWN, true, getString(R.string.authentication_failed), TAG, FINGERPRINT_MANAGER_ERROR);
    }
}
 
Example 2
Source File: FingerprintHandler.java    From programming with GNU General Public License v3.0 6 votes vote down vote up
public void startAuth(FingerprintManager manager,
                      FingerprintManager.CryptoObject cryptoObject) {

    cancellationSignal = new CancellationSignal();

    if (ActivityCompat.checkSelfPermission(appContext,
            Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {

        Toast.makeText(appContext,
                appContext.getString(R.string.fingerprint_error_no_permission),
                Toast.LENGTH_LONG).show();

        return;
    }

    manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
 
Example 3
Source File: FingerprintHandler.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
public void authenticate(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {

    CancellationSignal cancellationSignal = new CancellationSignal();
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) !=
            PackageManager.PERMISSION_GRANTED) {
        return;
    }
    manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
 
Example 4
Source File: FingerprintHelper.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
public static void authenticate(Context context, CancellationSignal cancelSignal,
                                FingerprintManager.AuthenticationCallback callback) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;
    }

    FingerprintManager manager = context.getSystemService(FingerprintManager.class);
    if (manager != null) {
        manager.authenticate(null, cancelSignal, 0, callback, null);
    }
}
 
Example 5
Source File: FingerprintHandler.java    From lock-screen with MIT License 5 votes vote down vote up
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {

        cancellationSignal = new CancellationSignal();
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
    }
 
Example 6
Source File: FingerprintHandler.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {
    mCancellationSignal = new CancellationSignal();
    mSelfCancelled = false;
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    manager.authenticate(cryptoObject, mCancellationSignal, 0, this, null);
}
 
Example 7
Source File: FingerprintHelper.java    From journaldev with MIT License 5 votes vote down vote up
public void startAuthentication(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {

        if (!isFingerprintAuthAvailable())
            return;

        mCancellationSignal = new CancellationSignal();
        if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return;
        }

        manager.authenticate(cryptoObject, mCancellationSignal, 0, this, null);
    }
 
Example 8
Source File: MainActivity.java    From Sparkplug with Eclipse Public License 1.0 5 votes vote down vote up
public void startAuth(FingerprintManager manager, FingerprintManager.CryptoObject cryptoObject) {
    CancellationSignal cancellationSignal = new CancellationSignal();
    if (ActivityCompat.checkSelfPermission(appContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Log.e(TAG, "No permissions for USE_FINGERPRINT");
        return;
    }
    Log.d(TAG, "Attempting to authenticate...");
    manager.authenticate(cryptoObject, cancellationSignal, 0, this, null);
}
 
Example 9
Source File: FingerprintAuthHandler.java    From fingerlock with MIT License 5 votes vote down vote up
@RequiresPermission(Manifest.permission.USE_FINGERPRINT)
public void start(FingerprintManager fpm) {
    if (fpm == null || mCallback == null) {
        // FIXME: 23/05/16 report error?
        return;
    }
    mSelfCancelled = false;
    mCancellationSignal = new CancellationSignal();
    fpm.authenticate(mCryptoObject, mCancellationSignal, 0 /* flags */, this, null);;
}
 
Example 10
Source File: MarshmallowReprintModule.java    From reprint with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
Source File: FingerprintHandler.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
public void doAuth(FingerprintManager manager, FingerprintManager.CryptoObject obj) {
    try {
        manager.authenticate(obj, signal, 0, this, null);
    } catch (SecurityException sce) {
    }
}
 
Example 12
Source File: FingerprintDialogCompatV23.java    From FingerprintDialogCompat with Apache License 2.0 4 votes vote down vote up
/**
 * Start the finger print authentication by enabling the finger print sensor.
 * Note: Use this function in the onResume() of the activity/fragment. Never forget to call
 * {@link #stopAuthIfRunning()} in onPause() of the activity/fragment.
 */
@TargetApi(Build.VERSION_CODES.M)
private void startAuth() {
    if (isScanning) stopAuthIfRunning();
    final FingerprintManager fingerprintManager = (FingerprintManager) mContext.getSystemService(Context.FINGERPRINT_SERVICE);

    //Cannot access the fingerprint manager.
    if (fingerprintManager == null) {
        mCallback.fingerprintAuthenticationNotSupported();
        return;
    }

    //No fingerprint enrolled.
    if (!fingerprintManager.hasEnrolledFingerprints()) {
        mCallback.hasNoFingerprintEnrolled();
        return;
    }

    final FingerprintManager.CryptoObject cryptoObject = getCryptoObject();
    if (cryptoObject != null) {
        final FingerprintManager.AuthenticationCallback authCallback = new FingerprintManager.AuthenticationCallback() {
            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                displayStatusText(errString.toString(), true);

                switch (errMsgId) {
                    case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
                    case FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED:
                        mCallback.authenticationCanceledByUser();
                        break;
                    case FingerprintManager.FINGERPRINT_ERROR_HW_NOT_PRESENT:
                    case FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE:
                        mCallback.fingerprintAuthenticationNotSupported();
                        break;
                    default:
                        mCallback.onAuthenticationError(errMsgId, errString);
                }
            }

            @Override
            public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                displayStatusText(helpString.toString(), false);
                mCallback.onAuthenticationHelp(helpMsgId, helpString);
            }

            @Override
            public void onAuthenticationFailed() {
                displayStatusText(getString(R.string.fingerprint_not_recognised), false);
                mCallback.onAuthenticationFailed();
            }

            @Override
            public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                mCallback.onAuthenticationSucceeded();
                closeDialog();
            }
        };

        mCancellationSignal = new CancellationSignal();
        //noinspection MissingPermission
        fingerprintManager.authenticate(cryptoObject,
                mCancellationSignal,
                0,
                authCallback,
                new Handler(Looper.getMainLooper()));
    } else {
        //Cannot access the secure keystore.
        mCallback.fingerprintAuthenticationNotSupported();
        closeDialog();
    }
}
 
Example 13
Source File: FingerPrintAuthHelper.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
/**
 * Start the finger print authentication by enabling the finger print sensor.
 * Note: Use this function in the onResume() of the activity/fragment. Never forget to call {@link #stopAuth()}
 * in onPause() of the activity/fragment.
 */
@TargetApi(Build.VERSION_CODES.M)
void startAuth() {
    if (isScanning) stopAuth();

    //check if the device supports the finger print hardware?
    if (!checkFingerPrintAvailability(mContext)) return;

    FingerprintManager fingerprintManager = (FingerprintManager) mContext.getSystemService(Context.FINGERPRINT_SERVICE);

    FingerprintManager.CryptoObject cryptoObject = getCryptoObject();
    if (cryptoObject == null) {
        mCallback.onFingerprintAuthFailed(NON_RECOVERABLE_ERROR, ERROR_FAILED_TO_INIT_CHIPPER);
    } else {
        mCancellationSignal = new CancellationSignal();
        //noinspection MissingPermission
        fingerprintManager.authenticate(cryptoObject,
                mCancellationSignal,
                0,
                new FingerprintManager.AuthenticationCallback() {
                    @Override
                    public void onAuthenticationError(int errMsgId, CharSequence errString) {
                        mCallback.onFingerprintAuthFailed(NON_RECOVERABLE_ERROR, errString.toString());
                    }

                    @Override
                    public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
                        mCallback.onFingerprintAuthFailed(RECOVERABLE_ERROR, helpString.toString());
                    }

                    @Override
                    public void onAuthenticationFailed() {
                        mCallback.onFingerprintAuthFailed(CANNOT_RECOGNIZE_ERROR, "Cannot recognize the fingerprint.");
                    }

                    @Override
                    public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                        mCallback.onFingerprintAuthSuccess(result.getCryptoObject());
                    }
                }, null);
    }
}
 
Example 14
Source File: FingerprintManagerCompatApi23.java    From FingerprintIdentify with MIT License 4 votes vote down vote up
public static void authenticate(Context context, CryptoObject crypto, int flags, Object cancel, AuthenticationCallback callback, Handler handler) {
    final FingerprintManager fp = getFingerprintManagerOrNull(context);
    if (fp != null) {
        fp.authenticate(wrapCryptoObject(crypto), (CancellationSignal) cancel, flags, wrapCallback(callback), handler);
    }
}
 
Example 15
Source File: LoginFragment.java    From masterpassword with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("MissingPermission")
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onResume() {
    super.onResume();
    if (!(defaultPrefs.fingerprintEnabled() && FingerprintUtil.canUseFingerprint(false))) {
        fingerprintIcon.setVisibility(View.GONE);
    } else {
        try {
            final Drawable fingerprint = fingerprintIcon.getDrawable();
            FingerprintManager fingerprintManager = (FingerprintManager) App.get().getSystemService(FINGERPRINT_SERVICE);
            FingerprintManager.CryptoObject crypto = new FingerprintManager.CryptoObject(FingerprintUtil.initDecryptCipher(defaultPrefs.encryptionIV()));
            cancellationSignal = new CancellationSignal();
            fingerprintManager.authenticate(crypto, cancellationSignal, 0, new FingerprintManager.AuthenticationCallback() {
                @Override
                public void onAuthenticationError(int errorCode, CharSequence errString) {
                    super.onAuthenticationError(errorCode, errString);
                    if (fingerprint != null) {
                        DrawableCompat.setTint(fingerprint, Color.RED);
                    }
                    SnackbarUtil.showLong(App.get().getCurrentForegroundActivity(), errString.toString());
                }

                @Override
                public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
                    super.onAuthenticationHelp(helpCode, helpString);
                    if (fingerprint != null) {
                        DrawableCompat.setTint(fingerprint, Color.YELLOW);
                    }
                    SnackbarUtil.showLong(App.get().getCurrentForegroundActivity(), helpString.toString());
                }

                @Override
                public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
                    super.onAuthenticationSucceeded(result);
                    Cipher cipher = result.getCryptoObject().getCipher();
                    Pair<String, String> secret = FingerprintUtil.tryDecrypt(cipher, defaultPrefs.encrypted());
                    if (secret != null) {
                        String password = secret.first;
                        String name = secret.second;
                        doLogin(name, password);
                    } else {
                        DrawableCompat.setTint(fingerprint, Color.RED);
                        // TODO message
                    }
                }

                @Override
                public void onAuthenticationFailed() {
                    super.onAuthenticationFailed();
                    if (fingerprint != null) {
                        DrawableCompat.setTint(fingerprint, Color.RED);
                    }
                }
            }, null);
        } catch (FingerprintException e) {
            Throwable cause = e.getCause();
            if (cause.getClass().getSimpleName().equals("KeyPermanentlyInvalidatedException")) {
                FingerprintUtil.resetFingerprintSettings();
                SnackbarUtil.showLong(getActivity(), R.string.msg_fingerprint_changed);
            } else {
                SnackbarUtil.showLong(getActivity(), e.getMessage());
            }
        }
    }
}