more tweaking
This commit is contained in:
parent
7af7220301
commit
466084db71
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps.utils.protection
|
||||
|
||||
import androidx.biometric.BiometricConstants
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import info.nightscout.androidaps.MainApp
|
||||
|
@ -8,17 +9,30 @@ import info.nightscout.androidaps.utils.ToastUtils
|
|||
import java.util.concurrent.Executors
|
||||
|
||||
object BiometricCheck {
|
||||
fun biometricPrompt(activity: FragmentActivity, ok: Runnable?, cancel: Runnable? = null, fail: Runnable? = null) {
|
||||
fun biometricPrompt(activity: FragmentActivity, title: Int, ok: Runnable?, cancel: Runnable? = null, fail: Runnable? = null) {
|
||||
val executor = Executors.newSingleThreadExecutor()
|
||||
|
||||
val biometricPrompt = BiometricPrompt(activity, executor, object : BiometricPrompt.AuthenticationCallback() {
|
||||
|
||||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
||||
super.onAuthenticationError(errorCode, errString)
|
||||
if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) cancel?.run()
|
||||
else {
|
||||
// Called when an unrecoverable error has been encountered and the operation is complete.
|
||||
when (errorCode) {
|
||||
BiometricConstants.ERROR_UNABLE_TO_PROCESS,
|
||||
BiometricConstants.ERROR_TIMEOUT,
|
||||
BiometricConstants.ERROR_CANCELED,
|
||||
BiometricConstants.ERROR_LOCKOUT,
|
||||
BiometricConstants.ERROR_VENDOR,
|
||||
BiometricConstants.ERROR_LOCKOUT_PERMANENT,
|
||||
BiometricConstants.ERROR_USER_CANCELED -> {
|
||||
ToastUtils.showToastInUiThread(activity.baseContext, errString.toString())
|
||||
fail?.run()
|
||||
}
|
||||
BiometricConstants.ERROR_NEGATIVE_BUTTON ->
|
||||
cancel?.run()
|
||||
BiometricConstants.ERROR_NO_SPACE,
|
||||
BiometricConstants.ERROR_HW_UNAVAILABLE,
|
||||
BiometricConstants.ERROR_HW_NOT_PRESENT,
|
||||
BiometricConstants.ERROR_NO_DEVICE_CREDENTIAL,
|
||||
BiometricConstants.ERROR_NO_BIOMETRICS ->
|
||||
// call ok, because it's not possible to bypass it when biometrics fail
|
||||
ok?.run()
|
||||
}
|
||||
|
@ -38,8 +52,7 @@ object BiometricCheck {
|
|||
})
|
||||
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(MainApp.gs(R.string.biometric_title))
|
||||
.setSubtitle("Set the subtitle to display.")
|
||||
.setTitle(MainApp.gs(title))
|
||||
.setDescription(MainApp.gs(R.string.biometric_title))
|
||||
.setNegativeButtonText(MainApp.gs(R.string.cancel))
|
||||
.build()
|
||||
|
|
|
@ -47,7 +47,7 @@ object ProtectionCheck {
|
|||
ProtectionType.NONE ->
|
||||
ok?.run()
|
||||
ProtectionType.BIOMETRIC ->
|
||||
BiometricCheck.biometricPrompt(activity, ok, cancel, fail)
|
||||
BiometricCheck.biometricPrompt(activity, titleResourceIDs[protection.ordinal], ok, cancel, fail)
|
||||
ProtectionType.PASSWORD ->
|
||||
PasswordCheck.queryPassword(activity, titleResourceIDs[protection.ordinal], passwordsResourceIDs[protection.ordinal], ok, cancel, fail)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue