Crate adb_client

Source
Expand description

§adb_client

MIT licensed Documentation Crates.io Total Downloads

Rust library implementing ADB protocol.

§Installation

Add adb_client crate as a dependency by simply adding it to your Cargo.toml:

[dependencies]
adb_client = "*"

§Benchmarks

Benchmarks run on v2.0.6, on a Samsung S10 SM-G973F device and an Intel i7-1265U CPU laptop

§ADBServerDevice push vs adb push

ADBServerDevice performs all operations by using adb server as a bridge.

File sizeSample sizeADBServerDeviceadbDifference
10 MB100350,79 ms356,30 ms
-1,57 %
500 MB5015,60 s15,64 s
-0,25 %
1 GB2031,09 s31,12 s
-0,10 %

§Examples

§Get available ADB devices

use adb_client::ADBServer;
use std::net::{SocketAddrV4, Ipv4Addr};

// A custom server address can be provided
let server_ip = Ipv4Addr::new(127, 0, 0, 1);
let server_port = 5037;

let mut server = ADBServer::new(SocketAddrV4::new(server_ip, server_port));
server.devices();

§Using ADB server as bridge

§Launch a command on device
use adb_client::{ADBServer, ADBDeviceExt};

let mut server = ADBServer::default();
let mut device = server.get_device().expect("cannot get device");
device.shell_command(&["df", "-h"], &mut std::io::stdout());
§Push a file to the device
use adb_client::ADBServer;
use std::net::Ipv4Addr;
use std::fs::File;
use std::path::Path;

let mut server = ADBServer::default();
let mut device = server.get_device().expect("cannot get device");
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
device.push(&mut input, "/data/local/tmp");

§Interact directly with end devices

§(USB) Launch a command on device
use adb_client::{ADBUSBDevice, ADBDeviceExt};

let vendor_id = 0x04e8;
let product_id = 0x6860;
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
device.shell_command(&["df", "-h"], &mut std::io::stdout());
§(USB) Push a file to the device
use adb_client::{ADBUSBDevice, ADBDeviceExt};
use std::fs::File;
use std::path::Path;

let vendor_id = 0x04e8;
let product_id = 0x6860;
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
device.push(&mut input, &"/data/local/tmp");
§(TCP) Get a shell from device
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
use adb_client::{ADBTcpDevice, ADBDeviceExt};

let device_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 10));
let device_port = 43210;
let mut device = ADBTcpDevice::new(SocketAddr::new(device_ip, device_port)).expect("cannot find device");
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()));

Structs§

ADBEmulatorDevice
Represents an emulator connected to the ADB server.
ADBServer
Represents an ADB Server
ADBServerDevice
Represents a device connected to the ADB server.
ADBTcpDevice
Represent a device reached and available over USB.
ADBUSBDevice
Represent a device reached and available over USB.
AdbStatResponse
Represents a stat response
AdbVersion
Represents the ADB server version.
DeviceLong
Represents a new device with more informations.
DeviceShort
Represents a device connected to the ADB server.
MDNSDevice
Represent a device found from mdns search
MDNSDiscoveryService
Structure holding responsibility over mdns discovery
MDNSServices
Represents MDNS Services
ServerStatus
Structure representing current server status
TCPEmulatorTransport
Emulator transport running on top on TCP.
TCPServerTransport
Server transport running on top on TCP
TcpTransport
Transport running on USB
USBTransport
Transport running on USB

Enums§

DeviceState
Represents the connection state of the device.
MDNSBackend
MDNS Backend Status
RebootType
Type of reboot needed.
RustADBError
Represents all error types that can be thrown by the crate.
WaitForDeviceState
List of available states to wait for.
WaitForDeviceTransport
List of available transports to wait for.

Traits§

ADBDeviceExt
Trait representing all features available on both crate::ADBServerDevice and crate::ADBUSBDevice
ADBMessageTransport
Trait representing a transport able to read and write messages.
ADBTransport
Trait representing a transport usable by ADB protocol.

Type Aliases§

Result
Custom Result type thrown by this crate.