From 4041849791c5a885595d19e0776ec1f9223b7e77 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Mon, 21 Sep 2026 13:09:23 -0400 Subject: [PATCH] Logs: the app's own log, the crash buffer, audio and the network Closes the four gaps that were left after the session folder: everything the app itself decided was reaching logcat and nowhere a user can get at, sound had no record at all, the network had none either, and a session the system killed left its only trace in a buffer nobody was reading. app.log mirrors this process's logcat for the length of the session - which driver was chosen and why, the audio line, a rival client stopped, a helper missing, the exit status. An app may always read back its own entries, so this needs no permission; where a ROM refuses, the file says so rather than being absent and looking like silence. crash.log is Android's crash buffer at teardown. proot once died before main over a missing library and said so there and in no other log, and a session the OS kills for spawning children says it there too. audio.log takes the PulseAudio daemon's output and the relay helper's, both of which went to logcat only. The 17.0-module failure that cost the microphone a whole round of builds would have been one line in this file. network.txt records the transport, whether the link validated, the address families, the DNS the system offered and the resolv.conf the runtime was actually given - never the network's name, which is identifying. It also states plainly that the client's own "wifi is off" is cosmetic, since that reading has now cost two people an afternoon. Left out on purpose: a Vulkan dump. It needs a new native entry point for information wayland.log already carries on its first lines. --- README.md | 13 +++ .../audio/DirectAudioRelayComponent.java | 26 ++++- .../launcher/audio/PulseAudioComponent.java | 30 ++++- .../steamdeck/launcher/core/NetworkReport.kt | 101 ++++++++++++++++ .../launcher/core/SessionLogCapture.kt | 110 ++++++++++++++++++ .../launcher/session/SessionService.kt | 13 +++ 6 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/steamdeck/launcher/core/NetworkReport.kt create mode 100644 app/src/main/java/com/steamdeck/launcher/core/SessionLogCapture.kt diff --git a/README.md b/README.md index 7086c2cc10..61de4efea2 100644 --- a/README.md +++ b/README.md @@ -295,11 +295,24 @@ Download/SteamDeck/session-20260921-161256/ device.txt what this device is, and every setting the session ran with session.log the guest session: proot, gamescope, the client's own output wayland.log the app's compositor - what it presented, and how fast + app.log what the app itself decided and reported + crash.log Android's crash buffer, as it stood when the session ended + audio.log the PulseAudio daemon and the DirectAudio relay helper + network.txt the link, the DNS the runtime was given, and what it means steam.log the Steam client's log, scrubbed (Steam mode) steam/ the rest of the client's logs, scrubbed (Steam mode) desktop.log labwc, the panel and the programs on it (desktop mode) ``` +`app.log` is this app's own logcat, filtered to its process: which driver it chose and why, the +audio line, a rival Steam client being stopped, a helper that was missing, the session's exit +status. `crash.log` is Android's crash buffer at teardown, which is where a session the *system* +killed leaves its only trace - proot once died before `main` over a missing library and said so +there and nowhere else. `audio.log` is the PulseAudio daemon's own output plus the relay helper's, +so a module that refuses to load is visible instead of being a silent absence of sound. +`network.txt` records the transport, whether the link validated, the address families and the DNS +servers the runtime was actually given - **never the network's name**. + `device.txt` is written before the session starts, so a session that dies in its first second still says what it ran on: model, SoC, Android and kernel, cores and their ceilings, RAM, the GPU as KGSL names it, the panel, **which driver each half of the session chose**, the runtime version, diff --git a/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java index 9f872e1d43..55c6625c24 100644 --- a/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java +++ b/app/src/main/java/com/steamdeck/launcher/audio/DirectAudioRelayComponent.java @@ -34,6 +34,8 @@ public class DirectAudioRelayComponent extends EnvironmentComponent { public static final String BINARY = "libdirectaudiorelay.so"; private final File socketPath; + /** Shared with PulseAudioComponent: one audio.log per session, appended by both. */ + private File logFile; /** Null when the microphone was not asked for; the helper then opens no input stream. */ private final File micFifoPath; private int pid = -1; @@ -43,6 +45,11 @@ public class DirectAudioRelayComponent extends EnvironmentComponent { this.micFifoPath = micFifoPath; } + /** Send the helper's output to this file as well as logcat. Set before {@link #start()}. */ + public void setLogFile(File file) { + this.logFile = file; + } + @Override public void start() { stop(); @@ -91,7 +98,24 @@ public class DirectAudioRelayComponent extends EnvironmentComponent { } ArrayList env = new ArrayList<>(); env.add("HOME=" + context.getFilesDir()); - pid = ProcessHelper.exec(command.toString(), env.toArray(new String[0]), context.getFilesDir()); + java.io.PrintWriter out = null; + if (logFile != null) { + try { + out = new java.io.PrintWriter(new java.io.FileWriter(logFile, true)); + out.println("== DirectAudio relay helper starting" + + (micFifoPath != null ? " with the microphone" : " (no microphone)")); + out.flush(); + } catch (Exception e) { + Log.w(TAG, "could not open " + logFile, e); + } + } + final java.io.PrintWriter log = out; + pid = ProcessHelper.exec(command.toString(), env.toArray(new String[0]), + context.getFilesDir(), null, + line -> { + Log.i(TAG, line); + if (log != null) synchronized (log) { log.println(line); log.flush(); } + }); Log.i(TAG, "started pid=" + pid + " socket=" + socketPath + (micFifoPath != null ? " mic=" + micFifoPath : " (no microphone)")); } diff --git a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java index fb920405ff..3efdf2ad2a 100644 --- a/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java +++ b/app/src/main/java/com/steamdeck/launcher/audio/PulseAudioComponent.java @@ -34,6 +34,8 @@ public class PulseAudioComponent extends EnvironmentComponent { private static final String BUNDLE_STAMP = "2026-09-21-pa13-pipe-modules"; private final File workingDir; + /** Where the daemon's own output is kept for this session, or null for logcat only. */ + private File logFile; /** * A named pipe carrying microphone audio, or null for no microphone. The bundle ships * module-aaudio-sink but no matching source, and the daemon runs where Android permits @@ -53,6 +55,11 @@ public class PulseAudioComponent extends EnvironmentComponent { this.micFifoPath = micFifoPath; } + /** Send the daemon's output to this file as well as logcat. Set before {@link #start()}. */ + public void setLogFile(File file) { + this.logFile = file; + } + public File socket() { return new File(workingDir, SOCKET_NAME); } @@ -125,8 +132,15 @@ public class PulseAudioComponent extends EnvironmentComponent { String command = workingDir.getAbsolutePath() + "/libpulseaudio.so" + " --system=false --disable-shm=true --fail=false" + " -n --file=default.pa --daemonize=false --use-pid-file=false --exit-idle-time=-1"; + // A module that refuses to load, a pipe that could not be made, the daemon exiting at + // startup: all of it used to reach logcat and nothing else, so a user's folder said nothing + // at all about sound. Four separate faults hid behind "no input device" in one night. + final java.io.PrintWriter out = openLog(); pid = ProcessHelper.exec(command, env.toArray(new String[0]), workingDir, null, - line -> Log.i(TAG, line)); + line -> { + Log.i(TAG, line); + if (out != null) synchronized (out) { out.println(line); out.flush(); } + }); } @Override @@ -137,6 +151,20 @@ public class PulseAudioComponent extends EnvironmentComponent { } } + /** The session's audio log, appended to by both the daemon and the relay helper. */ + private java.io.PrintWriter openLog() { + if (logFile == null) return null; + try { + java.io.PrintWriter w = new java.io.PrintWriter(new java.io.FileWriter(logFile, true)); + w.println("== PulseAudio daemon starting" + (micFifoPath != null ? " with a microphone source" : "")); + w.flush(); + return w; + } catch (Exception e) { + Log.w(TAG, "could not open " + logFile, e); + return null; + } + } + private void copyFromLibraryDir() { String[] libs = {"libltdl.so", "libpulseaudio.so", "libpulse.so", "libpulsecommon-13.0.so", "libpulsecore-13.0.so", "libsndfile.so", "libffi.so"}; diff --git a/app/src/main/java/com/steamdeck/launcher/core/NetworkReport.kt b/app/src/main/java/com/steamdeck/launcher/core/NetworkReport.kt new file mode 100644 index 0000000000..0db6ea5bad --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/core/NetworkReport.kt @@ -0,0 +1,101 @@ +package com.steamdeck.launcher.core + +import android.content.Context +import android.net.ConnectivityManager +import android.net.NetworkCapabilities +import android.os.Build +import android.util.Log +import com.steamdeck.launcher.runtime.LinuxRuntime +import java.io.File +import java.net.Inet4Address +import java.net.Inet6Address + +/** + * `network.txt`: what the session was given to work with, for the reports that say "the client + * thinks WiFi is off" or "Firefox cannot resolve anything". + * + * The runtime has no NetworkManager, so the client's own network panel is blind by design and says + * so in ways that read like a fault. What actually matters is further down: whether the phone had + * a validated link, which DNS servers the app wrote into the runtime's `resolv.conf`, and whether + * the session can reach a name and an address at all. + * + * **No network names.** The SSID is identifying and is deliberately not collected; the transport + * type, the addresses' families and the DNS servers are what a diagnosis needs. + */ +object NetworkReport { + private const val TAG = "NetworkReport" + + fun write(context: Context, target: File) { + try { + target.writeText(build(context)) + } catch (e: Exception) { + Log.w(TAG, "could not write $target", e) + } + } + + private fun build(context: Context): String = buildString { + append("Network as the session starts\n") + append("=============================\n") + append("The SSID is deliberately not recorded. Transport, address families and DNS are.\n\n") + val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager + val network = cm?.activeNetwork + if (cm == null || network == null) { + append("Active network none - the phone reports no connection\n") + } else { + val caps = cm.getNetworkCapabilities(network) + val transport = when { + caps == null -> "unknown" + caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> "WiFi" + caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> "cellular" + caps.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> "ethernet" + caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN) -> "VPN" + else -> "other" + } + append("Transport ").append(transport).append('\n') + append("Validated ") + .append(caps?.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) ?: "unknown") + .append(" (false with a working link usually means a captive portal)\n") + append("Metered ") + .append(caps?.let { !it.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) } ?: "unknown") + .append('\n') + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && caps != null) { + append("Link speed down ").append(caps.linkDownstreamBandwidthKbps) + .append(" kbps / up ").append(caps.linkUpstreamBandwidthKbps).append(" kbps\n") + } + val link = cm.getLinkProperties(network) + append("Interface ").append(link?.interfaceName ?: "unknown").append('\n') + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + append("MTU ").append(link?.mtu ?: 0).append('\n') + } + val v4 = link?.linkAddresses.orEmpty().count { it.address is Inet4Address } + val v6 = link?.linkAddresses.orEmpty().count { it.address is Inet6Address } + append("Addresses ").append(v4).append(" IPv4, ").append(v6).append(" IPv6") + .append(if (v4 == 0) " (no IPv4 - Steam's content servers need it)" else "").append('\n') + append("DNS from the system ") + .append(link?.dnsServers.orEmpty().joinToString(", ") { it.hostAddress ?: "?" }.ifEmpty { "none" }) + .append('\n') + append("Search domains ").append(link?.domains ?: "none").append('\n') + } + + append("\nWhat the runtime was given\n") + append("--------------------------\n") + // The app writes this file from the live link at every change; it is what everything inside + // the session resolves with, so a mismatch with the system's list above is the bug itself. + val resolv = File(LinuxRuntime.rootDir(context), "etc/resolv.conf") + if (resolv.isFile) { + append("etc/resolv.conf:\n") + FileUtils.readString(resolv)?.lines()?.forEach { append(" ").append(it).append('\n') } + } else { + append("etc/resolv.conf does not exist yet - written when the session's link is published.\n") + } + val netdev = File(LinuxRuntime.rootDir(context), "etc/bannerlator-net") + if (netdev.isFile) { + append("\netc/bannerlator-net (the link as the session sees it):\n") + FileUtils.readString(netdev)?.lines()?.forEach { append(" ").append(it).append('\n') } + } + append("\nproot makes no network namespace, so the session uses the phone's connection\n") + append("directly: IPv4 and IPv6 both pass through, and there is nothing to forward.\n") + append("The Steam client's own network panel drives NetworkManager over D-Bus, which this\n") + append("runtime does not have - \"wifi is off\" there is cosmetic and not evidence.\n") + } +} diff --git a/app/src/main/java/com/steamdeck/launcher/core/SessionLogCapture.kt b/app/src/main/java/com/steamdeck/launcher/core/SessionLogCapture.kt new file mode 100644 index 0000000000..4d5e7f3b50 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/core/SessionLogCapture.kt @@ -0,0 +1,110 @@ +package com.steamdeck.launcher.core + +import android.os.Process +import android.util.Log +import java.io.BufferedWriter +import java.io.File + +/** + * `app.log`: what the app itself said while the session ran, and `crash.log`: what Android's crash + * buffer holds if something died hard. + * + * Everything this app decides is reported through `Log` - which driver was chosen and why, the + * audio line, a rival client being stopped, the session's exit status, a helper that was missing. + * None of it reaches a user's folder, so a report used to arrive with the settings visible in + * `device.txt` and no record of what actually happened. An app may always read back its own log + * entries, so the simplest complete answer is to run `logcat` filtered to our own pid and keep + * what it says. + * + * `logcat -b crash` earns its own file: proot once died before `main` over a missing library, and + * that appeared in the crash buffer and *nowhere else* - not in the session log, not in the main + * buffer. It is the first thing to read when a session "exits instantly". + * + * Both are best-effort. Where a ROM refuses to hand an app its own entries the files are written + * with a line saying so, which is better than their absence looking like silence. + */ +object SessionLogCapture { + private const val TAG = "SessionLogCapture" + + private var pid = -1 + private var writer: BufferedWriter? = null + + /** Start mirroring this process's log lines into [target]. Safe to call twice. */ + @Synchronized + fun start(target: File) { + stop() + try { + val out = target.bufferedWriter() + out.write("The app's own log for this session (logcat, this process only).\n") + out.write("Lines the app wrote before the session folder existed are in logcat only.\n\n") + out.flush() + writer = out + // -T 1 starts at the newest line rather than replaying the whole buffer; -v threadtime + // keeps the timestamps and thread ids that make two logs line up. + pid = ProcessHelper.exec( + "/system/bin/logcat -v threadtime -T 1 --pid=" + Process.myPid(), + null, target.parentFile, null, + ) { line -> + synchronized(this) { + try { + writer?.apply { write(line); newLine(); flush() } + } catch (e: Exception) { + // A full or unmounted card must not take the session with it. + } + } + } + if (pid == -1) { + out.write("logcat could not be started; this ROM may not hand an app its own entries.\n") + out.flush() + } + Log.i(TAG, "app log -> $target (logcat pid $pid)") + } catch (e: Exception) { + Log.w(TAG, "could not start the app log", e) + } + } + + @Synchronized + fun stop() { + if (pid != -1) { + try { + Process.killProcess(pid) + } catch (e: Exception) { + Log.w(TAG, "logcat would not stop", e) + } + pid = -1 + } + try { + writer?.close() + } catch (e: Exception) { + // nothing useful to do with a failure to close a log + } + writer = null + } + + /** + * Dump Android's crash buffer into [target]. Called at teardown: a session that was killed is + * exactly when this matters, and the buffer keeps its entries after the process is gone. + */ + fun dumpCrashBuffer(target: File) { + try { + val lines = StringBuilder() + val rc = ProcessHelper.exec( + "/system/bin/logcat -b crash -d -v threadtime -t 400", null, target.parentFile, null, + ) { line -> lines.append(line).append('\n') } + // exec returns a pid and runs on; give the dump a moment to finish rather than racing it. + var waited = 0 + while (waited < 3000 && lines.isEmpty()) { + Thread.sleep(100) + waited += 100 + } + target.writeText( + "Android's crash buffer, as it stood when this session ended.\n" + + "Not only this app: anything on the device that crashed is in here, which is the\n" + + "point - a session killed by the system leaves its trace here and nowhere else.\n\n" + + (if (lines.isEmpty()) "(empty, or this ROM does not hand an app the crash buffer; logcat rc=$rc)\n" else lines.toString()) + ) + } catch (e: Exception) { + Log.w(TAG, "could not dump the crash buffer", e) + } + } +} diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt index 23cd786aae..668591f445 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt @@ -25,6 +25,8 @@ import com.steamdeck.launcher.core.CpuCores import com.steamdeck.launcher.core.DeviceReport import com.steamdeck.launcher.core.EnvVars import com.steamdeck.launcher.core.LogRedactor +import com.steamdeck.launcher.core.SessionLogCapture +import com.steamdeck.launcher.core.NetworkReport import com.steamdeck.launcher.core.EnvironmentComponent import com.steamdeck.launcher.core.FileUtils import com.steamdeck.launcher.core.ProcessHelper @@ -109,9 +111,13 @@ class SessionService : Service() { } Log.i(TAG, "collected ${out.listFiles()?.size ?: 0} Steam log(s), scrubbed, into $out") } + // A session the system killed leaves its trace here and nowhere else. + SessionLogCapture.dumpCrashBuffer(File(dir, "crash.log")) } catch (e: Exception) { Log.w(TAG, "collecting session artifacts", e) } finally { + // Last, so everything above is in the file it is about. + SessionLogCapture.stop() SessionPaths.release() } } @@ -159,6 +165,10 @@ class SessionService : Service() { SessionState.logFile = sessionLog // Written first, so a session that dies in its first second still says what it ran on. DeviceReport.write(this, File(sessionDir, "device.txt"), SessionState.mode) + NetworkReport.write(this, File(sessionDir, "network.txt")) + // Everything the app decides from here on - the driver it chose, the audio line, a rival + // client stopped, the exit status - reaches logcat and nowhere a user can get at. Mirror it. + SessionLogCapture.start(File(sessionDir, "app.log")) val size = SessionState.outputSize val guest = ArrayList() @@ -229,13 +239,16 @@ class SessionService : Service() { val relaySocket = File(audioDir, "relay.sock") val micFifo = if (wantsMic) File(audioDir, "mic.fifo") else null + val audioLog = File(sessionDir, "audio.log") val pulse = PulseAudioComponent(this, micFifo?.absolutePath) + pulse.setLogFile(audioLog) pulse.setContext(this) guest.add("PULSE_SERVER=unix:" + pulse.socket().absolutePath) components.add(pulse) if (wantsDirectAudio || wantsMic) { // After the daemon in the list, so it can wait for the pipe the daemon makes. val relay = DirectAudioRelayComponent(relaySocket, micFifo) + relay.setLogFile(audioLog) relay.setContext(this) components.add(relay) }