From 4ab0038d21d160d00784c59ac97f4095b38914cd Mon Sep 17 00:00:00 2001 From: lisonge Date: Sat, 28 Oct 2023 14:45:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20shizuku=20=E5=9C=A8=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=9C=BA=E5=9E=8B=E4=B8=8A=20ClassNotFoundException=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/li/songe/gkd/shizuku/ShizukuApi.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/li/songe/gkd/shizuku/ShizukuApi.kt b/app/src/main/java/li/songe/gkd/shizuku/ShizukuApi.kt index 723843646..2efbe0afc 100644 --- a/app/src/main/java/li/songe/gkd/shizuku/ShizukuApi.kt +++ b/app/src/main/java/li/songe/gkd/shizuku/ShizukuApi.kt @@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.stateIn import li.songe.gkd.composition.CanOnDestroy import li.songe.gkd.data.DeviceInfo @@ -92,13 +91,23 @@ fun CanOnDestroy.useSafeGetTasksFc(scope: CoroutineScope): () -> List s.enableShizuku }) { shizukuAlive, shizukuGrant, enableShizuku -> - if (enableShizuku && shizukuAlive && shizukuGrant) newActivityTaskManager() else null - }.flowOn(Dispatchers.IO).stateIn(scope, SharingStarted.Eagerly, null) + enableShizuku && shizukuAlive && shizukuGrant + }.stateIn(scope, SharingStarted.Eagerly, false) + + val activityTaskManagerFlow = + shizukuCanUsedFlow.map(scope) { if (it) newActivityTaskManager() else null } + return { - activityTaskManagerFlow.value?.safeGetTasks() + if (shizukuCanUsedFlow.value) { + // 避免直接访问方法校验 android.app.IActivityTaskManager 类型 + // 报错 java.lang.ClassNotFoundException:Didn't find class "android.app.IActivityTaskManager" on path: DexPathList + activityTaskManagerFlow.value?.safeGetTasks() + } else { + null + } } } \ No newline at end of file