From cc045463737487efd554f8b2492a2ad6e1bb979f Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 26 Nov 2026 23:17:31 -0500 Subject: [PATCH] fix(logs): game debug logs turn off after the session, and a badge shows while they are on (#3239) --- .../launcher/session/BuildWatermarkSetting.kt | 4 + .../launcher/session/SessionPaths.kt | 7 ++ .../launcher/session/SessionPrefs.kt | 10 ++- .../droiddeck/launcher/ui/BuildWatermark.kt | 13 ++- app/src/main/res/values/strings.xml | 2 +- .../session/GameDebugLogsExpiryTest.kt | 88 +++++++++++++++++++ 6 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt b/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt index 98239f8eb..cf31b0240 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/BuildWatermarkSetting.kt @@ -39,6 +39,10 @@ internal object BuildWatermarkSetting { throw error } } + notifyChanged(context) + } + + fun notifyChanged(context: Context) { context.sendBroadcast(Intent(CHANGED).setPackage(context.packageName)) } } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt index 69cb7d4fa..d8117ae71 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt @@ -26,6 +26,9 @@ object SessionPaths { @Volatile private var startedAt = 0L + @Volatile + private var debugLogsContext: Context? = null + @Synchronized fun beginOrCurrent(context: Context, label: String? = null): File { dir?.let { if (it.isDirectory) return it } @@ -44,6 +47,7 @@ object SessionPaths { startedAt = System.currentTimeMillis() if (!made.isDirectory && !made.mkdirs()) Log.e(TAG, "could not create $made") dir = made + debugLogsContext = if (SessionPrefs.gameDebugLogsEnabled(context)) context.applicationContext else null if (enhanced && !EnhancedDiagnostics.consumeInto(context, made)) { Log.e(TAG, "could not activate enhanced diagnostics for $made") } @@ -65,6 +69,9 @@ object SessionPaths { val taken = dir dir = null if (taken != null) ended = taken + val expiring = debugLogsContext + debugLogsContext = null + if (taken != null && expiring != null) SessionPrefs.expireGameDebugLogs(expiring) return taken } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index b5794eff9..5d545c0b6 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -1228,7 +1228,7 @@ object SessionPrefs { oldValue = logsEnabled(context), newValue = on, newEffective = gameDebugLogsEffective(context, on, gameDebugLogsEnabled(context)), - ) + ).also { if (it) BuildWatermarkSetting.notifyChanged(context) } } fun gameDebugLogsEnabled(context: Context): Boolean = @@ -1241,7 +1241,13 @@ object SessionPrefs { oldValue = gameDebugLogsEnabled(context), newValue = on, newEffective = gameDebugLogsEffective(context, logsEnabled(context), on), - ) + ).also { if (it) BuildWatermarkSetting.notifyChanged(context) } + } + + /** The setting lasts for the session that started with it on; the next session's start republishes the environment. */ + internal fun expireGameDebugLogs(context: Context) { + prefs(context).edit().putBoolean("gameDebugLogsEnabled", false).apply() + runCatching { BuildWatermarkSetting.notifyChanged(context) } } private fun setLogPreference( diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt b/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt index 446420806..c916b3f7a 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BuildWatermark.kt @@ -81,10 +81,13 @@ object BuildWatermark { if (activity is QuestXrActivity) return val decor = activity.window.decorView as? ViewGroup ?: return decor.findViewWithTag(TAG)?.let(decor::removeView) - if (!com.droiddeck.launcher.session.SessionPrefs.buildWatermarkEnabled(activity)) return - val lab = com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" } - val build = lineProvider().orEmpty() - val content = (listOfNotNull(lab) + build).ifEmpty { return } + val prefs = com.droiddeck.launcher.session.SessionPrefs + val debugLogs = if (prefs.logsEnabled(activity) && prefs.gameDebugLogsEnabled(activity)) DEBUG_LOGS_LINE else null + val build = if (prefs.buildWatermarkEnabled(activity)) { + listOfNotNull(com.droiddeck.launcher.lab.LabOverlay.active?.let { "LAB | ${truncate(it.label)}" }) + + lineProvider().orEmpty() + } else emptyList() + val content = (build + listOfNotNull(debugLogs)).ifEmpty { return } val margin = (8 * activity.resources.displayMetrics.density).toInt() decor.addView( MarkView(activity, content).apply { tag = TAG }, @@ -96,6 +99,8 @@ object BuildWatermark { ) } + internal const val DEBUG_LOGS_LINE = "GAME DEBUG LOGS ON | slows games" + private const val TAG = "build-watermark" private class MarkView(context: Context, private val lines: List) : View(context) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc7f0aca3..e5d43de07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -966,7 +966,7 @@ Games and compatibility All bundles Game debug logs - Include Proton, Wine and graphics diagnostics on the next game launch. Can reduce performance and use more storage. + Include Proton, Wine and graphics diagnostics on the next game launch. Turns itself off when that session ends. Can reduce performance and use more storage. Restart this session to save game debug logs Couldn\'t update logging. Check the switch and try again. Debugging tools diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt new file mode 100644 index 000000000..9642b2746 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/GameDebugLogsExpiryTest.kt @@ -0,0 +1,88 @@ +package com.droiddeck.launcher.session + +import android.app.Activity +import android.app.Application +import android.content.Context +import android.os.Looper +import android.view.View +import com.droiddeck.launcher.ui.BuildWatermark +import org.junit.After +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import org.robolectric.annotation.ConscryptMode +import org.robolectric.annotation.GraphicsMode +import java.io.File + +@RunWith(RobolectricTestRunner::class) +@ConscryptMode(ConscryptMode.Mode.OFF) +@GraphicsMode(GraphicsMode.Mode.LEGACY) +@Config(sdk = [34], manifest = Config.NONE, application = Application::class) +class GameDebugLogsExpiryTest { + private val context get() = RuntimeEnvironment.getApplication() + private val prefs get() = context.getSharedPreferences("session", Context.MODE_PRIVATE) + + @Before fun reset() { + SessionPaths.take() + prefs.edit().clear().commit() + listOf("build-watermark", "build-watermark.lock").forEach { File(context.filesDir, it).delete() } + } + + @After fun end() { + SessionPaths.take() + } + + private fun setDebugLogs(on: Boolean) = prefs.edit().putBoolean("gameDebugLogsEnabled", on).commit() + + @Test fun settingTurnsOffWhenTheSessionItStartedWithEnds() { + setDebugLogs(true) + SessionPaths.beginOrCurrent(context, "steam") + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun settingStaysOnForTheSessionRunningWhenItWasEnabled() { + SessionPaths.beginOrCurrent(context, "steam") + setDebugLogs(true) + SessionPaths.take() + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun settingThatWasOffStaysOff() { + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + } + + @Test fun badgeShowsWhileOnEvenWithTheBuildWatermarkOff() { + BuildWatermark.install(context) + SessionPrefs.setBuildWatermarkEnabled(context, false) + val activity = Robolectric.buildActivity(Activity::class.java).setup() + try { + assertNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + setDebugLogs(true) + BuildWatermarkSetting.notifyChanged(context) + shadowOf(Looper.getMainLooper()).idle() + assertNotNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + SessionPaths.beginOrCurrent(context, "steam") + SessionPaths.take() + shadowOf(Looper.getMainLooper()).idle() + assertNull(activity.get().window.decorView.findViewWithTag("build-watermark")) + } finally { + activity.pause().stop().destroy() + } + } +}