Kaleido/scripts/device.py
Elijah 629546a50c
All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m16s
Smooth section switches and first row moves on weaker TVs
Measured every browse transition on the onn, a Fire TV Stick 4K and a TCL
TV with a new framestats harness and atrace breakdowns.

- Stage card artwork and titles a few cards per frame while a section
  enters, so its first frame no longer composes every card at once.
- Give every discovery list the lookahead cache window and nudge it once
  after a section settles, so the first move down composes nothing.
- Activate a focused top tab two frames later, so its highlight responds
  before the section switches; start the page entrance after composition
  settles, using per-draw alpha instead of an offscreen layer.
- Limit Coil to two concurrent decodes, drop the redundant window
  background, size card image requests explicitly, and skip a coroutine
  per card for focus restoration.

Home -> Movies UI stalls drop from 150-200 ms to 70-90 ms and Movies row
moves no longer skip frames. Device scripts can now target any authorized
serial and tolerate the TCL's flaky network ADB link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 13:11:45 -07:00

46 lines
3.2 KiB
Python

"""Operate only Kaleido on an authorized streamer. Credentials stay on stdin."""
import argparse, json, os, pathlib, subprocess, sys, time, xml.etree.ElementTree as ET
ROOT=pathlib.Path(__file__).resolve().parents[1]
ADB=pathlib.Path(r'C:\Users\Elijah\Desktop\platform-tools\adb.exe')
# The onn is the default; KALEIDO_DEVICE selects the authorized Fire TV Stick (192.168.50.146:5555).
DEVICE=os.environ.get('KALEIDO_DEVICE','192.168.50.195:5555')
OUT=ROOT/'evidence/private'
OUT.mkdir(parents=True,exist_ok=True)
def adb(*args, data=None):
for attempt in range(4):
p=subprocess.run([str(ADB),'-s',DEVICE,*args],input=data,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
error=p.stderr.decode(errors='replace')
# The TCL's network ADB link drops intermittently; reconnecting restores it.
if p.returncode and attempt<3 and ('closed' in error or 'offline' in error):
subprocess.run([str(ADB),'disconnect',DEVICE],capture_output=True);time.sleep(2)
subprocess.run([str(ADB),'connect',DEVICE],capture_output=True);time.sleep(2);continue
# It also occasionally fails a shell command silently. Retry, except key input,
# which may already have been delivered.
if p.returncode and attempt<3 and not error.strip() and args[:2]!=('shell','input'):time.sleep(1);continue
if p.returncode: raise RuntimeError(error)
return p.stdout
def screenshot(name):
path=OUT/(name+'.png');path.write_bytes(adb('exec-out','screencap','-p'));print(path)
def hierarchy():
adb('shell','uiautomator','dump','/data/local/tmp/kaleido-window.xml')
raw=adb('shell','cat','/data/local/tmp/kaleido-window.xml');(OUT/'window.xml').write_bytes(raw)
root=ET.fromstring(raw)
for n in root.iter('node'):
if n.get('text') or n.get('focused')=='true':print({k:n.get(k) for k in ['text','content-desc','focused','bounds']})
def seed():
env=dict(l.strip().split('=',1) for l in (ROOT/'.env').read_text().splitlines() if '=' in l and not l.startswith('#'))
data=json.dumps({'server':env['PLEX_SERVER_URL'].strip('\"\''),'token':env['PLEX_TOKEN'].strip('\"\'')}).encode()
adb('shell','am','force-stop','tv.kaleido.app')
adb('shell','run-as','tv.kaleido.app','mkdir','-p','files')
adb('shell','run-as','tv.kaleido.app','sh','-c','"cat > files/bootstrap.json"',data=data)
adb('shell','am','start','-n','tv.kaleido.app/.MainActivity')
print('Private test session provisioned. No credentials are embedded in the APK.')
if __name__=='__main__':
p=argparse.ArgumentParser();p.add_argument('action',choices=['seed','screenshot','hierarchy','key','launch','logs']);p.add_argument('value',nargs='?',default='screen');a=p.parse_args()
if a.action=='seed':seed()
if a.action=='screenshot':screenshot(a.value)
if a.action=='hierarchy':hierarchy()
if a.action=='key':adb('shell','input','keyevent',a.value)
if a.action=='launch':print(adb('shell','am','start','-n','tv.kaleido.app/.MainActivity').decode())
if a.action=='logs':
text=adb('logcat','-d','-t','2000','KaleidoPlayback:I','AndroidRuntime:E','ExoPlayerImpl:I','*:S').decode(errors='replace');(OUT/'device.log').write_text(text);print(text[-16000:])