Dumps the current UI XML and returns the sanitized JSON string.
()
| 20 | |
| 21 | |
| 22 | def get_screen_state() -> str: |
| 23 | """Dumps the current UI XML and returns the sanitized JSON string.""" |
| 24 | # 1. Capture XML from device |
| 25 | run_adb_command(["shell", "uiautomator", "dump", Config.SCREEN_DUMP_PATH]) |
| 26 | |
| 27 | # 2. Pull to local machine |
| 28 | run_adb_command(["pull", Config.SCREEN_DUMP_PATH, Config.LOCAL_DUMP_PATH]) |
| 29 | |
| 30 | # 3. Read & Sanitize |
| 31 | if not os.path.exists(Config.LOCAL_DUMP_PATH): |
| 32 | return "Error: Could not capture screen." |
| 33 | |
| 34 | with open(Config.LOCAL_DUMP_PATH, "r", encoding="utf-8") as f: |
| 35 | xml_content = f.read() |
| 36 | |
| 37 | elements = sanitizer.get_interactive_elements(xml_content) |
| 38 | return json.dumps(elements, indent=2) |
| 39 | |
| 40 | |
| 41 | def run_agent(goal: str, max_steps: int = None) -> None: |
no test coverage detected