From eeb76ae1867820fe406b0f3da0d8cb7680fe18ca Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Sun, 6 Dec 2026 07:59:59 -0500 Subject: [PATCH 1/2] fix(game-env): the audio-stream probe of a game launch ends when the game does (#2965) * fix(game-env): the audio-stream probe of a game launch ends when the game does * fix(game-env): the audio-stream probe checks the game is still running before each sample --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> --- .../overlay/usr/local/bin/droiddeck-game-env | 13 +++- tools/tests/test_game_environment.py | 60 +++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env index bc4c7c73c8..5dfa7803a1 100755 --- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env +++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-game-env @@ -1658,6 +1658,16 @@ def system_graphics_launch(command, env): return [str(wrapper), *command], result +AUDIO_STREAMS_PROBE = ( + 'folder=$1; launch=$2; shift 2; n=0; ' + 'for t in "$@"; do ' + 'while [ "$n" -lt "$t" ]; do kill -0 "$launch" 2>/dev/null || exit 0; sleep 1; n=$((n + 1)); done; ' + 'kill -0 "$launch" 2>/dev/null || exit 0; ' + '{ echo "== $(date +%T)"; pactl list sink-inputs 2>&1 | head -80; } >> "$folder/audio-streams.txt"; ' + 'done' +) + + def game_logs(command, env, app_id, now=None): """Detailed graphics logs for one game launch, in the session's log folder: Proton's own log, DXVK's and vkd3d-proton's, and the Vulkan driver's startup messages. The app turns this on @@ -1703,8 +1713,7 @@ def game_logs(command, env, app_id, now=None): pass # Whether the game's sound reaches PulseAudio: the streams 20 s and 60 s in, without waiting. try: - subprocess.Popen(["sh", "-c", 'for t in 20 40; do sleep $t; { echo "== $(date +%T)"; ' - 'pactl list sink-inputs 2>&1 | head -80; } >> "$1/audio-streams.txt"; done', "audio", str(folder)], + subprocess.Popen(["sh", "-c", AUDIO_STREAMS_PROBE, "audio", str(folder), str(os.getpid()), "20", "60"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) except OSError: diff --git a/tools/tests/test_game_environment.py b/tools/tests/test_game_environment.py index a20a86186e..f0d6c1f594 100644 --- a/tools/tests/test_game_environment.py +++ b/tools/tests/test_game_environment.py @@ -13,6 +13,7 @@ import subprocess import sys import tempfile import threading +import time from unittest import mock import unittest from unittest.mock import patch @@ -2499,6 +2500,65 @@ class GameEnvironmentTest(unittest.TestCase): self.assertIn("exe: first.exe", (Path(first["PROTON_LOG_DIR"]) / "launch.txt").read_text()) self.assertIn("exe: second.exe", (Path(second["PROTON_LOG_DIR"]) / "launch.txt").read_text()) + def test_audio_probe_watches_this_launch(self): + with tempfile.TemporaryDirectory() as tmp, mock.patch("subprocess.Popen") as popen: + env = {"DD_GAME_LOGS": "1", "DD_DEBUG_DIR": tmp} + result = MODULE["game_logs"](["/proton", "waitforexitandrun", "game.exe"], env, "42", now=0) + self.assertEqual(popen.call_args.args[0], [ + "sh", "-c", MODULE["AUDIO_STREAMS_PROBE"], "audio", result["PROTON_LOG_DIR"], str(os.getpid()), "20", "60", + ]) + + def test_audio_probe_ends_with_the_game_and_keeps_its_samples_while_it_runs(self): + probe = ["sh", "-c", MODULE["AUDIO_STREAMS_PROBE"], "audio"] + + def samples(folder): + path = Path(folder) / "audio-streams.txt" + return sum(line.startswith("== ") for line in path.read_text().splitlines()) if path.exists() else 0 + + with tempfile.TemporaryDirectory() as tmp: + game = subprocess.Popen(["sleep", "60"]) + try: + subprocess.run(probe + [tmp, str(game.pid), "1", "2"], timeout=15, check=True) + self.assertEqual(samples(tmp), 2) + finally: + game.kill() + game.wait() + + with tempfile.TemporaryDirectory() as tmp: + game = subprocess.Popen(["sleep", "60"]) + running = subprocess.Popen(probe + [tmp, str(game.pid), "1", "600"]) + try: + deadline = time.monotonic() + 15 + while samples(tmp) < 1 and time.monotonic() < deadline: + time.sleep(0.1) + self.assertEqual(samples(tmp), 1) + game.kill() + game.wait() + self.assertEqual(running.wait(timeout=10), 0) + self.assertEqual(samples(tmp), 1) + finally: + game.kill() + game.wait() + running.kill() + running.wait() + + with tempfile.TemporaryDirectory() as tmp: + ended = subprocess.Popen(["true"]) + ended.wait() + subprocess.run(probe + [tmp, str(ended.pid), "20", "60"], timeout=10, check=True) + self.assertEqual(samples(tmp), 0) + + with tempfile.TemporaryDirectory() as tmp: + game = subprocess.Popen(["sleep", "0.5"]) + running = subprocess.Popen(probe + [tmp, str(game.pid), "1"]) + try: + game.wait() + self.assertEqual(running.wait(timeout=10), 0) + self.assertEqual(samples(tmp), 0) + finally: + running.kill() + running.wait() + def test_open_driver_pairs_report_the_drivers_own_vkd3d_caps(self): apply = MODULE["apply_config"] config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2", "VKD3D_SHADER_MODEL": "6_9"}, From 051b188159325c5f1e9a28f58505d869ea53c916 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Sun, 6 Dec 2026 08:18:50 -0500 Subject: [PATCH 2/2] Preserve installed resource IDs in Lab builds (#3781) --- docs/lab-builds.md | 3 ++- tools/agent/dd-lab-build | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/lab-builds.md b/docs/lab-builds.md index 2e01e3b9d8..d2a59bef02 100644 --- a/docs/lab-builds.md +++ b/docs/lab-builds.md @@ -14,7 +14,8 @@ after restarting. If no complete copy exists, the pack uses the checkout's pin. - `tools/agent/dd-lab-build` builds the checkout with Gradle on the device (`processReleaseResources` and `mergeDexRelease`), packs the linked resources and dex files into `overlay.apk`, writes `overlay.json`, and stages both in the app's `files/lab/next`. It then recompiles the app without - an app image and restarts DroidDeck. + an app image and restarts DroidDeck. The resource linker uses IDs from the installed APK so + base and overlay code resolve the same resource names. - Run by the app's own agent (`DD_AGENT` set), it writes `files/agent/lab-request` instead, and the app runs the build in a process of its own, logging to `~/.cache/dd-lab-build.log`; the agent's copy follows that log and exits with the build. A turn's processes end with the turn, so a build diff --git a/tools/agent/dd-lab-build b/tools/agent/dd-lab-build index 459b12e640..88aab0da1d 100755 --- a/tools/agent/dd-lab-build +++ b/tools/agent/dd-lab-build @@ -134,6 +134,54 @@ fi gradle=(./gradlew :app:processReleaseResources :app:mergeDexRelease --max-workers=2 -PskipRust=true -x buildVkBridgeServer -Pandroid.aapt2FromMavenOverride=$HOME/aapt2/aapt2 -Pkotlin.compiler.execution.strategy=daemon -Pkotlin.daemon.jvmargs=-Xmx${kotlin_heap}m -Dorg.gradle.jvmargs=-Xmx${gradle_heap}m --console=plain) +# Release package aliases rewrite the manifest but keep the resource table under the linker package. +resource_package=com.droiddeck.launcher +resource_cache=$cache/dd-lab-resource-ids +mkdir -p "$resource_cache" +resource_key=$(printf '%s\n' "$pkg" "$base" "$apk" | sha256sum | cut -d ' ' -f1) +stable_ids=$resource_cache/$resource_key.txt +if [ ! -s "$stable_ids" ]; then + progress checking 0 "reading the installed APK resource IDs" + if ! ( + resource_work=$(mktemp -d "$resource_cache/.extract.XXXXXX") || exit 1 + trap 'rm -rf "$resource_work"' EXIT + adb -s "$serial" pull "$apk" "$resource_work/base.apk" >/dev/null && + "$HOME/aapt2/aapt2" dump resources "$resource_work/base.apk" > "$resource_work/resources.txt" && + awk -v package="$resource_package" ' + $1 == "Package" { in_package = ($2 == "name=" package) } + in_package && $1 == "resource" && $2 ~ /^0x[[:xdigit:]]+$/ { + print package ":" $3 " = " $2 + count++ + } + END { if (!count) exit 1 } + ' "$resource_work/resources.txt" > "$resource_work/ids.txt" && + mv "$resource_work/ids.txt" "$stable_ids" + ); then + fail "could not read resource IDs from the installed APK" + fi +fi + +resource_init=$resource_cache/link.gradle +cat > "$resource_init.part.$$" <<'EOF' +gradle.beforeProject { project -> + if (project.path == ':app') { + project.pluginManager.withPlugin('com.android.application') { + project.androidComponents.finalizeDsl { android -> + android.androidResources.additionalParameters.addAll([ + '--stable-ids', project.providers.gradleProperty('droiddeckLabStableIds').get() + ]) + } + } + } +} +EOF +if cmp -s "$resource_init.part.$$" "$resource_init"; then + rm "$resource_init.part.$$" +else + mv "$resource_init.part.$$" "$resource_init" +fi +gradle+=(--init-script "$resource_init" "-PdroiddeckLabStableIds=$stable_ids") + progress planning plan_file=$cache/dd-lab-build-plan plan_key=$(