Cleanup CrashHandler
This commit is contained in:
1 parent
769308c9f0
commit
eff5467ccf
3 files changed
+17
-15
No files matched your search
@@ -57,7 +57,7 @@ import com.hippo.ehviewer.ui.screen.detailCache
|
||||
import com.hippo.ehviewer.ui.tools.dataStateFlow
|
||||
import com.hippo.ehviewer.ui.tools.initSETConnection
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
import com.hippo.ehviewer.util.Crash
|
||||
import com.hippo.ehviewer.util.CrashHandler
|
||||
import com.hippo.ehviewer.util.FavouriteStatusRouter
|
||||
import com.hippo.ehviewer.util.FileUtils
|
||||
import com.hippo.ehviewer.util.isAtLeastO
|
||||
@@ -100,16 +100,7 @@ class EhApplication :
|
||||
}
|
||||
}
|
||||
lifecycle.addObserver(lockObserver)
|
||||
val handler = Thread.getDefaultUncaughtExceptionHandler()
|
||||
Thread.setDefaultUncaughtExceptionHandler { t, e ->
|
||||
try {
|
||||
if (Settings.saveCrashLog) {
|
||||
Crash.saveCrashLog(e)
|
||||
}
|
||||
} catch (ignored: Throwable) {
|
||||
}
|
||||
handler?.uncaughtException(t, e)
|
||||
}
|
||||
CrashHandler.install()
|
||||
super.onCreate()
|
||||
System.loadLibrary("ehviewer")
|
||||
lifecycleScope.launchIO {
|
||||
|
||||
@@ -44,7 +44,7 @@ import com.hippo.ehviewer.collectAsState
|
||||
import com.hippo.ehviewer.ui.tools.observed
|
||||
import com.hippo.ehviewer.ui.tools.rememberedAccessor
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
import com.hippo.ehviewer.util.Crash
|
||||
import com.hippo.ehviewer.util.CrashHandler
|
||||
import com.hippo.ehviewer.util.ReadableTime
|
||||
import com.hippo.ehviewer.util.displayPath
|
||||
import com.hippo.ehviewer.util.getAppLanguage
|
||||
@@ -147,7 +147,7 @@ fun AdvancedScreen(navigator: DestinationsNavigator) {
|
||||
}
|
||||
val logcatEntry = ZipEntry("logcat-" + ReadableTime.getFilenamableTime() + ".txt")
|
||||
zipOs.putNextEntry(logcatEntry)
|
||||
Crash.collectInfo(zipOs.writer())
|
||||
CrashHandler.collectInfo(zipOs.writer())
|
||||
Runtime.getRuntime().exec("logcat -d").inputStream.use { it.copyTo(zipOs) }
|
||||
}
|
||||
launchSnackBar(getString(R.string.settings_advanced_dump_logcat_to, uri.displayPath))
|
||||
|
||||
+13
-2
@@ -3,6 +3,7 @@ package com.hippo.ehviewer.util
|
||||
import android.os.Build
|
||||
import android.os.Debug
|
||||
import com.hippo.ehviewer.BuildConfig
|
||||
import com.hippo.ehviewer.Settings
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
@@ -14,7 +15,17 @@ private fun collectClassStaticInfo(clazz: Class<*>): String = clazz.fields.joinT
|
||||
"${it.name}=${joinIfStringArray(it.get(null))}"
|
||||
}
|
||||
|
||||
object Crash {
|
||||
object CrashHandler {
|
||||
fun install() {
|
||||
val handler = Thread.getDefaultUncaughtExceptionHandler()
|
||||
Thread.setDefaultUncaughtExceptionHandler { t, e ->
|
||||
if (Settings.saveCrashLog) {
|
||||
runCatching { saveCrashLog(e) }
|
||||
}
|
||||
handler?.uncaughtException(t, e)
|
||||
}
|
||||
}
|
||||
|
||||
fun collectInfo(writer: Writer) {
|
||||
writer.write("======== PackageInfo ========\n")
|
||||
writer.write("PackageName=${BuildConfig.APPLICATION_ID}\n")
|
||||
@@ -54,7 +65,7 @@ object Crash {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveCrashLog(t: Throwable) {
|
||||
private fun saveCrashLog(t: Throwable) {
|
||||
val dir = AppConfig.externalCrashDir ?: return
|
||||
val nowString = ReadableTime.getFilenamableTime()
|
||||
val fileName = "crash-$nowString.log"
|
||||
Reference in new issue
Block a user