From 207d7fd3f6c6c8626cd14f06b7344c295d34d44f Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Sun, 30 Jul 2023 01:40:22 +0800 Subject: [PATCH] SuRequestViewModel: fix await RootService on the main thread --- .../topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index 322dfcb31..bbcef4e96 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -34,6 +34,7 @@ import com.topjohnwu.magisk.events.BiometricEvent import com.topjohnwu.magisk.events.DieEvent import com.topjohnwu.magisk.events.ShowUIEvent import com.topjohnwu.magisk.utils.TextHolder +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.util.concurrent.TimeUnit.SECONDS @@ -71,7 +72,8 @@ class SuRequestViewModel( } private val handler = SuRequestHandler(AppContext.packageManager, policyDB) - private lateinit var timer: CountDownTimer + private val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong()) + private var timer = SuTimer(millis, 1000) private var initialized = false fun grantPressed() { @@ -97,7 +99,7 @@ class SuRequestViewModel( } fun handleRequest(intent: Intent) { - viewModelScope.launch { + viewModelScope.launch(Dispatchers.Default) { if (handler.start(intent)) showDialog() else @@ -126,8 +128,7 @@ class SuRequestViewModel( selectedItemPosition = timeoutPrefs.getInt(packageName, 0) // Set timer - val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong()) - timer = SuTimer(millis, 1000).apply { start() } + timer.start() // Actually show the UI ShowUIEvent(if (Config.suTapjack) EmptyAccessibilityDelegate else null).publish()