Java 类android.hardware.fingerprint.FingerprintManager 实例源码

项目:UAF    文件:ExampleFidoUafActivity.java   
@RequiresApi(api = Build.VERSION_CODES.M)
private void startFingerprintAuth() throws GeneralSecurityException, IOException {
    Signature signature = Signature.getInstance("SHA256withECDSA");
    PrivateKey privateKey = fidoKeystore.getKeyPair(Preferences.getSettingsParam("username")).getPrivate();
    signature.initSign(privateKey);

    FingerprintAuthenticationDialogFragment fragment
            = new FingerprintAuthenticationDialogFragment();
    FingerprintManager.CryptoObject cryptoObj = new FingerprintManager.CryptoObject(signature);
    fragment.setCryptoObject(cryptoObj);
    fragment.setStage(
            FingerprintAuthenticationDialogFragment.Stage.FINGERPRINT);

    Log.d(TAG, "Showing fragment: " + fragment);
    fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG);
}
项目:MakiLite    文件:FingerprintUiHelper.java   
/**
 * Called by {@link FingerprintManager} if the authentication succeeded.
 */
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    mIcon.setImageResource(R.drawable.ic_fingerprint_success);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(R.color.success_color, null));
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(R.string.pin_code_fingerprint_success));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated();
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:Phoenix-for-VK    文件:FingerprintTools.java   
public static SensorState checkSensorState(Context context) {
    if (checkFingerprintCompatibility(context)) {
        KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);

        if (!keyguardManager.isKeyguardSecure()) {
            return SensorState.NOT_BLOCKED;
        }

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !((FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE)).hasEnrolledFingerprints()) {
            return SensorState.NO_FINGERPRINTS;
        }

        return SensorState.READY;
    } else {
        return SensorState.NOT_SUPPORTED;
    }
}
项目:WeChatFingerprintPay    文件:FingerprintHandler.java   
@Override
public void onAuthenticationSucceeded(
        FingerprintManager.AuthenticationResult result) {

    String pwd = WCFPXSharedPreferencesUtil.getPwd(mContext);
    //TODO 这里逻辑有待修改
    if (pwd != null && pwd.length() > 0) {
        if (mEditText != null) {
            mEditText.setText(pwd);
        }
        else {
            showToast("Error: mEditText null");
        }
    } else {
        showToast("Sorry, but you have not set the password in WeChatFingerprintPay yet");
    }
}
项目:WeChatFingerprintPay    文件:PayHook.java   
private void initFingerPrint(Context context) {
    KeyguardManager keyguardManager =
            (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
    FingerprintManager fingerprintManager =
            (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);

    if (!fingerprintManager.isHardwareDetected()) {
        Toast.makeText(context, "Your device doesn't support fingerprint authentication", Toast.LENGTH_LONG).show();
    } else if (context.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        Toast.makeText(context, "Please enable the fingerprint permission", Toast.LENGTH_LONG).show();
    } else if (!fingerprintManager.hasEnrolledFingerprints()) {
        Toast.makeText(
                context,
                "No fingerprint configured. Please register at least one fingerprint in your device's Settings",
                Toast.LENGTH_LONG).show();
    } else if (!keyguardManager.isKeyguardSecure()) {
        Toast.makeText(
                context,
                "Please enable lock screen security in your device's Settings",
                Toast.LENGTH_LONG).show();
    } else {
        fHandler = new FingerprintHandler(context);
    }
}
项目:keemob    文件:FingerprintUiHelper.java   
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    fingerprintResult = result;
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    int ic_fingerprint_success_id = mContext.getResources()
            .getIdentifier("ic_fingerprint_success", "drawable", FingerprintAuth.packageName);
    mIcon.setImageResource(ic_fingerprint_success_id);
    int success_color_id = mContext.getResources()
            .getIdentifier("success_color", "color", FingerprintAuth.packageName);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(success_color_id, null));
    int fingerprint_success_id = mContext.getResources()
            .getIdentifier("fingerprint_success", "string", FingerprintAuth.packageName);
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(fingerprint_success_id));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated(fingerprintResult);
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:keemob    文件:FingerprintUiHelper.java   
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    fingerprintResult = result;
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    int ic_fingerprint_success_id = mContext.getResources()
            .getIdentifier("ic_fingerprint_success", "drawable", FingerprintAuth.packageName);
    mIcon.setImageResource(ic_fingerprint_success_id);
    int success_color_id = mContext.getResources()
            .getIdentifier("success_color", "color", FingerprintAuth.packageName);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(success_color_id, null));
    int fingerprint_success_id = mContext.getResources()
            .getIdentifier("fingerprint_success", "string", FingerprintAuth.packageName);
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(fingerprint_success_id));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated(fingerprintResult);
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:PasscodeView    文件:FingerPrintAuthHelper.java   
/**
 * Check if the finger print hardware is available.
 *
 * @param context instance of the caller.
 * @return true if finger print authentication is supported.
 */
@SuppressWarnings("MissingPermission")
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)
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);

        if (!fingerprintManager.isHardwareDetected()) {
            return false;
        } else if (!fingerprintManager.hasEnrolledFingerprints()) {
            return false;
        }
        return true;
    } else {
        return false;
    }
}
项目:FingerprintAssistant    文件:MainActivity.java   
@Override
public void onAuthentication(int helpOrErrorCode, CharSequence infoString, FingerprintManager.AuthenticationResult authenticationResult, int authCode) {
    switch (authCode) {
        case ResponseCode.AUTH_ERROR:
            // Show appropriate message
            break;
        case ResponseCode.AUTH_FAILED:
            // Show appropriate message
            showToast("Authentication Failed");
            break;
        case ResponseCode.AUTH_HELP:
            // Show appropriate message
            break;
        case ResponseCode.AUTH_SUCCESS:
            // Do whatever you want
            showToast("Authentication Success");
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                fingerprintResultsHandler.restartListening(fingerPrintHelper.getFingerprintManager(), fingerPrintHelper.getCryptoObject());
            }
            break;
    }
}
项目:react-native-touch-id-android    文件:FingerprintModule.java   
@ReactMethod
public void isSensorAvailable(final Promise promise) {

    response = Arguments.createMap();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (ActivityCompat.checkSelfPermission(mReactContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            sendResponse("failed", "You haven't allow this app to use your fingerprint sensor", promise);
            return;
        }

        if (mReactContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) ||
            ((FingerprintManager) mReactContext.getSystemService(Context.FINGERPRINT_SERVICE)).isHardwareDetected()) {
            if (((FingerprintManager) mReactContext.getSystemService(Context.FINGERPRINT_SERVICE)).hasEnrolledFingerprints()) {
                sendResponse("ok", null, promise);
            } else {
                sendResponse("failed", "You have fingerprint sensor, but you should set it enabled in your settings to use with this app", promise);
            }
        } else {
            sendResponse("failed", "You don\'t have appropriate hardware", promise);
        }
    } else {
        sendResponse("failed", "You don\'t have appropriate hardware", promise);
    }
}
项目:Lunary-Ethereum-Wallet    文件:AppLockActivity.java   
@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();
    }
}
项目:programming    文件:FingerprintHandler.java   
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);
}
项目:programming    文件:MainActivity.java   
private void inicializarSeguranca() {

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

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

            return;
        }

        keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);

        keystoreManager = new AndroidKeystoreManager(KEY_NAME);
        keystoreManager.generateKey();

        if (keystoreManager.cipherInit()) {
            cryptoObject = new FingerprintManager.CryptoObject(keystoreManager.getCipher());
        }
    }
