Skip to main content

AdbDevice

Struct AdbDevice 

Source
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: String

Implementations§

Source§

impl AdbDevice

Source

pub fn new( serial: impl Into<String>, host: impl Into<String>, port: u16, ) -> Self

Create a new device handle.

Source

pub fn with_serial(serial: impl Into<String>) -> Self

Create a device handle using default ADB server address.

Source

pub async fn get_state(&self) -> Result<DeviceState>

Get the device state (device, offline, unauthorized, etc.).

Source

pub async fn get_serialno(&self) -> Result<String>

Get the real serial number of the device.

Source

pub async fn get_features(&self) -> Result<Vec<String>>

Get the device feature list (e.g., shell_v2, cmd, stat_v2).

Source

pub async fn shell(&self, cmd: &str) -> Result<String>

Run a shell command and return stdout as a String.

Source

pub async fn shell_bytes(&self, cmd: &str) -> Result<Vec<u8>>

Run a shell command and return stdout as raw bytes.

Source

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.

Source

pub async fn getprop(&self, name: &str) -> Result<String>

Get a system property by name.

Source

pub async fn prop_model(&self) -> Result<String>

Get the device model (ro.product.model).

Source

pub async fn prop_name(&self) -> Result<String>

Get the device name (ro.product.name).

Source

pub async fn prop_device(&self) -> Result<String>

Get the device codename (ro.product.device).

Source

pub async fn tap(&self, x: i32, y: i32) -> Result<()>

Tap at screen coordinates.

Source

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.

Source

pub async fn keyevent(&self, keycode: i32) -> Result<()>

Send a key event.

Source

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.

Source

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.

Source

pub async fn screencap(&self) -> Result<Vec<u8>>

Take a screenshot and return PNG bytes.

Source

pub async fn app_start( &self, package: &str, activity: Option<&str>, ) -> Result<String>

Start an app with optional activity name.

Source

pub async fn app_stop(&self, package: &str) -> Result<()>

Force stop an app.

Source

pub async fn app_clear(&self, package: &str) -> Result<String>

Clear app data and cache.

Source

pub async fn app_current(&self) -> Result<CurrentApp>

Get the current foreground app.

Source

pub async fn app_info(&self, package: &str) -> Result<AppDetail>

Get detailed info about an installed app.

Source

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.

Source

pub async fn uninstall(&self, package: &str) -> Result<String>

Uninstall an app.

Source

pub async fn list_packages(&self, flags: &[&str]) -> Result<Vec<String>>

List installed packages.

Source

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.

Source

pub async fn forward_list(&self) -> Result<Vec<ForwardEntry>>

List all port forwards for this device.

Source

pub async fn forward_remove(&self, local_port: u16) -> Result<()>

Remove a specific port forward.

Source

pub async fn forward_remove_all(&self) -> Result<()>

Remove all port forwards for this device.

Source

pub async fn reverse(&self, remote_port: u16, local_port: u16) -> Result<()>

Set up reverse port forwarding (device → host).

Source

pub async fn reverse_list(&self) -> Result<Vec<ReverseEntry>>

List all reverse port forwards.

Source

pub async fn reverse_remove(&self, remote_port: u16) -> Result<()>

Remove a specific reverse forward.

Source

pub async fn reverse_remove_all(&self) -> Result<()>

Remove all reverse forwards.

Source

pub async fn root(&self) -> Result<String>

Restart adbd as root. Only works on userdebug/eng builds or emulators.

Source

pub async fn tcpip(&self, port: u16) -> Result<String>

Switch adbd to TCP/IP mode on the given port.

Source

pub async fn reboot(&self, mode: RebootMode) -> Result<()>

Reboot the device.

Source

pub async fn push(&self, local_path: &Path, remote_path: &str) -> Result<()>

Push a local file to the device using the sync protocol.

Source

pub async fn push_bytes(&self, data: &[u8], remote_path: &str) -> Result<()>

Push raw bytes to a file on the device.

Source

pub async fn pull_bytes(&self, remote_path: &str) -> Result<Vec<u8>>

Pull a file from the device and return its contents as bytes.

Source

pub async fn pull(&self, remote_path: &str, local_path: &Path) -> Result<()>

Pull a file from the device to a local path.

Source

pub async fn stat(&self, path: &str) -> Result<FileStat>

Get file metadata via sync STAT protocol.

Source

pub async fn list_dir(&self, path: &str) -> Result<Vec<SyncDirEntry>>

List directory contents via sync LIST protocol.

Source

pub async fn exists(&self, path: &str) -> Result<bool>

Check if a file or directory exists on the device.

Source

pub async fn remove(&self, path: &str) -> Result<()>

Delete a file on the device.

Source

pub async fn rmtree(&self, path: &str) -> Result<()>

Delete a directory recursively on the device.

Source

pub async fn window_size(&self) -> Result<ScreenSize>

Get screen dimensions.

Source

pub async fn rotation(&self) -> Result<u8>

Get current screen rotation (0=natural, 1=left, 2=inverted, 3=right).

Source

pub async fn is_screen_on(&self) -> Result<bool>

Check if the screen is currently on.

Source

pub async fn switch_screen(&self, on: bool) -> Result<()>

Turn screen on or off.

Source

pub async fn wlan_ip(&self) -> Result<String>

Get the device’s WLAN IP address.

Source

pub async fn get_date(&self) -> Result<String>

Get the device date/time.

Source

pub async fn logcat(&self, filter: Option<&str>) -> Result<Receiver<String>>

Stream logcat output. Returns an mpsc receiver.

The stream runs in a background task until the receiver is dropped.

Trait Implementations§

Source§

impl Clone for AdbDevice

Source§

fn clone(&self) -> AdbDevice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AdbDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more