mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-25 18:57:23 +00:00
Added biometric dialog instead of fingerprint one
This commit is contained in:
parent
c5f2f63458
commit
54930024f5
@ -130,6 +130,7 @@ dependencies {
|
|||||||
implementation 'androidx.transition:transition:1.2.0'
|
implementation 'androidx.transition:transition:1.2.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'androidx.core:core-ktx:1.1.0'
|
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.google.android.material:material:1.1.0-beta01'
|
||||||
implementation 'com.karumi:dexter:6.0.0'
|
implementation 'com.karumi:dexter:6.0.0'
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,15 @@ import com.topjohnwu.magisk.R
|
|||||||
import com.topjohnwu.magisk.utils.FingerprintHelper
|
import com.topjohnwu.magisk.utils.FingerprintHelper
|
||||||
import com.topjohnwu.magisk.utils.Utils
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
import com.topjohnwu.magisk.view.MagiskDialog
|
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(
|
class FingerprintDialog(
|
||||||
builder: Builder.() -> Unit
|
builder: Builder.() -> Unit
|
||||||
) : DialogEvent() {
|
) : DialogEvent() {
|
||||||
@ -15,7 +23,7 @@ class FingerprintDialog(
|
|||||||
private var helper: Helper? = null
|
private var helper: Helper? = null
|
||||||
get() {
|
get() {
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
runCatching { field = Helper() }
|
runCatching { field = Helper() }.onFailure { Timber.e(it) }
|
||||||
}
|
}
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import com.topjohnwu.magisk.model.entity.MagiskPolicy
|
|||||||
import com.topjohnwu.magisk.model.entity.recycler.PolicyItem
|
import com.topjohnwu.magisk.model.entity.recycler.PolicyItem
|
||||||
import com.topjohnwu.magisk.model.events.PolicyUpdateEvent
|
import com.topjohnwu.magisk.model.events.PolicyUpdateEvent
|
||||||
import com.topjohnwu.magisk.model.events.SnackbarEvent
|
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.events.dialog.SuperuserRevokeDialog
|
||||||
import com.topjohnwu.magisk.model.navigation.Navigation
|
import com.topjohnwu.magisk.model.navigation.Navigation
|
||||||
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
|
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
|
||||||
@ -72,7 +72,7 @@ class SuperuserViewModel(
|
|||||||
.add()
|
.add()
|
||||||
|
|
||||||
if (FingerprintHelper.useFingerprint()) {
|
if (FingerprintHelper.useFingerprint()) {
|
||||||
FingerprintDialog {
|
BiometricDialog {
|
||||||
onSuccess { updateState() }
|
onSuccess { updateState() }
|
||||||
}.publish()
|
}.publish()
|
||||||
} else {
|
} else {
|
||||||
@ -116,7 +116,7 @@ class SuperuserViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FingerprintHelper.useFingerprint()) {
|
if (FingerprintHelper.useFingerprint()) {
|
||||||
FingerprintDialog {
|
BiometricDialog {
|
||||||
onSuccess { updateState() }
|
onSuccess { updateState() }
|
||||||
onFailure { item.isEnabled.toggle() }
|
onFailure { item.isEnabled.toggle() }
|
||||||
}.publish()
|
}.publish()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user