|
|
@ -38,38 +38,39 @@ 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 = 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
|
|
|
|
// 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 (allowDeviceCredential && manager.isDeviceSecure) {
|
|
|
|
val allowDeviceCredential = allowDeviceCredentialArg && manager.isDeviceSecure;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
|
|
|
|
var authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK
|
|
|
|
if (title.isNullOrEmpty()) {
|
|
|
|
if (allowDeviceCredential) {
|
|
|
|
title = "Authenticate"
|
|
|
|
authenticators = authenticators or BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setAllowedAuthenticators(authenticators)
|
|
|
|
builder.setTitle(title).setSubtitle(subtitle).setDescription(description)
|
|
|
|
} else {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
var authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK
|
|
|
|
builder.setDeviceCredentialAllowed(allowDeviceCredential)
|
|
|
|
if (allowDeviceCredential) {
|
|
|
|
|
|
|
|
authenticators = authenticators or BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setAllowedAuthenticators(authenticators)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// From the Android docs:
|
|
|
|
@Suppress("DEPRECATION")
|
|
|
|
// You can't call setNegativeButtonText() and setAllowedAuthenticators(... or DEVICE_CREDENTIAL)
|
|
|
|
builder.setDeviceCredentialAllowed(allowDeviceCredential)
|
|
|
|
// 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,8 +86,7 @@ class BiometricActivity : AppCompatActivity() {
|
|
|
|
var errorCode = errorCode
|
|
|
|
var errorCode = errorCode
|
|
|
|
var errorMessage = errorMessage
|
|
|
|
var errorMessage = errorMessage
|
|
|
|
// override error to properly report no device credential if needed
|
|
|
|
// override error to properly report no device credential if needed
|
|
|
|
if (allowDeviceCredential
|
|
|
|
if (allowDeviceCredentialArg && errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) {
|
|
|
|
&& errorCode == BiometricPrompt.ERROR_NO_BIOMETRICS) {
|
|
|
|
|
|
|
|
errorCode = BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL
|
|
|
|
errorCode = BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL
|
|
|
|
errorMessage = "No device credential set"
|
|
|
|
errorMessage = "No device credential set"
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -127,8 +127,4 @@ class BiometricActivity : AppCompatActivity() {
|
|
|
|
setResult(Activity.RESULT_OK, intent)
|
|
|
|
setResult(Activity.RESULT_OK, intent)
|
|
|
|
finish()
|
|
|
|
finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
var allowDeviceCredential = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|