DeviceDriver
DeviceDriver is the base class for asynchronous device drivers in mobilerun-core-local. Use supported to check optional device operations. Most unavailable operations raise NotImplementedError; input_coordinate_size() is always available and defaults to the screenshot dimensions.
Quick Reference
Driver Methods:connect(),ensure_connected()tap(),swipe(),input_text(),press_button(),press_key_code(),drag()start_app(),stop_app(),install_app(),uninstall_app(),get_apps(),list_packages()screenshot(),input_coordinate_size(),get_ui_tree(),get_date()
supported:set[str]- Set of method names the driver implements. Check membership before calling.supported_buttons:set[str]- Set of button names accepted bypress_button()(e.g.{"back", "home", "enter"}).
How It Works
DeviceDriver sends commands to the device. StateProvider converts device data into UIState. Action functions receive an ActionContext and return an ActionResult.
Imports
Import asynchronous drivers frommobilerun-core-local:
mobilerun-core-local[cloud] to use CloudDriver.
Common Interface
All DeviceDriver implementations may provide these methods (checksupported set for availability):
Lifecycle
connect() -> None- Establish connection to the deviceensure_connected() -> None- Connect if not already connected
Input Actions
tap(x: int, y: int) -> None- Tap at screen coordinates (pixels on Android; logical points on iOS)swipe(x1: int, y1: int, x2: int, y2: int, duration_ms: float = 1000) -> None- Swipe gesturedrag(x1: int, y1: int, x2: int, y2: int, duration: float = 3.0) -> None- Drag gestureinput_text(text: str, clear: bool = False, stealth: bool = False, wpm: int = 0) -> bool- Text input into focused field.stealthenables human-like typing delays;wpmsets the typing speed in words per minute (0 = instant).press_button(button: str) -> None- Press a named button (e.g. back, home, enter). RaisesValueErrorif not insupported_buttons.press_key_code(key_code: int) -> None- Press an integer key code.
App Management
start_app(package: str, activity: str | None = None) -> str- Launch appstop_app(package: str) -> str- Stop a running appinstall_app(path: str, **kwargs) -> str- Install appuninstall_app(package: str) -> str- Uninstall applist_packages(include_system: bool = False) -> List[str]- List packagesget_apps(include_system: bool = True) -> List[Dict[str, str]]- Get apps with labels
State / Observation
screenshot(hide_overlay: bool = True) -> bytes- Capture screen as PNG bytesinput_coordinate_size(screenshot_width: int, screenshot_height: int) -> tuple[int, int]- Return the dimensions used for input coordinates. On iOS, these can differ from screenshot dimensions.get_ui_tree() -> Dict[str, Any]- Get raw UI / accessibility treeget_date() -> str- Get device date/time
StateProvider
supported set lists available UI features, such as element lookup and coordinate conversion.
AndroidStateProvider
UIState. Set stealth=True to vary tap coordinates within element bounds.
UIState
get_element(index: int) -> Dict | None- Recursively find an element by its indexget_element_coords(index: int) -> Tuple[int, int]- Return the centre (x, y) of an element. RaisesValueErrorwhen element is missing or has no bounds.get_element_info(index: int) -> Dict- Return element metadata (text, className, type, child_texts)get_clear_point(index: int) -> Tuple[int, int]- Find a tap point that avoids overlapping elements (falls back to centre)convert_point(x: int, y: int) -> Tuple[int, int]- Convert point to absolute pixels if normalized mode is active
elements- List of parsed UI elementsformatted_text- Formatted text representation of the UI treefocused_text- Text of the currently focused elementphone_state- Dict with current activity, keyboard visibility, etc.screen_width/screen_height- Device screen dimensionsuse_normalized- Whether normalized coordinate mode is active
ActionContext
driver-DeviceDriverinstance for raw device I/Oui-UIStateinstance for element resolution (refreshed each step)shared_state-MobileAgentStatefor shared agent statestate_provider-StateProviderfor fetching fresh UI stateapp_opener_llm- LLM instance for app opening workflow (optional)credential_manager- CredentialManager instance (optional)streaming- Whether streaming is enabled
ActionResult
summary field describes the result.
Action Functions
Action functions follow this pattern:click(index)- Click UI element by indexclick_at(x, y)- Click at screen coordinatesclick_area(x1, y1, x2, y2)- Click center of area defined by coordinateslong_press(index)- Long press UI element by indexlong_press_at(x, y)- Long press at screen coordinatestype(text, index=None, clear=False)- Optionally focus an indexed element, then input text (setclear=Trueto clear first)type_text(text, clear=False)- Input text into the focused fieldtype_secret(secret_id, index)- Input a configured credential into an indexed elementswipe(coordinate, coordinate2, duration=1.0)- Swipe gesture between two coordinate listssystem_button(button)- Press system buttons (back, home, enter)open_app(...)- Open an Android app by name or an iOS or Visual Remote app by IDwait(duration=1.0)- Wait for a duration in secondscomplete(success, message)- Mark task as finished
Custom Tool Integration
Adding Custom Tools
Driver and Platform Comparison
RecordingDriver and StealthDriver support the same methods as the driver they wrap.
Best Practices
1. Check supported methods before calling
2. Use ActionContext for agent-level interactions
3. Use StateProvider for UI state
Error Handling
Driver methods use consistent error handling: Unsupported operations:PlatformUnsupportedError is a subclass of NotImplementedError. Check driver.supported before calling an optional method. press_button() raises ValueError for names outside supported_buttons. CloudDriver raises DeviceDisconnectedError for SDK connection, timeout, and conflict failures. Other connection and authentication failures may raise connection, HTTP, or permission errors.
ActionResult for action functions:
See Also
- AndroidDriver API - Android driver
- IOSPortalHttpDriver API - iOS driver
- MobileAgent API - Agent integration
- Configuration - Configuration reference