"""Real network-settings and disposable-test-app uninstall checks. Run after instrumentation.""" import argparse import re import subprocess import time import xml.etree.ElementTree as ET p = argparse.ArgumentParser() p.add_argument('--adb', required=True) p.add_argument('--device', required=True) a = p.parse_args() def adb(*args): return subprocess.check_output([a.adb, '-s', a.device, *map(str, args)]).decode('utf-8') def key(k): adb('shell', 'input', 'keyevent', k) time.sleep(.4) def tree(): adb('shell', 'uiautomator', 'dump', '/sdcard/luma-actions.xml') return ET.fromstring(adb('shell', 'cat', '/sdcard/luma-actions.xml')) def tap(label, description=False): for _ in range(8): for n in tree().iter('node'): value = n.get('content-desc' if description else 'text', '') if (label in value if description else value.split('\n')[0] == label): x, y, right, bottom = map(int, re.findall(r'\d+', n.get('bounds'))) if bottom - y < 30: continue adb('shell', 'input', 'tap', (x + right) // 2, (y + bottom) // 2) time.sleep(.5) return adb('shell', 'input', 'swipe', 1200, 850, 1200, 400, 300) raise AssertionError('Missing control: ' + label) def package_present(): return 'package:tv.luma.launcher.tests' in adb( 'shell', 'pm', 'list', 'packages', '--user', user, 'tv.luma.launcher.tests').splitlines() def uninstall_menu(): key(82) tap('App library') tap('Luma test app') tap('Uninstall app') nodes = list(tree().iter('node')) assert any(n.get('package') == 'com.google.android.packageinstaller' or 'packageinstaller' in n.get('package', '') for n in nodes), 'No Android confirmation' assert any('Luma test app' in n.get('text', '') for n in nodes), 'Wrong uninstall target' user = adb('shell', 'am', 'get-current-user').strip() adb('shell', 'am', 'start', '-W', '-n', 'tv.luma.launcher/.MainActivity') key(4) tap('Open network settings', True) nodes = list(tree().iter('node')) assert any('Network' in n.get('text', '') or 'Wi-Fi' in n.get('text', '') for n in nodes), 'Network page missing' assert any(n.get('package') == 'com.android.tv.settings' for n in nodes), 'Not native TV settings' print('PASS: network status opens native TV network settings', flush=True) key(4) adb('shell', 'am', 'start', '-W', '-n', 'tv.luma.launcher/.MainActivity') assert package_present(), 'Install Luma-wake-tests.apk before this check' uninstall_menu() key(4) assert package_present(), 'Cancel removed test app' print('PASS: canceling Android confirmation preserves the app', flush=True) adb('shell', 'am', 'start', '-W', '-n', 'tv.luma.launcher/.MainActivity') uninstall_menu() tap('OK') for _ in range(15): if not package_present(): break time.sleep(.3) assert not package_present(), 'Confirmed uninstall failed' adb('shell', 'am', 'start', '-W', '-n', 'tv.luma.launcher/.MainActivity') key(82) tap('App library') assert not any(n.get('text', '').startswith('Luma test app') for n in tree().iter('node')), 'Removed app remains in library' key(4) print('PASS: confirmed uninstall removes disposable app and refreshes Luma library', flush=True)