"""Validate optional themes and PCM boost on the authorized onn; restore the prior audio preferences.""" import re,time,sys,xml.etree.ElementTree as ET from device import adb,OUT,screenshot from verify_ui import launch,key,text,focused,focus,snapshot,labels,wait,passed def settings(category): launch();key(22,4);focused('Settings');key(23);focused('Switch account') key(21);focused('Connection');key(20,category);key(22) def choose(options,value): key(23) current=focus(snapshot()) assert current in options,(current,options) delta=options.index(value)-options.index(current) key(20 if delta>=0 else 19,abs(delta));focused(value);key(23) def logs():return adb('logcat','-d','-s','KaleidoTheme:I','KaleidoPlayback:I','*:S').decode(errors='replace') def wait_log(fragment,timeout=40): deadline=time.monotonic()+timeout while time.monotonic() shared_prefs/preferences.xml"',data=ET.tostring(tree,encoding='utf-8',xml_declaration=True)) else: settings(3);focused('Navigation sounds');key(20);focused('Theme music') original_on=focus(snapshot()).endswith('On') if not original_on:key(23) key(20);focused('Theme music volume') original_volume=re.search(r'(\d+)%$',focus(snapshot())).group(1)+'%' choose([str(n)+'%' for n in range(10,101,10)],'20%');focused('Theme music volume') settings(1);focused('Playback quality');key(20,6);focused('Volume boost') current=focus(snapshot());original_boost='Off (+0 dB)' if current.endswith('Off (+0 dB)') else re.search(r'\+\d+ dB$',current).group() choose(['Off (+0 dB)','+3 dB','+6 dB','+9 dB','+12 dB'],'+6 dB');focused('Volume boost') screenshot('030-volume-boost') settings(3);key(20);focused('Theme music');assert focus(snapshot()).endswith('On') key(20);focused('Theme music volume');assert focus(snapshot()).endswith('20%') screenshot('030-theme-settings') passed('Theme toggle, theme volume and boost persist through cold starts; dialogs restore focus') try: adb('logcat','-c');open_silo();wait_log('KaleidoTheme: READY volume=20%') screenshot('030-silo-theme') adb('logcat','-c');key(3);wait_log('STOP') # Launchers may reopen Home rather than restore the previous Activity task. # Enter the title through the normal remote flow before expecting music again. open_silo();wait_log('PLAYING') passed('Theme stops in the background and plays again on a title page') # Show -> season -> neighbouring episode selection all retain a supported theme. key(20) wait(lambda r:'Season' in focus(r),'Season receives focus');key(23) wait(lambda r:any(t=='Episodes' or t.startswith(('Play','Resume')) for t in labels(r)),'Season episode header') wait_log('KaleidoTheme: READY volume=20%') passed('Series and season/episode detail pages play the real inherited Plex theme') # Actual video uses validation mode, which avoids changing Plex progress. adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','7599','--el','testOffset','90000','--ei','testMode','0','--ez','testValidation','true') wait_log('STOP');wait_log('BOOST processing PCM db=6');wait_log('READY item=7599') time.sleep(4) audit=adb('shell','run-as','tv.kaleido.app','cat','files/playback-validation.jsonl') (OUT/'030-boost-validation.jsonl').write_bytes(audit) import json events=[json.loads(line) for line in audit.decode().splitlines()] assert any(e.get('event')=='audioAdvancing' for e in events),'Decoded audio must advance' assert any(e.get('event')=='firstFrame' for e in events),'Video must render' passed('Theme stops for actual video; +6 dB processor receives decoded PCM and audio/video advance') adb('shell','am','force-stop','tv.kaleido.app');adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','9776','--el','testOffset','90000','--ei','testMode','2','--ez','testValidation','true') wait_log('BOOST processing PCM db=6');wait_log('READY item=9776');time.sleep(4) movie_audit=adb('shell','run-as','tv.kaleido.app','cat','files/playback-validation.jsonl') (OUT/'030-boost-movie-validation.jsonl').write_bytes(movie_audit) movie_events=[json.loads(line) for line in movie_audit.decode().splitlines()] assert any(e.get('event')=='audioAdvancing' for e in movie_events) assert any(e.get('event')=='firstFrame' for e in movie_events) passed('Volume boost also processes a real Plex-converted movie with rendered audio/video') adb('shell','am','force-stop','tv.kaleido.app') finally: if playback_only: adb('shell','am','force-stop','tv.kaleido.app') adb('shell','run-as','tv.kaleido.app','sh','-c','"cat > shared_prefs/preferences.xml"',data=original_xml) assert adb('shell','run-as','tv.kaleido.app','cat','shared_prefs/preferences.xml')==original_xml else: settings(1);key(20,6);focused('Volume boost') choose(['Off (+0 dB)','+3 dB','+6 dB','+9 dB','+12 dB'],original_boost) settings(3);key(20);focused('Theme music') if focus(snapshot()).endswith('On')!=original_on:key(23) key(20);focused('Theme music volume');choose([str(n)+'%' for n in range(10,101,10)],original_volume) launch() (OUT/'030-audio.log').write_text(logs()) passed('Prior theme and boost preferences restored; device returned to Home')