SuRequestViewModel: fix await RootService on the main thread

This commit is contained in:
vvb2060 2023-07-30 01:40:22 +08:00 committed by John Wu
parent bcdcfa1104
commit 207d7fd3f6

View File

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