From 78a444d601cde38aaaab0cc65954b3ccf8c5d125 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 30 Dec 2022 15:52:02 -0800 Subject: [PATCH] Wait for root service to bind --- .../com/topjohnwu/magisk/core/utils/RootUtils.kt | 14 +++++++++++--- .../topjohnwu/magisk/ui/module/ModuleViewModel.kt | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt index 1231ed8a6..8d43aa861 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/RootUtils.kt @@ -111,15 +111,23 @@ class RootUtils(stub: Any?) : RootService() { } fun await() { - // We cannot await on the main thread - if (Info.isRooted && !ShellUtils.onMainThread()) + if (!Info.isRooted) + return + if (!ShellUtils.onMainThread()) { acquireSharedInterruptibly(1) + } else if (state != 0) { + throw IllegalStateException("Cannot await on the main thread") + } } } companion object { var bindTask: Shell.Task? = null - var fs = FileSystemManager.getLocal() + var fs: FileSystemManager = FileSystemManager.getLocal() + get() { + Connection.await() + return field + } private set var obj: IRootUtils? = null get() { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index a9d2abd2e..9aa93ba3b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -35,7 +35,7 @@ class ModuleViewModel : AsyncLoadViewModel() { var loading = true private set(value) = set(value, field, { field = it }, BR.loading) - init { + private suspend fun init() = withContext(Dispatchers.IO) { if (Info.env.isActive && LocalModule.loaded()) { items.insertItem(InstallModule) .insertList(itemsInstalled) @@ -44,6 +44,9 @@ class ModuleViewModel : AsyncLoadViewModel() { override suspend fun doLoadWork() { loading = true + if (items.isEmpty()) { + init() + } loadInstalled() loading = false loadUpdateInfo()