import argparse import json import os import subprocess import time from pathlib import Path from adb_device import resolve_serial def validate_samples(samples, require_controllers=False, guest=False, steamvr=False, surface=False): if len(samples) < 2: return 'No advancing telemetry; check runtime initialization and headset wake/proximity' if samples[-1]['rendered'] - samples[0]['rendered'] < 72: return 'Fewer than 72 additional stereo frames were submitted' if not any(sample['sessionState'] == 5 and sample['headFlags'] & 15 == 15 for sample in samples): return 'No focused session with tracked 6DoF position and orientation' if require_controllers and not any(all(sample['controllersActive']) for sample in samples): return 'Both controllers did not become active' if steamvr and samples[-1].get('uploadedFrames', 0) - samples[0].get('uploadedFrames', 0) < 72: return 'No advancing owned SteamVR images; XR submissions alone are insufficient' if steamvr and samples[-1].get('sourceFrameId', 0) <= samples[0].get('sourceFrameId', 0): return 'SteamVR source frame IDs did not advance' if guest and not steamvr and samples[-1].get('guestFrames', 0) - samples[0].get('guestFrames', 0) < 72: return 'No advancing guest GPU presentation; submitting an XR layer alone is insufficient' if steamvr and samples[-1].get('steamvrState') != 4: return 'SteamVR did not report RUNNING' expected = 'frames' if steamvr else 'guest' if guest else 'surface' if surface else 'native' if samples[-1].get('source') != expected: return 'Wrong projection source' return None def main(): parser = argparse.ArgumentParser(description='Validate immersive DroidDeck XR on a connected Quest') parser.add_argument('--adb', default=os.environ.get('ADB', 'adb')) parser.add_argument('--serial') parser.add_argument('--seconds', type=int, default=20) parser.add_argument('--output', type=Path, default=Path('questxr-validation')) parser.add_argument('--require-controllers', action='store_true') parser.add_argument('--surface', action='store_true') parser.add_argument('--guest', action='store_true') parser.add_argument('--keep-awake', action='store_true') parser.add_argument('--steamvr', action='store_true') args = parser.parse_args() if args.seconds < 5 or args.seconds > 600: parser.error('--seconds must be between 5 and 600') if args.steamvr and not args.guest: parser.error('--steamvr requires --guest') if args.steamvr and args.surface: parser.error('--steamvr uses owned frames and cannot use --surface') serial = resolve_serial(args.adb, args.serial) args.output.mkdir(parents=True, exist_ok=True) def adb(*command): return subprocess.run([args.adb, '-s', serial, *command], check=True, capture_output=True, text=True, timeout=15).stdout package = 'com.droiddeck.launcher' if args.guest else 'com.droiddeck.questxr' health_path = f'/sdcard/Android/data/{package}/files/xr-health.json' if not args.guest: adb('shell', 'am', 'force-stop', package) adb('shell', 'rm', '-f', health_path) adb('shell', 'input', 'keyevent', 'KEYCODE_WAKEUP') component = f'{package}/.QuestXrActivity' if args.guest else f'{package}/android.app.NativeActivity' launch = ['shell', 'am', 'start', '-n', component] if args.surface: launch += ['--ez', 'surface_test', 'true'] if args.guest: launch += ['--ez', 'guest_frames' if args.steamvr else 'guest_surface', 'true'] if args.steamvr: launch += ['--ez', 'start_steamvr', 'true'] samples = [] failure = None try: adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_close') adb(*launch) deadline = time.monotonic() + args.seconds while time.monotonic() < deadline: time.sleep(1) adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_close') try: sample = json.loads(adb('shell', 'cat', health_path)) samples.append(sample) if sample.get('error'): failure = sample['error'] break except (subprocess.CalledProcessError, json.JSONDecodeError): pass except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error: failure = f'ADB operation failed: {type(error).__name__}' finally: if not args.keep_awake: try: adb('shell', 'am', 'broadcast', '-a', 'com.oculus.vrpowermanager.prox_far') except (subprocess.CalledProcessError, subprocess.TimeoutExpired): failure = failure or 'Could not restore headset proximity after testing' try: log = adb('logcat', '-d', '-s', 'DroidDeckXR:I', 'OpenXR-Loader:W', 'AndroidRuntime:E') except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as error: log = str(error) (args.output / 'logcat.txt').write_text(log, encoding='utf-8') failure = failure or validate_samples(samples, args.require_controllers, args.guest, args.steamvr, args.surface) report = {'ok': failure is None, 'error': failure, 'samples': samples} (args.output / 'report.json').write_text(json.dumps(report, indent=2), encoding='utf-8') print(json.dumps({'ok': report['ok'], 'error': failure, 'samples': len(samples), 'last': samples[-1] if samples else None}, indent=2)) return 0 if report['ok'] else 1 if __name__ == '__main__': raise SystemExit(main())