android.hardware.fingerprint.FingerprintManager Java Examples

The following examples show how to use android.hardware.fingerprint.FingerprintManager. 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: CipherStorageKeystoreRsaEcbTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testVerifySecureHardwareAvailability_api28() throws Exception {
  ReactApplicationContext context = getRNContext();

  // for api24+ system feature should be enabled
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available and fingerprints configured
  final FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  int result = BiometricManager.from(context).canAuthenticate();
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));

  final CipherStorage storage = new CipherStorageKeystoreAesCbc();;

  // expected RsaEcb with fingerprint
  assertThat(storage.supportsSecureHardware(), is(true));
}
 
Example #2
Source File: FingerprintAuthenticationTest.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Test
public void testAuthenticationSuccessful() throws Exception {
    when(fingerprintApiWrapper.isUnavailable()).thenReturn(false);
    when(fingerprintApiWrapper.getFingerprintManager()).thenReturn(fingerprintManager);

    AuthenticationResult result = mock(AuthenticationResult.class);
    TestObserver<FingerprintAuthenticationResult> testObserver = observable.test();

    ArgumentCaptor<FingerprintManager.AuthenticationCallback> callbackCaptor = ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
    verify(fingerprintManager).authenticate(any(CryptoObject.class), any(CancellationSignal.class), anyInt(), callbackCaptor.capture(), any(Handler.class));
    callbackCaptor.getValue().onAuthenticationSucceeded(result);

    testObserver.awaitTerminalEvent();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValueCount(1);

    FingerprintAuthenticationResult fingerprintAuthenticationResult = testObserver.values().get(0);
    assertTrue("Authentication should be successful", fingerprintAuthenticationResult.isSuccess());
    assertTrue("Result should be equal AUTHENTICATED", fingerprintAuthenticationResult.getResult().equals(FingerprintResult.AUTHENTICATED));
    assertTrue("Should contain no message", fingerprintAuthenticationResult.getMessage() == null);
}
 
Example #3
Source File: KeychainModuleTests.java    From react-native-keychain with MIT License 6 votes vote down vote up
@Test
@Config(sdk = Build.VERSION_CODES.P)
public void testFingerprintConfigured_api28() throws Exception {
  // GIVEN:
  //   API28 android version
  //   for api24+ system feature should be enabled
  //   fingerprints are configured
  ReactApplicationContext context = getRNContext();
  shadowOf(context.getPackageManager()).setSystemFeature(PackageManager.FEATURE_FINGERPRINT, true);

  // set that hardware is available
  FingerprintManager fm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
  shadowOf(fm).setIsHardwareDetected(true);
  shadowOf(fm).setDefaultFingerprints(5); // 5 fingerprints are available

  // WHEN: verify availability
  final int result = BiometricManager.from(context).canAuthenticate();
  final KeychainModule module = new KeychainModule(context);
  final boolean isFingerprintWorking = module.isFingerprintAuthAvailable();

  // THEN: biometrics works
  assertThat(result, is(BiometricManager.BIOMETRIC_SUCCESS));
  assertThat(isFingerprintWorking, is(true));
}
 
Example #4
Source File: FingerprintAuthenticationTest.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Test
public void testAuthenticationError() throws Exception {
    when(fingerprintApiWrapper.isUnavailable()).thenReturn(false);
    when(fingerprintApiWrapper.getFingerprintManager()).thenReturn(fingerprintManager);

    TestObserver<FingerprintAuthenticationResult> testObserver = observable.test();

    ArgumentCaptor<FingerprintManager.AuthenticationCallback> callbackCaptor = ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
    verify(fingerprintManager).authenticate(any(CryptoObject.class), any(CancellationSignal.class), anyInt(), callbackCaptor.capture(), any(Handler.class));
    callbackCaptor.getValue().onAuthenticationError(0, ERROR_MESSAGE);

    testObserver.awaitTerminalEvent();
    testObserver.assertError(FingerprintAuthenticationException.class);
    testObserver.assertValueCount(0);

    assertTrue("Should contain 1 error", testObserver.errorCount() == 1);

    Throwable throwable = testObserver.errors().get(0);
    assertTrue("Message should equal ERROR_MESSAGE", throwable.getMessage().equals(ERROR_MESSAGE));
}
 
