From 8e24977ade647516f35cc774f562880933d96182 Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Sun, 3 Mar 2024 00:53:35 -0500 Subject: [PATCH] RecorderThread: Always preserve logcat on errors This is more user-friendly since it doesn't require the user to manually enable debug mode and then try to reproduce the error. Signed-off-by: Andrew Gunnerson --- .../java/com/chiller3/bcr/RecorderThread.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt index ade56033a..672bd2048 100644 --- a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt +++ b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt @@ -59,7 +59,6 @@ class RecorderThread( ) : Thread(RecorderThread::class.java.simpleName) { private val tag = "${RecorderThread::class.java.simpleName}/${id}" private val prefs = Preferences(context) - private val isDebug = prefs.isDebugMode enum class State { NOT_STARTED, @@ -256,7 +255,16 @@ class RecorderThread( Log.i(tag, "Recording thread completed") try { - stopLogcat()?.let { additionalFiles.add(it) } + val logcatOutput = stopLogcat() + + // Log files are always kept when an error occurs to avoid the hassle of having the + // user manually enable debug mode and needing to reproduce the problem. + if (prefs.isDebugMode || errorMsg != null) { + additionalFiles.add(logcatOutput) + } else { + Log.d(tag, "No need to preserve logcat") + logcatOutput.toDocumentFile(context).delete() + } } catch (e: Exception) { Log.w(tag, "Failed to dump logcat", e) } @@ -305,10 +313,6 @@ class RecorderThread( } private fun startLogcat() { - if (!isDebug) { - return - } - assert(!this::logcatProcess.isInitialized) { "logcat already started" } Log.d(tag, "Starting log file (${BuildConfig.VERSION_NAME})") @@ -324,11 +328,7 @@ class RecorderThread( .start() } - private fun stopLogcat(): OutputFile? { - if (!isDebug) { - return null - } - + private fun stopLogcat(): OutputFile { assert(this::logcatProcess.isInitialized) { "logcat not started" } var uri = logcatFile.uri