fix(logs): game debug logs turn off after the session, and a badge shows while they are on (#3239)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-26 23:17:31 -05:00
1 parent bdd3d247c3
commit cc04546373
6 files changed
+117 -7

No files matched your search

@@ -39,6 +39,10 @@ internal object BuildWatermarkSetting {
throw error
}
}
notifyChanged(context)
}
fun notifyChanged(context: Context) {
context.sendBroadcast(Intent(CHANGED).setPackage(context.packageName))
}
}
@@ -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
}
@@ -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(
@@ -81,10 +81,13 @@ object BuildWatermark {
if (activity is QuestXrActivity) return
val decor = activity.window.decorView as? ViewGroup ?: return
decor.findViewWithTag<View>(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<String>) : View(context) {
+1 -1
View File
@@ -966,7 +966,7 @@
<string name="diagnostics_share_games">Games and compatibility</string>
<string name="diagnostics_share_all">All bundles</string>
<string name="setup_game_debug_logs">Game debug logs</string>
<string name="setup_game_debug_logs_hint">Include Proton, Wine and graphics diagnostics on the next game launch. Can reduce performance and use more storage.</string>
<string name="setup_game_debug_logs_hint">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.</string>
<string name="setup_game_debug_logs_restart">Restart this session to save game debug logs</string>
<string name="setup_logging_update_failed">Couldn\'t update logging. Check the switch and try again.</string>
<string name="setup_agent_commands">Debugging tools</string>
@@ -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<View>("build-watermark"))
setDebugLogs(true)
BuildWatermarkSetting.notifyChanged(context)
shadowOf(Looper.getMainLooper()).idle()
assertNotNull(activity.get().window.decorView.findViewWithTag<View>("build-watermark"))
SessionPaths.beginOrCurrent(context, "steam")
SessionPaths.take()
shadowOf(Looper.getMainLooper()).idle()
assertNull(activity.get().window.decorView.findViewWithTag<View>("build-watermark"))
} finally {
activity.pause().stop().destroy()
}
}
}