Start a session on every Play, not only on the compositor's first start

The compositor lives for the whole process, so the second Play after a session
had ended re-attached the Surface, started nothing, and left the loading panel
counting up over a dead session — it looked like a login that never came. The
service now starts whenever no session is running; the compositor's one-shot
first-frame notice is re-armed for the new session, or the panel would never
leave; and whatever the previous session left behind (gamescopereaper, the
session script, a dead client's helpers, the audio server) is killed first,
since it is our uid and still holds the socket the new one needs.
This commit is contained in:
The412Banner committed 2026-09-19 14:59:12 -04:00
1 parent ebae834e36
commit d46bd4a0c3
6 files changed
+63 -4

No files matched your search

@@ -108,14 +108,19 @@ class SessionActivity : Activity(), SurfaceHolder.Callback {
val size = outputSize()
SessionState.outputSize = size
SessionState.refreshHz = refreshHz()
val first = CompositorHost.startOrAttach(
CompositorHost.startOrAttach(
holder.surface, runtimeDir.path,
driverId?.let { turnip.driverPath(it) }, driverId?.let { turnip.libraryName(it) },
applicationInfo.nativeLibraryDir, size.first, size.second, refreshHz(),
)
// The service owns everything below the compositor, and starting it is idempotent: coming
// back to a running session just re-attaches the Surface above.
if (first) SessionService.start(this)
// The service owns everything below the compositor. It is started whenever no session is
// running — NOT only when the compositor was just started: the compositor lives for the
// whole process, so the second Play after a session ended used to re-attach the Surface,
// start nothing, and leave the loading panel counting up over a dead session.
if (!SessionState.running) {
CompositorHost.newSession()
SessionService.start(this)
}
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {}
@@ -79,6 +79,7 @@ class SessionService : Service() {
val root = LinuxRuntime.rootDir(this)
val sessionRoot = LinuxRuntime.sessionRoot(this).apply { mkdirs() }
val runtimeDir = File(filesDir, ".wayland-rt").apply { mkdirs() }
killStragglers()
SessionFiles.stage(this, root)
val logDir = SessionFiles.logDirectory(this)
@@ -174,6 +175,31 @@ class SessionService : Service() {
Log.i(TAG, "session pid $sessionPid, log ${sessionLog.path}")
}
/**
* proot's --kill-on-exit takes its tracees down, but a session that died from the inside
* (the client asserting, Xwayland going) leaves gamescopereaper and the session script
* behind, still holding the Wayland socket and the audio server the next session needs. They
* are our uid, so they are ours to kill.
*/
private fun killStragglers() {
val me = android.os.Process.myPid()
val procs = File("/proc").listFiles { f -> f.name.all { it.isDigit() } } ?: return
var killed = 0
for (proc in procs) {
val pid = proc.name.toIntOrNull() ?: continue
if (pid == me) continue
val cmdline = try {
File(proc, "cmdline").readBytes().toString(Charsets.UTF_8).replace('\u0000', ' ')
} catch (e: Exception) {
continue
}
if (STRAGGLERS.none { cmdline.contains(it) }) continue
android.os.Process.killProcess(pid)
killed++
}
if (killed > 0) Log.w(TAG, "killed $killed leftover process(es) of a previous session")
}
private fun stopSession(status: Int) {
if (!SessionState.running) return
SessionState.running = false
@@ -301,6 +327,9 @@ class SessionService : Service() {
private const val CHANNEL_ID = "session"
private const val NOTIFICATION_ID = 1001
const val ACTION_STOP = "com.steamdeck.launcher.STOP_SESSION"
/** Command lines that can only belong to a session of ours. */
private val STRAGGLERS = listOf("bannerlator-session", "gamescope", "Xwayland", "steamrtarm64",
"steamwebhelper", "linuxfs/opt/android-host/proot", "pulseaudio/libpulseaudio.so")
private const val NO_PAD_SWITCH = "Download/steamdeck-no-pad"
private const val PAD_LOG_SWITCH = "Download/steamdeck-pad-log"
@@ -70,5 +70,13 @@ object CompositorHost {
vsyncRunning = false
}
/**
* A new session behind a compositor that has already presented: the first-frame notice is
* one-shot in native code, so it is re-armed here or the loading panel would never leave.
*/
fun newSession() {
if (started) WaylandCompositor.nativeResetFirstFrame()
}
val isStarted: Boolean get() = started
}
@@ -240,6 +240,10 @@ public final class WaylandCompositor {
* list stops at the desktop size, as the X server's does on X11. Set before the compositor starts. */
public static native void nativeSetOutputSize(int width, int height);
/** Re-arms the one-shot first-frame notice, for a new session under a compositor that has
* already presented a previous one. */
public static native void nativeResetFirstFrame();
// ── HDR10 output, round 1 (waylandcomp/src/banner_color.h, wl_color_mgmt.c) ─────────────────
// Opt-in: BANNER_WAYLAND_HDR=1 in the container's or shortcut's env vars. The compositor offers
// games HDR10 (wp_color_manager_v1 + 10-bit buffers, frames tagged BT2020_PQ on the game's own