"""Exercise the actual release UI, measure startup/rebuffering, restore resume time.""" import argparse,json,os,pathlib,re,shlex,time,urllib.parse,urllib.request if pathlib.Path('/etc/ssl/cert.pem').exists():os.environ.setdefault('SSL_CERT_FILE','/etc/ssl/cert.pem') from device import adb,OUT,DEVICE from verify_ui import launch,key,focused,wait,labels,focus,snapshot from inspect_server import get,base,token def session(): raw=adb('shell','dumpsys','media_session').decode(errors='replace') m=re.search(r'package=tv\.kaleido\.app.*?PlaybackState \{state=(\w+)\(\d+\), position=(\d+).*?speed=([\d.]+), updated=(\d+)',raw,re.S) return {'state':m[1],'position':int(m[2]),'speed':float(m[3]),'updated':int(m[4])} if m else {} def main(): p=argparse.ArgumentParser();p.add_argument('label');p.add_argument('id');p.add_argument('--seconds',type=int,default=60);args=p.parse_args() folder=OUT/'release-comparison';folder.mkdir(exist_ok=True) pkg=adb('shell','dumpsys','package','tv.kaleido.app').decode() assert 'DEBUGGABLE' not in re.search(r'pkgFlags=\[(.*?)\]',pkg)[1] assert 'status=speed-profile' in pkg before=get('/library/metadata/'+args.id)['Metadata'][0];title=before['title'] (folder/(args.label+'-before.json')).write_text(json.dumps(before,indent=2)) # A previous ADB tap can leave Android in touch mode across app restarts. adb('shell','input','keyevent','19') launch() for target in ['Movies','TV Shows','Search']:key(22);focused(target) key(23);wait(lambda r:'Movies, shows, episodes' in labels(r),'Search field') adb('shell','input','text',shlex.quote(title.replace(' ','%s'))) wait(lambda r:title in labels(r),'Matching search result') ime=adb('shell','dumpsys','input_method').decode(errors='replace') if re.search(r'mInputShown=true|isInputViewShown=true',ime):key(4) # EditText has the same text as the result; Tab exits editing without entering # Android touch mode, and the focused poster is verified before activation. key(61) wait(lambda r:any(n.get('focused')=='true' and n.get('class')!='android.widget.EditText' and title in labels(n) for n in r.iter('node')),'Movie result focus') key(23) root=wait(lambda r:any(s=='Play' or s.startswith('Resume') for s in labels(r)),'Movie actions') wait(lambda r:focus(r)=='Play' or focus(r).startswith('Resume'),'Playback action focus') if 'Start over' in labels(root):key(22);focused('Start over') print('PLAYBACK_START',args.label,flush=True) adb('logcat','-c');start=time.monotonic();key(23) ready=None;samples=[];ready_logs='' while time.monotonic()-start<70: s=session();s['elapsed']=round(time.monotonic()-start,3);samples.append(s) ready_logs=adb('logcat','-d','-s','KaleidoPlayback:I','AndroidRuntime:E','*:S').decode(errors='replace') if s.get('state')=='PLAYING' and 'READY item='+args.id in ready_logs:ready=s['elapsed'];break time.sleep(.7) assert ready is not None,'Release playback did not become ready' print('PLAYBACK_READY',args.label,ready,flush=True) steady_start=time.monotonic();last='PLAYING';rebuffers=0 while time.monotonic()-steady_start