AndroidDriver
AndroidDriver controls Android devices through ADB. Portal is optional and adds Unicode text input, app labels, richer UI state, and overlay-aware screenshots.
Import the driver from mobilerun-core-local:
Constructor
serial— ADB serial, such asemulator-5554, a USB serial, or an ADB-over-network address.use_tcp— Use Portal HTTP through an ADB port forward when available.portal_mode—"auto","required", or"disabled".
Portal modes
An invalid mode raises
ValueError.
In Framework configuration, portal_mode="disabled" also skips automatic Portal setup.
Examples:
Supported methods
drag() is not supported. Use swipe() instead.
Lifecycle
AndroidDriver.connect
auto mode, connection continues through ADB if Portal is unavailable. In required mode, it raises an error.
AndroidDriver.ensure_connected
Input actions
AndroidDriver.tap
AndroidDriver.swipe
duration_ms milliseconds.
AndroidDriver.input_text
True on success.
- When the Portal keyboard is available, text input supports Unicode.
- If Portal input fails in
automode, the driver switches to ADB text input. - ADB-only input supports printable ASCII. It rejects control/non-ASCII characters and the literal substring
%s, which Android reserves as a space escape. clear=Trueclears the focused field first when possible.
AndroidDriver.press_button
back, home, or enter (case-insensitive). An unknown name raises ValueError.
AndroidDriver.press_key_code
AndroidDriver.drag
drag() raises NotImplementedError. Use swipe() instead.
App management
AndroidDriver.start_app
activity is omitted, Mobilerun opens the app’s launcher activity. It raises RuntimeError when the app cannot be launched.
AndroidDriver.install_app
reinstall=False and grant_permissions=True are the defaults. A missing path raises FileNotFoundError.
grant_permissions=True grants eligible runtime permissions. Grant special access such as Accessibility, Display over other apps, Notification Access, Install unknown apps, and screen-capture consent on the device.AndroidDriver.stop_app
am force-stop.
AndroidDriver.uninstall_app
pm uninstall.
AndroidDriver.list_packages
AndroidDriver.get_apps
{"package": ..., "label": ...} records. Portal supplies display labels when available. Without Portal, package names are used for both fields.
State and observation
AndroidDriver.screenshot
hide_overlay=True. In auto mode, the driver uses an ADB screenshot if Portal is unavailable.
AndroidDriver.get_ui_tree
AndroidDriver.get_date
date command.
Portal transport
use_tcp=True uses Portal HTTP over an ADB port forward. In auto mode, Mobilerun uses the ContentProvider or ADB if HTTP is unavailable. Authentication is handled automatically.
See the Portal Local API for direct API access.