Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-bio-fallback-error-android.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"biometric": patch:bug
"biometric-js": patch:bug
---

Fix biometric plugin reporting an inconsistent and incorrect error on Android when no device passcode was set.
19 changes: 10 additions & 9 deletions plugins/biometric/android/src/main/java/BiometricActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ class BiometricActivity : AppCompatActivity() {
var title = intent.getStringExtra(BiometricPlugin.TITLE)
val subtitle = intent.getStringExtra(BiometricPlugin.SUBTITLE)
val description = intent.getStringExtra(BiometricPlugin.REASON)
allowDeviceCredential = false
val allowDeviceCredentialArg = intent.getBooleanExtra(BiometricPlugin.DEVICE_CREDENTIAL, false)
// Android docs say we should check if the device is secure before enabling device credential fallback
val manager = getSystemService(
Context.KEYGUARD_SERVICE
) as KeyguardManager
if (manager.isDeviceSecure) {
allowDeviceCredential =
intent.getBooleanExtra(BiometricPlugin.DEVICE_CREDENTIAL, false)
}
val allowDeviceCredential = allowDeviceCredentialArg && manager.isDeviceSecure;

if (title.isNullOrEmpty()) {
title = "Authenticate"
Expand All @@ -73,6 +70,7 @@ class BiometricActivity : AppCompatActivity() {
if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText
)
}

builder.setConfirmationRequired(
intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true)
)
Expand All @@ -85,6 +83,13 @@ class BiometricActivity : AppCompatActivity() {
errorCode: Int,
errorMessage: CharSequence
) {
var errorCode = errorCode
var errorMessage = errorMessage
// override error to properly report no device credential if needed
if (allowDeviceCredentialArg && errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) {
errorCode = BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL
errorMessage = "No device credential set"
}
super.onAuthenticationError(errorCode, errorMessage)
finishActivity(
BiometryResultType.ERROR,
Expand Down Expand Up @@ -122,8 +127,4 @@ class BiometricActivity : AppCompatActivity() {
setResult(Activity.RESULT_OK, intent)
finish()
}

companion object {
var allowDeviceCredential = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BiometricPlugin(private val activity: Activity): Plugin(activity) {
biometryErrorCodeMap[BiometricPrompt.ERROR_LOCKOUT_PERMANENT] = "biometryLockout"
biometryErrorCodeMap[BiometricPrompt.ERROR_NEGATIVE_BUTTON] = "userCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_NO_BIOMETRICS] = "biometryNotEnrolled"
biometryErrorCodeMap[BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL] = "noDeviceCredential"
biometryErrorCodeMap[BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL] = "passcodeNotSet"
biometryErrorCodeMap[BiometricPrompt.ERROR_NO_SPACE] = "systemCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_TIMEOUT] = "systemCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_UNABLE_TO_PROCESS] = "systemCancel"
Expand Down
Loading