pub struct AdbWire { /* private fields */ }Expand description
Implementations§
Source§impl AdbWire
impl AdbWire
Sourcepub fn new(serial: &str) -> Self
pub fn new(serial: &str) -> Self
Create a client for the given device serial (e.g. "emulator-5554",
"127.0.0.1:5555", "R5CR1234567").
Sourcepub fn server(self, addr: SocketAddr) -> Self
pub fn server(self, addr: SocketAddr) -> Self
Use a custom ADB server address (default: 127.0.0.1:5037).
Sourcepub fn connect_timeout(self, dur: Duration) -> Self
pub fn connect_timeout(self, dur: Duration) -> Self
Set the TCP connect timeout (default: 2s).
Sourcepub fn read_timeout(self, dur: Duration) -> Self
pub fn read_timeout(self, dur: Duration) -> Self
Set the read timeout for buffered methods like shell
(default: 30s). For streaming methods, manage timeouts on the returned
stream directly.
Sourcepub async fn shell(&self, cmd: &str) -> Result<ShellOutput>
pub async fn shell(&self, cmd: &str) -> Result<ShellOutput>
Run a shell command, returning separated stdout, stderr, and exit code.
let adb = AdbWire::new("emulator-5554");
let result = adb.shell("ls /sdcard").await.unwrap();
if result.success() {
println!("{}", result.stdout_str());
} else {
eprintln!("exit {}: {}", result.exit_code, result.stderr_str());
}Sourcepub async fn shell_stream(&self, cmd: &str) -> Result<ShellStream>
pub async fn shell_stream(&self, cmd: &str) -> Result<ShellStream>
Run a shell command and return a streaming reader.
The returned ShellStream implements AsyncRead
yielding stdout bytes. Use collect_output
to buffer everything, or read incrementally for long-running commands.
use tokio::io::{AsyncBufReadExt, BufReader};
let adb = AdbWire::new("emulator-5554");
let stream = adb.shell_stream("logcat").await.unwrap();
let mut lines = BufReader::new(stream).lines();
while let Some(line) = lines.next_line().await.unwrap() {
println!("{line}");
}Sourcepub async fn shell_detach(&self, cmd: &str) -> Result<()>
pub async fn shell_detach(&self, cmd: &str) -> Result<()>
Send a shell command without waiting for output.
Opens a shell connection and immediately drops it. The ADB server will still deliver the command to the device, but the command may not have started on the device by the time this method returns.
Warning: Because the connection is dropped immediately, there is
no guarantee the command will execute. If the device has not received
the command before the TCP connection closes, it will be lost. Use
shell if you need confirmation that the command ran.
Best suited for input commands (tap, swipe, keyevent) where occasional drops are acceptable.
Sourcepub async fn stat(&self, remote_path: &str) -> Result<RemoteStat>
pub async fn stat(&self, remote_path: &str) -> Result<RemoteStat>
Query file metadata on the device.
Returns a RemoteStat with mode, size, and modification time.
If the path does not exist, all fields will be zero —
check with RemoteStat::exists().
let adb = AdbWire::new("emulator-5554");
let st = adb.stat("/sdcard/Download/test.txt").await.unwrap();
if st.exists() {
println!("size: {} bytes, mode: {:o}", st.size, st.mode);
}Sourcepub async fn list_dir(&self, remote_path: &str) -> Result<Vec<DirEntry>>
pub async fn list_dir(&self, remote_path: &str) -> Result<Vec<DirEntry>>
List files in a remote directory.
Returns entries excluding . and ... Uses the sync LIST protocol.
let adb = AdbWire::new("emulator-5554");
for entry in adb.list_dir("/sdcard").await.unwrap() {
println!("{}\t{} bytes", entry.name, entry.size);
}Sourcepub async fn pull(
&self,
remote_path: &str,
writer: &mut (impl AsyncWrite + Unpin),
) -> Result<u64>
pub async fn pull( &self, remote_path: &str, writer: &mut (impl AsyncWrite + Unpin), ) -> Result<u64>
Pull a file from the device, writing its contents to writer.
Returns the number of bytes written.
Sourcepub async fn pull_file(
&self,
remote_path: &str,
local_path: impl AsRef<Path>,
) -> Result<u64>
pub async fn pull_file( &self, remote_path: &str, local_path: impl AsRef<Path>, ) -> Result<u64>
Pull a file from the device to a local path.
Sourcepub async fn push(
&self,
remote_path: &str,
mode: u32,
mtime: u32,
reader: &mut (impl AsyncRead + Unpin),
) -> Result<()>
pub async fn push( &self, remote_path: &str, mode: u32, mtime: u32, reader: &mut (impl AsyncRead + Unpin), ) -> Result<()>
Push data from reader to a file on the device.
mode is the Unix file permission as an octal value (e.g. 0o644,
0o755). mtime is seconds since the Unix epoch.
Sourcepub async fn push_file(
&self,
local_path: impl AsRef<Path>,
remote_path: &str,
) -> Result<()>
pub async fn push_file( &self, local_path: impl AsRef<Path>, remote_path: &str, ) -> Result<()>
Push a local file to the device with mode 0o644.
Sourcepub async fn push_file_with_mode(
&self,
local_path: impl AsRef<Path>,
remote_path: &str,
mode: u32,
) -> Result<()>
pub async fn push_file_with_mode( &self, local_path: impl AsRef<Path>, remote_path: &str, mode: u32, ) -> Result<()>
Push a local file to the device with a custom Unix file mode.
let adb = AdbWire::new("emulator-5554");
adb.push_file_with_mode("run.sh", "/data/local/tmp/run.sh", 0o755).await.unwrap();Sourcepub async fn install(&self, local_apk: impl AsRef<Path>) -> Result<()>
pub async fn install(&self, local_apk: impl AsRef<Path>) -> Result<()>
Install an APK on the device. Equivalent to adb install <path>.
let adb = AdbWire::new("emulator-5554");
adb.install("app-debug.apk").await.unwrap();Sourcepub async fn install_with_args(
&self,
local_apk: impl AsRef<Path>,
args: &[&str],
) -> Result<()>
pub async fn install_with_args( &self, local_apk: impl AsRef<Path>, args: &[&str], ) -> Result<()>
Install an APK with additional pm install flags.
let adb = AdbWire::new("emulator-5554");
adb.install_with_args("app.apk", &["-r", "-d"]).await.unwrap();Sourcepub async fn forward(&self, local: &str, remote: &str) -> Result<()>
pub async fn forward(&self, local: &str, remote: &str) -> Result<()>
Set up port forwarding from a local socket to the device.
local and remote are ADB socket specs, e.g. "tcp:8080",
"localabstract:chrome_devtools_remote".
Sourcepub async fn reverse(&self, remote: &str, local: &str) -> Result<()>
pub async fn reverse(&self, remote: &str, local: &str) -> Result<()>
Set up reverse port forwarding from the device to a local socket.
Sourcepub async fn wait_for_device(&self) -> Result<()>
pub async fn wait_for_device(&self) -> Result<()>
Wait until the device is online.
Blocks until the ADB server reports the device as available.
Equivalent to adb -s <serial> wait-for-device.
let adb = AdbWire::new("192.168.1.100:5555");
adb.wait_for_device().await.unwrap();
println!("device online");Sourcepub async fn wait_for_boot(&self) -> Result<()>
pub async fn wait_for_boot(&self) -> Result<()>
Wait until the device has finished booting.
Waits for the device to come online, then polls sys.boot_completed
until it reports 1.
let adb = AdbWire::new("emulator-5554");
adb.wait_for_boot().await.unwrap();
println!("device booted");