From 303c024deddd53089b0ba2e39a4e8bbfe4012ccd Mon Sep 17 00:00:00 2001 From: glayyiyi Date: Mon, 26 Oct 2026 07:59:07 +0800 Subject: [PATCH] fix(adb): launch apps with monkey --pct-syskeys 0 On devices without physical keys (emulators, Redroid, car head units) monkey warns "SYS_KEYS has no physical keys" and its single event does not launch the app, so the initial app launch timed out three times (about 45 s) before the agent opened the app from the app drawer. With --pct-syskeys 0 the launch event is injected ("Events injected: 1") and the app comes to the foreground. --- artemis/drivers/android/adb_driver.py | 5 ++++- tests/unit/test_drivers.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/artemis/drivers/android/adb_driver.py b/artemis/drivers/android/adb_driver.py index 360aa4862..a3a2baa7f 100644 --- a/artemis/drivers/android/adb_driver.py +++ b/artemis/drivers/android/adb_driver.py @@ -384,7 +384,10 @@ async def press_key(self, key: KeyCode | str | int) -> bool: async def launch_app(self, package_name: str) -> bool: try: - cmd = f"monkey -p {package_name} -c android.intent.category.LAUNCHER 1" + # --pct-syskeys 0: on devices without physical keys (emulators, head units) monkey otherwise warns + # "SYS_KEYS has no physical keys" and can spend its single event on a key instead of the launch, + # leaving the previous app in the foreground. + cmd = f"monkey --pct-syskeys 0 -p {package_name} -c android.intent.category.LAUNCHER 1" await asyncio.to_thread(self.device.shell, cmd) return True except Exception as e: diff --git a/tests/unit/test_drivers.py b/tests/unit/test_drivers.py index 6d5b2493a..89386bec5 100644 --- a/tests/unit/test_drivers.py +++ b/tests/unit/test_drivers.py @@ -101,6 +101,12 @@ async def test_android_driver_with_mock_adb(): await driver.press_key(KeyCode.BACK) mock_adb_device.shell.assert_called_with("input keyevent 4") + # Launch through the LAUNCHER category without system-key events (keyless devices) + assert await driver.launch_app("com.example.themesim") is True + mock_adb_device.shell.assert_called_with( + "monkey --pct-syskeys 0 -p com.example.themesim -c android.intent.category.LAUNCHER 1" + ) + @pytest.mark.asyncio async def test_android_driver_preserves_elements_from_combined_screen_data():