From 586964128f3338344a6db96791579937fd6ee235 Mon Sep 17 00:00:00 2001 From: Corentin LIAUD Date: Mon, 1 Sep 2025 21:40:40 +0200 Subject: [PATCH] feat: improve modules ordering --- .gitignore | 2 +- adb_cli/src/handlers/emulator_commands.rs | 2 +- adb_cli/src/handlers/host_commands.rs | 5 ++- adb_cli/src/handlers/local_commands.rs | 2 +- adb_cli/src/main.rs | 9 ++-- adb_cli/src/models/host.rs | 2 +- adb_client/README.md | 12 +++--- adb_client/src/adb_device_ext.rs | 2 +- .../{transports/traits => }/adb_transport.rs | 0 adb_client/src/constants.rs | 1 - adb_client/src/device/mod.rs | 28 ------------ adb_client/src/device/models/mod.rs | 9 ---- .../adb_emulator_device.rs | 5 ++- .../commands/mod.rs | 0 .../commands/rotate.rs | 5 ++- .../commands/sms.rs | 5 ++- .../src/{emulator_device => emulator}/mod.rs | 4 +- .../models/adb_emulator_command.rs | 0 .../models/mod.rs | 0 .../tcp_emulator_transport.rs | 5 ++- adb_client/src/error.rs | 6 +-- adb_client/src/lib.rs | 43 ++++++++----------- adb_client/src/mdns/mdns_discovery.rs | 8 ++-- .../adb_message_device.rs | 11 ++++- .../adb_message_device_commands.rs | 10 +++-- .../adb_message_transport.rs | 6 ++- .../adb_transport_message.rs | 4 +- .../commands/framebuffer.rs | 7 ++- .../commands/install.rs | 7 ++- .../commands/mod.rs | 1 + .../commands/pull.rs | 10 +++-- .../commands/push.rs | 8 ++-- .../commands/reboot.rs | 7 ++- .../commands/shell.rs | 10 +++-- .../commands/stat.rs | 5 ++- .../commands/uninstall.rs | 7 ++- .../commands/utils}/message_writer.rs | 7 +-- .../src/message_devices/commands/utils/mod.rs | 4 ++ .../commands/utils}/shell_message_writer.rs | 7 +-- .../message_commands.rs | 0 adb_client/src/message_devices/mod.rs | 14 ++++++ .../tcp}/adb_tcp_device.rs | 10 +++-- adb_client/src/message_devices/tcp/mod.rs | 4 ++ .../tcp}/tcp_transport.rs | 10 +++-- .../usb}/adb_rsa_key.rs | 0 .../usb}/adb_usb_device.rs | 15 ++++--- adb_client/src/message_devices/usb/mod.rs | 6 +++ .../usb}/usb_transport.rs | 8 +++- adb_client/src/models/host_features.rs | 3 ++ adb_client/src/models/mod.rs | 6 +-- adb_client/src/server/adb_server.rs | 2 +- .../{models => server}/adb_server_command.rs | 6 ++- adb_client/src/server/commands/connect.rs | 5 ++- adb_client/src/server/commands/devices.rs | 6 ++- adb_client/src/server/commands/disconnect.rs | 5 ++- adb_client/src/server/commands/kill.rs | 5 ++- adb_client/src/server/commands/mdns.rs | 3 +- adb_client/src/server/commands/pair.rs | 6 ++- adb_client/src/server/commands/reconnect.rs | 5 ++- .../src/server/commands/server_status.rs | 5 ++- adb_client/src/server/commands/version.rs | 5 ++- .../src/server/commands/wait_for_device.rs | 3 +- adb_client/src/server/mod.rs | 4 ++ adb_client/src/server/models/device_long.rs | 3 +- adb_client/src/server/models/device_short.rs | 2 +- .../tcp_server_transport.rs | 3 +- .../src/server_device/adb_server_device.rs | 5 ++- .../adb_server_device_commands.rs | 6 ++- .../src/server_device/commands/forward.rs | 2 +- .../src/server_device/commands/framebuffer.rs | 6 ++- .../server_device/commands/host_features.rs | 3 +- .../src/server_device/commands/install.rs | 2 +- adb_client/src/server_device/commands/list.rs | 3 +- .../src/server_device/commands/logcat.rs | 2 +- .../src/server_device/commands/reboot.rs | 5 +-- .../src/server_device/commands/reconnect.rs | 2 +- adb_client/src/server_device/commands/recv.rs | 9 ++-- .../src/server_device/commands/reverse.rs | 2 +- adb_client/src/server_device/commands/send.rs | 12 ++++-- adb_client/src/server_device/commands/stat.rs | 4 +- .../src/server_device/commands/tcpip.rs | 2 +- .../src/server_device/commands/transport.rs | 2 +- .../src/server_device/commands/uninstall.rs | 2 +- adb_client/src/server_device/commands/usb.rs | 2 +- adb_client/src/transports/mod.rs | 17 -------- adb_client/src/transports/traits/mod.rs | 5 --- examples/mdns/src/main.rs | 3 +- pyadb_client/src/adb_server.rs | 2 +- pyadb_client/src/adb_server_device.rs | 2 +- pyadb_client/src/adb_usb_device.rs | 2 +- pyadb_client/src/models/devices.rs | 2 +- 91 files changed, 290 insertions(+), 224 deletions(-) rename adb_client/src/{transports/traits => }/adb_transport.rs (100%) delete mode 100644 adb_client/src/constants.rs delete mode 100644 adb_client/src/device/mod.rs delete mode 100644 adb_client/src/device/models/mod.rs rename adb_client/src/{emulator_device => emulator}/adb_emulator_device.rs (94%) rename adb_client/src/{emulator_device => emulator}/commands/mod.rs (100%) rename adb_client/src/{emulator_device => emulator}/commands/rotate.rs (72%) rename adb_client/src/{emulator_device => emulator}/commands/sms.rs (80%) rename adb_client/src/{emulator_device => emulator}/mod.rs (61%) rename adb_client/src/{emulator_device => emulator}/models/adb_emulator_command.rs (100%) rename adb_client/src/{emulator_device => emulator}/models/mod.rs (100%) rename adb_client/src/{transports => emulator}/tcp_emulator_transport.rs (97%) rename adb_client/src/{device => message_devices}/adb_message_device.rs (96%) rename adb_client/src/{device => message_devices}/adb_message_device_commands.rs (85%) rename adb_client/src/{transports/traits => message_devices}/adb_message_transport.rs (90%) rename adb_client/src/{device => message_devices}/adb_transport_message.rs (97%) rename adb_client/src/{device => message_devices}/commands/framebuffer.rs (94%) rename adb_client/src/{device => message_devices}/commands/install.rs (87%) rename adb_client/src/{device => message_devices}/commands/mod.rs (89%) rename adb_client/src/{device => message_devices}/commands/pull.rs (85%) rename adb_client/src/{device => message_devices}/commands/push.rs (81%) rename adb_client/src/{device => message_devices}/commands/reboot.rs (66%) rename adb_client/src/{device => message_devices}/commands/shell.rs (90%) rename adb_client/src/{device => message_devices}/commands/stat.rs (69%) rename adb_client/src/{device => message_devices}/commands/uninstall.rs (81%) rename adb_client/src/{device => message_devices/commands/utils}/message_writer.rs (88%) create mode 100644 adb_client/src/message_devices/commands/utils/mod.rs rename adb_client/src/{device => message_devices/commands/utils}/shell_message_writer.rs (85%) rename adb_client/src/{device/models => message_devices}/message_commands.rs (100%) create mode 100644 adb_client/src/message_devices/mod.rs rename adb_client/src/{device => message_devices/tcp}/adb_tcp_device.rs (90%) create mode 100644 adb_client/src/message_devices/tcp/mod.rs rename adb_client/src/{transports => message_devices/tcp}/tcp_transport.rs (97%) rename adb_client/src/{device/models => message_devices/usb}/adb_rsa_key.rs (100%) rename adb_client/src/{device => message_devices/usb}/adb_usb_device.rs (95%) create mode 100644 adb_client/src/message_devices/usb/mod.rs rename adb_client/src/{transports => message_devices/usb}/usb_transport.rs (97%) rename adb_client/src/{models => server}/adb_server_command.rs (97%) rename adb_client/src/{transports => server}/tcp_server_transport.rs (98%) delete mode 100644 adb_client/src/transports/mod.rs delete mode 100644 adb_client/src/transports/traits/mod.rs diff --git a/.gitignore b/.gitignore index a7d61ce..a3ae0cf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ target /.vscode venv /.mypy_cache -pyadb_client/pyadb_client.pyi \ No newline at end of file +pyadb_client/pyadb_client.pyi diff --git a/adb_cli/src/handlers/emulator_commands.rs b/adb_cli/src/handlers/emulator_commands.rs index 5855cd7..dcd6c16 100644 --- a/adb_cli/src/handlers/emulator_commands.rs +++ b/adb_cli/src/handlers/emulator_commands.rs @@ -1,4 +1,4 @@ -use adb_client::ADBEmulatorDevice; +use adb_client::emulator::ADBEmulatorDevice; use crate::models::{EmuCommand, EmulatorCommand}; diff --git a/adb_cli/src/handlers/host_commands.rs b/adb_cli/src/handlers/host_commands.rs index 250f465..aefcf34 100644 --- a/adb_cli/src/handlers/host_commands.rs +++ b/adb_cli/src/handlers/host_commands.rs @@ -1,4 +1,7 @@ -use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result, WaitForDeviceState}; +use adb_client::{ + Result, + server::{ADBServer, DeviceShort, MDNSBackend, WaitForDeviceState}, +}; use crate::models::{HostCommand, MdnsCommand, ServerCommand}; diff --git a/adb_cli/src/handlers/local_commands.rs b/adb_cli/src/handlers/local_commands.rs index 92411ad..4b9af4a 100644 --- a/adb_cli/src/handlers/local_commands.rs +++ b/adb_cli/src/handlers/local_commands.rs @@ -1,6 +1,6 @@ use std::{fs::File, io::Write}; -use adb_client::ADBServerDevice; +use adb_client::server_device::ADBServerDevice; use anyhow::{Result, anyhow}; use crate::models::LocalDeviceCommand; diff --git a/adb_cli/src/main.rs b/adb_cli/src/main.rs index 3ac5af6..059d116 100644 --- a/adb_cli/src/main.rs +++ b/adb_cli/src/main.rs @@ -7,9 +7,12 @@ mod handlers; mod models; mod utils; -use adb_client::{ - ADBDeviceExt, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService, -}; +use adb_client::ADBDeviceExt; +use adb_client::mdns::MDNSDiscoveryService; +use adb_client::server::ADBServer; +use adb_client::server_device::ADBServerDevice; +use adb_client::tcp::ADBTcpDevice; +use adb_client::usb::ADBUSBDevice; #[cfg(any(target_os = "linux", target_os = "macos"))] use adb_termios::ADBTermios; diff --git a/adb_cli/src/models/host.rs b/adb_cli/src/models/host.rs index 4161d18..6904d39 100644 --- a/adb_cli/src/models/host.rs +++ b/adb_cli/src/models/host.rs @@ -1,6 +1,6 @@ use std::net::SocketAddrV4; -use adb_client::{RustADBError, WaitForDeviceTransport}; +use adb_client::{RustADBError, server::WaitForDeviceTransport}; use clap::Parser; fn parse_wait_for_device_device_transport( diff --git a/adb_client/README.md b/adb_client/README.md index 87cd518..40e4911 100644 --- a/adb_client/README.md +++ b/adb_client/README.md @@ -49,7 +49,7 @@ Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel ### Get available ADB devices ```rust no_run -use adb_client::ADBServer; +use adb_client::server::ADBServer; use std::net::{SocketAddrV4, Ipv4Addr}; // A custom server address can be provided @@ -65,7 +65,7 @@ server.devices(); #### Launch a command on device ```rust no_run -use adb_client::{ADBServer, ADBDeviceExt}; +use adb_client::{server::ADBServer, ADBDeviceExt}; let mut server = ADBServer::default(); let mut device = server.get_device().expect("cannot get device"); @@ -75,7 +75,7 @@ device.shell_command(&["df", "-h"], &mut std::io::stdout()); #### Push a file to the device ```rust no_run -use adb_client::ADBServer; +use adb_client::server::ADBServer; use std::net::Ipv4Addr; use std::fs::File; use std::path::Path; @@ -91,7 +91,7 @@ device.push(&mut input, "/data/local/tmp"); #### (USB) Launch a command on device ```rust no_run -use adb_client::{ADBUSBDevice, ADBDeviceExt}; +use adb_client::{usb::ADBUSBDevice, ADBDeviceExt}; let vendor_id = 0x04e8; let product_id = 0x6860; @@ -102,7 +102,7 @@ device.shell_command(&["df", "-h"], &mut std::io::stdout()); #### (USB) Push a file to the device ```rust no_run -use adb_client::{ADBUSBDevice, ADBDeviceExt}; +use adb_client::{usb::ADBUSBDevice, ADBDeviceExt}; use std::fs::File; use std::path::Path; @@ -117,7 +117,7 @@ device.push(&mut input, &"/data/local/tmp"); ```rust no_run use std::net::{SocketAddr, IpAddr, Ipv4Addr}; -use adb_client::{ADBTcpDevice, ADBDeviceExt}; +use adb_client::{tcp::ADBTcpDevice, ADBDeviceExt}; let device_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 10)); let device_port = 43210; diff --git a/adb_client/src/adb_device_ext.rs b/adb_client/src/adb_device_ext.rs index a342f3a..9fd4d1a 100644 --- a/adb_client/src/adb_device_ext.rs +++ b/adb_client/src/adb_device_ext.rs @@ -6,7 +6,7 @@ use image::{ImageBuffer, ImageFormat, Rgba}; use crate::models::AdbStatResponse; use crate::{RebootType, Result}; -/// Trait representing all features available on both [`crate::ADBServerDevice`] and [`crate::ADBUSBDevice`] +/// Trait representing all features available on both [`crate::server_device::ADBServerDevice`] and [`crate::usb::ADBUSBDevice`] pub trait ADBDeviceExt { /// Runs command in a shell on the device, and write its output and error streams into output. fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()>; diff --git a/adb_client/src/transports/traits/adb_transport.rs b/adb_client/src/adb_transport.rs similarity index 100% rename from adb_client/src/transports/traits/adb_transport.rs rename to adb_client/src/adb_transport.rs diff --git a/adb_client/src/constants.rs b/adb_client/src/constants.rs deleted file mode 100644 index c2eb05e..0000000 --- a/adb_client/src/constants.rs +++ /dev/null @@ -1 +0,0 @@ -pub const BUFFER_SIZE: usize = 65536; diff --git a/adb_client/src/device/mod.rs b/adb_client/src/device/mod.rs deleted file mode 100644 index d9bbf06..0000000 --- a/adb_client/src/device/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -mod adb_message_device; -mod adb_message_device_commands; -mod adb_tcp_device; -mod adb_transport_message; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -mod adb_usb_device; -mod commands; -mod message_writer; -mod models; -mod shell_message_writer; - -use adb_message_device::ADBMessageDevice; -pub use adb_tcp_device::ADBTcpDevice; -pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader}; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -pub use adb_usb_device::{ADBUSBDevice, is_adb_device, search_adb_devices}; - -pub use message_writer::MessageWriter; -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -pub use models::ADBRsaKey; - -pub use models::{MessageCommand, MessageSubcommand}; -pub use shell_message_writer::ShellMessageWriter; diff --git a/adb_client/src/device/models/mod.rs b/adb_client/src/device/models/mod.rs deleted file mode 100644 index da632e9..0000000 --- a/adb_client/src/device/models/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -mod adb_rsa_key; -mod message_commands; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -pub use adb_rsa_key::ADBRsaKey; -pub use message_commands::{MessageCommand, MessageSubcommand}; diff --git a/adb_client/src/emulator_device/adb_emulator_device.rs b/adb_client/src/emulator/adb_emulator_device.rs similarity index 94% rename from adb_client/src/emulator_device/adb_emulator_device.rs rename to adb_client/src/emulator/adb_emulator_device.rs index 9c3ec4f..e48dbd1 100644 --- a/adb_client/src/emulator_device/adb_emulator_device.rs +++ b/adb_client/src/emulator/adb_emulator_device.rs @@ -3,7 +3,10 @@ use std::{ sync::LazyLock, }; -use crate::{ADBServerDevice, ADBTransport, Result, RustADBError, TCPEmulatorTransport}; +use crate::{ + ADBTransport, Result, RustADBError, emulator::tcp_emulator_transport::TCPEmulatorTransport, + server_device::ADBServerDevice, +}; use regex::Regex; static EMULATOR_REGEX: LazyLock = LazyLock::new(|| { diff --git a/adb_client/src/emulator_device/commands/mod.rs b/adb_client/src/emulator/commands/mod.rs similarity index 100% rename from adb_client/src/emulator_device/commands/mod.rs rename to adb_client/src/emulator/commands/mod.rs diff --git a/adb_client/src/emulator_device/commands/rotate.rs b/adb_client/src/emulator/commands/rotate.rs similarity index 72% rename from adb_client/src/emulator_device/commands/rotate.rs rename to adb_client/src/emulator/commands/rotate.rs index 0da9d3e..d4e9db4 100644 --- a/adb_client/src/emulator_device/commands/rotate.rs +++ b/adb_client/src/emulator/commands/rotate.rs @@ -1,4 +1,7 @@ -use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand}; +use crate::{ + Result, + emulator::{ADBEmulatorCommand, ADBEmulatorDevice}, +}; impl ADBEmulatorDevice { /// Send a SMS to this emulator with given content with given phone number diff --git a/adb_client/src/emulator_device/commands/sms.rs b/adb_client/src/emulator/commands/sms.rs similarity index 80% rename from adb_client/src/emulator_device/commands/sms.rs rename to adb_client/src/emulator/commands/sms.rs index 627feb9..e988db3 100644 --- a/adb_client/src/emulator_device/commands/sms.rs +++ b/adb_client/src/emulator/commands/sms.rs @@ -1,4 +1,7 @@ -use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand}; +use crate::{ + Result, + emulator::{ADBEmulatorCommand, ADBEmulatorDevice}, +}; impl ADBEmulatorDevice { /// Send a SMS to this emulator with given content with given phone number diff --git a/adb_client/src/emulator_device/mod.rs b/adb_client/src/emulator/mod.rs similarity index 61% rename from adb_client/src/emulator_device/mod.rs rename to adb_client/src/emulator/mod.rs index d3f0450..3f799e8 100644 --- a/adb_client/src/emulator_device/mod.rs +++ b/adb_client/src/emulator/mod.rs @@ -1,5 +1,7 @@ mod adb_emulator_device; mod commands; mod models; +mod tcp_emulator_transport; + pub use adb_emulator_device::ADBEmulatorDevice; -pub(crate) use models::ADBEmulatorCommand; +use models::ADBEmulatorCommand; diff --git a/adb_client/src/emulator_device/models/adb_emulator_command.rs b/adb_client/src/emulator/models/adb_emulator_command.rs similarity index 100% rename from adb_client/src/emulator_device/models/adb_emulator_command.rs rename to adb_client/src/emulator/models/adb_emulator_command.rs diff --git a/adb_client/src/emulator_device/models/mod.rs b/adb_client/src/emulator/models/mod.rs similarity index 100% rename from adb_client/src/emulator_device/models/mod.rs rename to adb_client/src/emulator/models/mod.rs diff --git a/adb_client/src/transports/tcp_emulator_transport.rs b/adb_client/src/emulator/tcp_emulator_transport.rs similarity index 97% rename from adb_client/src/transports/tcp_emulator_transport.rs rename to adb_client/src/emulator/tcp_emulator_transport.rs index 9a31542..7842d2e 100644 --- a/adb_client/src/transports/tcp_emulator_transport.rs +++ b/adb_client/src/emulator/tcp_emulator_transport.rs @@ -6,8 +6,9 @@ use std::{ use homedir::my_home; -use super::ADBTransport; -use crate::{Result, RustADBError, emulator_device::ADBEmulatorCommand}; +use crate::{ + Result, RustADBError, adb_transport::ADBTransport, emulator::models::ADBEmulatorCommand, +}; /// Emulator transport running on top on TCP. #[derive(Debug)] diff --git a/adb_client/src/error.rs b/adb_client/src/error.rs index f3742d4..3f32b29 100644 --- a/adb_client/src/error.rs +++ b/adb_client/src/error.rs @@ -123,10 +123,8 @@ pub enum RustADBError { #[error(transparent)] MDNSError(#[from] mdns_sd::Error), /// An error occurred while sending data to channel - #[cfg(feature = "mdns")] - #[cfg_attr(docsrs, doc(cfg(feature = "mdns")))] - #[error(transparent)] - SendError(#[from] std::sync::mpsc::SendError), + #[error("error sending data to channel")] + SendError, /// An unknown transport has been provided #[error("unknown transport: {0}")] UnknownTransport(String), diff --git a/adb_client/src/lib.rs b/adb_client/src/lib.rs index 7b41eee..63a4cc3 100644 --- a/adb_client/src/lib.rs +++ b/adb_client/src/lib.rs @@ -10,36 +10,27 @@ #![cfg_attr(docsrs, feature(doc_cfg))] mod adb_device_ext; -mod constants; -mod device; -mod emulator_device; +mod adb_transport; +/// Emulator-related definitions +pub mod emulator; mod error; - -#[cfg(feature = "mdns")] -#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))] -mod mdns; - +mod message_devices; mod models; -mod server; -mod server_device; -mod transports; + +/// Server-related definitions +pub mod server; + +/// Device reachable by the server related definitions +pub mod server_device; mod utils; -pub use adb_device_ext::ADBDeviceExt; -pub use device::ADBTcpDevice; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -pub use device::{ADBUSBDevice, is_adb_device, search_adb_devices}; - -pub use emulator_device::ADBEmulatorDevice; -pub use error::{Result, RustADBError}; - +/// MDNS-related definitions #[cfg(feature = "mdns")] #[cfg_attr(docsrs, doc(cfg(feature = "mdns")))] -pub use mdns::*; +pub mod mdns; -pub use models::{AdbStatResponse, RebootType}; -pub use server::*; -pub use server_device::ADBServerDevice; -pub use transports::*; +pub use adb_device_ext::ADBDeviceExt; +use adb_transport::ADBTransport; +pub use error::{Result, RustADBError}; +pub use message_devices::*; +pub use models::{AdbStatResponse, HostFeatures, RebootType}; diff --git a/adb_client/src/mdns/mdns_discovery.rs b/adb_client/src/mdns/mdns_discovery.rs index 39b4e67..0284faa 100644 --- a/adb_client/src/mdns/mdns_discovery.rs +++ b/adb_client/src/mdns/mdns_discovery.rs @@ -1,7 +1,7 @@ use mdns_sd::{ServiceDaemon, ServiceEvent}; use std::{sync::mpsc::Sender, thread::JoinHandle}; -use crate::{MDNSDevice, Result, RustADBError}; +use crate::{Result, RustADBError, mdns::MDNSDevice}; const ADB_SERVICE_NAME: &str = "_adb-tls-connect._tcp.local."; @@ -45,9 +45,9 @@ impl MDNSDiscoveryService { continue; } ServiceEvent::ServiceResolved(service_info) => { - if let Err(e) = sender.send(MDNSDevice::from(service_info)) { - return Err(e.into()); - } + return sender + .send(MDNSDevice::from(service_info)) + .map_err(|_| RustADBError::SendError); } } } diff --git a/adb_client/src/device/adb_message_device.rs b/adb_client/src/message_devices/adb_message_device.rs similarity index 96% rename from adb_client/src/device/adb_message_device.rs rename to adb_client/src/message_devices/adb_message_device.rs index e3036c9..fedbe8d 100644 --- a/adb_client/src/device/adb_message_device.rs +++ b/adb_client/src/message_devices/adb_message_device.rs @@ -2,9 +2,16 @@ use byteorder::{LittleEndian, ReadBytesExt}; use rand::Rng; use std::io::{Cursor, Read, Seek}; -use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE}; +use crate::{ + AdbStatResponse, Result, RustADBError, + message_devices::{ + adb_message_transport::ADBMessageTransport, + adb_transport_message::ADBTransportMessage, + message_commands::{MessageCommand, MessageSubcommand}, + }, +}; -use super::{ADBTransportMessage, MessageCommand, models::MessageSubcommand}; +const BUFFER_SIZE: usize = 65535; /// Generic structure representing an ADB device reachable over an [`ADBMessageTransport`]. /// Structure is totally agnostic over which transport is truly used. diff --git a/adb_client/src/device/adb_message_device_commands.rs b/adb_client/src/message_devices/adb_message_device_commands.rs similarity index 85% rename from adb_client/src/device/adb_message_device_commands.rs rename to adb_client/src/message_devices/adb_message_device_commands.rs index 994676e..dbb59cc 100644 --- a/adb_client/src/device/adb_message_device_commands.rs +++ b/adb_client/src/message_devices/adb_message_device_commands.rs @@ -1,11 +1,15 @@ -use crate::{ADBDeviceExt, ADBMessageTransport, RebootType, Result, models::AdbStatResponse}; +use crate::{ + ADBDeviceExt, RebootType, Result, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + }, + models::AdbStatResponse, +}; use std::{ io::{Read, Write}, path::Path, }; -use super::ADBMessageDevice; - impl ADBDeviceExt for ADBMessageDevice { fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> { self.shell_command(command, output) diff --git a/adb_client/src/transports/traits/adb_message_transport.rs b/adb_client/src/message_devices/adb_message_transport.rs similarity index 90% rename from adb_client/src/transports/traits/adb_message_transport.rs rename to adb_client/src/message_devices/adb_message_transport.rs index 67eefd5..d56b12a 100644 --- a/adb_client/src/transports/traits/adb_message_transport.rs +++ b/adb_client/src/message_devices/adb_message_transport.rs @@ -1,7 +1,9 @@ use std::time::Duration; -use super::ADBTransport; -use crate::{Result, device::ADBTransportMessage}; +use crate::{ + Result, adb_transport::ADBTransport, + message_devices::adb_transport_message::ADBTransportMessage, +}; const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(u64::MAX); const DEFAULT_WRITE_TIMEOUT: Duration = Duration::from_secs(2); diff --git a/adb_client/src/device/adb_transport_message.rs b/adb_client/src/message_devices/adb_transport_message.rs similarity index 97% rename from adb_client/src/device/adb_transport_message.rs rename to adb_client/src/message_devices/adb_transport_message.rs index 7971fea..31b532f 100644 --- a/adb_client/src/device/adb_transport_message.rs +++ b/adb_client/src/message_devices/adb_transport_message.rs @@ -1,8 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::{Result, RustADBError}; - -use super::models::MessageCommand; +use crate::{Result, RustADBError, message_devices::message_commands::MessageCommand}; #[derive(Debug)] pub struct ADBTransportMessage { diff --git a/adb_client/src/device/commands/framebuffer.rs b/adb_client/src/message_devices/commands/framebuffer.rs similarity index 94% rename from adb_client/src/device/commands/framebuffer.rs rename to adb_client/src/message_devices/commands/framebuffer.rs index d41422f..d824310 100644 --- a/adb_client/src/device/commands/framebuffer.rs +++ b/adb_client/src/message_devices/commands/framebuffer.rs @@ -4,8 +4,11 @@ use byteorder::{LittleEndian, ReadBytesExt}; use image::{ImageBuffer, Rgba}; use crate::{ - ADBMessageTransport, Result, RustADBError, - device::{MessageCommand, adb_message_device::ADBMessageDevice}, + Result, RustADBError, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + message_commands::MessageCommand, + }, models::{FrameBufferInfoV1, FrameBufferInfoV2}, }; diff --git a/adb_client/src/device/commands/install.rs b/adb_client/src/message_devices/commands/install.rs similarity index 87% rename from adb_client/src/device/commands/install.rs rename to adb_client/src/message_devices/commands/install.rs index 3e25b62..b3abb4e 100644 --- a/adb_client/src/device/commands/install.rs +++ b/adb_client/src/message_devices/commands/install.rs @@ -1,8 +1,11 @@ use std::{fs::File, path::Path}; use crate::{ - ADBMessageTransport, Result, - device::{MessageWriter, adb_message_device::ADBMessageDevice}, + Result, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + commands::utils::MessageWriter, + }, utils::check_extension_is_apk, }; diff --git a/adb_client/src/device/commands/mod.rs b/adb_client/src/message_devices/commands/mod.rs similarity index 89% rename from adb_client/src/device/commands/mod.rs rename to adb_client/src/message_devices/commands/mod.rs index d1d3de3..f1d698e 100644 --- a/adb_client/src/device/commands/mod.rs +++ b/adb_client/src/message_devices/commands/mod.rs @@ -6,3 +6,4 @@ mod reboot; mod shell; mod stat; mod uninstall; +mod utils; diff --git a/adb_client/src/device/commands/pull.rs b/adb_client/src/message_devices/commands/pull.rs similarity index 85% rename from adb_client/src/device/commands/pull.rs rename to adb_client/src/message_devices/commands/pull.rs index 9e5bc55..d7735df 100644 --- a/adb_client/src/device/commands/pull.rs +++ b/adb_client/src/message_devices/commands/pull.rs @@ -1,10 +1,12 @@ use std::io::Write; use crate::{ - ADBMessageTransport, Result, RustADBError, - device::{ - ADBTransportMessage, MessageCommand, adb_message_device::ADBMessageDevice, - models::MessageSubcommand, + Result, RustADBError, + message_devices::{ + adb_message_device::ADBMessageDevice, + adb_message_transport::ADBMessageTransport, + adb_transport_message::ADBTransportMessage, + message_commands::{MessageCommand, MessageSubcommand}, }, }; diff --git a/adb_client/src/device/commands/push.rs b/adb_client/src/message_devices/commands/push.rs similarity index 81% rename from adb_client/src/device/commands/push.rs rename to adb_client/src/message_devices/commands/push.rs index d87ee7a..6594839 100644 --- a/adb_client/src/device/commands/push.rs +++ b/adb_client/src/message_devices/commands/push.rs @@ -1,10 +1,12 @@ use std::io::Read; use crate::{ - ADBMessageTransport, Result, RustADBError, - device::{ - ADBTransportMessage, MessageCommand, MessageSubcommand, + Result, RustADBError, + message_devices::{ adb_message_device::ADBMessageDevice, + adb_message_transport::ADBMessageTransport, + adb_transport_message::ADBTransportMessage, + message_commands::{MessageCommand, MessageSubcommand}, }, }; diff --git a/adb_client/src/device/commands/reboot.rs b/adb_client/src/message_devices/commands/reboot.rs similarity index 66% rename from adb_client/src/device/commands/reboot.rs rename to adb_client/src/message_devices/commands/reboot.rs index 58438f2..ce46117 100644 --- a/adb_client/src/device/commands/reboot.rs +++ b/adb_client/src/message_devices/commands/reboot.rs @@ -1,6 +1,9 @@ use crate::{ - ADBMessageTransport, RebootType, Result, - device::{MessageCommand, adb_message_device::ADBMessageDevice}, + RebootType, Result, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + message_commands::MessageCommand, + }, }; impl ADBMessageDevice { diff --git a/adb_client/src/device/commands/shell.rs b/adb_client/src/message_devices/commands/shell.rs similarity index 90% rename from adb_client/src/device/commands/shell.rs rename to adb_client/src/message_devices/commands/shell.rs index 99dc873..426265c 100644 --- a/adb_client/src/device/commands/shell.rs +++ b/adb_client/src/message_devices/commands/shell.rs @@ -1,10 +1,12 @@ use std::io::{ErrorKind, Read, Write}; -use crate::Result; -use crate::device::ShellMessageWriter; use crate::{ - ADBMessageTransport, RustADBError, - device::{ADBMessageDevice, ADBTransportMessage, MessageCommand}, + Result, RustADBError, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + adb_transport_message::ADBTransportMessage, commands::utils::ShellMessageWriter, + message_commands::MessageCommand, + }, }; impl ADBMessageDevice { diff --git a/adb_client/src/device/commands/stat.rs b/adb_client/src/message_devices/commands/stat.rs similarity index 69% rename from adb_client/src/device/commands/stat.rs rename to adb_client/src/message_devices/commands/stat.rs index 27619b0..7da5896 100644 --- a/adb_client/src/device/commands/stat.rs +++ b/adb_client/src/message_devices/commands/stat.rs @@ -1,5 +1,8 @@ use crate::{ - ADBMessageTransport, AdbStatResponse, Result, device::adb_message_device::ADBMessageDevice, + AdbStatResponse, Result, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + }, }; impl ADBMessageDevice { diff --git a/adb_client/src/device/commands/uninstall.rs b/adb_client/src/message_devices/commands/uninstall.rs similarity index 81% rename from adb_client/src/device/commands/uninstall.rs rename to adb_client/src/message_devices/commands/uninstall.rs index d230446..1af47fd 100644 --- a/adb_client/src/device/commands/uninstall.rs +++ b/adb_client/src/message_devices/commands/uninstall.rs @@ -1,4 +1,9 @@ -use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageDevice}; +use crate::{ + Result, + message_devices::{ + adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport, + }, +}; impl ADBMessageDevice { pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> { diff --git a/adb_client/src/device/message_writer.rs b/adb_client/src/message_devices/commands/utils/message_writer.rs similarity index 88% rename from adb_client/src/device/message_writer.rs rename to adb_client/src/message_devices/commands/utils/message_writer.rs index 8345144..ae5f53a 100644 --- a/adb_client/src/device/message_writer.rs +++ b/adb_client/src/message_devices/commands/utils/message_writer.rs @@ -1,8 +1,9 @@ use std::io::{Error, ErrorKind, Result, Write}; -use crate::ADBMessageTransport; - -use super::{ADBTransportMessage, MessageCommand}; +use crate::message_devices::{ + adb_message_transport::ADBMessageTransport, adb_transport_message::ADBTransportMessage, + message_commands::MessageCommand, +}; /// [`Write`] trait implementation to hide underlying ADB protocol write logic. /// diff --git a/adb_client/src/message_devices/commands/utils/mod.rs b/adb_client/src/message_devices/commands/utils/mod.rs new file mode 100644 index 0000000..9a7fd27 --- /dev/null +++ b/adb_client/src/message_devices/commands/utils/mod.rs @@ -0,0 +1,4 @@ +mod message_writer; +mod shell_message_writer; +pub use message_writer::MessageWriter; +pub use shell_message_writer::ShellMessageWriter; diff --git a/adb_client/src/device/shell_message_writer.rs b/adb_client/src/message_devices/commands/utils/shell_message_writer.rs similarity index 85% rename from adb_client/src/device/shell_message_writer.rs rename to adb_client/src/message_devices/commands/utils/shell_message_writer.rs index 5533a1f..48fe49a 100644 --- a/adb_client/src/device/shell_message_writer.rs +++ b/adb_client/src/message_devices/commands/utils/shell_message_writer.rs @@ -1,8 +1,9 @@ use std::io::Write; -use crate::ADBMessageTransport; - -use super::{ADBTransportMessage, models::MessageCommand}; +use crate::message_devices::{ + adb_message_transport::ADBMessageTransport, adb_transport_message::ADBTransportMessage, + message_commands::MessageCommand, +}; /// [`Write`] trait implementation to hide underlying ADB protocol write logic for shell commands. pub struct ShellMessageWriter { diff --git a/adb_client/src/device/models/message_commands.rs b/adb_client/src/message_devices/message_commands.rs similarity index 100% rename from adb_client/src/device/models/message_commands.rs rename to adb_client/src/message_devices/message_commands.rs diff --git a/adb_client/src/message_devices/mod.rs b/adb_client/src/message_devices/mod.rs new file mode 100644 index 0000000..f7a105d --- /dev/null +++ b/adb_client/src/message_devices/mod.rs @@ -0,0 +1,14 @@ +/// USB-related definitions +#[cfg(feature = "usb")] +#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] +pub mod usb; + +/// Device reachable over TCP related definition +pub mod tcp; + +mod adb_message_device; +mod adb_message_device_commands; +mod adb_message_transport; +mod adb_transport_message; +mod commands; +mod message_commands; diff --git a/adb_client/src/device/adb_tcp_device.rs b/adb_client/src/message_devices/tcp/adb_tcp_device.rs similarity index 90% rename from adb_client/src/device/adb_tcp_device.rs rename to adb_client/src/message_devices/tcp/adb_tcp_device.rs index ac6b39f..75753a4 100644 --- a/adb_client/src/device/adb_tcp_device.rs +++ b/adb_client/src/message_devices/tcp/adb_tcp_device.rs @@ -2,10 +2,12 @@ use std::io::Write; use std::path::Path; use std::{io::Read, net::SocketAddr}; -use super::ADBTransportMessage; -use super::adb_message_device::ADBMessageDevice; -use super::models::MessageCommand; -use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, TcpTransport}; +use crate::message_devices::adb_message_device::ADBMessageDevice; +use crate::message_devices::adb_message_transport::ADBMessageTransport; +use crate::message_devices::adb_transport_message::ADBTransportMessage; +use crate::message_devices::message_commands::MessageCommand; +use crate::tcp::tcp_transport::TcpTransport; +use crate::{ADBDeviceExt, ADBTransport, Result}; /// Represent a device reached and available over USB. #[derive(Debug)] diff --git a/adb_client/src/message_devices/tcp/mod.rs b/adb_client/src/message_devices/tcp/mod.rs new file mode 100644 index 0000000..cd9a81d --- /dev/null +++ b/adb_client/src/message_devices/tcp/mod.rs @@ -0,0 +1,4 @@ +mod adb_tcp_device; +mod tcp_transport; + +pub use adb_tcp_device::ADBTcpDevice; diff --git a/adb_client/src/transports/tcp_transport.rs b/adb_client/src/message_devices/tcp/tcp_transport.rs similarity index 97% rename from adb_client/src/transports/tcp_transport.rs rename to adb_client/src/message_devices/tcp/tcp_transport.rs index 0fadef9..7e7379e 100644 --- a/adb_client/src/transports/tcp_transport.rs +++ b/adb_client/src/message_devices/tcp/tcp_transport.rs @@ -5,10 +5,14 @@ use rustls::{ pki_types::{CertificateDer, PrivatePkcs8KeyDer, pem::PemObject}, }; -use super::{ADBMessageTransport, ADBTransport}; use crate::{ Result, RustADBError, - device::{ADBTransportMessage, ADBTransportMessageHeader, MessageCommand}, + adb_transport::ADBTransport, + message_devices::{ + adb_message_transport::ADBMessageTransport, + adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader}, + message_commands::MessageCommand, + }, utils::get_default_adb_key_path, }; use std::{ @@ -210,7 +214,7 @@ impl ADBMessageTransport for TcpTransport { fn read_message_with_timeout( &mut self, read_timeout: std::time::Duration, - ) -> Result { + ) -> Result { let raw_connection_lock = self.get_current_connection()?; let mut raw_connection = raw_connection_lock.lock()?; diff --git a/adb_client/src/device/models/adb_rsa_key.rs b/adb_client/src/message_devices/usb/adb_rsa_key.rs similarity index 100% rename from adb_client/src/device/models/adb_rsa_key.rs rename to adb_client/src/message_devices/usb/adb_rsa_key.rs diff --git a/adb_client/src/device/adb_usb_device.rs b/adb_client/src/message_devices/usb/adb_usb_device.rs similarity index 95% rename from adb_client/src/device/adb_usb_device.rs rename to adb_client/src/message_devices/usb/adb_usb_device.rs index 0d14d25..4944955 100644 --- a/adb_client/src/device/adb_usb_device.rs +++ b/adb_client/src/message_devices/usb/adb_usb_device.rs @@ -9,14 +9,17 @@ use std::path::Path; use std::path::PathBuf; use std::time::Duration; -use super::adb_message_device::ADBMessageDevice; -use super::models::MessageCommand; -use super::{ADBRsaKey, ADBTransportMessage}; use crate::ADBDeviceExt; -use crate::ADBMessageTransport; -use crate::ADBTransport; +use crate::Result; +use crate::RustADBError; +use crate::adb_transport::ADBTransport; +use crate::message_devices::adb_message_device::ADBMessageDevice; +use crate::message_devices::adb_message_transport::ADBMessageTransport; +use crate::message_devices::adb_transport_message::ADBTransportMessage; +use crate::message_devices::message_commands::MessageCommand; +use crate::usb::adb_rsa_key::ADBRsaKey; +use crate::usb::usb_transport::USBTransport; use crate::utils::get_default_adb_key_path; -use crate::{Result, RustADBError, USBTransport}; const AUTH_TOKEN: u32 = 1; const AUTH_SIGNATURE: u32 = 2; diff --git a/adb_client/src/message_devices/usb/mod.rs b/adb_client/src/message_devices/usb/mod.rs new file mode 100644 index 0000000..29d3490 --- /dev/null +++ b/adb_client/src/message_devices/usb/mod.rs @@ -0,0 +1,6 @@ +mod adb_rsa_key; +mod adb_usb_device; +mod usb_transport; + +pub use adb_usb_device::ADBUSBDevice; +pub use usb_transport::USBTransport; diff --git a/adb_client/src/transports/usb_transport.rs b/adb_client/src/message_devices/usb/usb_transport.rs similarity index 97% rename from adb_client/src/transports/usb_transport.rs rename to adb_client/src/message_devices/usb/usb_transport.rs index 9f536cb..d1ccfe4 100644 --- a/adb_client/src/transports/usb_transport.rs +++ b/adb_client/src/message_devices/usb/usb_transport.rs @@ -5,10 +5,14 @@ use rusb::{ constants::LIBUSB_CLASS_VENDOR_SPEC, }; -use super::{ADBMessageTransport, ADBTransport}; use crate::{ Result, RustADBError, - device::{ADBTransportMessage, ADBTransportMessageHeader, MessageCommand}, + adb_transport::ADBTransport, + message_devices::{ + adb_message_transport::ADBMessageTransport, + adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader}, + message_commands::MessageCommand, + }, }; #[derive(Clone, Debug)] diff --git a/adb_client/src/models/host_features.rs b/adb_client/src/models/host_features.rs index 85fc22d..25db03a 100644 --- a/adb_client/src/models/host_features.rs +++ b/adb_client/src/models/host_features.rs @@ -1,8 +1,11 @@ use std::fmt::Display; +/// Available host features. #[derive(Debug, PartialEq)] pub enum HostFeatures { + /// Shell version 2. ShellV2, + /// Command. Cmd, } diff --git a/adb_client/src/models/mod.rs b/adb_client/src/models/mod.rs index 66f3cef..5dbc0be 100644 --- a/adb_client/src/models/mod.rs +++ b/adb_client/src/models/mod.rs @@ -1,15 +1,13 @@ mod adb_request_status; -mod adb_server_command; mod adb_stat_response; mod framebuffer_info; mod host_features; mod reboot_type; mod sync_command; -pub use adb_request_status::AdbRequestStatus; -pub(crate) use adb_server_command::AdbServerCommand; +pub(crate) use adb_request_status::AdbRequestStatus; pub use adb_stat_response::AdbStatResponse; pub(crate) use framebuffer_info::{FrameBufferInfoV1, FrameBufferInfoV2}; pub use host_features::HostFeatures; pub use reboot_type::RebootType; -pub use sync_command::SyncCommand; +pub(crate) use sync_command::SyncCommand; diff --git a/adb_client/src/server/adb_server.rs b/adb_client/src/server/adb_server.rs index 33b7987..5a12f61 100644 --- a/adb_client/src/server/adb_server.rs +++ b/adb_client/src/server/adb_server.rs @@ -1,7 +1,7 @@ use crate::ADBTransport; use crate::Result; use crate::RustADBError; -use crate::TCPServerTransport; +use crate::server::tcp_server_transport::TCPServerTransport; use std::collections::HashMap; use std::net::SocketAddrV4; use std::process::Command; diff --git a/adb_client/src/models/adb_server_command.rs b/adb_client/src/server/adb_server_command.rs similarity index 97% rename from adb_client/src/models/adb_server_command.rs rename to adb_client/src/server/adb_server_command.rs index 8790fbc..337981b 100644 --- a/adb_client/src/models/adb_server_command.rs +++ b/adb_client/src/server/adb_server_command.rs @@ -1,8 +1,10 @@ use std::fmt::Display; -use crate::{WaitForDeviceState, WaitForDeviceTransport}; +use crate::{ + RebootType, + server::{WaitForDeviceState, WaitForDeviceTransport}, +}; -use super::RebootType; use std::net::SocketAddrV4; pub(crate) enum AdbServerCommand { diff --git a/adb_client/src/server/commands/connect.rs b/adb_client/src/server/commands/connect.rs index 2dab419..70ca941 100644 --- a/adb_client/src/server/commands/connect.rs +++ b/adb_client/src/server/commands/connect.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand}; +use crate::{ + Result, RustADBError, + server::{ADBServer, AdbServerCommand}, +}; use std::net::SocketAddrV4; impl ADBServer { diff --git a/adb_client/src/server/commands/devices.rs b/adb_client/src/server/commands/devices.rs index 9c4dc2c..cdbc2b4 100644 --- a/adb_client/src/server/commands/devices.rs +++ b/adb_client/src/server/commands/devices.rs @@ -1,8 +1,10 @@ use std::io::Read; use crate::{ - ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong, DeviceShort, Result, RustADBError, - models::AdbServerCommand, + Result, RustADBError, + emulator::ADBEmulatorDevice, + server::{ADBServer, AdbServerCommand, DeviceLong, DeviceShort}, + server_device::ADBServerDevice, }; impl ADBServer { diff --git a/adb_client/src/server/commands/disconnect.rs b/adb_client/src/server/commands/disconnect.rs index 2d4ea1e..fdf072a 100644 --- a/adb_client/src/server/commands/disconnect.rs +++ b/adb_client/src/server/commands/disconnect.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand}; +use crate::{ + Result, RustADBError, + server::{ADBServer, AdbServerCommand}, +}; use std::net::SocketAddrV4; impl ADBServer { diff --git a/adb_client/src/server/commands/kill.rs b/adb_client/src/server/commands/kill.rs index 89f02f8..669665e 100644 --- a/adb_client/src/server/commands/kill.rs +++ b/adb_client/src/server/commands/kill.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, Result, models::AdbServerCommand}; +use crate::{ + Result, + server::{ADBServer, AdbServerCommand}, +}; impl ADBServer { /// Asks the ADB server to quit immediately. diff --git a/adb_client/src/server/commands/mdns.rs b/adb_client/src/server/commands/mdns.rs index 05a8f28..3be35ca 100644 --- a/adb_client/src/server/commands/mdns.rs +++ b/adb_client/src/server/commands/mdns.rs @@ -1,7 +1,8 @@ use std::io::BufRead; use crate::{ - ADBServer, MDNSServices, Result, models::AdbServerCommand, server::models::MDNSBackend, + Result, + server::{ADBServer, AdbServerCommand, MDNSServices, models::MDNSBackend}, }; const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN"; diff --git a/adb_client/src/server/commands/pair.rs b/adb_client/src/server/commands/pair.rs index bafbf7d..38d1de1 100644 --- a/adb_client/src/server/commands/pair.rs +++ b/adb_client/src/server/commands/pair.rs @@ -1,5 +1,7 @@ -use crate::models::AdbServerCommand; -use crate::{ADBServer, Result, RustADBError}; +use crate::{ + Result, RustADBError, + server::{ADBServer, AdbServerCommand}, +}; use std::net::SocketAddrV4; impl ADBServer { diff --git a/adb_client/src/server/commands/reconnect.rs b/adb_client/src/server/commands/reconnect.rs index aa24bbd..042fa18 100644 --- a/adb_client/src/server/commands/reconnect.rs +++ b/adb_client/src/server/commands/reconnect.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, Result, models::AdbServerCommand}; +use crate::{ + Result, + server::{ADBServer, AdbServerCommand}, +}; impl ADBServer { /// Reconnect the device diff --git a/adb_client/src/server/commands/server_status.rs b/adb_client/src/server/commands/server_status.rs index dcba402..d7eb158 100644 --- a/adb_client/src/server/commands/server_status.rs +++ b/adb_client/src/server/commands/server_status.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, Result, models::AdbServerCommand, server::models::ServerStatus}; +use crate::{ + Result, + server::{ADBServer, AdbServerCommand, models::ServerStatus}, +}; impl ADBServer { /// Check ADB server status diff --git a/adb_client/src/server/commands/version.rs b/adb_client/src/server/commands/version.rs index 8dd0a52..69ae171 100644 --- a/adb_client/src/server/commands/version.rs +++ b/adb_client/src/server/commands/version.rs @@ -1,4 +1,7 @@ -use crate::{ADBServer, AdbVersion, Result, models::AdbServerCommand}; +use crate::{ + Result, + server::{ADBServer, AdbServerCommand, AdbVersion}, +}; impl ADBServer { /// Gets server's internal version number. diff --git a/adb_client/src/server/commands/wait_for_device.rs b/adb_client/src/server/commands/wait_for_device.rs index abef15c..c89b019 100644 --- a/adb_client/src/server/commands/wait_for_device.rs +++ b/adb_client/src/server/commands/wait_for_device.rs @@ -1,5 +1,6 @@ use crate::{ - ADBServer, Result, WaitForDeviceState, WaitForDeviceTransport, models::AdbServerCommand, + Result, + server::{ADBServer, AdbServerCommand, WaitForDeviceState, WaitForDeviceTransport}, }; impl ADBServer { diff --git a/adb_client/src/server/mod.rs b/adb_client/src/server/mod.rs index d55f131..30d7341 100644 --- a/adb_client/src/server/mod.rs +++ b/adb_client/src/server/mod.rs @@ -1,6 +1,10 @@ mod adb_server; +mod adb_server_command; mod commands; mod models; +mod tcp_server_transport; pub use adb_server::ADBServer; +pub(crate) use adb_server_command::AdbServerCommand; pub use models::*; +pub use tcp_server_transport::TCPServerTransport; diff --git a/adb_client/src/server/models/device_long.rs b/adb_client/src/server/models/device_long.rs index d22050a..1ddab82 100644 --- a/adb_client/src/server/models/device_long.rs +++ b/adb_client/src/server/models/device_long.rs @@ -2,7 +2,8 @@ use std::str::FromStr; use std::sync::LazyLock; use std::{fmt::Display, str}; -use crate::{DeviceState, RustADBError}; +use crate::RustADBError; +use crate::server::DeviceState; use regex::bytes::Regex; static DEVICES_LONG_REGEX: LazyLock = LazyLock::new(|| { diff --git a/adb_client/src/server/models/device_short.rs b/adb_client/src/server/models/device_short.rs index 493cd6e..1759df0 100644 --- a/adb_client/src/server/models/device_short.rs +++ b/adb_client/src/server/models/device_short.rs @@ -1,7 +1,7 @@ use regex::bytes::Regex; use std::{fmt::Display, str::FromStr, sync::LazyLock}; -use crate::{DeviceState, RustADBError}; +use crate::{RustADBError, server::DeviceState}; static DEVICES_REGEX: LazyLock = LazyLock::new(|| Regex::new("^(\\S+)\t(\\w+)\n?$").expect("Cannot build devices regex")); diff --git a/adb_client/src/transports/tcp_server_transport.rs b/adb_client/src/server/tcp_server_transport.rs similarity index 98% rename from adb_client/src/transports/tcp_server_transport.rs rename to adb_client/src/server/tcp_server_transport.rs index 0b0c29b..b5129b9 100644 --- a/adb_client/src/transports/tcp_server_transport.rs +++ b/adb_client/src/server/tcp_server_transport.rs @@ -4,8 +4,9 @@ use std::str::FromStr; use byteorder::{ByteOrder, LittleEndian}; +use crate::ADBTransport; use crate::models::{AdbRequestStatus, SyncCommand}; -use crate::{ADBTransport, models::AdbServerCommand}; +use crate::server::AdbServerCommand; use crate::{Result, RustADBError}; const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1); diff --git a/adb_client/src/server_device/adb_server_device.rs b/adb_client/src/server_device/adb_server_device.rs index 1c8d480..1253ce9 100644 --- a/adb_client/src/server_device/adb_server_device.rs +++ b/adb_client/src/server_device/adb_server_device.rs @@ -1,4 +1,7 @@ -use crate::{ADBTransport, Result, TCPServerTransport, models::AdbServerCommand}; +use crate::{ + ADBTransport, Result, + server::{AdbServerCommand, TCPServerTransport}, +}; use std::net::SocketAddrV4; /// Represents a device connected to the ADB server. diff --git a/adb_client/src/server_device/adb_server_device_commands.rs b/adb_client/src/server_device/adb_server_device_commands.rs index b6ad638..1e90afb 100644 --- a/adb_client/src/server_device/adb_server_device_commands.rs +++ b/adb_client/src/server_device/adb_server_device_commands.rs @@ -5,12 +5,14 @@ use std::{ use crate::{ ADBDeviceExt, Result, RustADBError, - constants::BUFFER_SIZE, - models::{AdbServerCommand, AdbStatResponse, HostFeatures}, + models::{AdbStatResponse, HostFeatures}, + server::AdbServerCommand, }; use super::ADBServerDevice; +const BUFFER_SIZE: usize = 65535; + impl ADBDeviceExt for ADBServerDevice { fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> { let supported_features = self.host_features()?; diff --git a/adb_client/src/server_device/commands/forward.rs b/adb_client/src/server_device/commands/forward.rs index ff571f3..9bf1fb3 100644 --- a/adb_client/src/server_device/commands/forward.rs +++ b/adb_client/src/server_device/commands/forward.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Forward socket connection diff --git a/adb_client/src/server_device/commands/framebuffer.rs b/adb_client/src/server_device/commands/framebuffer.rs index b3a6e9f..5284226 100644 --- a/adb_client/src/server_device/commands/framebuffer.rs +++ b/adb_client/src/server_device/commands/framebuffer.rs @@ -4,8 +4,10 @@ use byteorder::{LittleEndian, ReadBytesExt}; use image::{ImageBuffer, Rgba}; use crate::{ - ADBServerDevice, Result, RustADBError, - models::{AdbServerCommand, FrameBufferInfoV1, FrameBufferInfoV2}, + Result, RustADBError, + models::{FrameBufferInfoV1, FrameBufferInfoV2}, + server::AdbServerCommand, + server_device::ADBServerDevice, }; impl ADBServerDevice { diff --git a/adb_client/src/server_device/commands/host_features.rs b/adb_client/src/server_device/commands/host_features.rs index 428b7eb..d01f74f 100644 --- a/adb_client/src/server_device/commands/host_features.rs +++ b/adb_client/src/server_device/commands/host_features.rs @@ -1,6 +1,5 @@ use crate::{ - ADBServerDevice, Result, - models::{AdbServerCommand, HostFeatures}, + Result, models::HostFeatures, server::AdbServerCommand, server_device::ADBServerDevice, }; impl ADBServerDevice { diff --git a/adb_client/src/server_device/commands/install.rs b/adb_client/src/server_device/commands/install.rs index 29a77ef..50e3610 100644 --- a/adb_client/src/server_device/commands/install.rs +++ b/adb_client/src/server_device/commands/install.rs @@ -1,7 +1,7 @@ use std::{fs::File, io::Read, path::Path}; use crate::{ - Result, models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk, + Result, server::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk, }; impl ADBServerDevice { diff --git a/adb_client/src/server_device/commands/list.rs b/adb_client/src/server_device/commands/list.rs index 54ceb02..c300cbc 100644 --- a/adb_client/src/server_device/commands/list.rs +++ b/adb_client/src/server_device/commands/list.rs @@ -1,6 +1,5 @@ use crate::{ - ADBServerDevice, Result, - models::{AdbServerCommand, SyncCommand}, + Result, models::SyncCommand, server::AdbServerCommand, server_device::ADBServerDevice, }; use byteorder::{ByteOrder, LittleEndian}; use std::{ diff --git a/adb_client/src/server_device/commands/logcat.rs b/adb_client/src/server_device/commands/logcat.rs index b2dc0d4..866bd29 100644 --- a/adb_client/src/server_device/commands/logcat.rs +++ b/adb_client/src/server_device/commands/logcat.rs @@ -1,6 +1,6 @@ use std::io::{self, Write}; -use crate::{ADBDeviceExt, ADBServerDevice, Result}; +use crate::{ADBDeviceExt, Result, server_device::ADBServerDevice}; struct LogFilter { writer: W, diff --git a/adb_client/src/server_device/commands/reboot.rs b/adb_client/src/server_device/commands/reboot.rs index 3829e83..a41b0b8 100644 --- a/adb_client/src/server_device/commands/reboot.rs +++ b/adb_client/src/server_device/commands/reboot.rs @@ -1,7 +1,4 @@ -use crate::{ - ADBServerDevice, Result, - models::{AdbServerCommand, RebootType}, -}; +use crate::{Result, models::RebootType, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Reboots the device diff --git a/adb_client/src/server_device/commands/reconnect.rs b/adb_client/src/server_device/commands/reconnect.rs index 03e889a..0c4abf7 100644 --- a/adb_client/src/server_device/commands/reconnect.rs +++ b/adb_client/src/server_device/commands/reconnect.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Reconnect device diff --git a/adb_client/src/server_device/commands/recv.rs b/adb_client/src/server_device/commands/recv.rs index d20fcee..c061a53 100644 --- a/adb_client/src/server_device/commands/recv.rs +++ b/adb_client/src/server_device/commands/recv.rs @@ -1,6 +1,5 @@ use crate::{ - ADBServerDevice, Result, constants, - models::{AdbServerCommand, SyncCommand}, + Result, models::SyncCommand, server::AdbServerCommand, server_device::ADBServerDevice, }; use byteorder::{LittleEndian, ReadBytesExt}; use std::io::{BufReader, BufWriter, Read, Write}; @@ -63,6 +62,8 @@ impl Read for ADBRecvCommandReader { } } +const BUFFER_SIZE: usize = 65535; + impl ADBServerDevice { /// Receives path to stream from the device. pub fn pull(&mut self, path: &dyn AsRef, stream: &mut dyn Write) -> Result<()> { @@ -92,8 +93,8 @@ impl ADBServerDevice { let reader = ADBRecvCommandReader::new(raw_connection); std::io::copy( - &mut BufReader::with_capacity(constants::BUFFER_SIZE, reader), - &mut BufWriter::with_capacity(constants::BUFFER_SIZE, output), + &mut BufReader::with_capacity(BUFFER_SIZE, reader), + &mut BufWriter::with_capacity(BUFFER_SIZE, output), )?; // Connection should've been left in SYNC mode by now diff --git a/adb_client/src/server_device/commands/reverse.rs b/adb_client/src/server_device/commands/reverse.rs index b7d06db..8541918 100644 --- a/adb_client/src/server_device/commands/reverse.rs +++ b/adb_client/src/server_device/commands/reverse.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Reverse socket connection diff --git a/adb_client/src/server_device/commands/send.rs b/adb_client/src/server_device/commands/send.rs index 3454c7e..ed4131b 100644 --- a/adb_client/src/server_device/commands/send.rs +++ b/adb_client/src/server_device/commands/send.rs @@ -1,6 +1,8 @@ use crate::{ - ADBServerDevice, Result, RustADBError, constants, - models::{AdbRequestStatus, AdbServerCommand, SyncCommand}, + Result, RustADBError, + models::{AdbRequestStatus, SyncCommand}, + server::AdbServerCommand, + server_device::ADBServerDevice, }; use std::{ convert::TryInto, @@ -40,6 +42,8 @@ impl Write for ADBSendCommandWriter { } } +const BUFFER_SIZE: usize = 65535; + impl ADBServerDevice { /// Send stream to path on the device. pub fn push>(&mut self, stream: R, path: A) -> Result<()> { @@ -71,8 +75,8 @@ impl ADBServerDevice { let writer = ADBSendCommandWriter::new(raw_connection); std::io::copy( - &mut BufReader::with_capacity(constants::BUFFER_SIZE, input), - &mut BufWriter::with_capacity(constants::BUFFER_SIZE, writer), + &mut BufReader::with_capacity(BUFFER_SIZE, input), + &mut BufWriter::with_capacity(BUFFER_SIZE, writer), )?; // Copy is finished, we can now notify as finished diff --git a/adb_client/src/server_device/commands/stat.rs b/adb_client/src/server_device/commands/stat.rs index 8e107fa..4554cf0 100644 --- a/adb_client/src/server_device/commands/stat.rs +++ b/adb_client/src/server_device/commands/stat.rs @@ -3,8 +3,8 @@ use std::io::{Read, Write}; use byteorder::{ByteOrder, LittleEndian}; use crate::{ - ADBServerDevice, Result, RustADBError, - models::{AdbServerCommand, AdbStatResponse, SyncCommand}, + AdbStatResponse, Result, RustADBError, models::SyncCommand, server::AdbServerCommand, + server_device::ADBServerDevice, }; impl ADBServerDevice { diff --git a/adb_client/src/server_device/commands/tcpip.rs b/adb_client/src/server_device/commands/tcpip.rs index 3cb01ed..5f4d6c9 100644 --- a/adb_client/src/server_device/commands/tcpip.rs +++ b/adb_client/src/server_device/commands/tcpip.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Set adb daemon to tcp/ip mode diff --git a/adb_client/src/server_device/commands/transport.rs b/adb_client/src/server_device/commands/transport.rs index 25b6ccb..29f429c 100644 --- a/adb_client/src/server_device/commands/transport.rs +++ b/adb_client/src/server_device/commands/transport.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Asks ADB server to switch the connection to either the device or emulator connect to/running on the host. Will fail if there is more than one such device/emulator available. diff --git a/adb_client/src/server_device/commands/uninstall.rs b/adb_client/src/server_device/commands/uninstall.rs index 32b8f95..2f8e9ef 100644 --- a/adb_client/src/server_device/commands/uninstall.rs +++ b/adb_client/src/server_device/commands/uninstall.rs @@ -1,6 +1,6 @@ use std::io::Read; -use crate::{Result, models::AdbServerCommand, server_device::ADBServerDevice}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Uninstall a package from device diff --git a/adb_client/src/server_device/commands/usb.rs b/adb_client/src/server_device/commands/usb.rs index e3c0ce2..df711a3 100644 --- a/adb_client/src/server_device/commands/usb.rs +++ b/adb_client/src/server_device/commands/usb.rs @@ -1,4 +1,4 @@ -use crate::{ADBServerDevice, Result, models::AdbServerCommand}; +use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice}; impl ADBServerDevice { /// Set adb daemon to usb mode diff --git a/adb_client/src/transports/mod.rs b/adb_client/src/transports/mod.rs deleted file mode 100644 index da50c1f..0000000 --- a/adb_client/src/transports/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod tcp_emulator_transport; -mod tcp_server_transport; -mod tcp_transport; -mod traits; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -mod usb_transport; - -pub use tcp_emulator_transport::TCPEmulatorTransport; -pub use tcp_server_transport::TCPServerTransport; -pub use tcp_transport::TcpTransport; -pub use traits::{ADBMessageTransport, ADBTransport}; - -#[cfg(feature = "usb")] -#[cfg_attr(docsrs, doc(cfg(feature = "usb")))] -pub use usb_transport::USBTransport; diff --git a/adb_client/src/transports/traits/mod.rs b/adb_client/src/transports/traits/mod.rs deleted file mode 100644 index e655c81..0000000 --- a/adb_client/src/transports/traits/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod adb_message_transport; -mod adb_transport; - -pub use adb_message_transport::ADBMessageTransport; -pub use adb_transport::ADBTransport; diff --git a/examples/mdns/src/main.rs b/examples/mdns/src/main.rs index 3f3da82..16861c1 100644 --- a/examples/mdns/src/main.rs +++ b/examples/mdns/src/main.rs @@ -1,7 +1,8 @@ -use adb_client::{MDNSDevice, MDNSDiscoveryService}; use std::sync::mpsc; use std::time::Duration; +use adb_client::mdns::{MDNSDevice, MDNSDiscoveryService}; + fn main() -> Result<(), Box> { println!("Starting mDNS device discovery..."); diff --git a/pyadb_client/src/adb_server.rs b/pyadb_client/src/adb_server.rs index abea3cd..201d9b8 100644 --- a/pyadb_client/src/adb_server.rs +++ b/pyadb_client/src/adb_server.rs @@ -1,6 +1,6 @@ use std::net::SocketAddrV4; -use adb_client::ADBServer; +use adb_client::server::ADBServer; use anyhow::Result; use pyo3::{PyResult, pyclass, pymethods}; use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods}; diff --git a/pyadb_client/src/adb_server_device.rs b/pyadb_client/src/adb_server_device.rs index e6fd207..27f979b 100644 --- a/pyadb_client/src/adb_server_device.rs +++ b/pyadb_client/src/adb_server_device.rs @@ -1,4 +1,4 @@ -use adb_client::{ADBDeviceExt, ADBServerDevice}; +use adb_client::{ADBDeviceExt, server_device::ADBServerDevice}; use anyhow::Result; use pyo3::{pyclass, pymethods}; use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods}; diff --git a/pyadb_client/src/adb_usb_device.rs b/pyadb_client/src/adb_usb_device.rs index ea3cf5e..44d2433 100644 --- a/pyadb_client/src/adb_usb_device.rs +++ b/pyadb_client/src/adb_usb_device.rs @@ -1,6 +1,6 @@ use std::{fs::File, path::PathBuf}; -use adb_client::{ADBDeviceExt, ADBUSBDevice}; +use adb_client::{ADBDeviceExt, usb::ADBUSBDevice}; use anyhow::Result; use pyo3::{pyclass, pymethods}; use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods}; diff --git a/pyadb_client/src/models/devices.rs b/pyadb_client/src/models/devices.rs index 3ace3ef..3ede677 100644 --- a/pyadb_client/src/models/devices.rs +++ b/pyadb_client/src/models/devices.rs @@ -1,4 +1,4 @@ -use adb_client::DeviceShort; +use adb_client::server::DeviceShort; use pyo3::{pyclass, pymethods}; use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods};