From 6840b9139fb1513638813a2157be1d3886304fd1 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:12:19 -0400 Subject: [PATCH] fix: let the Steam client shut down cleanly when a session stops (#68) --- .../launcher/session/SessionService.kt | 22 ++++++++++++++++ .../overlay/usr/local/bin/bannerlator-session | 25 +++++++++++++++++++ 2 files changed, 47 insertions(+) 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 0cc8bdedd9..590dd834e8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -736,6 +736,24 @@ class SessionService : Service() { return try { Pair(fields[1].toInt(), fields[19].toLong()) } catch (e: NumberFormatException) { null } } + private fun askSteamToExit(prootPid: Int) { + if (!File("/proc/$prootPid").exists()) return + val request = File(LinuxRuntime.sessionRoot(this), "steam-stop") + try { + request.writeText("") + } catch (e: Exception) { + Log.w(TAG, "could not ask the Steam client to exit", e) + return + } + val started = System.currentTimeMillis() + if (waitForExit(prootPid, STEAM_PICKUP_MS) || request.exists()) { + request.delete() + return + } + val exited = waitForExit(prootPid, STEAM_EXIT_MS) + Log.i(TAG, "Steam client ${if (exited) "exited" else "did not exit"} after ${System.currentTimeMillis() - started} ms") + } + private fun waitForExit(pid: Int, timeoutMs: Long): Boolean { val deadline = System.currentTimeMillis() + timeoutMs while (System.currentTimeMillis() < deadline) { @@ -953,9 +971,11 @@ class SessionService : Service() { } components.clear() FakeInputWriter.releaseAllRingSlots() + val steamClientMayRun = SessionState.mode == MODE_STEAM || SessionState.mode == MODE_DESKTOP val finishAfterTeardown: () -> Unit = { if (prootPid > 1 || auxiliary.isNotEmpty()) { Thread({ + if (prootPid > 1 && steamClientMayRun) askSteamToExit(prootPid) auxiliary.forEach { (pid, started) -> teardown(pid, started) } if (prootPid > 1) teardown(prootPid) killGuestLeftovers() @@ -1114,6 +1134,8 @@ class SessionService : Service() { "steamwebhelper", "linuxfs/opt/android-host/proot", "/libproot.so", "pulseaudio/libpulseaudio.so") /** How long proot gets to run its own cleanup before it is killed outright. */ private const val GRACE_MS = 1200L + private const val STEAM_PICKUP_MS = 1500L + private const val STEAM_EXIT_MS = 10_000L private const val NO_PAD_SWITCH = "Download/droiddeck-no-pad" private const val PAD_LOG_SWITCH = "Download/droiddeck-pad-log" diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index 1cb8472a39..b7fdc0a552 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -547,6 +547,23 @@ BUSCONF # An update that cannot install asks for a restart (rc=42) every time; the count is capped so a # session can never again loop in silence, which reads as a menu opening and closing by itself. steam_updates=0 + rm -f "$HOME/.bl-stop-requested" + if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -d "$BL_LAUNCH_DIR" ]; then + rm -f "$BL_LAUNCH_DIR/steam-stop" + ( + while :; do + if [ -e "$BL_LAUNCH_DIR/steam-stop" ]; then + rm -f "$BL_LAUNCH_DIR/steam-stop" + : > "$HOME/.bl-stop-requested" + echo "== steam: the app asked for a clean exit" + "$steam_root/steamrtarm64/steam" -shutdown >/dev/null 2>&1 || true + exit 0 + fi + sleep 0.5 + done + ) & + stop_watcher=$! + fi while :; do rm -f "$HOME/.bl-restart-once" if [ -f "$steam_beta" ] && [ "$(cat "$steam_beta" 2>/dev/null)" != "$steam_channel" ]; then @@ -563,6 +580,10 @@ BUSCONF if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then bannerlator-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true fi + if [ -f "$HOME/.bl-stop-requested" ]; then + rm -f "$HOME/.bl-stop-requested" "$HOME/.bl-restart-once" + break + fi # The session asked for this exit (the ARM64 Proton landed): start again, without the URL # arguments, which were acted on. Not counted against the update cap. if [ -f "$HOME/.bl-restart-once" ]; then @@ -579,6 +600,10 @@ BUSCONF # The URL arguments were acted on the first time; a restart must not repeat them. set -- done + if [ -n "${stop_watcher:-}" ]; then + kill "$stop_watcher" 2>/dev/null || true + wait "$stop_watcher" 2>/dev/null || true + fi if [ -n "${games_watcher:-}" ]; then kill "$games_watcher" 2>/dev/null || true wait "$games_watcher" 2>/dev/null || true