AndroidDriver
supported set, and unsupported methods raise NotImplementedError.
AndroidDriver.__init__
serialstr | None - Device serial number (e.g., “emulator-5554”, “192.168.1.100:5555”). If None, auto-detects the first available device.use_tcpbool - Whether to prefer TCP communication (default: False). TCP is faster but requires port forwarding. Falls back to content provider mode if TCP fails.remote_tcp_portint - TCP port for Portal app communication on device (default: 8080)
- Automatically sets up the Droidrun Portal keyboard on
connect()viasetup_keyboard() - Creates a PortalClient instance that handles TCP/content provider communication
- Device serial can be emulator name, USB serial, or TCP/IP address:port
- Must call
connect()orensure_connected()before using any methods
Lifecycle Methods
AndroidDriver.connect
AndroidDriver.ensure_connected
Input Action Methods
AndroidDriver.tap
xint - X coordinateyint - Y coordinate
AndroidDriver.swipe
x1int - Starting X coordinatey1int - Starting Y coordinatex2int - Ending X coordinatey2int - Ending Y coordinateduration_msfloat - Duration of swipe in milliseconds (default: 1000)
- Duration is converted to seconds internally (dividing by 1000)
- Includes an async sleep matching the swipe duration for UI settling
AndroidDriver.input_text
textstr - Text to input. Supports Unicode and special characters.clearbool - Whether to clear existing text before inputting (default: False)
bool- True if input succeeded, False otherwise
- Uses the Droidrun Portal app keyboard for reliable text input via PortalClient
- Supports Unicode characters and special characters
AndroidDriver.press_key
3: HOME4: BACK66: ENTER67: DELETE
keycodeint - Android keycode to press
AndroidDriver.drag
x1int - Starting X coordinatey1int - Starting Y coordinatex2int - Ending X coordinatey2int - Ending Y coordinatedurationfloat - Duration of drag in seconds (default: 3.0)
- Currently raises
NotImplementedError(declared insupportedset but not yet implemented)
App Management Methods
AndroidDriver.start_app
cmd package resolve-activity.
Arguments:
packagestr - Package name (e.g., “com.android.settings”, “com.google.android.apps.messaging”)activitystr | None - Optional activity name (e.g., ”.Settings”). If None, auto-detects the main launcher activity.
str- Result message indicating success or error
AndroidDriver.install_app
pathstr - Path to the APK file on the local machinereinstallbool - Whether to reinstall if app already exists (default: False)grant_permissionsbool - Whether to grant all permissions automatically (default: True)
str- Result message indicating success or error
AndroidDriver.list_packages
include_systembool - Whether to include system apps (default: False)
List[str]- List of package names
AndroidDriver.get_apps
include_systembool - Whether to include system apps (default: True)
List[Dict[str, str]]- List of dictionaries containing ‘package’ and ‘label’ keys
State and Observation Methods
AndroidDriver.screenshot
hide_overlaybool - Whether to hide Portal app overlay elements during screenshot (default: True)
bytes- Raw PNG image data
AndroidDriver.get_ui_tree
Dict[str, Any]- Raw UI tree data from the device
AndroidDriver.get_date
str- Date and time string from device
Properties
Instance variables:device- ADB device instance (from async_adbutils)portal- PortalClient instance for device communication (TCP or content provider mode)supported- Set of supported method names for capability checking
Notes
- Portal app required: The Droidrun Portal app must be installed and accessibility service enabled on the device
- TCP vs Content Provider: TCP is faster but requires port forwarding (
adb forward tcp:8080 tcp:8080). Content provider is the fallback mode using ADB shell commands. - Capability checking: Check
"method_name" in driver.supportedto determine if a method is available before calling it - Async-only: All methods are async and must be awaited
- No element resolution: AndroidDriver provides raw device I/O only. Element resolution (by index) is handled by
UIStatevia theStateProviderlayer.
Example Workflow
ActionContext (see DroidAgent) rather than calling the driver directly.
