Fix incorrect error being reported in certain cases with fallback allowed

pull/2648/head
pjf-dev 3 months ago
parent dac4d53724
commit 78a3bea4f2
No known key found for this signature in database
GPG Key ID: 98096A74F5021841

@ -38,41 +38,38 @@ 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 allowDeviceCredential = 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) { if (allowDeviceCredential && manager.isDeviceSecure) {
allowDeviceCredential = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
intent.getBooleanExtra(BiometricPlugin.DEVICE_CREDENTIAL, false) var authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK
} if (allowDeviceCredential) {
authenticators = authenticators or BiometricManager.Authenticators.DEVICE_CREDENTIAL
if (title.isNullOrEmpty()) { }
title = "Authenticate" builder.setAllowedAuthenticators(authenticators)
} } else {
@Suppress("DEPRECATION")
builder.setTitle(title).setSubtitle(subtitle).setDescription(description) builder.setDeviceCredentialAllowed(allowDeviceCredential)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
var authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK
if (allowDeviceCredential) {
authenticators = authenticators or BiometricManager.Authenticators.DEVICE_CREDENTIAL
} }
builder.setAllowedAuthenticators(authenticators)
} else { } else {
@Suppress("DEPRECATION") // From the Android docs:
builder.setDeviceCredentialAllowed(allowDeviceCredential) // You can't call setNegativeButtonText() and setAllowedAuthenticators(... or DEVICE_CREDENTIAL)
} // at the same time on a BiometricPrompt.PromptInfo.Builder instance.
// From the Android docs:
// You can't call setNegativeButtonText() and setAllowedAuthenticators(... or DEVICE_CREDENTIAL)
// at the same time on a BiometricPrompt.PromptInfo.Builder instance.
if (!allowDeviceCredential) {
val negativeButtonText = intent.getStringExtra(BiometricPlugin.CANCEL_TITLE) val negativeButtonText = intent.getStringExtra(BiometricPlugin.CANCEL_TITLE)
builder.setNegativeButtonText( builder.setNegativeButtonText(
if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText
) )
} }
if (title.isNullOrEmpty()) {
title = "Authenticate"
}
builder.setTitle(title).setSubtitle(subtitle).setDescription(description)
builder.setConfirmationRequired( builder.setConfirmationRequired(
intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true) intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true)
) )
@ -85,6 +82,14 @@ 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 (allowDeviceCredential
&& 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,

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