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()