From 6521c3c3ade4d67b237cb22acb1a9527d8d34a89 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 02:22:15 -0500 Subject: [PATCH 01/13] Add opt-in game debug logs and bounded log sharing --- .../com/droiddeck/launcher/MainActivity.kt | 17 ++ .../droiddeck/launcher/core/LogRedactor.kt | 155 ++++++++++++---- .../launcher/session/GameEnvironmentStore.kt | 6 + .../launcher/session/SessionArtifacts.kt | 170 +++++++++++++----- .../launcher/session/SessionPaths.kt | 4 + .../launcher/session/SessionPrefs.kt | 10 ++ .../launcher/session/SessionService.kt | 2 +- .../launcher/session/SettingsReset.kt | 2 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 3 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 6 + app/src/main/res/values/strings.xml | 3 + .../launcher/core/LogRedactorTest.kt | 70 ++++++++ .../session/GameEnvironmentStoreTest.kt | 69 +++++++ .../launcher/session/SessionLogShareTest.kt | 120 +++++++++++++ .../session/SessionLogShareZipTest.kt | 44 +++++ .../launcher/session/SettingsResetTest.kt | 5 + docs/development/game-environment.md | 38 ++++ .../overlay/usr/local/bin/droiddeck-game-env | 60 +++++++ tools/tests/test_game_environment.py | 115 ++++++++++++ 19 files changed, 825 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 4c41ea2693..632f95af98 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -44,6 +44,7 @@ import com.droiddeck.launcher.session.ComponentsManager import com.droiddeck.launcher.ui.ComponentsPage import com.droiddeck.launcher.session.GameSaves import com.droiddeck.launcher.session.SessionLogShare +import com.droiddeck.launcher.session.SessionPaths import com.droiddeck.launcher.session.SessionPrefs import com.droiddeck.launcher.session.SteamRepair import com.droiddeck.launcher.core.CpuCores @@ -406,6 +407,8 @@ class MainActivity : ComponentActivity() { private var emulatorList by mutableStateOf>(emptyList()) private var runningLabel by mutableStateOf(null) private var logsEnabled by mutableStateOf(true) + private var gameDebugLogsEnabled by mutableStateOf(false) + private var gameDebugLogsNeedsRestart by mutableStateOf(false) private var vacDiagnostics by mutableStateOf(false) private var agentCommands by mutableStateOf(false) private var showRoms by mutableStateOf(false) @@ -767,6 +770,7 @@ class MainActivity : ComponentActivity() { desktopInstalled = desktopInstalled, desktopPresent = desktopPresent, offlineAccount = offlineAccount, offline = offline, frameGenLabel = frameGenLabel, romsDir = romsDir, logsEnabled = logsEnabled, + gameDebugLogsEnabled = gameDebugLogsEnabled, gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart, vacDiagnostics = vacDiagnostics, agentCommands = agentCommands, steamGames = steamGames, steamGamesX64 = steamGamesX64, emulators = emulatorList, running = runningLabel, frameGen = FrameGen.mode(this), @@ -916,6 +920,13 @@ class MainActivity : ComponentActivity() { onLogs = { SessionPrefs.setLogsEnabled(this, !SessionPrefs.logsEnabled(this)) logsEnabled = SessionPrefs.logsEnabled(this) + gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) + gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() + }, + onGameDebugLogs = { + SessionPrefs.setGameDebugLogsEnabled(this, !SessionPrefs.gameDebugLogsEnabled(this)) + gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) + gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() }, onVacDiagnostics = { SessionPrefs.setVacDiagnostics(this, !SessionPrefs.vacDiagnostics(this)) @@ -1875,6 +1886,10 @@ class MainActivity : ComponentActivity() { refreshPhantomStatus() } + private fun gameDebugLogsNeedsRestart(): Boolean = + SessionPrefs.logsEnabled(this) && SessionPrefs.gameDebugLogsEnabled(this) && + !SessionPaths.currentSessionLogsRetained(this) + private fun refresh() { // Until the scan finishes, the other client's games would launch in this one. val listX64 = SessionPrefs.activeSteamClientArch(this) == "x86_64" @@ -1895,6 +1910,8 @@ class MainActivity : ComponentActivity() { frameGenLabel = FrameGen.label(this) romsDir = SessionPrefs.romsDir(this).takeIf { it.isNotEmpty() } logsEnabled = SessionPrefs.logsEnabled(this) + gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) + gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() vacDiagnostics = SessionPrefs.vacDiagnostics(this) agentCommands = com.droiddeck.launcher.agent.AgentAccess.commandsEnabled(this) runningLabel = if (SessionState.running) when (SessionState.mode) { diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index d2128476ac..f3103625d5 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -1,6 +1,52 @@ package com.droiddeck.launcher.core object LogRedactor { + internal const val MAX_LINE_LENGTH = 64 * 1024 + internal const val OVERSIZED_LINE = "" + + private data class MatcherKey(val pattern: String, val options: Set) + + private class MatcherCache : LinkedHashMap(32, 0.75f, true) { + override fun removeEldestEntry(eldest: MutableMap.MutableEntry?): Boolean = + size > 32 + } + + // Android matchers own native state, so reuse them instead of creating one for every log line. + private val matchers = object : ThreadLocal() { + override fun initialValue(): MatcherCache = MatcherCache() + } + + private fun withMatcher( + regex: Regex, + input: CharSequence, + action: (java.util.regex.Matcher) -> T, + ): T { + val key = MatcherKey(regex.pattern, regex.options) + val matcher = matchers.get()!!.getOrPut(key) { regex.toPattern().matcher("") } + return try { + action(matcher.reset(input)) + } finally { + matcher.reset("") + } + } + + private fun replaceMatches(input: String, regex: Regex, replacement: String): String = + replaceMatches(input, regex) { replacement } + + private fun replaceMatches( + input: String, + regex: Regex, + replacement: (java.util.regex.Matcher) -> String, + ): String = withMatcher(regex, input) { matcher -> + if (!matcher.find()) return@withMatcher input + val out = StringBuffer(input.length) + do { + matcher.appendReplacement(out, java.util.regex.Matcher.quoteReplacement(replacement(matcher))) + } while (matcher.find()) + matcher.appendTail(out) + out.toString() + } + private val EMAIL = Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}") private val JWT_LABELLED = Regex("(?i)(\\bJWT[\\s=:]+)(\\d{8,})") private val JWT_BASE64 = Regex("ey[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}") @@ -74,6 +120,7 @@ object LogRedactor { java.io.File(root, "root/.local/share/Steam/config/loginusers.vdf"), java.io.File(root, "root/.droiddeck-x64/.local/share/Steam/config/loginusers.vdf"), ) + matchers.remove() } @Volatile @@ -141,13 +188,13 @@ object LogRedactor { } fun describeAddresses(text: String): String { - var out = IPV6.replace(text) { m -> kind(m.value)?.let { "<$it>" } ?: m.value } - out = IPV4.replace(out) { m -> kind(m.value)?.let { "<$it>" } ?: m.value } + var out = replaceMatches(text, IPV6) { m -> kind(m.group())?.let { "<$it>" } ?: m.group() } + out = replaceMatches(out, IPV4) { m -> kind(m.group())?.let { "<$it>" } ?: m.group() } return out } fun isText(file: java.io.File): Boolean = try { - file.isFile && file.length() < 64L * 1024 * 1024 && file.inputStream().use { input -> + file.isFile && file.inputStream().use { input -> val buf = ByteArray(4096) val n = input.read(buf) n <= 0 || (0 until n).none { buf[it].toInt() == 0 } @@ -163,21 +210,68 @@ object LogRedactor { ) fun scrubTo(src: java.io.File, out: java.io.Writer) { - src.forEachLine { line -> out.write(redact(line)); out.write("\n") } + scrubLines(src, out, ::redact) } fun redactForShare(line: String): String { if (line.isEmpty()) return line + if (line.length > MAX_LINE_LENGTH) return OVERSIZED_LINE return try { val out = SecretScrub.scrub(redact(line), SecretScrub.Urls.KEEP_PATH, "") - LAN_IPV4.replace(out, "") + replaceMatches(out, LAN_IPV4, "") } catch (t: Throwable) { "" } } fun scrubForShare(src: java.io.File, out: java.io.Writer) { - src.forEachLine { line -> out.write(redactForShare(line)); out.write("\n") } + scrubLines(src, out, ::redactForShare) + } + + private fun scrubLines(src: java.io.File, out: java.io.Writer, scrub: (String) -> String) { + src.bufferedReader().use { input -> + val chunk = CharArray(8192) + val line = StringBuilder(4096) + var oversized = false + var pendingContent = false + var pendingCarriageReturn = false + + fun emit() { + out.write(if (oversized) OVERSIZED_LINE else scrub(line.toString())) + out.write("\n") + line.setLength(0) + oversized = false + pendingContent = false + } + + while (true) { + val count = input.read(chunk) + if (count < 0) break + for (i in 0 until count) { + val char = chunk[i] + if (pendingCarriageReturn) { + emit() + pendingCarriageReturn = false + if (char == '\n') continue + } + when (char) { + '\r' -> pendingCarriageReturn = true + '\n' -> emit() + else -> { + pendingContent = true + if (!oversized) { + if (line.length < MAX_LINE_LENGTH) line.append(char) + else { + line.setLength(0) + oversized = true + } + } + } + } + } + } + if (pendingCarriageReturn || pendingContent) emit() + } } private fun quoted(value: String): String { @@ -219,43 +313,44 @@ object LogRedactor { fun redact(line: String): String { if (line.isEmpty()) return line + if (line.length > MAX_LINE_LENGTH) return OVERSIZED_LINE return try { val out = Line(line) - if (out.has("mac")) out.set(MAC_FIELD.replace(out.text) { "${it.groupValues[1]}" }) - if (out.holds(':', 5) || out.holds('-', 5)) out.set(MAC.replace(out.text, "")) - if (out.has("serial", "android")) out.set(DEVICE_IDENTIFIER.replace(out.text) { - val value = it.groupValues[2] + if (out.has("mac")) out.set(replaceMatches(out.text, MAC_FIELD) { "${it.group(1)}" }) + if (out.holds(':', 5) || out.holds('-', 5)) out.set(replaceMatches(out.text, MAC, "")) + if (out.has("serial", "android")) out.set(replaceMatches(out.text, DEVICE_IDENTIFIER) { + val value = it.group(2) val quote = value.first().takeIf { char -> char == '\"' || char == '\'' }?.toString().orEmpty() - "${it.groupValues[1]}${quote}${quote}" + "${it.group(1)}${quote}${quote}" }) - if (out.holds('-', 4)) out.set(GUID.replace(out.text, "")) - if (out.has("jwt")) out.set(JWT_LABELLED.replace(out.text) { "${it.groupValues[1]}" }) - if ("ey" in out.text) out.set(JWT_BASE64.replace(out.text, "")) + if (out.holds('-', 4)) out.set(replaceMatches(out.text, GUID, "")) + if (out.has("jwt")) out.set(replaceMatches(out.text, JWT_LABELLED) { "${it.group(1)}" }) + if ("ey" in out.text) out.set(replaceMatches(out.text, JWT_BASE64, "")) if (out.has("token", "auth", "ticket", "sessionid", "steamloginsecure", "api", "machine", "pass", "pwd", "secret")) { - out.set(SECRET_KV.replace(out.text) { "${it.groupValues[1]}${it.groupValues[2]}" }) + out.set(replaceMatches(out.text, SECRET_KV) { "${it.group(1)}${it.group(2)}" }) } - if (out.has("guard", "factor", "2fa")) out.set(GUARD_CODE.replace(out.text) { "${it.groupValues[1]}" }) - if (out.hasRun(32, ::isHex)) out.set(WEBAPI_KEY.replace(out.text, "")) - if ("76561" in out.text) out.set(STEAMID64.replace(out.text) { "${it.groupValues[1]}********${it.groupValues[3]}" }) - if ("[U:1:" in out.text) out.set(STEAMID3.replace(out.text) { m -> - val id = m.groupValues[1] + if (out.has("guard", "factor", "2fa")) out.set(replaceMatches(out.text, GUARD_CODE) { "${it.group(1)}" }) + if (out.hasRun(32, ::isHex)) out.set(replaceMatches(out.text, WEBAPI_KEY, "")) + if ("76561" in out.text) out.set(replaceMatches(out.text, STEAMID64) { "${it.group(1)}********${it.group(3)}" }) + if ("[U:1:" in out.text) out.set(replaceMatches(out.text, STEAMID3) { m -> + val id = m.group(1) "[U:1:${if (id.length > 4) "*".repeat(id.length - 4) + id.takeLast(4) else id}]" }) - if (out.has("external")) out.set(EXTERNAL_ADDR.replace(out.text) { "${it.groupValues[1]}" }) - for (r in own) if (r.needs == null || out.has(r.needs)) out.set(r.regex.replace(out.text, "")) - if (out.has("onloginstatechange")) out.set(LOGIN_STATE.replace(out.text) { "${it.groupValues[1]}" }) - if ("OnLoginUsersChanged " in out.text) out.set(LOGIN_USERS.replace(out.text) { "${it.groupValues[1]}" }) + if (out.has("external")) out.set(replaceMatches(out.text, EXTERNAL_ADDR) { "${it.group(1)}" }) + for (r in own) if (r.needs == null || out.has(r.needs)) out.set(replaceMatches(out.text, r.regex, "")) + if (out.has("onloginstatechange")) out.set(replaceMatches(out.text, LOGIN_STATE) { "${it.group(1)}" }) + if ("OnLoginUsersChanged " in out.text) out.set(replaceMatches(out.text, LOGIN_USERS) { "${it.group(1)}" }) if (out.has("account", "user")) { - out.set(ACCOUNT_KV.replace(out.text) { "${it.groupValues[1]}${it.groupValues[2]}${quoted(it.groupValues[3])}" }) + out.set(replaceMatches(out.text, ACCOUNT_KV) { "${it.group(1)}${it.group(2)}${quoted(it.group(3))}" }) } - if (out.has("login")) out.set(LOGIN_KV.replace(out.text) { "${it.groupValues[1]}${it.groupValues[2]}${quoted(it.groupValues[3])}" }) - for (r in accounts) if (r.needs == null || out.has(r.needs)) out.set(r.regex.replace(out.text, "")) - if ('@' in out.text) out.set(EMAIL.replace(out.text, "")) + if (out.has("login")) out.set(replaceMatches(out.text, LOGIN_KV) { "${it.group(1)}${it.group(2)}${quoted(it.group(3))}" }) + for (r in accounts) if (r.needs == null || out.has(r.needs)) out.set(replaceMatches(out.text, r.regex, "")) + if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL, "")) if (out.has("jwt", "token", "ticket", "sessionid", "steamloginsecure", "machineauth")) { - out.set(RESIDUAL.replace(out.text) { "${it.groupValues[1]}=" }) + out.set(replaceMatches(out.text, RESIDUAL) { "${it.group(1)}=" }) } if (out.hasRun(88) { it in 'a'..'z' || it in 'A'..'Z' || it in '0'..'9' || it == '_' || it == '-' }) { - out.set(LONG_TOKEN.replace(out.text, "")) + out.set(replaceMatches(out.text, LONG_TOKEN, "")) } out.text } catch (t: Throwable) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index 351fe304c0..e64f12343d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -13,6 +13,7 @@ object GameEnvironmentStore { private const val GUEST_FILE = "root/.config/droiddeck/game-environment.json" const val DXVK_CONFIG = "dxvkConfig" const val DXVK_CONFIG_GAMES = "dxvkConfigGames" + const val GAME_DEBUG_LOGS = "gameDebugLogs" @Synchronized fun read(context: Context): GameEnvironment.Config { @@ -102,6 +103,11 @@ object GameEnvironmentStore { ) } if (gameDxvk.length() > 0) json.put(DXVK_CONFIG_GAMES, gameDxvk) + json.put( + GAME_DEBUG_LOGS, + SessionPrefs.logsEnabled(context) && SessionPrefs.gameDebugLogsEnabled(context) && + SessionPaths.currentSessionLogsRetained(context), + ) write(File(LinuxRuntime.rootDir(context), GUEST_FILE), json.toString()) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index e0e8557422..6d961d1f7e 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -88,15 +88,10 @@ object SessionArtifacts { }?.toList() ?: return if (dirs.isEmpty()) return LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) - val workers = (Runtime.getRuntime().availableProcessors() / 2).coerceIn(1, 4) - val pool = java.util.concurrent.Executors.newFixedThreadPool(workers) { r -> - Thread({ android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); r.run() }, "scrub-logs") - } - val done = try { - pool.invokeAll(dirs.map { dir -> java.util.concurrent.Callable { scrubAndMark(dir) } }) - .count { f -> try { f.get() } catch (e: Exception) { false } } - } finally { - pool.shutdown() + var done = 0 + for (dir in dirs) { + if (SessionState.running) break + if (scrubAndMark(dir, stopWhenSessionStarts = true)) done++ } val failed = dirs.size - done Log.i(TAG, "logs: scrubbed $done folders under r${LogRedactor.RULES_VERSION}" + @@ -114,14 +109,18 @@ object SessionArtifacts { private class Record(val dir: File) { val files = HashMap() var failed = false + var deferred = false } - private fun scrubFolder(dir: File, record: Record) { - dir.listFiles { f -> f.isFile && !f.name.startsWith(".") && f !in record.files }?.forEach { f -> - if (!LogRedactor.isText(f)) return@forEach + private fun scrubFolder(dir: File, record: Record, stopWhenSessionStarts: Boolean): Boolean { + val files = dir.listFiles { f -> f.isFile && !f.name.startsWith(".") && f !in record.files } ?: return true + for (f in files) { + if (stopWhenSessionStarts && SessionState.running) return false + if (!LogRedactor.isText(f)) continue val done = scrubFile(dir, f) if (done == null) record.failed = true else record.files[f] = done } + return true } private fun scrubFile(dir: File, f: File): Scrubbed? { @@ -129,13 +128,16 @@ object SessionArtifacts { return try { val before = Scrubbed(f.length(), f.lastModified()) tmp.bufferedWriter().use { w -> LogRedactor.scrubTo(f, w) } - val scrubbed = tmp.readBytes() - if (scrubbed.contentEquals(f.readBytes())) { + val scrubbedLength = tmp.length() + if (sameContents(tmp, f)) { tmp.delete() before.takeIf { f.length() == it.length && f.lastModified() == it.modified } } else { - if (!tmp.renameTo(f)) { f.writeBytes(scrubbed); tmp.delete() } - Scrubbed(scrubbed.size.toLong(), f.lastModified()).takeIf { f.length() == it.length } + if (!tmp.renameTo(f)) { + tmp.inputStream().use { input -> f.outputStream().use { output -> input.copyTo(output, 64 * 1024) } } + tmp.delete() + } + Scrubbed(scrubbedLength, f.lastModified()).takeIf { f.length() == it.length } } } catch (e: Exception) { Log.w(TAG, "could not scrub ${f.name}", e) @@ -144,6 +146,34 @@ object SessionArtifacts { } } + private fun sameContents(a: File, b: File): Boolean { + if (a.length() != b.length()) return false + fun readChunk(input: java.io.InputStream, buffer: ByteArray): Int { + var count = 0 + while (count < buffer.size) { + val read = input.read(buffer, count, buffer.size - count) + if (read < 0) break + if (read == 0) continue + count += read + } + return count + } + return a.inputStream().buffered().use { left -> + b.inputStream().buffered().use { right -> + val leftBuffer = ByteArray(64 * 1024) + val rightBuffer = ByteArray(64 * 1024) + while (true) { + val leftCount = readChunk(left, leftBuffer) + val rightCount = readChunk(right, rightBuffer) + if (leftCount != rightCount) return false + if (leftCount == 0) break + for (i in 0 until leftCount) if (leftBuffer[i] != rightBuffer[i]) return false + } + true + } + } + } + private fun markScrubbed(record: Record): Boolean { val dir = record.dir val tree = File(dir, SCRUBBED_TREE_MARKER) @@ -181,10 +211,27 @@ object SessionArtifacts { }.toSet() } - internal fun scrubAndMark(dir: File): Boolean = markScrubbed(scrubTree(Record(dir))) + internal fun scrubAndMark(dir: File, stopWhenSessionStarts: Boolean = false): Boolean { + val record = scrubTree(Record(dir), stopWhenSessionStarts) + if (stopWhenSessionStarts && SessionState.running) { + record.failed = true + record.deferred = true + } + return markScrubbed(record) + } - private fun scrubTree(record: Record): Record { - record.dir.walkTopDown().filter { it.isDirectory }.forEach { scrubFolder(it, record) } + private fun scrubTree(record: Record, stopWhenSessionStarts: Boolean = false): Record { + for (dir in record.dir.walkTopDown().filter { it.isDirectory }) { + if (stopWhenSessionStarts && SessionState.running || !scrubFolder(dir, record, stopWhenSessionStarts)) { + record.failed = true + record.deferred = true + break + } + } + if (stopWhenSessionStarts && SessionState.running) { + record.failed = true + record.deferred = true + } return record } @@ -198,16 +245,26 @@ object SessionArtifacts { internal fun recordedClient(dir: File): String? = runCatching { File(dir, CLIENT_FILE).readText().trim() }.getOrNull()?.takeIf { it == "arm64" || it == "x86_64" } - private fun copySteamLogs(context: Context, dir: File, record: Record, steamArch: String? = null) { + private fun copySteamLogs( + context: Context, + dir: File, + record: Record, + steamArch: String? = null, + stopWhenSessionStarts: Boolean = false, + ) { val logs = File(steamArch?.let { SessionPrefs.steamRoot(context, it) } ?: SessionPrefs.activeSteamRoot(context), "logs") if (!logs.isDirectory) return val out = File(dir, "steam").apply { mkdirs() } - logs.listFiles { f -> f.isFile && f.length() < 8L * 1024 * 1024 }?.forEach { src -> + val sources = logs.listFiles { f -> f.isFile && f.length() < 8L * 1024 * 1024 } ?: return + for (src in sources) { + if (stopWhenSessionStarts && SessionState.running) { + record.failed = true + record.deferred = true + break + } try { val dst = File(out, src.name) - dst.bufferedWriter().use { w -> - src.forEachLine { line -> w.write(LogRedactor.redact(line)); w.newLine() } - } + dst.bufferedWriter().use { w -> LogRedactor.scrubTo(src, w) } record.files[dst] = Scrubbed(dst.length(), dst.lastModified()) } catch (e: Exception) { Log.w(TAG, "could not scrub ${src.name}", e) @@ -217,36 +274,65 @@ object SessionArtifacts { } @Synchronized - fun finishAbandoned(context: Context) { + fun finishAbandoned(context: Context, beforeGuestStart: Boolean = false) { + val stopWhenSessionStarts = !beforeGuestStart val parent = LinuxRuntime.logDir(context) val abandoned = parent.listFiles { f -> SessionPaths.isSessionFolder(f) && !File(f, COMPLETE_MARKER).exists() && !inFlight(f) }?.sortedWith(SessionPaths.chronological) ?: return if (abandoned.isEmpty()) return val current = SessionPaths.current() + val latestSession = SessionPaths.sessionFolders(context).lastOrNull() LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) - abandoned.forEachIndexed { i, dir -> - if (dir == current) return@forEachIndexed - val newest = i == abandoned.lastIndex + for (dir in abandoned) { + if (stopWhenSessionStarts && SessionState.running) break + if (dir == current) continue + val newest = dir == latestSession try { - File(dir, "ended-without-teardown.txt").writeText( - "This session's process ended without running its own teardown - killed by\n" + - "Android, a native crash, or the device going down - so the files below were\n" + - "gathered when the app next started, at ${now()}.\n" + - "The logs written during the session (session.log, app.log, wayland.log,\n" + - "audio.log, device.txt) were on disk already and are as they were left.\n" + - (if (newest) "" else "Steam's logs are not included: a later session has overwritten them.\n") + - "crash.log holds Android's crash buffer as of the next app start - if this\n" + - "session died of a crash, the entry is in there unless the device rebooted.\n" - ) + val recoveryNote = File(dir, "ended-without-teardown.txt") + val recoveryAttempted = recoveryNote.exists() + if (!recoveryAttempted) { + recoveryNote.writeText( + "This session's process ended without running its own teardown - killed by\n" + + "Android, a native crash, or the device going down - so the files below were\n" + + "gathered when the app next started, at ${now()}.\n" + + "The logs written during the session (session.log, app.log, wayland.log,\n" + + "audio.log, device.txt) were on disk already and are as they were left.\n" + + (if (newest) "" else "Steam's logs are not included: a later session has overwritten them.\n") + + "crash.log holds Android's crash buffer as of the next app start - if this\n" + + "session died of a crash, the entry is in there unless the device rebooted.\n" + ) + } val record = Record(dir) - if (newest) { - copySteamLogs(context, dir, record, recordedClient(dir)) - VacDiagnostics.collect(context, dir) + if (newest && !recoveryAttempted) { + copySteamLogs( + context, + dir, + record, + steamArch = recordedClient(dir), + stopWhenSessionStarts = stopWhenSessionStarts, + ) + if (!record.deferred && (!stopWhenSessionStarts || !SessionState.running)) { + VacDiagnostics.collect(context, dir) + } + } + if (record.deferred || stopWhenSessionStarts && SessionState.running) { + record.failed = true + record.deferred = true + markScrubbed(record) + break } SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) + if (stopWhenSessionStarts && SessionState.running) { + record.failed = true + record.deferred = true + markScrubbed(record) + break + } SessionEvents.record("session.artifacts_recovered", mapOf("newest" to newest), dir) - markScrubbed(scrubTree(record)) + val scrubbed = scrubTree(record, stopWhenSessionStarts = stopWhenSessionStarts) + markScrubbed(scrubbed) + if (scrubbed.deferred) break File(dir, COMPLETE_MARKER).writeText("collected: late, at next app start, ${now()}\n") Log.i(TAG, "finished the abandoned session folder $dir") } catch (e: Exception) { 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 e67092c1d0..f73609f442 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPaths.kt @@ -44,6 +44,10 @@ object SessionPaths { fun current(): File? = dir + /** Whether the current session folder will survive teardown. No session means the next one can retain logs. */ + fun currentSessionLogsRetained(context: Context): Boolean = + dir?.let { it.parentFile == SessionFiles.logDirectory(context) } ?: true + fun lastEnded(): File? = ended?.takeIf { it.isDirectory } @Synchronized 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 49aa2e9ba7..4cc0ac796a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -443,6 +443,16 @@ object SessionPrefs { fun setLogsEnabled(context: Context, on: Boolean) { prefs(context).edit().putBoolean("logs", on).apply() + publishGameEnvironment(context) + } + + /** Extra Proton, Wine and graphics diagnostics for the next game launch; off unless chosen. */ + fun gameDebugLogsEnabled(context: Context): Boolean = + prefs(context).getBoolean("gameDebugLogsEnabled", false) + + fun setGameDebugLogsEnabled(context: Context, on: Boolean) { + prefs(context).edit().putBoolean("gameDebugLogsEnabled", on).apply() + publishGameEnvironment(context) } fun storageDiagnosticsEnabled(context: Context): Boolean = diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 1d8db3d539..078ee5b721 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -322,7 +322,7 @@ class SessionService : Service() { SessionFiles.stage(this, root) // Earlier sessions' reports still read the Steam logs and VAC marker this session replaces. SessionArtifacts.awaitCollections() - SessionArtifacts.finishAbandoned(this) + SessionArtifacts.finishAbandoned(this, beforeGuestStart = true) VacDiagnostics.arm(this) com.droiddeck.launcher.agent.AgentGuest.reset(this) com.droiddeck.launcher.stores.gog.GogComet.begin() diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index f5304ed1ea..0c3cccf76a 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -19,7 +19,7 @@ object SettingsReset { "tuSysmem", "glThread", "noGlError", "zinkLazy", "mangoapp", "gpuClockPin", "gamescopeRealtime", "directAudio", "mic", "wifiDiscovery", "clientCpusOverride", "clientCpus", "gameCpus", "noXalia", "fastSync", "fsyncFirst", "syncFallback", "prootNoSeccomp", "prootFastPath", - "guestHostname", "fexPreset", "forceSsbs", "logs", "storageDiagnostics", + "guestHostname", "fexPreset", "forceSsbs", "logs", "gameDebugLogsEnabled", "storageDiagnostics", "upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias", "steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "questDefaultsV1", diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 543778b344..40dbcbf9c3 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -98,6 +98,8 @@ class FrontEndState( val frameGenLabel: String, val romsDir: String?, val logsEnabled: Boolean, + val gameDebugLogsEnabled: Boolean = false, + val gameDebugLogsNeedsRestart: Boolean = false, val vacDiagnostics: Boolean = false, val agentCommands: Boolean = false, val steamGames: List, @@ -195,6 +197,7 @@ class FrontEndActions( val onFiles: () -> Unit, val onBrowseFiles: (File) -> Unit = {}, val onLogs: () -> Unit, + val onGameDebugLogs: () -> Unit = {}, val onVacDiagnostics: () -> Unit = {}, val onAgentCommands: () -> Unit = {}, val onShareLogs: () -> Unit = {}, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 6ac40e8316..bc70d04042 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -436,6 +436,12 @@ internal fun SetupPanel( 4 -> { SettingsGroup(stringResource(R.string.setup_tab_diagnostics)) { ToggleRow(host, "logs", stringResource(R.string.setup_logs), stringResource(R.string.setup_logs_hint), s.logsEnabled) { a.onLogs() } + ToggleRow( + host, "game-debug-logs", stringResource(R.string.setup_game_debug_logs), + stringResource(if (s.gameDebugLogsNeedsRestart) R.string.setup_game_debug_logs_restart else R.string.setup_game_debug_logs_hint), + s.gameDebugLogsEnabled, + enabled = s.logsEnabled, + ) { a.onGameDebugLogs() } ToggleRow(host, "vacdiag", stringResource(R.string.setup_vac_diag), stringResource(R.string.setup_vac_diag_hint), s.vacDiagnostics) { a.onVacDiagnostics() } ToggleRow(host, "agent-commands", stringResource(R.string.setup_agent_commands), null, s.agentCommands) { a.onAgentCommands() } ActionRow(stringResource(R.string.setup_latest_logs), stringResource(R.string.drawer_logs_hint), stringResource(R.string.drawer_share_logs), a.onShareLogs, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c8f633854..95ae21ab4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -731,6 +731,9 @@ Session Session logs Saved after each session + Game debug logs + Include Proton, Wine and graphics diagnostics on the next game launch. Can reduce performance and use more storage. + Restart this session to save game debug logs Debugging tools Latest session logs Saved session logs diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index ddeb3ac1fa..77ed2b57c1 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -3,9 +3,14 @@ package com.droiddeck.launcher.core import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue +import org.junit.Rule import org.junit.Test +import org.junit.rules.TemporaryFolder +import java.io.StringWriter class LogRedactorTest { + @get:Rule val tmp = TemporaryFolder() + @Test fun labelledJwtIsRedacted() { val out = LogRedactor.redact("Using JWT 25484942796017334") assertFalse(out.contains("25484942796017334")) @@ -148,6 +153,71 @@ class LogRedactorTest { assertEquals(once, LogRedactor.redactForShare(once)) } + @Test fun anOversizedDirectInputIsWithheldBeforeRegex() { + val secret = "sessionid=abcdef123456" + val line = "x".repeat(LogRedactor.MAX_LINE_LENGTH) + secret + assertEquals(LogRedactor.OVERSIZED_LINE, LogRedactor.redact(line)) + assertEquals(LogRedactor.OVERSIZED_LINE, LogRedactor.redactForShare(line)) + } + + @Test fun streamWithholdsAnOversizedLogicalLineWholeAndContinues() { + val secret = "sessionid=abcdef123456" + val src = tmp.newFile("oversized.log") + src.writeText( + "before\r" + + "x".repeat(LogRedactor.MAX_LINE_LENGTH - 3) + secret + "\r\n" + + "after $secret" + ) + val out = StringWriter() + + LogRedactor.scrubTo(src, out) + + assertEquals( + "before\n${LogRedactor.OVERSIZED_LINE}\nafter sessionid=\n", + out.toString(), + ) + assertFalse(out.toString().contains("abcdef123456")) + } + + @Test fun aMaximumLengthLineBeforeCrLfIsStillScrubbed() { + val src = tmp.newFile("maximum.log") + val line = "x ".repeat(LogRedactor.MAX_LINE_LENGTH / 2) + src.writeText(line + "\r\n") + val out = StringWriter() + + LogRedactor.scrubTo(src, out) + + assertEquals(line + "\n", out.toString()) + assertFalse(out.toString().contains(LogRedactor.OVERSIZED_LINE)) + } + + @Test fun manyLearnedAccountsKeepBoundariesAndLiteralNames() { + val users = tmp.newFile("loginusers.vdf") + users.writeText((0 until 40).joinToString("\n") { + "\"AccountName\" \"probe_account_$it\"" + } + "\n\"PersonaName\" \"Player.+[40]\"\n") + try { + LogRedactor.learnAccounts(users) + assertEquals("owner= persona=", + LogRedactor.redact("owner=probe_account_39 persona=Player.+[40]")) + assertEquals("owner=probe_account_390", LogRedactor.redact("owner=probe_account_390")) + } finally { + LogRedactor.learnAccounts(tmp.root.resolve("missing-users")) + } + } + + @Test fun manyLearnedAddressesKeepOtherAddresses() { + val link = tmp.newFile("droiddeck-net") + link.writeText((1..40).joinToString("\n") { "addr 203.0.113.$it 24" }) + try { + LogRedactor.learnOwnAddresses(link) + assertEquals("local= server=203.0.113.200", + LogRedactor.redact("local=203.0.113.40 server=203.0.113.200")) + } finally { + LogRedactor.learnOwnAddresses(tmp.root.resolve("missing-network")) + } + } + @Test fun learnedAccountsComeFromBothClients() { val root = java.nio.file.Files.createTempDirectory("redactor").toFile() try { diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt index 6645c6ee17..f581e3ab44 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt @@ -4,6 +4,7 @@ import android.content.Context import com.droiddeck.launcher.core.GameEnvironment import com.droiddeck.launcher.runtime.LinuxRuntime import org.json.JSONObject +import org.junit.After import org.junit.Assert.* import org.junit.Before import org.junit.Test @@ -21,10 +22,78 @@ class GameEnvironmentStoreTest { @Before fun setUp() { context = RuntimeEnvironment.getApplication() + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .remove("logs") + .remove("gameDebugLogsEnabled") + .commit() guest = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-environment.json") File(context.filesDir, "game-environment.json").delete() } + @After fun tearDown() { + context.getSharedPreferences("session", Context.MODE_PRIVATE).edit() + .remove("logs") + .remove("gameDebugLogsEnabled") + .commit() + } + + @Test fun gameDebugLogsAreOffByDefault() { + assertFalse(SessionPrefs.gameDebugLogsEnabled(context)) + + GameEnvironmentStore.save(context, GameEnvironment.Config()) + + assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + } + + @Test fun gameDebugLogsRequireSessionLogsAndPreserveCustomDiagnostics() { + val config = GameEnvironment.Config(shared = mapOf("PROTON_LOG" to "0", "WINEDEBUG" to "+warn")) + GameEnvironmentStore.save(context, config) + + SessionPrefs.setGameDebugLogsEnabled(context, true) + var published = JSONObject(guest.readText()) + assertTrue(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + assertEquals("0", published.getJSONObject("shared").getString("PROTON_LOG")) + assertEquals("+warn", published.getJSONObject("shared").getString("WINEDEBUG")) + assertEquals(config, GameEnvironmentStore.read(context)) + + SessionPrefs.setLogsEnabled(context, false) + published = JSONObject(guest.readText()) + assertFalse(published.getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + + SessionPrefs.setLogsEnabled(context, true) + assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + } + + @Test fun gameDebugLogsWaitForARetainedSessionFolder() { + assertNull(SessionPaths.current()) + assertTrue(SessionPaths.currentSessionLogsRetained(context)) + SessionPrefs.setLogsEnabled(context, false) + val cacheSession = SessionPaths.beginOrCurrent(context, "game-debug-logs") + try { + assertFalse(SessionPaths.currentSessionLogsRetained(context)) + + SessionPrefs.setLogsEnabled(context, true) + SessionPrefs.setGameDebugLogsEnabled(context, true) + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + assertFalse(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + + assertEquals(cacheSession, SessionPaths.take()) + SessionPaths.release(context, cacheSession) + val retainedSession = SessionPaths.beginOrCurrent(context, "game-debug-logs") + assertTrue(SessionPaths.currentSessionLogsRetained(context)) + + GameEnvironmentStore.publish(context) + assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + assertEquals(retainedSession, SessionPaths.current()) + } finally { + SessionPaths.take()?.let { ended -> + SessionPaths.release(context, ended) + ended.deleteRecursively() + } + } + } + @Test fun savedSettingsAndPublishedSettingsPreserveUnsetsAndLiteralValues() { val config = GameEnvironment.Config( shared = mapOf("LITERAL" to "a=b 'quoted' $(echo test)", "EMPTY" to ""), diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index b91e5bcf67..61127bb9d7 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -131,4 +131,124 @@ class SessionLogShareTest { assertTrue("steam/console_log.txt" in names) assertFalse("steam/cef_log.previous.txt" in names) } + + @Test fun streamingComparisonPreservesUnchangedFileAndReplacesChangedFile() { + val folder = tmp.newFolder("2026-10-06-08-steam") + val unchanged = File(folder, "unchanged.log") + unchanged.bufferedWriter().use { out -> repeat(5000) { out.write("safe diagnostic $it\n") } } + val originalModified = 1_600_000_000_000L + assertTrue(unchanged.setLastModified(originalModified)) + val changed = File(folder, "changed.log") + changed.bufferedWriter().use { out -> + repeat(5000) { out.write("safe diagnostic $it\n") } + out.write("$secret\n") + } + + assertTrue(SessionArtifacts.scrubAndMark(folder)) + + assertEquals(originalModified, unchanged.lastModified()) + assertFalse(changed.readText().contains(leaked)) + assertTrue(changed.readText().contains("sessionid=")) + } + + @Test fun historicalScrubDefersWithoutLeavingMarkersAndResumes() { + val folder = tmp.newFolder("2026-10-06-09-steam") + val log = File(folder, "session.log").apply { writeText("$secret\n") } + val rulesMarker = File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").apply { writeText("stale\n") } + val treeMarker = File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply { writeText("rules ${LogRedactor.RULES_VERSION}\n") } + + SessionState.running = true + try { + assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true)) + } finally { + SessionState.running = false + } + assertFalse(rulesMarker.exists()) + assertFalse(treeMarker.exists()) + assertTrue(log.readText().contains(leaked)) + + assertTrue(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true)) + assertFalse(log.readText().contains(leaked)) + assertTrue(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").isFile) + } + + @Test fun recoveryRetryKeepsItsSteamLogsWhenALaterSessionLeftNoFolder() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2026-10-08-01-steam").apply { mkdirs() } + val saved = File(folder, "steam/console_log.txt").apply { + parentFile!!.mkdirs() + writeText("session A\n") + } + File(folder, "ended-without-teardown.txt").writeText("recovery attempted before session B\n") + val runtime = File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply { + parentFile!!.mkdirs() + writeText("session B\n") + } + + SessionArtifacts.finishAbandoned(context) + + assertEquals("session A\n", saved.readText()) + assertEquals("session B\n", runtime.readText()) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + } + + @Test fun abandonedRecoveryDoesNotCopyLogsFromANewerCompletedSession() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context) + val folder = File(logs, "2026-10-08-02-steam").apply { mkdirs() } + val saved = File(folder, "steam/console_log.txt").apply { + parentFile!!.mkdirs() + writeText("session A\n") + } + File(logs, "2026-10-08-03-steam").apply { mkdirs() } + .resolve(SessionArtifacts.COMPLETE_MARKER).writeText("finished session B\n") + File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/Steam/logs/console_log.txt").apply { + parentFile!!.mkdirs() + writeText("session B\n") + } + + SessionArtifacts.finishAbandoned(context) + + assertEquals("session A\n", saved.readText()) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + } + + @Test fun startupRecoveryRunsBeforeVacMarkerArmWhileOrdinaryCleanupDefers() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context) + val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2999-12-31-99-startup-recovery") + val marker = File(root, "root/.droiddeck-vac-diagnostics") + val launches = File(root, "root/.droiddeck-vac-launches") + val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/startup-recovery-vac.log") + val previousRunning = SessionState.running + val previousPhase = SessionState.phase + try { + folder.deleteRecursively() + folder.mkdirs() + SessionArtifacts.recordClient(folder, "arm64") + marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") } + launches.writeText("startup VAC evidence\n") + runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("startup VAC evidence\n") } + SessionState.running = true + SessionState.phase = SessionPhase.STARTING_GUEST + + SessionArtifacts.finishAbandoned(context) + + assertFalse(File(folder, "ended-without-teardown.txt").exists()) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + + SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) + + assertEquals("startup VAC evidence\n", File(folder, "steam/startup-recovery-vac.log").readText()) + assertTrue(File(folder, "vac.txt").readText().contains("startup VAC evidence")) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + } finally { + SessionState.running = previousRunning + SessionState.phase = previousPhase + folder.deleteRecursively() + runtimeSteamLog.delete() + marker.delete() + launches.delete() + } + } } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 95893adde6..94832edcc6 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -2,6 +2,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.runtime.LinuxRuntime import java.io.File +import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -20,6 +21,49 @@ import org.robolectric.annotation.Config class SessionLogShareZipTest { private val app get() = RuntimeEnvironment.getApplication() + @Test fun aLargeSteamLogIsRedactedInTheSharedArchive() { + val session = File(LinuxRuntime.logDir(app), "2026-10-08-02-steam").apply { mkdirs() } + val raw = File(session, "steam-42.log") + val earlySecret = "early-sessionid-abcdef123456" + val trailingSecret = "late-refresh-token-abcdef123456" + try { + // One long line exercises the streaming limit; the final ordinary line must still be redacted. + raw.bufferedWriter().use { out -> + out.write("sessionid=$earlySecret") + val chunk = "x".repeat(8192) + repeat(8192) { out.write(chunk) } + out.write("\nrefresh_token=$trailingSecret\n") + } + assertTrue(raw.length() > 64L * 1024 * 1024) + + val zip = SessionLogShare.zipFolder(app, session)!! + ZipFile(zip).use { archive -> + val entry = archive.getEntry("${session.name}/steam-42.log")!! + archive.getInputStream(entry).use { input -> + // Only inspect the bounded scrubbed prefix: the pre-fix raw archive is over 64 MiB. + val expected = "${com.droiddeck.launcher.core.LogRedactor.OVERSIZED_LINE}\n" + val prefix = ByteArray(expected.toByteArray(StandardCharsets.UTF_8).size) + var offset = 0 + while (offset < prefix.size) { + val count = input.read(prefix, offset, prefix.size - offset) + assertTrue("zip entry ended before its scrubbed prefix", count > 0) + offset += count + } + assertEquals(expected, String(prefix, StandardCharsets.UTF_8)) + input.bufferedReader().use { reader -> + val trailing = requireNotNull(reader.readLine()) + assertFalse("trailing secret survived", trailing.contains(trailingSecret)) + assertEquals("refresh_token=", trailing) + assertEquals(null, reader.readLine()) + } + } + } + } finally { + SessionLogShare.clear(app) + session.deleteRecursively() + } + } + @Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() { val logs = LinuxRuntime.logDir(app) val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt index e636bee703..fbda857653 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SettingsResetTest.kt @@ -32,6 +32,7 @@ class SettingsResetTest { SessionPrefs.setHdr(app, SessionService.MODE_DESKTOP, true) SessionPrefs.setResolutionChoice(app, SessionService.MODE_STEAM, "1280x800") SessionPrefs.setGuestHostname(app, "MyDeck") + SessionPrefs.setGameDebugLogsEnabled(app, true) ControllerPrefs.setOpacity(app, 40) AppUiPrefs.setScale(app, 150) FrameGen.set(app, FrameGen.Mode(FrameGen.ENGINE_WINFG, 3)) @@ -45,6 +46,10 @@ class SettingsResetTest { assertFalse(SessionPrefs.hdr(app, SessionService.MODE_DESKTOP)) assertFalse(SessionPrefs.resolutionChosen(app, SessionService.MODE_STEAM)) assertEquals(SessionPrefs.DEFAULT_GUEST_HOSTNAME, SessionPrefs.guestHostname(app)) + assertFalse(SessionPrefs.gameDebugLogsEnabled(app)) + val guest = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), + "root/.config/droiddeck/game-environment.json") + assertFalse(org.json.JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) assertEquals(100, ControllerPrefs.read(app).opacity) assertEquals(AppUiPrefs.DEFAULT_SCALE, AppUiPrefs.scale(app)) assertEquals(FrameGen.Mode.OFF.engine, FrameGen.engine(app)) diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 2bbf28c786..e0a416e914 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -50,6 +50,44 @@ environment entries and is intentionally narrower than **Reset game profile**. Values are literal strings, with no shell expansion; quotes are only needed when the consuming program expects them. +## Game debug logs + +Under **Setup > Diagnostics**, enable **Session logs** and **Game debug logs** +before reproducing a Windows game problem. Game debug logs is off by default and +is available when Session logs is enabled. It applies to the next game launch through DroidDeck's +Valve or third-party Proton wrapper, including added games and store shortcuts. +A running game must be restarted. If the current session began with Session logs +disabled, restart that session first: its existing log folder is disposable, and +the UI shows a restart reminder instead of enabling logs that would be discarded. + +| Generated setting | Effective value while enabled | +| --- | --- | +| `PROTON_LOG` | `1` | +| `PROTON_LOG_DIR`, `PROTON_CRASH_REPORT_DIR`, `DXVK_LOG_PATH` | The actual session log directory | +| `DXVK_LOG_LEVEL` | `debug` | +| `VKD3D_DEBUG` | `info` | +| `WINEDEBUG` | Valid custom channels plus Proton's standard diagnostic channels | + +Diagnostics take precedence over conflicting inherited, shared, or per-game log +settings while the switch is on. Wine channel selectors are normalized and +deduplicated with the last selector winning; required exception, module, and +timestamp channels are applied last, including when a profile contains `-all`. +Custom channels from `PROTON_LOG` are retained when valid. Malformed channel tokens +are omitted; an oversized list falls back to the standard diagnostic channels. + +Saved profiles and Steam launch options are unchanged. The launcher merges a +process-environment map, so every variable has one value and paths containing +spaces, quotes, or shell characters stay literal. Existing arguments and +`%command%` are not reconstructed. Disabling the switch restores the user's normal +settings on the next launch. It does not change Steam probes or native Linux +programs, whose ordinary output remains in the session log. + +After reproducing once, stop the session and use **Latest session logs > Share +logs**. The archive includes the generated Wine/Proton and graphics logs. Debug +logging can reduce performance and consume storage; disable it after collecting +the report. If the session log directory is unavailable, the launcher reports +that diagnostics were skipped instead of writing uncollected files elsewhere. + ## Defaults and available suggestions The initial configuration enables Mesa shader caching with diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index 30c8a25552..2d211c93a0 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -179,6 +179,59 @@ def apply_config(env, config, app_id, fixes=None): return result +GAME_DEBUG_CHANNELS = ( + "timestamp", "pid", "tid", "seh", "unwind", "threadname", "debugstr", "loaddll", "mscoree", +) +WINE_DEBUG_SELECTOR = re.compile(r"(?:(trace|warn|err|fixme))?([+-])([A-Za-z_][A-Za-z0-9_]*)") + + +def game_debug_channels(*values): + """Normalize Wine selectors, retaining custom channels before required diagnostics.""" + selectors = {} + for value in values: + if not isinstance(value, str) or "\0" in value or len(value) > 8192: + continue + for part in value.split(","): + part = part.strip() + match = WINE_DEBUG_SELECTOR.fullmatch(part) + if match is None: + continue + key = (match[1] or "", match[3]) + # Move the last value to the end: global +/-all and per-class selectors + # have ordered semantics, so replacing a value in its old position is wrong. + selectors.pop(key, None) + selectors[key] = part + for channel in GAME_DEBUG_CHANNELS: + key = ("", channel) + selectors.pop(key, None) + selectors[key] = "+" + channel + formatted = ",".join(selectors.values()) + if len(formatted) > 8192: + formatted = ",".join("+" + channel for channel in GAME_DEBUG_CHANNELS) + return formatted + + +def apply_game_debug_logs(env, config, debug_dir): + """Apply app-owned diagnostics to a real game, without editing its launch command.""" + if not isinstance(config, dict) or config.get("version") != 1 or config.get("gameDebugLogs") is not True: + return env + if (not isinstance(debug_dir, str) or "\0" in debug_dir or len(debug_dir) > 8192 + or not os.path.isabs(debug_dir) or not os.path.isdir(debug_dir)): + print("droiddeck-game-env: game debug logs skipped; session log directory unavailable", file=sys.stderr) + return env + result = dict(env) + result.update({ + "PROTON_LOG": "1", + "PROTON_LOG_DIR": debug_dir, + "PROTON_CRASH_REPORT_DIR": debug_dir, + "DXVK_LOG_PATH": debug_dir, + "DXVK_LOG_LEVEL": "debug", + "VKD3D_DEBUG": "info", + "WINEDEBUG": game_debug_channels(env.get("WINEDEBUG"), env.get("PROTON_LOG")), + }) + return result + + def sync_config(config, app_id): games = config.get("games", {}) return { @@ -279,6 +332,7 @@ def main(): return 2 env = os.environ.copy() mic_enabled = env.get("BL_MIC_ENABLED") + debug_dir = env.get("BL_DEBUG_DIR", "") mark_install_scripts(command, env) app_id = game_id(env) if app_id: @@ -295,6 +349,7 @@ def main(): own = fixes.get("WINEDLLOVERRIDES") fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components path = Path.home() / ".config/droiddeck/game-environment.json" + config = {} try: with path.open(encoding="utf-8") as source: config = json.load(source) @@ -307,6 +362,11 @@ def main(): env = apply_config(env, {"version": 1}, app_id, fixes) except (OSError, ValueError, TypeError, AttributeError): print("droiddeck-game-env: invalid configuration; using inherited environment", file=sys.stderr) + if waiting: + before_debug = env + env = apply_game_debug_logs(env, config, debug_dir) + if env is not before_debug: + print("droiddeck-game-env: game debug logs enabled for this launch", file=sys.stderr) if mic_enabled == "0": env["BANNER_AUDIO_DIRECT_MIC"] = "0" env = force_ssbs(command, env) diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index 26612ec383..2472c2aef3 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -26,6 +26,121 @@ def config_text(entries): return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping +class GameDebugLoggingTest(unittest.TestCase): + def test_real_game_launch_without_config_file_keeps_the_base_environment(self): + with tempfile.TemporaryDirectory() as tmp: + home = Path(tmp) + probe = home / "proton" + probe.write_text("#!" + sys.executable + "\nimport os\nprint(os.environ['PROTON_LOG'])\n") + probe.chmod(0o755) + result = subprocess.run( + [sys.executable, str(BIN / "droiddeck-game-env"), str(probe), "waitforexitandrun"], + env={**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"), + "BL_DEBUG_DIR": tmp, "PROTON_LOG": "0"}, + text=True, capture_output=True, check=True, + ) + self.assertEqual(result.stdout.strip(), "0") + + def test_game_debug_logs_override_only_diagnostic_values_and_keep_raw_settings(self): + with tempfile.TemporaryDirectory(prefix="game logs '") as debug_dir: + inherited = {"BL_DEBUG_DIR": debug_dir, "PROTON_LOG": "0", "WINEDEBUG": "-all,+relay", + "PROTON_LOG_DIR": "/old", "PROTON_CRASH_REPORT_DIR": "/old-crashes", + "DXVK_LOG_PATH": "/old-dxvk", "DXVK_LOG_LEVEL": "none", "VKD3D_DEBUG": "none", + "CUSTOM": "$(touch never); 'quoted' = literal", "DXVK_CONFIG": "dxvk.tearFree = True"} + config = {"version": 1, "gameDebugLogs": True, + "shared": {"PROTON_LOG": "0", "BL_DEBUG_DIR": "/profile-redirect"}, + "games": {"42": {"PROTON_LOG_DIR": None, "DXVK_LOG_PATH": "/game-redirect"}}} + normal = MODULE["apply_config"](inherited, config, "42") + debug = MODULE["apply_game_debug_logs"](normal, config, inherited["BL_DEBUG_DIR"]) + self.assertEqual(debug["PROTON_LOG"], "1") + for key in ("PROTON_LOG_DIR", "PROTON_CRASH_REPORT_DIR", "DXVK_LOG_PATH"): + self.assertEqual(debug[key], debug_dir) + self.assertEqual(debug["DXVK_LOG_LEVEL"], "debug") + self.assertEqual(debug["VKD3D_DEBUG"], "info") + self.assertIn("+relay", debug["WINEDEBUG"].split(",")) + self.assertTrue(debug["WINEDEBUG"].endswith("+loaddll,+mscoree")) + for key in ("CUSTOM", "DXVK_CONFIG", "BL_DEBUG_DIR"): + self.assertEqual(debug[key], normal[key]) + self.assertEqual(normal["PROTON_LOG"], "0") + self.assertEqual(inherited["PROTON_LOG_DIR"], "/old") + self.assertIs(MODULE["apply_game_debug_logs"](normal, {**config, "gameDebugLogs": False}, debug_dir), normal) + self.assertEqual(MODULE["apply_game_debug_logs"](debug, config, debug_dir), debug) + + def test_wine_debug_channels_are_formatted_deduplicated_and_diagnostics_win(self): + formatted = MODULE["game_debug_channels"]( + " +relay, trace-vulkan, -all, -seh, +relay, trace+vulkan, garbage, $(touch never) ", + "+seh,warn-foo,warn+foo,+relay", + ) + self.assertEqual(formatted, "-all,trace+vulkan,warn+foo,+relay," + + "+timestamp,+pid,+tid,+seh,+unwind,+threadname,+debugstr,+loaddll,+mscoree") + self.assertEqual(MODULE["game_debug_channels"](formatted, "1"), formatted) + self.assertNotIn("-seh", formatted) + for value in ("x\0,+relay", "+" + "x" * 8192, 1, None): + self.assertEqual(MODULE["game_debug_channels"](value), MODULE["game_debug_channels"]()) + oversized = ",".join("+channel_" + str(i) for i in range(550)) + other = ",".join("+other_" + str(i) for i in range(550)) + self.assertLessEqual(len(MODULE["game_debug_channels"](oversized, other)), 8192) + self.assertTrue(MODULE["game_debug_channels"](oversized, other).endswith("+loaddll,+mscoree")) + + def test_game_debug_logs_require_opt_in_and_a_real_session_log_directory(self): + env = {"PROTON_LOG": "user", "CUSTOM": "keep"} + for config in ({}, {"version": 1}, {"version": 1, "gameDebugLogs": False}, + {"version": 1, "gameDebugLogs": "true"}, {"version": 2, "gameDebugLogs": True}): + self.assertIs(MODULE["apply_game_debug_logs"](env, config, "/"), env) + with tempfile.TemporaryDirectory() as tmp: + not_a_directory = Path(tmp) / "file" + not_a_directory.write_text("file") + for path in (None, "", "relative", "bad\0path", str(not_a_directory), str(Path(tmp) / "missing")): + with self.subTest(path=path): + self.assertIs(MODULE["apply_game_debug_logs"](env, {"version": 1, "gameDebugLogs": True}, path), env) + + def test_game_debug_toggle_is_live_preserves_command_and_excludes_probes(self): + with tempfile.TemporaryDirectory() as tmp: + home = Path(tmp) + config_path = home / ".config/droiddeck/game-environment.json" + config_path.parent.mkdir(parents=True) + debug_dir = home / "session logs '$literal; directory'" + debug_dir.mkdir() + probe = home / "fake proton" + probe.write_text("#!" + sys.executable + "\nimport json, os, sys\n" + "print(json.dumps({'env': dict(os.environ), 'argv': sys.argv[1:]}))\n") + probe.chmod(0o755) + literal = "$(touch " + str(home / "never-created") + "); 'literal'=value" + config = {"version": 1, "gameDebugLogs": True, + "shared": {"PROTON_LOG": "0", "WINEDEBUG": "-all,+relay", "CUSTOM": literal, + "BL_DEBUG_DIR": "/profile-must-not-redirect"}} + env = {**os.environ, "HOME": tmp, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/42"), + "BL_DEBUG_DIR": str(debug_dir), "PROTON_LOG": "0", "WINEDEBUG": "-all"} + command = [str(probe), "waitforexitandrun", "game 'with quotes'.exe", "argument with spaces", "$(literal)", "%command%"] + + def launch(arguments, environment): + result = subprocess.run([sys.executable, str(BIN / "droiddeck-game-env"), *arguments], + env=environment, text=True, capture_output=True, check=True) + return json.loads(result.stdout) + + for enabled in (True, False, True): + config_path.write_text(json.dumps({**config, "gameDebugLogs": enabled})) + result = launch(command, env) + self.assertEqual(result["argv"], command[1:]) + self.assertEqual(result["env"]["CUSTOM"], literal) + self.assertEqual(result["env"]["PROTON_LOG"], "1" if enabled else "0") + if enabled: + self.assertEqual(result["env"]["PROTON_LOG_DIR"], str(debug_dir)) + self.assertIn("+relay", result["env"]["WINEDEBUG"].split(",")) + self.assertIn("+seh", result["env"]["WINEDEBUG"].split(",")) + else: + self.assertEqual(result["env"]["WINEDEBUG"], "-all,+relay") + for verb, prefix in (("run", "42"), ("waitforexitandrun", "0"), ("waitforexitandrun", "not-a-game")): + result = launch([str(probe), verb], {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata" / prefix)}) + self.assertEqual(result["env"]["PROTON_LOG"], "0") + self.assertEqual(result["env"]["WINEDEBUG"], "-all") + # Non-Steam shortcuts use the same normalized unsigned compatdata identity. + result = launch(command, {**env, "STEAM_COMPAT_DATA_PATH": str(home / "compatdata/-1")}) + self.assertEqual(result["env"]["PROTON_LOG"], "1") + self.assertFalse((home / "never-created").exists()) + self.assertEqual(json.loads(config_path.read_text())["shared"], config["shared"]) + + class ReadConfigMappingTest(unittest.TestCase): def test_missing_parent_or_unbalanced_vdf_is_not_treated_as_absent_choices(self): with tempfile.TemporaryDirectory() as tmp: From 536bb11df83fde0101c8108880c0c63756f1ee58 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 03:22:32 -0500 Subject: [PATCH 02/13] Preserve Android shared-library names in logs --- .../droiddeck/launcher/core/LogRedactor.kt | 18 ++++++++- .../launcher/core/LogRedactorTest.kt | 39 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index f3103625d5..aed8f9bcd4 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -47,7 +47,21 @@ object LogRedactor { out.toString() } + private fun matchesEntire(input: String, regex: Regex): Boolean = + withMatcher(regex, input) { it.matches() } + + private fun isHidlSharedLibrary(input: String, match: java.util.regex.Matcher): Boolean { + if (!matchesEntire(match.group(), HIDL_SHARED_LIBRARY)) return false + fun continuesToken(char: Char) = char.isLetterOrDigit() || char in "._%+@-" + return (match.start() == 0 || !continuesToken(input[match.start() - 1])) && + (match.end() == input.length || !continuesToken(input[match.end()])) + } + private val EMAIL = Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}") + private val HIDL_SHARED_LIBRARY = Regex( + "(?:android\\.(?:hardware|frameworks|hidl|system)|vendor\\.[A-Za-z0-9_]+\\.hardware)" + + "(?:\\.[A-Za-z0-9_]+)+@[0-9]+\\.[0-9]+(?:-[A-Za-z0-9_]+)*\\.so" + ) private val JWT_LABELLED = Regex("(?i)(\\bJWT[\\s=:]+)(\\d{8,})") private val JWT_BASE64 = Regex("ey[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}") private val GUID = Regex("\\b[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\b") @@ -345,7 +359,9 @@ object LogRedactor { } if (out.has("login")) out.set(replaceMatches(out.text, LOGIN_KV) { "${it.group(1)}${it.group(2)}${quoted(it.group(3))}" }) for (r in accounts) if (r.needs == null || out.has(r.needs)) out.set(replaceMatches(out.text, r.regex, "")) - if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL, "")) + if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL) { m -> + m.group().takeIf { isHidlSharedLibrary(out.text, m) } ?: "" + }) if (out.has("jwt", "token", "ticket", "sessionid", "steamloginsecure", "machineauth")) { out.set(replaceMatches(out.text, RESIDUAL) { "${it.group(1)}=" }) } diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index 77ed2b57c1..50a9364422 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -42,6 +42,45 @@ class LogRedactorTest { assertEquals("login ok", LogRedactor.redact("login someone@example.com ok")) } + @Test fun hidlSharedLibrariesStayVisibleWhileAdjacentSecretsAndEmailsAreRedacted() { + val library = "android.hardware.graphics.mapper@4.0.so" + val vendorLibrary = "vendor.qti.hardware.display.mapper@4.0.so" + val line = "/vendor/lib64/hw/$library loaded $vendorLibrary contact=someone@company.so token=abcdef123456" + val expected = "/vendor/lib64/hw/$library loaded $vendorLibrary contact= token=" + + assertEquals(expected, LogRedactor.redact(line)) + assertEquals(expected, LogRedactor.redactForShare(line)) + } + + @Test fun privacyRulesOverrideTheHidlSharedLibraryException() { + val library = "android.hardware.graphics.mapper@4.0.so" + assertEquals("token=", LogRedactor.redact("token=$library")) + assertEquals("username=", LogRedactor.redact("username=$library")) + + val users = tmp.newFile("hidl-loginusers.vdf") + users.writeText("\"AccountName\" \"$library\"") + try { + LogRedactor.learnAccounts(users) + assertEquals("", LogRedactor.redact(library)) + } finally { + LogRedactor.learnAccounts() + } + } + + @Test fun onlyExactHidlSharedLibraryNamesBypassEmailRedaction() { + val library = "android.hardware.graphics.mapper@4.0.so" + + assertEquals(library, LogRedactor.redact(library)) + assertEquals("", LogRedactor.redact("$library.evil")) + assertEquals("", LogRedactor.redact("someone@company.so")) + assertEquals("", LogRedactor.redact("not$library")) + assertEquals("_debug", LogRedactor.redact("${library}_debug")) + assertEquals(".1", LogRedactor.redact("${library}.1")) + assertEquals("@attacker", LogRedactor.redact("${library}@attacker")) + assertEquals("", LogRedactor.redact("android.hardware.graphics.mapper@4.0.software")) + assertEquals("", LogRedactor.redact("android.hardware.graphics.mapper@4.0.so.evil")) + } + @Test fun clockTimeIsNotAnAddress() { val line = "[2026-09-27 10:03:05] Startup" assertEquals(line, LogRedactor.redact(line)) From 66f5d39bab495bc4cc95cc134ff2775b90e4818b Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 03:36:30 -0500 Subject: [PATCH 03/13] Fix game diagnostics recovery races --- .../com/droiddeck/launcher/MainActivity.kt | 10 +- .../droiddeck/launcher/core/LogRedactor.kt | 31 +++- .../launcher/session/GameEnvironmentStore.kt | 10 +- .../launcher/session/SessionArtifacts.kt | 150 ++++++++++++++---- .../launcher/session/SessionPrefs.kt | 61 ++++++- .../launcher/session/SessionService.kt | 1 + .../launcher/session/VacDiagnostics.kt | 8 +- app/src/main/res/values/strings.xml | 1 + .../launcher/core/LogRedactorTest.kt | 13 ++ .../session/GameEnvironmentStoreTest.kt | 18 +++ .../launcher/session/SessionLogShareTest.kt | 126 +++++++++++++++ 11 files changed, 374 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index 632f95af98..7c9448a311 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -918,13 +918,19 @@ class MainActivity : ComponentActivity() { .putExtra(com.droiddeck.launcher.files.FileManagerActivity.EXTRA_START_DIR, dir.absolutePath)) }, onLogs = { - SessionPrefs.setLogsEnabled(this, !SessionPrefs.logsEnabled(this)) + val changed = SessionPrefs.setLogsEnabled(this, !SessionPrefs.logsEnabled(this)) + if (!changed) android.widget.Toast.makeText( + this, R.string.setup_logging_update_failed, android.widget.Toast.LENGTH_LONG, + ).show() logsEnabled = SessionPrefs.logsEnabled(this) gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() }, onGameDebugLogs = { - SessionPrefs.setGameDebugLogsEnabled(this, !SessionPrefs.gameDebugLogsEnabled(this)) + val changed = SessionPrefs.setGameDebugLogsEnabled(this, !SessionPrefs.gameDebugLogsEnabled(this)) + if (!changed) android.widget.Toast.makeText( + this, R.string.setup_logging_update_failed, android.widget.Toast.LENGTH_LONG, + ).show() gameDebugLogsEnabled = SessionPrefs.gameDebugLogsEnabled(this) gameDebugLogsNeedsRestart = gameDebugLogsNeedsRestart() }, diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index aed8f9bcd4..1a870fa010 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -223,9 +223,11 @@ object LogRedactor { "(? Boolean = { false }, + ): Boolean = scrubLines(src, out, ::redact, shouldStop) fun redactForShare(line: String): String { if (line.isEmpty()) return line @@ -238,11 +240,18 @@ object LogRedactor { } } - fun scrubForShare(src: java.io.File, out: java.io.Writer) { - scrubLines(src, out, ::redactForShare) - } + fun scrubForShare( + src: java.io.File, + out: java.io.Writer, + shouldStop: () -> Boolean = { false }, + ): Boolean = scrubLines(src, out, ::redactForShare, shouldStop) - private fun scrubLines(src: java.io.File, out: java.io.Writer, scrub: (String) -> String) { + private fun scrubLines( + src: java.io.File, + out: java.io.Writer, + scrub: (String) -> String, + shouldStop: () -> Boolean, + ): Boolean { src.bufferedReader().use { input -> val chunk = CharArray(8192) val line = StringBuilder(4096) @@ -259,8 +268,10 @@ object LogRedactor { } while (true) { + if (shouldStop()) return false val count = input.read(chunk) if (count < 0) break + if (shouldStop()) return false for (i in 0 until count) { val char = chunk[i] if (pendingCarriageReturn) { @@ -284,8 +295,12 @@ object LogRedactor { } } } - if (pendingCarriageReturn || pendingContent) emit() + if (pendingCarriageReturn || pendingContent) { + if (shouldStop()) return false + emit() + } } + return true } private fun quoted(value: String): String { diff --git a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt index e64f12343d..8c50e0a37d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/GameEnvironmentStore.kt @@ -80,7 +80,11 @@ object GameEnvironmentStore { } @Synchronized - fun publish(context: Context, config: GameEnvironment.Config = read(context)) { + fun publish( + context: Context, + config: GameEnvironment.Config = read(context), + gameDebugLogsOverride: Boolean? = null, + ) { val resolved = config.copy(shared = GameEnvironment.defaults(SessionPrefs.fexPreset(context), SessionPrefs.forceSsbs(context)) + config.shared) val json = encode(resolved) val dxvk = TextureFiltering.dxvkOptions( @@ -105,8 +109,8 @@ object GameEnvironmentStore { if (gameDxvk.length() > 0) json.put(DXVK_CONFIG_GAMES, gameDxvk) json.put( GAME_DEBUG_LOGS, - SessionPrefs.logsEnabled(context) && SessionPrefs.gameDebugLogsEnabled(context) && - SessionPaths.currentSessionLogsRetained(context), + gameDebugLogsOverride ?: (SessionPrefs.logsEnabled(context) && + SessionPrefs.gameDebugLogsEnabled(context) && SessionPaths.currentSessionLogsRetained(context)), ) write(File(LinuxRuntime.rootDir(context), GUEST_FILE), json.toString()) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 6d961d1f7e..9027d7dceb 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -16,6 +16,9 @@ object SessionArtifacts { const val COMPLETE_MARKER = ".complete" + private const val RECOVERY_RUNTIME_CAPTURED_MARKER = ".recovery-runtime-captured" + private const val RECOVERY_RUNTIME_EXPIRED_MARKER = ".recovery-runtime-expired" + private val SCRUBBED_MARKER = ".scrubbed-r${LogRedactor.RULES_VERSION}" private val OLD_SCRUBBED_MARKER = Regex("""\.scrubbed-(r?\d+)""") @@ -112,46 +115,79 @@ object SessionArtifacts { var deferred = false } - private fun scrubFolder(dir: File, record: Record, stopWhenSessionStarts: Boolean): Boolean { + private sealed class ScrubResult { + class Done(val scrubbed: Scrubbed) : ScrubResult() + object Failed : ScrubResult() + object Deferred : ScrubResult() + } + + private fun scrubFolder(dir: File, record: Record, shouldStop: () -> Boolean): Boolean { val files = dir.listFiles { f -> f.isFile && !f.name.startsWith(".") && f !in record.files } ?: return true for (f in files) { - if (stopWhenSessionStarts && SessionState.running) return false + if (shouldStop()) return false if (!LogRedactor.isText(f)) continue - val done = scrubFile(dir, f) - if (done == null) record.failed = true else record.files[f] = done + when (val result = scrubFile(dir, f, shouldStop)) { + is ScrubResult.Done -> record.files[f] = result.scrubbed + ScrubResult.Failed -> record.failed = true + ScrubResult.Deferred -> { + record.failed = true + record.deferred = true + return false + } + } } return true } - private fun scrubFile(dir: File, f: File): Scrubbed? { + private fun scrubFile(dir: File, f: File, shouldStop: () -> Boolean): ScrubResult { val tmp = File(dir, ".${f.name}.scrub") return try { val before = Scrubbed(f.length(), f.lastModified()) - tmp.bufferedWriter().use { w -> LogRedactor.scrubTo(f, w) } - val scrubbedLength = tmp.length() - if (sameContents(tmp, f)) { + val scrubbed = tmp.bufferedWriter().use { w -> LogRedactor.scrubTo(f, w, shouldStop) } + if (!scrubbed) { tmp.delete() - before.takeIf { f.length() == it.length && f.lastModified() == it.modified } - } else { - if (!tmp.renameTo(f)) { - tmp.inputStream().use { input -> f.outputStream().use { output -> input.copyTo(output, 64 * 1024) } } + return ScrubResult.Deferred + } + val scrubbedLength = tmp.length() + when (sameContents(tmp, f, shouldStop)) { + null -> { tmp.delete() + ScrubResult.Deferred + } + true -> { + tmp.delete() + before.takeIf { f.length() == it.length && f.lastModified() == it.modified } + ?.let { ScrubResult.Done(it) } ?: ScrubResult.Failed + } + false -> { + if (shouldStop()) { + tmp.delete() + return ScrubResult.Deferred + } + if (!tmp.renameTo(f)) { + tmp.delete() + return ScrubResult.Failed + } + Scrubbed(scrubbedLength, f.lastModified()).takeIf { f.length() == it.length } + ?.let { ScrubResult.Done(it) } ?: ScrubResult.Failed } - Scrubbed(scrubbedLength, f.lastModified()).takeIf { f.length() == it.length } } } catch (e: Exception) { Log.w(TAG, "could not scrub ${f.name}", e) tmp.delete() - null + ScrubResult.Failed } } - private fun sameContents(a: File, b: File): Boolean { + internal fun sameContents(a: File, b: File, shouldStop: () -> Boolean = { false }): Boolean? { + if (shouldStop()) return null if (a.length() != b.length()) return false - fun readChunk(input: java.io.InputStream, buffer: ByteArray): Int { + fun readChunk(input: java.io.InputStream, buffer: ByteArray): Int? { var count = 0 while (count < buffer.size) { + if (shouldStop()) return null val read = input.read(buffer, count, buffer.size - count) + if (shouldStop()) return null if (read < 0) break if (read == 0) continue count += read @@ -163,10 +199,11 @@ object SessionArtifacts { val leftBuffer = ByteArray(64 * 1024) val rightBuffer = ByteArray(64 * 1024) while (true) { - val leftCount = readChunk(left, leftBuffer) - val rightCount = readChunk(right, rightBuffer) + val leftCount = readChunk(left, leftBuffer) ?: return null + val rightCount = readChunk(right, rightBuffer) ?: return null if (leftCount != rightCount) return false if (leftCount == 0) break + if (shouldStop()) return null for (i in 0 until leftCount) if (leftBuffer[i] != rightBuffer[i]) return false } true @@ -211,24 +248,29 @@ object SessionArtifacts { }.toSet() } - internal fun scrubAndMark(dir: File, stopWhenSessionStarts: Boolean = false): Boolean { - val record = scrubTree(Record(dir), stopWhenSessionStarts) - if (stopWhenSessionStarts && SessionState.running) { + internal fun scrubAndMark( + dir: File, + stopWhenSessionStarts: Boolean = false, + sessionStarted: () -> Boolean = { SessionState.running }, + ): Boolean { + val shouldStop = { stopWhenSessionStarts && sessionStarted() } + val record = scrubTree(Record(dir), shouldStop) + if (shouldStop()) { record.failed = true record.deferred = true } return markScrubbed(record) } - private fun scrubTree(record: Record, stopWhenSessionStarts: Boolean = false): Record { + private fun scrubTree(record: Record, shouldStop: () -> Boolean = { false }): Record { for (dir in record.dir.walkTopDown().filter { it.isDirectory }) { - if (stopWhenSessionStarts && SessionState.running || !scrubFolder(dir, record, stopWhenSessionStarts)) { + if (shouldStop() || !scrubFolder(dir, record, shouldStop)) { record.failed = true record.deferred = true break } } - if (stopWhenSessionStarts && SessionState.running) { + if (shouldStop()) { record.failed = true record.deferred = true } @@ -255,7 +297,11 @@ object SessionArtifacts { val logs = File(steamArch?.let { SessionPrefs.steamRoot(context, it) } ?: SessionPrefs.activeSteamRoot(context), "logs") if (!logs.isDirectory) return val out = File(dir, "steam").apply { mkdirs() } - val sources = logs.listFiles { f -> f.isFile && f.length() < 8L * 1024 * 1024 } ?: return + val sources = logs.listFiles { f -> f.isFile && f.length() < 8L * 1024 * 1024 } + if (sources == null) { + record.failed = true + return + } for (src in sources) { if (stopWhenSessionStarts && SessionState.running) { record.failed = true @@ -264,10 +310,19 @@ object SessionArtifacts { } try { val dst = File(out, src.name) - dst.bufferedWriter().use { w -> LogRedactor.scrubTo(src, w) } + val copied = dst.bufferedWriter().use { w -> + LogRedactor.scrubTo(src, w) { stopWhenSessionStarts && SessionState.running } + } + if (!copied) { + dst.delete() + record.failed = true + record.deferred = true + break + } record.files[dst] = Scrubbed(dst.length(), dst.lastModified()) } catch (e: Exception) { Log.w(TAG, "could not scrub ${src.name}", e) + record.failed = true } } Log.i(TAG, "collected ${out.listFiles()?.size ?: 0} Steam log(s), scrubbed, into $out") @@ -282,15 +337,19 @@ object SessionArtifacts { }?.sortedWith(SessionPaths.chronological) ?: return if (abandoned.isEmpty()) return val current = SessionPaths.current() - val latestSession = SessionPaths.sessionFolders(context).lastOrNull() + val latestPreviousSession = SessionPaths.sessionFolders(context).lastOrNull { it != current } LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) for (dir in abandoned) { if (stopWhenSessionStarts && SessionState.running) break if (dir == current) continue - val newest = dir == latestSession + val newest = dir == latestPreviousSession try { val recoveryNote = File(dir, "ended-without-teardown.txt") - val recoveryAttempted = recoveryNote.exists() + val runtimeCaptured = File(dir, RECOVERY_RUNTIME_CAPTURED_MARKER) + val runtimeExpired = File(dir, RECOVERY_RUNTIME_EXPIRED_MARKER) + val recoveryPreviouslyAttempted = recoveryNote.exists() + val recoveryAttempted = recoveryPreviouslyAttempted && + (runtimeCaptured.exists() || runtimeExpired.exists() || !beforeGuestStart) if (!recoveryAttempted) { recoveryNote.writeText( "This session's process ended without running its own teardown - killed by\n" + @@ -303,6 +362,17 @@ object SessionArtifacts { "session died of a crash, the entry is in there unless the device rebooted.\n" ) } + if (recoveryPreviouslyAttempted && !runtimeCaptured.exists() && + (runtimeExpired.exists() || !beforeGuestStart) && + !recoveryNote.readText().contains("runtime capture did not finish")) { + recoveryNote.appendText( + "Steam's logs and VAC evidence are not included: runtime capture did not finish " + + "before its evidence expired.\n" + ) + } + if (recoveryPreviouslyAttempted && !runtimeCaptured.exists() && !beforeGuestStart) { + runtimeExpired.writeText("runtime evidence no longer belongs to this session, at ${now()}\n") + } val record = Record(dir) if (newest && !recoveryAttempted) { copySteamLogs( @@ -313,7 +383,22 @@ object SessionArtifacts { stopWhenSessionStarts = stopWhenSessionStarts, ) if (!record.deferred && (!stopWhenSessionStarts || !SessionState.running)) { - VacDiagnostics.collect(context, dir) + if (!record.failed && VacDiagnostics.collect(context, dir)) { + try { + runtimeCaptured.writeText("collected at ${now()}\n") + } catch (e: Exception) { + record.failed = true + if (beforeGuestStart) { + runtimeExpired.writeText("runtime capture marker failed, at ${now()}\n") + } + Log.w(TAG, "could not mark runtime capture for $dir", e) + } + } else { + record.failed = true + if (beforeGuestStart) { + runtimeExpired.writeText("runtime capture failed, at ${now()}\n") + } + } } } if (record.deferred || stopWhenSessionStarts && SessionState.running) { @@ -330,9 +415,10 @@ object SessionArtifacts { break } SessionEvents.record("session.artifacts_recovered", mapOf("newest" to newest), dir) - val scrubbed = scrubTree(record, stopWhenSessionStarts = stopWhenSessionStarts) - markScrubbed(scrubbed) + val scrubbed = scrubTree(record) { stopWhenSessionStarts && SessionState.running } + val marked = markScrubbed(scrubbed) if (scrubbed.deferred) break + if (!marked) continue File(dir, COMPLETE_MARKER).writeText("collected: late, at next app start, ${now()}\n") Log.i(TAG, "finished the abandoned session folder $dir") } catch (e: Exception) { 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 4cc0ac796a..2f7bcd87b0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -441,18 +441,65 @@ object SessionPrefs { fun logsEnabled(context: Context): Boolean = prefs(context).getBoolean("logs", true) - fun setLogsEnabled(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("logs", on).apply() - publishGameEnvironment(context) - } + fun setLogsEnabled(context: Context, on: Boolean): Boolean = setLogPreference( + context, + key = "logs", + oldValue = logsEnabled(context), + newValue = on, + newEffective = on && gameDebugLogsEnabled(context) && SessionPaths.currentSessionLogsRetained(context), + ) /** Extra Proton, Wine and graphics diagnostics for the next game launch; off unless chosen. */ fun gameDebugLogsEnabled(context: Context): Boolean = prefs(context).getBoolean("gameDebugLogsEnabled", false) - fun setGameDebugLogsEnabled(context: Context, on: Boolean) { - prefs(context).edit().putBoolean("gameDebugLogsEnabled", on).apply() - publishGameEnvironment(context) + fun setGameDebugLogsEnabled(context: Context, on: Boolean): Boolean = setLogPreference( + context, + key = "gameDebugLogsEnabled", + oldValue = gameDebugLogsEnabled(context), + newValue = on, + newEffective = logsEnabled(context) && on && SessionPaths.currentSessionLogsRetained(context), + ) + + private fun setLogPreference( + context: Context, + key: String, + oldValue: Boolean, + newValue: Boolean, + newEffective: Boolean, + ): Boolean { + if (oldValue == newValue) return true + val saved = prefs(context) + val oldEffective = logsEnabled(context) && gameDebugLogsEnabled(context) && + SessionPaths.currentSessionLogsRetained(context) + fun publish(value: Boolean) = GameEnvironmentStore.publish(context, gameDebugLogsOverride = value) + if (oldEffective && !newEffective) { + try { + publish(false) + } catch (e: Exception) { + android.util.Log.e("GameEnvironment", "Could not disable game diagnostics", e) + return false + } + if (saved.edit().putBoolean(key, newValue).commit()) return true + saved.edit().putBoolean(key, oldValue).commit() + runCatching { publish(oldEffective) } + .onFailure { android.util.Log.e("GameEnvironment", "Could not restore game diagnostics", it) } + return false + } + if (!saved.edit().putBoolean(key, newValue).commit()) { + saved.edit().putBoolean(key, oldValue).commit() + return false + } + return try { + publish(newEffective) + true + } catch (e: Exception) { + saved.edit().putBoolean(key, oldValue).commit() + runCatching { publish(oldEffective) } + .onFailure { android.util.Log.e("GameEnvironment", "Could not restore game diagnostics", it) } + android.util.Log.e("GameEnvironment", "Could not update game diagnostics", e) + false + } } fun storageDiagnosticsEnabled(context: Context): Boolean = diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 078ee5b721..6a65677175 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -329,6 +329,7 @@ class SessionService : Service() { com.droiddeck.launcher.stores.StoreLaunchRequests.start(this) val sessionDir = openSessionFolder() + GameEnvironmentStore.publish(this) val sessionLog = File(sessionDir, "session.log") Log.i(TAG, GpuClockPin.start(this)) diff --git a/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt b/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt index 5681882097..2f0d03c280 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/VacDiagnostics.kt @@ -68,13 +68,13 @@ object VacDiagnostics { } } - fun collect(context: Context, dir: File) { + fun collect(context: Context, dir: File): Boolean { val root = LinuxRuntime.rootDir(context) val kept = File(dir, SNAPSHOT_MARKER).takeIf { it.isFile } val marker = kept ?: File(root, MARKER) val launchList = if (kept != null) File(dir, SNAPSHOT_LAUNCHES) else File(root, LAUNCHES) - if (!marker.isFile) return - try { + if (!marker.isFile) return true + return try { val armed = marker.readLines().map { it.trim() } val since = (armed.getOrNull(0)?.toLongOrNull() ?: 0L) * 1000 - 5_000 val arch = armed.getOrNull(1)?.takeIf { it.isNotEmpty() } ?: SessionPrefs.steamClientArch(context) @@ -125,8 +125,10 @@ object VacDiagnostics { File(dir, SNAPSHOT_MARKER).delete() File(dir, SNAPSHOT_LAUNCHES).delete() Log.i(TAG, "VAC diagnostics: ${consoles.size} console log(s), ${steamHits.size} client VAC line(s), into $dir") + true } catch (e: Exception) { Log.w(TAG, "collecting VAC diagnostics", e) + false } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 95ae21ab4e..8156f5c4ea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -734,6 +734,7 @@ Game debug logs Include Proton, Wine and graphics diagnostics on the next game launch. 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 Latest session logs Saved session logs diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index 50a9364422..1246b5c128 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -230,6 +230,19 @@ class LogRedactorTest { assertFalse(out.toString().contains(LogRedactor.OVERSIZED_LINE)) } + @Test fun streamingScrubStopsBetweenInputChunks() { + val src = tmp.newFile("cancelled.log") + src.writeText("first safe line\n" + "x".repeat(20_000) + " sessionid=abcdef123456\n") + val out = StringWriter() + var checks = 0 + + val complete = LogRedactor.scrubTo(src, out) { ++checks >= 4 } + + assertFalse(complete) + assertFalse(out.toString().contains("abcdef123456")) + assertTrue(checks >= 4) + } + @Test fun manyLearnedAccountsKeepBoundariesAndLiteralNames() { val users = tmp.newFile("loginusers.vdf") users.writeText((0 until 40).joinToString("\n") { diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt index f581e3ab44..2599de30a5 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt @@ -65,6 +65,24 @@ class GameEnvironmentStoreTest { assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) } + @Test fun failedGameDebugOptOutLeavesTheEnabledPreferenceVisible() { + assertTrue(SessionPrefs.setGameDebugLogsEnabled(context, true)) + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + val guestDirectory = guest.parentFile!! + guestDirectory.deleteRecursively() + guestDirectory.parentFile!!.mkdirs() + guestDirectory.writeText("blocks the guest configuration directory\n") + try { + assertFalse(SessionPrefs.setGameDebugLogsEnabled(context, false)) + assertTrue(SessionPrefs.gameDebugLogsEnabled(context)) + } finally { + guestDirectory.delete() + guestDirectory.mkdirs() + GameEnvironmentStore.publish(context) + } + assertTrue(JSONObject(guest.readText()).getBoolean(GameEnvironmentStore.GAME_DEBUG_LOGS)) + } + @Test fun gameDebugLogsWaitForARetainedSessionFolder() { assertNull(SessionPaths.current()) assertTrue(SessionPaths.currentSessionLogsRetained(context)) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 61127bb9d7..2de76b1482 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -3,6 +3,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.core.LogRedactor import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test @@ -12,6 +13,9 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment import org.robolectric.annotation.Config import java.io.File +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale import java.util.zip.ZipFile @RunWith(RobolectricTestRunner::class) @@ -172,6 +176,39 @@ class SessionLogShareTest { assertTrue(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").isFile) } + @Test fun historicalScrubCancellationDuringStreamingPreservesTheOriginal() { + val folder = tmp.newFolder("2026-10-06-10-steam") + val original = "first safe line\n" + "x".repeat(20_000) + " $secret\n" + val log = File(folder, "session.log").apply { writeText(original) } + var checks = 0 + + assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { ++checks >= 4 }) + + assertEquals(original, log.readText()) + assertFalse(File(folder, ".session.log.scrub").exists()) + assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists()) + } + + @Test fun historicalScrubCancellationBeforeComparisonPreservesTheOriginal() { + val folder = tmp.newFolder("2026-10-06-11-steam") + val original = "safe diagnostic\n" + val log = File(folder, "session.log").apply { writeText(original) } + val temporary = File(folder, ".session.log.scrub") + + assertFalse(SessionArtifacts.scrubAndMark(folder, stopWhenSessionStarts = true) { temporary.length() > 0 }) + + assertEquals(original, log.readText()) + assertFalse(temporary.exists()) + assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists()) + } + + @Test fun comparisonCancellationWinsOverAnImmediateLengthMismatch() { + val left = tmp.newFile("left.log").apply { writeText("short\n") } + val right = tmp.newFile("right.log").apply { writeText("a different length\n") } + + assertNull(SessionArtifacts.sameContents(left, right) { true }) + } + @Test fun recoveryRetryKeepsItsSteamLogsWhenALaterSessionLeftNoFolder() { val context: android.content.Context = RuntimeEnvironment.getApplication() val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "2026-10-08-01-steam").apply { mkdirs() } @@ -189,6 +226,7 @@ class SessionLogShareTest { assertEquals("session A\n", saved.readText()) assertEquals("session B\n", runtime.readText()) + assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish")) assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) } @@ -251,4 +289,92 @@ class SessionLogShareTest { launches.delete() } } + + @Test fun startupRecoveryExcludesCurrentFolderAndCompletesDeferredRuntimeCapture() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context) + val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context) + val day = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()) + val folder = File(logs, "$day-9000-deferred-recovery") + val marker = File(root, "root/.droiddeck-vac-diagnostics") + val launches = File(root, "root/.droiddeck-vac-launches") + val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/deferred-recovery-vac.log") + val previousRunning = SessionState.running + val previousPhase = SessionState.phase + val previousLogsEnabled = SessionPrefs.logsEnabled(context) + var currentFolder: File? = null + try { + folder.deleteRecursively() + folder.mkdirs() + SessionArtifacts.recordClient(folder, "arm64") + File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n") + marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") } + launches.writeText("deferred VAC evidence\n") + runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("deferred VAC evidence\n") } + SessionState.running = true + SessionState.phase = SessionPhase.STARTING_GUEST + SessionPrefs.setLogsEnabled(context, true) + currentFolder = SessionPaths.beginOrCurrent(context, "current-session") + + SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) + + assertEquals("deferred VAC evidence\n", File(folder, "steam/deferred-recovery-vac.log").readText()) + assertTrue(File(folder, "vac.txt").readText().contains("deferred VAC evidence")) + assertTrue(File(folder, ".recovery-runtime-captured").isFile) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + assertFalse(File(currentFolder, "ended-without-teardown.txt").exists()) + assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists()) + } finally { + SessionState.running = previousRunning + SessionState.phase = previousPhase + SessionPaths.take()?.let { SessionPaths.release(context, it) } + currentFolder?.deleteRecursively() + SessionPrefs.setLogsEnabled(context, previousLogsEnabled) + folder.deleteRecursively() + runtimeSteamLog.delete() + marker.delete() + launches.delete() + } + } + + @Test fun failedPreGuestRuntimeCaptureWritesNeitherCaptureNorCompleteMarker() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context) + val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-01-vac-failure") + val marker = File(root, "root/.droiddeck-vac-diagnostics") + val launches = File(root, "root/.droiddeck-vac-launches") + val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/expired-recovery.log") + val previousRunning = SessionState.running + try { + folder.deleteRecursively() + folder.mkdirs() + SessionArtifacts.recordClient(folder, "arm64") + File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n") + File(folder, "vac.txt").mkdirs() + marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") } + launches.writeText("VAC evidence that cannot be reported\n") + runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("session A\n") } + SessionState.running = true + + SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) + + assertFalse(File(folder, ".recovery-runtime-captured").exists()) + assertTrue(File(folder, ".recovery-runtime-expired").isFile) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + + File(folder, "vac.txt").deleteRecursively() + runtimeSteamLog.writeText("session B\n") + SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) + + assertEquals("session A\n", File(folder, "steam/expired-recovery.log").readText()) + assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish")) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + } finally { + SessionState.running = previousRunning + folder.deleteRecursively() + runtimeSteamLog.delete() + marker.delete() + launches.delete() + } + } } From 4ab4a86507992d75cdae1cf801b5f16895eb7c0b Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 03:56:09 -0500 Subject: [PATCH 04/13] Defer abandoned log scrubbing past launch --- .../launcher/session/SessionArtifacts.kt | 2 ++ .../launcher/session/SessionLogShareTest.kt | 32 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 9027d7dceb..6696b0d18d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -342,6 +342,7 @@ object SessionArtifacts { for (dir in abandoned) { if (stopWhenSessionStarts && SessionState.running) break if (dir == current) continue + if (beforeGuestStart && dir != latestPreviousSession) continue val newest = dir == latestPreviousSession try { val recoveryNote = File(dir, "ended-without-teardown.txt") @@ -415,6 +416,7 @@ object SessionArtifacts { break } SessionEvents.record("session.artifacts_recovered", mapOf("newest" to newest), dir) + if (beforeGuestStart) return val scrubbed = scrubTree(record) { stopWhenSessionStarts && SessionState.running } val marked = markScrubbed(scrubbed) if (scrubbed.deferred) break diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 2de76b1482..e10df29a07 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -258,12 +258,14 @@ class SessionLogShareTest { val marker = File(root, "root/.droiddeck-vac-diagnostics") val launches = File(root, "root/.droiddeck-vac-launches") val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/startup-recovery-vac.log") + val sessionLog = File(folder, "session.log") val previousRunning = SessionState.running val previousPhase = SessionState.phase try { folder.deleteRecursively() folder.mkdirs() SessionArtifacts.recordClient(folder, "arm64") + sessionLog.writeText("$secret\n") marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") } launches.writeText("startup VAC evidence\n") runtimeSteamLog.apply { parentFile!!.mkdirs(); writeText("startup VAC evidence\n") } @@ -279,6 +281,14 @@ class SessionLogShareTest { assertEquals("startup VAC evidence\n", File(folder, "steam/startup-recovery-vac.log").readText()) assertTrue(File(folder, "vac.txt").readText().contains("startup VAC evidence")) + assertTrue(File(folder, ".recovery-runtime-captured").isFile) + assertTrue(sessionLog.readText().contains(leaked)) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + + SessionState.running = false + SessionArtifacts.finishAbandoned(context) + + assertFalse(sessionLog.readText().contains(leaked)) assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) } finally { SessionState.running = previousRunning @@ -290,11 +300,12 @@ class SessionLogShareTest { } } - @Test fun startupRecoveryExcludesCurrentFolderAndCompletesDeferredRuntimeCapture() { + @Test fun startupRecoveryExcludesCurrentFolderAndCapturesDeferredRuntime() { val context: android.content.Context = RuntimeEnvironment.getApplication() val root = com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context) val logs = com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context) val day = SimpleDateFormat("yyyy-MM-dd", Locale.US).format(Date()) + val olderFolder = File(logs, "$day-8999-older-recovery") val folder = File(logs, "$day-9000-deferred-recovery") val marker = File(root, "root/.droiddeck-vac-diagnostics") val launches = File(root, "root/.droiddeck-vac-launches") @@ -304,6 +315,8 @@ class SessionLogShareTest { val previousLogsEnabled = SessionPrefs.logsEnabled(context) var currentFolder: File? = null try { + olderFolder.deleteRecursively() + olderFolder.mkdirs() folder.deleteRecursively() folder.mkdirs() SessionArtifacts.recordClient(folder, "arm64") @@ -321,15 +334,25 @@ class SessionLogShareTest { assertEquals("deferred VAC evidence\n", File(folder, "steam/deferred-recovery-vac.log").readText()) assertTrue(File(folder, "vac.txt").readText().contains("deferred VAC evidence")) assertTrue(File(folder, ".recovery-runtime-captured").isFile) - assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + assertFalse(File(olderFolder, "ended-without-teardown.txt").exists()) + assertFalse(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).exists()) assertFalse(File(currentFolder, "ended-without-teardown.txt").exists()) assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists()) + + SessionState.running = false + SessionArtifacts.finishAbandoned(context) + + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + assertTrue(File(olderFolder, SessionArtifacts.COMPLETE_MARKER).isFile) + assertFalse(File(currentFolder, SessionArtifacts.COMPLETE_MARKER).exists()) } finally { SessionState.running = previousRunning SessionState.phase = previousPhase SessionPaths.take()?.let { SessionPaths.release(context, it) } currentFolder?.deleteRecursively() SessionPrefs.setLogsEnabled(context, previousLogsEnabled) + olderFolder.deleteRecursively() folder.deleteRecursively() runtimeSteamLog.delete() marker.delete() @@ -368,6 +391,11 @@ class SessionLogShareTest { assertEquals("session A\n", File(folder, "steam/expired-recovery.log").readText()) assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish")) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + + SessionState.running = false + SessionArtifacts.finishAbandoned(context) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) } finally { SessionState.running = previousRunning From 3e90875be8d214f43d27be35d445ff16b4b6e55f Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 04:05:36 -0500 Subject: [PATCH 05/13] Restrict library redaction exceptions to loader diagnostics --- .../droiddeck/launcher/core/LogRedactor.kt | 41 +++++++++++--- .../launcher/core/LogRedactorTest.kt | 56 ++++++++++++++++--- 2 files changed, 79 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index 1a870fa010..9357f37699 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -50,11 +50,31 @@ object LogRedactor { private fun matchesEntire(input: String, regex: Regex): Boolean = withMatcher(regex, input) { it.matches() } - private fun isHidlSharedLibrary(input: String, match: java.util.regex.Matcher): Boolean { + private fun isHidlLoaderDiagnostic(input: String, match: java.util.regex.Matcher): Boolean { if (!matchesEntire(match.group(), HIDL_SHARED_LIBRARY)) return false - fun continuesToken(char: Char) = char.isLetterOrDigit() || char in "._%+@-" - return (match.start() == 0 || !continuesToken(input[match.start() - 1])) && - (match.end() == input.length || !continuesToken(input[match.end()])) + val start = match.start() + val end = match.end() + val prefix = "library \"" + val suffix = "\" not found" + val earliestQuote = (start - 4096).coerceAtLeast(0) + var quote = start - 1 + while (quote >= earliestQuote && input[quote] != '"') { + val char = input[quote] + if (!char.isLetterOrDigit() && char !in "/._-") return false + quote-- + } + if (quote < earliestQuote) return false + val pathStart = quote + 1 + if (pathStart < start && (input[start - 1] != '/' || + !(input.regionMatches(pathStart, "/vendor/", 0, 8) || + input.regionMatches(pathStart, "/system/", 0, 8)))) return false + val prefixStart = quote - prefix.length + 1 + val suffixEnd = end + suffix.length + return prefixStart >= 0 && suffixEnd <= input.length && + input.regionMatches(prefixStart, prefix, 0, prefix.length, ignoreCase = true) && + input.regionMatches(end, suffix, 0, suffix.length, ignoreCase = true) && + (prefixStart == 0 || !(input[prefixStart - 1].isLetterOrDigit() || input[prefixStart - 1] == '_')) && + (suffixEnd == input.length || !(input[suffixEnd].isLetterOrDigit() || input[suffixEnd] == '_')) } private val EMAIL = Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}") @@ -66,10 +86,10 @@ object LogRedactor { private val JWT_BASE64 = Regex("ey[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}") private val GUID = Regex("\\b[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\b") private val SECRET_KV = Regex( - "(?i)\\b(access[_-]?token|refresh[_-]?token|auth[_-]?token|authtoken|token|authcode|" + + "(?i)(\\b(?:access[_-]?token|refresh[_-]?token|auth[_-]?token|authtoken|token|authcode|" + "auth[_-]?ticket|ticket|sessionid|steamloginsecure|webapikey|api[_-]?key|" + - "machine[_-]?auth(?:[_-]?token)?|machineauth|password|passwd|pwd|secret)" + - "(\\s*[=:]\\s*|=)([^\\s\"'<>&;,]{4,})" + "machine[_-]?auth(?:[_-]?token)?|machineauth|password|passwd|pwd|secret)[\"']?\\s*[=:]\\s*)" + + "(?:([\"'])((?:\\\\.|(?!\\2)[^\\\\\\r\\n]){4,})\\2|([^\\s\"'<>&;,]{4,}))" ) private val GUARD_CODE = Regex( "(?i)((?:steam\\s*)?guard\\s*code[\\s:=]*|two[\\s-]?factor[\\s:=]*|2fa[\\s:=]*)([A-Za-z0-9]{5})" @@ -356,7 +376,10 @@ object LogRedactor { if (out.has("jwt")) out.set(replaceMatches(out.text, JWT_LABELLED) { "${it.group(1)}" }) if ("ey" in out.text) out.set(replaceMatches(out.text, JWT_BASE64, "")) if (out.has("token", "auth", "ticket", "sessionid", "steamloginsecure", "api", "machine", "pass", "pwd", "secret")) { - out.set(replaceMatches(out.text, SECRET_KV) { "${it.group(1)}${it.group(2)}" }) + out.set(replaceMatches(out.text, SECRET_KV) { + val quote = it.group(2).orEmpty() + "${it.group(1)}${quote}${quote}" + }) } if (out.has("guard", "factor", "2fa")) out.set(replaceMatches(out.text, GUARD_CODE) { "${it.group(1)}" }) if (out.hasRun(32, ::isHex)) out.set(replaceMatches(out.text, WEBAPI_KEY, "")) @@ -375,7 +398,7 @@ object LogRedactor { if (out.has("login")) out.set(replaceMatches(out.text, LOGIN_KV) { "${it.group(1)}${it.group(2)}${quoted(it.group(3))}" }) for (r in accounts) if (r.needs == null || out.has(r.needs)) out.set(replaceMatches(out.text, r.regex, "")) if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL) { m -> - m.group().takeIf { isHidlSharedLibrary(out.text, m) } ?: "" + m.group().takeIf { isHidlLoaderDiagnostic(out.text, m) } ?: "" }) if (out.has("jwt", "token", "ticket", "sessionid", "steamloginsecure", "machineauth")) { out.set(replaceMatches(out.text, RESIDUAL) { "${it.group(1)}=" }) diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index 1246b5c128..4ac56d32a5 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -42,35 +42,54 @@ class LogRedactorTest { assertEquals("login ok", LogRedactor.redact("login someone@example.com ok")) } - @Test fun hidlSharedLibrariesStayVisibleWhileAdjacentSecretsAndEmailsAreRedacted() { + @Test fun onlyLoaderDiagnosticsKeepHidlSharedLibraryNames() { val library = "android.hardware.graphics.mapper@4.0.so" - val vendorLibrary = "vendor.qti.hardware.display.mapper@4.0.so" - val line = "/vendor/lib64/hw/$library loaded $vendorLibrary contact=someone@company.so token=abcdef123456" - val expected = "/vendor/lib64/hw/$library loaded $vendorLibrary contact= token=" + val line = "dlopen failed: library \"$library\" not found" + val pathLine = "dlopen failed: library \"/vendor/lib64/hw/$library\" not found" - assertEquals(expected, LogRedactor.redact(line)) - assertEquals(expected, LogRedactor.redactForShare(line)) + assertEquals(line, LogRedactor.redact(line)) + assertEquals(line, LogRedactor.redactForShare(line)) + assertEquals(pathLine, LogRedactor.redact(pathLine)) + assertEquals(pathLine, LogRedactor.redactForShare(pathLine)) } @Test fun privacyRulesOverrideTheHidlSharedLibraryException() { val library = "android.hardware.graphics.mapper@4.0.so" assertEquals("token=", LogRedactor.redact("token=$library")) assertEquals("username=", LogRedactor.redact("username=$library")) + assertEquals("{\"password\":\"\"}", LogRedactor.redact("{\"password\":\"$library\"}")) + assertEquals("{\"password\":\"\"}", LogRedactor.redactForShare("{\"password\":\"$library\"}")) + assertEquals("{\"password\":\"\"}", LogRedactor.redact("{\"password\":\"don't-use-$library\"}")) + assertEquals("{\"password\":\"\"}", LogRedactor.redactForShare("{\"password\":\"don't-use-$library\"}")) - val users = tmp.newFile("hidl-loginusers.vdf") + val mixed = "dlopen failed: library \"$library\" not found; token=abcdef123456; contact=alice!$library; {\"password\":\"library \\\"$library\\\" not found\"}" + val expected = "dlopen failed: library \"$library\" not found; token=; contact=alice!; {\"password\":\"\"}" + assertEquals(expected, LogRedactor.redact(mixed)) + assertEquals(expected, LogRedactor.redactForShare(mixed)) + + val root = java.nio.file.Files.createTempDirectory("hidl-redactor").toFile() + val users = java.io.File(root, "loginusers.vdf") users.writeText("\"AccountName\" \"$library\"") try { LogRedactor.learnAccounts(users) assertEquals("", LogRedactor.redact(library)) } finally { LogRedactor.learnAccounts() + root.deleteRecursively() } } - @Test fun onlyExactHidlSharedLibraryNamesBypassEmailRedaction() { + @Test fun hidlSharedLibraryNamesAreRedactedOutsideLoaderDiagnostics() { val library = "android.hardware.graphics.mapper@4.0.so" - assertEquals(library, LogRedactor.redact(library)) + assertEquals("", LogRedactor.redact(library)) + assertEquals("", LogRedactor.redactForShare(library)) + assertEquals("/vendor/lib64/hw/", LogRedactor.redact("/vendor/lib64/hw/$library")) + for (punctuation in listOf("!", "#", "~", "/", "=")) { + val expected = "contact=alice$punctuation" + assertEquals(expected, LogRedactor.redact("contact=alice$punctuation$library")) + assertEquals(expected, LogRedactor.redactForShare("contact=alice$punctuation$library")) + } assertEquals("", LogRedactor.redact("$library.evil")) assertEquals("", LogRedactor.redact("someone@company.so")) assertEquals("", LogRedactor.redact("not$library")) @@ -81,6 +100,25 @@ class LogRedactorTest { assertEquals("", LogRedactor.redact("android.hardware.graphics.mapper@4.0.so.evil")) } + @Test fun loaderContextRequiresExactWordsAndABoundedAndroidPath() { + val library = "android.hardware.graphics.mapper@4.0.so" + val valid = "library \"/system/lib64/$library\" not found: needed by app" + assertEquals(valid, LogRedactor.redact(valid)) + assertEquals(valid, LogRedactor.redactForShare(valid)) + for (line in listOf( + "not_library \"$library\" not found", + "library \"$library\" not found_suffix", + "library \"/home/user/$library\" not found", + "library \"relative/$library\" not found", + "library \"/vendor/invalid!/$library\" not found", + "library \"/vendor/" + "a/".repeat(2050) + "$library\" not found", + )) { + val expected = line.replace(library, "") + assertEquals(expected, LogRedactor.redact(line)) + assertEquals(expected, LogRedactor.redactForShare(line)) + } + } + @Test fun clockTimeIsNotAnAddress() { val line = "[2026-09-27 10:03:05] Startup" assertEquals(line, LogRedactor.redact(line)) From 5c55b84d94aac6248f41f87308dad880544b833f Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 04:15:04 -0500 Subject: [PATCH 06/13] Preserve recovered crash snapshots --- .../launcher/session/SessionArtifacts.kt | 5 ++- .../launcher/session/SessionLogShareTest.kt | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 6696b0d18d..4f8572f863 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -408,7 +408,10 @@ object SessionArtifacts { markScrubbed(record) break } - SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) + val crashLog = File(dir, "crash.log") + if (!crashLog.exists()) { + SessionLogCapture.dumpCrashBuffer(crashLog) + } if (stopWhenSessionStarts && SessionState.running) { record.failed = true record.deferred = true diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index e10df29a07..6e2ba64898 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -1,6 +1,7 @@ package com.droiddeck.launcher.session import com.droiddeck.launcher.core.LogRedactor +import org.junit.Assert.assertArrayEquals import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull @@ -259,6 +260,7 @@ class SessionLogShareTest { val launches = File(root, "root/.droiddeck-vac-launches") val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/startup-recovery-vac.log") val sessionLog = File(folder, "session.log") + val crashLog = File(folder, "crash.log") val previousRunning = SessionState.running val previousPhase = SessionState.phase try { @@ -282,6 +284,7 @@ class SessionLogShareTest { assertEquals("startup VAC evidence\n", File(folder, "steam/startup-recovery-vac.log").readText()) assertTrue(File(folder, "vac.txt").readText().contains("startup VAC evidence")) assertTrue(File(folder, ".recovery-runtime-captured").isFile) + assertTrue(crashLog.isFile && crashLog.length() > 0L) assertTrue(sessionLog.readText().contains(leaked)) assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) @@ -367,12 +370,15 @@ class SessionLogShareTest { val marker = File(root, "root/.droiddeck-vac-diagnostics") val launches = File(root, "root/.droiddeck-vac-launches") val runtimeSteamLog = File(SessionPrefs.steamRoot(context, "arm64"), "logs/expired-recovery.log") + val crashLog = File(folder, "crash.log") val previousRunning = SessionState.running try { folder.deleteRecursively() folder.mkdirs() SessionArtifacts.recordClient(folder, "arm64") File(folder, "ended-without-teardown.txt").writeText("recovery began before session start\n") + val firstCrashSnapshot = "first crash snapshot\n".toByteArray() + crashLog.writeBytes(firstCrashSnapshot) File(folder, "vac.txt").mkdirs() marker.apply { parentFile!!.mkdirs(); writeText("0\narm64\n") } launches.writeText("VAC evidence that cannot be reported\n") @@ -384,18 +390,21 @@ class SessionLogShareTest { assertFalse(File(folder, ".recovery-runtime-captured").exists()) assertTrue(File(folder, ".recovery-runtime-expired").isFile) assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + assertArrayEquals(firstCrashSnapshot, crashLog.readBytes()) File(folder, "vac.txt").deleteRecursively() runtimeSteamLog.writeText("session B\n") SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) assertEquals("session A\n", File(folder, "steam/expired-recovery.log").readText()) + assertArrayEquals(firstCrashSnapshot, crashLog.readBytes()) assertTrue(File(folder, "ended-without-teardown.txt").readText().contains("runtime capture did not finish")) assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) SessionState.running = false SessionArtifacts.finishAbandoned(context) + assertArrayEquals(firstCrashSnapshot, crashLog.readBytes()) assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) } finally { SessionState.running = previousRunning @@ -405,4 +414,29 @@ class SessionLogShareTest { launches.delete() } } + + @Test fun emptyCrashSnapshotIsPreservedAcrossRecovery() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val folder = File(com.droiddeck.launcher.runtime.LinuxRuntime.logDir(context), "9999-12-31-02-empty-crash") + val crashLog = File(folder, "crash.log") + val previousRunning = SessionState.running + try { + folder.deleteRecursively() + folder.mkdirs() + crashLog.writeBytes(ByteArray(0)) + SessionState.running = true + + SessionArtifacts.finishAbandoned(context, beforeGuestStart = true) + assertTrue(crashLog.isFile) + assertEquals(0L, crashLog.length()) + + SessionState.running = false + SessionArtifacts.finishAbandoned(context) + assertEquals(0L, crashLog.length()) + assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) + } finally { + SessionState.running = previousRunning + folder.deleteRecursively() + } + } } From 93c358c54162c22b7fca7ee9d17dbb4274a8d991 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 18 Oct 2026 04:26:34 -0500 Subject: [PATCH 07/13] Assert empty crash snapshot retention --- .../java/com/droiddeck/launcher/session/SessionLogShareTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index 6e2ba64898..71def17f1a 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -432,6 +432,7 @@ class SessionLogShareTest { SessionState.running = false SessionArtifacts.finishAbandoned(context) + assertTrue(crashLog.isFile) assertEquals(0L, crashLog.length()) assertTrue(File(folder, SessionArtifacts.COMPLETE_MARKER).isFile) } finally { From 5eaa6a49020b0ec657dc95e889e50d647fbdaea3 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 25 Oct 2026 18:39:19 -0500 Subject: [PATCH 08/13] Preserve scrub cancellation callbacks and initialize test snapshots --- .../java/com/droiddeck/launcher/session/SessionArtifacts.kt | 2 +- .../com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 5972dfb20b..ea87a30706 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -265,8 +265,8 @@ object SessionArtifacts { internal fun scrubAndMark( dir: File, stopWhenSessionStarts: Boolean = false, - sessionStarted: () -> Boolean = { SessionState.running }, beforeReplace: (File) -> Unit = {}, + sessionStarted: () -> Boolean = { SessionState.running }, ): Boolean { val shouldStop = { stopWhenSessionStarts && sessionStarted() } val record = scrubTree(Record(dir), shouldStop, beforeReplace) diff --git a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt index a7cc5cf1ad..197512e5be 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/GameEnvironmentStoreTest.kt @@ -103,6 +103,7 @@ class GameEnvironmentStoreTest { } @Test fun logPreferenceUpdatesUseThePublisherLock() { + GameEnvironmentStore.publish(context) val entered = CountDownLatch(1) val finished = CountDownLatch(1) lateinit var thread: Thread @@ -127,6 +128,7 @@ class GameEnvironmentStoreTest { @Test fun gameDebugLogsWaitForARetainedSessionFolder() { assertNull(SessionPaths.current()) assertTrue(SessionPaths.currentSessionLogsRetained(context)) + GameEnvironmentStore.publish(context) SessionPrefs.setLogsEnabled(context, false) val cacheSession = SessionPaths.beginOrCurrent(context, "game-debug-logs") try { From f845b5c44f75757296e0d0821e65f516cd5d59dc Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 25 Oct 2026 21:23:17 -0500 Subject: [PATCH 09/13] Keep failed session artifact collections incomplete --- .../launcher/session/SessionArtifacts.kt | 50 +++++++++++++++---- .../launcher/session/SessionLogShareTest.kt | 34 +++++++++++++ .../launcher/session/SessionSteamLogsTest.kt | 35 +++++++++++++ 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index ea87a30706..b4408c48b9 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -7,6 +7,9 @@ import com.droiddeck.launcher.core.SessionLogCapture import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.wayland.WaylandCompositor import java.io.File +import java.io.Writer +import java.nio.file.Files +import java.nio.file.StandardCopyOption import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -75,9 +78,9 @@ object SessionArtifacts { copySteamLogs(context, dir, record, steamArch) VacDiagnostics.collect(context, dir) SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) - markScrubbed(scrubTree(record)) + val scrubbed = markScrubbed(scrubTree(record)) SessionEvents.record("session.artifacts_collected", mapOf("reason" to reason), dir) - File(dir, COMPLETE_MARKER).writeText("collected: $reason at ${now()}\n") + if (scrubbed) File(dir, COMPLETE_MARKER).writeText("collected: $reason at ${now()}\n") } catch (e: Exception) { Log.w(TAG, "collecting session artifacts", e) } @@ -126,8 +129,13 @@ object SessionArtifacts { record: Record, shouldStop: () -> Boolean, beforeReplace: (File) -> Unit, + listFiles: (File) -> Array?, ): Boolean { - val files = dir.listFiles { f -> f.isFile && !f.name.startsWith(".") && f !in record.files } ?: return true + val files = listFiles(dir)?.filter { f -> f.isFile && !f.name.startsWith(".") && f !in record.files } + if (files == null) { + record.failed = true + return true + } for (f in files) { if (shouldStop()) return false if (LogRedactor.isBinary(f)) continue @@ -266,10 +274,16 @@ object SessionArtifacts { dir: File, stopWhenSessionStarts: Boolean = false, beforeReplace: (File) -> Unit = {}, + listFiles: (File) -> Array? = { it.listFiles() }, sessionStarted: () -> Boolean = { SessionState.running }, ): Boolean { val shouldStop = { stopWhenSessionStarts && sessionStarted() } - val record = scrubTree(Record(dir), shouldStop, beforeReplace) + val record = scrubTree( + Record(dir), + listFiles = listFiles, + beforeReplace = beforeReplace, + shouldStop = shouldStop, + ) if (shouldStop()) { record.failed = true record.deferred = true @@ -279,11 +293,12 @@ object SessionArtifacts { private fun scrubTree( record: Record, - shouldStop: () -> Boolean = { false }, + listFiles: (File) -> Array? = { it.listFiles() }, beforeReplace: (File) -> Unit = {}, + shouldStop: () -> Boolean = { false }, ): Record { for (dir in record.dir.walkTopDown().filter { it.isDirectory }) { - if (shouldStop() || !scrubFolder(dir, record, shouldStop, beforeReplace)) { + if (shouldStop() || !scrubFolder(dir, record, shouldStop, beforeReplace, listFiles)) { record.failed = true record.deferred = true break @@ -364,13 +379,18 @@ object SessionArtifacts { Log.i(TAG, "collected ${out.listFiles()?.size ?: 0} Steam log(s), scrubbed, into $out") } - internal fun copySessionLogs(logs: File, dir: File, out: File): List = - copySessionLogsResult(logs, dir, out) { false }.files + internal fun copySessionLogs( + logs: File, + dir: File, + out: File, + openWriter: (File) -> Writer = { it.bufferedWriter() }, + ): List = copySessionLogsResult(logs, dir, out, openWriter) { false }.files private fun copySessionLogsResult( logs: File, dir: File, out: File, + openWriter: (File) -> Writer = { it.bufferedWriter() }, shouldStop: () -> Boolean, ): CopyResult { val marks = steamLogMarks(dir) @@ -387,8 +407,9 @@ object SessionArtifacts { val size = src.length() val from = marks?.let { startOf(src, size, it) } ?: 0L if (marks != null && from == size || size - from >= MAX_STEAM_LOG) continue + val dst = File(out, src.name) + val staging = File(out, ".${src.name}.copy") try { - val dst = File(out, src.name) src.inputStream().buffered().use { input -> var left = if (from > 0) from - 1 else 0L while (left > 0) { @@ -402,16 +423,23 @@ object SessionArtifacts { if (c < 0 || c == '\n'.code) break } } - val complete = dst.bufferedWriter().use { w -> scrubSteamLog(input, w, shouldStop) } + val complete = openWriter(staging).use { w -> scrubSteamLog(input, w, shouldStop) } if (!complete) { - dst.delete() + staging.delete() failed = true deferred = true } } if (deferred) break + Files.move( + staging.toPath(), + dst.toPath(), + StandardCopyOption.ATOMIC_MOVE, + StandardCopyOption.REPLACE_EXISTING, + ) copied += dst } catch (e: Exception) { + staging.delete() Log.w(TAG, "could not scrub ${src.name}", e) failed = true } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index f7de6d27ee..fc42592057 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -152,6 +152,40 @@ class SessionLogShareTest { assertTrue(zip(folder).values.none { it.contains(leaked) }) } + @Test fun aDirectoryListingFailureLeavesTheTreeUnrecordedButDoesNotStopSiblingScrubbing() { + val folder = tmp.newFolder("2026-10-06-06-listing") + val unavailable = File(folder, "unavailable").apply { mkdirs() } + val unavailableLog = File(unavailable, "session.log").apply { writeText("$secret\n") } + val availableLog = File(folder, "available/session.log").apply { + parentFile!!.mkdirs() + writeText("$secret\n") + } + + assertFalse(SessionArtifacts.scrubAndMark(folder, listFiles = { + if (it == unavailable) null else it.listFiles() + })) + + assertTrue(unavailableLog.readText().contains(leaked)) + assertFalse(availableLog.readText().contains(leaked)) + assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists()) + assertFalse(File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).exists()) + } + + @Test fun aFailedScrubStillRecordsTheCollectionEventWithoutCompletingTheFolder() { + val context: android.content.Context = RuntimeEnvironment.getApplication() + val folder = tmp.newFolder("2026-10-06-06-collect") + File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply { + mkdirs() + resolve("blocker").writeText("force marker write failure\n") + } + + SessionArtifacts.collect(context, folder, "test") + + assertTrue(File(folder, "events.jsonl").readText().contains("session.artifacts_collected")) + assertFalse(File(folder, SessionArtifacts.COMPLETE_MARKER).exists()) + assertFalse(File(folder, ".scrubbed-r${LogRedactor.RULES_VERSION}").exists()) + } + @Test fun steamLogsPastTheSizeLimitStayOut() { val folder = tmp.newFolder("2026-10-06-07-steam") File(folder, "session.log").writeText("ok\n") diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt index 60c57ecfd5..73847dc534 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt @@ -6,6 +6,8 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder import java.io.File +import java.io.IOException +import java.io.Writer class SessionSteamLogsTest { @get:Rule val tmp = TemporaryFolder() @@ -59,4 +61,37 @@ class SessionSteamLogsTest { assertEquals(listOf("web.txt"), names(copied)) assertFalse(File(out, "web.txt").readText().contains("abcdef123456")) } + + @Test fun aCopyFailurePreservesThePreviousSnapshotAndRemovesPartialStaging() { + val logs = tmp.newFolder("logs") + val session = tmp.newFolder("session") + val out = tmp.newFolder("out") + File(logs, "console_log.txt").writeText("new complete line\n") + val snapshot = File(out, "console_log.txt").apply { writeText("previous valid snapshot\n") } + lateinit var staging: File + + val copied = SessionArtifacts.copySessionLogs(logs, session, out) { target -> + staging = target + val delegate = target.bufferedWriter() + object : Writer() { + private var failed = false + + override fun write(buffer: CharArray, offset: Int, length: Int) { + if (!failed) { + delegate.write(buffer, offset, minOf(length, 4)) + delegate.flush() + failed = true + } + throw IOException("injected writer failure") + } + + override fun flush() = delegate.flush() + override fun close() = delegate.close() + } + } + + assertTrue(copied.isEmpty()) + assertEquals("previous valid snapshot\n", snapshot.readText()) + assertFalse(staging.exists()) + } } From d3d12d75855448ce5e84dde9fec2828d8f9dd6fc Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 25 Oct 2026 21:35:26 -0500 Subject: [PATCH 10/13] Import assertion for failed Steam copy regression --- .../java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt index 73847dc534..3b996ae3d2 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionSteamLogsTest.kt @@ -2,6 +2,7 @@ package com.droiddeck.launcher.session import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder From d3faca19192b0fd87e87f0d06998d93e9454b623 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 25 Oct 2026 21:41:30 -0500 Subject: [PATCH 11/13] Register stopped-session collection before allowing restart --- .../java/com/droiddeck/launcher/session/SessionService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 0bb1e5d1e6..803b769c6e 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1747,7 +1747,9 @@ class SessionService : Service() { SessionEvents.record("guest.exited", mapOf("status" to status)) SessionEvents.transition(SessionPhase.STOPPING, "session.stopping", mapOf("status" to status)) SessionState.running = false - SessionPaths.take() to SessionState.steamClientArch + val ended = SessionPaths.take() + if (ended != null) SessionArtifacts.collectionStarted(ended) + ended to SessionState.steamClientArch } SessionState.micAvailable = false SessionState.micEnabled = false @@ -1776,7 +1778,6 @@ class SessionService : Service() { suspendController = null if (ended != null) { VacDiagnostics.snapshot(this, ended) - SessionArtifacts.collectionStarted(ended) } components.reversed().forEach { try { From 91cb966f93cde1290265d883f220bc0eed693ad9 Mon Sep 17 00:00:00 2001 From: wallentx Date: Sun, 25 Oct 2026 21:59:59 -0500 Subject: [PATCH 12/13] Provide captured compositor log in artifact collection test --- .../java/com/droiddeck/launcher/session/SessionLogShareTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt index fc42592057..2e00e83c69 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareTest.kt @@ -174,6 +174,7 @@ class SessionLogShareTest { @Test fun aFailedScrubStillRecordsTheCollectionEventWithoutCompletingTheFolder() { val context: android.content.Context = RuntimeEnvironment.getApplication() val folder = tmp.newFolder("2026-10-06-06-collect") + File(folder, "wayland.log").writeText("test compositor log\n") File(folder, SessionArtifacts.SCRUBBED_TREE_MARKER).apply { mkdirs() resolve("blocker").writeText("force marker write failure\n") From 82c07c4be79a52a6a310b570b8993a462ac83ef8 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:43:36 -0400 Subject: [PATCH 13/13] fix(library): keep installed/all owned filter when stores tab is off (#1700) --- app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt index 0f1b579c92..29c2e8c99e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LibraryPage.kt @@ -309,7 +309,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String, grid = { LibraryGrid( s, a, grid, visible, split, visible.size, sources, source, sizesPending, syncing, - showUninstalled = listUninstalled.takeIf { stores }, onShowUninstalled = setShowUninstalled, + showUninstalled = listUninstalled.takeIf { !s.shortcutPicker },onShowUninstalled = setShowUninstalled, hiddenUninstalled = hiddenUninstalled, onSource = { LibraryView.source = it }, onCycle = { step ->