Files
OrbitTv/tools/nav_map.py
T

84 lines
3.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Navigation map for the disposable emulator only (emulator-5580): runs remote presses and records where focus lands.
Usage: python3 -I navmap.py OUT.md (Orbit must be open on Home, signed in, with channel 701 on)"""
import subprocess, sys, time, re
import xml.etree.ElementTree as ET
A = ["/opt/android-sdk/platform-tools/adb", "-s", "emulator-5580"]
KEYS = {"Up": 19, "Down": 20, "Left": 21, "Right": 22, "OK": 23, "Back": 4}
def sh(*a):
return subprocess.run(A + ["shell", *a], capture_output=True, text=True).stdout
def key(name, wait=1.2):
sh("input", "keyevent", str(KEYS[name])); time.sleep(wait)
def texts(node):
out = [n.get("text") or n.get("content-desc") for n in node.iter() if (n.get("text") or n.get("content-desc"))]
return [t for t in out if t.strip()]
def state():
sh("uiautomator", "dump", "/sdcard/nav.xml")
x = sh("cat", "/sdcard/nav.xml")
try:
root = ET.fromstring(x[x.index("<?xml"):] if "<?xml" in x else x)
except Exception:
return "?", "?"
allt = texts(root)
focused = [n for n in root.iter() if n.get("focused") == "true"]
f = focused[-1] if focused else None
label = " / ".join(texts(f)[:2]) if f is not None else "(nothing focused)"
if f is not None and not texts(f):
label = f"(unlabelled {f.get('class','').split('.')[-1]} at {f.get('bounds')})"
# The screen: a known heading on screen.
screen = next((t for t in allt if t in ("Settings", "Who's watching?", "What would you like to watch?", "Pick a game!", "Director's Chair",
"Connect a phone", "Add a room", "Restore a backup", "QUIZ NIGHT")), allt[0] if allt else "?")
return screen, label[:70]
rows = []
def step(context, press, expect=""):
before = state()
key(press)
after = state()
rows.append((context, press, f"{before[0]}: {before[1]}", f"{after[0]}: {after[1]}", expect))
print(rows[-1], flush=True)
return after
def home():
for _ in range(4):
s = state()
if s[0] == "What would you like to watch?": return
key("Back")
sh("am", "start", "-n", "tv.orbit.classic/.MainActivity"); time.sleep(3)
out = sys.argv[1]
home()
for p in ["Up", "Down", "Left", "Right"]:
step("Home", p); home()
# Top bar: up to it, then along to Settings.
key("Up")
for _ in range(8): step("Top bar", "Right")
step("Top bar (Settings gear)", "OK", "Settings opens")
# Settings rail into Channels: Director's Chair.
step("Settings rail", "Right", "into Channels: Create your own")
step("Settings › Channels", "Right", "Director's Chair card")
step("Director's Chair card", "OK", "Chair opens, focus inside it")
time.sleep(4)
step("Director's Chair (open)", "Down", "stays inside the Chair")
step("Director's Chair (open)", "Left", "stays inside the Chair")
step("Director's Chair (open)", "Left", "stays inside the Chair")
step("Director's Chair (open)", "Back", "back to the Channels list, Chair card focused")
home()
# Who's watching from the top bar's profile button.
key("Up")
for _ in range(7): key("Right", 0.6)
step("Top bar (profile)", "OK", "Who's watching opens")
for p in ["Up", "Down", "Left", "Right", "Right", "Right"]:
step("Who's watching (from inside Orbit)", p, "stays on the profiles")
step("Who's watching (from inside Orbit)", "Back", "back where it was opened, profile kept")
home()
with open(out, "w") as f:
f.write("| From | Press | Before | After | Should be |\n| --- | --- | --- | --- | --- |\n")
for r in rows: f.write("| " + " | ".join(c.replace("|", "/") for c in r) + " |\n")
print("written", out)