Add Quest 3/3S compatibility to the standard APK (#642)

This commit is contained in:
Jagger15 authored and GitHub committed 2026-10-12 17:13:07 -04:00
1 parent 5e38e79c96
commit 2503d69293
25 files changed
+659 -12

No files matched your search

+84
View File
@@ -0,0 +1,84 @@
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
PROGRAM = r"""
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#ifdef BACKEND
int ioctl(int fd, unsigned long request, ...) {
va_list ap;
va_start(ap, request);
int *value = va_arg(ap, int *);
va_end(ap);
assert(fd == -1 && request == 0x12345678 && value);
*value = 0x51;
errno = EACCES;
return -1;
}
#else
int main(int argc, char **argv) {
if (argc > 1) {
int value = 0;
assert(ioctl(-1, 0x12345678, &value) == -1);
assert(value == 0x51 && errno == EACCES);
} else {
int fds[2];
assert(pipe(fds) == 0);
struct termios term;
assert(ioctl(fds[0], TCGETS, &term) == -1 && errno == ENOTTY);
close(fds[0]);
close(fds[1]);
}
return 0;
}
#endif
"""
@unittest.skipUnless(sys.platform == "linux" and shutil.which("gcc") and shutil.which("g++"),
"needs Linux, gcc and g++")
class FakeinputIoctlTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmp = tempfile.TemporaryDirectory()
cls.addClassCleanup(cls.tmp.cleanup)
cls.path = Path(cls.tmp.name)
source = cls.path / "program.c"
source.write_text(PROGRAM)
subprocess.run(["gcc", "-o", str(cls.path / "program"), str(source)], check=True)
subprocess.run(["gcc", "-shared", "-fPIC", "-DBACKEND", "-o",
str(cls.path / "backend.so"), str(source)], check=True)
subprocess.run(["g++", "-shared", "-fPIC", "-O2", "-Wno-attributes", "-pthread",
"-std=c++17", "-static-libstdc++", "-static-libgcc",
"-Wl,--exclude-libs,ALL", "-o", str(cls.path / "libfakeinput.so"),
str(SOURCE), "-ldl"], check=True)
def run_program(self, backend=False):
preload = str(self.path / "libfakeinput.so")
args = [str(self.path / "program")]
if backend:
preload += ":" + str(self.path / "backend.so")
args.append("backend")
subprocess.run(args, env=dict(os.environ, LD_PRELOAD=preload), check=True, timeout=10)
def test_later_interposer_receives_arguments_and_returns_errno(self):
self.run_program(backend=True)
def test_libc_passthrough_retains_kernel_error(self):
self.run_program()
if __name__ == "__main__":
unittest.main()
+23
View File
@@ -0,0 +1,23 @@
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest
QUEST = Path(__file__).resolve().parents[1] / 'quest'
@unittest.skipUnless(sys.platform == 'linux' and shutil.which('gcc'), 'needs Linux and gcc')
class QuestKgslTest(unittest.TestCase):
def test_allocation_passthrough_translation_and_cleanup(self):
with tempfile.TemporaryDirectory() as folder:
binary = str(Path(folder) / 'test-kgsl')
subprocess.run(['gcc', '-Wall', '-Wextra', '-Werror', '-O2', '-o', binary,
str(QUEST / 'test_kgsl_compat.c'), str(QUEST / 'kgsl_compat.c')], check=True)
result = subprocess.run([binary], capture_output=True, text=True, check=True, timeout=10)
self.assertIn('PASS: 12 GPUOBJ', result.stdout)
if __name__ == '__main__':
unittest.main()
+14
View File
@@ -55,6 +55,20 @@ class RuntimeInputsTest(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'sources changed'):
runtime.verify(self.root)
def test_changed_quest_source_rejects_old_outputs(self):
source = self.root / 'tools/quest/kgsl_compat.c'
source.parent.mkdir(parents=True)
source.write_text('old compatibility code')
runtime.record(self.root)
source.write_text('new compatibility code')
with self.assertRaisesRegex(ValueError, 'sources changed'):
runtime.verify(self.root)
def test_missing_quest_driver_cannot_be_attested(self):
(self.root / 'app/build/prepared-assets/graphics_driver/adrenotools-turnip25.1.0-quest1.tzst').unlink()
with self.assertRaisesRegex(ValueError, 'quest1.tzst'):
runtime.record(self.root)
def test_modified_prebuilt_binary_is_rejected(self):
runtime.record(self.root)
(self.root / 'app/src/main/jniLibs/arm64-v8a/libproot.so').write_bytes(b'old APK binary')
+67
View File
@@ -0,0 +1,67 @@
"""Exercise the literal launch prefix from SessionService without an Android runtime.
This is a focused source/exec regression check, not a Kotlin or PRoot integration
test. PRoot executes the first guest argument directly; KEY=VALUE is meaningful
only after /usr/bin/env. Read the production prefix rather than duplicate it.
"""
import json
from pathlib import Path
import re
import subprocess
import unittest
SERVICE = Path(__file__).resolve().parents[2] / (
"app/src/main/java/com/droiddeck/launcher/session/SessionService.kt")
VARIANTS = Path(__file__).resolve().parents[1] / "release/variants.txt"
PACKAGES = [line.split()[1] for line in VARIANTS.read_text().splitlines()
if line.strip() and not line.startswith("#")]
def guest_prefix(package):
source = SERVICE.read_text()
before_environment = source.split("val guest = ArrayList<String>()", 1)[1].split(
"addClientEnvironment(guest, steamHere)", 1)[0]
environment = source.split("private fun addClientEnvironment(", 1)[1].split(
'guest.add("HOME=/root")', 1)[0]
prefix = []
for line in (before_environment + environment).splitlines():
line = line.strip()
if not line.startswith("guest.add("):
continue
expression = line[len("guest.add("):-1]
match = re.fullmatch(r'("[^"\\]*")(?: \+ (.+))?', expression)
if match is None:
raise AssertionError("Launch prefix changed; update its regression harness: " + line)
value = json.loads(match[1])
if match[2]:
if match[2] != "com.droiddeck.launcher.runtime.BwrapSpawner.socket(this)":
raise AssertionError("Unexpected dynamic launch-prefix argument: " + line)
value += package + ".bwrap"
prefix.append(value)
return prefix
class SessionGuestCommandTest(unittest.TestCase):
def test_env_is_the_executable_for_every_package(self):
for package in PACKAGES:
with self.subTest(package=package):
self.assertEqual(["/usr/bin/env", "-i"], guest_prefix(package)[:2])
@unittest.skipUnless(Path("/usr/bin/env").is_file(), "needs /usr/bin/env")
def test_child_receives_its_package_socket_after_environment_is_cleared(self):
for package in PACKAGES:
with self.subTest(package=package):
# env with no command prints the environment it would pass to the
# session. A misplaced assignment fails at exec, before it runs.
result = subprocess.run(
guest_prefix(package), capture_output=True, text=True, check=True,
timeout=5, env={"DROIDDECK_BWRAP_SOCKET": "wrong.bwrap", "STALE_HOST": "1"})
self.assertEqual(
["DROIDDECK_BWRAP_SOCKET=" + package + ".bwrap"],
result.stdout.splitlines())
if __name__ == "__main__":
unittest.main()