diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/Dialog.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/Dialog.kt index 472d0b796..3f90d643b 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/Dialog.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/component/Dialog.kt @@ -65,7 +65,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withContext import timber.log.Timber -import java.io.IOException +import kotlin.coroutines.cancellation.CancellationException import kotlin.coroutines.resume sealed interface ConfirmResult { @@ -642,7 +642,10 @@ fun MarkdownTextAsync( LaunchedEffect(Unit) { try { mdText = withContext(Dispatchers.IO) { getMarkdownText() } - } catch (e: IOException) { + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + // The text can come from a URL provided by a module, which can be malformed Timber.e(e) error = true } diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt index ea42ceb57..80a0e993c 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleScreen.kt @@ -253,7 +253,8 @@ fun ModuleScreen( ) { items( items = uiState.modules, - key = { it.module.id }, + // Module ids come from module.prop and can be duplicated, directory names can't + key = { it.module.base.name }, contentType = { "ModuleCard" } ) { item -> val isLast = item == uiState.modules.lastOrNull() @@ -285,7 +286,7 @@ private fun ModuleCard( val infoAlpha = if (!item.isRemoved && item.isEnabled && !item.showNotice) 1f else 0.5f val strikeThrough = if (item.isRemoved) TextDecoration.LineThrough else TextDecoration.None val colorScheme = MaterialTheme.colorScheme - var expanded by rememberSaveable(item.module.id) { mutableStateOf(false) } + var expanded by rememberSaveable(item.module.base.name) { mutableStateOf(false) } val hasDescription = item.module.description.isNotBlank() Card( diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt index c34c1d17b..705ed572a 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ModuleViewModel.kt @@ -127,7 +127,7 @@ class ModuleViewModel : AsyncLoadViewModel() { _uiState.update { state -> state.copy( modules = state.modules.map { - if (it.module.id == item.module.id) it.copy(isEnabled = newEnabled) else it + if (it.module.base.name == item.module.base.name) it.copy(isEnabled = newEnabled) else it } ) } @@ -139,7 +139,7 @@ class ModuleViewModel : AsyncLoadViewModel() { _uiState.update { state -> state.copy( modules = state.modules.map { - if (it.module.id == item.module.id) it.copy(isRemoved = newRemoved) else it + if (it.module.base.name == item.module.base.name) it.copy(isRemoved = newRemoved) else it } ) } diff --git a/app/core/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt b/app/core/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt index a8dd43abd..baa49ee9f 100644 --- a/app/core/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt +++ b/app/core/src/main/java/com/topjohnwu/magisk/core/model/module/LocalModule.kt @@ -1,6 +1,5 @@ package com.topjohnwu.magisk.core.model.module -import com.squareup.moshi.JsonDataException import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.di.ServiceLocator import com.topjohnwu.magisk.core.utils.RootUtils @@ -9,8 +8,8 @@ import com.topjohnwu.superuser.nio.ExtendedFile import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber -import java.io.IOException import java.util.Locale +import kotlin.coroutines.cancellation.CancellationException data class LocalModule( val base: ExtendedFile, @@ -110,9 +109,11 @@ data class LocalModule( updateInfo = OnlineModule(this, json) outdated = json.versionCode > versionCode return true - } catch (e: IOException) { - Timber.w(e) - } catch (e: JsonDataException) { + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + // The URL and the JSON come from the module, so anything can be wrong with them, + // e.g. a malformed URL makes Retrofit throw IllegalArgumentException Timber.w(e) }