Compare commits
25 Commits
v2.1.8
...
wasm-suppo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa3943f21f | ||
|
|
4ebbd99607 | ||
|
|
4129d9d218 | ||
|
|
c23dca61d7 | ||
|
|
2bc338fdf5 | ||
|
|
728fb7da95 | ||
|
|
2e762400e5 | ||
|
|
c85c76228d | ||
|
|
e91a35b3ff | ||
|
|
8f979eff91 | ||
|
|
af51584736 | ||
|
|
864bde01f6 | ||
|
|
8361a0fe06 | ||
|
|
218ec3d679 | ||
|
|
4b817c0435 | ||
|
|
2dd30931f2 | ||
|
|
8b4602c62f | ||
|
|
e917a45670 | ||
|
|
b0303ad544 | ||
|
|
f3f95d92c2 | ||
|
|
886adfa392 | ||
|
|
cdf062c3e1 | ||
|
|
b8e3d02311 | ||
|
|
1b7efc1cc6 | ||
|
|
ad064a9f41 |
6
.github/workflows/python-build.yml
vendored
6
.github/workflows/python-build.yml
vendored
@@ -1,8 +1,10 @@
|
|||||||
name: Python - Build packages & Release
|
name: Python - Build packages & Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push: {}
|
push:
|
||||||
pull_request: {}
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
|
|||||||
16
.github/workflows/rust-build.yml
vendored
16
.github/workflows/rust-build.yml
vendored
@@ -1,14 +1,22 @@
|
|||||||
name: Rust - Build
|
name: Rust - Build
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-release:
|
build:
|
||||||
name: "build-release"
|
name: "Build on ${{ matrix.os }}"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Build project
|
- name: Build project
|
||||||
|
|||||||
6
.github/workflows/rust-quality.yml
vendored
6
.github/workflows/rust-quality.yml
vendored
@@ -1,6 +1,10 @@
|
|||||||
name: Rust - Quality
|
name: Rust - Quality
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|||||||
73
.github/workflows/rust-release.yml
vendored
73
.github/workflows/rust-release.yml
vendored
@@ -4,46 +4,101 @@ on:
|
|||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
create-release:
|
release-linux:
|
||||||
|
name: Linux - Build and Publish
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: "Set up Rust"
|
- name: Set up Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: "Install dependencies"
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y rpm
|
sudo apt install -y rpm
|
||||||
cargo install cargo-deb
|
cargo install cargo-deb
|
||||||
cargo install cargo-generate-rpm
|
cargo install cargo-generate-rpm
|
||||||
|
|
||||||
- name: "Publish crates"
|
- name: Publish crates
|
||||||
run: |
|
run: |
|
||||||
cargo publish -p adb_client --token ${CRATES_IO_TOKEN}
|
cargo publish -p adb_client --token ${CRATES_IO_TOKEN}
|
||||||
cargo publish -p adb_cli --token ${CRATES_IO_TOKEN}
|
cargo publish -p adb_cli --token ${CRATES_IO_TOKEN}
|
||||||
env:
|
env:
|
||||||
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
||||||
|
|
||||||
- name: "build-release"
|
- name: Build release
|
||||||
run: cargo build --all-features --release
|
run: cargo build --all-features --release
|
||||||
|
|
||||||
- name: "Build DEB package"
|
- name: Rename binary
|
||||||
|
run: mv target/release/adb_cli target/release/adb_cli-linux
|
||||||
|
|
||||||
|
- name: Build DEB package
|
||||||
run: cargo deb -p adb_cli
|
run: cargo deb -p adb_cli
|
||||||
|
|
||||||
- name: "Build RPM package"
|
- name: Build RPM package
|
||||||
run: cargo generate-rpm -p adb_cli
|
run: cargo generate-rpm -p adb_cli
|
||||||
|
|
||||||
- name: "Publish GitHub artefacts"
|
- name: Upload Linux artifacts
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
target/debian/*.deb
|
target/debian/*.deb
|
||||||
target/generate-rpm/*.rpm
|
target/generate-rpm/*.rpm
|
||||||
target/release/adb_cli
|
target/release/adb_cli-linux
|
||||||
|
|
||||||
|
release-macos:
|
||||||
|
name: macOS - Build Binary
|
||||||
|
runs-on: macos-13
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Build release
|
||||||
|
run: cargo build --all-features --release
|
||||||
|
|
||||||
|
- name: Rename binary
|
||||||
|
run: mv target/release/adb_cli target/release/adb_cli-macos
|
||||||
|
|
||||||
|
- name: Upload macOS binary
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: target/release/adb_cli-macos
|
||||||
|
|
||||||
|
release-windows:
|
||||||
|
name: Windows - Build Binary
|
||||||
|
runs-on: windows-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Build release
|
||||||
|
run: cargo build --all-features --release
|
||||||
|
|
||||||
|
- name: Rename binary
|
||||||
|
run: Rename-Item -Path target/release/adb_cli.exe -NewName adb_cli-windows.exe
|
||||||
|
|
||||||
|
- name: Upload Windows binary
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: target/release/adb_cli-windows.exe
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ resolver = "2"
|
|||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
authors = ["Corentin LIAUD"]
|
authors = ["Corentin LIAUD"]
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
homepage = "https://github.com/cocool97/adb_client"
|
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.8"
|
version = "2.1.13"
|
||||||
|
|
||||||
# To build locally when working on a new release
|
# To build locally when working on a new release
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ adb_client = { version = "^2.0.0" }
|
|||||||
anyhow = { version = "1.0.94" }
|
anyhow = { version = "1.0.94" }
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
env_logger = { version = "0.11.5" }
|
env_logger = { version = "0.11.5" }
|
||||||
log = { version = "0.4.22" }
|
log = { version = "0.4.26" }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
termios = { version = "0.3.3" }
|
termios = { version = "0.3.3" }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::os::unix::prelude::{AsRawFd, RawFd};
|
use std::os::unix::prelude::{AsRawFd, RawFd};
|
||||||
|
|
||||||
use termios::{tcsetattr, Termios, TCSANOW, VMIN, VTIME};
|
use termios::{TCSANOW, Termios, VMIN, VTIME, tcsetattr};
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result};
|
use adb_client::{ADBServer, DeviceShort, MDNSBackend, Result, WaitForDeviceState};
|
||||||
|
|
||||||
use crate::models::{HostCommand, MdnsCommand, ServerCommand};
|
use crate::models::{HostCommand, MdnsCommand, ServerCommand};
|
||||||
|
|
||||||
@@ -72,6 +72,10 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
|||||||
HostCommand::ServerStatus => {
|
HostCommand::ServerStatus => {
|
||||||
log::info!("{}", adb_server.server_status()?);
|
log::info!("{}", adb_server.server_status()?);
|
||||||
}
|
}
|
||||||
|
HostCommand::WaitForDevice { transport } => {
|
||||||
|
log::info!("waiting for device to be connected...");
|
||||||
|
adb_server.wait_for_device(WaitForDeviceState::Device, transport)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{fs::File, io::Write};
|
use std::{fs::File, io::Write};
|
||||||
|
|
||||||
use adb_client::ADBServerDevice;
|
use adb_client::ADBServerDevice;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{Result, anyhow};
|
||||||
|
|
||||||
use crate::models::LocalDeviceCommand;
|
use crate::models::LocalDeviceCommand;
|
||||||
|
|
||||||
|
|||||||
@@ -7,21 +7,33 @@ mod handlers;
|
|||||||
mod models;
|
mod models;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use adb_client::{ADBDeviceExt, ADBServer, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService};
|
use adb_client::{
|
||||||
|
ADBDeviceExt, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
use adb_termios::ADBTermios;
|
use adb_termios::ADBTermios;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use handlers::{handle_emulator_commands, handle_host_commands, handle_local_commands};
|
use handlers::{handle_emulator_commands, handle_host_commands, handle_local_commands};
|
||||||
use models::{DeviceCommands, LocalCommand, MainCommand, Opts};
|
use models::{DeviceCommands, LocalCommand, MainCommand, Opts};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use utils::setup_logger;
|
use utils::setup_logger;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
|
// This depends on `clap`
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
|
|
||||||
setup_logger(opts.debug);
|
// SAFETY:
|
||||||
|
// We are assuming the entire process is single-threaded
|
||||||
|
// at this point.
|
||||||
|
// This seems true for the current version of `clap`,
|
||||||
|
// but there's no guarantee for future updates
|
||||||
|
unsafe { setup_logger(opts.debug) };
|
||||||
|
|
||||||
// Directly handling methods / commands that aren't linked to [`ADBDeviceExt`] trait.
|
// Directly handling methods / commands that aren't linked to [`ADBDeviceExt`] trait.
|
||||||
// Other methods just have to create a concrete [`ADBDeviceExt`] instance, and return it.
|
// Other methods just have to create a concrete [`ADBDeviceExt`] instance, and return it.
|
||||||
@@ -30,17 +42,21 @@ fn main() -> Result<()> {
|
|||||||
MainCommand::Host(server_command) => return Ok(handle_host_commands(server_command)?),
|
MainCommand::Host(server_command) => return Ok(handle_host_commands(server_command)?),
|
||||||
MainCommand::Emu(emulator_command) => return handle_emulator_commands(emulator_command),
|
MainCommand::Emu(emulator_command) => return handle_emulator_commands(emulator_command),
|
||||||
MainCommand::Local(server_command) => {
|
MainCommand::Local(server_command) => {
|
||||||
let mut adb_server = ADBServer::new(server_command.address);
|
// Must start server to communicate with device, but only if this is a local one.
|
||||||
|
let server_address_ip = server_command.address.ip();
|
||||||
|
if server_address_ip.is_loopback() || server_address_ip.is_unspecified() {
|
||||||
|
ADBServer::start(&HashMap::default(), &None);
|
||||||
|
}
|
||||||
|
|
||||||
let device = match server_command.serial {
|
let device = match server_command.serial {
|
||||||
Some(serial) => adb_server.get_device_by_name(&serial)?,
|
Some(serial) => ADBServerDevice::new(serial, Some(server_command.address)),
|
||||||
None => adb_server.get_device()?,
|
None => ADBServerDevice::autodetect(Some(server_command.address)),
|
||||||
};
|
};
|
||||||
|
|
||||||
match server_command.command {
|
match server_command.command {
|
||||||
LocalCommand::DeviceCommands(device_commands) => (device.boxed(), device_commands),
|
LocalCommand::DeviceCommands(device_commands) => (device.boxed(), device_commands),
|
||||||
LocalCommand::LocalDeviceCommand(local_device_command) => {
|
LocalCommand::LocalDeviceCommand(local_device_command) => {
|
||||||
return handle_local_commands(device, local_device_command)
|
return handle_local_commands(device, local_device_command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +71,9 @@ fn main() -> Result<()> {
|
|||||||
None => ADBUSBDevice::autodetect()?,
|
None => ADBUSBDevice::autodetect()?,
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
anyhow::bail!("please either supply values for both the --vendor-id and --product-id flags or none.");
|
anyhow::bail!(
|
||||||
|
"please either supply values for both the --vendor-id and --product-id flags or none."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
(device.boxed(), usb_command.commands)
|
(device.boxed(), usb_command.commands)
|
||||||
@@ -97,7 +115,7 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
||||||
{
|
{
|
||||||
device.shell(std::io::stdin(), 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(|v| v.as_str()).collect();
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
|
use adb_client::{RustADBError, WaitForDeviceTransport};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
fn parse_wait_for_device_device_transport(
|
||||||
|
value: &str,
|
||||||
|
) -> Result<WaitForDeviceTransport, RustADBError> {
|
||||||
|
WaitForDeviceTransport::try_from(value)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum HostCommand {
|
pub enum HostCommand {
|
||||||
/// Print current ADB version.
|
/// Print current ADB version.
|
||||||
@@ -28,6 +35,12 @@ pub enum HostCommand {
|
|||||||
},
|
},
|
||||||
/// Display server status
|
/// Display server status
|
||||||
ServerStatus,
|
ServerStatus,
|
||||||
|
/// Wait for a device, on optionally given transport
|
||||||
|
WaitForDevice {
|
||||||
|
/// Transport on which wait for devices
|
||||||
|
#[clap(short = 't', long = "transport", value_parser = parse_wait_for_device_device_transport)]
|
||||||
|
transport: Option<WaitForDeviceTransport>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ pub enum RebootTypeCommand {
|
|||||||
Recovery,
|
Recovery,
|
||||||
Sideload,
|
Sideload,
|
||||||
SideloadAutoReboot,
|
SideloadAutoReboot,
|
||||||
|
Fastboot,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RebootTypeCommand> for RebootType {
|
impl From<RebootTypeCommand> for RebootType {
|
||||||
@@ -18,6 +19,7 @@ impl From<RebootTypeCommand> for RebootType {
|
|||||||
RebootTypeCommand::Recovery => RebootType::Recovery,
|
RebootTypeCommand::Recovery => RebootType::Recovery,
|
||||||
RebootTypeCommand::Sideload => RebootType::Sideload,
|
RebootTypeCommand::Sideload => RebootType::Sideload,
|
||||||
RebootTypeCommand::SideloadAutoReboot => RebootType::SideloadAutoReboot,
|
RebootTypeCommand::SideloadAutoReboot => RebootType::SideloadAutoReboot,
|
||||||
|
RebootTypeCommand::Fastboot => RebootType::Fastboot,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
pub fn setup_logger(debug: bool) {
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// This conditionally mutates the process' environment.
|
||||||
|
/// See [`std::env::set_var`] for more info.
|
||||||
|
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 = match debug {
|
||||||
@@ -6,7 +10,7 @@ pub fn setup_logger(debug: bool) {
|
|||||||
false => "info",
|
false => "info",
|
||||||
};
|
};
|
||||||
|
|
||||||
std::env::set_var("RUST_LOG", level);
|
unsafe { std::env::set_var("RUST_LOG", level) };
|
||||||
}
|
}
|
||||||
|
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|||||||
@@ -10,33 +10,44 @@ repository.workspace = true
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = { version = "0.22.1" }
|
getrandom = { version = "*", features = ["js"] }
|
||||||
|
ring = { version = "*", features = ["wasm32_unknown_unknown_js"] }
|
||||||
|
|
||||||
bincode = { version = "1.3.3" }
|
bincode = { version = "1.3.3" }
|
||||||
byteorder = { version = "1.5.0" }
|
base64 = { version = "0.22.1", optional = true }
|
||||||
chrono = { version = "0.4.39" }
|
byteorder = { version = "1.5.0", optional = true }
|
||||||
homedir = { version = "0.3.4" }
|
chrono = { version = "0.4.40", default-features = false, features = ["std"] }
|
||||||
image = { version = "0.25.5" }
|
homedir = { version = "0.3.4", optional = true }
|
||||||
lazy_static = { version = "1.5.0" }
|
image = { version = "0.25.5", default-features = false }
|
||||||
log = { version = "0.4.22" }
|
log = { version = "0.4.26" }
|
||||||
mdns-sd = { version = "0.13.2" }
|
mdns-sd = { version = "0.13.9", default-features = false, features = [
|
||||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
"logging",
|
||||||
num-traits = { version = "0.2.19" }
|
], optional = true }
|
||||||
quick-protobuf = { version = "0.8.1" }
|
num-bigint = { version = "0.8.4", package = "num-bigint-dig", optional = true }
|
||||||
rand = { version = "0.9.0" }
|
num-traits = { version = "0.2.19", optional = true }
|
||||||
rcgen = { version = "0.13.1" }
|
quick-protobuf = { version = "0.8.1", optional = true }
|
||||||
regex = { version = "1.11.1", features = ["perf", "std", "unicode"] }
|
rand = { version = "0.8.5", optional = true }
|
||||||
rsa = { version = "0.9.7" }
|
rcgen = { version = "0.13.1", default-features = false, features = [
|
||||||
rusb = { version = "0.9.4", features = ["vendored"] }
|
"aws_lc_rs",
|
||||||
rustls = { version = "0.23.22" }
|
"pem",
|
||||||
rustls-pki-types = "1.11.0"
|
], optional = true }
|
||||||
|
regex = { version = "1.11.1", features = [
|
||||||
|
"perf",
|
||||||
|
"std",
|
||||||
|
"unicode",
|
||||||
|
], optional = true }
|
||||||
|
rsa = { version = "0.9.7", optional = true }
|
||||||
|
rusb = { version = "0.9.4", features = ["vendored"], optional = true }
|
||||||
|
rustls = { version = "0.23.27", optional = true }
|
||||||
|
rustls-pki-types = { version = "1.11.0", optional = true }
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
serde_repr = { version = "0.1.19" }
|
serde_repr = { version = "0.1.19", optional = true }
|
||||||
sha1 = { version = "0.10.6", features = ["oid"] }
|
sha1 = { version = "0.10.6", features = ["oid"], optional = true }
|
||||||
thiserror = { version = "2.0.7" }
|
thiserror = { version = "2.0.7" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = { version = "1.0.93" }
|
anyhow = { version = "1.0.93" }
|
||||||
criterion = { version = "0.5.1" } # Used for benchmarks
|
criterion = { version = "0.6.0" } # Used for benchmarks
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
harness = false
|
harness = false
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
|
|
||||||
use crate::{constants::BUFFER_SIZE, ADBMessageTransport, AdbStatResponse, Result, RustADBError};
|
use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE};
|
||||||
|
|
||||||
use super::{models::MessageSubcommand, ADBTransportMessage, MessageCommand};
|
use super::{ADBTransportMessage, MessageCommand, models::MessageSubcommand};
|
||||||
|
|
||||||
/// 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.
|
||||||
@@ -146,7 +146,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
return Err(RustADBError::ADBRequestFailed(format!(
|
return Err(RustADBError::ADBRequestFailed(format!(
|
||||||
"Wrong command received {}",
|
"Wrong command received {}",
|
||||||
c
|
c
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbStatResponse, ADBDeviceExt, ADBMessageTransport, RebootType, Result};
|
use crate::{ADBDeviceExt, ADBMessageTransport, RebootType, Result, models::AdbStatResponse};
|
||||||
use std::{
|
use std::{
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ use std::io::Write;
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::{io::Read, net::SocketAddr};
|
use std::{io::Read, net::SocketAddr};
|
||||||
|
|
||||||
|
use super::ADBTransportMessage;
|
||||||
use super::adb_message_device::ADBMessageDevice;
|
use super::adb_message_device::ADBMessageDevice;
|
||||||
use super::models::MessageCommand;
|
use super::models::MessageCommand;
|
||||||
use super::ADBTransportMessage;
|
|
||||||
use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, TcpTransport};
|
use crate::{ADBDeviceExt, ADBMessageTransport, ADBTransport, Result, TcpTransport};
|
||||||
|
|
||||||
/// Represent a device reached and available over USB.
|
/// Represent a device reached and available over USB.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use rusb::constants::LIBUSB_CLASS_VENDOR_SPEC;
|
|
||||||
use rusb::Device;
|
use rusb::Device;
|
||||||
use rusb::DeviceDescriptor;
|
use rusb::DeviceDescriptor;
|
||||||
use rusb::UsbContext;
|
use rusb::UsbContext;
|
||||||
|
use rusb::constants::LIBUSB_CLASS_VENDOR_SPEC;
|
||||||
use std::fs::read_to_string;
|
use std::fs::read_to_string;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
@@ -12,10 +12,10 @@ use std::time::Duration;
|
|||||||
use super::adb_message_device::ADBMessageDevice;
|
use super::adb_message_device::ADBMessageDevice;
|
||||||
use super::models::MessageCommand;
|
use super::models::MessageCommand;
|
||||||
use super::{ADBRsaKey, ADBTransportMessage};
|
use super::{ADBRsaKey, ADBTransportMessage};
|
||||||
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
|
||||||
use crate::ADBDeviceExt;
|
use crate::ADBDeviceExt;
|
||||||
use crate::ADBMessageTransport;
|
use crate::ADBMessageTransport;
|
||||||
use crate::ADBTransport;
|
use crate::ADBTransport;
|
||||||
|
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
||||||
use crate::{Result, RustADBError, USBTransport};
|
use crate::{Result, RustADBError, USBTransport};
|
||||||
|
|
||||||
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>> {
|
||||||
@@ -188,7 +188,7 @@ impl ADBUSBDevice {
|
|||||||
v => {
|
v => {
|
||||||
return Err(RustADBError::ADBRequestFailed(format!(
|
return Err(RustADBError::ADBRequestFailed(format!(
|
||||||
"Received AUTH message with type != 1 ({v})"
|
"Received AUTH message with type != 1 ({v})"
|
||||||
)))
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{adb_message_device::ADBMessageDevice, MessageCommand},
|
|
||||||
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
|
||||||
ADBMessageTransport, Result, RustADBError,
|
ADBMessageTransport, Result, RustADBError,
|
||||||
|
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||||
|
models::{FrameBufferInfoV1, FrameBufferInfoV2},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use std::{fs::File, path::Path};
|
use std::{fs::File, path::Path};
|
||||||
|
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{adb_message_device::ADBMessageDevice, MessageWriter},
|
|
||||||
utils::check_extension_is_apk,
|
|
||||||
ADBMessageTransport, Result,
|
ADBMessageTransport, Result,
|
||||||
|
device::{MessageWriter, adb_message_device::ADBMessageDevice},
|
||||||
|
utils::check_extension_is_apk,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
@@ -16,15 +14,11 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let file_size = apk_file.metadata()?.len();
|
let file_size = apk_file.metadata()?.len();
|
||||||
|
|
||||||
let mut rng = rand::rng();
|
|
||||||
|
|
||||||
let local_id = rng.random();
|
|
||||||
|
|
||||||
self.open_session(format!("exec:cmd package 'install' -S {}\0", file_size).as_bytes())?;
|
self.open_session(format!("exec:cmd package 'install' -S {}\0", file_size).as_bytes())?;
|
||||||
|
|
||||||
let transport = self.get_transport().clone();
|
let transport = self.get_transport().clone();
|
||||||
|
|
||||||
let mut writer = MessageWriter::new(transport, local_id, self.get_remote_id()?);
|
let mut writer = MessageWriter::new(transport, self.get_local_id()?, self.get_remote_id()?);
|
||||||
|
|
||||||
std::io::copy(&mut apk_file, &mut writer)?;
|
std::io::copy(&mut apk_file, &mut writer)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{
|
|
||||||
adb_message_device::ADBMessageDevice, models::MessageSubcommand, ADBTransportMessage,
|
|
||||||
MessageCommand,
|
|
||||||
},
|
|
||||||
ADBMessageTransport, Result, RustADBError,
|
ADBMessageTransport, Result, RustADBError,
|
||||||
|
device::{
|
||||||
|
ADBTransportMessage, MessageCommand, adb_message_device::ADBMessageDevice,
|
||||||
|
models::MessageSubcommand,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{
|
|
||||||
adb_message_device::ADBMessageDevice, ADBTransportMessage, MessageCommand,
|
|
||||||
MessageSubcommand,
|
|
||||||
},
|
|
||||||
ADBMessageTransport, Result, RustADBError,
|
ADBMessageTransport, Result, RustADBError,
|
||||||
|
device::{
|
||||||
|
ADBTransportMessage, MessageCommand, MessageSubcommand,
|
||||||
|
adb_message_device::ADBMessageDevice,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
device::{adb_message_device::ADBMessageDevice, MessageCommand},
|
|
||||||
ADBMessageTransport, RebootType, Result,
|
ADBMessageTransport, RebootType, Result,
|
||||||
|
device::{MessageCommand, adb_message_device::ADBMessageDevice},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::io::{ErrorKind, Read, Write};
|
use std::io::{ErrorKind, Read, Write};
|
||||||
|
|
||||||
use crate::device::ShellMessageWriter;
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
use crate::device::ShellMessageWriter;
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
|
||||||
ADBMessageTransport, RustADBError,
|
ADBMessageTransport, RustADBError,
|
||||||
|
device::{ADBMessageDevice, ADBTransportMessage, MessageCommand},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
device::adb_message_device::ADBMessageDevice, ADBMessageTransport, AdbStatResponse, Result,
|
ADBMessageTransport, AdbStatResponse, Result, device::adb_message_device::ADBMessageDevice,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{device::adb_message_device::ADBMessageDevice, ADBMessageTransport, Result};
|
use crate::{ADBMessageTransport, Result, device::adb_message_device::ADBMessageDevice};
|
||||||
|
|
||||||
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<()> {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ mod shell_message_writer;
|
|||||||
use adb_message_device::ADBMessageDevice;
|
use adb_message_device::ADBMessageDevice;
|
||||||
pub use adb_tcp_device::ADBTcpDevice;
|
pub use adb_tcp_device::ADBTcpDevice;
|
||||||
pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader};
|
pub use adb_transport_message::{ADBTransportMessage, ADBTransportMessageHeader};
|
||||||
pub use adb_usb_device::{get_default_adb_key_path, ADBUSBDevice};
|
pub use adb_usb_device::{ADBUSBDevice, get_default_adb_key_path};
|
||||||
pub use message_writer::MessageWriter;
|
pub use message_writer::MessageWriter;
|
||||||
pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand};
|
pub use models::{ADBRsaKey, MessageCommand, MessageSubcommand};
|
||||||
pub use shell_message_writer::ShellMessageWriter;
|
pub use shell_message_writer::ShellMessageWriter;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::{Result, RustADBError};
|
use crate::{Result, RustADBError};
|
||||||
use base64::{engine::general_purpose::STANDARD, Engine};
|
use base64::{Engine, engine::general_purpose::STANDARD};
|
||||||
use num_bigint::{BigUint, ModInverse};
|
use num_bigint::{BigUint, ModInverse};
|
||||||
use num_traits::cast::ToPrimitive;
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
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};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::io::Write;
|
|||||||
|
|
||||||
use crate::ADBMessageTransport;
|
use crate::ADBMessageTransport;
|
||||||
|
|
||||||
use super::{models::MessageCommand, ADBTransportMessage};
|
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> {
|
||||||
|
|||||||
@@ -65,10 +65,15 @@ impl TryFrom<ADBServerDevice> for ADBEmulatorDevice {
|
|||||||
type Error = RustADBError;
|
type Error = RustADBError;
|
||||||
|
|
||||||
fn try_from(value: ADBServerDevice) -> std::result::Result<Self, Self::Error> {
|
fn try_from(value: ADBServerDevice) -> std::result::Result<Self, Self::Error> {
|
||||||
ADBEmulatorDevice::new(
|
match &value.identifier {
|
||||||
value.identifier.clone(),
|
Some(device_identifier) => ADBEmulatorDevice::new(
|
||||||
Some(*value.transport.get_socketaddr().ip()),
|
device_identifier.clone(),
|
||||||
)
|
Some(*value.transport.get_socketaddr().ip()),
|
||||||
|
),
|
||||||
|
None => Err(RustADBError::DeviceNotFound(
|
||||||
|
"cannot connect to an emulator device without knowing its identifier".to_string(),
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{emulator_device::ADBEmulatorCommand, ADBEmulatorDevice, Result};
|
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||||
|
|
||||||
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,4 +1,4 @@
|
|||||||
use crate::{emulator_device::ADBEmulatorCommand, ADBEmulatorDevice, Result};
|
use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand};
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ pub enum RustADBError {
|
|||||||
/// An error occurred while sending data to channel
|
/// An error occurred while sending data to channel
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
||||||
|
/// An unknown transport has been provided
|
||||||
|
#[error("unknown transport: {0}")]
|
||||||
|
UnknownTransport(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> From<std::sync::PoisonError<T>> for RustADBError {
|
impl<T> From<std::sync::PoisonError<T>> for RustADBError {
|
||||||
|
|||||||
@@ -7,21 +7,37 @@
|
|||||||
mod adb_device_ext;
|
mod adb_device_ext;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod device;
|
mod device;
|
||||||
mod emulator_device;
|
|
||||||
mod error;
|
mod error;
|
||||||
mod mdns;
|
|
||||||
mod models;
|
mod models;
|
||||||
mod server;
|
|
||||||
mod server_device;
|
|
||||||
mod transports;
|
mod transports;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
mod emulator_device;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
mod mdns;
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
mod server;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
mod server_device;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use adb_device_ext::ADBDeviceExt;
|
pub use adb_device_ext::ADBDeviceExt;
|
||||||
pub use device::{ADBTcpDevice, ADBUSBDevice};
|
pub use device::ADBUSBDevice;
|
||||||
pub use emulator_device::ADBEmulatorDevice;
|
|
||||||
pub use error::{Result, RustADBError};
|
pub use error::{Result, RustADBError};
|
||||||
pub use mdns::*;
|
|
||||||
pub use models::{AdbStatResponse, RebootType};
|
pub use models::{AdbStatResponse, RebootType};
|
||||||
|
pub use transports::{ADBMessageTransport, ADBTransport};
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub use device::ADBTcpDevice;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub use emulator_device::ADBEmulatorDevice;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
pub use mdns::*;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use server::*;
|
pub use server::*;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use server_device::ADBServerDevice;
|
pub use server_device::ADBServerDevice;
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub use transports::*;
|
pub use transports::*;
|
||||||
|
|||||||
@@ -33,19 +33,21 @@ impl MDNSDiscoveryService {
|
|||||||
pub fn start(&mut self, sender: Sender<MDNSDevice>) -> Result<()> {
|
pub fn start(&mut self, sender: Sender<MDNSDevice>) -> Result<()> {
|
||||||
let receiver = self.daemon.browse(ADB_SERVICE_NAME)?;
|
let receiver = self.daemon.browse(ADB_SERVICE_NAME)?;
|
||||||
|
|
||||||
let handle: JoinHandle<Result<()>> = std::thread::spawn(move || loop {
|
let handle: JoinHandle<Result<()>> = std::thread::spawn(move || {
|
||||||
while let Ok(event) = receiver.recv() {
|
loop {
|
||||||
match event {
|
while let Ok(event) = receiver.recv() {
|
||||||
ServiceEvent::SearchStarted(_)
|
match event {
|
||||||
| ServiceEvent::ServiceRemoved(_, _)
|
ServiceEvent::SearchStarted(_)
|
||||||
| ServiceEvent::ServiceFound(_, _)
|
| ServiceEvent::ServiceRemoved(_, _)
|
||||||
| ServiceEvent::SearchStopped(_) => {
|
| ServiceEvent::ServiceFound(_, _)
|
||||||
// Ignoring these events. We are only interesting in found devices
|
| ServiceEvent::SearchStopped(_) => {
|
||||||
continue;
|
// Ignoring these events. We are only interesting in found devices
|
||||||
}
|
continue;
|
||||||
ServiceEvent::ServiceResolved(service_info) => {
|
}
|
||||||
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
ServiceEvent::ServiceResolved(service_info) => {
|
||||||
return Err(e.into());
|
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::{WaitForDeviceState, WaitForDeviceTransport};
|
||||||
|
|
||||||
use super::RebootType;
|
use super::RebootType;
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
@@ -22,6 +24,7 @@ pub(crate) enum AdbServerCommand {
|
|||||||
ReconnectOffline,
|
ReconnectOffline,
|
||||||
Uninstall(String),
|
Uninstall(String),
|
||||||
Install(u64),
|
Install(u64),
|
||||||
|
WaitForDevice(WaitForDeviceState, WaitForDeviceTransport),
|
||||||
// Local commands
|
// Local commands
|
||||||
ShellCommand(String),
|
ShellCommand(String),
|
||||||
Shell,
|
Shell,
|
||||||
@@ -87,6 +90,12 @@ impl Display for AdbServerCommand {
|
|||||||
AdbServerCommand::Uninstall(package) => {
|
AdbServerCommand::Uninstall(package) => {
|
||||||
write!(f, "exec:cmd package 'uninstall' {package}")
|
write!(f, "exec:cmd package 'uninstall' {package}")
|
||||||
}
|
}
|
||||||
|
AdbServerCommand::WaitForDevice(wait_for_device_state, wait_for_device_transport) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"host:wait-for-{wait_for_device_transport}-{wait_for_device_state}"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ pub enum RebootType {
|
|||||||
Sideload,
|
Sideload,
|
||||||
/// Same as `Sideload` but reboots after sideloading
|
/// Same as `Sideload` but reboots after sideloading
|
||||||
SideloadAutoReboot,
|
SideloadAutoReboot,
|
||||||
|
/// Reboots to fastboot
|
||||||
|
Fastboot,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for RebootType {
|
impl Display for RebootType {
|
||||||
@@ -23,6 +25,7 @@ impl Display for RebootType {
|
|||||||
RebootType::Recovery => write!(f, "recovery"),
|
RebootType::Recovery => write!(f, "recovery"),
|
||||||
RebootType::Sideload => write!(f, "sideload"),
|
RebootType::Sideload => write!(f, "sideload"),
|
||||||
RebootType::SideloadAutoReboot => write!(f, "sideload-auto-reboot"),
|
RebootType::SideloadAutoReboot => write!(f, "sideload-auto-reboot"),
|
||||||
|
RebootType::Fastboot => write!(f, "fastboot"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ pub struct ADBServer {
|
|||||||
pub(crate) socket_addr: Option<SocketAddrV4>,
|
pub(crate) socket_addr: Option<SocketAddrV4>,
|
||||||
/// adb-server start envs
|
/// adb-server start envs
|
||||||
pub(crate) envs: HashMap<String, String>,
|
pub(crate) envs: HashMap<String, String>,
|
||||||
|
/// Path to adb binary
|
||||||
|
/// If not set, will use adb from PATH
|
||||||
|
pub(crate) adb_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
@@ -24,6 +27,44 @@ impl ADBServer {
|
|||||||
transport: None,
|
transport: None,
|
||||||
socket_addr: Some(address),
|
socket_addr: Some(address),
|
||||||
envs: HashMap::new(),
|
envs: HashMap::new(),
|
||||||
|
adb_path: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiates a new [ADBServer] with a custom adb path
|
||||||
|
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
||||||
|
Self {
|
||||||
|
transport: None,
|
||||||
|
socket_addr: Some(address),
|
||||||
|
envs: HashMap::new(),
|
||||||
|
adb_path,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start an instance of `adb-server`
|
||||||
|
pub fn start(envs: &HashMap<String, String>, adb_path: &Option<String>) {
|
||||||
|
// ADB Server is local, we start it if not already running
|
||||||
|
let mut command = Command::new(adb_path.as_deref().unwrap_or("adb"));
|
||||||
|
command.arg("start-server");
|
||||||
|
for (env_k, env_v) in envs.iter() {
|
||||||
|
command.env(env_k, env_v);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
// Do not show a prompt on Windows
|
||||||
|
command.creation_flags(0x08000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
let child = command.spawn();
|
||||||
|
match child {
|
||||||
|
Ok(mut child) => {
|
||||||
|
if let Err(e) = child.wait() {
|
||||||
|
log::error!("error while starting adb server: {e}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => log::error!("error while starting adb server: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,22 +93,7 @@ impl ADBServer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if is_local_ip {
|
if is_local_ip {
|
||||||
// ADB Server is local, we start it if not already running
|
Self::start(&self.envs, &self.adb_path);
|
||||||
let mut command = Command::new("adb");
|
|
||||||
command.arg("start-server");
|
|
||||||
for (env_k, env_v) in self.envs.iter() {
|
|
||||||
command.env(env_k, env_v);
|
|
||||||
}
|
|
||||||
|
|
||||||
let child = command.spawn();
|
|
||||||
match child {
|
|
||||||
Ok(mut child) => {
|
|
||||||
if let Err(e) = child.wait() {
|
|
||||||
log::error!("error while starting adb server: {e}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => log::error!("error while starting adb server: {e}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transport.connect()?;
|
transport.connect()?;
|
||||||
@@ -79,7 +105,7 @@ impl ADBServer {
|
|||||||
|
|
||||||
impl Drop for ADBServer {
|
impl Drop for ADBServer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(ref mut transport) = &mut self.transport {
|
if let Some(transport) = &mut self.transport {
|
||||||
let _ = transport.disconnect();
|
let _ = transport.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServer, Result, RustADBError};
|
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::AdbServerCommand, ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong,
|
ADBEmulatorDevice, ADBServer, ADBServerDevice, DeviceLong, DeviceShort, Result, RustADBError,
|
||||||
DeviceShort, Result, RustADBError,
|
models::AdbServerCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
@@ -36,7 +36,7 @@ impl ADBServer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec_devices.push(DeviceLong::try_from(device.to_vec())?);
|
vec_devices.push(DeviceLong::try_from(device)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(vec_devices)
|
Ok(vec_devices)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServer, Result, RustADBError};
|
use crate::{ADBServer, Result, RustADBError, models::AdbServerCommand};
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServer, Result};
|
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Asks the ADB server to quit immediately.
|
/// Asks the ADB server to quit immediately.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::AdbServerCommand, server::models::MDNSBackend, ADBServer, MDNSServices, Result,
|
ADBServer, MDNSServices, Result, models::AdbServerCommand, server::models::MDNSBackend,
|
||||||
};
|
};
|
||||||
|
|
||||||
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
|
const OPENSCREEN_MDNS_BACKEND: &str = "ADB_MDNS_OPENSCREEN";
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ mod pair;
|
|||||||
mod reconnect;
|
mod reconnect;
|
||||||
mod server_status;
|
mod server_status;
|
||||||
mod version;
|
mod version;
|
||||||
|
mod wait_for_device;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServer, Result};
|
use crate::{ADBServer, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Reconnect the device
|
/// Reconnect the device
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, server::models::ServerStatus, ADBServer, Result};
|
use crate::{ADBServer, Result, models::AdbServerCommand, server::models::ServerStatus};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Check ADB server status
|
/// Check ADB server status
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServer, AdbVersion, Result};
|
use crate::{ADBServer, AdbVersion, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Gets server's internal version number.
|
/// Gets server's internal version number.
|
||||||
|
|||||||
20
adb_client/src/server/commands/wait_for_device.rs
Normal file
20
adb_client/src/server/commands/wait_for_device.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use crate::{
|
||||||
|
ADBServer, Result, WaitForDeviceState, WaitForDeviceTransport, models::AdbServerCommand,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl ADBServer {
|
||||||
|
/// Wait for a device in a given state to be connected
|
||||||
|
pub fn wait_for_device(
|
||||||
|
&mut self,
|
||||||
|
state: WaitForDeviceState,
|
||||||
|
transport: Option<WaitForDeviceTransport>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let transport = transport.unwrap_or_default();
|
||||||
|
|
||||||
|
self.connect()?
|
||||||
|
.send_adb_request(AdbServerCommand::WaitForDevice(state, transport))?;
|
||||||
|
|
||||||
|
// Server should respond with an "OKAY" response
|
||||||
|
self.get_transport()?.read_adb_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ use crate::{DeviceState, RustADBError};
|
|||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
Regex::new(r"^(?P<identifier>\S+)\s+(?P<state>\w+)\s+(usb:(?P<usb1>\S+)|(?P<usb2>\S+))?\s*(product:(?P<product>\w+)\s+model:(?P<model>\w+)\s+device:(?P<device>\w+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
Regex::new(r"^(?P<identifier>\S+)\s+(?P<state>\w+)\s+(usb:(?P<usb1>\S+)|(?P<usb2>\S+))?\s*(product:(?P<product>\S+)\s+model:(?P<model>\w+)\s+device:(?P<device>\S+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Represents a new device with more informations.
|
/// Represents a new device with more informations.
|
||||||
@@ -44,12 +44,12 @@ impl Display for DeviceLong {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Vec<u8>> for DeviceLong {
|
impl TryFrom<&[u8]> for DeviceLong {
|
||||||
type Error = RustADBError;
|
type Error = RustADBError;
|
||||||
|
|
||||||
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
||||||
let groups = DEVICES_LONG_REGEX
|
let groups = DEVICES_LONG_REGEX
|
||||||
.captures(&value)
|
.captures(value)
|
||||||
.ok_or(RustADBError::RegexParsingError)?;
|
.ok_or(RustADBError::RegexParsingError)?;
|
||||||
|
|
||||||
Ok(DeviceLong {
|
Ok(DeviceLong {
|
||||||
@@ -98,3 +98,17 @@ impl TryFrom<Vec<u8>> for DeviceLong {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_static_devices_long() {
|
||||||
|
let inputs = [
|
||||||
|
"7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4",
|
||||||
|
"n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58",
|
||||||
|
"192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97",
|
||||||
|
"emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101",
|
||||||
|
"QQ20131020250511 device 20-4 product:NOH-AN00 model:NOH_AN00 device:HWNOH transport_id:3",
|
||||||
|
];
|
||||||
|
for input in inputs {
|
||||||
|
DeviceLong::try_from(input.as_bytes()).expect(&format!("cannot parse input: '{input}'"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ mod device_short;
|
|||||||
mod device_state;
|
mod device_state;
|
||||||
mod mdns_services;
|
mod mdns_services;
|
||||||
mod server_status;
|
mod server_status;
|
||||||
|
mod wait_for_device;
|
||||||
|
|
||||||
pub use adb_version::AdbVersion;
|
pub use adb_version::AdbVersion;
|
||||||
pub use device_long::DeviceLong;
|
pub use device_long::DeviceLong;
|
||||||
@@ -11,3 +12,4 @@ pub use device_short::DeviceShort;
|
|||||||
pub use device_state::DeviceState;
|
pub use device_state::DeviceState;
|
||||||
pub use mdns_services::MDNSServices;
|
pub use mdns_services::MDNSServices;
|
||||||
pub use server_status::{MDNSBackend, ServerStatus};
|
pub use server_status::{MDNSBackend, ServerStatus};
|
||||||
|
pub use wait_for_device::{WaitForDeviceState, WaitForDeviceTransport};
|
||||||
|
|||||||
67
adb_client/src/server/models/wait_for_device.rs
Normal file
67
adb_client/src/server/models/wait_for_device.rs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::RustADBError;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
/// List of available transports to wait for.
|
||||||
|
pub enum WaitForDeviceTransport {
|
||||||
|
/// USB transport
|
||||||
|
Usb,
|
||||||
|
/// Local transport
|
||||||
|
Local,
|
||||||
|
/// Any transport (default value)
|
||||||
|
Any,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for WaitForDeviceTransport {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for WaitForDeviceTransport {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
WaitForDeviceTransport::Usb => write!(f, "usb"),
|
||||||
|
WaitForDeviceTransport::Local => write!(f, "local"),
|
||||||
|
WaitForDeviceTransport::Any => write!(f, "any"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&str> for WaitForDeviceTransport {
|
||||||
|
type Error = RustADBError;
|
||||||
|
|
||||||
|
fn try_from(value: &str) -> Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
"usb" => Ok(Self::Usb),
|
||||||
|
"local" => Ok(Self::Local),
|
||||||
|
"any" => Ok(Self::Any),
|
||||||
|
t => Err(RustADBError::UnknownTransport(t.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
/// List of available states to wait for.
|
||||||
|
pub enum WaitForDeviceState {
|
||||||
|
/// Device in "device" state
|
||||||
|
Device,
|
||||||
|
/// Device in "recovery" state
|
||||||
|
Recovery,
|
||||||
|
/// Device in "sideload" state
|
||||||
|
Sideload,
|
||||||
|
/// Device in "bootloader" state
|
||||||
|
Bootloader,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for WaitForDeviceState {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
WaitForDeviceState::Device => write!(f, "device"),
|
||||||
|
WaitForDeviceState::Recovery => write!(f, "recovery"),
|
||||||
|
WaitForDeviceState::Sideload => write!(f, "sideload"),
|
||||||
|
WaitForDeviceState::Bootloader => write!(f, "bootloader"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,32 @@
|
|||||||
use crate::{ADBTransport, Result, TCPServerTransport};
|
use crate::{ADBTransport, Result, TCPServerTransport, models::AdbServerCommand};
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
/// Represents a device connected to the ADB server.
|
/// Represents a device connected to the ADB server.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ADBServerDevice {
|
pub struct ADBServerDevice {
|
||||||
/// Unique device identifier.
|
/// Unique device identifier.
|
||||||
pub identifier: 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]
|
/// Instantiates a new [ADBServerDevice], knowing its ADB identifier (as returned by `adb devices` command).
|
||||||
pub fn new(identifier: String, socket_addr: Option<SocketAddrV4>) -> Self {
|
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
let transport = if let Some(addr) = socket_addr {
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
TCPServerTransport::new(addr)
|
|
||||||
} else {
|
|
||||||
TCPServerTransport::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
identifier,
|
identifier: Some(identifier),
|
||||||
|
transport,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Instantiates a new [ADBServerDevice], assuming only one is currently connected.
|
||||||
|
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
identifier: None,
|
||||||
transport,
|
transport,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +37,19 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
Ok(&mut self.transport)
|
Ok(&mut self.transport)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set device connection to use serial transport
|
||||||
|
pub(crate) fn set_serial_transport(&mut self) -> Result<()> {
|
||||||
|
let identifier = self.identifier.clone();
|
||||||
|
let transport = self.connect()?;
|
||||||
|
if let Some(serial) = identifier {
|
||||||
|
transport.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||||
|
} else {
|
||||||
|
transport.send_adb_request(AdbServerCommand::TransportAny)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ADBServerDevice {
|
impl Drop for ADBServerDevice {
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
ADBDeviceExt, Result, RustADBError,
|
||||||
constants::BUFFER_SIZE,
|
constants::BUFFER_SIZE,
|
||||||
models::{AdbServerCommand, AdbStatResponse, HostFeatures},
|
models::{AdbServerCommand, AdbStatResponse, HostFeatures},
|
||||||
ADBDeviceExt, Result, RustADBError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::ADBServerDevice;
|
use super::ADBServerDevice;
|
||||||
@@ -20,9 +20,8 @@ impl ADBDeviceExt for ADBServerDevice {
|
|||||||
return Err(RustADBError::ADBShellNotSupported);
|
return Err(RustADBError::ADBShellNotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
self.transport
|
self.transport
|
||||||
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
||||||
|
|
||||||
@@ -59,9 +58,7 @@ impl ADBDeviceExt for ADBServerDevice {
|
|||||||
return Err(RustADBError::ADBShellNotSupported);
|
return Err(RustADBError::ADBShellNotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
self.transport.send_adb_request(AdbServerCommand::Shell)?;
|
self.transport.send_adb_request(AdbServerCommand::Shell)?;
|
||||||
|
|
||||||
let mut read_stream = self.transport.get_raw_connection()?.try_clone()?;
|
let mut read_stream = self.transport.get_raw_connection()?.try_clone()?;
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Forward socket connection
|
/// Forward socket connection
|
||||||
pub fn forward(&mut self, remote: String, local: String) -> Result<()> {
|
pub fn forward(&mut self, remote: String, local: String) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::Forward(remote, local), false)
|
.proxy_connection(AdbServerCommand::Forward(remote, local), false)
|
||||||
@@ -14,9 +12,7 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
/// Remove all previously applied forward rules
|
/// Remove all previously applied forward rules
|
||||||
pub fn forward_remove_all(&mut self) -> Result<()> {
|
pub fn forward_remove_all(&mut self) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::ForwardRemoveAll, false)
|
.proxy_connection(AdbServerCommand::ForwardRemoveAll, false)
|
||||||
|
|||||||
@@ -4,16 +4,14 @@ use byteorder::{LittleEndian, ReadBytesExt};
|
|||||||
use image::{ImageBuffer, Rgba};
|
use image::{ImageBuffer, Rgba};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{AdbServerCommand, FrameBufferInfoV1, FrameBufferInfoV2},
|
|
||||||
ADBServerDevice, Result, RustADBError,
|
ADBServerDevice, Result, RustADBError,
|
||||||
|
models::{AdbServerCommand, FrameBufferInfoV1, FrameBufferInfoV2},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Inner method requesting framebuffer from Android device
|
/// Inner method requesting framebuffer from Android device
|
||||||
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||||
let serial: String = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.send_adb_request(AdbServerCommand::FrameBuffer)?;
|
.send_adb_request(AdbServerCommand::FrameBuffer)?;
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
models::{AdbServerCommand, HostFeatures},
|
|
||||||
ADBServerDevice, Result,
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, HostFeatures},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Lists available ADB server features.
|
/// Lists available ADB server features.
|
||||||
pub fn host_features(&mut self) -> Result<Vec<HostFeatures>> {
|
pub fn host_features(&mut self) -> Result<Vec<HostFeatures>> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
let features = self
|
let features = self
|
||||||
.transport
|
.transport
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::{fs::File, io::Read, path::Path};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk, Result,
|
Result, models::AdbServerCommand, server_device::ADBServerDevice, utils::check_extension_is_apk,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
@@ -13,9 +13,7 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
let file_size = apk_file.metadata()?.len();
|
let file_size = apk_file.metadata()?.len();
|
||||||
|
|
||||||
let serial: String = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.send_adb_request(AdbServerCommand::Install(file_size))?;
|
.send_adb_request(AdbServerCommand::Install(file_size))?;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
models::{AdbServerCommand, SyncCommand},
|
|
||||||
ADBServerDevice, Result,
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, SyncCommand},
|
||||||
};
|
};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use std::{
|
use std::{
|
||||||
@@ -11,9 +11,7 @@ use std::{
|
|||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Lists files in path on the device.
|
/// Lists files in path on the device.
|
||||||
pub fn list<A: AsRef<str>>(&mut self, path: A) -> Result<()> {
|
pub fn list<A: AsRef<str>>(&mut self, path: A) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
// Set device in SYNC mode
|
// Set device in SYNC mode
|
||||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
models::{AdbServerCommand, RebootType},
|
|
||||||
ADBServerDevice, Result,
|
ADBServerDevice, Result,
|
||||||
|
models::{AdbServerCommand, RebootType},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reboots the device
|
/// Reboots the device
|
||||||
pub fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
pub fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::Reboot(reboot_type), false)
|
.proxy_connection(AdbServerCommand::Reboot(reboot_type), false)
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reconnect device
|
/// Reconnect device
|
||||||
pub fn reconnect(&mut self) -> Result<()> {
|
pub fn reconnect(&mut self) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::Reconnect, false)
|
.proxy_connection(AdbServerCommand::Reconnect, false)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
ADBServerDevice, Result, constants,
|
||||||
models::{AdbServerCommand, SyncCommand},
|
models::{AdbServerCommand, SyncCommand},
|
||||||
ADBServerDevice, Result,
|
|
||||||
};
|
};
|
||||||
use byteorder::{LittleEndian, ReadBytesExt};
|
use byteorder::{LittleEndian, ReadBytesExt};
|
||||||
use std::io::{BufReader, BufWriter, Read, Write};
|
use std::io::{BufReader, BufWriter, Read, Write};
|
||||||
@@ -71,9 +70,7 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
|
|||||||
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<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
// Set device in SYNC mode
|
// Set device in SYNC mode
|
||||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Reverse socket connection
|
/// Reverse socket connection
|
||||||
pub fn reverse(&mut self, remote: String, local: String) -> Result<()> {
|
pub fn reverse(&mut self, remote: String, local: String) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::Reverse(remote, local), false)
|
.proxy_connection(AdbServerCommand::Reverse(remote, local), false)
|
||||||
@@ -14,9 +12,7 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
/// Remove all reverse rules
|
/// Remove all reverse rules
|
||||||
pub fn reverse_remove_all(&mut self) -> Result<()> {
|
pub fn reverse_remove_all(&mut self) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::ReverseRemoveAll, false)
|
.proxy_connection(AdbServerCommand::ReverseRemoveAll, false)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
constants,
|
ADBServerDevice, Result, RustADBError, constants,
|
||||||
models::{AdbRequestStatus, AdbServerCommand, SyncCommand},
|
models::{AdbRequestStatus, AdbServerCommand, SyncCommand},
|
||||||
ADBServerDevice, Result, RustADBError,
|
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@@ -45,9 +44,7 @@ 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<()> {
|
||||||
log::info!("Sending data to {}", path.as_ref());
|
log::info!("Sending data to {}", path.as_ref());
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
// Set device in SYNC mode
|
// Set device in SYNC mode
|
||||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ use std::io::{Read, Write};
|
|||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{AdbServerCommand, AdbStatResponse, SyncCommand},
|
|
||||||
ADBServerDevice, Result, RustADBError,
|
ADBServerDevice, Result, RustADBError,
|
||||||
|
models::{AdbServerCommand, AdbStatResponse, SyncCommand},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
@@ -39,9 +39,7 @@ impl ADBServerDevice {
|
|||||||
|
|
||||||
/// Stat file given as path on the device.
|
/// Stat file given as path on the device.
|
||||||
pub fn stat<A: AsRef<str>>(&mut self, path: A) -> Result<AdbStatResponse> {
|
pub fn stat<A: AsRef<str>>(&mut self, path: A) -> Result<AdbStatResponse> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
// Set device in SYNC mode
|
// Set device in SYNC mode
|
||||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Set adb daemon to tcp/ip mode
|
/// Set adb daemon to tcp/ip mode
|
||||||
pub fn tcpip(&mut self, port: u16) -> Result<()> {
|
pub fn tcpip(&mut self, port: u16) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::TcpIp(port), false)
|
.proxy_connection(AdbServerCommand::TcpIp(port), false)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
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,13 +1,11 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use crate::{models::AdbServerCommand, server_device::ADBServerDevice, Result};
|
use crate::{Result, models::AdbServerCommand, server_device::ADBServerDevice};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Uninstall a package from device
|
/// Uninstall a package from device
|
||||||
pub fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
pub fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
||||||
let serial: String = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.send_adb_request(AdbServerCommand::Uninstall(package_name.to_string()))?;
|
.send_adb_request(AdbServerCommand::Uninstall(package_name.to_string()))?;
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
use crate::{ADBServerDevice, Result, models::AdbServerCommand};
|
||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Set adb daemon to usb mode
|
/// Set adb daemon to usb mode
|
||||||
pub fn usb(&mut self) -> Result<()> {
|
pub fn usb(&mut self) -> Result<()> {
|
||||||
let serial = self.identifier.clone();
|
self.set_serial_transport()?;
|
||||||
self.connect()?
|
|
||||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
|
||||||
|
|
||||||
self.transport
|
self.transport
|
||||||
.proxy_connection(AdbServerCommand::Usb, false)
|
.proxy_connection(AdbServerCommand::Usb, false)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::{
|
|||||||
use homedir::my_home;
|
use homedir::my_home;
|
||||||
|
|
||||||
use super::ADBTransport;
|
use super::ADBTransport;
|
||||||
use crate::{emulator_device::ADBEmulatorCommand, Result, RustADBError};
|
use crate::{Result, RustADBError, emulator_device::ADBEmulatorCommand};
|
||||||
|
|
||||||
/// Emulator transport running on top on TCP.
|
/// Emulator transport running on top on TCP.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
|
|
||||||
use crate::models::{AdbRequestStatus, SyncCommand};
|
use crate::models::{AdbRequestStatus, SyncCommand};
|
||||||
use crate::{models::AdbServerCommand, ADBTransport};
|
use crate::{ADBTransport, models::AdbServerCommand};
|
||||||
use crate::{Result, RustADBError};
|
use crate::{Result, RustADBError};
|
||||||
|
|
||||||
const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||||
@@ -33,6 +33,14 @@ impl TCPServerTransport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Instantiate a new instance of [TCPServerTransport] using given address, or default if not specified.
|
||||||
|
pub fn new_or_default(socket_addr: Option<SocketAddrV4>) -> Self {
|
||||||
|
match socket_addr {
|
||||||
|
Some(s) => Self::new(s),
|
||||||
|
None => Self::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get underlying [SocketAddrV4]
|
/// Get underlying [SocketAddrV4]
|
||||||
pub fn get_socketaddr(&self) -> SocketAddrV4 {
|
pub fn get_socketaddr(&self) -> SocketAddrV4 {
|
||||||
self.socket_addr
|
self.socket_addr
|
||||||
@@ -113,6 +121,11 @@ impl TCPServerTransport {
|
|||||||
self.get_raw_connection()?
|
self.get_raw_connection()?
|
||||||
.write_all(adb_request.as_bytes())?;
|
.write_all(adb_request.as_bytes())?;
|
||||||
|
|
||||||
|
self.read_adb_response()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read a response from ADB server
|
||||||
|
pub(crate) fn read_adb_response(&mut self) -> Result<()> {
|
||||||
// Reads returned status code from ADB server
|
// Reads returned status code from ADB server
|
||||||
let mut request_status = [0; 4];
|
let mut request_status = [0; 4];
|
||||||
self.get_raw_connection()?.read_exact(&mut request_status)?;
|
self.get_raw_connection()?.read_exact(&mut request_status)?;
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
use rcgen::{CertificateParams, KeyPair, PKCS_RSA_SHA256};
|
use rcgen::{CertificateParams, KeyPair, PKCS_RSA_SHA256};
|
||||||
use rustls::{
|
use rustls::{
|
||||||
client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
|
|
||||||
pki_types::{pem::PemObject, CertificateDer, PrivatePkcs8KeyDer},
|
|
||||||
ClientConfig, ClientConnection, KeyLogFile, SignatureScheme, StreamOwned,
|
ClientConfig, ClientConnection, KeyLogFile, SignatureScheme, StreamOwned,
|
||||||
|
client::danger::{HandshakeSignatureValid, ServerCertVerified, ServerCertVerifier},
|
||||||
|
pki_types::{CertificateDer, PrivatePkcs8KeyDer, pem::PemObject},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{ADBMessageTransport, ADBTransport};
|
use super::{ADBMessageTransport, ADBTransport};
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{
|
|
||||||
get_default_adb_key_path, ADBTransportMessage, ADBTransportMessageHeader, MessageCommand,
|
|
||||||
},
|
|
||||||
Result, RustADBError,
|
Result, RustADBError,
|
||||||
|
device::{
|
||||||
|
ADBTransportMessage, ADBTransportMessageHeader, MessageCommand, get_default_adb_key_path,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fs::read_to_string,
|
fs::read_to_string,
|
||||||
@@ -125,7 +125,7 @@ impl TcpTransport {
|
|||||||
None => {
|
None => {
|
||||||
return Err(RustADBError::UpgradeError(
|
return Err(RustADBError::UpgradeError(
|
||||||
"cannot upgrade a non-existing connection...".into(),
|
"cannot upgrade a non-existing connection...".into(),
|
||||||
))
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ impl TcpTransport {
|
|||||||
CurrentConnection::Tls(_) => {
|
CurrentConnection::Tls(_) => {
|
||||||
return Err(RustADBError::UpgradeError(
|
return Err(RustADBError::UpgradeError(
|
||||||
"cannot upgrade a TLS connection...".into(),
|
"cannot upgrade a TLS connection...".into(),
|
||||||
))
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::ADBTransport;
|
use super::ADBTransport;
|
||||||
use crate::{device::ADBTransportMessage, Result};
|
use crate::{Result, device::ADBTransportMessage};
|
||||||
|
|
||||||
const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(u64::MAX);
|
const DEFAULT_READ_TIMEOUT: Duration = Duration::from_secs(u64::MAX);
|
||||||
const DEFAULT_WRITE_TIMEOUT: Duration = Duration::from_secs(2);
|
const DEFAULT_WRITE_TIMEOUT: Duration = Duration::from_secs(2);
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
use rusb::{
|
use rusb::{
|
||||||
constants::LIBUSB_CLASS_VENDOR_SPEC, Device, DeviceHandle, Direction, GlobalContext,
|
Device, DeviceHandle, Direction, GlobalContext, TransferType,
|
||||||
TransferType,
|
constants::LIBUSB_CLASS_VENDOR_SPEC,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{ADBMessageTransport, ADBTransport};
|
use super::{ADBMessageTransport, ADBTransport};
|
||||||
use crate::{
|
use crate::{
|
||||||
device::{ADBTransportMessage, ADBTransportMessageHeader, MessageCommand},
|
|
||||||
Result, RustADBError,
|
Result, RustADBError,
|
||||||
|
device::{ADBTransportMessage, ADBTransportMessageHeader, MessageCommand},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct Endpoint {
|
struct Endpoint {
|
||||||
iface: u8,
|
iface: u8,
|
||||||
address: u8,
|
address: u8,
|
||||||
|
max_packet_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transport running on USB
|
/// Transport running on USB
|
||||||
@@ -111,6 +112,7 @@ impl USBTransport {
|
|||||||
let endpoint = Endpoint {
|
let endpoint = Endpoint {
|
||||||
iface: interface_desc.interface_number(),
|
iface: interface_desc.interface_number(),
|
||||||
address: endpoint_desc.address(),
|
address: endpoint_desc.address(),
|
||||||
|
max_packet_size: endpoint_desc.max_packet_size() as usize,
|
||||||
};
|
};
|
||||||
match endpoint_desc.direction() {
|
match endpoint_desc.direction() {
|
||||||
Direction::In => {
|
Direction::In => {
|
||||||
@@ -136,6 +138,34 @@ impl USBTransport {
|
|||||||
|
|
||||||
Err(RustADBError::USBNoDescriptorFound)
|
Err(RustADBError::USBNoDescriptorFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_bulk_data(&self, data: &[u8], timeout: Duration) -> Result<()> {
|
||||||
|
let endpoint = self.get_write_endpoint()?;
|
||||||
|
let handle = self.get_raw_connection()?;
|
||||||
|
let max_packet_size = endpoint.max_packet_size;
|
||||||
|
|
||||||
|
let mut offset = 0;
|
||||||
|
let data_len = data.len();
|
||||||
|
while offset < data_len {
|
||||||
|
let end = (offset + max_packet_size).min(data_len);
|
||||||
|
let write_amount = handle.write_bulk(endpoint.address, &data[offset..end], timeout)?;
|
||||||
|
offset += write_amount;
|
||||||
|
|
||||||
|
log::trace!(
|
||||||
|
"wrote chunk of size {} - {}/{}",
|
||||||
|
write_amount,
|
||||||
|
offset,
|
||||||
|
data_len
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if offset % max_packet_size == 0 {
|
||||||
|
log::trace!("must send final zero-length packet");
|
||||||
|
handle.write_bulk(endpoint.address, &[], timeout)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ADBTransport for USBTransport {
|
impl ADBTransport for USBTransport {
|
||||||
@@ -145,9 +175,11 @@ impl ADBTransport for USBTransport {
|
|||||||
let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?;
|
let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?;
|
||||||
|
|
||||||
Self::configure_endpoint(&device, &read_endpoint)?;
|
Self::configure_endpoint(&device, &read_endpoint)?;
|
||||||
|
log::debug!("got read endpoint: {:?}", read_endpoint);
|
||||||
self.read_endpoint = Some(read_endpoint);
|
self.read_endpoint = Some(read_endpoint);
|
||||||
|
|
||||||
Self::configure_endpoint(&device, &write_endpoint)?;
|
Self::configure_endpoint(&device, &write_endpoint)?;
|
||||||
|
log::debug!("got write endpoint: {:?}", write_endpoint);
|
||||||
self.write_endpoint = Some(write_endpoint);
|
self.write_endpoint = Some(write_endpoint);
|
||||||
|
|
||||||
self.handle = Some(Arc::new(device));
|
self.handle = Some(Arc::new(device));
|
||||||
@@ -157,7 +189,21 @@ impl ADBTransport for USBTransport {
|
|||||||
|
|
||||||
fn disconnect(&mut self) -> crate::Result<()> {
|
fn disconnect(&mut self) -> crate::Result<()> {
|
||||||
let message = ADBTransportMessage::new(MessageCommand::Clse, 0, 0, &[]);
|
let message = ADBTransportMessage::new(MessageCommand::Clse, 0, 0, &[]);
|
||||||
self.write_message(message)
|
if let Err(e) = self.write_message(message) {
|
||||||
|
log::error!("error while sending CLSE message: {e}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(handle) = &self.handle {
|
||||||
|
let endpoint = self.read_endpoint.as_ref().or(self.write_endpoint.as_ref());
|
||||||
|
if let Some(endpoint) = &endpoint {
|
||||||
|
match handle.release_interface(endpoint.iface) {
|
||||||
|
Ok(_) => log::debug!("succesfully released interface"),
|
||||||
|
Err(e) => log::error!("error while release interface: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,29 +213,15 @@ impl ADBMessageTransport for USBTransport {
|
|||||||
message: ADBTransportMessage,
|
message: ADBTransportMessage,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let endpoint = self.get_write_endpoint()?;
|
|
||||||
let handle = self.get_raw_connection()?;
|
|
||||||
|
|
||||||
let message_bytes = message.header().as_bytes()?;
|
let message_bytes = message.header().as_bytes()?;
|
||||||
let mut total_written = 0;
|
self.write_bulk_data(&message_bytes, timeout)?;
|
||||||
loop {
|
|
||||||
total_written +=
|
log::trace!("successfully write header: {} bytes", message_bytes.len());
|
||||||
handle.write_bulk(endpoint.address, &message_bytes[total_written..], timeout)?;
|
|
||||||
if total_written == message_bytes.len() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let payload = message.into_payload();
|
let payload = message.into_payload();
|
||||||
if !payload.is_empty() {
|
if !payload.is_empty() {
|
||||||
let mut total_written = 0;
|
self.write_bulk_data(&payload, timeout)?;
|
||||||
loop {
|
log::trace!("successfully write payload: {} bytes", payload.len());
|
||||||
total_written +=
|
|
||||||
handle.write_bulk(endpoint.address, &payload[total_written..], timeout)?;
|
|
||||||
if total_written == payload.len() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -198,29 +230,26 @@ impl ADBMessageTransport for USBTransport {
|
|||||||
fn read_message_with_timeout(&mut self, timeout: Duration) -> Result<ADBTransportMessage> {
|
fn read_message_with_timeout(&mut self, timeout: Duration) -> Result<ADBTransportMessage> {
|
||||||
let endpoint = self.get_read_endpoint()?;
|
let endpoint = self.get_read_endpoint()?;
|
||||||
let handle = self.get_raw_connection()?;
|
let handle = self.get_raw_connection()?;
|
||||||
|
let max_packet_size = endpoint.max_packet_size;
|
||||||
|
|
||||||
let mut data = [0; 24];
|
let mut data = [0u8; 24];
|
||||||
let mut total_read = 0;
|
let mut offset = 0;
|
||||||
loop {
|
while offset < data.len() {
|
||||||
total_read += handle.read_bulk(endpoint.address, &mut data[total_read..], timeout)?;
|
let end = (offset + max_packet_size).min(data.len());
|
||||||
if total_read == data.len() {
|
let chunk = &mut data[offset..end];
|
||||||
break;
|
offset += handle.read_bulk(endpoint.address, chunk, timeout)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let header = ADBTransportMessageHeader::try_from(data)?;
|
let header = ADBTransportMessageHeader::try_from(data)?;
|
||||||
|
|
||||||
log::trace!("received header {header:?}");
|
log::trace!("received header {header:?}");
|
||||||
|
|
||||||
if header.data_length() != 0 {
|
if header.data_length() != 0 {
|
||||||
let mut msg_data = vec![0_u8; header.data_length() as usize];
|
let mut msg_data = vec![0_u8; header.data_length() as usize];
|
||||||
let mut total_read = 0;
|
let mut offset = 0;
|
||||||
loop {
|
while offset < msg_data.len() {
|
||||||
total_read +=
|
let end = (offset + max_packet_size).min(msg_data.len());
|
||||||
handle.read_bulk(endpoint.address, &mut msg_data[total_read..], timeout)?;
|
let chunk = &mut msg_data[offset..end];
|
||||||
if total_read == msg_data.capacity() {
|
offset += handle.read_bulk(endpoint.address, chunk, timeout)?;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = ADBTransportMessage::from_header_and_payload(header, msg_data);
|
let message = ADBTransportMessage::from_header_and_payload(header, msg_data);
|
||||||
|
|||||||
@@ -12,5 +12,7 @@ pub fn check_extension_is_apk<P: AsRef<Path>>(path: P) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::debug!("Given file is an APK");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use adb_client::ADBServer;
|
use adb_client::ADBServer;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
|
||||||
use rand::{rng, Rng};
|
use rand::{Rng, rng};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ name = "stub_gen"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
adb_client = { path = "../adb_client" }
|
adb_client = { path = "../adb_client" }
|
||||||
anyhow = { version = "1.0.95" }
|
anyhow = { version = "1.0.95" }
|
||||||
pyo3 = { version = "0.23.4", features = [
|
pyo3 = { version = "0.25.0", features = ["abi3-py37", "anyhow"] }
|
||||||
"abi3-py37",
|
|
||||||
"anyhow",
|
|
||||||
"extension-module",
|
|
||||||
] }
|
|
||||||
pyo3-stub-gen = "0.7.0"
|
pyo3-stub-gen = "0.7.0"
|
||||||
pyo3-stub-gen-derive = "0.7.0"
|
pyo3-stub-gen-derive = "0.7.0"
|
||||||
|
|||||||
@@ -1,6 +1,16 @@
|
|||||||
# pyadb_client
|
# pyadb_client
|
||||||
|
|
||||||
Python library to communicate with ADB devices. Built on top of Rust `adb_client` library.
|
<p align="center">
|
||||||
|
<p align="center">Python library to communicate with ADB devices. Built on top of Rust adb_client library.</p>
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://pypi.org/project/pyadb_client">
|
||||||
|
<img alt="pypi.org" src="https://img.shields.io/pypi/v/pyadb_client.svg" />
|
||||||
|
</a>
|
||||||
|
<a href="https://pypi.org/project/pyadb_client">
|
||||||
|
<img alt="downloads" src="https://static.pepy.tech/badge/pyadb_client" />
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -37,7 +47,6 @@ usb_device.push("file.txt", "/data/local/tmp/file.txt")
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Create Python virtual environment
|
# Create Python virtual environment
|
||||||
cd pyadb_client
|
|
||||||
python3 -m venv .venv
|
python3 -m venv .venv
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::net::SocketAddrV4;
|
|||||||
|
|
||||||
use adb_client::ADBServer;
|
use adb_client::ADBServer;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use pyo3::{pyclass, pymethods, PyResult};
|
use pyo3::{PyResult, pyclass, pymethods};
|
||||||
use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods};
|
use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods};
|
||||||
|
|
||||||
use crate::{PyADBServerDevice, PyDeviceShort};
|
use crate::{PyADBServerDevice, PyDeviceShort};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ pub struct PyADBServerDevice(pub ADBServerDevice);
|
|||||||
impl PyADBServerDevice {
|
impl PyADBServerDevice {
|
||||||
#[getter]
|
#[getter]
|
||||||
/// Device identifier
|
/// Device identifier
|
||||||
pub fn identifier(&self) -> String {
|
pub fn identifier(&self) -> Option<String> {
|
||||||
self.0.identifier.clone()
|
self.0.identifier.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
101
tests/tests.rs
101
tests/tests.rs
@@ -1,101 +0,0 @@
|
|||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
use adb_client::{ADBServer, ADBServerDevice, DeviceLong};
|
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
fn new_client() -> ADBServer {
|
|
||||||
ADBServer::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_device() -> ADBServerDevice {
|
|
||||||
let mut client = new_client();
|
|
||||||
return client.get_device().expect("cannot get device");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_version() {
|
|
||||||
let mut adb = new_client();
|
|
||||||
adb.version().expect("cannot get adb version");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_shell_commands() {
|
|
||||||
let mut device = new_device();
|
|
||||||
|
|
||||||
device.shell_command(["ls"]).expect("error while executing `ls` command");
|
|
||||||
device.shell_command(["pwd"]).expect("error while executing `pwd` command");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_devices() {
|
|
||||||
let mut adb = new_client();
|
|
||||||
adb.devices().expect("cannot list devices");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_devices_long() {
|
|
||||||
let mut adb = new_client();
|
|
||||||
adb.devices_long().expect("cannot list devices long");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_static_devices_long() {
|
|
||||||
let inputs = ["7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4",
|
|
||||||
"n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58",
|
|
||||||
"192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97",
|
|
||||||
"emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101"];
|
|
||||||
for input in inputs {
|
|
||||||
DeviceLong::try_from(input.as_bytes().to_vec())
|
|
||||||
.expect(&format!("cannot parse input: '{input}'"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_send_recv() {
|
|
||||||
// Create random "Reader" in memory
|
|
||||||
let mut key = [0u8; 1000];
|
|
||||||
rand::thread_rng().fill(&mut key[..]);
|
|
||||||
let mut c: Cursor<Vec<u8>> = Cursor::new(key.to_vec());
|
|
||||||
|
|
||||||
let mut device = new_device();
|
|
||||||
|
|
||||||
const TEST_FILENAME: &'static str = "/data/local/tmp/test_file";
|
|
||||||
// Send it
|
|
||||||
device
|
|
||||||
.send(&mut c, TEST_FILENAME)
|
|
||||||
.expect("cannot send file");
|
|
||||||
|
|
||||||
// Pull it to memory
|
|
||||||
let mut res = vec![];
|
|
||||||
device
|
|
||||||
.recv(TEST_FILENAME, &mut res)
|
|
||||||
.expect("cannot recv file");
|
|
||||||
|
|
||||||
// diff
|
|
||||||
assert_eq!(c.get_ref(), &res);
|
|
||||||
|
|
||||||
device
|
|
||||||
.shell_command::<&str>([format!("rm {TEST_FILENAME}").as_str()])
|
|
||||||
.expect("cannot remove test file");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn multiple_connexions() {
|
|
||||||
let mut connection = new_client();
|
|
||||||
|
|
||||||
for _ in 0..2 {
|
|
||||||
let _ = connection.devices().expect("cannot get version");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn command_emulator() {
|
|
||||||
let mut connection = new_client();
|
|
||||||
let mut emulator = connection
|
|
||||||
.get_emulator_device()
|
|
||||||
.expect("no emulator running");
|
|
||||||
emulator.hello().expect("cannot hello");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user