mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 14:25:28 +00:00
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:
@@ -9,6 +9,7 @@ import android.os.Handler
|
|||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.biometric.BiometricConstants
|
import androidx.biometric.BiometricConstants
|
||||||
import androidx.biometric.BiometricManager
|
import androidx.biometric.BiometricManager
|
||||||
|
import androidx.biometric.BiometricManager.Authenticators
|
||||||
import androidx.biometric.BiometricPrompt
|
import androidx.biometric.BiometricPrompt
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
@@ -60,13 +61,15 @@ object BiometricAuthenticator {
|
|||||||
callback(Result.Success(result.cryptoObject))
|
callback(Result.Success(result.cryptoObject))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val biometricPrompt = BiometricPrompt(activity, { handler.post(it) }, authCallback)
|
val validAuthenticators = Authenticators.DEVICE_CREDENTIAL or Authenticators.BIOMETRIC_STRONG
|
||||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
val canAuth = BiometricManager.from(activity).canAuthenticate(validAuthenticators) == BiometricManager.BIOMETRIC_SUCCESS
|
||||||
.setTitle(activity.getString(dialogTitleRes))
|
val deviceHasKeyguard = activity.getSystemService<KeyguardManager>()?.isDeviceSecure == true
|
||||||
.build()
|
if (canAuth || deviceHasKeyguard) {
|
||||||
if (BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||||
== BiometricManager.BIOMETRIC_SUCCESS || activity.getSystemService<KeyguardManager>()?.isDeviceSecure == true) {
|
.setTitle(activity.getString(dialogTitleRes))
|
||||||
biometricPrompt.authenticate(promptInfo)
|
.setAllowedAuthenticators(validAuthenticators)
|
||||||
|
.build()
|
||||||
|
BiometricPrompt(activity, { handler.post(it) }, authCallback).authenticate(promptInfo)
|
||||||
} else {
|
} else {
|
||||||
callback(Result.HardwareUnavailableOrDisabled)
|
callback(Result.HardwareUnavailableOrDisabled)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user