项目:FingerprintIdentify    文件:FingerprintManagerCompatApi23.java   
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();
        }
    };
}
项目:boohee_v5.6    文件:FingerprintManagerCompatApi23.java   
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();
        }
    };
}
项目:GravityBox    文件:FingerprintLauncher.java   
private void initFingerprintManager() throws Throwable {
    mFpManager = (FingerprintManager) mContext.getSystemService(Context.FINGERPRINT_SERVICE);
    if (!mFpManager.isHardwareDetected())
        throw new IllegalStateException("Fingerprint hardware not present");

    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    KeyGenerator keyGenerator = KeyGenerator.getInstance(
            KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
    keyStore.load(null);
    keyGenerator.init(new KeyGenParameterSpec.Builder(
            KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
            .build());
    keyGenerator.generateKey();

    Cipher cipher = Cipher.getInstance(
            KeyProperties.KEY_ALGORITHM_AES + "/" +
            KeyProperties.BLOCK_MODE_CBC + "/" +
            KeyProperties.ENCRYPTION_PADDING_PKCS7);
    SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
    cipher.init(Cipher.ENCRYPT_MODE, key);

    mFpHandler = new FingerprintHandler(cipher);

    if (DEBUG) log("Fingeprint manager initialized");
}
项目:AndroidFingerPrintDemo    文件:MainActivity.java   
private void handleHelpCode(int code) {
    switch (code) {
        case FingerprintManager.FINGERPRINT_ACQUIRED_GOOD:
            setResultInfo(R.string.AcquiredGood_warning);
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_IMAGER_DIRTY:
            setResultInfo(R.string.AcquiredImageDirty_warning);
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_INSUFFICIENT:
            setResultInfo(R.string.AcquiredInsufficient_warning);
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_PARTIAL:
            setResultInfo(R.string.AcquiredPartial_warning);
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_TOO_FAST:
            setResultInfo(R.string.AcquiredTooFast_warning);
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_TOO_SLOW:
            setResultInfo(R.string.AcquiredToSlow_warning);
            break;
    }
}
项目:AndroidFingerPrintDemo    文件:MainActivity.java   
private void handleErrorCode(int code) {
    switch (code) {
        case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
            setResultInfo(R.string.ErrorCanceled_warning);
            break;
        case FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE:
            setResultInfo(R.string.ErrorHwUnavailable_warning);
            break;
        case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
            setResultInfo(R.string.ErrorLockout_warning);
            break;
        case FingerprintManager.FINGERPRINT_ERROR_NO_SPACE:
            setResultInfo(R.string.ErrorNoSpace_warning);
            break;
        case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT:
            setResultInfo(R.string.ErrorTimeout_warning);
            break;
        case FingerprintManager.FINGERPRINT_ERROR_UNABLE_TO_PROCESS:
            setResultInfo(R.string.ErrorUnableToProcess_warning);
            break;
    }
}
项目:whorlwind    文件:Whorlwind.java   
@TargetApi(Build.VERSION_CODES.M)
private static Whorlwind createRealWhorlwind(Context context, Storage storage, String keyAlias) {
  try {
    FingerprintManager fingerprintManager = context.getSystemService(FingerprintManager.class);

    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
    keyStore.load(null); // Ensure the key store can be loaded before continuing.

    KeyPairGenerator keyGenerator =
        KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");

    RealWhorlwind.createCipher(); // If this doesn't throw, the cipher we need is available.

    return new RealWhorlwind(context, fingerprintManager, storage, keyAlias, keyStore,
        keyGenerator, keyFactory);
  } catch (Exception e) {
    Log.w("Cannot store securely.", e);
    return new NullWhorlwind();
  }
}
项目:whorlwind    文件:RealWhorlwindTest.java   
@Ignore @Test public void immediateUnsubscribeShouldntCallAuthenticate()
    throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, IOException {
  Key key = mock(Key.class);
  shadowContext.grantPermissions(USE_FINGERPRINT);
  when(fingerprintManager.isHardwareDetected()).thenReturn(true);
  when(fingerprintManager.hasEnrolledFingerprints()).thenReturn(true);
  when(keyStore.getKey("test", null)).thenReturn(key);

  Observable<ReadResult> read = whorlwind.read("test").take(1);

  ReadResult readResult = read.blockingSingle();
  assertEquals(ReadResult.ReadState.NEEDS_AUTH, readResult.readState);

  verify(fingerprintManager, never()).authenticate(any(FingerprintManager.CryptoObject.class),
      any(CancellationSignal.class), anyInt(),
      any(FingerprintManager.AuthenticationCallback.class), any(Handler.class));
}
项目:permissionsModule    文件:FingerprintManagerCompatApi23.java   
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();
        }
    };
}
项目:cordova-plugin-android-fingerprint-auth    文件:FingerprintUiHelper.java   
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    fingerprintResult = result;
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    int ic_fingerprint_success_id = mContext.getResources()
            .getIdentifier("ic_fingerprint_success", "drawable", FingerprintAuth.packageName);
    mIcon.setImageResource(ic_fingerprint_success_id);
    int success_color_id = mContext.getResources()
            .getIdentifier("success_color", "color", FingerprintAuth.packageName);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(success_color_id, null));
    int fingerprint_success_id = mContext.getResources()
            .getIdentifier("fingerprint_success", "string", FingerprintAuth.packageName);
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(fingerprint_success_id));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated(fingerprintResult);
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:LLApp    文件:RxFingerPrinter.java   
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;

    }
