diff --git a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt index d5f9e97961..dc20875057 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/DeviceReport.kt @@ -181,8 +181,14 @@ object DeviceReport { h("Android process limits") k("Phantom proc monitor", PhantomProcessLimit.reportValue(PhantomProcessLimit.read(context))) - h("Device switch files in Download") - for (name in listOf("droiddeck-env", "droiddeck-tu-debug", "droiddeck-driver", + h("Device switch files") + SessionService.envSwitchFile(context)?.takeIf { it.isFile }?.let { f -> + k("droiddeck-env", FileUtils.readString(f)?.trim()?.replace('\n', ' ')?.ifEmpty { "(present, empty)" } ?: "(present)") + } + if (File(Environment.getExternalStorageDirectory(), "Download/droiddeck-env").isFile) { + k("Download/droiddeck-env", "(ignored - it moved to Android/data/${context.packageName}/files)") + } + for (name in listOf("droiddeck-tu-debug", "droiddeck-driver", "droiddeck-osc", "droiddeck-no-pad", "droiddeck-no-hud", "droiddeck-wlr-renderer")) { val f = File(Environment.getExternalStorageDirectory(), "Download/$name") 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 96d02cee63..0ea919b1c8 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -285,11 +285,15 @@ class SessionService : Service() { } private fun extraEnv(): List { - val file = File(Environment.getExternalStorageDirectory(), ENV_SWITCH).takeIf { it.isFile } ?: return emptyList() + if (File(Environment.getExternalStorageDirectory(), LEGACY_ENV_SWITCH).isFile) { + Log.w(TAG, "ignoring $LEGACY_ENV_SWITCH: any app with storage access can write there; " + + "the file now lives at ${envSwitchFile(this)?.path ?: "(not available before Android 11)"}") + } + val file = envSwitchFile(this)?.takeIf { it.isFile } ?: return emptyList() val lines = FileUtils.readString(file)?.lines().orEmpty() .map { it.trim() } .filter { it.isNotEmpty() && !it.startsWith("#") && it.contains('=') && !it.startsWith("=") } - if (lines.isNotEmpty()) Log.i(TAG, "extra environment from $ENV_SWITCH: $lines") + if (lines.isNotEmpty()) Log.i(TAG, "extra environment from ${file.path}: $lines") return lines } @@ -649,10 +653,11 @@ class SessionService : Service() { // GAMESCOPE_FORCE_VULKAN_REALTIME); off unless the user turns it on. guest.add("BL_GAMESCOPE_REALTIME=" + (if (SessionPrefs.gamescopeRealtime(this)) "1" else "0")) guest.add("BANNER_AUDIO_DIRECT_DECAY=0") - // Anything else, for a device that cannot be reached with a debugger: Downloads/droiddeck-env - // holds KEY=VALUE lines that go into the session's environment as written, after ours, so a - // line here wins. Zink and Turnip tunables (ZINK_DESCRIPTORS=lazy, MESA_*), gamescope's, - // the client's - whatever the experiment needs, without a build per attempt. + // Anything else, for a device that cannot be reached with a debugger: droiddeck-env in the + // app's own external files (envSwitchFile) holds KEY=VALUE lines that go into the session's + // environment as written, after ours, so a line here wins. Zink and Turnip tunables + // (ZINK_DESCRIPTORS=lazy, MESA_*), gamescope's, the client's - whatever the experiment + // needs, without a build per attempt. extraEnv().forEach { guest.add(it) } // Core masks, Bannerlator's two (cfca3912). The client's is sent whenever the override is // on, even naming every core: it exists to undo the pin Steam applies to its own interface @@ -1700,8 +1705,25 @@ class SessionService : Service() { private const val TRACER_NICE = -6 /** Downloads file whose contents become TU_DEBUG inside the session, e.g. "sysmem". */ private const val TU_DEBUG_SWITCH = "Download/droiddeck-tu-debug" - /** Downloads file of KEY=VALUE lines added to the session environment verbatim. */ - private const val ENV_SWITCH = "Download/droiddeck-env" + /** + * Where droiddeck-env (KEY=VALUE lines added to the session environment verbatim) used to + * be. Ignored now: a line there reaches the Steam client's environment as written + * (LD_PRELOAD, VK_ICD_FILENAMES, PATH...), and any app with storage access can write to + * Download - code of its choosing inside our sandbox, next to the client's saved login. + */ + private const val LEGACY_ENV_SWITCH = "Download/droiddeck-env" + private const val ENV_SWITCH_NAME = "droiddeck-env" + + /** + * The session's extra-environment file: Android/data//files/droiddeck-env. Only + * this app, adb and the user (through the app's own file manager) can write there - from + * Android 11 on. Before that other apps with storage access can reach Android/data too, so + * there is no such file at all. + */ + fun envSwitchFile(context: Context): File? = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) + context.getExternalFilesDir(null)?.let { File(it, ENV_SWITCH_NAME) } + else null private const val CHANNEL_ID = "session" private const val NOTIFICATION_ID = 1001 const val ACTION_STOP = "com.droiddeck.launcher.STOP_SESSION" diff --git a/docs/development/steam-display-scaling.md b/docs/development/steam-display-scaling.md index e24bebf65d..299f4b188b 100644 --- a/docs/development/steam-display-scaling.md +++ b/docs/development/steam-display-scaling.md @@ -61,7 +61,7 @@ Why the current choices were made, from the history: All runs on the AYN Thor (SD 8 Gen 2, Adreno 740, 1920x1080 top panel), Deck mode on, Force fullscreen off, with a spike build of `feat/steam-native-output`. Each run sets -`Download/droiddeck-env` and starts the session with +`Android/data/com.droiddeck.launcher/files/droiddeck-env` and starts the session with `am start -n com.droiddeck.launcher/.SessionActivity --es mode steam [--es steamUrl ...]`. ### Run 1: baseline (Resolution = Match screen, 1920x1080) @@ -181,7 +181,7 @@ game. `--xwayland-count 2` and `STEAM_MULTIPLE_XWAYLANDS=1` went through `Downlo ## Two Xwayland servers by default (`feat/steam-dual-xwayland`) Steam sessions now start gamescope with `--xwayland-count 2` and `STEAM_MULTIPLE_XWAYLANDS=1`. -`BL_XWAYLAND_COUNT=1` in `Download/droiddeck-env` goes back to one. The session script's +`BL_XWAYLAND_COUNT=1` in `Android/data/com.droiddeck.launcher/files/droiddeck-env` goes back to one. The session script's root-window requests that are meant for the game (the drawer's live Force fullscreen, `GAMESCOPE_FORCE_WINDOWS_FULLSCREEN`, and the resume watcher's `GAMESCOPE_RESTORE_FOCUS_WINDOW`) go to both displays, `$DISPLAY` and `STEAM_GAME_DISPLAY_0`. gamescope reads both per server, so @@ -222,7 +222,7 @@ reason "Force game windows fullscreen" existed. What it still did was make any g Resolution differs from what it draws fight it (runs 4 and 5). The switch is gone from Steam settings (Games) and the session drawer (Display), along with its preference, the `BL_GAMESCOPE_FORCE_FULLSCREEN` flag, the `~/.droiddeck-fill` live watcher and the device report -line. `BL_GAMESCOPE_ARGS=--force-windows-fullscreen` in `Download/droiddeck-env` still passes the +line. `BL_GAMESCOPE_ARGS=--force-windows-fullscreen` in `Android/data/com.droiddeck.launcher/files/droiddeck-env` still passes the flag for an experiment. Device check (Thor): Alan Wake's American Nightmare with its 1280x720 Game Resolution runs on `:1` diff --git a/docs/development/steam-focus-debugging.md b/docs/development/steam-focus-debugging.md index f18062edcb..42ec5da320 100644 --- a/docs/development/steam-focus-debugging.md +++ b/docs/development/steam-focus-debugging.md @@ -81,7 +81,7 @@ $R/usr/lib/ld-linux-aarch64.so.1 --library-path $R/usr/lib $R/usr/bin/xprop -dis nothing. - To test gamescope with a candidate binary without rebuilding the apk, put it in the rootfs (for example `/opt/gstest/gamescope`, owned by the app's uid) and add - `PATH=/opt/gstest:/usr/local/bin:/usr/bin:/bin` to `Download/droiddeck-env`. The session log's + `PATH=/opt/gstest:/usr/local/bin:/usr/bin:/bin` to `Android/data/com.droiddeck.launcher/files/droiddeck-env`. The session log's first lines name the gamescope that ran. Remove the line afterwards: the app stages its own gamescope over `/usr/local/bin` at every session start. - Never `pkill -f ` inside `su -c '…'`: the pattern matches that shell's own command line.