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 <me@msfjarvis.dev>
This commit is contained in:
parent
45a179580d
commit
dd0ff8fe60
@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
package com.wireguard.android.util
|
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.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -17,7 +13,6 @@ import androidx.biometric.BiometricConstants
|
|||||||
import androidx.biometric.BiometricManager
|
import androidx.biometric.BiometricManager
|
||||||
import androidx.biometric.BiometricManager.Authenticators
|
import androidx.biometric.BiometricManager.Authenticators
|
||||||
import androidx.biometric.BiometricPrompt
|
import androidx.biometric.BiometricPrompt
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import com.wireguard.android.R
|
import com.wireguard.android.R
|
||||||
|
|
||||||
@ -35,20 +30,6 @@ object BiometricAuthenticator {
|
|||||||
object Cancelled : Result()
|
object Cancelled : Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("PrivateApi")
|
|
||||||
private fun isPinEnabled(context: Context): Boolean {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
|
||||||
return context.getSystemService<KeyguardManager>()!!.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(
|
fun authenticate(
|
||||||
@StringRes dialogTitleRes: Int,
|
@StringRes dialogTitleRes: Int,
|
||||||
fragment: Fragment,
|
fragment: Fragment,
|
||||||
@ -86,7 +67,7 @@ object BiometricAuthenticator {
|
|||||||
.setTitle(fragment.getString(dialogTitleRes))
|
.setTitle(fragment.getString(dialogTitleRes))
|
||||||
.setAllowedAuthenticators(allowedAuthenticators)
|
.setAllowedAuthenticators(allowedAuthenticators)
|
||||||
.build()
|
.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)
|
biometricPrompt.authenticate(promptInfo)
|
||||||
} else {
|
} else {
|
||||||
callback(Result.HardwareUnavailableOrDisabled)
|
callback(Result.HardwareUnavailableOrDisabled)
|
||||||
|
Loading…
Reference in New Issue
Block a user