Java Code Examples for android.hardware.fingerprint.FingerprintManager.AuthenticationResult

The following are top voted examples for showing how to use android.hardware.fingerprint.FingerprintManager.AuthenticationResult. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boohee_v5.6   File: FingerprintManagerCompatApi23.java   View source code 6 votes vote down vote up
private static android.hardware.fingerprint.FingerprintManager.AuthenticationCallback wrapCallback(final AuthenticationCallback callback) {
    return new android.hardware.fingerprint.FingerprintManager.AuthenticationCallback() {
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
            callback.onAuthenticationError(errMsgId, errString);
        }

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

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

        public void onAuthenticationFailed() {
            callback.onAuthenticationFailed();
        }
    };
}
 
Example 2
Project: RxFingerprint   File: AesEncryptionObservable.java   View source code 6 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintEncryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] encryptedBytes = cipher.doFinal(toEncrypt.getBytes("UTF-8"));
		byte[] ivBytes = cipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();

		String encryptedString = CryptoData.fromBytes(encodingProvider, encryptedBytes, ivBytes).toString();
		CryptoData.verifyCryptoDataString(encryptedString);

		emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.AUTHENTICATED, null, encryptedString));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}
}
 
Example 3
Project: RxFingerprint   File: FingerprintObservable.java   View source code 6 votes vote down vote up
private AuthenticationCallback createAuthenticationCallback(final ObservableEmitter<T> emitter) {
	return new AuthenticationCallback() {
		@Override
		public void onAuthenticationError(int errMsgId, CharSequence errString) {
			if (!emitter.isDisposed()) {
				emitter.onError(new FingerprintAuthenticationException(errString));
			}
		}

		@Override
		public void onAuthenticationFailed() {
			FingerprintObservable.this.onAuthenticationFailed(emitter);
		}

		@Override
		public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) {
			FingerprintObservable.this.onAuthenticationHelp(emitter, helpMsgId, helpString.toString());
		}

		@Override
		public void onAuthenticationSucceeded(AuthenticationResult result) {
			FingerprintObservable.this.onAuthenticationSucceeded(emitter, result);
		}
	};
}
 
Example 4
Project: RxFingerprint   File: FingerprintAuthenticationTest.java   View source code 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 5
Project: FMTech   File: FingerprintUiHelper.java   View source code 5 votes vote down vote up
public final void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult paramAuthenticationResult)
{
  this.mIcon.setImageResource(2130837767);
  this.mStatusTextView.setTextColor(this.mStatusTextView.getResources().getColor(2131689543, null));
  updateAndAnnounceTextView(this.mStatusTextView.getResources().getString(2131362156));
  this.mStatusTextView.postDelayed(this.mSuccessRunnable, 300L);
}
 
Example 6
Project: RxFingerprint   File: AesDecryptionObservable.java   View source code 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		CryptoData cryptoData = CryptoData.fromString(encodingProvider, encryptedString);
		Cipher cipher = result.getCryptoObject().getCipher();
		String decrypted = new String(cipher.doFinal(cryptoData.getMessage()));

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, decrypted));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 7
Project: RxFingerprint   File: RsaDecryptionObservable.java   View source code 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] bytes = cipher.doFinal(encodingProvider.decode(encryptedString));
		String decrypted = new String(bytes, "UTF-8");

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, decrypted));
		emitter.onComplete();
	} catch (Exception e) {
		Logger.error("Unable to decrypt given value. RxFingerprint is only able to decrypt values previously encrypted by RxFingerprint with the same encryption mode.", e);
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 8
Project: RxFingerprint   File: FingerprintAuthenticationTest.java   View source code 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 9
Project: GravityBox   File: FingerprintLauncher.java   View source code 4 votes vote down vote up
@Override
public void onAuthenticationSucceeded(AuthenticationResult result) {
    startActivity(getFingerIdFromResult(result));
    restartListeningDelayed(1000);
}
 
Example 10
Project: RxFingerprint   File: FingerprintAuthenticationObservable.java   View source code 4 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintAuthenticationResult> emitter, AuthenticationResult result) {
    emitter.onNext(new FingerprintAuthenticationResult(FingerprintResult.AUTHENTICATED, null));
    emitter.onComplete();
}
 
Example 11
Project: RxFingerprint   File: FingerprintObservable.java   View source code 2 votes vote down vote up
/**
 * Action to execute when fingerprint authentication was successful.
 * Should return the needed result via the given {@link Emitter}.
 * <p/>
 * Should call {@link Emitter#onComplete()}.
 *
 * @param emitter current subscriber
 * @param result  result of the successful fingerprint authentication
 */
protected abstract void onAuthenticationSucceeded(ObservableEmitter<T> emitter, AuthenticationResult result);