Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
with:
files: |
target/wheels/pyadb_client*.whl
target/wheels/pyadb_client*.tar.gz
target/wheels/pyadb_client*.tar.gz
6 changes: 3 additions & 3 deletions .github/workflows/rust-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v4
- name: Build project
run: cargo build --release --all-features
- uses: actions/checkout@v4
- name: Build project
run: cargo build --release --all-features
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ target
/.vscode
venv
/.mypy_cache
pyadb_client/pyadb_client.pyi
pyadb_client/pyadb_client.pyi
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["adb_cli", "adb_client", "pyadb_client"]
members = ["adb_cli", "adb_client", "examples/mdns", "pyadb_client"]
resolver = "2"

[workspace.package]
Expand All @@ -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.16"
version = "2.1.17"
rust-version = "1.85.1"

# To build locally when working on a new release
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Provides a "real-world" usage example of this library.

Improved documentation available [here](./adb_cli/README.md).

## examples

Some examples are available in the `examples` directory:

- `examples/mdns`: mDNS device discovery example

## pyadb_client

Python wrapper using `adb_client` library to export classes usable directly from a Python environment.
Expand Down
10 changes: 5 additions & 5 deletions adb_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
adb_client = { version = "^2.0.0" }
anyhow = { version = "1.0.94" }
clap = { version = "4.5.23", features = ["derive"] }
env_logger = { version = "0.11.5" }
log = { version = "0.4.26" }
adb_client = { version = "^2.1.17", features = ["mdns", "rusb"] }
anyhow = { version = "1.0.100" }
clap = { version = "4.5.49", features = ["derive"] }
env_logger = { version = "0.11.8" }
log = { version = "0.4.28" }

[target.'cfg(unix)'.dependencies]
termios = { version = "0.3.3" }
Expand Down
4 changes: 2 additions & 2 deletions adb_cli/src/adb_termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct ADBTermios {
}

