pull/2648/merge
Patrick F. 2 days ago committed by GitHub
commit 0ef8fdc444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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.

@ -38,15 +38,12 @@ class BiometricActivity : AppCompatActivity() {
var title = intent.getStringExtra(BiometricPlugin.TITLE) var title = intent.getStringExtra(BiometricPlugin.TITLE)
val subtitle = intent.getStringExtra(BiometricPlugin.SUBTITLE) val subtitle = intent.getStringExtra(BiometricPlugin.SUBTITLE)
val description = intent.getStringExtra(BiometricPlugin.REASON) 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 // Android docs say we should check if the device is secure before enabling device credential fallback
val manager = getSystemService( val manager = getSystemService(
Context.KEYGUARD_SERVICE Context.KEYGUARD_SERVICE
) as KeyguardManager ) as KeyguardManager
if (manager.isDeviceSecure) { val allowDeviceCredential = allowDeviceCredentialArg && manager.isDeviceSecure;
allowDeviceCredential =
intent.getBooleanExtra(BiometricPlugin.DEVICE_CREDENTIAL, false)
}
if (title.isNullOrEmpty()) { if (title.isNullOrEmpty()) {
title = "Authenticate" title = "Authenticate"
@ -73,6 +70,7 @@ class BiometricActivity : AppCompatActivity() {
if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText
) )
} }
builder.setConfirmationRequired( builder.setConfirmationRequired(
intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true) intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true)
) )
@ -85,6 +83,13 @@ class BiometricActivity : AppCompatActivity() {
errorCode: Int, errorCode: Int,
errorMessage: CharSequence 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) super.onAuthenticationError(errorCode, errorMessage)
finishActivity( finishActivity(
BiometryResultType.ERROR, BiometryResultType.ERROR,
@ -122,8 +127,4 @@ class BiometricActivity : AppCompatActivity() {
setResult(Activity.RESULT_OK, intent) setResult(Activity.RESULT_OK, intent)
finish() finish()
} }
companion object {
var allowDeviceCredential = false
}
} }

@ -73,7 +73,7 @@ class BiometricPlugin(private val activity: Activity): Plugin(activity) {
biometryErrorCodeMap[BiometricPrompt.ERROR_LOCKOUT_PERMANENT] = "biometryLockout" biometryErrorCodeMap[BiometricPrompt.ERROR_LOCKOUT_PERMANENT] = "biometryLockout"
biometryErrorCodeMap[BiometricPrompt.ERROR_NEGATIVE_BUTTON] = "userCancel" biometryErrorCodeMap[BiometricPrompt.ERROR_NEGATIVE_BUTTON] = "userCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_NO_BIOMETRICS] = "biometryNotEnrolled" 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_NO_SPACE] = "systemCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_TIMEOUT] = "systemCancel" biometryErrorCodeMap[BiometricPrompt.ERROR_TIMEOUT] = "systemCancel"
biometryErrorCodeMap[BiometricPrompt.ERROR_UNABLE_TO_PROCESS] = "systemCancel" biometryErrorCodeMap[BiometricPrompt.ERROR_UNABLE_TO_PROCESS] = "systemCancel"

Loading…
Cancel
Save