Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdf062c3e1 | ||
|
|
b8e3d02311 | ||
|
|
1b7efc1cc6 | ||
|
|
ad064a9f41 | ||
|
|
d0e0f46571 | ||
|
|
727f3a3eb4 | ||
|
|
ab77db5cc8 | ||
|
|
1255f2b5d6 | ||
|
|
eb04f9064c | ||
|
|
69107e2333 |
35
.github/workflows/python-build.yml
vendored
35
.github/workflows/python-build.yml
vendored
@@ -1,49 +1,36 @@
|
||||
name: Python - Build packages & Release
|
||||
|
||||
on:
|
||||
push: {}
|
||||
pull_request: {}
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
gen-stubs:
|
||||
name: "build-release"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build project
|
||||
run: cargo run --bin stub_gen
|
||||
|
||||
build-python-packages:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build Python stubs
|
||||
run: cargo run --bin stub_gen
|
||||
|
||||
- name: Install Python build dependencies
|
||||
run: pip install maturin==1.8.2
|
||||
|
||||
- name: Build Python packages
|
||||
run: maturin build --release -m pyadb_client/Cargo.toml --compatibility manylinux_2_25 --auditwheel=skip
|
||||
|
||||
publish-python-packages:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-python-packages]
|
||||
if: github.event_name == 'release' && github.event.action == 'created'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Python build dependencies
|
||||
run: pip install maturin==1.8.2
|
||||
run: maturin build --sdist --release -m pyadb_client/Cargo.toml
|
||||
|
||||
- name: Publish Python packages
|
||||
run: maturin publish -m pyadb_client/Cargo.toml --non-interactive --compatibility manylinux_2_25 --auditwheel=skip
|
||||
if: github.event_name == 'release' && github.event.action == 'created'
|
||||
run: maturin publish -m pyadb_client/Cargo.toml --non-interactive
|
||||
env:
|
||||
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
||||
|
||||
- name: "Publish GitHub artefacts"
|
||||
if: github.event_name == 'release' && github.event.action == 'created'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
|
||||
6
.github/workflows/rust-build.yml
vendored
6
.github/workflows/rust-build.yml
vendored
@@ -1,6 +1,10 @@
|
||||
name: Rust - Build
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
6
.github/workflows/rust-quality.yml
vendored
6
.github/workflows/rust-quality.yml
vendored
@@ -1,6 +1,10 @@
|
||||
name: Rust - Quality
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
||||
keywords = ["adb", "android", "tcp", "usb"]
|
||||
license = "MIT"
|
||||
repository = "https://github.com/cocool97/adb_client"
|
||||
version = "2.1.6"
|
||||
version = "2.1.9"
|
||||
|
||||
# To build locally when working on a new release
|
||||
[patch.crates-io]
|
||||
|
||||
@@ -14,7 +14,7 @@ adb_client = { version = "^2.0.0" }
|
||||
anyhow = { version = "1.0.94" }
|
||||
clap = { version = "4.5.23", features = ["derive"] }
|
||||
env_logger = { version = "0.11.5" }
|
||||
log = { version = "0.4.22" }
|
||||
log = { version = "0.4.26" }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
termios = { version = "0.3.3" }
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -72,6 +72,10 @@ pub fn handle_host_commands(server_command: ServerCommand<HostCommand>) -> Resul
|
||||
HostCommand::ServerStatus => {
|
||||
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(())
|
||||
|
||||
@@ -7,12 +7,15 @@ mod handlers;
|
||||
mod models;
|
||||
mod utils;
|
||||
|
||||
use adb_client::{ADBDeviceExt, ADBServer, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService};
|
||||
use adb_client::{
|
||||
ADBDeviceExt, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice, MDNSDiscoveryService,
|
||||
};
|
||||
use adb_termios::ADBTermios;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use handlers::{handle_emulator_commands, handle_host_commands, handle_local_commands};
|
||||
use models::{DeviceCommands, LocalCommand, MainCommand, Opts};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
@@ -30,11 +33,15 @@ fn main() -> Result<()> {
|
||||
MainCommand::Host(server_command) => return Ok(handle_host_commands(server_command)?),
|
||||
MainCommand::Emu(emulator_command) => return handle_emulator_commands(emulator_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());
|
||||
}
|
||||
|
||||
let device = match server_command.serial {
|
||||
Some(serial) => adb_server.get_device_by_name(&serial)?,
|
||||
None => adb_server.get_device()?,
|
||||
Some(serial) => ADBServerDevice::new(serial, Some(server_command.address)),
|
||||
None => ADBServerDevice::autodetect(Some(server_command.address)),
|
||||
};
|
||||
|
||||
match server_command.command {
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
use adb_client::{RustADBError, WaitForDeviceTransport};
|
||||
use clap::Parser;
|
||||
|
||||
fn parse_wait_for_device_device_transport(
|
||||
value: &str,
|
||||
) -> Result<WaitForDeviceTransport, RustADBError> {
|
||||
WaitForDeviceTransport::try_from(value)
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub enum HostCommand {
|
||||
/// Print current ADB version.
|
||||
@@ -28,6 +35,12 @@ pub enum HostCommand {
|
||||
},
|
||||
/// Display server status
|
||||
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)]
|
||||
|
||||
@@ -13,11 +13,11 @@ version.workspace = true
|
||||
base64 = { version = "0.22.1" }
|
||||
bincode = { version = "1.3.3" }
|
||||
byteorder = { version = "1.5.0" }
|
||||
chrono = { version = "0.4.39" }
|
||||
chrono = { version = "0.4.40" }
|
||||
homedir = { version = "0.3.4" }
|
||||
image = { version = "0.25.5" }
|
||||
lazy_static = { version = "1.5.0" }
|
||||
log = { version = "0.4.22" }
|
||||
log = { version = "0.4.26" }
|
||||
mdns-sd = { version = "0.13.2" }
|
||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
||||
num-traits = { version = "0.2.19" }
|
||||
|
||||
@@ -38,18 +38,26 @@ impl ADBTcpDevice {
|
||||
|
||||
self.get_transport_mut().write_message(message)?;
|
||||
|
||||
// At this point, we should have received a STLS command indicating that the device wants to upgrade connection with TLS
|
||||
self.get_transport_mut()
|
||||
.read_message()
|
||||
.and_then(|message| message.assert_command(MessageCommand::Stls))?;
|
||||
let message = self.get_transport_mut().read_message()?;
|
||||
|
||||
self.get_transport_mut()
|
||||
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
||||
|
||||
// Upgrade TCP connection to TLS
|
||||
self.get_transport_mut().upgrade_connection()?;
|
||||
|
||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
||||
// Check if client is requesting a secure connection and upgrade it if necessary
|
||||
match message.header().command() {
|
||||
MessageCommand::Stls => {
|
||||
self.get_transport_mut()
|
||||
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
||||
self.get_transport_mut().upgrade_connection()?;
|
||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
||||
}
|
||||
MessageCommand::Cnxn => {
|
||||
log::debug!("Unencrypted connection established");
|
||||
}
|
||||
_ => {
|
||||
return Err(crate::RustADBError::WrongResponseReceived(
|
||||
"Expected CNXN or STLS command".to_string(),
|
||||
message.header().command().to_string(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -65,10 +65,15 @@ impl TryFrom<ADBServerDevice> for ADBEmulatorDevice {
|
||||
type Error = RustADBError;
|
||||
|
||||
fn try_from(value: ADBServerDevice) -> std::result::Result<Self, Self::Error> {
|
||||
ADBEmulatorDevice::new(
|
||||
value.identifier.clone(),
|
||||
Some(*value.transport.get_socketaddr().ip()),
|
||||
)
|
||||
match &value.identifier {
|
||||
Some(device_identifier) => ADBEmulatorDevice::new(
|
||||
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(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,9 @@ pub enum RustADBError {
|
||||
/// An error occurred while sending data to channel
|
||||
#[error(transparent)]
|
||||
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 {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::{WaitForDeviceState, WaitForDeviceTransport};
|
||||
|
||||
use super::RebootType;
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
@@ -22,6 +24,7 @@ pub(crate) enum AdbServerCommand {
|
||||
ReconnectOffline,
|
||||
Uninstall(String),
|
||||
Install(u64),
|
||||
WaitForDevice(WaitForDeviceState, WaitForDeviceTransport),
|
||||
// Local commands
|
||||
ShellCommand(String),
|
||||
Shell,
|
||||
@@ -87,6 +90,12 @@ impl Display for AdbServerCommand {
|
||||
AdbServerCommand::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}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,33 @@ impl ADBServer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Start an instance of `adb-server`
|
||||
pub fn start(envs: &HashMap<String, String>) {
|
||||
// ADB Server is local, we start it if not already running
|
||||
let mut command = Command::new("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}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the current selected transport
|
||||
pub(crate) fn get_transport(&mut self) -> Result<&mut TCPServerTransport> {
|
||||
self.transport
|
||||
@@ -52,22 +79,7 @@ impl ADBServer {
|
||||
};
|
||||
|
||||
if is_local_ip {
|
||||
// ADB Server is local, we start it if not already running
|
||||
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}"),
|
||||
}
|
||||
Self::start(&self.envs);
|
||||
}
|
||||
|
||||
transport.connect()?;
|
||||
|
||||
@@ -7,3 +7,4 @@ mod pair;
|
||||
mod reconnect;
|
||||
mod server_status;
|
||||
mod version;
|
||||
mod wait_for_device;
|
||||
|
||||
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::{
|
||||
models::AdbServerCommand, ADBServer, Result, WaitForDeviceState, WaitForDeviceTransport,
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||
Regex::new("^(?P<identifier>\\S+)\\s+(?P<state>\\w+) ((usb:(?P<usb1>.*)|(?P<usb2>\\d-\\d)) )?(product:(?P<product>\\w+) model:(?P<model>\\w+) device:(?P<device>\\w+) )?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>\w+)\s+model:(?P<model>\w+)\s+device:(?P<device>\w+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
||||
});
|
||||
|
||||
/// Represents a new device with more informations.
|
||||
|
||||
@@ -4,6 +4,7 @@ mod device_short;
|
||||
mod device_state;
|
||||
mod mdns_services;
|
||||
mod server_status;
|
||||
mod wait_for_device;
|
||||
|
||||
pub use adb_version::AdbVersion;
|
||||
pub use device_long::DeviceLong;
|
||||
@@ -11,3 +12,4 @@ pub use device_short::DeviceShort;
|
||||
pub use device_state::DeviceState;
|
||||
pub use mdns_services::MDNSServices;
|
||||
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::{models::AdbServerCommand, ADBTransport, Result, TCPServerTransport};
|
||||
use std::net::SocketAddrV4;
|
||||
|
||||
/// Represents a device connected to the ADB server.
|
||||
#[derive(Debug)]
|
||||
pub struct ADBServerDevice {
|
||||
/// Unique device identifier.
|
||||
pub identifier: String,
|
||||
pub identifier: Option<String>,
|
||||
/// Internal [TCPServerTransport]
|
||||
pub(crate) transport: TCPServerTransport,
|
||||
}
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Instantiates a new [ADBServerDevice]
|
||||
pub fn new(identifier: String, socket_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = if let Some(addr) = socket_addr {
|
||||
TCPServerTransport::new(addr)
|
||||
} else {
|
||||
TCPServerTransport::default()
|
||||
};
|
||||
/// Instantiates a new [ADBServerDevice], knowing its ADB identifier (as returned by `adb devices` command).
|
||||
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -31,6 +37,19 @@ impl ADBServerDevice {
|
||||
|
||||
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 {
|
||||
|
||||
@@ -20,9 +20,8 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
return Err(RustADBError::ADBShellNotSupported);
|
||||
}
|
||||
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?;
|
||||
|
||||
@@ -59,9 +58,7 @@ impl ADBDeviceExt for ADBServerDevice {
|
||||
return Err(RustADBError::ADBShellNotSupported);
|
||||
}
|
||||
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
self.transport.send_adb_request(AdbServerCommand::Shell)?;
|
||||
|
||||
let mut read_stream = self.transport.get_raw_connection()?.try_clone()?;
|
||||
|
||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Forward socket connection
|
||||
pub fn forward(&mut self, remote: String, local: String) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Forward(remote, local), false)
|
||||
@@ -14,9 +12,7 @@ impl ADBServerDevice {
|
||||
|
||||
/// Remove all previously applied forward rules
|
||||
pub fn forward_remove_all(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::ForwardRemoveAll, false)
|
||||
|
||||
@@ -11,9 +11,7 @@ use crate::{
|
||||
impl ADBServerDevice {
|
||||
/// Inner method requesting framebuffer from Android device
|
||||
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||
let serial: String = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::FrameBuffer)?;
|
||||
|
||||
@@ -6,9 +6,7 @@ use crate::{
|
||||
impl ADBServerDevice {
|
||||
/// Lists available ADB server features.
|
||||
pub fn host_features(&mut self) -> Result<Vec<HostFeatures>> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
let features = self
|
||||
.transport
|
||||
|
||||
@@ -13,9 +13,7 @@ impl ADBServerDevice {
|
||||
|
||||
let file_size = apk_file.metadata()?.len();
|
||||
|
||||
let serial: String = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::Install(file_size))?;
|
||||
|
||||
@@ -11,9 +11,7 @@ use std::{
|
||||
impl ADBServerDevice {
|
||||
/// Lists files in path on the device.
|
||||
pub fn list<A: AsRef<str>>(&mut self, path: A) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
@@ -6,9 +6,7 @@ use crate::{
|
||||
impl ADBServerDevice {
|
||||
/// Reboots the device
|
||||
pub fn reboot(&mut self, reboot_type: RebootType) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reboot(reboot_type), false)
|
||||
|
||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Reconnect device
|
||||
pub fn reconnect(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reconnect, false)
|
||||
|
||||
@@ -71,9 +71,7 @@ impl<R: Read> Read for ADBRecvCommandReader<R> {
|
||||
impl ADBServerDevice {
|
||||
/// Receives path to stream from the device.
|
||||
pub fn pull(&mut self, path: &dyn AsRef<str>, stream: &mut dyn Write) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Reverse socket connection
|
||||
pub fn reverse(&mut self, remote: String, local: String) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Reverse(remote, local), false)
|
||||
@@ -14,9 +12,7 @@ impl ADBServerDevice {
|
||||
|
||||
/// Remove all reverse rules
|
||||
pub fn reverse_remove_all(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::ReverseRemoveAll, false)
|
||||
|
||||
@@ -45,9 +45,7 @@ impl ADBServerDevice {
|
||||
/// Send stream to path on the device.
|
||||
pub fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||
log::info!("Sending data to {}", path.as_ref());
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
@@ -39,9 +39,7 @@ impl ADBServerDevice {
|
||||
|
||||
/// Stat file given as path on the device.
|
||||
pub fn stat<A: AsRef<str>>(&mut self, path: A) -> Result<AdbStatResponse> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
// Set device in SYNC mode
|
||||
self.transport.send_adb_request(AdbServerCommand::Sync)?;
|
||||
|
||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Set adb daemon to tcp/ip mode
|
||||
pub fn tcpip(&mut self, port: u16) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::TcpIp(port), false)
|
||||
|
||||
@@ -5,9 +5,7 @@ use crate::{models::AdbServerCommand, server_device::ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Uninstall a package from device
|
||||
pub fn uninstall(&mut self, package_name: &str) -> Result<()> {
|
||||
let serial: String = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
self.set_serial_transport()?;
|
||||
|
||||
self.transport
|
||||
.send_adb_request(AdbServerCommand::Uninstall(package_name.to_string()))?;
|
||||
|
||||
@@ -3,10 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
||||
impl ADBServerDevice {
|
||||
/// Set adb daemon to usb mode
|
||||
pub fn usb(&mut self) -> Result<()> {
|
||||
let serial = self.identifier.clone();
|
||||
self.connect()?
|
||||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;
|
||||
|
||||
self.set_serial_transport()?;
|
||||
self.transport
|
||||
.proxy_connection(AdbServerCommand::Usb, false)
|
||||
.map(|_| ())
|
||||
|
||||
@@ -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]
|
||||
pub fn get_socketaddr(&self) -> SocketAddrV4 {
|
||||
self.socket_addr
|
||||
@@ -113,6 +121,11 @@ impl TCPServerTransport {
|
||||
self.get_raw_connection()?
|
||||
.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
|
||||
let mut request_status = [0; 4];
|
||||
self.get_raw_connection()?.read_exact(&mut request_status)?;
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
[package]
|
||||
name = "pyadb_client"
|
||||
description = "Python wrapper for adb_client library"
|
||||
authors.workspace = true
|
||||
description = "Python wrapper for adb_client library"
|
||||
edition.workspace = true
|
||||
homepage.workspace = true
|
||||
keywords.workspace = true
|
||||
license.workspace = true
|
||||
name = "pyadb_client"
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
version.workspace = true
|
||||
readme = "README.md"
|
||||
|
||||
[lib]
|
||||
name = "pyadb_client"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
name = "pyadb_client"
|
||||
|
||||
[[bin]]
|
||||
name = "stub_gen"
|
||||
doc = false
|
||||
name = "stub_gen"
|
||||
|
||||
[dependencies]
|
||||
adb_client = { path = "../adb_client" }
|
||||
anyhow = { version = "1.0.95" }
|
||||
adb_client = { version = "2.1.5" }
|
||||
pyo3 = { version = "0.23.4", features = ["extension-module", "anyhow", "abi3-py37"] }
|
||||
pyo3 = { version = "0.23.4", features = [
|
||||
"abi3-py37",
|
||||
"anyhow",
|
||||
"extension-module",
|
||||
] }
|
||||
pyo3-stub-gen = "0.7.0"
|
||||
pyo3-stub-gen-derive = "0.7.0"
|
||||
pyo3-stub-gen-derive = "0.7.0"
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct PyADBServerDevice(pub ADBServerDevice);
|
||||
impl PyADBServerDevice {
|
||||
#[getter]
|
||||
/// Device identifier
|
||||
pub fn identifier(&self) -> String {
|
||||
pub fn identifier(&self) -> Option<String> {
|
||||
self.0.identifier.clone()
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_static_devices_long() {
|
||||
let inputs = ["7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4"];
|
||||
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}'"));
|
||||
|
||||
Reference in New Issue
Block a user