first commit

This commit is contained in:
Elijah Kuntz 2026-10-17 22:38:45 -07:00
commit f5f1c0928f
39 changed files with 4478 additions and 0 deletions

325
scripts/device_smoke.py Normal file
View file

@ -0,0 +1,325 @@
#!/usr/bin/env python3
"""On-device integration checks. Operates only Luma UI and launches installed apps.
Run with the TV awake. Keeps Projectivy installed as a fallback.
"""
import argparse
import re
import subprocess
import time
import struct
import statistics
import xml.etree.ElementTree as ET
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
ADB = str(ROOT / '.tools/platform-tools/adb')
parser = argparse.ArgumentParser()
parser.add_argument('--device', default='192.168.50.195:35635')
parser.add_argument('--part', choices=['navigation', 'home-routing', 'customization', 'performance', 'plex', 'appearance-modes', 'final-defaults', 'screensaver', 'screensaver-video', 'screensaver-timeout'], default='navigation')
args = parser.parse_args()
def adb(*cmd):
r = subprocess.run([ADB, '-s', args.device, *map(str,cmd)], capture_output=True, check=True)
return r.stdout.decode(errors='replace')
def key(*keys):
adb('shell','input','keyevent',*keys)
time.sleep(.35)
def tree():
adb('shell','uiautomator','dump','/sdcard/luma-test.xml')
return ET.fromstring(adb('shell','cat','/sdcard/luma-test.xml'))
def tap_text(text):
for attempt in range(9):
root = tree()
for n in root.iter('node'):
if n.get('text','').split('\n')[0] == text:
x1,y1,x2,y2=map(int,re.findall(r'\d+',n.get('bounds')))
if y2-y1<35: continue
adb('shell','input','tap',(x1+x2)//2,(y1+y2)//2)
time.sleep(.45)
return
adb('shell','input','swipe',1200,850,1200,380,250)
time.sleep(.2)
raise AssertionError('Missing control: '+text)
def text_exists(text):
assert any(text in n.get('text','') for n in tree().iter('node')),text
def focus():
for n in tree().iter('node'):
if n.get('focused')=='true':
return n.get('content-desc') or n.get('text')
def start():
adb('shell','am','start','-W','-a','android.intent.action.MAIN','-c','android.intent.category.HOME','-n','tv.luma.launcher/.MainActivity')
time.sleep(1)
def package():
out=adb('shell','dumpsys','activity','activities')
m=re.search(r'topResumedActivity=.*? u0 ([^/]+)/',out)
return m.group(1) if m else None
def ok(label): print('PASS: '+label,flush=True)
if args.part=='navigation':
start()
assert package()=='tv.luma.launcher'
ok('Luma launches directly')
key(82);text_exists('Make it yours');key(4)
ok('Menu opens settings; Back closes it')
# Return to the first icon using Back and directional navigation.
key(4);time.sleep(.4)
start();key(19)
assert 'settings' in focus().lower()
key(20)
assert focus()=='Plex',focus()
key(22);assert focus()=='Plezy',focus()
key(22);assert focus()=='SmartTube beta',focus()
key(20);assert focus()=='Prime Video',focus()
key(19);assert focus()=='SmartTube beta',focus()
ok('D-pad moves horizontally and between app rows')
key(23);time.sleep(2)
assert package()=='org.smarttube.beta',package()
ok('OK launches the selected app')
key(3);time.sleep(2)
assert package()=='tv.luma.launcher',package()
ok('Home returns to Luma')
start();key(4,4,4);time.sleep(1)
assert package()=='tv.luma.launcher',package()
ok('Repeated Back at home stays on Luma')
key(20,20);key(4)
assert focus()=='Plex',focus()
assert package()=='tv.luma.launcher',package()
ok('Back from lower rows returns to the first row and stays on Luma')
start()
elif args.part=='home-routing':
start();key(82);tap_text('Default launcher')
text_exists('Home button override: On')
tap_text('Open Projectivy');time.sleep(2)
assert package()=='com.spocky.projengmenu',package()
time.sleep(3)
assert package()=='com.spocky.projengmenu',package()
ok('Explicit Projectivy fallback remains open without a redirect loop')
key(3);time.sleep(1)
assert package()=='tv.luma.launcher',package()
for _ in range(5):key(3)
assert package()=='tv.luma.launcher',package()
ok('Home returns from fallback and repeated Home presses stay in Luma')
adb('shell','am','start','-a','android.settings.SETTINGS');time.sleep(1)
assert package()!='tv.luma.launcher'
key(3);time.sleep(1)
assert package()=='tv.luma.launcher',package()
ok('Home returns to Luma from Android settings')
key(82);tap_text('Screensaver');tap_text('Preview now');time.sleep(1)
assert any(n.get('content-desc')=='Luma screensaver' for n in tree().iter('node'))
key(3);time.sleep(1)
assert not any(n.get('content-desc')=='Luma screensaver' for n in tree().iter('node'))
assert package()=='tv.luma.launcher',package()
ok('Home dismisses the screensaver and returns to the app grid')
assert 'LumaHomeService' in adb('shell','dumpsys','activity','services','tv.luma.launcher')
assert 'com.spocky.projengmenu' in adb('shell','pm','list','packages','-e','com.spocky.projengmenu')
ok('Home override is bound; Projectivy remains enabled')
elif args.part=='customization':
start();key(82);tap_text('Appearance')
tap_text('App spacing · 6 columns');tap_text('Spacious · 5 columns')
text_exists('App spacing · 5 columns');key(4)
# Settings Back closes the whole dialog, then reopen and restore default.
key(82);tap_text('Appearance');tap_text('App spacing · 5 columns');tap_text('Balanced · 6 columns')
tap_text('Wallpaper · Alpine');tap_text('Aurora · Soft teal & indigo')
text_exists('Wallpaper · Aurora')
key(4);key(3);time.sleep(1);start();key(82);tap_text('Appearance')
text_exists('Wallpaper · Aurora')
ok('Wallpaper preference persists across leaving and resuming')
tap_text('Wallpaper · Aurora');tap_text('Alpine · Cinematic mountain light')
tap_text('Focus animations · On');text_exists('Focus animations · Off');tap_text('Focus animations · Off')
tap_text('Clock · On');text_exists('Clock · Off');tap_text('Clock · Off');key(4)
ok('Spacing, wallpaper, reduced motion, and clock controls work')
# Long press on a focused tile exposes actual app actions.
key(19);key(20)
adb('shell','input','keyevent','--longpress',23);time.sleep(.5)
text_exists('Move to front');text_exists('Hide from home');key(4)
ok('Hold OK exposes app management')
elif args.part=='plex':
# Requires scripts/plex_fixture.py running on the host.
adb('reverse','tcp:8765','tcp:8765')
start();key(82);tap_text('Plex media rows');tap_text('Enter server manually')
inputs=[n for n in tree().iter('node') if n.get('class')=='android.widget.EditText']
assert len(inputs)==2
for node,value in zip(inputs,['http://127.0.0.1:8765','luma-test-fixture']):
x1,y1,x2,y2=map(int,re.findall(r'\d+',node.get('bounds')))
adb('shell','input','tap',(x1+x2)//2,(y1+y2)//2)
adb('shell','input','text',value)
key(4)
tap_text('Connect');time.sleep(2)
assert package()=='tv.luma.launcher'
# Move from app grid into optional rows.
key(19);key(20);key(20,20,20,20)
text_exists('Continue watching');text_exists('Alpine at dusk')
(ROOT/'output/luma-media-fixture.png').write_bytes(subprocess.run([ADB,'-s',args.device,'exec-out','screencap','-p'],capture_output=True,check=True).stdout)
ok('Plex connection, encrypted credential storage, Continue Watching, and artwork rendering')
# Open settings and ensure fixture credentials are removed before finishing.
key(82);tap_text('Plex media rows');tap_text('Disconnect Plex')
text_exists('Media rows · Off')
key(4);key(4)
adb('reverse','--remove','tcp:8765')
ok('Disconnect clears test connection and disables media rows')
elif args.part=='appearance-modes':
start();key(82);tap_text('Appearance')
nodes=list(tree().iter('node'))
label_control=next(n.get('text').split('\n')[0] for n in nodes if n.get('text','').startswith('App labels · '))
if label_control!='App labels · Focused only':
tap_text(label_control);tap_text('Focused only')
tap_text('Banner · Artwork only');tap_text('Dynamic')
text_exists('Banner · Dynamic');key(4)
assert any('Your library.' in n.get('text','') for n in tree().iter('node'))
key(82);tap_text('Appearance');tap_text('Banner · Dynamic');tap_text('Minimal')
text_exists('Banner · Minimal');key(4)
nodes=list(tree().iter('node'))
first=next(n for n in nodes if n.get('content-desc')=='Plex' and n.get('focusable')=='true')
assert int(re.findall(r'\d+',first.get('bounds'))[1]) < 250
key(82);tap_text('Appearance');tap_text('Banner · Minimal');tap_text('Artwork only')
tap_text('App labels · Focused only');tap_text('Always')
text_exists('App labels · Always');key(4)
assert any(n.get('text')=='Plezy' for n in tree().iter('node'))
key(82);tap_text('Appearance');tap_text('App labels · Always');tap_text('Never')
text_exists('App labels · Never');key(4)
assert not any(n.get('text')=='Plex' for n in tree().iter('node'))
key(82);tap_text('Appearance');tap_text('App labels · Never');tap_text('Focused only');key(4);key(19,19,20)
nodes=list(tree().iter('node'))
assert any(n.get('text')=='Plex' for n in nodes)
assert not any(n.get('text')=='Plezy' for n in nodes)
assert not any('Your library.' in n.get('text','') for n in nodes)
# Original spacious layout: first full row and a partial second row.
first=next(n for n in nodes if n.get('content-desc')=='Plex' and n.get('focusable')=='true')
assert int(re.findall(r'\d+',first.get('bounds'))[1]) >= 650
key(3);time.sleep(1);start();key(82);tap_text('Appearance')
text_exists('Banner · Artwork only');text_exists('App labels · Focused only');key(4)
ok('All banner and label modes work; original spacious layout and clean defaults persist')
elif args.part=='final-defaults':
start();key(82);tap_text('Appearance')
text_exists('Banner · Artwork only');text_exists('App labels · Focused only');key(4);key(19,19,20)
nodes=list(tree().iter('node'))
assert not any('Your library.' in n.get('text','') for n in nodes)
assert any(n.get('text')=='Plex' for n in nodes)
assert not any(n.get('text')=='Plezy' for n in nodes)
first=next(n for n in nodes if n.get('content-desc')=='Plex' and n.get('focusable')=='true')
assert first.get('focused')=='true'
assert int(re.findall(r'\d+',first.get('bounds'))[1]) >= 650
ok('Artwork only, Focused only labels, and original spacious layout are active')
elif args.part=='screensaver':
adb('shell','am','force-stop','tv.luma.launcher')
start();key(82);tap_text('Screensaver')
nodes=list(tree().iter('node'))
mode_control=next(n.get('text') for n in nodes if n.get('text','').startswith('Mode · '))
tap_text(mode_control);tap_text('Art gallery')
nodes=list(tree().iter('node'))
interval_control=next(n.get('text') for n in nodes if n.get('text','').startswith('Photo duration · '))
tap_text(interval_control);tap_text('15 sec')
tap_text('Preview now');time.sleep(2)
nodes=list(tree().iter('node'))
assert any(n.get('content-desc')=='Luma screensaver' for n in nodes)
titles=['Wheat Field with Cypresses','The Great Wave','The Death of Socrates']
seen=[]
for index in range(3):
nodes=list(tree().iter('node'))
seen.append(next(n.get('text') for n in nodes if n.get('text') in titles))
path=ROOT/f'output/luma-art-{index}.png'
path.write_bytes(subprocess.run([ADB,'-s',args.device,'exec-out','screencap','-p'],capture_output=True,check=True).stdout)
bmp=Path('/tmp/luma-frame-check.bmp')
subprocess.run(['sips','-z','64','112','-s','format','bmp',str(path),'--out',str(bmp)],stdout=subprocess.DEVNULL,check=True)
data=bmp.read_bytes();offset=struct.unpack_from('<I',data,10)[0]
width,height=struct.unpack_from('<ii',data,18);bits=struct.unpack_from('<H',data,28)[0]
assert bits==32
rowbytes=width*4
def rgb(x,y):
yy=y if height<0 else abs(height)-1-y
b,g,r,_=data[offset+yy*rowbytes+x*4:offset+yy*rowbytes+x*4+4]
return r,g,b
luminance=[sum(rgb(x,y))/3 for y in range(8,42) for x in range(22,90)]
assert statistics.pstdev(luminance)>8,('Blank artwork frame',seen[-1])
assert max(rgb(0,5))<=2,('Matte is not black',rgb(0,5))
if index<2:
for _ in range(10):
time.sleep(2)
next_nodes=list(tree().iter('node'))
next_title=next((n.get('text') for n in next_nodes if n.get('text') in titles),None)
if next_title and next_title!=seen[-1]:break
assert len(set(seen))==3,seen
ok('All three artwork images render, crossfade, and use pure-black mattes')
key(20)
assert not any(n.get('content-desc')=='Luma screensaver' for n in tree().iter('node'))
assert package()=='tv.luma.launcher'
key(82);tap_text('Screensaver');tap_text('Mode · Art gallery');tap_text('Scenic')
tap_text('Photo duration · 15 sec');tap_text('30 sec');tap_text('Preview now');time.sleep(2)
assert any(n.get('content-desc')=='Luma screensaver' for n in tree().iter('node'))
(ROOT/'output/luma-scenic-screensaver.png').write_bytes(subprocess.run([ADB,'-s',args.device,'exec-out','screencap','-p'],capture_output=True,check=True).stdout)
key(23)
ok('Scenic preview works; D-pad and OK wake without launching an app')
elif args.part=='screensaver-video':
start();key(82);tap_text('Screensaver');tap_text('Nature video');tap_text('Download bird nature loop')
for _ in range(24):
time.sleep(2)
nodes=list(tree().iter('node'))
if any(n.get('text')=='Screensaver' for n in nodes):break
error=next((n.get('text') for n in nodes if n.get('text','').startswith('Download stopped.')),None)
assert error is None,error
text_exists('Mode · Nature video');tap_text('Preview now');time.sleep(4)
nodes=list(tree().iter('node'))
assert any(n.get('content-desc')=='Luma screensaver' for n in nodes)
assert any(n.get('text')=='Nature loop' for n in nodes)
(ROOT/'output/luma-nature-screensaver.png').write_bytes(subprocess.run([ADB,'-s',args.device,'exec-out','screencap','-p'],capture_output=True,check=True).stdout)
ok('NPS nature video downloads locally and plays in the screensaver')
key(3);time.sleep(3)
assert package()=='tv.luma.launcher'
start();key(82);tap_text('Screensaver');tap_text('Mode · Nature video');tap_text('Scenic');key(4);key(19,19,20)
ok('Home exits video to Luma; scenic mode restored and local video retained for use')
elif args.part=='screensaver-timeout':
start();key(82);tap_text('Screensaver');tap_text('Idle timeout · 10 min');tap_text('1 min');key(4)
print('Waiting for the 1 minute idle timeout…',flush=True)
time.sleep(63)
assert any(n.get('content-desc')=='Luma screensaver' for n in tree().iter('node'))
key(20);key(82);tap_text('Screensaver');tap_text('Idle timeout · 1 min');tap_text('10 min');key(4);key(19,19,20)
ok('Real 1 minute idle activation works; 10 minute default restored')
elif args.part=='performance':
start();key(20,20,20,20)
assert focus()=='All apps',focus()
key(19,19,19,19)
assert focus()=='Plex',focus()
ok('Focus scrolls through all rows to the footer and back')
adb('shell','dumpsys','gfxinfo','tv.luma.launcher','reset')
for _ in range(4):key(22,22,20,21,21,19)
(ROOT/'output/luma-focus-frames.txt').write_text(adb('shell','dumpsys','gfxinfo','tv.luma.launcher'))
time.sleep(2)
(ROOT/'output/luma-foreground-memory.txt').write_text(adb('shell','dumpsys','meminfo','tv.luma.launcher'))
adb('shell','am','start','-a','android.settings.SETTINGS');time.sleep(12)
pid=adb('shell','pidof','tv.luma.launcher').strip()
first=adb('shell','cat',f'/proc/{pid}/stat').split()
time.sleep(10)
second=adb('shell','cat',f'/proc/{pid}/stat').split()
ticks=sum(int(second[i])-int(first[i]) for i in [13,14])
assert ticks==0, f'Background CPU ticks: {ticks}'
ok('Zero background CPU ticks over a 10 second sample')
services=adb('shell','dumpsys','activity','services','tv.luma.launcher')
assert 'LumaHomeService' in services and 'LumaDreamService' not in services
router_pid=adb('shell','pidof','tv.luma.launcher:home').strip()
first=adb('shell','cat',f'/proc/{router_pid}/stat').split()
time.sleep(10)
second=adb('shell','cat',f'/proc/{router_pid}/stat').split()
router_ticks=sum(int(second[i])-int(first[i]) for i in [13,14])
assert router_ticks==0, f'Idle Home router CPU ticks: {router_ticks}'
(ROOT/'output/luma-home-router-memory.txt').write_text(adb('shell','dumpsys','meminfo',router_pid))
(ROOT/'output/luma-background-memory.txt').write_text(adb('shell','dumpsys','meminfo','tv.luma.launcher'))
(ROOT/'output/luma-background-cpu.txt').write_text(f'Launcher background CPU ticks in 10 seconds: {ticks}\nHome router idle CPU ticks in 10 seconds: {router_ticks}\n'+services)
ok('Only the separate Home router service is bound; zero idle CPU ticks over 10 seconds')
start()