### Local Development Setup Source: https://github.com/cocool97/adb_client/blob/main/pyadb_client/README.md Commands for setting up a local development environment, including creating a virtual environment, installing build dependencies, and building the package. ```bash # Create Python virtual environment python3 -m venv .venv source .venv/bin/activate # Install needed build dependencies pip install maturin # Build development package maturin develop # Build stub file (.pyi) cargo run --bin stub_gen # Build release Python package maturin build --release -m pyadb_client/Cargo.toml ``` -------------------------------- ### Install pyadb_client Source: https://github.com/cocool97/adb_client/blob/main/pyadb_client/README.md Install the library using pip. ```bash pip install pyadb_client ``` -------------------------------- ### start Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Starts an instance of the ADB server process locally. This is automatically called when connecting to local server instances. ```APIDOC ## start ### Description Starts an instance of the ADB server process locally. Automatically called when connecting to local server instances. ### Method `POST` (Conceptual) ### Endpoint `/start` (Conceptual) ### Parameters #### Path Parameters (none) #### Query Parameters (none) #### Request Body - **envs** (`HashMap`) - Environment variables to pass to the adb process - **adb_path** (`Option`) - Path to adb binary, or `None` to use PATH ### Request Example ```json { "envs": { "ADB_MDNS_OPENSCREEN": "1" }, "adb_path": "/usr/bin/adb" } ``` ### Response #### Success Response (200) - **(void)** ### Example ```rust use std::collections::HashMap; let mut envs = HashMap::new(); envs.insert("ADB_MDNS_OPENSCREEN".to_string(), "1".to_string()); ADBServer::start(&envs, &Some("/usr/bin/adb".to_string())); ``` ``` -------------------------------- ### Install adb_cli Source: https://github.com/cocool97/adb_client/blob/main/adb_cli/README.md Install the adb_cli Rust binary using Cargo. Ensure you have Rust and Cargo installed. ```shell cargo install adb_cli ``` -------------------------------- ### install Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Installs an APK on the device. Supports specifying a user for multi-user devices. ```APIDOC ## install ### Description Installs an APK on the device. Supports specifying a user for multi-user devices. ### Method Rust (method call) ### Parameters #### Path Parameters - **apk_path** (`&dyn AsRef`) - Required - Local .apk file path - **user** (`Option<&str>`) - Optional - Optional user ID for multi-user devices ### Response #### Success Response - `Result<()>` — success or error #### Error Handling - `RustADBError::WrongFileExtension`: File is not .apk - `RustADBError::IOError`: File not found ### Request Example ```rust device.install(&Path::new("app.apk"), None)?; // For multi-user device: device.install(&Path::new("app.apk"), Some("10"))?; ``` ``` -------------------------------- ### Minimal ADB Server Example Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/INDEX.md Connects to the ADB server, retrieves a device, and executes a shell command. ```rust use adb_client::server::ADBServer; use adb_client::server_device::ADBServerDevice; use std::net::{SocketAddrV4, Ipv4Addr}; fn main() -> adb_client::Result<()> { let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); let device = server.get_device()?; let mut dev = ADBServerDevice::new(device.identifier, None); let mut out = Vec::new(); dev.shell_command(&"id", Some(&mut out), None)?; println!("{}", String::from_utf8_lossy(&out)); Ok(()) } ``` -------------------------------- ### Start ADB Server Instance Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Starts a local ADB server process. Useful for setting custom environment variables for the ADB process. Ensure the ADB binary path is correctly specified or `None` to use the system's PATH. ```rust use std::collections::HashMap; let mut envs = HashMap::new(); envs.insert("ADB_MDNS_OPENSCREEN".to_string(), "1".to_string()); ADBServer::start(&envs, &Some("/usr/bin/adb".to_string())); ``` -------------------------------- ### Install USB Support on Ubuntu Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Install necessary development headers and configure user permissions for USB device access on Ubuntu systems when using the USB feature. ```bash sudo apt-get install libusb-1.0-0-dev sudo usermod -a -G plugdev $USER # For device access ``` -------------------------------- ### Configuration and Setup Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Explains how to configure and set up the ADB Client library, including feature gates, private key paths, server addresses, and environment settings. ```APIDOC ## configuration-and-setup.md ### Description Details on configuring and setting up the ADB Client library. ### Configuration Options - Feature gates - Private key paths - Server addresses - Environment setup - Logging - MSRV ``` -------------------------------- ### TCP ADB Device Example Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/INDEX.md Connects to an ADB device over TCP and executes a shell command to get system information. ```rust use adb_client::message_devices::tcp::ADBTcpDevice; use adb_client::ADBDeviceExt; fn main() -> adb_client::Result<()> { let mut device = ADBTcpDevice::new("192.168.1.100:5555")?; let mut output = Vec::new(); device.shell_command(&"uname -a", Some(&mut output), None)?; println!("{}", String::from_utf8_lossy(&output)); Ok(()) } ``` -------------------------------- ### Install APK Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Installs an APK file onto the connected Android device. Ensure the APK path is correct and the device is accessible. ```rust use adb_client::server_device::ADBServerDevice; use adb_client::ADBDeviceExt; use std::path::Path; fn install_app() -> adb_client::Result<()> { let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); device.install(&Path::new("app.apk"), None)?; println!("APK installed"); Ok(()) } ``` -------------------------------- ### Install APK on Device Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Installs an Android application package (APK) from a given path onto the device. Optionally specify a user ID to install for a specific user. ```rust pub fn install(&mut self, apk_path: &dyn AsRef, user: Option<&str>) -> Result<()> ``` -------------------------------- ### Install APK on Device Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server-device.md Installs an APK file onto the Android device. Ensure the provided path points to a valid .apk file and handle potential errors like incorrect file extensions or installation rejections. ```rust use std::path::Path; let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); device.install(&Path::new("app.apk"), None)?; ``` -------------------------------- ### Configure ADB Server with Environment Variables Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Start the ADB server using a HashMap of environment variables to control its behavior, such as forcing a specific backend or setting a custom server port. ```rust use std::collections::HashMap; let mut envs = HashMap::new(); // Force mDNS backend envs.insert("ADB_MDNS_OPENSCREEN".to_string(), "1".to_string()); // Custom server port envs.insert("ANDROID_ADB_SERVER_PORT".to_string(), "5038".to_string()); ADBServer::start(&envs, &None); ``` -------------------------------- ### Package Management Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Install and uninstall applications on the device. ```APIDOC ## Package Management ### `install` #### Description Install an APK file on the device. #### Method Not applicable (SDK method) #### Parameters - `apk_path` (&dyn AsRef) - Required - The path to the APK file. - `user` (Option<&str>) - Optional - The target user ID. ### `uninstall` #### Description Uninstall a package from the device. #### Method Not applicable (SDK method) #### Parameters - `package` (&dyn AsRef) - Required - The package name to uninstall. - `user` (Option<&str>) - Optional - The target user ID. ``` -------------------------------- ### Get First Available Device Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves the first connected device, assuming only one is present. This is a convenient method for single-device setups and can fail if no devices are connected or if there's a connection issue. ```rust let device = server.get_device()?; // Now use device for operations ``` -------------------------------- ### ADBDeviceExt Trait - Package Management (Install) Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Installs an application package on the device using the ADBDeviceExt trait. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; device.install("app-release.apk").await?; ``` -------------------------------- ### Get Available ADB Devices Source: https://github.com/cocool97/adb_client/blob/main/adb_client/src/server/README.md Connect to a custom ADB server address and retrieve a list of available devices. Ensure the ADB server is running. ```rust use adb_client::server::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(); ``` -------------------------------- ### USBDeviceNotFound Example and Definition (feature: usb) Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/errors.md Handles cases where a USB device with the specified vendor and product ID is not found. The example demonstrates how to match this specific error. ```rust #[error("USB Device not found: {0} {1}")] USBDeviceNotFound(u16, u16) ``` ```rust #[cfg(feature = "usb")] match ADBUSBDevice::new(0x18d1, 0x4e42) { Err(RustADBError::USBDeviceNotFound(vid, pid)) => { eprintln!("Device not found: {:04x}:{:04x}", vid, pid); }, Ok(device) => {}, Err(e) => eprintln!("{}", e), } ``` -------------------------------- ### Comprehensive Import Pattern Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/module-structure.md An example of importing all available types and modules, including server, TCP, emulator devices, models, and feature-gated mDNS and USB components. This is useful for projects requiring broad access to the library's functionality. ```rust use adb_client::{ server::ADBServer, server_device::ADBServerDevice, message_devices::tcp::ADBTcpDevice, emulator::ADBEmulatorDevice, models::*, ADBDeviceExt, Result, RustADBError, }; #[cfg(feature = "mdns")] use adb_client::mdns::MDNSDiscoveryService; #[cfg(feature = "usb")] use adb_client::message_devices::usb::ADBUSBDevice; ``` -------------------------------- ### shell Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Starts an interactive shell session with bidirectional I/O, typically connecting stdin to the device's shell and stdout/stderr back to the host. ```APIDOC ## shell ### Description Starts an interactive shell session with bidirectional I/O. ### Method `shell` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **reader** (`&mut dyn Read`) - Required - Input stream (typically stdin) - **writer** (`Box`) - Required - Output stream (typically stdout) ### Response #### Success Response - `Result<()>` — success or error ### Request Example ```rust use std::io::{stdin, stdout}; device.shell(&mut stdin(), Box::new(stdout()))?; ``` ``` -------------------------------- ### Run Activity and Get Output Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Launches a specific activity within a given package on the Android device and captures its output. The activity name should not include the package prefix. ```rust fn run_activity( &mut self, package: &dyn AsRef, activity: &dyn AsRef, ) -> Result> ``` ```rust let output = device.run_activity(&"com.example.app", &"MainActivity")?; println!("Activity output: {}", String::from_utf8_lossy(&output)); ``` -------------------------------- ### Framebuffer Capture Example Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Captures a screenshot from the device's framebuffer. Requires the 'framebuffer' feature. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; let frame = device.framebuffer().await?; let image = frame.to_image(); image.save("screenshot.png").expect("Failed to save screenshot"); ``` -------------------------------- ### Connect and Execute Shell Command Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Connect to the ADB server, get the first available device, and execute a shell command to retrieve its Android API level. Ensure the ADB server is running and a device is connected. ```rust use adb_client::server::{ADBServer, DeviceState}; use adb_client::server_device::ADBServerDevice; use std::net::{SocketAddrV4, Ipv4Addr}; fn main() -> adb_client::Result<()> { // Create server connection let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); // Get first connected device let device = server.get_device()?; // Create device controller let mut dev = ADBServerDevice::new(device.identifier.clone(), None); // Run shell command let mut output = Vec::new(); dev.shell_command( &"getprop ro.build.version.sdk", Some(&mut output), None, )?; println!("Android API Level: {}", String::from_utf8_lossy(&output)); Ok(()) } ``` -------------------------------- ### Install APK on Android Device Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Installs an APK file onto the connected Android device. Supports specifying a user ID for multi-user devices. Ensure the file has a .apk extension to avoid errors. ```rust fn install(&mut self, apk_path: &dyn AsRef, user: Option<&str>) -> Result<()> ``` ```rust device.install(&Path::new("app.apk"), None)?; // For multi-user device: device.install(&Path::new("app.apk"), Some("10"))?; ``` -------------------------------- ### Start Interactive Shell Session Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Initiates an interactive shell session with the device, allowing for continuous command input and output. Requires a reader for input and a writer for output. ```rust pub fn shell( &mut self, reader: &mut dyn Read, writer: Box ) -> Result<()> ``` -------------------------------- ### Reuse ADB Device Instance for Multiple Operations Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md This example shows how to reuse a single ADB device instance to perform multiple shell commands. Reusing the instance helps in maintaining the same connection for efficiency. ```rust // Reuse same device instance let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); device.shell_command(&"cmd1", None, None)?; device.shell_command(&"cmd2", None, None)?; // Both use same connection ``` -------------------------------- ### ADB Server Management Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Provides documentation for managing the ADB server, including connection, discovery, pairing, and server control operations like starting, killing, and checking the version. ```APIDOC ## adb-server.md ### Description Documentation for managing the ADB server, including connection, discovery, pairing, and server control operations. ### Subsystems Covered - ADBServer (connection, discovery, pairing) - Device lists (short, long) - Device state management - Server control (start, kill, version) - mDNS backend management ``` -------------------------------- ### Test ADB Device Connection Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md This snippet demonstrates how to test a connection to an ADB device within a test environment. It includes starting the ADB server and verifying the connection by checking the server version. ```rust #[cfg(test)] mod tests { use adb_client::server::ADBServer; use std::net::{SocketAddrV4, Ipv4Addr}; #[test] fn test_device_connection() { let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); // Start server if not running ADBServer::start(&std::collections::HashMap::new(), &None); // Allow time for startup std::thread::sleep(std::time::Duration::from_millis(500)); // Test connection assert!(server.version().is_ok()); } } ``` -------------------------------- ### shell Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server-device.md Starts an interactive shell session. Input is read from the provided reader and output is written to the provided writer. ```APIDOC ## shell ### Description Starts an interactive shell session. Input is read from the provided reader and output is written to the provided writer. ### Method `shell` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **reader** (`&mut dyn Read`) - Required - Input stream (typically stdin) - **writer** (`Box`) - Required - Output stream (typically stdout) ### Response #### Success Response - `Result<()>` — success or error ### Throws - `RustADBError::IOError` - Connection or I/O error ### Example ```rust use std::io::{stdin, stdout}; let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); let mut input = stdin(); let output = Box::new(stdout()); device.shell(&mut input, output)?; ``` ``` -------------------------------- ### Pattern Matching on ADB Error Types Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Illustrates how to pattern match on specific `RustADBError` variants for more granular error handling during ADB operations like installation. ```rust use adb_client::{RustADBError, server_device::ADBServerDevice, ADBDeviceExt}; fn install_with_error_handling() { let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); match device.install(&std::path::Path::new("app.apk"), None) { Ok(_) => println!("Installation successful"), Err(RustADBError::WrongFileExtension(ext)) => { eprintln!("Wrong file type: {}", ext); } Err(RustADBError::ADBRequestFailed(msg)) => { eprintln!("Installation rejected: {}", msg); } Err(e) => eprintln!("Error: {}", e), } } ``` -------------------------------- ### Get Shell from Device (Rust) Source: https://github.com/cocool97/adb_client/blob/main/adb_client/src/message_devices/tcp/README.md Connects to an ADB device via TCP and obtains a shell. Ensure the device is accessible at the specified IP address and port. ```rust use std::net::{SocketAddr, IpAddr, Ipv4Addr}; use adb_client::{tcp::ADBTcpDevice, ADBDeviceExt}; let mut device = ADBTcpDevice::new((IpAddr::from([192, 168, 0, 10]), 43210)).expect("cannot find device"); device.shell(&mut std::io::stdin(), Box::new(std::io::stdout())); ``` -------------------------------- ### Run Commands in Sequence Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Execute a series of shell commands on a device sequentially. Useful for automating multi-step operations like getting device info and clearing app data. ```rust use adb_client::server_device::ADBServerDevice; use adb_client::ADBDeviceExt; fn sequence_of_commands() -> adb_client::Result<()> { let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); // Command 1: Get device info let mut info = Vec::new(); device.shell_command(&"getprop ro.product.model", Some(&mut info), None)?; println!("Model: {}", String::from_utf8_lossy(&info)); // Command 2: Get SDK version let mut sdk = Vec::new(); device.shell_command(&"getprop ro.build.version.sdk", Some(&mut sdk), None)?; println!("SDK: {}", String::from_utf8_lossy(&sdk)); // Command 3: Clear app data device.shell_command(&"pm clear com.example.app", None, None)?; println!("App data cleared"); Ok(()) } ``` -------------------------------- ### ADB Server Constructors Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Demonstrates the creation of ADBServer instances. Two constructors are available. ```Rust let server = ADBServer::new(); let server_with_addr = ADBServer::new_with_addr(std::net::SocketAddr::from(([127, 0, 0, 1], 5037))); ``` -------------------------------- ### ADB Server Connection Methods Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Illustrates various methods for connecting to an ADB server. Eight connection methods are provided. ```Rust let server = ADBServer::new(); let devices = server.device_list().await?; let device = server.device("emulator-5554").await?; ``` -------------------------------- ### Instantiate ADBServer with Custom Path Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Use this constructor to create a new ADBServer instance with a specified path to the ADB binary. This is useful when the ADB binary is not in the system's PATH. ```rust use std::net::{SocketAddrV4, Ipv4Addr}; use adb_client::server::ADBServer; let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let server = ADBServer::new_from_path( addr, Some("/custom/path/to/adb".to_string()) ); ``` -------------------------------- ### Rust WrongFileExtension Error Handling Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/errors.md Handles errors when a file with an incorrect extension is provided for installation, such as attempting to install a non-APK file. ```rust #[error("wrong file extension: {0}")] WrongFileExtension(String) ``` ```rust match device.install(&Path::new("file.txt"), None) { Err(RustADBError::WrongFileExtension(ext)) => eprintln!("Not an APK: {}", ext), Ok(_) => println!("Installed"), Err(e) => eprintln!("{}", e), } ``` -------------------------------- ### ADBServerDevice Constructors Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Illustrates the creation of ADBServerDevice instances. Three constructors are available. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; let device_by_addr = server.device_with_addr(std::net::SocketAddr::from(([127, 0, 0, 1], 5554))).await?; ``` -------------------------------- ### run_activity Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Launches an activity in a package and returns the command output. ```APIDOC ## run_activity ### Description Launches an activity in a package and returns the command output. ### Method Rust (method call) ### Parameters #### Path Parameters - **package** (`dyn AsRef`) - Required - Package name - **activity** (`dyn AsRef`) - Required - Activity name (without package prefix) ### Response #### Success Response - `Result>` — command output bytes ### Request Example ```rust let output = device.run_activity(&"com.example.app", &"MainActivity")?; println!("Activity output: {}", String::from_utf8_lossy(&output)); ``` ``` -------------------------------- ### Basic ADB Command Execution Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/errors.md Demonstrates basic execution of an ADB shell command and handling potential errors using `Result`. Imports `ADBServerDevice`, `Result`, and `RustADBError`. ```rust use adb_client::{server_device::ADBServerDevice, Result, RustADBError}; fn execute_command() -> Result<()> { let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); device.shell_command(&"ls -la", None, None)?; Ok(()) } // Usage if let Err(e) = execute_command() { eprintln!("Error: {}", e); } ``` -------------------------------- ### adb_cli USB Command Help Source: https://github.com/cocool97/adb_client/blob/main/adb_cli/README.md View help for adb_cli commands when interacting directly with devices via USB, without needing an ADB server. Requires specifying vendor and product IDs. ```bash user@laptop ~/adb_client (main)> adb_cli usb --help Device commands via USB, no server needed Usage: adb_cli usb [OPTIONS] --vendor-id --product-id Commands: shell Spawn an interactive shell or run a list of commands on the device pull Pull a file from device push Push a file on device stat Stat a file on device reboot Reboot the device help Print this message or the help of the given subcommand(s) Options: -v, --vendor-id Hexadecimal vendor id of this USB device -p, --product-id Hexadecimal product id of this USB device -k, --private-key Path to a custom private key to use for authentication -h, --help Print help ``` -------------------------------- ### adb_cli Local Command Help Source: https://github.com/cocool97/adb_client/blob/main/adb_cli/README.md View help for adb_cli commands when using the ADB server as a proxy. This is the default mode. ```bash user@laptop ~/adb_client (main)> adb_cli local --help Device related commands using server Usage: adb_cli local [OPTIONS] Commands: shell Spawn an interactive shell or run a list of commands on the device pull Pull a file from device push Push a file on device stat Stat a file on device run Run an activity on device specified by the intent reboot Reboot the device install Install an APK on device framebuffer Dump framebuffer of device host-features List available server features list List a directory on device logcat Get logs of device help Print this message or the help of the given subcommand(s) Options: -a, --address
[default: 127.0.0.1:5037] -s, --serial Serial id of a specific device. Every request will be sent to this device -h, --help Print help ``` -------------------------------- ### Get Product ID of ADBUSBDevice Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Retrieves the USB product ID of the connected device. ```rust pub const fn product_id(&self) -> u16 ``` -------------------------------- ### Get Vendor ID of ADBUSBDevice Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Retrieves the USB vendor ID of the connected device. ```rust pub const fn vendor_id(&self) -> u16 ``` -------------------------------- ### Instantiate MDNSDiscoveryService Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/emulator-and-mdns.md Creates a new instance of the mDNS discovery service. Requires the 'mdns' feature to be enabled. Ensure mDNS initialization does not fail. ```rust #[cfg(feature = "mdns")] { use adb_client::mdns::MDNSDiscoveryService; let discovery = MDNSDiscoveryService::new()?; } ``` -------------------------------- ### Advanced Pattern: File Push and Execute Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Pushes a script to the device and then executes it. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; let script_content = b"#!/system/bin/sh\necho 'Hello from device!'\n"; device.push(script_content.to_vec(), "/data/local/tmp/myscript.sh").await?; device.shell("chmod +x /data/local/tmp/myscript.sh").await?; let output = device.shell("/data/local/tmp/myscript.sh").await?; println!("Script output: {}", output); ``` -------------------------------- ### Instantiate ADBServer with Default Path Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Use this constructor to create a new ADBServer instance connected to a specific socket address. It utilizes the system's default ADB binary path. ```rust use std::net::{SocketAddrV4, Ipv4Addr}; use adb_client::server::ADBServer; let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); ``` -------------------------------- ### Update Rust Toolchain Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Update your Rust installation to the latest stable version if it is older than the minimum supported Rust version. ```bash rustup update stable ``` -------------------------------- ### Get File Information Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Retrieves file status information (mode, size, modification time) for a given path on the device. ```rust use adb_client::server_device::ADBServerDevice; use adb_client::ADBDeviceExt; fn get_file_stat() -> adb_client::Result<()> { let mut device = ADBServerDevice::new("emulator-5554".to_string(), None); let stat = device.stat(&"/system")?; println!("Mode: {:o}", stat.mode); println!("Size: {}", stat.size); println!("Modified: {}", stat.mtime); Ok(()) } ``` -------------------------------- ### ADBServerDevice Shell Commands Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Shows how to execute shell commands on a device. Three methods are available for shell command execution. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; let output = device.shell("ls -l /sdcard").await?; println!("Shell output: {}", output); ``` -------------------------------- ### pair Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Pairs with a device over Wi-Fi using a provided pairing code. This is typically used for initial setup or re-authentication of a device. ```APIDOC ## pair ### Description Pairs with a device over Wi-Fi using a pairing code. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **address** (`SocketAddrV4`) - Required - Device address - **code** (`String`) - Required - Pairing code (usually 6 digits) ### Request Example ```rust let device_addr = SocketAddrV4::new(Ipv4Addr::new(192, 168, 1, 100), 5555); server.pair(device_addr, "123456".to_string())?; ``` ### Response #### Success Response (200) `()` - Indicates successful pairing. #### Response Example ```rust // No explicit response body for success, indicates success by returning Ok(()) ``` ### Error Handling - `RustADBError::ADBRequestFailed`: Pairing code invalid or device rejected. - `RustADBError::IOError`: Network error. ``` -------------------------------- ### Programmatic Logging Configuration Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Initialize the logging system programmatically. Use `env_logger::init()` for simple cases or configure other logging backends as needed. ```rust // Using env_logger env_logger::init(); // Using other logging implementations // Configure as you normally would with your chosen logging backend ``` -------------------------------- ### ADBServer::new_from_path Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Instantiates a new ADBServer with a custom ADB binary path. This allows specifying a non-standard location for the ADB executable. ```APIDOC ## ADBServer::new_from_path ### Description Instantiates a new `ADBServer` with a custom ADB binary path. This is useful when the ADB executable is not in the system's PATH. ### Method Rust constructor ### Parameters #### Path Parameters - **address** (`SocketAddrV4`) - Required - Server address in IPv4 socket format - **adb_path** (`Option`) - Optional - Path to adb binary. If `None`, uses `adb` from system PATH ### Returns - `ADBServer` - new server instance ### Example ```rust use std::net::{SocketAddrV4, Ipv4Addr}; use adb_client::server::ADBServer; let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let server = ADBServer::new_from_path( addr, Some("/custom/path/to/adb".to_string()) ); ``` ``` -------------------------------- ### Get ADB Server Socket Address Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves the configured socket address of the ADB server. Use this to determine where the server is listening. ```rust if let Some(addr) = server.socket_addr() { println!("Server at {}", addr); } ``` -------------------------------- ### Implement ADB Device Connection Pooling Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Demonstrates how to create a reusable pool of ADB devices to execute commands efficiently. This pattern is useful when performing multiple operations on the same device. ```rust use adb_client::server_device::ADBServerDevice; use adb_client::ADBDeviceExt; struct DevicePool { device: ADBServerDevice, } impl DevicePool { fn new(identifier: String) -> Self { Self { device: ADBServerDevice::new(identifier, None), } } fn execute_command(&mut self, cmd: &str) -> adb_client::Result { let mut output = Vec::new(); self.device.shell_command(&cmd, Some(&mut output), None)?; Ok(String::from_utf8(output)?) } } fn use_pool() -> adb_client::Result<()> { let mut pool = DevicePool::new("emulator-5554".to_string()); let result1 = pool.execute_command("id")?; let result2 = pool.execute_command("pwd")?; println!("ID: {}", result1); println!("PWD: {}", result2); Ok(()) } ``` -------------------------------- ### Check Rust Version Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Verify the currently installed Rust compiler version. Ensure it meets the minimum supported Rust version (MSRV) requirement. ```bash rustc --version ``` -------------------------------- ### ADBServerDevice Package Management Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Illustrates package management operations on a device. Two methods are available. ```Rust let server = ADBServer::new(); let device = server.device("emulator-5554").await?; device.install("app.apk").await?; device.uninstall("com.example.app").await?; ``` -------------------------------- ### Get ADB Server Version Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves the ADB server version information. Use this to check compatibility or gather details about the running ADB server. ```rust pub fn version(&mut self) -> Result let version = server.version()?; println!("ADB version: {}", version); ``` -------------------------------- ### Instantiate ADBEmulatorDevice Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/emulator-and-mdns.md Use this constructor to create a new emulator device instance. Provide the emulator's ADB identifier and optionally its IP address. ```rust use adb_client::emulator::ADBEmulatorDevice; use std::net::Ipv4Addr; let emulator = ADBEmulatorDevice::new( "emulator-5554".to_string(), Some(Ipv4Addr::LOCALHOST) )?; ``` -------------------------------- ### Instantiate TCP Device Connection with Custom Key Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md This constructor allows establishing a TCP connection to a device while specifying a custom RSA private key for authentication. Provide the device address and the file path to your private key. ```rust let device = ADBTcpDevice::new_with_custom_private_key( "192.168.1.100:5555", "/home/user/.android/my_custom_key" )?; ``` -------------------------------- ### Import Models from Module Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/module-structure.md Demonstrates importing specific models directly from the 'models' module. ```rust use adb_client::models::{ADBListItem, RebootType}; ``` -------------------------------- ### Instantiate ADBServerDevice by Autodetect Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server-device.md Creates a new ADBServerDevice instance by automatically selecting the first available device. This is convenient for scenarios with only one connected device. An optional custom ADB server address can be provided. ```rust let device = ADBServerDevice::autodetect(None); ``` -------------------------------- ### Get File Stat Information Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Retrieves file mode, size, and modification time using the STAT protocol command. Use this for basic file metadata retrieval. ```rust let stat = device.stat(&"/system")?; println!("Size: {}, Mode: {:o}", stat.size, stat.mode); ``` -------------------------------- ### Get Extended Device Information Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/quick-start.md Retrieve detailed information for all connected devices, including model, product, and transport ID. This provides a more comprehensive view of connected devices. ```rust fn get_device_info() -> adb_client::Result<()> { let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); for device in server.devices_long()? { println!("Identifier: {}", device.identifier); println!("State: {}", device.state); println!("Model: {}", device.model); println!("Product: {}", device.product); println!("Transport ID: {}", device.transport_id); println!("---"); } Ok(()) } ``` -------------------------------- ### Create ADB Device with Custom Private Key Path Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/configuration-and-setup.md Instantiate an ADB TCP device, providing a custom path to the private key file. This is useful when the default key location is not used or accessible. ```rust use adb_client::message_devices::tcp::ADBTcpDevice; let device = ADBTcpDevice::new_with_custom_private_key( "192.168.1.100:5555", "/home/user/.config/adb/custom_key" )?; ``` -------------------------------- ### Get ADB Server Status Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves the current ADB server status, including mDNS backend information. Useful for monitoring the server's operational state. ```rust pub fn server_status(&mut self) -> Result let status = server.server_status()?; println!("mDNS backend: {:?}", status.mdns_backend); ``` -------------------------------- ### ADB Server Device Discovery Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Shows how to discover connected ADB devices. Three methods are available for device discovery. ```Rust let server = ADBServer::new(); let devices = server.device_list().await?; println!("Found devices: {:?}", devices); ``` -------------------------------- ### Get File Stat Information Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Retrieves detailed file status information (like size, modification time, permissions) for a given remote path. Returns an AdbStatResponse struct. ```rust pub fn stat(&mut self, remote_path: &dyn AsRef) -> Result ``` -------------------------------- ### Get Extended File Stat Information Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md Retrieves detailed file information using the shell 'stat' command. Returns an Option containing detailed stat data or None if the file is not found. ```rust if let Some(stat) = device.stat_extended(&"/data")? { println!("Inode: {}", stat.inode); println!("UID: {}", stat.uid); } ``` -------------------------------- ### Common Device Operations (Shell Command) Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Shows how to execute a shell command on a connected device. ```Rust let device = ADBTcpDevice::new("127.0.0.1:5555").await?; let output = device.shell("getprop ro.product.model").await?; println!("Device model: {}", output); ``` -------------------------------- ### Instantiate ADBUSBDevice by Vendor and Product ID Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Use this constructor to connect to a specific USB device when its vendor and product IDs are known. Ensure the 'usb' feature is enabled. ```rust #[cfg(feature = "usb")] { use adb_client::message_devices::usb::ADBUSBDevice; // Google Nexus devices typically use vendor_id 0x18d1 let device = ADBUSBDevice::new(0x18d1, 0x4e42)?; } ``` -------------------------------- ### Get Framebuffer as PNG Bytes Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Retrieves the device's framebuffer as a PNG byte vector. This is useful for programmatic access to the screen content without saving to a file. Requires the 'framebuffer' feature. ```rust #[cfg(feature = "framebuffer")] pub fn framebuffer_bytes(&mut self) -> Result> ``` -------------------------------- ### Discover and Connect to an ADB Device Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/emulator-and-mdns.md This Rust function demonstrates how to discover ADB devices on the network using mDNS, connect to the first discovered device, and execute a shell command to retrieve its Android API level. Ensure the `mdns` feature is enabled. ```rust #[cfg(feature = "mdns")] fn discover_and_connect() -> Result<()> { use adb_client::mdns::MDNSDiscoveryService; use adb_client::message_devices::tcp::ADBTcpDevice; // Discover devices on network let discovery = MDNSDiscoveryService::new()?; let devices = discovery.discover_devices()?; if let Some(device) = devices.first() { // Connect to first discovered device let socket = format!( "{}:{}", device.address, device.port); let mut tcp_device = ADBTcpDevice::new(&socket)?; // Execute command let mut stdout = Vec::new(); tcp_device.shell_command(&"getprop ro.build.version.sdk", Some(&mut stdout), None)?; println!( "Android API Level: {}", String::from_utf8_lossy(&stdout)); } Ok(()) } ``` -------------------------------- ### Instantiate ADBServerDevice by Identifier Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server-device.md Creates a new ADBServerDevice instance using a device serial number. Optionally specify a custom ADB server address; otherwise, the default (127.0.0.1:5037) is used. ```rust use adb_client::server_device::ADBServerDevice; let device = ADBServerDevice::new( "emulator-5554".to_string(), None ); ``` -------------------------------- ### Get Raw Framebuffer Image Buffer Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/traits-and-interfaces.md An internal method that returns the raw framebuffer data as an RGBA image buffer. This provides direct access to the pixel data. Ensure the 'framebuffer' feature is enabled. ```rust #[cfg(feature = "framebuffer")] fn framebuffer_inner(&mut self) -> Result, Vec>> ``` -------------------------------- ### ADB Server mDNS Operations Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Demonstrates mDNS operations for ADB server discovery. Three methods are provided. ```Rust let mdns_service = MDNSDiscoveryService::new().await?; let devices = mdns_service.discover_devices().await?; println!("mDNS discovered devices: {:?}", devices); ``` -------------------------------- ### Get Device by Identifier Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves a specific ADB device using its unique identifier (serial number). This is useful when multiple devices are connected and you need to target a particular one. It throws `DeviceNotFound` if the identifier does not match any connected device. ```rust let device = server.get_device_by_identifier("emulator-5554")?; ``` -------------------------------- ### Server Module Export Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/module-structure.md This snippet shows how to import types for ADB server management and device discovery. It includes the main ADBServer type and basic device information structures. ```rust pub mod server ``` ```rust use adb_client::server::{ADBServer, DeviceShort}; ``` -------------------------------- ### Push a file to a device Source: https://github.com/cocool97/adb_client/blob/main/pyadb_client/README.md Autodetect a USB device and push a local file to a specified path on the device. ```python from pyadb_client import PyADBUSBDevice usb_device = PyADBUSBDevice.autodetect() usb_device.push("file.txt", "/data/local/tmp/file.txt") ``` -------------------------------- ### Minimal Import for Server Only Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/module-structure.md A minimal import pattern for projects that only interact with the ADB server directly, without needing device-specific transports. ```rust use adb_client::{server::ADBServer, server_device::ADBServerDevice}; ``` -------------------------------- ### ADBEmulatorDevice API - Emulator Commands Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Demonstrates control commands specific to ADBEmulatorDevice. Four commands are available. ```Rust let server = ADBServer::new(); let emulator = server.emulator("emulator-5554").await?; emulator.avd_name().await?; emulator.avd_path().await?; ``` -------------------------------- ### Direct Device Connections Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Documentation for establishing direct connections to devices via TCP and USB, covering the ADBTcpDevice and ADBUSBDevice APIs, and common device operations. ```APIDOC ## Direct Device Connections ### Description Provides APIs for establishing direct connections to Android devices using TCP/IP or USB. This section details the `ADBTcpDevice` and `ADBUSBDevice` interfaces, along with common operations applicable to both connection types. ### APIs - **ADBTcpDevice API**: Complete documentation for connecting and interacting with devices over TCP. - **ADBUSBDevice API**: Complete documentation for connecting and interacting with devices over USB. ### Common Device Operations - **8 categories** of common operations are supported across direct connections, including file transfer, shell execution, and device information retrieval. ``` -------------------------------- ### ADBServer::new Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Instantiates a new ADBServer instance connected to a specific socket address. This constructor initializes the server with a lazy-initialized transport. ```APIDOC ## ADBServer::new ### Description Instantiates a new `ADBServer` instance connected to a specific socket address. It handles connection management, device discovery, and device pairing over TCP/IP networks. ### Method Rust constructor ### Parameters #### Path Parameters - **address** (`SocketAddrV4`) - Required - Server address in IPv4 socket format (e.g., 127.0.0.1:5037) ### Returns - `ADBServer` - new server instance with lazy-initialized transport ### Example ```rust use std::net::{SocketAddrV4, Ipv4Addr}; use adb_client::server::ADBServer; let addr = SocketAddrV4::new(Ipv4Addr::LOCALHOST, 5037); let mut server = ADBServer::new(addr); ``` ``` -------------------------------- ### ADB Server Management Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/MANIFEST.txt Documentation for managing the ADB server, including constructors, connection methods, device discovery, network operations, server control, and mDNS operations. ```APIDOC ## ADB Server Management ### Description Provides methods for constructing and managing the ADB server instance, establishing connections, discovering devices, performing network operations, controlling the server state, and utilizing mDNS for discovery. ### Methods - **Constructors**: 2 methods for creating an ADBServer instance. - **Connection Methods**: 8 methods for establishing and managing connections. - **Device Discovery**: 3 methods for discovering connected devices. - **Network Operations**: 3 methods for network-related tasks. - **Server Control**: 3 methods for controlling the ADB server. - **mDNS Operations**: 3 methods for mDNS-related functionalities. ``` -------------------------------- ### Instantiate ADBUSBDevice with Custom Private Key Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/direct-device-connections.md Connect to a USB device using a custom private key file for authentication. This is useful for specific security configurations. ```rust let device = ADBUSBDevice::new_with_custom_private_key( 0x18d1, 0x4e42, "/custom/path/to/key" )?; ``` -------------------------------- ### version Source: https://github.com/cocool97/adb_client/blob/main/_autodocs/adb-server.md Retrieves the ADB server version information. ```APIDOC ## version ### Description Retrieves the ADB server version information. ### Method (Not specified, likely a method call on an ADB client object) ### Endpoint (Not applicable, SDK method) ### Parameters (none) ### Returns `Result` — version details ### Example ```rust let version = server.version()?; println!("ADB version: {}", version); ``` ```