2021-01-22 00:21:03 +01:00
|
|
|
package eu.kanade.tachiyomi.util
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
2021-04-13 15:06:41 +02:00
|
|
|
import android.os.Build
|
|
|
|
|
import eu.kanade.tachiyomi.BuildConfig
|
2021-01-22 00:21:03 +01:00
|
|
|
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
2021-01-24 17:04:25 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.createFileInCacheDir
|
2023-04-02 21:30:07 +02:00
|
|
|
import eu.kanade.tachiyomi.util.system.toShareIntent
|
2021-01-22 00:21:03 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.toast
|
2021-04-15 00:45:48 +02:00
|
|
|
import exh.syDebugVersion
|
2023-01-28 04:31:12 +01:00
|
|
|
import tachiyomi.core.util.lang.withNonCancellableContext
|
|
|
|
|
import tachiyomi.core.util.lang.withUIContext
|
2021-01-22 00:21:03 +01:00
|
|
|
|
|
|
|
|
class CrashLogUtil(private val context: Context) {
|
|
|
|
|
|
2022-10-16 22:35:20 +02:00
|
|
|
suspend fun dumpLogs() = withNonCancellableContext {
|
2022-09-02 17:50:44 +02:00
|
|
|
try {
|
|
|
|
|
val file = context.createFileInCacheDir("tachiyomi_crash_logs.txt")
|
|
|
|
|
Runtime.getRuntime().exec("logcat *:E -d -f ${file.absolutePath}").waitFor()
|
|
|
|
|
file.appendText(getDebugInfo())
|
2021-01-22 00:21:03 +01:00
|
|
|
|
2023-04-02 21:30:07 +02:00
|
|
|
val uri = file.getUriCompat(context)
|
|
|
|
|
context.startActivity(uri.toShareIntent(context, "text/plain"))
|
2022-09-02 17:50:44 +02:00
|
|
|
} catch (e: Throwable) {
|
|
|
|
|
withUIContext { context.toast("Failed to get logs") }
|
2021-01-22 00:21:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:06:41 +02:00
|
|
|
fun getDebugInfo(): String {
|
|
|
|
|
return """
|
2021-05-20 04:39:31 +02:00
|
|
|
App version: ${BuildConfig.VERSION_NAME} (${BuildConfig.FLAVOR}, ${BuildConfig.COMMIT_SHA}, ${BuildConfig.VERSION_CODE}, ${BuildConfig.BUILD_TIME})
|
2021-04-13 15:06:41 +02:00
|
|
|
Preview build: $syDebugVersion
|
|
|
|
|
Android version: ${Build.VERSION.RELEASE} (SDK ${Build.VERSION.SDK_INT})
|
|
|
|
|
Android build ID: ${Build.DISPLAY}
|
|
|
|
|
Device brand: ${Build.BRAND}
|
|
|
|
|
Device manufacturer: ${Build.MANUFACTURER}
|
|
|
|
|
Device name: ${Build.DEVICE}
|
|
|
|
|
Device model: ${Build.MODEL}
|
|
|
|
|
Device product name: ${Build.PRODUCT}
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
}
|
2021-01-22 00:21:03 +01:00
|
|
|
}
|