Source:
protected void onPermissionsGranted() { Button startTestButton = findViewById(R.id.sec_start_test_button); mBiometricManager = getSystemService(BiometricManager.class); final int result = mBiometricManager.canAuthenticate(); if (result == BiometricManager.BIOMETRIC_SUCCESS) { try { final Method canAuthenticateCrypto = BiometricManager.class.getMethod( "canAuthenticate", BiometricPrompt.CryptoObject.class); final Object canAuthenticateResult = canAuthenticateCrypto .invoke(mBiometricManager, (Cipher) null); if (!(canAuthenticateResult instanceof Integer)) { showToast("Unexpected result type"); } switch ((int) canAuthenticateResult) { case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: startTestButton.setEnabled(false); getPassButton().setEnabled(true); showToast("The device has WEAK biometrics but no STRONG biometrics. You can" + " skip the keystore integration test."); break; case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: case BiometricManager.BIOMETRIC_SUCCESS: default: showToast("canAuthenticateCrypto result: " + canAuthenticateResult + " Please proceed with the keystore integration test"); break; } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } } else if (result == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) { showToast("No biometric features, test passed."); getPassButton().setEnabled(true); } else if (result == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE) { showToast("Biometric unavailable, something is wrong with your device"); } else if (result == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) { showToast("Error: " + result + " Please ensure you have a biometric enrolled"); startTestButton.setEnabled(false); } }

Target:
protected void onPermissionsGranted() { Button startTestButton = findViewById(R.id.sec_start_test_button); mBiometricManager = getSystemService(BiometricManager.class); final int result = mBiometricManager.canAuthenticate(); if (result == BiometricManager.BIOMETRIC_SUCCESS) { try { final Method canAuthenticateCrypto = BiometricManager.class.getMethod( "canAuthenticate", BiometricPrompt.CryptoObject.class); final Object canAuthenticateResult = canAuthenticateCrypto .invoke(mBiometricManager, (Cipher) null); if (canAuthenticateResult instanceof Integer) { switch ((int) canAuthenticateResult) { case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: startTestButton.setEnabled(false); getPassButton().setEnabled(true); showToast("The device has WEAK biometrics but no STRONG biometrics." + " You can skip the keystore integration test."); break; case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: case BiometricManager.BIOMETRIC_SUCCESS: default: showToast("canAuthenticateCrypto result: " + canAuthenticateResult + " Please proceed with the keystore integration test"); break; } } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } } else if (result == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) { showToast("No biometric features, test passed."); getPassButton().setEnabled(true); } else if (result == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE) { showToast("Biometric unavailable, something is wrong with your device"); } else if (result == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) { showToast("Error: " + result + " Please ensure you have a biometric enrolled"); startTestButton.setEnabled(false); } }