diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt index 5ec90bfce..d80f7692a 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/settings/AdvancedScreen.kt @@ -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())) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt b/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt index ba4fa2d58..bd7be27f7 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/util/Crash.kt @@ -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) {