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():