Example #5
Source File: ClientMonitor.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Called when we get notification from fingerprint HAL that an image has been acquired.
 * Common to authenticate and enroll.
 * @param acquiredInfo info about the current image acquisition
 * @return true if client should be removed
 */
public boolean onAcquired(int acquiredInfo, int vendorCode) {
    if (mReceiver == null)
        return true; // client not connected
    try {
        mReceiver.onAcquired(getHalDeviceId(), acquiredInfo, vendorCode);
        return false; // acquisition continues...
    } catch (RemoteException e) {
        Slog.w(TAG, "Failed to invoke sendAcquired:", e);
        return true; // client failed
    } finally {
        // Good scans will keep the device awake
        if (acquiredInfo == FingerprintManager.FINGERPRINT_ACQUIRED_GOOD) {
            notifyUserActivity();
        }
    }
}
 
Example #6
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
public boolean supportFingerprint() {
    if (Build.VERSION.SDK_INT < 23) {
        Toast.makeText(this, "您的系统版本过低,不支持指纹功能", Toast.LENGTH_SHORT).show();
        return false;
    } else {
        KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
        FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
        if (!fingerprintManager.isHardwareDetected()) {
            Toast.makeText(this, "您的手机不支持指纹功能", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!keyguardManager.isKeyguardSecure()) {
            Toast.makeText(this, "您还未设置锁屏,请先设置锁屏并添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        } else if (!fingerprintManager.hasEnrolledFingerprints()) {
            Toast.makeText(this, "您至少需要在系统设置中添加一个指纹", Toast.LENGTH_SHORT).show();
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: AuthenticationClient.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override // binder call
public void onDialogDismissed(int reason) {
    if (mBundle != null && mDialogReceiverFromClient != null) {
        try {
            mDialogReceiverFromClient.onDialogDismissed(reason);
            if (reason == BiometricPrompt.DISMISSED_REASON_USER_CANCEL) {
                onError(FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED,
                        0 /* vendorCode */);
            }
            mDialogDismissed = true;
        } catch (RemoteException e) {
            Slog.e(TAG, "Unable to notify dialog dismissed", e);
        }
        stop(true /* initiatedByClient */);
    }
}
 
Example #8
Source File: EnrollClient.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public int start() {
    IBiometricsFingerprint daemon = getFingerprintDaemon();
    if (daemon == null) {
        Slog.w(TAG, "enroll: no fingerprint HAL!");
        return ERROR_ESRCH;
    }
    final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC);
    try {
        final int result = daemon.enroll(mCryptoToken, getGroupId(), timeout);
        if (result != 0) {
            Slog.w(TAG, "startEnroll failed, result=" + result);
            MetricsLogger.histogram(getContext(), "fingerprintd_enroll_start_error", result);
            onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
            return result;
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "startEnroll failed", e);
    }
    return 0; // success
}
 
Example #9
Source File: EnrollClient.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public int stop(boolean initiatedByClient) {
    if (mAlreadyCancelled) {
        Slog.w(TAG, "stopEnroll: already cancelled!");
        return 0;
    }
    IBiometricsFingerprint daemon = getFingerprintDaemon();
    if (daemon == null) {
        Slog.w(TAG, "stopEnrollment: no fingerprint HAL!");
        return ERROR_ESRCH;
    }
    try {
        final int result = daemon.cancel();
        if (result != 0) {
            Slog.w(TAG, "startEnrollCancel failed, result = " + result);
            return result;
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "stopEnrollment failed", e);
    }
    if (initiatedByClient) {
        onError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, 0 /* vendorCode */);
    }
    mAlreadyCancelled = true;
    return 0;
}
 
Example #10
Source File: FingerprintAuthenticationTest.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Test
public void testAuthenticationHelp() throws Exception {
    when(fingerprintApiWrapper.isUnavailable()).thenReturn(false);
    when(fingerprintApiWrapper.getFingerprintManager()).thenReturn(fingerprintManager);

    TestObserver<FingerprintAuthenticationResult> testObserver = observable.test();

    ArgumentCaptor<FingerprintManager.AuthenticationCallback> callbackCaptor = ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
    verify(fingerprintManager).authenticate(any(CryptoObject.class), any(CancellationSignal.class), anyInt(), callbackCaptor.capture(), any(Handler.class));
    callbackCaptor.getValue().onAuthenticationHelp(0, MESSAGE_HELP);

    testObserver.assertNotTerminated();
    testObserver.assertNoErrors();
    testObserver.assertNotComplete();
    testObserver.assertValueCount(1);

    FingerprintAuthenticationResult fingerprintAuthenticationResult = testObserver.values().get(0);
    assertTrue("Authentication should not be successful", !fingerprintAuthenticationResult.isSuccess());
    assertTrue("Result should be equal HELP", fingerprintAuthenticationResult.getResult().equals(FingerprintResult.HELP));
    assertTrue("Should contain help message", fingerprintAuthenticationResult.getMessage().equals(MESSAGE_HELP));
}
 
Example #11
Source File: SignTransactionDialog.java    From alpha-wallet-android with MIT License 6 votes vote down vote up
private static FingerprintManager fingerprintUnlockSupported(Context ctx)
{
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return null;
    }
    if (ctx.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    FingerprintManager fpManager = (FingerprintManager) ctx.getSystemService(Context.FINGERPRINT_SERVICE);
    if (fpManager == null || !fpManager.isHardwareDetected() || !fpManager.hasEnrolledFingerprints()) {
        return null;
    }

    return fpManager;
}
 
Example #12
Source File: AppLockActivity.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
public void setupFingerprintStuff() {
    fingerprintManager = (FingerprintManager) this.getSystemService(Context.FINGERPRINT_SERVICE);
    fingerprintHelper = new FingerprintHelper(this);
    try {
        generateKey();

        if (cipherInit()) {
            cryptoObject = new FingerprintManager.CryptoObject(cipher);
            fingerprintHelper.startAuth(fingerprintManager, cryptoObject);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example #13
Source File: RxFingerPrinter.java    From LLApp with Apache License 2.0 6 votes vote down vote up
public PublishSubject<Boolean> begin() {

        if(publishSubject == null){
            publishSubject = PublishSubject.create();
        }
        if (Build.VERSION.SDK_INT < 23){
            publishSubject.onError(new FPerException(SYSTEM_API_ERROR));
        }else {
            initManager();
            confirmFinger();
            try {
                CryptoObjectHelper helper = new CryptoObjectHelper();
                FingerprintManager.CryptoObject cryptoObject = helper.buildCryptoObject();
                startListening(cryptoObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
//            startListening(null);
        }
        return publishSubject;

    }
 
Example #14
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 #15
Source File: FingerprintManagerCompatApi23.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static FingerprintManager.AuthenticationCallback wrapCallback(
        final AuthenticationCallback callback) {
    return new FingerprintManager.AuthenticationCallback() {
        @Override
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
            callback.onAuthenticationError(errMsgId, errString);
        }

        @Override
        public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
            callback.onAuthenticationHelp(helpMsgId, helpString);
        }

        @Override
        public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
            callback.onAuthenticationSucceeded(new AuthenticationResultInternal(
                    unwrapCryptoObject(result.getCryptoObject())));
        }

        @Override
        public void onAuthenticationFailed() {
            callback.onAuthenticationFailed();
        }
    };
}
 
Example #16
Source File: AndroidSecurityBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
    System.out.println("Error " + errorCode + " : " + errString);
    NSError error;
    switch (errorCode) {
        case FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE:
            error = new NSError(LAErrorDomain, LAError.TouchIDNotAvailable, getUserInfo(errString.toString()));
            break;
        case FingerprintManager.FINGERPRINT_ERROR_UNABLE_TO_PROCESS:
            error = new NSError(LAErrorDomain, LAError.AuthenticationFailed, getUserInfo(errString.toString()));
            break;
        case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT:
            error = new NSError(LAErrorDomain, LAError.SystemCancel, getUserInfo(errString.toString()));
            break;
        case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
            error = new NSError(LAErrorDomain, LAError.SystemCancel, getUserInfo(errString.toString()));
            break;
        case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
            error = new NSError(LAErrorDomain, LAError.TouchIDLockout, getUserInfo(errString.toString()));
    }
}
 
Example #17
Source File: FingerprintAuthenticationTest.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthenticationSuccessfulOnSecondTry() throws Exception {
    when(fingerprintApiWrapper.isUnavailable()).thenReturn(false);
    when(fingerprintApiWrapper.getFingerprintManager()).thenReturn(fingerprintManager);

    TestObserver<FingerprintAuthenticationResult> testObserver = observable.test();

    ArgumentCaptor<FingerprintManager.AuthenticationCallback> callbackCaptor = ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
    verify(fingerprintManager).authenticate(any(CryptoObject.class), any(CancellationSignal.class), anyInt(), callbackCaptor.capture(), any(Handler.class));
    callbackCaptor.getValue().onAuthenticationHelp(0, MESSAGE_HELP);

    testObserver.assertNotTerminated();
    testObserver.assertNoErrors();
    testObserver.assertNotComplete();
    testObserver.assertValueCount(1);

    FingerprintAuthenticationResult helpResult = testObserver.values().get(0);
    assertTrue("Authentication should not be successful", !helpResult.isSuccess());
    assertTrue("Result should be equal HELP", helpResult.getResult().equals(FingerprintResult.HELP));
    assertTrue("Should contain help message", helpResult.getMessage().equals(MESSAGE_HELP));

    callbackCaptor.getValue().onAuthenticationSucceeded(mock(AuthenticationResult.class));

    testObserver.awaitTerminalEvent();
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    testObserver.assertValueCount(2);

    FingerprintAuthenticationResult successResult = testObserver.values().get(1);
    assertTrue("Authentication should be successful", successResult.isSuccess());
    assertTrue("Result should be equal AUTHENTICATED", successResult.getResult().equals(FingerprintResult.AUTHENTICATED));
    assertTrue("Should contain no message", successResult.getMessage() == null);
}
 
Example #18
Source File: DeviceAvailability.java    From react-native-secure-storage with MIT License 5 votes vote down vote up
public static boolean isFingerprintAuthAvailable(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager =
                (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        return fingerprintManager.isHardwareDetected() &&
                fingerprintManager.hasEnrolledFingerprints();
    }
    return false;
}
 
Example #19
Source File: FingerPrintFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void startListening(Cipher cipher) {
    isSelfCancelled = false;
    mCancellationSignal = new CancellationSignal();
    //authenticate()方法来开启指纹指纹监听
    //第一个参数是CryptoObject对象。
    // 第二个参数是CancellationSignal对象,可以使用它来取消指纹认证操作。
    // 第三个参数是可选参数,官方的建议是直接传0就可以了。
    // 第四个参数用于接收指纹认证的回调,下述代码中我将所有的回调可能都进行了界面提示,方便大家观察。
    // 第五个参数用于指定处理回调的Handler,这里直接传null表示回调到主线程即可。
    fingerprintManager.authenticate(new FingerprintManager.CryptoObject(cipher), mCancellationSignal, 0, new FingerprintManager.AuthenticationCallback() {
        @Override
        public void onAuthenticationError(int errorCode, CharSequence errString) {
            if (!isSelfCancelled) {
                errorMsg.setText(errString);
                if (errorCode == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT) {
                    Toast.makeText(mActivity, errString, Toast.LENGTH_SHORT).show();
                    dismiss();
                }
            }
        }

        @Override
        public void onAuthenticationHelp(int helpCode, CharSequence helpString) {
            errorMsg.setText(helpString);
        }

        @Override
        public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
            Toast.makeText(mActivity, "指纹认证成功", Toast.LENGTH_SHORT).show();
            mActivity.onAuthenticated();
        }

        @Override
        public void onAuthenticationFailed() {
            errorMsg.setText("指纹认证失败,请再试一次");
        }
    }, null);
}
 
Example #20
Source File: SmartLockHelper.java    From samples-android with Apache License 2.0 5 votes vote down vote up
public static boolean isHardwareSupported(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        boolean isGrantedFingerprintPermission = ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED;
        // In some reason FingerprintManagerCompat return false when you check
        // isHardwareDetected on some devices. Better to use FingerprintManger to check it.
        boolean isSupportedByDevice = context.getSystemService(FingerprintManager.class).isHardwareDetected();
        return isGrantedFingerprintPermission && isSupportedByDevice;
    } else {
        return false;
    }
}
 
Example #21
Source File: AndroidFingerprint.java    From FingerprintIdentify with MIT License 5 votes vote down vote up
@Override
protected void doIdentify() {
    try {
        mCancellationSignal = new CancellationSignal();
        mFingerprintManagerCompat.authenticate(null, 0, mCancellationSignal, new FingerprintManagerCompat.AuthenticationCallback() {
            @Override
            public void onAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) {
                super.onAuthenticationSucceeded(result);
                onSucceed();
            }

            @Override
            public void onAuthenticationFailed() {
                super.onAuthenticationFailed();
                onNotMatch();
            }

            @Override
            public void onAuthenticationError(int errMsgId, CharSequence errString) {
                super.onAuthenticationError(errMsgId, errString);

                if (errMsgId == FingerprintManager.FINGERPRINT_ERROR_CANCELED ||
                        errMsgId == FingerprintManager.FINGERPRINT_ERROR_USER_CANCELED) {
                    return;
                }

                onFailed(errMsgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT ||
                        errMsgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT);
            }
        }, null);
    } catch (Throwable e) {
        onCatchException(e);
        onFailed(false);
    }
}
 
Example #22
Source File: AppLockActivity.java    From LolliPin with MIT License 5 votes vote down vote up
/**
 * Init {@link FingerprintManager} of the {@link android.os.Build.VERSION#SDK_INT} is > to Marshmallow
 * and {@link FingerprintManager#isHardwareDetected()}.
 */
private void initLayoutForFingerprint() {
    mFingerprintImageView = (ImageView) this.findViewById(R.id.pin_code_fingerprint_imageview);
    mFingerprintTextView = (TextView) this.findViewById(R.id.pin_code_fingerprint_textview);
    if (mType == AppLock.UNLOCK_PIN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mFingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);
        mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManager).build(mFingerprintImageView, mFingerprintTextView, this);
        try {
        if (mFingerprintManager.isHardwareDetected() && mFingerprintUiHelper.isFingerprintAuthAvailable()
                && mLockManager.getAppLock().isFingerprintAuthEnabled()) {
                mFingerprintImageView.setVisibility(View.VISIBLE);
                mFingerprintTextView.setVisibility(View.VISIBLE);
                mFingerprintUiHelper.startListening();
            } else {
                mFingerprintImageView.setVisibility(View.GONE);
                mFingerprintTextView.setVisibility(View.GONE);
            }
        } catch (SecurityException e) {
            Log.e(TAG, e.toString());
            mFingerprintImageView.setVisibility(View.GONE);
            mFingerprintTextView.setVisibility(View.GONE);
        }
    } else {
        mFingerprintImageView.setVisibility(View.GONE);
        mFingerprintTextView.setVisibility(View.GONE);
    }
}
 
