diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt b/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt index e1ad91b6..ade7f435 100644 --- a/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt +++ b/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt @@ -15,6 +15,7 @@ import android.util.Log 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.Fragment @@ -23,6 +24,9 @@ import com.wireguard.android.R object BiometricAuthenticator { private const val TAG = "WireGuard/BiometricAuthenticator" + // Not all devices support strong biometric auth so we're allowing both device credentials as + // well as weak biometrics. + private const val allowedAuthenticators = Authenticators.DEVICE_CREDENTIAL or Authenticators.BIOMETRIC_WEAK sealed class Result { data class Success(val cryptoObject: BiometricPrompt.CryptoObject?) : Result() @@ -80,9 +84,9 @@ object BiometricAuthenticator { val biometricPrompt = BiometricPrompt(fragment, { Handler(Looper.getMainLooper()).post(it) }, authCallback) val promptInfo = BiometricPrompt.PromptInfo.Builder() .setTitle(fragment.getString(dialogTitleRes)) - .setDeviceCredentialAllowed(true) + .setAllowedAuthenticators(allowedAuthenticators) .build() - if (BiometricManager.from(fragment.requireContext()).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS || isPinEnabled(fragment.requireContext())) { + if (BiometricManager.from(fragment.requireContext()).canAuthenticate(allowedAuthenticators) == BiometricManager.BIOMETRIC_SUCCESS || isPinEnabled(fragment.requireContext())) { biometricPrompt.authenticate(promptInfo) } else { callback(Result.HardwareUnavailableOrDisabled) |