From b510dc51acdb9f7dd7ec41dabe62cd637bbd16c5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 11 Sep 2020 03:09:01 -0700 Subject: [PATCH] Fix su request auto response --- .../magisk/core/su/SuRequestHandler.kt | 16 +-- .../{BiometricDialog.kt => BiometricEvent.kt} | 2 +- .../magisk/ui/settings/SettingsViewModel.kt | 4 +- .../magisk/ui/superuser/SuperuserViewModel.kt | 6 +- .../magisk/ui/surequest/SuRequestActivity.kt | 2 +- .../magisk/ui/surequest/SuRequestViewModel.kt | 121 +++++++++--------- 6 files changed, 74 insertions(+), 77 deletions(-) rename app/src/main/java/com/topjohnwu/magisk/events/dialog/{BiometricDialog.kt => BiometricEvent.kt} (97%) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt index aefbe2895..cc5123840 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/su/SuRequestHandler.kt @@ -18,17 +18,16 @@ import java.io.* import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit.SECONDS -abstract class SuRequestHandler( - private val packageManager: PackageManager, +class SuRequestHandler( + private val pm: PackageManager, private val policyDB: PolicyDao ) : Closeable { private lateinit var output: DataOutputStream - protected lateinit var policy: SuPolicy + lateinit var policy: SuPolicy private set - abstract fun onStart() - + // Return true to indicate undetermined policy, require user interaction suspend fun start(intent: Intent): Boolean { if (!init(intent)) return false @@ -40,15 +39,14 @@ abstract class SuRequestHandler( when (Config.suAutoReponse) { Config.Value.SU_AUTO_DENY -> { respond(SuPolicy.DENY, 0) - return true + return false } Config.Value.SU_AUTO_ALLOW -> { respond(SuPolicy.ALLOW, 0) - return true + return false } } - onStart() return true } @@ -82,7 +80,7 @@ abstract class SuRequestHandler( val map = async { input.readRequest() }.timedAwait() ?: throw SuRequestError() uid = map["uid"]?.toIntOrNull() ?: throw SuRequestError() } - policy = uid.toPolicy(packageManager) + policy = uid.toPolicy(pm) true } catch (e: Exception) { when (e) { diff --git a/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt b/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricEvent.kt similarity index 97% rename from app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt rename to app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricEvent.kt index 6a8302d68..63a4f247d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricDialog.kt +++ b/app/src/main/java/com/topjohnwu/magisk/events/dialog/BiometricEvent.kt @@ -5,7 +5,7 @@ import com.topjohnwu.magisk.arch.BaseUIActivity import com.topjohnwu.magisk.arch.ViewEvent import com.topjohnwu.magisk.core.utils.BiometricHelper -class BiometricDialog( +class BiometricEvent( builder: Builder.() -> Unit ) : ViewEvent(), ActivityExecutor { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt index eead2a620..3ec02f8c3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt @@ -23,7 +23,7 @@ import com.topjohnwu.magisk.core.tasks.PatchAPK import com.topjohnwu.magisk.data.database.RepoDao import com.topjohnwu.magisk.events.AddHomeIconEvent import com.topjohnwu.magisk.events.RecreateEvent -import com.topjohnwu.magisk.events.dialog.BiometricDialog +import com.topjohnwu.magisk.events.dialog.BiometricEvent import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.superuser.Shell import kotlinx.coroutines.launch @@ -125,7 +125,7 @@ class SettingsViewModel( } private fun authenticate(callback: () -> Unit) { - BiometricDialog { + BiometricEvent { // allow the change on success onSuccess { callback() } }.publish() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt index 7d55de1d3..4ac7cafc2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt @@ -16,7 +16,7 @@ import com.topjohnwu.magisk.core.utils.BiometricHelper import com.topjohnwu.magisk.core.utils.currentLocale import com.topjohnwu.magisk.databinding.ComparableRvItem import com.topjohnwu.magisk.events.SnackbarEvent -import com.topjohnwu.magisk.events.dialog.BiometricDialog +import com.topjohnwu.magisk.events.dialog.BiometricEvent import com.topjohnwu.magisk.events.dialog.SuperuserRevokeDialog import com.topjohnwu.magisk.view.TappableHeadlineItem import com.topjohnwu.magisk.view.TextItem @@ -86,7 +86,7 @@ class SuperuserViewModel( } if (BiometricHelper.isEnabled) { - BiometricDialog { + BiometricEvent { onSuccess { updateState() } }.publish() } else { @@ -130,7 +130,7 @@ class SuperuserViewModel( } if (BiometricHelper.isEnabled) { - BiometricDialog { + BiometricEvent { onSuccess { updateState() } }.publish() } else { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt index a28572013..d5f49cb69 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestActivity.kt @@ -29,7 +29,7 @@ open class SuRequestActivity : BaseUIActivity