12 Commits

Author SHA1 Message Date
LIAUD Corentin
34d5811420 chore: version 2.1.16 2025-08-03 17:32:50 +02:00
LIAUD Corentin
86e28a6e25 chore: add msrv badges 2025-08-03 17:31:24 +02:00
LIAUD Corentin
9f113bdb93 chore: add msrv + fix clippy lints 2025-08-03 17:27:54 +02:00
cocool97
8670d6db58 fix: use random adb key if not existing (#130) 2025-08-03 17:08:15 +02:00
LIAUD Corentin
0732a0bbad chore: v2.1.15 2025-07-27 20:20:57 +02:00
cocool97
b5673001ca feat: make search_adb_devices and is_adb_device public (#129) 2025-07-27 20:19:03 +02:00
LIAUD Corentin
81829c1523 chore: v2.1.14 2025-07-07 08:21:22 +02:00
LIAUD Corentin
b9d2b8374f dep(homedir): fix to 0.3.4 to fix windows build 2025-07-06 20:00:24 +02:00
LIAUD Corentin
5716784f5d deps(homedir): fix version 0.3.5 because of hard rust 1.88 dep 2025-07-06 19:42:15 +02:00
LIAUD Corentin
b6ddc720d8 chore(clippy): run linter 2025-07-06 19:41:58 +02:00
Sashanoraa
5438e53361 Support devices that don't do auth (#124) 2025-07-06 19:34:34 +02:00
cocool97
39a7f0a8cf chore: bump criterion + pyo3 (#122) 2025-05-24 14:56:34 +02:00
28 changed files with 88 additions and 76 deletions

View File

@@ -9,7 +9,8 @@ homepage = "https://github.com/cocool97/adb_client"
keywords = ["adb", "android", "tcp", "usb"] keywords = ["adb", "android", "tcp", "usb"]
license = "MIT" license = "MIT"
repository = "https://github.com/cocool97/adb_client" repository = "https://github.com/cocool97/adb_client"
version = "2.1.13" version = "2.1.16"
rust-version = "1.85.1"
# To build locally when working on a new release # To build locally when working on a new release
[patch.crates-io] [patch.crates-io]

View File

@@ -8,6 +8,9 @@
<a href="https://crates.io/crates/adb_client"> <a href="https://crates.io/crates/adb_client">
<img alt="crates.io" src="https://img.shields.io/crates/v/adb_client.svg"/> <img alt="crates.io" src="https://img.shields.io/crates/v/adb_client.svg"/>
</a> </a>
<a href="https://crates.io/crates/adb_client">
<img alt="msrv" src="https://img.shields.io/crates/msrv/adb_client/latest"/>
</a>
<a href="https://github.com/cocool97/adb_client/actions"> <a href="https://github.com/cocool97/adb_client/actions">
<img alt="ci status" src="https://github.com/cocool97/adb_client/actions/workflows/rust-build.yml/badge.svg"/> <img alt="ci status" src="https://github.com/cocool97/adb_client/actions/workflows/rust-build.yml/badge.svg"/>
</a> </a>

View File

@@ -7,6 +7,7 @@ license.workspace = true
name = "adb_cli" name = "adb_cli"
readme = "README.md" readme = "README.md"
repository.workspace = true repository.workspace = true
rust-version.workspace = true
version.workspace = true version.workspace = true
[dependencies] [dependencies]

View File

@@ -2,6 +2,7 @@
[![MIT licensed](https://img.shields.io/crates/l/adb_cli.svg)](./LICENSE-MIT) [![MIT licensed](https://img.shields.io/crates/l/adb_cli.svg)](./LICENSE-MIT)
![Crates.io Total Downloads](https://img.shields.io/crates/d/adb_cli) ![Crates.io Total Downloads](https://img.shields.io/crates/d/adb_cli)
![MSRV](https://img.shields.io/crates/msrv/adb_cli/latest)
Rust binary providing an improved version of `adb` CLI. Rust binary providing an improved version of `adb` CLI.
@@ -10,7 +11,7 @@ Rust binary providing an improved version of `adb` CLI.
This crate provides a lightweight binary based on the `adb_client` crate. You can install it by running the following command : This crate provides a lightweight binary based on the `adb_client` crate. You can install it by running the following command :
```shell ```shell
cargo install adb_cli cargo install adb_cli
``` ```
Usage is quite simple, and tends to look like `adb`: Usage is quite simple, and tends to look like `adb`:
@@ -64,4 +65,4 @@ Options:
-p, --product-id <PID> Hexadecimal product id of this USB device -p, --product-id <PID> Hexadecimal product id of this USB device
-k, --private-key <PATH_TO_PRIVATE_KEY> Path to a custom private key to use for authentication -k, --private-key <PATH_TO_PRIVATE_KEY> Path to a custom private key to use for authentication
-h, --help Print help -h, --help Print help
``` ```

View File

@@ -8,7 +8,7 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
match server_command.command { match server_command.command {
HostCommand::Version => { HostCommand::Version => {
let version = adb_server.version()?; let version = adb_server.version()?;
log::info!("Android Debug Bridge version {}", version); log::info!("Android Debug Bridge version {version}");
log::info!("Package version {}-rust", std::env!("CARGO_PKG_VERSION")); log::info!("Package version {}-rust", std::env!("CARGO_PKG_VERSION"));
} }
HostCommand::Kill => { HostCommand::Kill => {
@@ -18,18 +18,18 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
if long { if long {
log::info!("List of devices attached (extended)"); log::info!("List of devices attached (extended)");
for device in adb_server.devices_long()? { for device in adb_server.devices_long()? {
log::info!("{}", device); log::info!("{device}");
} }
} else { } else {
log::info!("List of devices attached"); log::info!("List of devices attached");
for device in adb_server.devices()? { for device in adb_server.devices()? {
log::info!("{}", device); log::info!("{device}");
} }
} }
} }
HostCommand::TrackDevices => { HostCommand::TrackDevices => {
let callback = |device: DeviceShort| { let callback = |device: DeviceShort| {
log::info!("{}", device); log::info!("{device}");
Ok(()) Ok(())
}; };
log::info!("Live list of devices attached"); log::info!("Live list of devices attached");
@@ -65,7 +65,7 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
MdnsCommand::Services => { MdnsCommand::Services => {
log::info!("List of discovered mdns services"); log::info!("List of discovered mdns services");
for service in adb_server.mdns_services()? { for service in adb_server.mdns_services()? {
log::info!("{}", service); log::info!("{service}");
} }
} }
}, },

View File

@@ -132,10 +132,10 @@ fn main() -> Result<()> {
} }
DeviceCommands::Stat { path } => { DeviceCommands::Stat { path } => {
let stat_response = device.stat(&path)?; let stat_response = device.stat(&path)?;
println!("{}", stat_response); println!("{stat_response}");
} }
DeviceCommands::Reboot { reboot_type } => { DeviceCommands::Reboot { reboot_type } => {
log::info!("Reboots device in mode {:?}", reboot_type); log::info!("Reboots device in mode {reboot_type:?}");
device.reboot(reboot_type.into())? device.reboot(reboot_type.into())?
} }
DeviceCommands::Push { filename, path } => { DeviceCommands::Push { filename, path } => {
@@ -152,7 +152,7 @@ fn main() -> Result<()> {
device.install(&path)?; device.install(&path)?;
} }
DeviceCommands::Uninstall { package } => { DeviceCommands::Uninstall { package } => {
log::info!("Uninstalling the package {}...", package); log::info!("Uninstalling the package {package}...");
device.uninstall(&package)?; device.uninstall(&package)?;
} }
DeviceCommands::Framebuffer { path } => { DeviceCommands::Framebuffer { path } => {

View File

@@ -7,6 +7,7 @@ license.workspace = true
name = "adb_client" name = "adb_client"
readme = "README.md" readme = "README.md"
repository.workspace = true repository.workspace = true
rust-version.workspace = true
version.workspace = true version.workspace = true
[dependencies] [dependencies]
@@ -14,7 +15,7 @@ base64 = { version = "0.22.1" }
bincode = { version = "1.3.3" } bincode = { version = "1.3.3" }
byteorder = { version = "1.5.0" } byteorder = { version = "1.5.0" }
chrono = { version = "0.4.40", default-features = false, features = ["std"] } chrono = { version = "0.4.40", default-features = false, features = ["std"] }
homedir = { version = "0.3.4" } homedir = { version = "= 0.3.4" }
image = { version = "0.25.5", default-features = false } image = { version = "0.25.5", default-features = false }
log = { version = "0.4.26" } log = { version = "0.4.26" }
mdns-sd = { version = "0.13.9", default-features = false, features = [ mdns-sd = { version = "0.13.9", default-features = false, features = [
@@ -40,7 +41,7 @@ thiserror = { version = "2.0.7" }
[dev-dependencies] [dev-dependencies]
anyhow = { version = "1.0.93" } anyhow = { version = "1.0.93" }
criterion = { version = "0.5.1" } # Used for benchmarks criterion = { version = "0.6.0" } # Used for benchmarks
[[bench]] [[bench]]
harness = false harness = false

View File

@@ -3,6 +3,7 @@
[![MIT licensed](https://img.shields.io/crates/l/adb_client.svg)](./LICENSE-MIT) [![MIT licensed](https://img.shields.io/crates/l/adb_client.svg)](./LICENSE-MIT)
[![Documentation](https://docs.rs/adb_client/badge.svg)](https://docs.rs/adb_client) [![Documentation](https://docs.rs/adb_client/badge.svg)](https://docs.rs/adb_client)
[![Crates.io Total Downloads](https://img.shields.io/crates/d/adb_client)](https://crates.io/crates/adb_client) [![Crates.io Total Downloads](https://img.shields.io/crates/d/adb_client)](https://crates.io/crates/adb_client)
![MSRV](https://img.shields.io/crates/msrv/adb_client/latest)
Rust library implementing ADB protocol. Rust library implementing ADB protocol.

View File

@@ -144,8 +144,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
MessageCommand::Write => return Ok(()), MessageCommand::Write => return Ok(()),
c => { c => {
return Err(RustADBError::ADBRequestFailed(format!( return Err(RustADBError::ADBRequestFailed(format!(
"Wrong command received {}", "Wrong command received {c}"
c
))); )));
} }
} }

View File

@@ -19,19 +19,24 @@ use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AU
use crate::{Result, RustADBError, USBTransport}; use crate::{Result, RustADBError, USBTransport};
pub fn read_adb_private_key<P: AsRef<Path>>(private_key_path: P) -> Result<Option<ADBRsaKey>> { pub fn read_adb_private_key<P: AsRef<Path>>(private_key_path: P) -> Result<Option<ADBRsaKey>> {
Ok(read_to_string(private_key_path.as_ref()).map(|pk| { // Try to read the private key file from given path
match ADBRsaKey::new_from_pkcs8(&pk) { // If the file is not found, return None
Ok(pk) => Some(pk), // If there is another error while reading the file, return this error
Err(e) => { // Else, return the private key content
log::error!("Error while create RSA private key: {e}"); let pk = match read_to_string(private_key_path.as_ref()) {
None Ok(pk) => pk,
} Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
} Err(e) => return Err(e.into()),
})?) };
match ADBRsaKey::new_from_pkcs8(&pk) {
Ok(pk) => Ok(Some(pk)),
Err(e) => Err(e),
}
} }
/// Search for adb devices with known interface class and subclass values /// Search for adb devices with known interface class and subclass values
fn search_adb_devices() -> Result<Option<(u16, u16)>> { pub fn search_adb_devices() -> Result<Option<(u16, u16)>> {
let mut found_devices = vec![]; let mut found_devices = vec![];
for device in rusb::devices()?.iter() { for device in rusb::devices()?.iter() {
let Ok(des) = device.device_descriptor() else { let Ok(des) = device.device_descriptor() else {
@@ -51,13 +56,13 @@ fn search_adb_devices() -> Result<Option<(u16, u16)>> {
(None, _) => Ok(None), (None, _) => Ok(None),
(Some(identifiers), None) => Ok(Some(*identifiers)), (Some(identifiers), None) => Ok(Some(*identifiers)),
(Some((vid1, pid1)), Some((vid2, pid2))) => Err(RustADBError::DeviceNotFound(format!( (Some((vid1, pid1)), Some((vid2, pid2))) => Err(RustADBError::DeviceNotFound(format!(
"Found two Android devices {:04x}:{:04x} and {:04x}:{:04x}", "Found two Android devices {vid1:04x}:{pid1:04x} and {vid2:04x}:{pid2:04x}",
vid1, pid1, vid2, pid2
))), ))),
} }
} }
fn is_adb_device<T: UsbContext>(device: &Device<T>, des: &DeviceDescriptor) -> bool { /// Check whether a device with given descriptor is an ADB device
pub fn is_adb_device<T: UsbContext>(device: &Device<T>, des: &DeviceDescriptor) -> bool {
const ADB_SUBCLASS: u8 = 0x42; const ADB_SUBCLASS: u8 = 0x42;
const ADB_PROTOCOL: u8 = 0x1; const ADB_PROTOCOL: u8 = 0x1;
@@ -134,9 +139,15 @@ impl ADBUSBDevice {
transport: USBTransport, transport: USBTransport,
private_key_path: PathBuf, private_key_path: PathBuf,
) -> Result<Self> { ) -> Result<Self> {
let private_key = match read_adb_private_key(private_key_path)? { let private_key = match read_adb_private_key(&private_key_path)? {
Some(pk) => pk, Some(pk) => pk,
None => ADBRsaKey::new_random()?, None => {
log::warn!(
"No private key found at path {}. Using a temporary random one.",
private_key_path.display()
);
ADBRsaKey::new_random()?
}
}; };
let mut s = Self { let mut s = Self {
@@ -180,6 +191,11 @@ impl ADBUSBDevice {
self.get_transport_mut().write_message(message)?; self.get_transport_mut().write_message(message)?;
let message = self.get_transport_mut().read_message()?; let message = self.get_transport_mut().read_message()?;
// If the device returned CNXN instead of AUTH it does not require authentication,
// so we can skip the auth steps.
if message.header().command() == MessageCommand::Cnxn {
return Ok(());
}
message.assert_command(MessageCommand::Auth)?; message.assert_command(MessageCommand::Auth)?;
// At this point, we should have receive an AUTH message with arg0 == 1 // At this point, we should have receive an AUTH message with arg0 == 1

View File

@@ -14,7 +14,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
let file_size = apk_file.metadata()?.len(); let file_size = apk_file.metadata()?.len();
self.open_session(format!("exec:cmd package 'install' -S {}\0", file_size).as_bytes())?; self.open_session(format!("exec:cmd package 'install' -S {file_size}\0").as_bytes())?;
let transport = self.get_transport().clone(); let transport = self.get_transport().clone();

View File

@@ -5,7 +5,7 @@ use crate::{
impl<T: ADBMessageTransport> ADBMessageDevice<T> { impl<T: ADBMessageTransport> ADBMessageDevice<T> {
pub(crate) fn reboot(&mut self, reboot_type: RebootType) -> Result<()> { pub(crate) fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
self.open_session(format!("reboot:{}\0", reboot_type).as_bytes())?; self.open_session(format!("reboot:{reboot_type}\0").as_bytes())?;
self.get_transport_mut() self.get_transport_mut()
.read_message() .read_message()

View File

@@ -2,13 +2,13 @@ use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageD
impl<T: ADBMessageTransport> ADBMessageDevice<T> { impl<T: ADBMessageTransport> ADBMessageDevice<T> {
pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> { pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> {
self.open_session(format!("exec:cmd package 'uninstall' {}\0", package_name).as_bytes())?; self.open_session(format!("exec:cmd package 'uninstall' {package_name}\0").as_bytes())?;
let final_status = self.get_transport_mut().read_message()?; let final_status = self.get_transport_mut().read_message()?;
match final_status.into_payload().as_slice() { match final_status.into_payload().as_slice() {
b"Success\n" => { b"Success\n" => {
log::info!("Package {} successfully uninstalled", package_name); log::info!("Package {package_name} successfully uninstalled");
Ok(()) Ok(())
} }
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8( d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(

View File

@@ -35,10 +35,10 @@ impl<T: ADBMessageTransport> Write for MessageWriter<T> {
Ok(response) => { Ok(response) => {
response response
.assert_command(MessageCommand::Okay) .assert_command(MessageCommand::Okay)
.map_err(|e| Error::new(ErrorKind::Other, e))?; .map_err(Error::other)?;
Ok(buf.len()) Ok(buf.len())
} }
Err(e) => Err(Error::new(ErrorKind::Other, e)), Err(e) => Err(Error::other(e)),
} }
} }

View File

@@ -11,7 +11,9 @@ mod shell_message_writer;
use adb_message_device::ADBMessageDevice; use adb_message_device::ADBMessageDevice;
pub use adb_tcp_device::ADBTcpDevice; pub use adb_tcp_device::ADBTcpDevice;
pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader}; pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader};
pub use adb_usb_device::{ADBUSBDevice, get_default_adb_key_path}; pub use adb_usb_device::{
ADBUSBDevice, get_default_adb_key_path, is_adb_device, search_adb_devices,
};
pub use message_writer::MessageWriter; pub use message_writer::MessageWriter;
pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand}; pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand};
pub use shell_message_writer::ShellMessageWriter; pub use shell_message_writer::ShellMessageWriter;

View File

@@ -30,8 +30,7 @@ impl ADBEmulatorDevice {
let groups = EMULATOR_REGEX let groups = EMULATOR_REGEX
.captures(&identifier) .captures(&identifier)
.ok_or(RustADBError::DeviceNotFound(format!( .ok_or(RustADBError::DeviceNotFound(format!(
"Device {} is likely not an emulator", "Device {identifier} is likely not an emulator"
identifier
)))?; )))?;
let port = groups let port = groups

View File

@@ -17,7 +17,7 @@ mod transports;
mod utils; mod utils;
pub use adb_device_ext::ADBDeviceExt; pub use adb_device_ext::ADBDeviceExt;
pub use device::{ADBTcpDevice, ADBUSBDevice}; pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
pub use emulator_device::ADBEmulatorDevice; pub use emulator_device::ADBEmulatorDevice;
pub use error::{Result, RustADBError}; pub use error::{Result, RustADBError};
pub use mdns::*; pub use mdns::*;

View File

@@ -63,8 +63,8 @@ impl Display for AdbServerCommand {
AdbServerCommand::Reboot(reboot_type) => { AdbServerCommand::Reboot(reboot_type) => {
write!(f, "reboot:{reboot_type}") write!(f, "reboot:{reboot_type}")
} }
AdbServerCommand::Connect(addr) => write!(f, "host:connect:{}", addr), AdbServerCommand::Connect(addr) => write!(f, "host:connect:{addr}"),
AdbServerCommand::Disconnect(addr) => write!(f, "host:disconnect:{}", addr), AdbServerCommand::Disconnect(addr) => write!(f, "host:disconnect:{addr}"),
AdbServerCommand::Pair(addr, code) => { AdbServerCommand::Pair(addr, code) => {
write!(f, "host:pair:{code}:{addr}") write!(f, "host:pair:{code}:{addr}")
} }

View File

@@ -32,7 +32,7 @@ impl ADBServer {
Ok(service) => { Ok(service) => {
vec_services.push(MDNSServices::try_from(service.as_bytes())?); vec_services.push(MDNSServices::try_from(service.as_bytes())?);
} }
Err(e) => log::error!("{}", e), Err(e) => log::error!("{e}"),
} }
} }

View File

@@ -64,7 +64,7 @@ impl ADBServerDevice {
"DONE" => { "DONE" => {
return Ok(()); return Ok(());
} }
x => log::error!("Got an unknown response {}", x), x => log::error!("Got an unknown response {x}"),
} }
} }
} }

View File

@@ -42,18 +42,14 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
let mut error_msg = vec![0; length]; let mut error_msg = vec![0; length];
self.inner.read_exact(&mut error_msg)?; self.inner.read_exact(&mut error_msg)?;
Err(std::io::Error::new( Err(std::io::Error::other(format!(
std::io::ErrorKind::Other, "ADB request failed: {}",
format!( String::from_utf8_lossy(&error_msg)
"ADB request failed: {}", )))
String::from_utf8_lossy(&error_msg)
),
))
} }
_ => Err(std::io::Error::new( _ => Err(std::io::Error::other(format!(
std::io::ErrorKind::Other, "Unknown response from device {header:#?}"
format!("Unknown response from device {:#?}", header), ))),
)),
} }
} else { } else {
// Computing minimum to ensure to stop reading before next header... // Computing minimum to ensure to stop reading before next header...

View File

@@ -31,8 +31,7 @@ impl ADBServerDevice {
Ok(data.into()) Ok(data.into())
} }
x => Err(RustADBError::UnknownResponseType(format!( x => Err(RustADBError::UnknownResponseType(format!(
"Unknown response {}", "Unknown response {x}"
x
))), ))),
} }
} }

View File

@@ -15,7 +15,7 @@ impl ADBServerDevice {
match &data[0..read_amount] { match &data[0..read_amount] {
b"Success\n" => { b"Success\n" => {
log::info!("Package {} successfully uninstalled", package_name); log::info!("Package {package_name} successfully uninstalled");
Ok(()) Ok(())
} }
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8( d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(

View File

@@ -99,13 +99,13 @@ impl TCPServerTransport {
} }
/// Gets the body length from a LittleEndian value /// Gets the body length from a LittleEndian value
pub(crate) fn get_body_length(&mut self) -> Result<u32> { pub(crate) fn get_body_length(&self) -> Result<u32> {
let length_buffer = self.read_body_length()?; let length_buffer = self.read_body_length()?;
Ok(LittleEndian::read_u32(&length_buffer)) Ok(LittleEndian::read_u32(&length_buffer))
} }
/// Read 4 bytes representing body length /// Read 4 bytes representing body length
fn read_body_length(&mut self) -> Result<[u8; 4]> { fn read_body_length(&self) -> Result<[u8; 4]> {
let mut length_buffer = [0; 4]; let mut length_buffer = [0; 4];
self.get_raw_connection()?.read_exact(&mut length_buffer)?; self.get_raw_connection()?.read_exact(&mut length_buffer)?;

View File

@@ -109,7 +109,7 @@ impl TcpTransport {
}) })
} }
fn get_current_connection(&mut self) -> Result<Arc<Mutex<CurrentConnection>>> { fn get_current_connection(&self) -> Result<Arc<Mutex<CurrentConnection>>> {
self.current_connection self.current_connection
.as_ref() .as_ref()
.ok_or(RustADBError::IOError(std::io::Error::new( .ok_or(RustADBError::IOError(std::io::Error::new(
@@ -175,8 +175,7 @@ impl TcpTransport {
Ok(()) Ok(())
} }
c => Err(RustADBError::ADBRequestFailed(format!( c => Err(RustADBError::ADBRequestFailed(format!(
"Wrong command received {}", "Wrong command received {c}"
c
))), ))),
} }
} }

View File

@@ -40,8 +40,7 @@ impl USBTransport {
} }
Err(RustADBError::DeviceNotFound(format!( Err(RustADBError::DeviceNotFound(format!(
"cannot find USB device with vendor_id={} and product_id={}", "cannot find USB device with vendor_id={vendor_id} and product_id={product_id}",
vendor_id, product_id
))) )))
} }
@@ -151,12 +150,7 @@ impl USBTransport {
let write_amount = handle.write_bulk(endpoint.address, &data[offset..end], timeout)?; let write_amount = handle.write_bulk(endpoint.address, &data[offset..end], timeout)?;
offset += write_amount; offset += write_amount;
log::trace!( log::trace!("wrote chunk of size {write_amount} - {offset}/{data_len}",)
"wrote chunk of size {} - {}/{}",
write_amount,
offset,
data_len
)
} }
if offset % max_packet_size == 0 { if offset % max_packet_size == 0 {
@@ -175,11 +169,11 @@ impl ADBTransport for USBTransport {
let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?; let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?;
Self::configure_endpoint(&device, &read_endpoint)?; Self::configure_endpoint(&device, &read_endpoint)?;
log::debug!("got read endpoint: {:?}", read_endpoint); log::debug!("got read endpoint: {read_endpoint:?}");
self.read_endpoint = Some(read_endpoint); self.read_endpoint = Some(read_endpoint);
Self::configure_endpoint(&device, &write_endpoint)?; Self::configure_endpoint(&device, &write_endpoint)?;
log::debug!("got write endpoint: {:?}", write_endpoint); log::debug!("got write endpoint: {write_endpoint:?}");
self.write_endpoint = Some(write_endpoint); self.write_endpoint = Some(write_endpoint);
self.handle = Some(Arc::new(device)); self.handle = Some(Arc::new(device));
@@ -197,7 +191,7 @@ impl ADBTransport for USBTransport {
let endpoint = self.read_endpoint.as_ref().or(self.write_endpoint.as_ref()); let endpoint = self.read_endpoint.as_ref().or(self.write_endpoint.as_ref());
if let Some(endpoint) = &endpoint { if let Some(endpoint) = &endpoint {
match handle.release_interface(endpoint.iface) { match handle.release_interface(endpoint.iface) {
Ok(_) => log::debug!("succesfully released interface"), Ok(()) => log::debug!("succesfully released interface"),
Err(e) => log::error!("error while release interface: {e}"), Err(e) => log::error!("error while release interface: {e}"),
} }
} }

View File

@@ -9,6 +9,7 @@ name = "pyadb_client"
readme = "README.md" readme = "README.md"
repository.workspace = true repository.workspace = true
version.workspace = true version.workspace = true
rust-version.workspace = true
[lib] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
@@ -21,6 +22,6 @@ name = "stub_gen"
[dependencies] [dependencies]
adb_client = { path = "../adb_client" } adb_client = { path = "../adb_client" }
anyhow = { version = "1.0.95" } anyhow = { version = "1.0.95" }
pyo3 = { version = "0.24.1", features = ["abi3-py37", "anyhow"] } pyo3 = { version = "0.25.0", features = ["abi3-py37", "anyhow"] }
pyo3-stub-gen = "0.7.0" pyo3-stub-gen = "0.7.0"
pyo3-stub-gen-derive = "0.7.0" pyo3-stub-gen-derive = "0.7.0"

View File

@@ -47,7 +47,6 @@ usb_device.push("file.txt", "/data/local/tmp/file.txt")
```bash ```bash
# Create Python virtual environment # Create Python virtual environment
cd pyadb_client
python3 -m venv .venv python3 -m venv .venv
source .venv/bin/activate source .venv/bin/activate