Autoplay page narration after a three-second delay

This commit is contained in:
Hadrian Burkhardt
2026-11-02 05:35:14 +01:00
parent a3ead03b6b
commit 4887eca6d4
10 changed files with 327 additions and 73 deletions
+10 -6
View File
@@ -10,11 +10,13 @@ def dump():
adb('shell','uiautomator','dump','/sdcard/lumen-flutter-smoke.xml')
return ET.fromstring(adb('exec-out','cat','/sdcard/lumen-flutter-smoke.xml'))
def value(n):return n.get('text','')+' '+n.get('content-desc','')
def find(text):
def find_any(*texts):
root=dump()
for n in root.iter('node'):
if text.casefold() in value(n).casefold():return n
raise AssertionError('Missing '+text+'; screen: '+str([value(n) for n in root.iter('node') if value(n).strip()]))
for text in texts:
for n in root.iter('node'):
if text.casefold() in value(n).casefold():return n
raise AssertionError('Missing '+str(texts)+'; screen: '+str([value(n) for n in root.iter('node') if value(n).strip()]))
def find(text):return find_any(text)
def tapnode(n):
x1,y1,x2,y2=map(int,re.findall(r'\d+',n.get('bounds')));adb('shell','input','tap',str((x1+x2)//2),str((y1+y2)//2))
def tap(text):tapnode(find(text))
@@ -38,7 +40,9 @@ def swipe_text(text,dx):
swipe_text('For you, when you are ready',-360);find('By the cottage window')
swipe_text('By the cottage window',360);find('For you, when you are ready')
tap('Next leaf');find('By the cottage window')
play=find('Play this reading');tapnode(play);time.sleep(2)
play=find_any('Pause recording','Play this reading')
if 'Pause recording' not in value(play):tapnode(play)
time.sleep(2)
# A clock can advance even when the decoder creates no audio track. Inspect
# the real mixer while playback is active (verified on the API 26 tablet).
pid=adb('shell','pidof',a.package).decode().strip().split()[0]
@@ -52,7 +56,7 @@ def seconds():
first=seconds();assert first>=1
tapnode(play);time.sleep(2);tapnode(play);find('Resume recording');assert seconds()>=first+1
tap('Stop');find('Play this reading')
adb('shell','am','force-stop',a.package);launch();find('By the cottage window');find('Play this reading');shot('main-restored-page.png')
adb('shell','am','force-stop',a.package);launch();find('By the cottage window');find_any('Play this reading','Pause recording');shot('main-restored-page.png')
tap('Close book')
if a.expect_fresh:find('0 / 12');find('0\nPATTERNS FOUND')
print('PASS: optimized app launches, swipes over the writing in both directions, plays through its UI, resumes audio and restores the reading place after process restart.')