Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36097fdc07 | ||
|
|
4ab0b01e37 | ||
|
|
ee3d879744 | ||
|
|
31d5388ffa | ||
|
|
f108b5ed5f | ||
|
|
46c8c54751 | ||
|
|
f616373ae2 | ||
|
|
c83df4309f | ||
|
|
88526aa943 | ||
|
|
8cce59193c | ||
|
|
e0b6bb0139 | ||
|
|
373a5265a0 | ||
|
|
060e43590d | ||
|
|
f51ba984ca | ||
|
|
66ebc8a030 |
2
.github/workflows/python-build.yml
vendored
2
.github/workflows/python-build.yml
vendored
@@ -35,4 +35,4 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
target/wheels/pyadb_client*.whl
|
target/wheels/pyadb_client*.whl
|
||||||
target/wheels/pyadb_client*.tar.gz
|
target/wheels/pyadb_client*.tar.gz
|
||||||
6
.github/workflows/rust-build.yml
vendored
6
.github/workflows/rust-build.yml
vendored
@@ -19,5 +19,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.10"
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: cargo build --release --all-features
|
run: cargo build --release --all-features
|
||||||
|
|||||||
5
.github/workflows/rust-release.yml
vendored
5
.github/workflows/rust-release.yml
vendored
@@ -92,6 +92,11 @@ jobs:
|
|||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: "3.10"
|
||||||
|
|
||||||
- name: Build release
|
- name: Build release
|
||||||
run: cargo build --all-features --release
|
run: cargo build --all-features --release
|
||||||
|
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,4 +3,4 @@ target
|
|||||||
/.vscode
|
/.vscode
|
||||||
venv
|
venv
|
||||||
/.mypy_cache
|
/.mypy_cache
|
||||||
pyadb_client/pyadb_client.pyi
|
pyadb_client/pyadb_client.pyi
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["adb_cli", "adb_client", "examples/mdns", "pyadb_client"]
|
members = ["adb_cli", "adb_client", "pyadb_client"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
|||||||
keywords = ["adb", "android", "tcp", "usb"]
|
keywords = ["adb", "android", "tcp", "usb"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/cocool97/adb_client"
|
repository = "https://github.com/cocool97/adb_client"
|
||||||
version = "2.1.16"
|
version = "2.1.18"
|
||||||
rust-version = "1.85.1"
|
rust-version = "1.85.1"
|
||||||
|
|
||||||
# To build locally when working on a new release
|
# To build locally when working on a new release
|
||||||
|
|||||||
@@ -49,12 +49,6 @@ Provides a "real-world" usage example of this library.
|
|||||||
|
|
||||||
Improved documentation available [here](./adb_cli/README.md).
|
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
|
## pyadb_client
|
||||||
|
|
||||||
Python wrapper using `adb_client` library to export classes usable directly from a Python environment.
|
Python wrapper using `adb_client` library to export classes usable directly from a Python environment.
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ rust-version.workspace = true
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
adb_client = { version = "^2.0.0", features = ["mdns", "usb"] }
|
adb_client = { version = "^2.1.17" }
|
||||||
anyhow = { version = "1.0.94" }
|
anyhow = { version = "1.0.100" }
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.51", features = ["derive"] }
|
||||||
env_logger = { version = "0.11.5" }
|
env_logger = { version = "0.11.8" }
|
||||||
log = { version = "0.4.26" }
|
log = { version = "0.4.28" }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
termios = { version = "0.3.3" }
|
termios = { version = "0.3.3" }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ pub struct ADBTermios {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 mut new_termios = Termios::from_fd(fd.as_raw_fd())?;
|
||||||
let old_termios = new_termios; // Saves previous state
|
let old_termios = new_termios; // Saves previous state
|
||||||
new_termios.c_lflag = 0;
|
new_termios.c_lflag = 0;
|
||||||
@@ -36,7 +36,7 @@ impl Drop for ADBTermios {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Custom drop implementation, restores previous termios structure.
|
// Custom drop implementation, restores previous termios structure.
|
||||||
if let Err(e) = tcsetattr(self.fd, TCSANOW, &self.old_termios) {
|
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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use adb_client::emulator::ADBEmulatorDevice;
|
use adb_client::ADBEmulatorDevice;
|
||||||
|
|
||||||
use crate::models::{EmuCommand, EmulatorCommand};
|
use crate::models::{EmuCommand, EmulatorCommand};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use adb_client::{
|
use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result, WaitForDeviceState};
|
||||||
Result,
|
|
||||||
server::{ADBServer, DeviceShort, MDNSBackend, WaitForDeviceState},
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::models::{HostCommand, MdnsCommand, ServerCommand};
|
use crate::models::{HostCommand, MdnsCommand, ServerCommand};
|
||||||
|
|
||||||
@@ -56,12 +53,15 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
|||||||
let server_status = adb_server.server_status()?;
|
let server_status = adb_server.server_status()?;
|
||||||
match server_status.mdns_backend {
|
match server_status.mdns_backend {
|
||||||
MDNSBackend::Unknown => log::info!("unknown mdns backend..."),
|
MDNSBackend::Unknown => log::info!("unknown mdns backend..."),
|
||||||
MDNSBackend::Bonjour => match check {
|
MDNSBackend::Bonjour => {
|
||||||
true => log::info!("mdns daemon version [Bonjour]"),
|
if check {
|
||||||
false => log::info!("ERROR: mdns daemon unavailable"),
|
log::info!("mdns daemon version [Bonjour]");
|
||||||
},
|
} else {
|
||||||
|
log::info!("ERROR: mdns daemon unavailable");
|
||||||
|
}
|
||||||
|
}
|
||||||
MDNSBackend::OpenScreen => {
|
MDNSBackend::OpenScreen => {
|
||||||
log::info!("mdns daemon version [Openscreen discovery 0.0.0]")
|
log::info!("mdns daemon version [Openscreen discovery 0.0.0]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{fs::File, io::Write};
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
use adb_client::server_device::ADBServerDevice;
|
use adb_client::ADBServerDevice;
|
||||||
use anyhow::{Result, anyhow};
|
use anyhow::{Result, anyhow};
|
||||||
|
|
||||||
use crate::models::LocalDeviceCommand;
|
use crate::models::LocalDeviceCommand;
|
||||||
@@ -14,7 +14,7 @@ pub fn handle_local_commands(
|
|||||||
let features = device
|
let features = device
|
||||||
.host_features()?
|
.host_features()?
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| v.to_string())
|
.map(ToString::to_string)
|
||||||
.reduce(|a, b| format!("{a},{b}"))
|
.reduce(|a, b| format!("{a},{b}"))
|
||||||
.ok_or(anyhow!("cannot list features"))?;
|
.ok_or(anyhow!("cannot list features"))?;
|
||||||
log::info!("Available host features: {features}");
|
log::info!("Available host features: {features}");
|
||||||
|
|||||||
@@ -7,12 +7,9 @@ mod handlers;
|
|||||||
mod models;
|
mod models;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use adb_client::ADBDeviceExt;
|
use adb_client::{
|
||||||
use adb_client::mdns::MDNSDiscoveryService;
|
ADBDeviceExt, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice, 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"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
use adb_termios::ADBTermios;
|
use adb_termios::ADBTermios;
|
||||||
@@ -82,7 +79,10 @@ fn main() -> Result<()> {
|
|||||||
(device.boxed(), usb_command.commands)
|
(device.boxed(), usb_command.commands)
|
||||||
}
|
}
|
||||||
MainCommand::Tcp(tcp_command) => {
|
MainCommand::Tcp(tcp_command) => {
|
||||||
let device = ADBTcpDevice::new(tcp_command.address)?;
|
let device = match tcp_command.path_to_private_key {
|
||||||
|
Some(pk) => ADBTcpDevice::new_with_custom_private_key(tcp_command.address, pk)?,
|
||||||
|
None => ADBTcpDevice::new(tcp_command.address)?,
|
||||||
|
};
|
||||||
(device.boxed(), tcp_command.commands)
|
(device.boxed(), tcp_command.commands)
|
||||||
}
|
}
|
||||||
MainCommand::Mdns => {
|
MainCommand::Mdns => {
|
||||||
@@ -97,7 +97,7 @@ fn main() -> Result<()> {
|
|||||||
"Found device {} with addresses {:?}",
|
"Found device {} with addresses {:?}",
|
||||||
device.fullname,
|
device.fullname,
|
||||||
device.addresses
|
device.addresses
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(service.shutdown()?);
|
return Ok(service.shutdown()?);
|
||||||
@@ -111,7 +111,7 @@ fn main() -> Result<()> {
|
|||||||
// Using a scope here would call drop() too early..
|
// Using a scope here would call drop() too early..
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[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()?;
|
adb_termios.set_adb_termios()?;
|
||||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ fn main() -> Result<()> {
|
|||||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
|
||||||
}
|
}
|
||||||
} else {
|
} 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())?;
|
device.shell_command(&commands, &mut std::io::stdout())?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
DeviceCommands::Reboot { reboot_type } => {
|
DeviceCommands::Reboot { reboot_type } => {
|
||||||
log::info!("Reboots device in mode {reboot_type:?}");
|
log::info!("Reboots device in mode {reboot_type:?}");
|
||||||
device.reboot(reboot_type.into())?
|
device.reboot(reboot_type.into())?;
|
||||||
}
|
}
|
||||||
DeviceCommands::Push { filename, path } => {
|
DeviceCommands::Push { filename, path } => {
|
||||||
let mut input = File::open(Path::new(&filename))?;
|
let mut input = File::open(Path::new(&filename))?;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ pub enum DeviceCommands {
|
|||||||
/// The package whose activity is to be invoked
|
/// The package whose activity is to be invoked
|
||||||
#[clap(short = 'p', long = "package")]
|
#[clap(short = 'p', long = "package")]
|
||||||
package: String,
|
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")]
|
#[clap(short = 'a', long = "activity")]
|
||||||
activity: String,
|
activity: String,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
use adb_client::{RustADBError, server::WaitForDeviceTransport};
|
use adb_client::{RustADBError, WaitForDeviceTransport};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
fn parse_wait_for_device_device_transport(
|
fn parse_wait_for_device_device_transport(
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use super::DeviceCommands;
|
use super::DeviceCommands;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub struct TcpCommand {
|
pub struct TcpCommand {
|
||||||
pub address: SocketAddr,
|
pub address: SocketAddr,
|
||||||
|
/// Path to a custom private key to use for authentication
|
||||||
|
#[clap(short = 'k', long = "private-key")]
|
||||||
|
pub path_to_private_key: Option<PathBuf>,
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub commands: DeviceCommands,
|
pub commands: DeviceCommands,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,7 @@
|
|||||||
pub unsafe fn setup_logger(debug: bool) {
|
pub unsafe fn setup_logger(debug: bool) {
|
||||||
// RUST_LOG variable has more priority then "--debug" flag
|
// RUST_LOG variable has more priority then "--debug" flag
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
let level = match debug {
|
let level = if debug { "trace" } else { "info" };
|
||||||
true => "trace",
|
|
||||||
false => "info",
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe { std::env::set_var("RUST_LOG", level) };
|
unsafe { std::env::set_var("RUST_LOG", level) };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,54 +10,34 @@ repository.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
all-features = true
|
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = []
|
|
||||||
mdns = ["dep:mdns-sd"]
|
|
||||||
usb = ["dep:rsa", "dep:rusb"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = { version = "0.22.1" }
|
base64 = { version = "0.22.1" }
|
||||||
bincode = { version = "1.3.3" }
|
bincode = { version = "2.0.1", features = ["serde"] }
|
||||||
byteorder = { version = "1.5.0" }
|
byteorder = { version = "1.5.0" }
|
||||||
chrono = { version = "0.4.40", default-features = false, features = ["std"] }
|
chrono = { version = "0.4.42", default-features = false, features = ["std"] }
|
||||||
homedir = { version = "= 0.3.4" }
|
image = { version = "0.25.8", default-features = false }
|
||||||
image = { version = "0.25.5", default-features = false }
|
log = { version = "0.4.28" }
|
||||||
log = { version = "0.4.26" }
|
mdns-sd = { version = "0.17.0", default-features = false, features = [
|
||||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
"logging",
|
||||||
|
] }
|
||||||
|
num-bigint = { version = "0.8.5", package = "num-bigint-dig" }
|
||||||
num-traits = { version = "0.2.19" }
|
num-traits = { version = "0.2.19" }
|
||||||
quick-protobuf = { version = "0.8.1" }
|
quick-protobuf = { version = "0.8.1" }
|
||||||
rand = { version = "0.9.0" }
|
rand = { version = "0.9.2" }
|
||||||
rcgen = { version = "0.13.1", default-features = false, features = [
|
rcgen = { version = "0.14.5" }
|
||||||
"aws_lc_rs",
|
regex = { version = "1.12.2", features = ["perf", "std", "unicode"] }
|
||||||
"pem",
|
rsa = { version = "0.9.8" }
|
||||||
] }
|
rusb = { version = "0.9.4", features = ["vendored"] }
|
||||||
regex = { version = "1.11.1", features = ["perf", "std", "unicode"] }
|
rustls = { version = "0.23.35" }
|
||||||
rustls = { version = "0.23.27" }
|
rustls-pki-types = { version = "1.13.0" }
|
||||||
rustls-pki-types = { version = "1.11.0" }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde_repr = { version = "0.1.20" }
|
||||||
serde_repr = { version = "0.1.19" }
|
|
||||||
sha1 = { version = "0.10.6", features = ["oid"] }
|
sha1 = { version = "0.10.6", features = ["oid"] }
|
||||||
thiserror = { version = "2.0.7" }
|
thiserror = { version = "2.0.17" }
|
||||||
|
|
||||||
#########
|
|
||||||
# MDNS-only dependencies
|
|
||||||
mdns-sd = { version = "0.13.9", 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]
|
[dev-dependencies]
|
||||||
anyhow = { version = "1.0.93" }
|
anyhow = { version = "1.0.100" }
|
||||||
criterion = { version = "0.6.0" } # Used for benchmarks
|
criterion = { version = "0.7.0" } # Used for benchmarks
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
harness = false
|
harness = false
|
||||||
|
|||||||
@@ -16,26 +16,6 @@ Add `adb_client` crate as a dependency by simply adding it to your `Cargo.toml`:
|
|||||||
adb_client = "*"
|
adb_client = "*"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Crate features
|
|
||||||
|
|
||||||
| Feature | Description | Default? |
|
|
||||||
| :-----: | :---------------------------------------------: | :------: |
|
|
||||||
| `mdns` | Enables mDNS device discovery on local network. | No |
|
|
||||||
| `usb` | Enables interactions with USB devices. | No |
|
|
||||||
|
|
||||||
To deactivate some features you can use the `default-features = false` option in your `Cargo.toml` file and manually specify the features you want to activate:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
adb_client = { version = "*" }
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
Usage examples can be found in the `examples/` directory of this repository.
|
|
||||||
|
|
||||||
Some example are also provided in the various `README.md` files of modules.
|
|
||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
|
|
||||||
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
||||||
@@ -44,8 +24,89 @@ Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel
|
|||||||
|
|
||||||
`ADBServerDevice` performs all operations by using adb server as a bridge.
|
`ADBServerDevice` performs all operations by using adb server as a bridge.
|
||||||
|
|
||||||
| File size | Sample size | `ADBServerDevice` | `adb` | Difference |
|
|File size|Sample size|`ADBServerDevice`|`adb`|Difference|
|
||||||
| :-------: | :---------: | :---------------: | :-------: | :------------------------------------: |
|
|:-------:|:---------:|:----------:|:---:|:-----:|
|
||||||
| 10 MB | 100 | 350,79 ms | 356,30 ms | <div style="color:green">-1,57 %</div> |
|
|10 MB|100|350,79 ms|356,30 ms|<div style="color:green">-1,57 %</div>|
|
||||||
| 500 MB | 50 | 15,60 s | 15,64 s | <div style="color:green">-0,25 %</div> |
|
|500 MB|50|15,60 s|15,64 s|<div style="color:green">-0,25 %</div>|
|
||||||
| 1 GB | 20 | 31,09 s | 31,12 s | <div style="color:green">-0,10 %</div> |
|
|1 GB|20|31,09 s|31,12 s|<div style="color:green">-0,10 %</div>|
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Get available ADB devices
|
||||||
|
|
||||||
|
```rust no_run
|
||||||
|
use adb_client::ADBServer;
|
||||||
|
use std::net::{SocketAddrV4, Ipv4Addr};
|
||||||
|
|
||||||
|
// A custom server address can be provided
|
||||||
|
let server_ip = Ipv4Addr::new(127, 0, 0, 1);
|
||||||
|
let server_port = 5037;
|
||||||
|
|
||||||
|
let mut server = ADBServer::new(SocketAddrV4::new(server_ip, server_port));
|
||||||
|
server.devices();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using ADB server as bridge
|
||||||
|
|
||||||
|
#### Launch a command on device
|
||||||
|
|
||||||
|
```rust no_run
|
||||||
|
use adb_client::{ADBServer, ADBDeviceExt};
|
||||||
|
|
||||||
|
let mut server = ADBServer::default();
|
||||||
|
let mut device = server.get_device().expect("cannot get device");
|
||||||
|
device.shell_command(&["df", "-h"], &mut std::io::stdout());
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Push a file to the device
|
||||||
|
|
||||||
|
```rust no_run
|
||||||
|
use adb_client::ADBServer;
|
||||||
|
use std::net::Ipv4Addr;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
let mut server = ADBServer::default();
|
||||||
|
let mut device = server.get_device().expect("cannot get device");
|
||||||
|
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
|
||||||
|
device.push(&mut input, "/data/local/tmp");
|
||||||
|
```
|
||||||
|
|
||||||
|
### Interact directly with end devices
|
||||||
|
|
||||||
|
#### (USB) Launch a command on device
|
||||||
|
|
||||||
|
```rust no_run
|
||||||
|
use adb_client::{ADBUSBDevice, ADBDeviceExt};
|
||||||
|
|
||||||
|
let vendor_id = 0x04e8;
|
||||||
|
let product_id = 0x6860;
|
||||||
|
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
||||||
|
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 std::fs::File;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
let vendor_id = 0x04e8;
|
||||||
|
let product_id = 0x6860;
|
||||||
|
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
||||||
|
let mut input = File::open(Path::new("/tmp/f")).expect("Cannot open file");
|
||||||
|
device.push(&mut input, &"/data/local/tmp");
|
||||||
|
```
|
||||||
|
|
||||||
|
#### (TCP) Get a shell from device
|
||||||
|
|
||||||
|
```rust no_run
|
||||||
|
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
||||||
|
use adb_client::{ADBTcpDevice, ADBDeviceExt};
|
||||||
|
|
||||||
|
let device_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 10));
|
||||||
|
let device_port = 43210;
|
||||||
|
let mut device = ADBTcpDevice::new(SocketAddr::new(device_ip, device_port)).expect("cannot find device");
|
||||||
|
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()));
|
||||||
|
```
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use image::{ImageBuffer, ImageFormat, Rgba};
|
|||||||
use crate::models::AdbStatResponse;
|
use crate::models::AdbStatResponse;
|
||||||
use crate::{RebootType, Result};
|
use crate::{RebootType, Result};
|
||||||
|
|
||||||
/// Trait representing all features available on both [`crate::server_device::ADBServerDevice`] and [`crate::usb::ADBUSBDevice`]
|
/// Trait representing all features available on both [`crate::ADBServerDevice`] and [`crate::ADBUSBDevice`]
|
||||||
pub trait ADBDeviceExt {
|
pub trait ADBDeviceExt {
|
||||||
/// Runs command in a shell on the device, and write its output and error streams into output.
|
/// 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<()>;
|
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()>;
|
||||||
|
|||||||
1
adb_client/src/constants.rs
Normal file
1
adb_client/src/constants.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub const BUFFER_SIZE: usize = 65536;
|
||||||
@@ -1,17 +1,26 @@
|
|||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use super::{ADBRsaKey, ADBTransportMessage, MessageCommand, models::MessageSubcommand};
|
||||||
|
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
||||||
|
use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE};
|
||||||
|
use bincode::config::{Configuration, Fixint, LittleEndian, NoLimit};
|
||||||
|
use byteorder::ReadBytesExt;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use serde::Serialize;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::{
|
const BINCODE_CONFIG: Configuration<LittleEndian, Fixint, NoLimit> = bincode::config::legacy();
|
||||||
AdbStatResponse, Result, RustADBError,
|
|
||||||
message_devices::{
|
|
||||||
adb_message_transport::ADBMessageTransport,
|
|
||||||
adb_transport_message::ADBTransportMessage,
|
|
||||||
message_commands::{MessageCommand, MessageSubcommand},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 65535;
|
pub(crate) fn bincode_serialize_to_vec<E: Serialize>(val: E) -> Result<Vec<u8>> {
|
||||||
|
bincode::serde::encode_to_vec(val, BINCODE_CONFIG).map_err(|_e| RustADBError::ConversionError)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn bincode_deserialize_from_slice<D: DeserializeOwned>(data: &[u8]) -> Result<D> {
|
||||||
|
let (response, _) = bincode::serde::decode_from_slice(data, BINCODE_CONFIG)
|
||||||
|
.map_err(|_e| RustADBError::ConversionError)?;
|
||||||
|
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
|
||||||
/// Generic structure representing an ADB device reachable over an [`ADBMessageTransport`].
|
/// Generic structure representing an ADB device reachable over an [`ADBMessageTransport`].
|
||||||
/// Structure is totally agnostic over which transport is truly used.
|
/// Structure is totally agnostic over which transport is truly used.
|
||||||
@@ -40,6 +49,66 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
&mut self.transport
|
&mut self.transport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn auth_handshake(
|
||||||
|
&mut self,
|
||||||
|
message: ADBTransportMessage,
|
||||||
|
private_key: &ADBRsaKey,
|
||||||
|
) -> Result<()> {
|
||||||
|
match message.header().command() {
|
||||||
|
MessageCommand::Auth => {
|
||||||
|
log::debug!("Authentication required");
|
||||||
|
}
|
||||||
|
_ => return Ok(()),
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point, we should have received an AUTH message with arg0 == 1
|
||||||
|
let auth_message = match message.header().arg0() {
|
||||||
|
AUTH_TOKEN => message,
|
||||||
|
v => {
|
||||||
|
return Err(RustADBError::ADBRequestFailed(format!(
|
||||||
|
"Received AUTH message with type != 1 ({v})"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let sign = private_key.sign(auth_message.into_payload())?;
|
||||||
|
|
||||||
|
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_SIGNATURE, 0, &sign);
|
||||||
|
|
||||||
|
self.get_transport_mut().write_message(message)?;
|
||||||
|
|
||||||
|
let received_response = self.get_transport_mut().read_message()?;
|
||||||
|
|
||||||
|
if received_response.header().command() == MessageCommand::Cnxn {
|
||||||
|
log::info!(
|
||||||
|
"Authentication OK, device info {}",
|
||||||
|
String::from_utf8(received_response.into_payload())?
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut pubkey = private_key.android_pubkey_encode()?.into_bytes();
|
||||||
|
pubkey.push(b'\0');
|
||||||
|
|
||||||
|
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_RSAPUBLICKEY, 0, &pubkey);
|
||||||
|
|
||||||
|
self.get_transport_mut().write_message(message)?;
|
||||||
|
|
||||||
|
let response = self
|
||||||
|
.get_transport_mut()
|
||||||
|
.read_message_with_timeout(Duration::from_secs(10))
|
||||||
|
.and_then(|message| {
|
||||||
|
message.assert_command(MessageCommand::Cnxn)?;
|
||||||
|
Ok(message)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
log::info!(
|
||||||
|
"Authentication OK, device info {}",
|
||||||
|
String::from_utf8(response.into_payload())?
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Receive a message and acknowledge it by replying with an `OKAY` command
|
/// Receive a message and acknowledge it by replying with an `OKAY` command
|
||||||
pub(crate) fn recv_and_reply_okay(&mut self) -> Result<ADBTransportMessage> {
|
pub(crate) fn recv_and_reply_okay(&mut self) -> Result<ADBTransportMessage> {
|
||||||
let message = self.transport.read_message()?;
|
let message = self.transport.read_message()?;
|
||||||
@@ -77,7 +146,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
match len.take() {
|
match len.take() {
|
||||||
Some(0) | None => {
|
Some(0) | None => {
|
||||||
rdr.seek_relative(4)?;
|
rdr.seek_relative(4)?;
|
||||||
len.replace(rdr.read_u32::<LittleEndian>()? as u64);
|
len.replace(u64::from(rdr.read_u32::<byteorder::LittleEndian>()?));
|
||||||
}
|
}
|
||||||
Some(length) => {
|
Some(length) => {
|
||||||
let remaining_bytes = payload.len() as u64 - rdr.position();
|
let remaining_bytes = payload.len() as u64 - rdr.position();
|
||||||
@@ -93,7 +162,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if Cursor::new(&payload[(payload.len() - 8)..(payload.len() - 4)])
|
if Cursor::new(&payload[(payload.len() - 8)..(payload.len() - 4)])
|
||||||
.read_u32::<LittleEndian>()?
|
.read_u32::<byteorder::LittleEndian>()?
|
||||||
== MessageSubcommand::Done as u32
|
== MessageSubcommand::Done as u32
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@@ -108,12 +177,11 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
remote_id: u32,
|
remote_id: u32,
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
) -> std::result::Result<(), RustADBError> {
|
) -> std::result::Result<(), RustADBError> {
|
||||||
let mut buffer = [0; BUFFER_SIZE];
|
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
||||||
let amount_read = reader.read(&mut buffer)?;
|
let amount_read = reader.read(&mut buffer)?;
|
||||||
let subcommand_data = MessageSubcommand::Data.with_arg(amount_read as u32);
|
let subcommand_data = MessageSubcommand::Data.with_arg(u32::try_from(amount_read)?);
|
||||||
|
|
||||||
let mut serialized_message =
|
let mut serialized_message = bincode_serialize_to_vec(&subcommand_data)?;
|
||||||
bincode::serialize(&subcommand_data).map_err(|_e| RustADBError::ConversionError)?;
|
|
||||||
serialized_message.append(&mut buffer[..amount_read].to_vec());
|
serialized_message.append(&mut buffer[..amount_read].to_vec());
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
@@ -126,16 +194,14 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
self.send_and_expect_okay(message)?;
|
self.send_and_expect_okay(message)?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = [0; BUFFER_SIZE];
|
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
||||||
|
|
||||||
match reader.read(&mut buffer) {
|
match reader.read(&mut buffer) {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
// Currently file mtime is not forwarded
|
// Currently file mtime is not forwarded
|
||||||
let subcommand_data = MessageSubcommand::Done.with_arg(0);
|
let subcommand_data = MessageSubcommand::Done.with_arg(0);
|
||||||
|
|
||||||
let serialized_message = bincode::serialize(&subcommand_data)
|
let serialized_message = bincode_serialize_to_vec(&subcommand_data)?;
|
||||||
.map_err(|_e| RustADBError::ConversionError)?;
|
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
local_id,
|
local_id,
|
||||||
@@ -157,10 +223,9 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(size) => {
|
Ok(size) => {
|
||||||
let subcommand_data = MessageSubcommand::Data.with_arg(size as u32);
|
let subcommand_data = MessageSubcommand::Data.with_arg(u32::try_from(size)?);
|
||||||
|
|
||||||
let mut serialized_message = bincode::serialize(&subcommand_data)
|
let mut serialized_message = bincode_serialize_to_vec(&subcommand_data)?;
|
||||||
.map_err(|_e| RustADBError::ConversionError)?;
|
|
||||||
serialized_message.append(&mut buffer[..size].to_vec());
|
serialized_message.append(&mut buffer[..size].to_vec());
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
@@ -185,12 +250,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn stat_with_explicit_ids(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
pub(crate) fn stat_with_explicit_ids(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
||||||
let stat_buffer = MessageSubcommand::Stat.with_arg(remote_path.len() as u32);
|
let stat_buffer = MessageSubcommand::Stat.with_arg(u32::try_from(remote_path.len())?);
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
self.get_local_id()?,
|
||||||
self.get_remote_id()?,
|
self.get_remote_id()?,
|
||||||
&bincode::serialize(&stat_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
&bincode_serialize_to_vec(&stat_buffer)?,
|
||||||
);
|
);
|
||||||
self.send_and_expect_okay(message)?;
|
self.send_and_expect_okay(message)?;
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
@@ -202,8 +267,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
let response = self.transport.read_message()?;
|
let response = self.transport.read_message()?;
|
||||||
// Skip first 4 bytes as this is the literal "STAT".
|
// Skip first 4 bytes as this is the literal "STAT".
|
||||||
// Interesting part starts right after
|
// Interesting part starts right after
|
||||||
bincode::deserialize(&response.into_payload()[4..])
|
|
||||||
.map_err(|_e| RustADBError::ConversionError)
|
bincode_deserialize_from_slice(&response.into_payload()[4..])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn end_transaction(&mut self) -> Result<()> {
|
pub(crate) fn end_transaction(&mut self) -> Result<()> {
|
||||||
@@ -212,7 +277,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
self.get_local_id()?,
|
||||||
self.get_remote_id()?,
|
self.get_remote_id()?,
|
||||||
&bincode::serialize(&quit_buffer).map_err(|_e| RustADBError::ConversionError)?,
|
&bincode_serialize_to_vec(&quit_buffer)?,
|
||||||
))?;
|
))?;
|
||||||
let _discard_close = self.transport.read_message()?;
|
let _discard_close = self.transport.read_message()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
use crate::{
|
use crate::{ADBDeviceExt, ADBMessageTransport, RebootType, Result, models::AdbStatResponse};
|
||||||
ADBDeviceExt, RebootType, Result,
|
|
||||||
message_devices::{
|
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
},
|
|
||||||
models::AdbStatResponse,
|
|
||||||
};
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::ADBMessageDevice;
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
|
||||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||||
self.shell_command(command, output)
|
self.shell_command(command, output)
|
||||||
@@ -1,24 +1,43 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::{io::Read, net::SocketAddr};
|
use std::{io::Read, net::SocketAddr};
|
||||||
|
|
||||||
use crate::message_devices::adb_message_device::ADBMessageDevice;
|
use super::adb_message_device::ADBMessageDevice;
|
||||||
use crate::message_devices::adb_message_transport::ADBMessageTransport;
|
use super::models::MessageCommand;
|
||||||
use crate::message_devices::adb_transport_message::ADBTransportMessage;
|
use super::{ADBRsaKey, ADBTransportMessage, get_default_adb_key_path};
|
||||||
use crate::message_devices::message_commands::MessageCommand;
|
use crate::device::adb_usb_device::read_adb_private_key;
|
||||||
use crate::tcp::tcp_transport::TcpTransport;
|
use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, TcpTransport};
|
||||||
use crate::{ADBDeviceExt, ADBTransport, Result};
|
|
||||||
|
|
||||||
/// Represent a device reached and available over USB.
|
/// Represent a device reached and available over USB.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ADBTcpDevice {
|
pub struct ADBTcpDevice {
|
||||||
|
private_key: ADBRsaKey,
|
||||||
inner: ADBMessageDevice<TcpTransport>,
|
inner: ADBMessageDevice<TcpTransport>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ADBTcpDevice {
|
impl ADBTcpDevice {
|
||||||
/// Instantiate a new [`ADBTcpDevice`]
|
/// Instantiate a new [`ADBTcpDevice`]
|
||||||
pub fn new(address: SocketAddr) -> Result<Self> {
|
pub fn new(address: SocketAddr) -> Result<Self> {
|
||||||
|
Self::new_with_custom_private_key(address, get_default_adb_key_path()?)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiate a new [`ADBTcpDevice`] using a custom private key path
|
||||||
|
pub fn new_with_custom_private_key(
|
||||||
|
address: SocketAddr,
|
||||||
|
private_key_path: PathBuf,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let private_key = if let Some(private_key) = read_adb_private_key(&private_key_path)? {
|
||||||
|
private_key
|
||||||
|
} else {
|
||||||
|
log::warn!(
|
||||||
|
"No private key found at path {}. Using a temporary random one.",
|
||||||
|
private_key_path.display()
|
||||||
|
);
|
||||||
|
ADBRsaKey::new_random()?
|
||||||
|
};
|
||||||
|
|
||||||
let mut device = Self {
|
let mut device = Self {
|
||||||
|
private_key,
|
||||||
inner: ADBMessageDevice::new(TcpTransport::new(address)?),
|
inner: ADBMessageDevice::new(TcpTransport::new(address)?),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,8 +52,8 @@ impl ADBTcpDevice {
|
|||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Cnxn,
|
MessageCommand::Cnxn,
|
||||||
0x01000000,
|
0x0100_0000,
|
||||||
1048576,
|
1_048_576,
|
||||||
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -42,26 +61,28 @@ impl ADBTcpDevice {
|
|||||||
|
|
||||||
let message = self.get_transport_mut().read_message()?;
|
let message = self.get_transport_mut().read_message()?;
|
||||||
|
|
||||||
// Check if client is requesting a secure connection and upgrade it if necessary
|
// Check if a client is requesting a secure connection and upgrade it if necessary
|
||||||
match message.header().command() {
|
match message.header().command() {
|
||||||
MessageCommand::Stls => {
|
MessageCommand::Stls => {
|
||||||
self.get_transport_mut()
|
self.get_transport_mut()
|
||||||
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
||||||
self.get_transport_mut().upgrade_connection()?;
|
self.get_transport_mut().upgrade_connection()?;
|
||||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
log::debug!("Connection successfully upgraded from TCP to TLS");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
MessageCommand::Cnxn => {
|
MessageCommand::Cnxn => {
|
||||||
log::debug!("Unencrypted connection established");
|
log::debug!("Unencrypted connection established");
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => {
|
MessageCommand::Auth => {
|
||||||
return Err(crate::RustADBError::WrongResponseReceived(
|
log::debug!("Authentication required");
|
||||||
"Expected CNXN or STLS command".to_string(),
|
self.inner.auth_handshake(message, &self.private_key)
|
||||||
message.header().command().to_string(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
_ => Err(crate::RustADBError::WrongResponseReceived(
|
||||||
|
"Expected CNXN, STLS or AUTH command".to_string(),
|
||||||
|
message.header().command().to_string(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Result, RustADBError, message_devices::message_commands::MessageCommand};
|
use crate::{Result, RustADBError, device::adb_message_device};
|
||||||
|
|
||||||
|
use super::models::MessageCommand;
|
||||||
|
|
||||||
|
pub const AUTH_TOKEN: u32 = 1;
|
||||||
|
pub const AUTH_SIGNATURE: u32 = 2;
|
||||||
|
pub const AUTH_RSAPUBLICKEY: u32 = 3;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ADBTransportMessage {
|
pub struct ADBTransportMessage {
|
||||||
@@ -52,16 +58,16 @@ impl ADBTransportMessageHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn compute_crc32(data: &[u8]) -> u32 {
|
pub(crate) fn compute_crc32(data: &[u8]) -> u32 {
|
||||||
data.iter().map(|&x| x as u32).sum()
|
data.iter().map(|&x| u32::from(x)).sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_magic(command: MessageCommand) -> u32 {
|
fn compute_magic(command: MessageCommand) -> u32 {
|
||||||
let command_u32 = command as u32;
|
let command_u32 = command as u32;
|
||||||
command_u32 ^ 0xFFFFFFFF
|
command_u32 ^ 0xFFFF_FFFF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_bytes(&self) -> Result<Vec<u8>> {
|
pub fn as_bytes(&self) -> Result<Vec<u8>> {
|
||||||
bincode::serialize(&self).map_err(|_e| RustADBError::ConversionError)
|
adb_message_device::bincode_serialize_to_vec(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +117,6 @@ impl TryFrom<[u8; 24]> for ADBTransportMessageHeader {
|
|||||||
type Error = RustADBError;
|
type Error = RustADBError;
|
||||||
|
|
||||||
fn try_from(value: [u8; 24]) -> Result<Self> {
|
fn try_from(value: [u8; 24]) -> Result<Self> {
|
||||||
bincode::deserialize(&value).map_err(|_e| RustADBError::ConversionError)
|
adb_message_device::bincode_deserialize_from_slice(&value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,23 +7,14 @@ use std::io::Read;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
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::ADBDeviceExt;
|
||||||
use crate::Result;
|
use crate::ADBMessageTransport;
|
||||||
use crate::RustADBError;
|
use crate::ADBTransport;
|
||||||
use crate::adb_transport::ADBTransport;
|
use crate::{Result, RustADBError, USBTransport};
|
||||||
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;
|
|
||||||
|
|
||||||
const AUTH_TOKEN: u32 = 1;
|
|
||||||
const AUTH_SIGNATURE: u32 = 2;
|
|
||||||
const AUTH_RSAPUBLICKEY: u32 = 3;
|
|
||||||
|
|
||||||
pub fn read_adb_private_key<P: AsRef<Path>>(private_key_path: P) -> Result<Option<ADBRsaKey>> {
|
pub fn read_adb_private_key<P: AsRef<Path>>(private_key_path: P) -> Result<Option<ADBRsaKey>> {
|
||||||
// Try to read the private key file from given path
|
// Try to read the private key file from given path
|
||||||
@@ -99,6 +90,12 @@ pub fn is_adb_device<T: UsbContext>(device: &Device<T>, des: &DeviceDescriptor)
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_default_adb_key_path() -> Result<PathBuf> {
|
||||||
|
std::env::home_dir()
|
||||||
|
.map(|home| home.join(".android").join("adbkey"))
|
||||||
|
.ok_or(RustADBError::NoHomeDirectory)
|
||||||
|
}
|
||||||
|
|
||||||
/// Represent a device reached and available over USB.
|
/// Represent a device reached and available over USB.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ADBUSBDevice {
|
pub struct ADBUSBDevice {
|
||||||
@@ -118,7 +115,7 @@ impl ADBUSBDevice {
|
|||||||
product_id: u16,
|
product_id: u16,
|
||||||
private_key_path: PathBuf,
|
private_key_path: PathBuf,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Self::new_from_transport_inner(USBTransport::new(vendor_id, product_id)?, private_key_path)
|
Self::new_from_transport_inner(USBTransport::new(vendor_id, product_id)?, &private_key_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate a new [`ADBUSBDevice`] from a [`USBTransport`] and an optional private key path.
|
/// Instantiate a new [`ADBUSBDevice`] from a [`USBTransport`] and an optional private key path.
|
||||||
@@ -131,22 +128,21 @@ impl ADBUSBDevice {
|
|||||||
None => get_default_adb_key_path()?,
|
None => get_default_adb_key_path()?,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::new_from_transport_inner(transport, private_key_path)
|
Self::new_from_transport_inner(transport, &private_key_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_from_transport_inner(
|
fn new_from_transport_inner(
|
||||||
transport: USBTransport,
|
transport: USBTransport,
|
||||||
private_key_path: PathBuf,
|
private_key_path: &PathBuf,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let private_key = match read_adb_private_key(&private_key_path)? {
|
let private_key = if let Some(private_key) = read_adb_private_key(private_key_path)? {
|
||||||
Some(pk) => pk,
|
private_key
|
||||||
None => {
|
} else {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"No private key found at path {}. Using a temporary random one.",
|
"No private key found at path {}. Using a temporary random one.",
|
||||||
private_key_path.display()
|
private_key_path.display()
|
||||||
);
|
);
|
||||||
ADBRsaKey::new_random()?
|
ADBRsaKey::new_random()?
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut s = Self {
|
let mut s = Self {
|
||||||
@@ -182,8 +178,8 @@ impl ADBUSBDevice {
|
|||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Cnxn,
|
MessageCommand::Cnxn,
|
||||||
0x01000000,
|
0x0100_0000,
|
||||||
1048576,
|
1_048_576,
|
||||||
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -195,55 +191,9 @@ impl ADBUSBDevice {
|
|||||||
if message.header().command() == MessageCommand::Cnxn {
|
if message.header().command() == MessageCommand::Cnxn {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
message.assert_command(MessageCommand::Auth)?;
|
message.assert_command(MessageCommand::Auth)?;
|
||||||
|
self.inner.auth_handshake(message, &self.private_key)
|
||||||
// At this point, we should have receive an AUTH message with arg0 == 1
|
|
||||||
let auth_message = match message.header().arg0() {
|
|
||||||
AUTH_TOKEN => message,
|
|
||||||
v => {
|
|
||||||
return Err(RustADBError::ADBRequestFailed(format!(
|
|
||||||
"Received AUTH message with type != 1 ({v})"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sign = self.private_key.sign(auth_message.into_payload())?;
|
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_SIGNATURE, 0, &sign);
|
|
||||||
|
|
||||||
self.get_transport_mut().write_message(message)?;
|
|
||||||
|
|
||||||
let received_response = self.get_transport_mut().read_message()?;
|
|
||||||
|
|
||||||
if received_response.header().command() == MessageCommand::Cnxn {
|
|
||||||
log::info!(
|
|
||||||
"Authentication OK, device info {}",
|
|
||||||
String::from_utf8(received_response.into_payload())?
|
|
||||||
);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut pubkey = self.private_key.android_pubkey_encode()?.into_bytes();
|
|
||||||
pubkey.push(b'\0');
|
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(MessageCommand::Auth, AUTH_RSAPUBLICKEY, 0, &pubkey);
|
|
||||||
|
|
||||||
self.get_transport_mut().write_message(message)?;
|
|
||||||
|
|
||||||
let response = self
|
|
||||||
.get_transport_mut()
|
|
||||||
.read_message_with_timeout(Duration::from_secs(10))
|
|
||||||
.and_then(|message| {
|
|
||||||
message.assert_command(MessageCommand::Cnxn)?;
|
|
||||||
Ok(message)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
log::info!(
|
|
||||||
"Authentication OK, device info {}",
|
|
||||||
String::from_utf8(response.into_payload())?
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -4,11 +4,8 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBMessageTransport, Result, RustADBError,
|
||||||
message_devices::{
|
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
message_commands::MessageCommand,
|
|
||||||
},
|
|
||||||
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,7 +32,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if framebuffer_data.len() as u32 == framebuffer_info.size {
|
if u32::try_from(framebuffer_data.len())? == framebuffer_info.size {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +65,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
payload_cursor.read_to_end(&mut framebuffer_data)?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if framebuffer_data.len() as u32 == framebuffer_info.size {
|
if u32::try_from(framebuffer_data.len())? == framebuffer_info.size {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
use std::{fs::File, path::Path};
|
use std::{fs::File, path::Path};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result,
|
ADBMessageTransport, Result,
|
||||||
message_devices::{
|
device::{MessageWriter, adb_message_device::ADBMessageDevice},
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
commands::utils::MessageWriter,
|
|
||||||
},
|
|
||||||
utils::check_extension_is_apk,
|
utils::check_extension_is_apk,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -6,4 +6,3 @@ mod reboot;
|
|||||||
mod shell;
|
mod shell;
|
||||||
mod stat;
|
mod stat;
|
||||||
mod uninstall;
|
mod uninstall;
|
||||||
mod utils;
|
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBMessageTransport, Result, RustADBError,
|
||||||
message_devices::{
|
device::{
|
||||||
adb_message_device::ADBMessageDevice,
|
ADBTransportMessage, MessageCommand,
|
||||||
adb_message_transport::ADBMessageTransport,
|
adb_message_device::{self, ADBMessageDevice},
|
||||||
adb_transport_message::ADBTransportMessage,
|
models::MessageSubcommand,
|
||||||
message_commands::{MessageCommand, MessageSubcommand},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,9 +30,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
std::time::Duration::from_secs(4),
|
std::time::Duration::from_secs(4),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let recv_buffer = MessageSubcommand::Recv.with_arg(source.len() as u32);
|
let recv_buffer = MessageSubcommand::Recv.with_arg(u32::try_from(source.len())?);
|
||||||
let recv_buffer =
|
let recv_buffer = adb_message_device::bincode_serialize_to_vec(&recv_buffer)?;
|
||||||
bincode::serialize(&recv_buffer).map_err(|_e| RustADBError::ConversionError)?;
|
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
self.get_local_id()?,
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBMessageTransport, Result,
|
||||||
message_devices::{
|
device::{
|
||||||
adb_message_device::ADBMessageDevice,
|
ADBTransportMessage, MessageCommand, MessageSubcommand,
|
||||||
adb_message_transport::ADBMessageTransport,
|
adb_message_device::{self, ADBMessageDevice},
|
||||||
adb_transport_message::ADBTransportMessage,
|
|
||||||
message_commands::{MessageCommand, MessageSubcommand},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,9 +14,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let path_header = format!("{},0777", path.as_ref());
|
let path_header = format!("{},0777", path.as_ref());
|
||||||
|
|
||||||
let send_buffer = MessageSubcommand::Send.with_arg(path_header.len() as u32);
|
let send_buffer = MessageSubcommand::Send.with_arg(u32::try_from(path_header.len())?);
|
||||||
let mut send_buffer =
|
let mut send_buffer = adb_message_device::bincode_serialize_to_vec(&send_buffer)?;
|
||||||
bincode::serialize(&send_buffer).map_err(|_e| RustADBError::ConversionError)?;
|
|
||||||
send_buffer.append(&mut path_header.as_bytes().to_vec());
|
send_buffer.append(&mut path_header.as_bytes().to_vec());
|
||||||
|
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
RebootType, Result,
|
ADBMessageTransport, RebootType, Result,
|
||||||
message_devices::{
|
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
message_commands::MessageCommand,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
use std::io::{ErrorKind, Read, Write};
|
use std::io::{ErrorKind, Read, Write};
|
||||||
|
|
||||||
|
use crate::Result;
|
||||||
|
use crate::device::ShellMessageWriter;
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBMessageTransport, RustADBError,
|
||||||
message_devices::{
|
device::{ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
adb_transport_message::ADBTransportMessage, commands::utils::ShellMessageWriter,
|
|
||||||
message_commands::MessageCommand,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
@@ -62,7 +60,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
writer.write_all(&message.into_payload())?;
|
writer.write_all(&message.into_payload())?;
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
}
|
}
|
||||||
MessageCommand::Okay => continue,
|
MessageCommand::Okay => {}
|
||||||
_ => return Err(RustADBError::ADBShellNotSupported),
|
_ => return Err(RustADBError::ADBShellNotSupported),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
AdbStatResponse, Result,
|
ADBMessageTransport, AdbStatResponse, Result, device::adb_message_device::ADBMessageDevice,
|
||||||
message_devices::{
|
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
@@ -1,9 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageDevice};
|
||||||
Result,
|
|
||||||
message_devices::{
|
|
||||||
adb_message_device::ADBMessageDevice, adb_message_transport::ADBMessageTransport,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
pub(crate) fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
use std::io::{Error, ErrorKind, Result, Write};
|
use std::io::{Error, ErrorKind, Result, Write};
|
||||||
|
|
||||||
use crate::message_devices::{
|
use crate::ADBMessageTransport;
|
||||||
adb_message_transport::ADBMessageTransport, adb_transport_message::ADBTransportMessage,
|
|
||||||
message_commands::MessageCommand,
|
use super::{ADBTransportMessage, MessageCommand};
|
||||||
};
|
|
||||||
|
|
||||||
/// [`Write`] trait implementation to hide underlying ADB protocol write logic.
|
/// [`Write`] trait implementation to hide underlying ADB protocol write logic.
|
||||||
///
|
///
|
||||||
19
adb_client/src/device/mod.rs
Normal file
19
adb_client/src/device/mod.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
mod adb_message_device;
|
||||||
|
mod adb_message_device_commands;
|
||||||
|
mod adb_tcp_device;
|
||||||
|
mod adb_transport_message;
|
||||||
|
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};
|
||||||
|
pub use adb_usb_device::{
|
||||||
|
ADBUSBDevice, get_default_adb_key_path, is_adb_device, search_adb_devices,
|
||||||
|
};
|
||||||
|
pub use message_writer::MessageWriter;
|
||||||
|
pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand};
|
||||||
|
pub use shell_message_writer::ShellMessageWriter;
|
||||||
@@ -6,6 +6,7 @@ use num_traits::cast::ToPrimitive;
|
|||||||
use rsa::pkcs8::DecodePrivateKey;
|
use rsa::pkcs8::DecodePrivateKey;
|
||||||
use rsa::traits::PublicKeyParts;
|
use rsa::traits::PublicKeyParts;
|
||||||
use rsa::{Pkcs1v15Sign, RsaPrivateKey};
|
use rsa::{Pkcs1v15Sign, RsaPrivateKey};
|
||||||
|
use std::fmt::Write;
|
||||||
|
|
||||||
const ADB_PRIVATE_KEY_SIZE: usize = 2048;
|
const ADB_PRIVATE_KEY_SIZE: usize = 2048;
|
||||||
const ANDROID_PUBKEY_MODULUS_SIZE_WORDS: u32 = 64;
|
const ANDROID_PUBKEY_MODULUS_SIZE_WORDS: u32 = 64;
|
||||||
@@ -92,15 +93,16 @@ impl ADBRsaKey {
|
|||||||
.to_u32()
|
.to_u32()
|
||||||
.ok_or(RustADBError::ConversionError)?;
|
.ok_or(RustADBError::ConversionError)?;
|
||||||
|
|
||||||
Ok(self.encode_public_key(adb_rsa_pubkey.into_bytes()))
|
Self::encode_public_key(adb_rsa_pubkey.into_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_public_key(&self, pub_key: Vec<u8>) -> String {
|
fn encode_public_key(pub_key: Vec<u8>) -> Result<String> {
|
||||||
let mut encoded = STANDARD.encode(pub_key);
|
let mut encoded = STANDARD.encode(pub_key);
|
||||||
encoded.push(' ');
|
encoded.push(' ');
|
||||||
encoded.push_str(&format!("adb_client@{}", env!("CARGO_PKG_VERSION")));
|
write!(encoded, "adb_client@{}", env!("CARGO_PKG_VERSION"))
|
||||||
|
.map_err(|_| RustADBError::ConversionError)?;
|
||||||
|
|
||||||
encoded
|
Ok(encoded)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign(&self, msg: impl AsRef<[u8]>) -> Result<Vec<u8>> {
|
pub fn sign(&self, msg: impl AsRef<[u8]>) -> Result<Vec<u8>> {
|
||||||
@@ -6,32 +6,32 @@ use std::fmt::Display;
|
|||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum MessageCommand {
|
pub enum MessageCommand {
|
||||||
/// Connect to a device
|
/// Connect to a device
|
||||||
Cnxn = 0x4E584E43,
|
Cnxn = 0x4E58_4E43,
|
||||||
/// Close connection to a device
|
/// Close connection to a device
|
||||||
Clse = 0x45534C43,
|
Clse = 0x4553_4C43,
|
||||||
/// Device ask for authentication
|
/// Device ask for authentication
|
||||||
Auth = 0x48545541,
|
Auth = 0x4854_5541,
|
||||||
/// Open a data connection
|
/// Open a data connection
|
||||||
Open = 0x4E45504F,
|
Open = 0x4E45_504F,
|
||||||
/// Write data to connection
|
/// Write data to connection
|
||||||
Write = 0x45545257,
|
Write = 0x4554_5257,
|
||||||
/// Server understood the message
|
/// Server understood the message
|
||||||
Okay = 0x59414B4F,
|
Okay = 0x5941_4B4F,
|
||||||
/// Start a connection using TLS
|
/// Start a connection using TLS
|
||||||
Stls = 0x534C5453,
|
Stls = 0x534C_5453,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum MessageSubcommand {
|
pub enum MessageSubcommand {
|
||||||
Stat = 0x54415453,
|
Stat = 0x5441_5453,
|
||||||
Send = 0x444E4553,
|
Send = 0x444E_4553,
|
||||||
Recv = 0x56434552,
|
Recv = 0x5643_4552,
|
||||||
Quit = 0x54495551,
|
Quit = 0x5449_5551,
|
||||||
Fail = 0x4C494146,
|
Fail = 0x4C49_4146,
|
||||||
Done = 0x454E4F44,
|
Done = 0x454E_4F44,
|
||||||
Data = 0x41544144,
|
Data = 0x4154_4144,
|
||||||
List = 0x5453494C,
|
List = 0x5453_494C,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
5
adb_client/src/device/models/mod.rs
Normal file
5
adb_client/src/device/models/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
mod adb_rsa_key;
|
||||||
|
mod message_commands;
|
||||||
|
|
||||||
|
pub use adb_rsa_key::ADBRsaKey;
|
||||||
|
pub use message_commands::{MessageCommand, MessageSubcommand};
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use crate::message_devices::{
|
use crate::ADBMessageTransport;
|
||||||
adb_message_transport::ADBMessageTransport, adb_transport_message::ADBTransportMessage,
|
|
||||||
message_commands::MessageCommand,
|
use super::{ADBTransportMessage, models::MessageCommand};
|
||||||
};
|
|
||||||
|
|
||||||
/// [`Write`] trait implementation to hide underlying ADB protocol write logic for shell commands.
|
/// [`Write`] trait implementation to hide underlying ADB protocol write logic for shell commands.
|
||||||
pub struct ShellMessageWriter<T: ADBMessageTransport> {
|
pub struct ShellMessageWriter<T: ADBMessageTransport> {
|
||||||
@@ -3,10 +3,7 @@ use std::{
|
|||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{ADBServerDevice, ADBTransport, Result, RustADBError, TCPEmulatorTransport};
|
||||||
ADBTransport, Result, RustADBError, emulator::tcp_emulator_transport::TCPEmulatorTransport,
|
|
||||||
server_device::ADBServerDevice,
|
|
||||||
};
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
static EMULATOR_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
static EMULATOR_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
@@ -18,16 +15,16 @@ static EMULATOR_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
|||||||
pub struct ADBEmulatorDevice {
|
pub struct ADBEmulatorDevice {
|
||||||
/// Unique device identifier.
|
/// Unique device identifier.
|
||||||
pub identifier: String,
|
pub identifier: String,
|
||||||
/// Internal [TCPEmulatorTransport]
|
/// Internal [`TCPEmulatorTransport`]
|
||||||
transport: TCPEmulatorTransport,
|
transport: TCPEmulatorTransport,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ADBEmulatorDevice {
|
impl ADBEmulatorDevice {
|
||||||
/// Instantiates a new [ADBEmulatorDevice]
|
/// Instantiates a new [`ADBEmulatorDevice`]
|
||||||
pub fn new(identifier: String, ip_address: Option<Ipv4Addr>) -> Result<Self> {
|
pub fn new(identifier: String, ip_address: Option<Ipv4Addr>) -> Result<Self> {
|
||||||
let ip_address = match ip_address {
|
let ip_address = match ip_address {
|
||||||
Some(ip_address) => ip_address,
|
Some(ip_address) => ip_address,
|
||||||
None => Ipv4Addr::new(127, 0, 0, 1),
|
None => Ipv4Addr::LOCALHOST,
|
||||||
};
|
};
|
||||||
|
|
||||||
let groups = EMULATOR_REGEX
|
let groups = EMULATOR_REGEX
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||||
Result,
|
|
||||||
emulator::{ADBEmulatorCommand, ADBEmulatorDevice},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBEmulatorDevice {
|
impl ADBEmulatorDevice {
|
||||||
/// Send a SMS to this emulator with given content with given phone number
|
/// Send a SMS to this emulator with given content with given phone number
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||||
Result,
|
|
||||||
emulator::{ADBEmulatorCommand, ADBEmulatorDevice},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBEmulatorDevice {
|
impl ADBEmulatorDevice {
|
||||||
/// Send a SMS to this emulator with given content with given phone number
|
/// Send a SMS to this emulator with given content with given phone number
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
mod adb_emulator_device;
|
mod adb_emulator_device;
|
||||||
mod commands;
|
mod commands;
|
||||||
mod models;
|
mod models;
|
||||||
mod tcp_emulator_transport;
|
|
||||||
|
|
||||||
pub use adb_emulator_device::ADBEmulatorDevice;
|
pub use adb_emulator_device::ADBEmulatorDevice;
|
||||||
use models::ADBEmulatorCommand;
|
pub(crate) use models::ADBEmulatorCommand;
|
||||||
@@ -24,8 +24,7 @@ impl ADBEmulatorCommand {
|
|||||||
pub(crate) fn skip_response_lines(&self) -> u8 {
|
pub(crate) fn skip_response_lines(&self) -> u8 {
|
||||||
match self {
|
match self {
|
||||||
ADBEmulatorCommand::Authenticate(_) => 1,
|
ADBEmulatorCommand::Authenticate(_) => 1,
|
||||||
ADBEmulatorCommand::Sms(_, _) => 0,
|
ADBEmulatorCommand::Sms(_, _) | ADBEmulatorCommand::Rotate => 0,
|
||||||
ADBEmulatorCommand::Rotate => 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,9 @@ pub enum RustADBError {
|
|||||||
/// Indicates that an error occurred when converting a value.
|
/// Indicates that an error occurred when converting a value.
|
||||||
#[error("Conversion error")]
|
#[error("Conversion error")]
|
||||||
ConversionError,
|
ConversionError,
|
||||||
|
/// Indicates an error with the integer conversion.
|
||||||
|
#[error(transparent)]
|
||||||
|
IntegerConversionError(#[from] std::num::TryFromIntError),
|
||||||
/// Remote ADB server does not support shell feature.
|
/// Remote ADB server does not support shell feature.
|
||||||
#[error("Remote ADB server does not support shell feature")]
|
#[error("Remote ADB server does not support shell feature")]
|
||||||
ADBShellNotSupported,
|
ADBShellNotSupported,
|
||||||
@@ -61,14 +64,12 @@ pub enum RustADBError {
|
|||||||
#[error("Unimplemented framebuffer image version: {0}")]
|
#[error("Unimplemented framebuffer image version: {0}")]
|
||||||
UnimplementedFramebufferImageVersion(u32),
|
UnimplementedFramebufferImageVersion(u32),
|
||||||
/// An error occurred while getting user's home directory
|
/// An error occurred while getting user's home directory
|
||||||
#[error(transparent)]
|
#[error("Cannot get user home directory")]
|
||||||
HomeError(#[from] homedir::GetHomeError),
|
HomeError,
|
||||||
/// Cannot get home directory
|
/// Cannot get home directory
|
||||||
#[error("Cannot get home directory")]
|
#[error("Cannot get home directory")]
|
||||||
NoHomeDirectory,
|
NoHomeDirectory,
|
||||||
/// Generic USB error
|
/// Generic USB error
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "usb")))]
|
|
||||||
#[error("USB Error: {0}")]
|
#[error("USB Error: {0}")]
|
||||||
UsbError(#[from] rusb::Error),
|
UsbError(#[from] rusb::Error),
|
||||||
/// USB device not found
|
/// USB device not found
|
||||||
@@ -87,8 +88,6 @@ pub enum RustADBError {
|
|||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Base64EncodeError(#[from] base64::EncodeSliceError),
|
Base64EncodeError(#[from] base64::EncodeSliceError),
|
||||||
/// An error occurred with RSA engine
|
/// An error occurred with RSA engine
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "usb")))]
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
RSAError(#[from] rsa::errors::Error),
|
RSAError(#[from] rsa::errors::Error),
|
||||||
/// Cannot convert given data from slice
|
/// Cannot convert given data from slice
|
||||||
@@ -98,8 +97,6 @@ pub enum RustADBError {
|
|||||||
#[error("wrong file extension: {0}")]
|
#[error("wrong file extension: {0}")]
|
||||||
WrongFileExtension(String),
|
WrongFileExtension(String),
|
||||||
/// An error occurred with PKCS8 data
|
/// An error occurred with PKCS8 data
|
||||||
#[cfg(feature = "usb")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "usb")))]
|
|
||||||
#[error("error with pkcs8: {0}")]
|
#[error("error with pkcs8: {0}")]
|
||||||
RsaPkcs8Error(#[from] rsa::pkcs8::Error),
|
RsaPkcs8Error(#[from] rsa::pkcs8::Error),
|
||||||
/// Error during certificate generation
|
/// Error during certificate generation
|
||||||
@@ -118,13 +115,11 @@ pub enum RustADBError {
|
|||||||
#[error("upgrade error: {0}")]
|
#[error("upgrade error: {0}")]
|
||||||
UpgradeError(String),
|
UpgradeError(String),
|
||||||
/// An error occurred while getting mdns devices
|
/// An error occurred while getting mdns devices
|
||||||
#[cfg(feature = "mdns")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
MDNSError(#[from] mdns_sd::Error),
|
MDNSError(#[from] mdns_sd::Error),
|
||||||
/// An error occurred while sending data to channel
|
/// An error occurred while sending data to channel
|
||||||
#[error("error sending data to channel")]
|
#[error(transparent)]
|
||||||
SendError,
|
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
||||||
/// An unknown transport has been provided
|
/// An unknown transport has been provided
|
||||||
#[error("unknown transport: {0}")]
|
#[error("unknown transport: {0}")]
|
||||||
UnknownTransport(String),
|
UnknownTransport(String),
|
||||||
|
|||||||
@@ -3,34 +3,25 @@
|
|||||||
#![forbid(missing_debug_implementations)]
|
#![forbid(missing_debug_implementations)]
|
||||||
#![forbid(missing_docs)]
|
#![forbid(missing_docs)]
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
// Feature `doc_cfg` is currently only available on nightly.
|
|
||||||
// It is activated when cfg `docsrs` is enabled.
|
|
||||||
// Documentation can be build locally using:
|
|
||||||
// `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features`
|
|
||||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
|
||||||
|
|
||||||
mod adb_device_ext;
|
mod adb_device_ext;
|
||||||
mod adb_transport;
|
mod constants;
|
||||||
/// Emulator-related definitions
|
mod device;
|
||||||
pub mod emulator;
|
mod emulator_device;
|
||||||
mod error;
|
mod error;
|
||||||
mod message_devices;
|
mod mdns;
|
||||||
mod models;
|
mod models;
|
||||||
|
mod server;
|
||||||
/// Server-related definitions
|
mod server_device;
|
||||||
pub mod server;
|
mod transports;
|
||||||
|
|
||||||
/// Device reachable by the server related definitions
|
|
||||||
pub mod server_device;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
/// MDNS-related definitions
|
|
||||||
#[cfg(feature = "mdns")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
|
||||||
pub mod mdns;
|
|
||||||
|
|
||||||
pub use adb_device_ext::ADBDeviceExt;
|
pub use adb_device_ext::ADBDeviceExt;
|
||||||
use adb_transport::ADBTransport;
|
pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
|
||||||
|
pub use emulator_device::ADBEmulatorDevice;
|
||||||
pub use error::{Result, RustADBError};
|
pub use error::{Result, RustADBError};
|
||||||
pub use message_devices::*;
|
pub use mdns::*;
|
||||||
pub use models::{AdbStatResponse, HostFeatures, RebootType};
|
pub use models::{AdbStatResponse, RebootType};
|
||||||
|
pub use server::*;
|
||||||
|
pub use server_device::ADBServerDevice;
|
||||||
|
pub use transports::*;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use std::{collections::HashSet, net::IpAddr};
|
use std::{collections::HashSet, net::IpAddr};
|
||||||
|
|
||||||
|
use mdns_sd::{ResolvedService, ScopedIp};
|
||||||
|
|
||||||
/// Represent a device found from mdns search
|
/// Represent a device found from mdns search
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MDNSDevice {
|
pub struct MDNSDevice {
|
||||||
@@ -9,11 +11,11 @@ pub struct MDNSDevice {
|
|||||||
pub addresses: HashSet<IpAddr>,
|
pub addresses: HashSet<IpAddr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<mdns_sd::ServiceInfo> for MDNSDevice {
|
impl From<Box<ResolvedService>> for MDNSDevice {
|
||||||
fn from(value: mdns_sd::ServiceInfo) -> Self {
|
fn from(value: Box<ResolvedService>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
fullname: value.get_fullname().to_string(),
|
fullname: value.fullname,
|
||||||
addresses: value.get_addresses().to_owned(),
|
addresses: value.addresses.iter().map(ScopedIp::to_ip_addr).collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use mdns_sd::{ServiceDaemon, ServiceEvent};
|
use mdns_sd::{ServiceDaemon, ServiceEvent};
|
||||||
use std::{sync::mpsc::Sender, thread::JoinHandle};
|
use std::{sync::mpsc::Sender, thread::JoinHandle};
|
||||||
|
|
||||||
use crate::{Result, RustADBError, mdns::MDNSDevice};
|
use crate::{MDNSDevice, Result, RustADBError};
|
||||||
|
|
||||||
const ADB_SERVICE_NAME: &str = "_adb-tls-connect._tcp.local.";
|
const ADB_SERVICE_NAME: &str = "_adb-tls-connect._tcp.local.";
|
||||||
|
|
||||||
@@ -42,12 +42,14 @@ impl MDNSDiscoveryService {
|
|||||||
| ServiceEvent::ServiceFound(_, _)
|
| ServiceEvent::ServiceFound(_, _)
|
||||||
| ServiceEvent::SearchStopped(_) => {
|
| ServiceEvent::SearchStopped(_) => {
|
||||||
// Ignoring these events. We are only interesting in found devices
|
// Ignoring these events. We are only interesting in found devices
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
ServiceEvent::ServiceResolved(service_info) => {
|
ServiceEvent::ServiceResolved(service_info) => {
|
||||||
return sender
|
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
||||||
.send(MDNSDevice::from(service_info))
|
return Err(e.into());
|
||||||
.map_err(|_| RustADBError::SendError);
|
}
|
||||||
|
}
|
||||||
|
e => {
|
||||||
|
log::warn!("received unknown event type {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
mod message_writer;
|
|
||||||
mod shell_message_writer;
|
|
||||||
pub use message_writer::MessageWriter;
|
|
||||||
pub use shell_message_writer::ShellMessageWriter;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
/// 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;
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# Examples
|
|
||||||
|
|
||||||
## Get a shell from device
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
|
|
||||||
use adb_client::{tcp::ADBTcpDevice, ADBDeviceExt};
|
|
||||||
|
|
||||||
let device_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 10));
|
|
||||||
let device_port = 43210;
|
|
||||||
let mut device = ADBTcpDevice::new(SocketAddr::new(device_ip, device_port)).expect("cannot find device");
|
|
||||||
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()));
|
|
||||||
```
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#![doc = include_str!("./README.md")]
|
|
||||||
|
|
||||||
mod adb_tcp_device;
|
|
||||||
mod tcp_transport;
|
|
||||||
|
|
||||||
pub use adb_tcp_device::ADBTcpDevice;
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# Examples
|
|
||||||
|
|
||||||
## Launch a command on device
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use adb_client::{usb::ADBUSBDevice, ADBDeviceExt};
|
|
||||||
|
|
||||||
let vendor_id = 0x04e8;
|
|
||||||
let product_id = 0x6860;
|
|
||||||
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
|
||||||
device.shell_command(&["df", "-h"], &mut std::io::stdout());
|
|
||||||
```
|
|
||||||
|
|
||||||
## Push a file to the device
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use adb_client::{usb::ADBUSBDevice, ADBDeviceExt};
|
|
||||||
use std::fs::File;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
let vendor_id = 0x04e8;
|
|
||||||
let product_id = 0x6860;
|
|
||||||
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
|
|
||||||
let mut input = File::open(Path::new("/tmp/file.txt")).expect("Cannot open file");
|
|
||||||
device.push(&mut input, &"/data/local/tmp");
|
|
||||||
```
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#![doc = include_str!("./README.md")]
|
|
||||||
|
|
||||||
mod adb_rsa_key;
|
|
||||||
mod adb_usb_device;
|
|
||||||
mod usb_transport;
|
|
||||||
|
|
||||||
pub use adb_usb_device::ADBUSBDevice;
|
|
||||||
pub use usb_transport::USBTransport;
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::{
|
use crate::{WaitForDeviceState, WaitForDeviceTransport};
|
||||||
RebootType,
|
|
||||||
server::{WaitForDeviceState, WaitForDeviceTransport},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
use super::RebootType;
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
pub(crate) enum AdbServerCommand {
|
pub(crate) enum AdbServerCommand {
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
/// Available host features.
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum HostFeatures {
|
pub enum HostFeatures {
|
||||||
/// Shell version 2.
|
|
||||||
ShellV2,
|
ShellV2,
|
||||||
/// Command.
|
|
||||||
Cmd,
|
Cmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
mod adb_request_status;
|
mod adb_request_status;
|
||||||
|
mod adb_server_command;
|
||||||
mod adb_stat_response;
|
mod adb_stat_response;
|
||||||
mod framebuffer_info;
|
mod framebuffer_info;
|
||||||
mod host_features;
|
mod host_features;
|
||||||
mod reboot_type;
|
mod reboot_type;
|
||||||
mod sync_command;
|
mod sync_command;
|
||||||
|
|
||||||
pub(crate) use adb_request_status::AdbRequestStatus;
|
pub use adb_request_status::AdbRequestStatus;
|
||||||
|
pub(crate) use adb_server_command::AdbServerCommand;
|
||||||
pub use adb_stat_response::AdbStatResponse;
|
pub use adb_stat_response::AdbStatResponse;
|
||||||
pub(crate) use framebuffer_info::{FrameBufferInfoV1, FrameBufferInfoV2};
|
pub(crate) use framebuffer_info::{FrameBufferInfoV1, FrameBufferInfoV2};
|
||||||
pub use host_features::HostFeatures;
|
pub use host_features::HostFeatures;
|
||||||
pub use reboot_type::RebootType;
|
pub use reboot_type::RebootType;
|
||||||
pub(crate) use sync_command::SyncCommand;
|
pub use sync_command::SyncCommand;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
# Examples
|
|
||||||
|
|
||||||
## Get available ADB devices
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use adb_client::server::ADBServer;
|
|
||||||
use std::net::{SocketAddrV4, Ipv4Addr};
|
|
||||||
|
|
||||||
// A custom server address can be provided
|
|
||||||
let server_ip = Ipv4Addr::new(127, 0, 0, 1);
|
|
||||||
let server_port = 5037;
|
|
||||||
|
|
||||||
let mut server = ADBServer::new(SocketAddrV4::new(server_ip, server_port));
|
|
||||||
server.devices();
|
|
||||||
```
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::ADBTransport;
|
use crate::ADBTransport;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::RustADBError;
|
use crate::RustADBError;
|
||||||
use crate::server::tcp_server_transport::TCPServerTransport;
|
use crate::TCPServerTransport;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
@@ -9,7 +9,7 @@ use std::process::Command;
|
|||||||
/// Represents an ADB Server
|
/// Represents an ADB Server
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ADBServer {
|
pub struct ADBServer {
|
||||||
/// Internal [TcpStream], lazily initialized
|
/// Internal [`TcpStream`], lazily initialized
|
||||||
pub(crate) transport: Option<TCPServerTransport>,
|
pub(crate) transport: Option<TCPServerTransport>,
|
||||||
/// Address to connect to
|
/// Address to connect to
|
||||||
pub(crate) socket_addr: Option<SocketAddrV4>,
|
pub(crate) socket_addr: Option<SocketAddrV4>,
|
||||||
@@ -21,7 +21,7 @@ pub struct ADBServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Instantiates a new [ADBServer]
|
/// Instantiates a new [`ADBServer`]
|
||||||
pub fn new(address: SocketAddrV4) -> Self {
|
pub fn new(address: SocketAddrV4) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transport: None,
|
transport: None,
|
||||||
@@ -31,7 +31,7 @@ impl ADBServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a new [ADBServer] with a custom adb path
|
/// Instantiates a new [`ADBServer`] with a custom adb path
|
||||||
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transport: None,
|
transport: None,
|
||||||
@@ -46,7 +46,7 @@ impl ADBServer {
|
|||||||
// ADB Server is local, we start it if not already running
|
// ADB Server is local, we start it if not already running
|
||||||
let mut command = Command::new(adb_path.as_deref().unwrap_or("adb"));
|
let mut command = Command::new(adb_path.as_deref().unwrap_or("adb"));
|
||||||
command.arg("start-server");
|
command.arg("start-server");
|
||||||
for (env_k, env_v) in envs.iter() {
|
for (env_k, env_v) in envs {
|
||||||
command.env(env_k, env_v);
|
command.env(env_k, env_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ impl ADBServer {
|
|||||||
match child {
|
match child {
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
if let Err(e) = child.wait() {
|
if let Err(e) = child.wait() {
|
||||||
log::error!("error while starting adb server: {e}")
|
log::error!("error while starting adb server: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => log::error!("error while starting adb server: {e}"),
|
Err(e) => log::error!("error while starting adb server: {e}"),
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||||
Result, RustADBError,
|
|
||||||
server::{ADBServer, AdbServerCommand},
|
|
||||||
};
|
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong, DeviceShort, Result, RustADBError,
|
||||||
emulator::ADBEmulatorDevice,
|
models::AdbServerCommand,
|
||||||
server::{ADBServer, AdbServerCommand, DeviceLong, DeviceShort},
|
|
||||||
server_device::ADBServerDevice,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
@@ -71,12 +69,12 @@ impl ADBServer {
|
|||||||
.filter(|d| d.identifier.as_str() == name)
|
.filter(|d| d.identifier.as_str() == name)
|
||||||
.collect::<Vec<DeviceShort>>()
|
.collect::<Vec<DeviceShort>>()
|
||||||
.len();
|
.len();
|
||||||
if nb_devices != 1 {
|
if nb_devices == 1 {
|
||||||
|
Ok(ADBServerDevice::new(name.to_string(), self.socket_addr))
|
||||||
|
} else {
|
||||||
Err(RustADBError::DeviceNotFound(format!(
|
Err(RustADBError::DeviceNotFound(format!(
|
||||||
"could not find device {name}"
|
"could not find device {name}"
|
||||||
)))
|
)))
|
||||||
} else {
|
|
||||||
Ok(ADBServerDevice::new(name.to_string(), self.socket_addr))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||||
Result, RustADBError,
|
|
||||||
server::{ADBServer, AdbServerCommand},
|
|
||||||
};
|
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||||
Result,
|
|
||||||
server::{ADBServer, AdbServerCommand},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Asks the ADB server to quit immediately.
|
/// Asks the ADB server to quit immediately.
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result,
|
ADBServer, MDNSServices, Result, models::AdbServerCommand, server::models::MDNSBackend,
|
||||||
server::{ADBServer, AdbServerCommand, MDNSServices, models::MDNSBackend},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
|
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use crate::{
|
use crate::models::AdbServerCommand;
|
||||||
Result, RustADBError,
|
use crate::{ADBServer, Result, RustADBError};
|
||||||
server::{ADBServer, AdbServerCommand},
|
|
||||||
};
|
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||||
Result,
|
|
||||||
server::{ADBServer, AdbServerCommand},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Reconnect the device
|
/// Reconnect the device
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, Result, models::AdbServerCommand, server::models::ServerStatus};
|
||||||
Result,
|
|
||||||
server::{ADBServer, AdbServerCommand, models::ServerStatus},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Check ADB server status
|
/// Check ADB server status
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBServer, AdbVersion, Result, models::AdbServerCommand};
|
||||||
Result,
|
|
||||||
server::{ADBServer, AdbServerCommand, AdbVersion},
|
|
||||||
};
|
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Gets server's internal version number.
|
/// Gets server's internal version number.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Result,
|
ADBServer, Result, WaitForDeviceState, WaitForDeviceTransport, models::AdbServerCommand,
|
||||||
server::{ADBServer, AdbServerCommand, WaitForDeviceState, WaitForDeviceTransport},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
#![doc = include_str!("./README.md")]
|
|
||||||
|
|
||||||
mod adb_server;
|
mod adb_server;
|
||||||
mod adb_server_command;
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod models;
|
mod models;
|
||||||
mod tcp_server_transport;
|
|
||||||
|
|
||||||
pub use adb_server::ADBServer;
|
pub use adb_server::ADBServer;
|
||||||
pub(crate) use adb_server_command::AdbServerCommand;
|
|
||||||
pub use models::*;
|
pub use models::*;
|
||||||
pub use tcp_server_transport::TCPServerTransport;
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub struct AdbVersion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AdbVersion {
|
impl AdbVersion {
|
||||||
/// Instantiates a new [AdbVersion].
|
/// Instantiates a new [`AdbVersion`].
|
||||||
pub fn new(minor: u32, revision: u32) -> Self {
|
pub fn new(minor: u32, revision: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
major: 1,
|
major: 1,
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ use std::str::FromStr;
|
|||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::{fmt::Display, str};
|
use std::{fmt::Display, str};
|
||||||
|
|
||||||
use crate::RustADBError;
|
use crate::{DeviceState, RustADBError};
|
||||||
use crate::server::DeviceState;
|
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
@@ -87,15 +86,13 @@ impl TryFrom<&[u8]> for DeviceLong {
|
|||||||
None => "Unk".to_string(),
|
None => "Unk".to_string(),
|
||||||
Some(device) => String::from_utf8(device.as_bytes().to_vec())?,
|
Some(device) => String::from_utf8(device.as_bytes().to_vec())?,
|
||||||
},
|
},
|
||||||
transport_id: u32::from_str_radix(
|
transport_id: (str::from_utf8(
|
||||||
str::from_utf8(
|
groups
|
||||||
groups
|
.name("transport_id")
|
||||||
.name("transport_id")
|
.ok_or(RustADBError::RegexParsingError)?
|
||||||
.ok_or(RustADBError::RegexParsingError)?
|
.as_bytes(),
|
||||||
.as_bytes(),
|
)?)
|
||||||
)?,
|
.parse::<u32>()?,
|
||||||
16,
|
|
||||||
)?,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
use std::{fmt::Display, str::FromStr, sync::LazyLock};
|
use std::{fmt::Display, str::FromStr, sync::LazyLock};
|
||||||
|
|
||||||
use crate::{RustADBError, server::DeviceState};
|
use crate::{DeviceState, RustADBError};
|
||||||
|
|
||||||
static DEVICES_REGEX: LazyLock<Regex> =
|
static DEVICES_REGEX: LazyLock<Regex> =
|
||||||
LazyLock::new(|| Regex::new("^(\\S+)\t(\\w+)\n?$").expect("Cannot build devices regex"));
|
LazyLock::new(|| Regex::new("^(\\S+)\t(\\w+)\n?$").expect("Cannot build devices regex"));
|
||||||
|
|||||||
@@ -48,11 +48,11 @@ impl Display for UsbBackend {
|
|||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
pub enum MDNSBackend {
|
pub enum MDNSBackend {
|
||||||
#[default]
|
#[default]
|
||||||
/// Unknown
|
/// `Unknown`
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
/// Bonjour
|
/// `Bonjour`
|
||||||
Bonjour = 1,
|
Bonjour = 1,
|
||||||
/// OpenScreen
|
/// `OpenScreen`
|
||||||
OpenScreen = 2,
|
OpenScreen = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||||||
|
|
||||||
use crate::RustADBError;
|
use crate::RustADBError;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, Default)]
|
||||||
/// List of available transports to wait for.
|
/// List of available transports to wait for.
|
||||||
pub enum WaitForDeviceTransport {
|
pub enum WaitForDeviceTransport {
|
||||||
/// USB transport
|
/// USB transport
|
||||||
@@ -10,15 +10,10 @@ pub enum WaitForDeviceTransport {
|
|||||||
/// Local transport
|
/// Local transport
|
||||||
Local,
|
Local,
|
||||||
/// Any transport (default value)
|
/// Any transport (default value)
|
||||||
|
#[default]
|
||||||
Any,
|
Any,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WaitForDeviceTransport {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for WaitForDeviceTransport {
|
impl Display for WaitForDeviceTransport {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# Examples
|
|
||||||
|
|
||||||
## Launch a command on device
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use adb_client::{server::ADBServer, ADBDeviceExt};
|
|
||||||
|
|
||||||
let mut server = ADBServer::default();
|
|
||||||
let mut device = server.get_device().expect("cannot get device");
|
|
||||||
device.shell_command(&["df", "-h"], &mut std::io::stdout());
|
|
||||||
```
|
|
||||||
|
|
||||||
## Push a file to the device
|
|
||||||
|
|
||||||
```rust no_run
|
|
||||||
use adb_client::server::ADBServer;
|
|
||||||
use std::net::Ipv4Addr;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
let mut server = ADBServer::default();
|
|
||||||
let mut device = server.get_device().expect("cannot get device");
|
|
||||||
let mut input = File::open(Path::new("/tmp/file.txt")).expect("Cannot open file");
|
|
||||||
device.push(&mut input, "/data/local/tmp");
|
|
||||||
```
|
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
use crate::{
|
use crate::{ADBTransport, Result, TCPServerTransport, models::AdbServerCommand};
|
||||||
ADBTransport, Result,
|
|
||||||
server::{AdbServerCommand, TCPServerTransport},
|
|
||||||
};
|
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
/// Represents a device connected to the ADB server.
|
/// Represents a device connected to the ADB server.
|
||||||
@@ -9,12 +6,12 @@ use std::net::SocketAddrV4;
|
|||||||
pub struct ADBServerDevice {
|
pub struct ADBServerDevice {
|
||||||
/// Unique device identifier.
|
/// Unique device identifier.
|
||||||
pub identifier: Option<String>,
|
pub identifier: Option<String>,
|
||||||
/// Internal [TCPServerTransport]
|
/// Internal [`TCPServerTransport`]
|
||||||
pub(crate) transport: TCPServerTransport,
|
pub(crate) transport: TCPServerTransport,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Instantiates a new [ADBServerDevice], knowing its ADB identifier (as returned by `adb devices` command).
|
/// Instantiates a new [`ADBServerDevice`], knowing its ADB identifier (as returned by `adb devices` command).
|
||||||
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
|
|
||||||
@@ -24,7 +21,7 @@ impl ADBServerDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a new [ADBServerDevice], assuming only one is currently connected.
|
/// Instantiates a new [`ADBServerDevice`], assuming only one is currently connected.
|
||||||
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ use std::{
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ADBDeviceExt, Result, RustADBError,
|
ADBDeviceExt, Result, RustADBError,
|
||||||
models::{AdbStatResponse, HostFeatures},
|
constants::BUFFER_SIZE,
|
||||||
server::AdbServerCommand,
|
models::{AdbServerCommand, AdbStatResponse, HostFeatures},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::ADBServerDevice;
|
use super::ADBServerDevice;
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 65535;
|
|
||||||
|
|
||||||
impl ADBDeviceExt for ADBServerDevice {
|
impl ADBDeviceExt for ADBServerDevice {
|
||||||
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||||
let supported_features = self.host_features()?;
|
let supported_features = self.host_features()?;
|
||||||
@@ -27,15 +25,14 @@ impl ADBDeviceExt for ADBServerDevice {
|
|||||||
self.transport
|
self.transport
|
||||||
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
||||||
|
|
||||||
|
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = [0; BUFFER_SIZE];
|
|
||||||
match self.transport.get_raw_connection()?.read(&mut buffer) {
|
match self.transport.get_raw_connection()?.read(&mut buffer) {
|
||||||
Ok(size) => {
|
Ok(size) => {
|
||||||
if size == 0 {
|
if size == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
|
||||||
output.write_all(&buffer[..size])?;
|
|
||||||
}
|
}
|
||||||
|
output.write_all(&buffer[..size])?;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(RustADBError::IOError(e));
|
return Err(RustADBError::IOError(e));
|
||||||
@@ -69,8 +66,9 @@ impl ADBDeviceExt for ADBServerDevice {
|
|||||||
|
|
||||||
// Reading thread, reads response from adb-server
|
// Reading thread, reads response from adb-server
|
||||||
std::thread::spawn(move || -> Result<()> {
|
std::thread::spawn(move || -> Result<()> {
|
||||||
|
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = [0; BUFFER_SIZE];
|
|
||||||
match read_stream.read(&mut buffer) {
|
match read_stream.read(&mut buffer) {
|
||||||
Ok(0) => {
|
Ok(0) => {
|
||||||
read_stream.shutdown(std::net::Shutdown::Both)?;
|
read_stream.shutdown(std::net::Shutdown::Both)?;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Forward socket connection
|
/// Forward socket connection
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBServerDevice, Result, RustADBError,
|
||||||
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
models::{AdbServerCommand, FrameBufferInfoV1, FrameBufferInfoV2},
|
||||||
server::AdbServerCommand,
|
|
||||||
server_device::ADBServerDevice,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Result, models::HostFeatures, server::AdbServerCommand, server_device::ADBServerDevice,
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, HostFeatures},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{fs::File, io::Read, path::Path};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Result, server::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk,
|
Result, models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Result, models::SyncCommand, server::AdbServerCommand, server_device::ADBServerDevice,
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, SyncCommand},
|
||||||
};
|
};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use std::{
|
use std::{
|
||||||
@@ -25,7 +26,7 @@ impl ADBServerDevice {
|
|||||||
// 'DONE' directly without listing anything.
|
// 'DONE' directly without listing anything.
|
||||||
fn handle_list_command<S: AsRef<str>>(&mut self, path: S) -> Result<()> {
|
fn handle_list_command<S: AsRef<str>>(&mut self, path: S) -> Result<()> {
|
||||||
let mut len_buf = [0_u8; 4];
|
let mut len_buf = [0_u8; 4];
|
||||||
LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32);
|
LittleEndian::write_u32(&mut len_buf, u32::try_from(path.as_ref().len())?);
|
||||||
|
|
||||||
// 4 bytes of command name is already sent by send_sync_request
|
// 4 bytes of command name is already sent by send_sync_request
|
||||||
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
|
||||||
use crate::{ADBDeviceExt, Result, server_device::ADBServerDevice};
|
use crate::{ADBDeviceExt, ADBServerDevice, Result};
|
||||||
|
|
||||||
struct LogFilter<W: Write> {
|
struct LogFilter<W: Write> {
|
||||||
writer: W,
|
writer: W,
|
||||||
@@ -23,21 +23,26 @@ impl<W: Write> LogFilter<W> {
|
|||||||
|
|
||||||
impl<W: Write> Write for LogFilter<W> {
|
impl<W: Write> Write for LogFilter<W> {
|
||||||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||||
|
// Add newly received bytes to the internal buffer
|
||||||
self.buffer.extend_from_slice(buf);
|
self.buffer.extend_from_slice(buf);
|
||||||
|
|
||||||
let buf_clone = self.buffer.clone();
|
let mut processed = 0;
|
||||||
let mut lines = buf_clone.split_inclusive(|&byte| byte == b'\n').peekable();
|
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];
|
||||||
|
|
||||||
while let Some(line) = lines.next() {
|
if self.should_write(line) {
|
||||||
if lines.peek().is_some() {
|
self.writer.write_all(line)?;
|
||||||
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())
|
Ok(buf.len())
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use crate::{Result, models::RebootType, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{
|
||||||
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, RebootType},
|
||||||
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reboots the device
|
/// Reboots the device
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reconnect device
|
/// Reconnect device
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Result, models::SyncCommand, server::AdbServerCommand, server_device::ADBServerDevice,
|
ADBServerDevice, Result, constants,
|
||||||
|
models::{AdbServerCommand, SyncCommand},
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::io::{BufReader, BufWriter, Read, Write};
|
use std::io::{BufReader, BufWriter, Read, Write};
|
||||||
|
|
||||||
/// Internal structure wrapping a [std::io::Read] and hiding underlying protocol logic.
|
/// Internal structure wrapping a [`std::io::Read`] and hiding underlying protocol logic.
|
||||||
struct ADBRecvCommandReader<R: Read> {
|
struct ADBRecvCommandReader<R: Read> {
|
||||||
inner: R,
|
inner: R,
|
||||||
remaining_data_bytes_to_read: usize,
|
remaining_data_bytes_to_read: usize,
|
||||||
@@ -62,8 +63,6 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 65535;
|
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Receives path to stream from the device.
|
/// Receives path to stream from the device.
|
||||||
pub fn pull(&mut self, path: &dyn AsRef<str>, stream: &mut dyn Write) -> Result<()> {
|
pub fn pull(&mut self, path: &dyn AsRef<str>, stream: &mut dyn Write) -> Result<()> {
|
||||||
@@ -87,14 +86,14 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
let from_as_bytes = from.as_ref().as_bytes();
|
let from_as_bytes = from.as_ref().as_bytes();
|
||||||
let mut buffer = Vec::with_capacity(4 + from_as_bytes.len());
|
let mut buffer = Vec::with_capacity(4 + from_as_bytes.len());
|
||||||
buffer.extend_from_slice(&(from.as_ref().len() as u32).to_le_bytes());
|
buffer.extend_from_slice(&(u32::try_from(from.as_ref().len())?).to_le_bytes());
|
||||||
buffer.extend_from_slice(from_as_bytes);
|
buffer.extend_from_slice(from_as_bytes);
|
||||||
raw_connection.write_all(&buffer)?;
|
raw_connection.write_all(&buffer)?;
|
||||||
|
|
||||||
let reader = ADBRecvCommandReader::new(raw_connection);
|
let reader = ADBRecvCommandReader::new(raw_connection);
|
||||||
std::io::copy(
|
std::io::copy(
|
||||||
&mut BufReader::with_capacity(BUFFER_SIZE, reader),
|
&mut BufReader::with_capacity(constants::BUFFER_SIZE, reader),
|
||||||
&mut BufWriter::with_capacity(BUFFER_SIZE, output),
|
&mut BufWriter::with_capacity(constants::BUFFER_SIZE, output),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Connection should've been left in SYNC mode by now
|
// Connection should've been left in SYNC mode by now
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reverse socket connection
|
/// Reverse socket connection
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
Result, RustADBError,
|
ADBServerDevice, Result, RustADBError, constants,
|
||||||
models::{AdbRequestStatus, SyncCommand},
|
models::{AdbRequestStatus, AdbServerCommand, SyncCommand},
|
||||||
server::AdbServerCommand,
|
|
||||||
server_device::ADBServerDevice,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@@ -11,7 +9,7 @@ use std::{
|
|||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Internal structure wrapping a [std::io::Write] and hiding underlying protocol logic.
|
/// Internal structure wrapping a [`std::io::Write`] and hiding underlying protocol logic.
|
||||||
struct ADBSendCommandWriter<W: Write> {
|
struct ADBSendCommandWriter<W: Write> {
|
||||||
inner: W,
|
inner: W,
|
||||||
}
|
}
|
||||||
@@ -42,8 +40,6 @@ impl<W: Write> Write for ADBSendCommandWriter<W> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 65535;
|
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Send stream to path on the device.
|
/// Send stream to path on the device.
|
||||||
pub fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
pub fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||||
@@ -68,22 +64,23 @@ impl ADBServerDevice {
|
|||||||
// The name of the command is already sent by get_transport()?.send_sync_request
|
// The name of the command is already sent by get_transport()?.send_sync_request
|
||||||
let to_as_bytes = to.as_bytes();
|
let to_as_bytes = to.as_bytes();
|
||||||
let mut buffer = Vec::with_capacity(4 + to_as_bytes.len());
|
let mut buffer = Vec::with_capacity(4 + to_as_bytes.len());
|
||||||
buffer.extend_from_slice(&(to.len() as u32).to_le_bytes());
|
buffer.extend_from_slice(&(u32::try_from(to.len())?).to_le_bytes());
|
||||||
buffer.extend_from_slice(to_as_bytes);
|
buffer.extend_from_slice(to_as_bytes);
|
||||||
raw_connection.write_all(&buffer)?;
|
raw_connection.write_all(&buffer)?;
|
||||||
|
|
||||||
let writer = ADBSendCommandWriter::new(raw_connection);
|
let writer = ADBSendCommandWriter::new(raw_connection);
|
||||||
|
|
||||||
std::io::copy(
|
std::io::copy(
|
||||||
&mut BufReader::with_capacity(BUFFER_SIZE, input),
|
&mut BufReader::with_capacity(constants::BUFFER_SIZE, input),
|
||||||
&mut BufWriter::with_capacity(BUFFER_SIZE, writer),
|
&mut BufWriter::with_capacity(constants::BUFFER_SIZE, writer),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Copy is finished, we can now notify as finished
|
// Copy is finished, we can now notify as finished
|
||||||
// Have to send DONE + file mtime
|
// Have to send DONE + file mtime
|
||||||
let last_modified = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
let Ok(last_modified) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) else {
|
||||||
Ok(n) => n,
|
return Err(RustADBError::ADBRequestFailed(
|
||||||
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
|
"SystemTime before UNIX EPOCH!".into(),
|
||||||
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut done_buffer = Vec::with_capacity(8);
|
let mut done_buffer = Vec::with_capacity(8);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ use std::io::{Read, Write};
|
|||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AdbStatResponse, Result, RustADBError, models::SyncCommand, server::AdbServerCommand,
|
ADBServerDevice, Result, RustADBError,
|
||||||
server_device::ADBServerDevice,
|
models::{AdbServerCommand, AdbStatResponse, SyncCommand},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
fn handle_stat_command<S: AsRef<str>>(&mut self, path: S) -> Result<AdbStatResponse> {
|
fn handle_stat_command<S: AsRef<str>>(&mut self, path: S) -> Result<AdbStatResponse> {
|
||||||
let mut len_buf = [0_u8; 4];
|
let mut len_buf = [0_u8; 4];
|
||||||
LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32);
|
LittleEndian::write_u32(&mut len_buf, u32::try_from(path.as_ref().len())?);
|
||||||
|
|
||||||
// 4 bytes of command name is already sent by send_sync_request
|
// 4 bytes of command name is already sent by send_sync_request
|
||||||
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
self.transport.get_raw_connection()?.write_all(&len_buf)?;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Set adb daemon to tcp/ip mode
|
/// Set adb daemon to tcp/ip mode
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl 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.
|
/// 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.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{Result, models::AdbServerCommand, server_device::ADBServerDevice};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Uninstall a package from device
|
/// Uninstall a package from device
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{Result, server::AdbServerCommand, server_device::ADBServerDevice};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Set adb daemon to usb mode
|
/// Set adb daemon to usb mode
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#![doc = include_str!("./README.md")]
|
|
||||||
|
|
||||||
mod adb_server_device;
|
mod adb_server_device;
|
||||||
mod adb_server_device_commands;
|
mod adb_server_device_commands;
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|||||||
11
adb_client/src/transports/mod.rs
Normal file
11
adb_client/src/transports/mod.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
mod tcp_emulator_transport;
|
||||||
|
mod tcp_server_transport;
|
||||||
|
mod tcp_transport;
|
||||||
|
mod traits;
|
||||||
|
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};
|
||||||
|
pub use usb_transport::USBTransport;
|
||||||
@@ -4,11 +4,8 @@ use std::{
|
|||||||
net::{SocketAddrV4, TcpStream},
|
net::{SocketAddrV4, TcpStream},
|
||||||
};
|
};
|
||||||
|
|
||||||
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.
|
/// Emulator transport running on top on TCP.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -18,7 +15,7 @@ pub struct TCPEmulatorTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TCPEmulatorTransport {
|
impl TCPEmulatorTransport {
|
||||||
/// Instantiates a new instance of [TCPEmulatorTransport]
|
/// Instantiates a new instance of [`TCPEmulatorTransport`]
|
||||||
pub fn new(socket_addr: SocketAddrV4) -> Self {
|
pub fn new(socket_addr: SocketAddrV4) -> Self {
|
||||||
Self {
|
Self {
|
||||||
socket_addr,
|
socket_addr,
|
||||||
@@ -35,11 +32,10 @@ impl TCPEmulatorTransport {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return authentication token stored in $HOME/.emulator_console_auth_token
|
/// Return authentication token stored in `$HOME/.emulator_console_auth_token`
|
||||||
pub fn get_authentication_token(&mut self) -> Result<String> {
|
pub fn get_authentication_token(&mut self) -> Result<String> {
|
||||||
let home = match my_home()? {
|
let Some(home) = std::env::home_dir() else {
|
||||||
Some(home) => home,
|
return Err(RustADBError::NoHomeDirectory);
|
||||||
None => return Err(RustADBError::NoHomeDirectory),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut f = File::open(home.join(".emulator_console_auth_token"))?;
|
let mut f = File::open(home.join(".emulator_console_auth_token"))?;
|
||||||
@@ -55,7 +51,7 @@ impl TCPEmulatorTransport {
|
|||||||
self.send_command(ADBEmulatorCommand::Authenticate(token))
|
self.send_command(ADBEmulatorCommand::Authenticate(token))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send an [ADBEmulatorCommand] to this emulator
|
/// Send an [`ADBEmulatorCommand`] to this emulator
|
||||||
pub(crate) fn send_command(&mut self, command: ADBEmulatorCommand) -> Result<()> {
|
pub(crate) fn send_command(&mut self, command: ADBEmulatorCommand) -> Result<()> {
|
||||||
let mut connection = self.get_raw_connection()?;
|
let mut connection = self.get_raw_connection()?;
|
||||||
|
|
||||||
@@ -81,10 +77,11 @@ impl TCPEmulatorTransport {
|
|||||||
let mut line = String::new();
|
let mut line = String::new();
|
||||||
reader.read_line(&mut line)?;
|
reader.read_line(&mut line)?;
|
||||||
|
|
||||||
match line.starts_with("OK") {
|
if line.starts_with("OK") {
|
||||||
true => Ok(()),
|
return Ok(());
|
||||||
false => Err(RustADBError::ADBRequestFailed(line)),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(RustADBError::ADBRequestFailed(line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user