Example #23
Source File: FingerprintCore.java    From LockDemo with Apache License 2.0 5 votes vote down vote up
private void initCryptoObject() {
    try {
        mCryptoObjectCreator = new  CryptoObjectCreator(new  CryptoObjectCreator.ICryptoObjectCreateListener() {
            @Override
            public void onDataPrepared(FingerprintManager.CryptoObject cryptoObject) {
                // startAuthenticate(cryptoObject);
                // 如果需要一开始就进行指纹识别,可以在秘钥数据创建之后就启动指纹认证
            }
        });
    } catch (Throwable throwable) {

    }
}
 
Example #24
Source File: AppLockUtils.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 5 votes vote down vote up
public static boolean hasDeviceFingerprintSupport(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints();
    } else {
        return false;
    }
}
 
Example #25
Source File: FingerprintUiHelper.java    From UAF with Apache License 2.0 5 votes vote down vote up
public void startListening(FingerprintManager.CryptoObject cryptoObject) {
    if (!isFingerprintAuthAvailable()) {
        return;
    }
    mCancellationSignal = new CancellationSignal();
    mSelfCancelled = false;
    // The line below prevents the false positive inspection from Android Studio
    // noinspection ResourceType
    mFingerprintManager
            .authenticate(cryptoObject, mCancellationSignal, 0 /* flags */, this, null);
    mIcon.setImageResource(R.drawable.ic_fp_40px);
}
 