impl ADBTermios {
pub fn new(fd: impl AsRawFd) -> Result<Self> {
pub fn new(fd: &impl AsRawFd) -> Result<Self> {
let mut new_termios = Termios::from_fd(fd.as_raw_fd())?;
let old_termios = new_termios; // Saves previous state
new_termios.c_lflag = 0;
Expand All @@ -36,7 +36,7 @@ impl Drop for ADBTermios {
fn drop(&mut self) {
// Custom drop implementation, restores previous termios structure.
if let Err(e) = tcsetattr(self.fd, TCSANOW, &self.old_termios) {
log::error!("Error while dropping ADBTermios: {e}")
log::error!("Error while dropping ADBTermios: {e}");
}
}
}
2 changes: 1 addition & 1 deletion adb_cli/src/handlers/emulator_commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use adb_client::ADBEmulatorDevice;
use adb_client::emulator::ADBEmulatorDevice;

use crate::models::{EmuCommand, EmulatorCommand};

Expand Down
18 changes: 12 additions & 6 deletions adb_cli/src/handlers/host_commands.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -53,12 +56,15 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
let server_status = adb_server.server_status()?;
match server_status.mdns_backend {
MDNSBackend::Unknown => log::info!("unknown mdns backend..."),
MDNSBackend::Bonjour => match check {
true => log::info!("mdns daemon version [Bonjour]"),
false => log::info!("ERROR: mdns daemon unavailable"),
},
MDNSBackend::Bonjour => {
if check {
log::info!("mdns daemon version [Bonjour]");
} else {
log::info!("ERROR: mdns daemon unavailable");
}
}
MDNSBackend::OpenScreen => {
log::info!("mdns daemon version [Openscreen discovery 0.0.0]")
log::info!("mdns daemon version [Openscreen discovery 0.0.0]");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions adb_cli/src/handlers/local_commands.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +14,7 @@ pub fn handle_local_commands(
let features = device
.host_features()?
.iter()
.map(|v| v.to_string())
.map(ToString::to_string)
.reduce(|a, b| format!("{a},{b}"))
.ok_or(anyhow!("cannot list features"))?;
log::info!("Available host features: {features}");
Expand Down
17 changes: 10 additions & 7 deletions adb_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +97,7 @@ fn main() -> Result<()> {
"Found device {} with addresses {:?}",
device.fullname,
device.addresses
)
);
}

return Ok(service.shutdown()?);
Expand All @@ -108,7 +111,7 @@ fn main() -> Result<()> {
// Using a scope here would call drop() too early..
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let mut adb_termios = ADBTermios::new(std::io::stdin())?;
let mut adb_termios = ADBTermios::new(&std::io::stdin())?;
adb_termios.set_adb_termios()?;
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
}
Expand All @@ -118,7 +121,7 @@ fn main() -> Result<()> {
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
}
} else {
let commands: Vec<&str> = commands.iter().map(|v| v.as_str()).collect();
let commands: Vec<&str> = commands.iter().map(String::as_str).collect();
device.shell_command(&commands, &mut std::io::stdout())?;
}
}
Expand All @@ -136,7 +139,7 @@ fn main() -> Result<()> {
}
DeviceCommands::Reboot { reboot_type } => {
log::info!("Reboots device in mode {reboot_type:?}");
device.reboot(reboot_type.into())?
device.reboot(reboot_type.into())?;
}
DeviceCommands::Push { filename, path } => {
let mut input = File::open(Path::new(&filename))?;
Expand Down
2 changes: 1 addition & 1 deletion adb_cli/src/models/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum DeviceCommands {
/// The package whose activity is to be invoked
#[clap(short = 'p', long = "package")]
package: String,
/// The activity to be invoked itself, Usually it is MainActivity
/// The activity to be invoked itself, Usually it is `MainActivity`
#[clap(short = 'a', long = "activity")]
activity: String,
},
Expand Down
2 changes: 1 addition & 1 deletion adb_cli/src/models/host.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
5 changes: 1 addition & 4 deletions adb_cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
pub unsafe fn setup_logger(debug: bool) {
// RUST_LOG variable has more priority then "--debug" flag
if std::env::var("RUST_LOG").is_err() {
let level = match debug {
true => "trace",
false => "info",
};
let level = if debug { "trace" } else { "info" };

unsafe { std::env::set_var("RUST_LOG", level) };
}
Expand Down
52 changes: 34 additions & 18 deletions adb_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,53 @@ repository.workspace = true
rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = []
mdns = ["dep:mdns-sd"]
rusb = ["dep:rsa", "dep:rusb"]

[dependencies]
base64 = { version = "0.22.1" }
bincode = { version = "1.3.3" }
byteorder = { version = "1.5.0" }
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",
] }
chrono = { version = "0.4.42", default-features = false, features = ["std"] }
homedir = { version = "=0.3.4" }
image = { version = "0.25.8", default-features = false }
log = { version = "0.4.28" }
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
num-traits = { version = "0.2.19" }
quick-protobuf = { version = "0.8.1" }
rand = { version = "0.9.0" }
rcgen = { version = "0.13.1", default-features = false, features = [
rand = { version = "0.9.2" }
rcgen = { version = "0.13.2", default-features = false, features = [
"aws_lc_rs",
"pem",
] }
regex = { version = "1.11.1", features = ["perf", "std", "unicode"] }
rsa = { version = "0.9.7" }
rusb = { version = "0.9.4", features = ["vendored"] }
rustls = { version = "0.23.27" }
rustls-pki-types = { version = "1.11.0" }
serde = { version = "1.0.216", features = ["derive"] }
serde_repr = { version = "0.1.19" }
regex = { version = "1.12.2", features = ["perf", "std", "unicode"] }
rustls = { version = "0.23.33" }
rustls-pki-types = { version = "1.12.0" }
serde = { version = "1.0.228", features = ["derive"] }
serde_repr = { version = "0.1.20" }
sha1 = { version = "0.10.6", features = ["oid"] }
thiserror = { version = "2.0.7" }
thiserror = { version = "2.0.17" }

#########
# MDNS dependencies
mdns-sd = { version = "0.13.11", default-features = false, features = [
"logging",
], optional = true }
#########
#########
# USB-only dependencies
rsa = { version = "0.9.7", optional = true }
rusb = { version = "0.9.4", features = ["vendored"], optional = true }
#########

[dev-dependencies]
anyhow = { version = "1.0.93" }
anyhow = { version = "1.0.100" }
criterion = { version = "0.6.0" } # Used for benchmarks

[[bench]]
Expand Down
Loading