From 0bdd3f79d4d14318ba8110748c6d39484c6d446b Mon Sep 17 00:00:00 2001 From: Seishirou101 <57241064+Seishirou101@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:13:46 -0500 Subject: [PATCH] Add info about problematic extensions to debug logs (#10059) * add ext info to crashlog * add unofficial to crashlog too * update to have header include unofficial too * after ktlintFormat * Clean up debug info output --------- Co-authored-by: arkon --- .../eu/kanade/tachiyomi/util/CrashLogUtil.kt | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) 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 505ec3cf9..7f39823e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.util import android.content.Context import android.os.Build import eu.kanade.tachiyomi.BuildConfig +import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.createFileInCacheDir @@ -10,14 +11,22 @@ import eu.kanade.tachiyomi.util.system.toShareIntent import eu.kanade.tachiyomi.util.system.toast import tachiyomi.core.util.lang.withNonCancellableContext import tachiyomi.core.util.lang.withUIContext +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get -class CrashLogUtil(private val context: Context) { +class CrashLogUtil( + private val context: Context, + private val extensionManager: ExtensionManager = Injekt.get(), +) { suspend fun dumpLogs() = withNonCancellableContext { try { val file = context.createFileInCacheDir("tachiyomi_crash_logs.txt") + + file.appendText(getDebugInfo() + "\n\n") + getExtensionsInfo()?.let { file.appendText("$it\n\n") } + Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor() - file.appendText(getDebugInfo()) val uri = file.getUriCompat(context) context.startActivity(uri.toShareIntent(context, "text/plain")) @@ -29,14 +38,38 @@ class CrashLogUtil(private val context: Context) { fun getDebugInfo(): String { return """ App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}, ${BuildConfig.COMMIT_SHA}, ${BuildConfig.VERSION_CODE}, ${BuildConfig.BUILD_TIME}) - Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT}) - Android build ID: ${Build.DISPLAY} + Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT}; build ${Build.DISPLAY}) Device brand: ${Build.BRAND} Device manufacturer: ${Build.MANUFACTURER} - Device name: ${Build.DEVICE} + Device name: ${Build.DEVICE} (${Build.PRODUCT}) Device model: ${Build.MODEL} - Device product name: ${Build.PRODUCT} WebView: ${WebViewUtil.getVersion(context)} """.trimIndent() } + + private fun getExtensionsInfo(): String? { + val availableExtensions = extensionManager.availableExtensionsFlow.value.associateBy { it.pkgName } + + val extensionInfoList = extensionManager.installedExtensionsFlow.value + .sortedBy { it.name } + .mapNotNull { + val availableExtension = availableExtensions[it.pkgName] + val hasUpdate = (availableExtension?.versionCode ?: 0) > it.versionCode + + if (!hasUpdate && !it.isObsolete && !it.isUnofficial) return@mapNotNull null + + """ + - ${it.name} + Installed: ${it.versionName} / Available: ${availableExtension?.versionName ?: "?"} + Obsolete: ${it.isObsolete} / Unofficial: ${it.isUnofficial} + """.trimIndent() + } + + return if (extensionInfoList.isNotEmpty()) { + (listOf("Problematic extensions:") + extensionInfoList) + .joinToString("\n") + } else { + null + } + } }