pub struct AdbDevice {
pub serial: String,
/* private fields */
}Expand description
Represents a connection to a specific Android device via the ADB server.
Each operation opens a fresh TCP connection to the ADB server, selects the transport for this device, then performs the command. This matches how the ADB protocol works — there is no persistent session.
Fields§
§serial: StringImplementations§
Source§impl AdbDevice
impl AdbDevice
Sourcepub fn new(
serial: impl Into<String>,
host: impl Into<String>,
port: u16,
) -> Self
pub fn new( serial: impl Into<String>, host: impl Into<String>, port: u16, ) -> Self
Create a new device handle.
Sourcepub fn with_serial(serial: impl Into<String>) -> Self
pub fn with_serial(serial: impl Into<String>) -> Self
Create a device handle using default ADB server address.
Sourcepub async fn get_state(&self) -> Result<DeviceState>
pub async fn get_state(&self) -> Result<DeviceState>
Get the device state (device, offline, unauthorized, etc.).
Sourcepub async fn get_serialno(&self) -> Result<String>
pub async fn get_serialno(&self) -> Result<String>
Get the real serial number of the device.
Sourcepub async fn get_features(&self) -> Result<Vec<String>>
pub async fn get_features(&self) -> Result<Vec<String>>
Get the device feature list (e.g., shell_v2, cmd, stat_v2).
Sourcepub async fn shell(&self, cmd: &str) -> Result<String>
pub async fn shell(&self, cmd: &str) -> Result<String>
Run a shell command and return stdout as a String.
Sourcepub async fn shell_bytes(&self, cmd: &str) -> Result<Vec<u8>>
pub async fn shell_bytes(&self, cmd: &str) -> Result<Vec<u8>>
Run a shell command and return stdout as raw bytes.
Sourcepub async fn shell2(&self, cmd: &str) -> Result<ShellOutput>
pub async fn shell2(&self, cmd: &str) -> Result<ShellOutput>
Run a shell command and return both stdout and exit code.
Wraps the command in a subshell (cmd) so that even exit N won’t
prevent the sentinel from being printed, then appends
; echo DROIDRUN_EXIT:$? to capture the exit code.
Sourcepub async fn prop_model(&self) -> Result<String>
pub async fn prop_model(&self) -> Result<String>
Get the device model (ro.product.model).
Sourcepub async fn prop_device(&self) -> Result<String>
pub async fn prop_device(&self) -> Result<String>
Get the device codename (ro.product.device).
Sourcepub async fn swipe(
&self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
duration_ms: u32,
) -> Result<()>
pub async fn swipe( &self, x1: i32, y1: i32, x2: i32, y2: i32, duration_ms: u32, ) -> Result<()>
Swipe from (x1, y1) to (x2, y2) over duration_ms milliseconds.
Sourcepub async fn drag(
&self,
sx: i32,
sy: i32,
ex: i32,
ey: i32,
duration_ms: u32,
) -> Result<()>
pub async fn drag( &self, sx: i32, sy: i32, ex: i32, ey: i32, duration_ms: u32, ) -> Result<()>
Drag from (sx, sy) to (ex, ey) over duration_ms milliseconds.
Sourcepub async fn input_text(&self, text: &str) -> Result<()>
pub async fn input_text(&self, text: &str) -> Result<()>
Type text using ADB input method.
Note: For reliable Unicode text input, use droidrun-core’s Portal keyboard. This method escapes special shell characters but cannot handle all Unicode.
Sourcepub async fn app_start(
&self,
package: &str,
activity: Option<&str>,
) -> Result<String>
pub async fn app_start( &self, package: &str, activity: Option<&str>, ) -> Result<String>
Start an app with optional activity name.
Sourcepub async fn app_current(&self) -> Result<CurrentApp>
pub async fn app_current(&self) -> Result<CurrentApp>
Get the current foreground app.
Sourcepub async fn app_info(&self, package: &str) -> Result<AppDetail>
pub async fn app_info(&self, package: &str) -> Result<AppDetail>
Get detailed info about an installed app.
Sourcepub async fn install(&self, apk_path: &Path, flags: &[&str]) -> Result<String>
pub async fn install(&self, apk_path: &Path, flags: &[&str]) -> Result<String>
Install an APK on the device.
Pushes the APK to /data/local/tmp/, runs pm install, then removes it.
Sourcepub async fn list_packages(&self, flags: &[&str]) -> Result<Vec<String>>
pub async fn list_packages(&self, flags: &[&str]) -> Result<Vec<String>>
List installed packages.
Sourcepub async fn forward(&self, local_port: u16, remote_port: u16) -> Result<u16>
pub async fn forward(&self, local_port: u16, remote_port: u16) -> Result<u16>
Set up port forwarding. Returns the local port.
If local_port is 0, the ADB server assigns a free port.
Sourcepub async fn forward_list(&self) -> Result<Vec<ForwardEntry>>
pub async fn forward_list(&self) -> Result<Vec<ForwardEntry>>
List all port forwards for this device.
Sourcepub async fn forward_remove(&self, local_port: u16) -> Result<()>
pub async fn forward_remove(&self, local_port: u16) -> Result<()>
Remove a specific port forward.
Sourcepub async fn forward_remove_all(&self) -> Result<()>
pub async fn forward_remove_all(&self) -> Result<()>
Remove all port forwards for this device.
Sourcepub async fn reverse(&self, remote_port: u16, local_port: u16) -> Result<()>
pub async fn reverse(&self, remote_port: u16, local_port: u16) -> Result<()>
Set up reverse port forwarding (device → host).
Sourcepub async fn reverse_list(&self) -> Result<Vec<ReverseEntry>>
pub async fn reverse_list(&self) -> Result<Vec<ReverseEntry>>
List all reverse port forwards.
Sourcepub async fn reverse_remove(&self, remote_port: u16) -> Result<()>
pub async fn reverse_remove(&self, remote_port: u16) -> Result<()>
Remove a specific reverse forward.
Sourcepub async fn reverse_remove_all(&self) -> Result<()>
pub async fn reverse_remove_all(&self) -> Result<()>
Remove all reverse forwards.
Sourcepub async fn root(&self) -> Result<String>
pub async fn root(&self) -> Result<String>
Restart adbd as root. Only works on userdebug/eng builds or emulators.
Sourcepub async fn tcpip(&self, port: u16) -> Result<String>
pub async fn tcpip(&self, port: u16) -> Result<String>
Switch adbd to TCP/IP mode on the given port.
Sourcepub async fn reboot(&self, mode: RebootMode) -> Result<()>
pub async fn reboot(&self, mode: RebootMode) -> Result<()>
Reboot the device.
Sourcepub async fn push(&self, local_path: &Path, remote_path: &str) -> Result<()>
pub async fn push(&self, local_path: &Path, remote_path: &str) -> Result<()>
Push a local file to the device using the sync protocol.
Sourcepub async fn push_bytes(&self, data: &[u8], remote_path: &str) -> Result<()>
pub async fn push_bytes(&self, data: &[u8], remote_path: &str) -> Result<()>
Push raw bytes to a file on the device.
Sourcepub async fn pull_bytes(&self, remote_path: &str) -> Result<Vec<u8>>
pub async fn pull_bytes(&self, remote_path: &str) -> Result<Vec<u8>>
Pull a file from the device and return its contents as bytes.
Sourcepub async fn pull(&self, remote_path: &str, local_path: &Path) -> Result<()>
pub async fn pull(&self, remote_path: &str, local_path: &Path) -> Result<()>
Pull a file from the device to a local path.
Sourcepub async fn stat(&self, path: &str) -> Result<FileStat>
pub async fn stat(&self, path: &str) -> Result<FileStat>
Get file metadata via sync STAT protocol.
Sourcepub async fn list_dir(&self, path: &str) -> Result<Vec<SyncDirEntry>>
pub async fn list_dir(&self, path: &str) -> Result<Vec<SyncDirEntry>>
List directory contents via sync LIST protocol.
Sourcepub async fn exists(&self, path: &str) -> Result<bool>
pub async fn exists(&self, path: &str) -> Result<bool>
Check if a file or directory exists on the device.
Sourcepub async fn rmtree(&self, path: &str) -> Result<()>
pub async fn rmtree(&self, path: &str) -> Result<()>
Delete a directory recursively on the device.
Sourcepub async fn window_size(&self) -> Result<ScreenSize>
pub async fn window_size(&self) -> Result<ScreenSize>
Get screen dimensions.
Sourcepub async fn rotation(&self) -> Result<u8>
pub async fn rotation(&self) -> Result<u8>
Get current screen rotation (0=natural, 1=left, 2=inverted, 3=right).
Sourcepub async fn is_screen_on(&self) -> Result<bool>
pub async fn is_screen_on(&self) -> Result<bool>
Check if the screen is currently on.
Sourcepub async fn switch_screen(&self, on: bool) -> Result<()>
pub async fn switch_screen(&self, on: bool) -> Result<()>
Turn screen on or off.