项目:cordova-plugin-fingerprint-aio    文件:FingerprintUiHelper.java   
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    int ic_fingerprint_success_id = mContext.getResources()
            .getIdentifier("ic_fingerprint_success", "drawable", Fingerprint.packageName);
    mIcon.setImageResource(ic_fingerprint_success_id);
    int success_color_id = mContext.getResources()
            .getIdentifier("success_color", "color", Fingerprint.packageName);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(success_color_id, null));
    int fingerprint_success_id = mContext.getResources()
            .getIdentifier("fingerprint_success", "string", Fingerprint.packageName);
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(fingerprint_success_id));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated();
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:android-fingerprint-example    文件:MainActivity.java   
private void checkFingerprints() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.USE_FINGERPRINT}, REQ_FINGERPRINT_PERMISSION);
        return;
    }
    mKeyguardManager = getSystemService(KeyguardManager.class);
    mFingerPrintManager = getSystemService(FingerprintManager.class);

    if(!backdoor) {
        Toast.makeText(MainActivity.this, R.string.checking_secure_n_permissions, Toast.LENGTH_SHORT).show();
        if (!mKeyguardManager.isKeyguardSecure()) {
            Toast.makeText(MainActivity.this, R.string.go_2_settings, Toast.LENGTH_LONG).show();
            return;
        }
        if (!mFingerPrintManager.hasEnrolledFingerprints()) {
            Toast.makeText(MainActivity.this, R.string.go_2_settings, Toast.LENGTH_LONG).show();
            return;
        }
    }
    createKey();
    showFingerPrintDialog();
}
项目:PasswordRecorder    文件:FingerPrintAuth.java   
private void handleHelpCode(int code) {
    switch (code) {
        case FingerprintManager.FINGERPRINT_ACQUIRED_GOOD:
            Log.i("success","good");
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_IMAGER_DIRTY:
            Log.i("success","dirty");
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_INSUFFICIENT:
            Log.i("success","insufficient");
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_PARTIAL:
            Log.i("success","partial");
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_TOO_FAST:
            Log.i("success","fast");
            break;
        case FingerprintManager.FINGERPRINT_ACQUIRED_TOO_SLOW:
            Log.i("success","slow");
            break;
    }
}
项目:PasswordRecorder    文件:FingerPrintAuth.java   
private void handleErrorCode(int code) {
    switch (code) {
        case FingerprintManager.FINGERPRINT_ERROR_CANCELED:
            Log.i("fail","cancel");
            break;
        case FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE:
            Log.i("fail","unavailable");
            break;
        case FingerprintManager.FINGERPRINT_ERROR_LOCKOUT:
            Log.i("fail","lockout");
            break;
        case FingerprintManager.FINGERPRINT_ERROR_NO_SPACE:
            Log.i("fail","nospace");
            break;
        case FingerprintManager.FINGERPRINT_ERROR_TIMEOUT:
            Log.i("fail","timeout");
            break;
        case FingerprintManager.FINGERPRINT_ERROR_UNABLE_TO_PROCESS:
            Log.i("fail","unable");
            break;
    }
}
项目:RxFingerprint    文件:FingerprintAuthenticationTest.java   
@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);
}
项目:RxFingerprint    文件:FingerprintAuthenticationTest.java   
@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));
}
项目:RxFingerprint    文件:FingerprintAuthenticationTest.java   
@Test
public void testAuthenticationFailed() 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().onAuthenticationFailed();

    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 FAILED", fingerprintAuthenticationResult.getResult().equals(FingerprintResult.FAILED));
    assertTrue("Should contain no message", fingerprintAuthenticationResult.getMessage() == null);
}
项目:RxFingerprint    文件:FingerprintAuthenticationTest.java   
@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));
}
项目:LolliPin    文件:FingerprintUiHelper.java   
/**
 * Called by {@link FingerprintManager} if the authentication succeeded.
 */
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    mErrorTextView.removeCallbacks(mResetErrorTextRunnable);
    mIcon.setImageResource(R.drawable.ic_fingerprint_success);
    mErrorTextView.setTextColor(
            mErrorTextView.getResources().getColor(R.color.success_color, null));
    mErrorTextView.setText(
            mErrorTextView.getResources().getString(R.string.pin_code_fingerprint_success));
    mIcon.postDelayed(new Runnable() {
        @Override
        public void run() {
            mCallback.onAuthenticated();
        }
    }, SUCCESS_DELAY_MILLIS);
}
项目:simple-marshmallow-samples    文件:FingerprintActivity.java   
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
    super.onAuthenticationSucceeded(result);
    Log.d(TAG, "onAuthenticationSucceeded");

    mTextView.append("指紋認証に成功しました\n");
    mTextView.append("復号処理中です...\n");

    try {
        // 復号処理
        byte[] plain = result.getCryptoObject().getCipher().doFinal(mEncryptedData);

        mTextView.append("復号されたデータ: ");
        mTextView.append(new String(plain, CHARSET));
    } catch (UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) {
        Log.d(TAG, e.getClass().getSimpleName(), e);
    }
}
项目:simple-marshmallow-samples    文件:FingerprintActivity.java   
private boolean scanFingerprint() throws CertificateException, NoSuchAlgorithmException,
        IOException, UnrecoverableKeyException, KeyStoreException, InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchPaddingException {

    FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);

    //noinspection ResourceType
    if (fingerprintManager.isHardwareDetected()) {

        Cipher cipher = getCipherInstance();

        IvParameterSpec ivSpec = new IvParameterSpec(mIvData);
        SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
        cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);

        FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);

        //noinspection ResourceType
        fingerprintManager.authenticate(cryptoObject, mCancellationSignal, 0x0, mAuthenticationCallback, mHandler);

        return true;
    } else {
        return false;
    }
}
项目:reprint    文件:MarshmallowReprintModule.java   
@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;
    }
}
项目:MyCTFWriteUps    文件:FingerprintManagerCompatApi23.java   
private static CryptoObject unwrapCryptoObject(android.hardware.fingerprint.FingerprintManager.CryptoObject cryptoobject)
{
    if (cryptoobject != null)
    {
        if (cryptoobject.getCipher() != null)
        {
            return new CryptoObject(cryptoobject.getCipher());
        }
        if (cryptoobject.getSignature() != null)
        {
            return new CryptoObject(cryptoobject.getSignature());
        }
        if (cryptoobject.getMac() != null)
        {
            return new CryptoObject(cryptoobject.getMac());
        }
    }
    return null;
}
项目:MyCTFWriteUps    文件:FingerprintManagerCompatApi23.java   
private static android.hardware.fingerprint.FingerprintManager.CryptoObject wrapCryptoObject(CryptoObject cryptoobject)
{
    if (cryptoobject != null)
    {
        if (cryptoobject.getCipher() != null)
        {
            return new android.hardware.fingerprint.FingerprintManager.CryptoObject(cryptoobject.getCipher());
        }
        if (cryptoobject.getSignature() != null)
        {
            return new android.hardware.fingerprint.FingerprintManager.CryptoObject(cryptoobject.getSignature());
        }
        if (cryptoobject.getMac() != null)
        {
            return new android.hardware.fingerprint.FingerprintManager.CryptoObject(cryptoobject.getMac());
        }
    }
    return null;
}
项目:EhViewer    文件:SecurityScene.java   
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context context = getContext2();
    Assert.assertNotNull(context);
    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    if (null != mSensorManager) {
        mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        if (null != mAccelerometer) {
            mShakeDetector = new ShakeDetector();
            mShakeDetector.setOnShakeListener(this);
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mFingerprintManager = context.getSystemService(FingerprintManager.class);
    }

    if (null == savedInstanceState) {
        mRetryTimes = MAX_RETRY_TIMES;
    } else {
        mRetryTimes = savedInstanceState.getInt(KEY_RETRY_TIMES);
    }
}
项目:Telegram    文件:FingerprintManagerCompatApi23.java   
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();
        }
    };
}
项目:FingerPrint-Authentication-With-React-Native-Android    文件:BiometricModule.java   
private boolean isSensorAvialable() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return ActivityCompat.checkSelfPermission(AppContext, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED &&
                AppContext.getSystemService(FingerprintManager.class).isHardwareDetected();
    } else {
        return FingerprintManagerCompat.from(AppContext).isHardwareDetected();
    }
}