Compare commits
1 Commits
v2.1.17
...
127-no-suc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e7f1c7e4e |
@@ -9,8 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
||||
keywords = ["adb", "android", "tcp", "usb"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/cocool97/adb_client"
|
||||
version = "2.1.17"
|
||||
rust-version = "1.85.1"
|
||||
version = "2.1.15"
|
||||
|
||||
# To build locally when working on a new release
|
||||
[patch.crates-io]
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
<a href="https://crates.io/crates/adb_client">
|
||||
<img alt="crates.io" src="https://img.shields.io/crates/v/adb_client.svg"/>
|
||||
</a>
|
||||
<a href="https://crates.io/crates/adb_client">
|
||||
<img alt="msrv" src="https://img.shields.io/crates/msrv/adb_client"/>
|
||||
</a>
|
||||
<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"/>
|
||||
</a>
|
||||
|
||||
@@ -7,7 +7,6 @@ license.workspace = true
|
||||
name = "adb_cli"
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
[](./LICENSE-MIT)
|
||||

|
||||

|
||||
|
||||
Rust binary providing an improved version of `adb` CLI.
|
||||
|
||||
@@ -11,7 +10,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 :
|
||||
|
||||
```shell
|
||||
cargo install adb_cli
|
||||
cargo install adb_cli
|
||||
```
|
||||
|
||||
Usage is quite simple, and tends to look like `adb`:
|
||||
@@ -65,4 +64,4 @@ Options:
|
||||
-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
|
||||
-h, --help Print help
|
||||
```
|
||||
```
|
||||
@@ -8,7 +8,7 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
||||
match server_command.command {
|
||||
HostCommand::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"));
|
||||
}
|
||||
HostCommand::Kill => {
|
||||
@@ -18,18 +18,18 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
||||
if long {
|
||||
log::info!("List of devices attached (extended)");
|
||||
for device in adb_server.devices_long()? {
|
||||
log::info!("{device}");
|
||||
log::info!("{}", device);
|
||||
}
|
||||
} else {
|
||||
log::info!("List of devices attached");
|
||||
for device in adb_server.devices()? {
|
||||
log::info!("{device}");
|
||||
log::info!("{}", device);
|
||||
}
|
||||
}
|
||||
}
|
||||
HostCommand::TrackDevices => {
|
||||
let callback = |device: DeviceShort| {
|
||||
log::info!("{device}");
|
||||
log::info!("{}", device);
|
||||
Ok(())
|
||||
};
|
||||
log::info!("Live list of devices attached");
|
||||
@@ -65,7 +65,7 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
||||
MdnsCommand::Services => {
|
||||
log::info!("List of discovered mdns services");
|
||||
for service in adb_server.mdns_services()? {
|
||||
log::info!("{service}");
|
||||
log::info!("{}", service);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -132,10 +132,10 @@ fn main() -> Result<()> {
|
||||
}
|
||||
DeviceCommands::Stat { path } => {
|
||||
let stat_response = device.stat(&path)?;
|
||||
println!("{stat_response}");
|
||||
println!("{}", stat_response);
|
||||
}
|
||||
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())?
|
||||
}
|
||||
DeviceCommands::Push { filename, path } => {
|
||||
@@ -152,7 +152,7 @@ fn main() -> Result<()> {
|
||||
device.install(&path)?;
|
||||
}
|
||||
DeviceCommands::Uninstall { package } => {
|
||||
log::info!("Uninstalling the package {package}...");
|
||||
log::info!("Uninstalling the package {}...", package);
|
||||
device.uninstall(&package)?;
|
||||
}
|
||||
DeviceCommands::Framebuffer { path } => {
|
||||
|
||||
@@ -7,7 +7,6 @@ license.workspace = true
|
||||
name = "adb_client"
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
[](./LICENSE-MIT)
|
||||
[](https://docs.rs/adb_client)
|
||||
[](https://crates.io/crates/adb_client)
|
||||

|
||||
|
||||
Rust library implementing ADB protocol.
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
MessageCommand::Write => return Ok(()),
|
||||
c => {
|
||||
return Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Wrong command received {c}"
|
||||
"Wrong command received {}",
|
||||
c
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,8 @@ pub fn search_adb_devices() -> Result<Option<(u16, u16)>> {
|
||||
(None, _) => Ok(None),
|
||||
(Some(identifiers), None) => Ok(Some(*identifiers)),
|
||||
(Some((vid1, pid1)), Some((vid2, pid2))) => Err(RustADBError::DeviceNotFound(format!(
|
||||
"Found two Android devices {vid1:04x}:{pid1:04x} and {vid2:04x}:{pid2:04x}",
|
||||
"Found two Android devices {:04x}:{:04x} and {:04x}:{:04x}",
|
||||
vid1, pid1, vid2, pid2
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
let file_size = apk_file.metadata()?.len();
|
||||
|
||||
self.open_session(format!("exec:cmd package 'install' -S {file_size}\0").as_bytes())?;
|
||||
self.open_session(format!("exec:cmd package 'install' -S {}\0", file_size).as_bytes())?;
|
||||
|
||||
let transport = self.get_transport().clone();
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
||||
self.open_session(format!("reboot:{reboot_type}\0").as_bytes())?;
|
||||
self.open_session(format!("reboot:{}\0", reboot_type).as_bytes())?;
|
||||
|
||||
self.get_transport_mut()
|
||||
.read_message()
|
||||
|
||||
@@ -2,13 +2,13 @@ use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageD
|
||||
|
||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
||||
self.open_session(format!("exec:cmd package 'uninstall' {package_name}\0").as_bytes())?;
|
||||
self.open_session(format!("exec:cmd package 'uninstall' {}\0", package_name).as_bytes())?;
|
||||
|
||||
let final_status = self.get_transport_mut().read_message()?;
|
||||
|
||||
match final_status.into_payload().as_slice() {
|
||||
b"Success\n" => {
|
||||
log::info!("Package {package_name} successfully uninstalled");
|
||||
log::info!("Package {} successfully uninstalled", package_name);
|
||||
Ok(())
|
||||
}
|
||||
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(
|
||||
|
||||
@@ -30,7 +30,8 @@ impl ADBEmulatorDevice {
|
||||
let groups = EMULATOR_REGEX
|
||||
.captures(&identifier)
|
||||
.ok_or(RustADBError::DeviceNotFound(format!(
|
||||
"Device {identifier} is likely not an emulator"
|
||||
"Device {} is likely not an emulator",
|
||||
identifier
|
||||
)))?;
|
||||
|
||||
let port = groups
|
||||
|
||||
@@ -63,8 +63,8 @@ impl Display for AdbServerCommand {
|
||||
AdbServerCommand::Reboot(reboot_type) => {
|
||||
write!(f, "reboot:{reboot_type}")
|
||||
}
|
||||
AdbServerCommand::Connect(addr) => write!(f, "host:connect:{addr}"),
|
||||
AdbServerCommand::Disconnect(addr) => write!(f, "host:disconnect:{addr}"),
|
||||
AdbServerCommand::Connect(addr) => write!(f, "host:connect:{}", addr),
|
||||
AdbServerCommand::Disconnect(addr) => write!(f, "host:disconnect:{}", addr),
|
||||
AdbServerCommand::Pair(addr, code) => {
|
||||
write!(f, "host:pair:{code}:{addr}")
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl ADBServer {
|
||||
Ok(service) => {
|
||||
vec_services.push(MDNSServices::try_from(service.as_bytes())?);
|
||||
}
|
||||
Err(e) => log::error!("{e}"),
|
||||
Err(e) => log::error!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ impl TryFrom<&[u8]> for DeviceLong {
|
||||
.ok_or(RustADBError::RegexParsingError)?
|
||||
.as_bytes(),
|
||||
)?,
|
||||
10,
|
||||
16,
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ impl ADBServerDevice {
|
||||
"DONE" => {
|
||||
return Ok(());
|
||||
}
|
||||
x => log::error!("Got an unknown response {x}"),
|
||||
x => log::error!("Got an unknown response {}", x),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,26 +23,21 @@ impl<W: Write> LogFilter<W> {
|
||||
|
||||
impl<W: Write> Write for LogFilter<W> {
|
||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
// Add newly received bytes to the internal buffer
|
||||
self.buffer.extend_from_slice(buf);
|
||||
|
||||
let mut processed = 0;
|
||||
while let Some(pos) = self.buffer[processed..].iter().position(|&b| b == b'\n') {
|
||||
// Found a newline, need to process it
|
||||
let end = processed + pos + 1; // +1 to include the '\n'
|
||||
let line = &self.buffer[processed..end];
|
||||
let buf_clone = self.buffer.clone();
|
||||
let mut lines = buf_clone.split_inclusive(|&byte| byte == b'\n').peekable();
|
||||
|
||||
if self.should_write(line) {
|
||||
self.writer.write_all(line)?;
|
||||
while let Some(line) = lines.next() {
|
||||
if lines.peek().is_some() {
|
||||
if self.should_write(line) {
|
||||
self.writer.write_all(line)?;
|
||||
}
|
||||
} else {
|
||||
// This is the last (unfinished) element, we keep it for next round
|
||||
self.buffer = line.to_vec();
|
||||
break;
|
||||
}
|
||||
|
||||
processed = end;
|
||||
}
|
||||
|
||||
// Keep only remaining bytes after the last complete line
|
||||
if processed > 0 {
|
||||
self.buffer.copy_within(processed.., 0);
|
||||
self.buffer.truncate(self.buffer.len() - processed);
|
||||
}
|
||||
|
||||
Ok(buf.len())
|
||||
|
||||
@@ -48,7 +48,8 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
|
||||
)))
|
||||
}
|
||||
_ => Err(std::io::Error::other(format!(
|
||||
"Unknown response from device {header:#?}"
|
||||
"Unknown response from device {:#?}",
|
||||
header
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -31,7 +31,8 @@ impl ADBServerDevice {
|
||||
Ok(data.into())
|
||||
}
|
||||
x => Err(RustADBError::UnknownResponseType(format!(
|
||||
"Unknown response {x}"
|
||||
"Unknown response {}",
|
||||
x
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ impl ADBServerDevice {
|
||||
|
||||
match &data[0..read_amount] {
|
||||
b"Success\n" => {
|
||||
log::info!("Package {package_name} successfully uninstalled");
|
||||
log::info!("Package {} successfully uninstalled", package_name);
|
||||
Ok(())
|
||||
}
|
||||
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(
|
||||
|
||||
@@ -99,13 +99,13 @@ impl TCPServerTransport {
|
||||
}
|
||||
|
||||
/// Gets the body length from a LittleEndian value
|
||||
pub(crate) fn get_body_length(&self) -> Result<u32> {
|
||||
pub(crate) fn get_body_length(&mut self) -> Result<u32> {
|
||||
let length_buffer = self.read_body_length()?;
|
||||
Ok(LittleEndian::read_u32(&length_buffer))
|
||||
}
|
||||
|
||||
/// Read 4 bytes representing body length
|
||||
fn read_body_length(&self) -> Result<[u8; 4]> {
|
||||
fn read_body_length(&mut self) -> Result<[u8; 4]> {
|
||||
let mut length_buffer = [0; 4];
|
||||
self.get_raw_connection()?.read_exact(&mut length_buffer)?;
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ impl TcpTransport {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_current_connection(&self) -> Result<Arc<Mutex<CurrentConnection>>> {
|
||||
fn get_current_connection(&mut self) -> Result<Arc<Mutex<CurrentConnection>>> {
|
||||
self.current_connection
|
||||
.as_ref()
|
||||
.ok_or(RustADBError::IOError(std::io::Error::new(
|
||||
@@ -175,7 +175,8 @@ impl TcpTransport {
|
||||
Ok(())
|
||||
}
|
||||
c => Err(RustADBError::ADBRequestFailed(format!(
|
||||
"Wrong command received {c}"
|
||||
"Wrong command received {}",
|
||||
c
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ impl USBTransport {
|
||||
}
|
||||
|
||||
Err(RustADBError::DeviceNotFound(format!(
|
||||
"cannot find USB device with vendor_id={vendor_id} and product_id={product_id}",
|
||||
"cannot find USB device with vendor_id={} and product_id={}",
|
||||
vendor_id, product_id
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -150,7 +151,12 @@ impl USBTransport {
|
||||
let write_amount = handle.write_bulk(endpoint.address, &data[offset..end], timeout)?;
|
||||
offset += write_amount;
|
||||
|
||||
log::trace!("wrote chunk of size {write_amount} - {offset}/{data_len}",)
|
||||
log::trace!(
|
||||
"wrote chunk of size {} - {}/{}",
|
||||
write_amount,
|
||||
offset,
|
||||
data_len
|
||||
)
|
||||
}
|
||||
|
||||
if offset % max_packet_size == 0 {
|
||||
@@ -169,11 +175,11 @@ impl ADBTransport for USBTransport {
|
||||
let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?;
|
||||
|
||||
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::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.handle = Some(Arc::new(device));
|
||||
@@ -191,7 +197,7 @@ impl ADBTransport for USBTransport {
|
||||
let endpoint = self.read_endpoint.as_ref().or(self.write_endpoint.as_ref());
|
||||
if let Some(endpoint) = &endpoint {
|
||||
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}"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ name = "pyadb_client"
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
version.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
Reference in New Issue
Block a user