BiometricAuthenticator: fix multiple regressions from AndroidX update (#1045)
Fixes: 80e43e5675
("Update dependencies (#1039)")
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
70aa41ae61
commit
2414c48d9f
1 changed files with 10 additions and 7 deletions
|
@ -9,6 +9,7 @@ import android.os.Handler
|
|||
import androidx.annotation.StringRes
|
||||
import androidx.biometric.BiometricConstants
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricManager.Authenticators
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
|
@ -60,13 +61,15 @@ object BiometricAuthenticator {
|
|||
callback(Result.Success(result.cryptoObject))
|
||||
}
|
||||
}
|
||||
val biometricPrompt = BiometricPrompt(activity, { handler.post(it) }, authCallback)
|
||||
val validAuthenticators = Authenticators.DEVICE_CREDENTIAL or Authenticators.BIOMETRIC_STRONG
|
||||
val canAuth = BiometricManager.from(activity).canAuthenticate(validAuthenticators) == BiometricManager.BIOMETRIC_SUCCESS
|
||||
val deviceHasKeyguard = activity.getSystemService<KeyguardManager>()?.isDeviceSecure == true
|
||||
if (canAuth || deviceHasKeyguard) {
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(activity.getString(dialogTitleRes))
|
||||
.setAllowedAuthenticators(validAuthenticators)
|
||||
.build()
|
||||
if (BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
||||
== BiometricManager.BIOMETRIC_SUCCESS || activity.getSystemService<KeyguardManager>()?.isDeviceSecure == true) {
|
||||
biometricPrompt.authenticate(promptInfo)
|
||||
BiometricPrompt(activity, { handler.post(it) }, authCallback).authenticate(promptInfo)
|
||||
} else {
|
||||
callback(Result.HardwareUnavailableOrDisabled)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue