#!/usr/bin/env python3 """Capture both installed PWAs with feature off, standalone param off/on.""" import os import subprocess import sys import time from pathlib import Path ROOT = Path(__file__).resolve().parent LAUNCHER = ROOT.parent / 'automation/scripts/launch_shortcut.py' os.environ.setdefault('ADB_SERVER_SOCKET', 'tcp:127.0.0.1:15037') def adb(*args, binary=False): return subprocess.run(['adb', *args], check=True, capture_output=True, text=not binary).stdout def shell(*args): return adb('shell', *args).strip() original_cmd = shell('cat', '/data/local/tmp/chrome-command-line') original_rotation = shell('cmd', 'window', 'user-rotation') original_fixed = shell('cmd', 'window', 'fixed-to-user-rotation') original_debug_app = shell('settings', 'get', 'global', 'debug_app') base = '_ --disable-fre --no-first-run ' states = { 'off': base + '--disable-features=WebAppShortEdgesCutoutMode', 'on-standalone-off': base + '--enable-features=WebAppShortEdgesCutoutMode', 'on-standalone-on': base + '--enable-features=WebAppShortEdgesCutoutMode:enable_standalone/true', } try: shell('settings', 'put', 'global', 'debug_app', 'org.chromium.chrome') shell('cmd', 'window', 'fixed-to-user-rotation', 'enabled') for state, cmdline in states.items(): shell(f"printf '%s\\n' '{cmdline}' > /data/local/tmp/chrome-command-line") shell('am', 'force-stop', 'org.chromium.chrome') # Cached feature params are persisted after native startup. Warm the new command # line once before measuring cold WebappActivity creation on the next launch. shell('cmd', 'window', 'user-rotation', 'lock', '0') shell('input', 'keyevent', 'HOME') time.sleep(3) subprocess.run([sys.executable, str(LAUNCHER), 'Mode Standalone'], check=True) time.sleep(7) shell('am', 'force-stop', 'org.chromium.chrome') for mode in ('standalone', 'fullscreen'): shell('cmd', 'window', 'user-rotation', 'lock', '0') shell('input', 'keyevent', 'WAKEUP') shell('input', 'keyevent', 'HOME') time.sleep(3) subprocess.run([sys.executable, str(LAUNCHER), f'Mode {mode.title()}'], check=True) time.sleep(5) active = shell('dumpsys', 'activity', 'activities') if '.browser.webapps.WebappActivity' not in next((x for x in active.splitlines() if 'topResumedActivity=' in x), ''): raise RuntimeError('Expected WebappActivity for ' + mode) for orientation, rotation in (('portrait', '0'), ('landscape', '1')): shell('cmd', 'window', 'user-rotation', 'lock', rotation) time.sleep(4) (ROOT / f'{state}-{mode}-{orientation}.png').write_bytes(adb('exec-out', 'screencap', '-p', binary=True)) print(state, mode, orientation, flush=True) finally: shell(f"printf '%s\\n' '{original_cmd}' > /data/local/tmp/chrome-command-line") shell('am', 'force-stop', 'org.chromium.chrome') if original_rotation.startswith('free'): shell('cmd', 'window', 'user-rotation', 'free') else: shell('cmd', 'window', 'user-rotation', *original_rotation.split()) shell('cmd', 'window', 'fixed-to-user-rotation', original_fixed) if original_debug_app == 'null': shell('settings', 'delete', 'global', 'debug_app') else: shell('settings', 'put', 'global', 'debug_app', original_debug_app)