From dd79f44b3a05b858c6801da2d69f49f3785b7b9a Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Sat, 24 Oct 2026 00:09:16 -0400 Subject: [PATCH] fix: the Steam download monitor no longer stalls the main thread on a long content log The content log was read with RandomAccessFile.readLine, one byte per read, on the main thread. A 4 MB log took about 2 s on the first poll, enough for an ANR on slower devices while a download runs. It is now read through a buffered reader with the same Latin-1 lines and offset, and the per-line regexes only run on lines that can match. --- .../launcher/session/SteamDownloadMonitor.kt | 16 ++++++++------ .../session/SteamDownloadMonitorTest.kt | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt index c125e59b80..ff3602c1bd 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamDownloadMonitor.kt @@ -1,7 +1,7 @@ package com.droiddeck.launcher.session import java.io.File -import java.io.RandomAccessFile +import java.io.FileInputStream internal class SteamDownloadMonitor { private data class ManifestState( @@ -63,16 +63,17 @@ internal class SteamDownloadMonitor { lastContentActivityAt = 0L } runCatching { - RandomAccessFile(log, "r").use { input -> - input.seek(contentLogOffset) + FileInputStream(log).use { input -> + input.channel.position(contentLogOffset) + val reader = input.bufferedReader(Charsets.ISO_8859_1) while (true) { - val line = input.readLine() ?: break + val line = reader.readLine() ?: break when { "Client version:" in line -> { activeContentUpdates.clear() lastContentActivityAt = 0L } - CONTENT_UPDATE.find(line)?.let { match -> + " update changed : " in line && CONTENT_UPDATE.find(line)?.let { match -> val appId = match.groupValues[1] val updateType = match.groupValues[2] val state = match.groupValues[3] @@ -85,14 +86,15 @@ internal class SteamDownloadMonitor { } true } == true -> Unit - CURRENT_RATE.find(line)?.groupValues?.get(1)?.toDoubleOrNull()?.let { it > 0.0 } == true -> + "Current download rate: " in line && + CURRENT_RATE.find(line)?.groupValues?.get(1)?.toDoubleOrNull()?.let { it > 0.0 } == true -> lastContentActivityAt = now "Downloading " in line && " chunks for depot " in line -> lastContentActivityAt = now } if (activeContentUpdates.isNotEmpty()) lastContentActivityAt = now } - contentLogOffset = input.filePointer + contentLogOffset = input.channel.position() } } return activeContentUpdates.isNotEmpty() && lastContentActivityAt > 0L && diff --git a/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt index 4da943020d..52920aefca 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SteamDownloadMonitorTest.kt @@ -101,6 +101,28 @@ class SteamDownloadMonitorTest { } } + @Test fun aLongLogIsFollowedFromWhereTheLastPollStopped() { + val root = Files.createTempDirectory("droiddeck-steam-download-").toFile() + try { + val contentLog = File(root, "root/.local/share/Steam/logs/content_log.txt").apply { + check(parentFile?.mkdirs() != false) + writeText(buildString { + repeat(5_000) { append("[2026-10-06 14:40:00] Detected write gap 64 MB in file \"data_$it.dat\"\r\n") } + append("[2026-10-06 14:44:17] AppID 44 App update changed : Running Update,Downloading,\r\n") + }) + } + val monitor = SteamDownloadMonitor() + + assertTrue(monitor.poll(root, now = 1_000L)) + contentLog.appendText("[2026-10-06 14:45:03] AppID 44 App update changed : None\r\n") + assertFalse(monitor.poll(root, now = 2_000L)) + contentLog.appendText("[2026-10-06 14:46:00] AppID 45 App update changed : Running Update,Downloading,\r\n") + assertTrue(monitor.poll(root, now = 3_000L)) + } finally { + root.deleteRecursively() + } + } + @Test fun theOtherClientsLogIsReadFromItsStart() { val root = Files.createTempDirectory("droiddeck-steam-download-").toFile() try {