1 Commits

Author SHA1 Message Date
LIAUD Corentin
4126c856d9 wip: feature-based 2025-08-17 10:46:40 +02:00
10 changed files with 33 additions and 21 deletions

View File

@@ -9,7 +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"
version = "2.1.16"
rust-version = "1.85.1"
# To build locally when working on a new release

View File

@@ -10,6 +10,10 @@ repository.workspace = true
rust-version.workspace = true
version.workspace = true
[features]
default = ["mdns"]
mdns = ["dep:mdns-sd"]
[dependencies]
base64 = { version = "0.22.1" }
bincode = { version = "1.3.3" }
@@ -18,9 +22,6 @@ chrono = { version = "0.4.40", default-features = false, features = ["std"] }
homedir = { version = "= 0.3.4" }
image = { version = "0.25.5", default-features = false }
log = { version = "0.4.26" }
mdns-sd = { version = "0.13.9", default-features = false, features = [
"logging",
] }
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
num-traits = { version = "0.2.19" }
quick-protobuf = { version = "0.8.1" }
@@ -39,6 +40,11 @@ serde_repr = { version = "0.1.19" }
sha1 = { version = "0.10.6", features = ["oid"] }
thiserror = { version = "2.0.7" }
# MDNS
mdns-sd = { version = "0.13.9", default-features = false, optional = true, features = [
"logging",
] }
[dev-dependencies]
anyhow = { version = "1.0.93" }
criterion = { version = "0.6.0" } # Used for benchmarks

View File

@@ -112,6 +112,7 @@ pub enum RustADBError {
#[error("upgrade error: {0}")]
UpgradeError(String),
/// An error occurred while getting mdns devices
#[cfg(feature = "mdns")]
#[error(transparent)]
MDNSError(#[from] mdns_sd::Error),
/// An error occurred while sending data to channel

View File

@@ -9,6 +9,7 @@ mod constants;
mod device;
mod emulator_device;
mod error;
#[cfg(feature = "mdns")]
mod mdns;
mod models;
mod server;
@@ -20,6 +21,7 @@ pub use adb_device_ext::ADBDeviceExt;
pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
pub use emulator_device::ADBEmulatorDevice;
pub use error::{Result, RustADBError};
#[cfg(feature = "mdns")]
pub use mdns::*;
pub use models::{AdbStatResponse, RebootType};
pub use server::*;

View File

@@ -18,7 +18,9 @@ pub(crate) enum AdbServerCommand {
Pair(SocketAddrV4, String),
TransportAny,
TransportSerial(String),
#[cfg(feature = "mdns")]
MDNSCheck,
#[cfg(feature = "mdns")]
MDNSServices,
ServerStatus,
ReconnectOffline,
@@ -77,7 +79,9 @@ impl Display for AdbServerCommand {
write!(f, "reverse:forward:{remote};{local}")
}
AdbServerCommand::ReverseRemoveAll => write!(f, "reverse:killforward-all"),
#[cfg(feature = "mdns")]
AdbServerCommand::MDNSCheck => write!(f, "host:mdns:check"),
#[cfg(feature = "mdns")]
AdbServerCommand::MDNSServices => write!(f, "host:mdns:services"),
AdbServerCommand::ServerStatus => write!(f, "host:server-status"),
AdbServerCommand::Reconnect => write!(f, "reconnect"),

View File

@@ -6,6 +6,7 @@ use crate::{
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
#[cfg(feature = "mdns")]
impl ADBServer {
/// Check if mdns discovery is available
pub fn mdns_check(&mut self) -> Result<bool> {

View File

@@ -2,6 +2,7 @@ mod connect;
mod devices;
mod disconnect;
mod kill;
#[cfg(feature = "mdns")]
mod mdns;
mod pair;
mod reconnect;

View File

@@ -93,7 +93,7 @@ impl TryFrom<&[u8]> for DeviceLong {
.ok_or(RustADBError::RegexParsingError)?
.as_bytes(),
)?,
10,
16,
)?,
})
}

View File

@@ -2,6 +2,7 @@ mod adb_version;
mod device_long;
mod device_short;
mod device_state;
#[cfg(feature = "mdns")]
mod mdns_services;
mod server_status;
mod wait_for_device;
@@ -10,6 +11,7 @@ pub use adb_version::AdbVersion;
pub use device_long::DeviceLong;
pub use device_short::DeviceShort;
pub use device_state::DeviceState;
#[cfg(feature = "mdns")]
pub use mdns_services::MDNSServices;
pub use server_status::{MDNSBackend, ServerStatus};
pub use wait_for_device::{WaitForDeviceState, WaitForDeviceTransport};

View File

@@ -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())