Example #26
Source File: MainActivity.java    From SafeApp with Apache License 2.0 5 votes vote down vote up
/**
 * Shows a { @code FingerprintDialog } .
 *
 * @param cipher             which needs user authentication
 * @param fingerprintPurpose represents the purpose e.g. ENCRYPT, DECRYPT
 */
private void showFingerprintDialog(Cipher cipher, int fingerprintPurpose) {
    if (getFragmentManager().findFragmentByTag(TAG_FINGERPRINT_DIALOG) == null) {
        mFingerprintDialog.init(fingerprintPurpose,
                new FingerprintManager.CryptoObject(cipher));
        mFingerprintDialog.show(getFragmentManager(), TAG_FINGERPRINT_DIALOG);
    }
}
 
Example #27
Source File: FingerprintManagerCompatApi23.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static FingerprintManager.CryptoObject wrapCryptoObject(CryptoObject cryptoObject) {
    if (cryptoObject == null) {
        return null;
    } else if (cryptoObject.getCipher() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getCipher());
    } else if (cryptoObject.getSignature() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getSignature());
    } else if (cryptoObject.getMac() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getMac());
    } else {
        return null;
    }
}
 
Example #28
Source File: FingerprintManagerCompatApi23.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static CryptoObject unwrapCryptoObject(FingerprintManager.CryptoObject cryptoObject) {
    if (cryptoObject == null) {
        return null;
    } else if (cryptoObject.getCipher() != null) {
        return new CryptoObject(cryptoObject.getCipher());
    } else if (cryptoObject.getSignature() != null) {
        return new CryptoObject(cryptoObject.getSignature());
    } else if (cryptoObject.getMac() != null) {
        return new CryptoObject(cryptoObject.getMac());
    } else {
        return null;
    }
}
 
Example #29
Source File: RealWhorlwind.java    From whorlwind with Apache License 2.0 5 votes vote down vote up
RealWhorlwind(Context context, FingerprintManager fingerprintManager, Storage storage,
    String keyAlias, KeyStore keyStore, KeyPairGenerator keyGenerator, KeyFactory keyFactory) {
  this.context = context;
  this.fingerprintManager = fingerprintManager;
  this.storage = storage;
  this.keyAlias = keyAlias;
  this.keyStore = keyStore;
  this.keyGenerator = keyGenerator;
  this.keyFactory = keyFactory;

  readerScanning = new AtomicBoolean();
}
 
Example #30
Source File: FingerprintManagerCompatApi23.java    From FingerprintIdentify with MIT License 5 votes vote down vote up
private static FingerprintManager.CryptoObject wrapCryptoObject(CryptoObject cryptoObject) {
    if (cryptoObject == null) {
        return null;
    } else if (cryptoObject.getCipher() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getCipher());
    } else if (cryptoObject.getSignature() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getSignature());
    } else if (cryptoObject.getMac() != null) {
        return new FingerprintManager.CryptoObject(cryptoObject.getMac());
    } else {
        return null;
    }
}