Rework original solution due to overlooking authenticators logic on API >= `Build.VERSION_CODES.R`

pull/2648/head
pjf-dev 3 months ago
parent 9c3a8e7b10
commit 8b8036feab
No known key found for this signature in database
GPG Key ID: 98096A74F5021841

@ -38,13 +38,18 @@ class BiometricActivity : AppCompatActivity() {
var title = intent.getStringExtra(BiometricPlugin.TITLE)
val subtitle = intent.getStringExtra(BiometricPlugin.SUBTITLE)
val description = intent.getStringExtra(BiometricPlugin.REASON)
allowDeviceCredential = intent.getBooleanExtra(BiometricPlugin.DEVICE_CREDENTIAL, 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 (allowDeviceCredential && manager.isDeviceSecure) {
val allowDeviceCredential = allowDeviceCredentialArg && manager.isDeviceSecure;
if (title.isNullOrEmpty()) {
title = "Authenticate"
}
builder.setTitle(title).setSubtitle(subtitle).setDescription(description)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
var authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK
if (allowDeviceCredential) {
@ -55,21 +60,17 @@ class BiometricActivity : AppCompatActivity() {
@Suppress("DEPRECATION")
builder.setDeviceCredentialAllowed(allowDeviceCredential)
}
} else {
// 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)
builder.setNegativeButtonText(
if (negativeButtonText.isNullOrEmpty()) "Cancel" else negativeButtonText
)
}
if (title.isNullOrEmpty()) {
title = "Authenticate"
}
builder.setTitle(title).setSubtitle(subtitle).setDescription(description)
builder.setConfirmationRequired(
intent.getBooleanExtra(BiometricPlugin.CONFIRMATION_REQUIRED, true)
)
@ -85,8 +86,7 @@ class BiometricActivity : AppCompatActivity() {
var errorCode = errorCode
var errorMessage = errorMessage
// override error to properly report no device credential if needed
if (allowDeviceCredential
&& errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) {
if (allowDeviceCredentialArg && errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) {
errorCode = BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL
errorMessage = "No device credential set"
}
@ -127,8 +127,4 @@ class BiometricActivity : AppCompatActivity() {
setResult(Activity.RESULT_OK, intent)
finish()
}
companion object {
var allowDeviceCredential = false
}
}
Loading…
Cancel
Save