"""Remote-only UI regression checks on the authorized onn; captures remain private."""
import argparse,json,pathlib,re,sys,time,xml.etree.ElementTree as ET
sys.path.insert(0,str(pathlib.Path(__file__).resolve().parent))
from device import adb,OUT,screenshot
results=[]
def key(code,count=1):
for _ in range(count):
adb('shell','input','keyevent',str(code));time.sleep(.22)
def snapshot():
adb('shell','uiautomator','dump','/data/local/tmp/kaleido-window.xml')
return ET.fromstring(adb('shell','cat','/data/local/tmp/kaleido-window.xml'))
def labels(root):return [n.get('text','') for n in root.iter('node') if n.get('text')]
def focus(root):
n=next((n for n in root.iter('node') if n.get('focused')=='true'),None)
if n is None:return ''
return n.get('content-desc','') or ' '.join(labels(n))
def wait(check,description,timeout=25):
deadline=time.monotonic()+timeout;root=ET.fromstring('')
while time.monotonic()=9000,'A tap must skip forward 10 seconds'
adb('shell','input','keyevent','--longpress','22');focused('Playback timeline')
passed('Left/Right taps skip silently; holding reveals the timeline')
key(4);wait(lambda r:'2 Fast 2 Furious' not in labels(r),'Back hides controls')
key(4);text('Continue Watching');passed('Back exits playback to live home')
if __name__=='__main__':
parser=argparse.ArgumentParser();parser.add_argument('phase',choices=['browse','player']);args=parser.parse_args()
try:
globals()[args.phase]()
finally:
(OUT/('ui-'+args.phase+'-results.json')).write_text(json.dumps(results,indent=2))
print(f'Completed {len(results)} UI checks',flush=True)