from pathlib import Path import os, subprocess, time E=dict(os.environ,ADB_SERVER_SOCKET='tcp:127.0.0.1:15037',ANDROID_SERIAL='33291JEGR14896') D=Path('/tmp/fullscreen-rotation-real-407420295');D.mkdir(exist_ok=True) def adb(*a,binary=False): return subprocess.run(['adb',*a],env=E,check=True,capture_output=True,text=not binary).stdout def sh(*a): return adb('shell',*a).strip() def launch(label,force_stop='org.chromium.chrome'): subprocess.run(['python3','/home/chrome/my-host/static-files/i-407420295/automation/scripts/launch_shortcut.py',label,'--force-stop',force_stop],env=E,check=True) def shot(name): time.sleep(6) f=D/name f.with_suffix('.png').write_bytes(adb('exec-out','screencap','-p',binary=True)) windows=sh('dumpsys','window','windows') activity=sh('dumpsys','activity','activities') top=next((l for l in activity.splitlines() if 'topResumedActivity=' in l),'') # capture only window block for CURRENT Chromium WebappActivity, not stock Chrome or SystemUI blocks=windows.split(' Window #') match=next((b for b in blocks if 'org.chromium.chrome/org.chromium.chrome.browser.webapps.WebappActivity}:' in b[:180]),'NOT FOUND') f.with_suffix('.txt').write_text('cmdline='+sh('cat','/data/local/tmp/chrome-command-line')+'\n'+top+'\n'+match[:3100]) print(name, top.strip(),flush=True) orig={'cmd':sh('cat','/data/local/tmp/chrome-command-line'),'debug':sh('settings','get','global','debug_app'),'rotate':sh('cmd','window','user-rotation'),'fixed':sh('cmd','window','fixed-to-user-rotation'),'accelerometer':sh('settings','get','system','accelerometer_rotation')} (D/'original.txt').write_text(repr(orig)) try: sh('settings','put','global','debug_app','org.chromium.chrome') sh("printf '_ --disable-fre --no-first-run --disable-features=WebAppShortEdgesCutoutMode\n' > /data/local/tmp/chrome-command-line") sh('cmd','window','fixed-to-user-rotation','enabled') sh('cmd','window','user-rotation','lock','0') # Cache new feature configuration before cold startup. for _ in range(2): sh('am','force-stop','org.chromium.chrome');sh('am','start','-n','org.chromium.chrome/com.google.android.apps.chrome.Main');time.sleep(7) (D/'cached-flags.txt').write_text('\n'.join(l for l in sh('run-as','org.chromium.chrome','cat','shared_prefs/org.chromium.chrome_preferences.xml').splitlines() if 'WebAppShortEdgesCutoutMode' in l)) launch('FS Rotation') shot('01-auto-cold-portrait') sh('cmd','window','user-rotation','lock','1');shot('02-auto-landscape') sh('cmd','window','user-rotation','lock','0');shot('03-auto-return-portrait') # Do not stop Chromium: switch installed PWAs in the same process following rotation. launch('E2E Fullscreen',force_stop='') shot('04-portrait-locked-demo-after-rotation') launch('FS Rotation',force_stop='') shot('05-auto-reopen-portrait') finally: sh(f"printf '%s\n' '{orig['cmd']}' > /data/local/tmp/chrome-command-line") sh('am','force-stop','org.chromium.chrome') if orig['rotate'].startswith('free'):sh('cmd','window','user-rotation','free') else: sh('cmd','window','user-rotation',*orig['rotate'].split()) sh('cmd','window','fixed-to-user-rotation',orig['fixed']) sh('settings','put','system','accelerometer_rotation',orig['accelerometer']) if orig['debug']=='null': sh('settings','delete','global','debug_app') else:sh('settings','put','global','debug_app',orig['debug'])