mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: don't crash on broken module metadata
Modules are third-party, but some of their metadata could crash the app: - A malformed updateJson URL (e.g. ftp://) made Retrofit throw IllegalArgumentException, which LocalModule.fetch() didn't catch, so the app exited every time the module list loaded, even offline. A malformed changelog URL did the same when opening the update dialog. - Two module directories with the same id in module.prop crashed the module list, which used the id as the item key. Catch every non-cancellation exception when fetching update info and changelogs, and identify modules by their directory name, which is unique. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user