From dd0ff8fe60daea6ae3666b5fe655c37303b77626 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 13 Sep 2020 18:34:17 +0530 Subject: ui: remove hacky manual check for keyguard Setting the correct value for the allowedAuthenticators field lets the library correctly detect this by itself as verified on an API 21 emulator Signed-off-by: Harsh Shandilya --- .../android/util/BiometricAuthenticator.kt | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'ui') 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 ade7f435..d5de319f 100644 --- a/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt +++ b/ui/src/main/java/com/wireguard/android/util/BiometricAuthenticator.kt @@ -5,10 +5,6 @@ package com.wireguard.android.util -import android.annotation.SuppressLint -import android.app.KeyguardManager -import android.content.Context -import android.os.Build import android.os.Handler import android.os.Looper import android.util.Log @@ -17,7 +13,6 @@ 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 import com.wireguard.android.R @@ -35,20 +30,6 @@ object BiometricAuthenticator { object Cancelled : Result() } - @SuppressLint("PrivateApi") - private fun isPinEnabled(context: Context): Boolean { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - return context.getSystemService()!!.isDeviceSecure - return try { - val lockUtilsClass = Class.forName("com.android.internal.widget.LockPatternUtils") - val lockUtils = lockUtilsClass.getConstructor(Context::class.java).newInstance(context) - val method = lockUtilsClass.getMethod("isLockScreenDisabled") - !(method.invoke(lockUtils) as Boolean) - } catch (e: Exception) { - false - } - } - fun authenticate( @StringRes dialogTitleRes: Int, fragment: Fragment, @@ -86,7 +67,7 @@ object BiometricAuthenticator { .setTitle(fragment.getString(dialogTitleRes)) .setAllowedAuthenticators(allowedAuthenticators) .build() - if (BiometricManager.from(fragment.requireContext()).canAuthenticate(allowedAuthenticators) == BiometricManager.BIOMETRIC_SUCCESS || isPinEnabled(fragment.requireContext())) { + if (BiometricManager.from(fragment.requireContext()).canAuthenticate(allowedAuthenticators) == BiometricManager.BIOMETRIC_SUCCESS) { biometricPrompt.authenticate(promptInfo) } else { callback(Result.HardwareUnavailableOrDisabled) -- cgit v1.2.3