Collect debug info when dumping logs

This commit is contained in:
FooIbar committed 2023-11-24 20:17:12 +08:00
1 parent b7627dc576
commit 7d74781f96
2 files changed
+25 -20

No files matched your search

@@ -40,6 +40,7 @@ import com.hippo.ehviewer.client.data.FavListUrlBuilder
import com.hippo.ehviewer.ui.tools.LocalDialogState
import com.hippo.ehviewer.ui.tools.observed
import com.hippo.ehviewer.util.AppConfig
import com.hippo.ehviewer.util.Crash
import com.hippo.ehviewer.util.ReadableTime
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
@@ -108,6 +109,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
}
val logcatEntry = ZipEntry("logcat-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt")
zipOs.putNextEntry(logcatEntry)
Crash.collectInfo(zipOs.writer())
Runtime.getRuntime().exec("logcat -d").inputStream.use { it.copyTo(zipOs) }
}
launchSnackBar(getString(R.string.settings_advanced_dump_logcat_to, uri.toString()))
@@ -5,6 +5,7 @@ import android.os.Debug
import com.hippo.ehviewer.BuildConfig
import java.io.File
import java.io.FileWriter
import java.io.OutputStreamWriter
import java.io.PrintWriter
private fun joinIfStringArray(any: Any?): String {
@@ -18,28 +19,30 @@ private fun collectClassStaticInfo(clazz: Class<*>): String {
}
object Crash {
private fun collectInfo(fw: FileWriter) {
fw.write("======== PackageInfo ========\n")
fw.write("${collectClassStaticInfo(BuildConfig::class.java)}\n")
fw.write("\n")
fun collectInfo(writer: OutputStreamWriter) {
writer.write("======== PackageInfo ========\n")
writer.write("${collectClassStaticInfo(BuildConfig::class.java)}\n")
writer.write("\n")
// Device info
fw.write("======== DeviceInfo ========\n")
fw.write("${collectClassStaticInfo(Build::class.java)}\n")
fw.write("${collectClassStaticInfo(Build.VERSION::class.java)}\n")
fw.write("MEMORY=")
fw.write(FileUtils.humanReadableByteCount(OSUtils.appAllocatedMemory, false))
fw.write("\n")
fw.write("MEMORY_NATIVE=")
fw.write(FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false))
fw.write("\n")
fw.write("MEMORY_MAX=")
fw.write(FileUtils.humanReadableByteCount(OSUtils.appMaxMemory, false))
fw.write("\n")
fw.write("MEMORY_TOTAL=")
fw.write(FileUtils.humanReadableByteCount(OSUtils.totalMemory, false))
fw.write("\n")
fw.write("\n")
writer.write("======== DeviceInfo ========\n")
writer.write("${collectClassStaticInfo(Build::class.java)}\n")
writer.write("${collectClassStaticInfo(Build.VERSION::class.java)}\n")
writer.write("MEMORY=")
writer.write(FileUtils.humanReadableByteCount(OSUtils.appAllocatedMemory, false))
writer.write("\n")
writer.write("MEMORY_NATIVE=")
writer.write(FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false))
writer.write("\n")
writer.write("MEMORY_MAX=")
writer.write(FileUtils.humanReadableByteCount(OSUtils.appMaxMemory, false))
writer.write("\n")
writer.write("MEMORY_TOTAL=")
writer.write(FileUtils.humanReadableByteCount(OSUtils.totalMemory, false))
writer.write("\n")
writer.write("\n")
writer.flush()
}
private fun getThrowableInfo(t: Throwable, fw: FileWriter) {