Added biometric dialog instead of fingerprint one

This commit is contained in:
Viktor De Pasquale 2019-11-12 18:01:24 +01:00
parent c5f2f63458
commit 54930024f5
4 changed files with 67 additions and 4 deletions

View File

@ -130,6 +130,7 @@ dependencies {
implementation 'androidx.transition:transition:1.2.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.biometric:biometric:1.0.0'
implementation 'com.google.android.material:material:1.1.0-beta01'
implementation 'com.karumi:dexter:6.0.0'
}

View File

@ -0,0 +1,54 @@
package com.topjohnwu.magisk.model.events.dialog
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricPrompt
import com.topjohnwu.magisk.model.events.ActivityExecutor
import com.topjohnwu.magisk.model.events.ViewEvent
class BiometricDialog(
builder: Builder.() -> Unit
) : ViewEvent(), ActivityExecutor {
private var listenerOnFailure: GenericDialogListener = {}
private var listenerOnSuccess: GenericDialogListener = {}
init {
builder(Builder())
}
override fun invoke(activity: AppCompatActivity) {
val handler = Handler()
val prompt = BiometricPrompt.PromptInfo.Builder()
.setNegativeButtonText(activity.getString(android.R.string.cancel))
.build()
val callback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
listenerOnFailure()
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
listenerOnSuccess()
}
override fun onAuthenticationFailed() {
listenerOnFailure()
}
}
BiometricPrompt(activity, { handler.post(it) }, callback)
.authenticate(prompt/*launch with no crypto for now*/)
}
inner class Builder internal constructor() {
fun onFailure(listener: GenericDialogListener) {
listenerOnFailure = listener
}
fun onSuccess(listener: GenericDialogListener) {
listenerOnSuccess = listener
}
}
}

View File

@ -6,7 +6,15 @@ import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.utils.FingerprintHelper
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.view.MagiskDialog
import timber.log.Timber
@Deprecated(
"Use Biometrics instead",
ReplaceWith(
"BiometricDialog",
imports = ["com.topjohnwu.magisk.model.events.dialog.BiometricDialog"]
)
)
class FingerprintDialog(
builder: Builder.() -> Unit
) : DialogEvent() {
@ -15,7 +23,7 @@ class FingerprintDialog(
private var helper: Helper? = null
get() {
if (field == null) {
runCatching { field = Helper() }
runCatching { field = Helper() }.onFailure { Timber.e(it) }
}
return field
}

View File

@ -13,7 +13,7 @@ import com.topjohnwu.magisk.model.entity.MagiskPolicy
import com.topjohnwu.magisk.model.entity.recycler.PolicyItem
import com.topjohnwu.magisk.model.events.PolicyUpdateEvent
import com.topjohnwu.magisk.model.events.SnackbarEvent
import com.topjohnwu.magisk.model.events.dialog.FingerprintDialog
import com.topjohnwu.magisk.model.events.dialog.BiometricDialog
import com.topjohnwu.magisk.model.events.dialog.SuperuserRevokeDialog
import com.topjohnwu.magisk.model.navigation.Navigation
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
@ -72,7 +72,7 @@ class SuperuserViewModel(
.add()
if (FingerprintHelper.useFingerprint()) {
FingerprintDialog {
BiometricDialog {
onSuccess { updateState() }
}.publish()
} else {
@ -116,7 +116,7 @@ class SuperuserViewModel(
}
if (FingerprintHelper.useFingerprint()) {
FingerprintDialog {
BiometricDialog {
onSuccess { updateState() }
onFailure { item.isEnabled.toggle() }
}.publish()