From a3d438e2f5b427eb8b4c391ab9fe10c5a83baf29 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Fri, 3 May 2024 02:59:29 +0800 Subject: [PATCH] Log app crash exceptions in dumped crash logs (#742) --- app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt | 2 +- app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt b/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt index fd8b27030..5be7a2ca5 100644 --- a/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/crash/CrashScreen.kt @@ -37,7 +37,7 @@ fun CrashScreen( acceptText = stringResource(MR.strings.pref_dump_crash_logs), onAcceptClick = { scope.launch { - CrashLogUtil(context).dumpLogs() + CrashLogUtil(context).dumpLogs(exception) } }, rejectText = stringResource(MR.strings.crash_screen_restart_application), diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt index 56e6c278b..ed27314ef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt @@ -19,12 +19,13 @@ class CrashLogUtil( private val extensionManager: ExtensionManager = Injekt.get(), ) { - suspend fun dumpLogs() = withNonCancellableContext { + suspend fun dumpLogs(exception: Throwable? = null) = withNonCancellableContext { try { val file = context.createFileInCacheDir("mihon_crash_logs.txt") file.appendText(getDebugInfo() + "\n\n") getExtensionsInfo()?.let { file.appendText("$it\n\n") } + exception?.let { file.appendText("$it\n\n") } Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor()