Răsfoiți Sursa

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 <[email protected]>
Seishirou101 1 an în urmă
părinte
comite
0bdd3f79d4
1 a modificat fișierele cu 39 adăugiri și 6 ștergeri
  1. 39 6
      app/src/main/java/eu/kanade/tachiyomi/util/CrashLogUtil.kt

+ 39 - 6
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
+        }
+    }
 }