Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3f95d92c2 | ||
|
|
886adfa392 | ||
|
|
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
|
name: Python - Build packages & Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push: {}
|
push:
|
||||||
pull_request: {}
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
release:
|
release:
|
||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
jobs:
|
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:
|
build-python-packages:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build Python stubs
|
||||||
|
run: cargo run --bin stub_gen
|
||||||
|
|
||||||
- name: Install Python build dependencies
|
- name: Install Python build dependencies
|
||||||
run: pip install maturin==1.8.2
|
run: pip install maturin==1.8.2
|
||||||
|
|
||||||
- name: Build Python packages
|
- name: Build Python packages
|
||||||
run: maturin build --release -m pyadb_client/Cargo.toml --compatibility manylinux_2_25 --auditwheel=skip
|
run: maturin build --sdist --release -m pyadb_client/Cargo.toml
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
- name: Publish Python packages
|
- 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:
|
env:
|
||||||
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
||||||
|
|
||||||
- name: "Publish GitHub artefacts"
|
- name: "Publish GitHub artefacts"
|
||||||
|
if: github.event_name == 'release' && github.event.action == 'created'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: |
|
||||||
|
|||||||
6
.github/workflows/rust-build.yml
vendored
6
.github/workflows/rust-build.yml
vendored
@@ -1,6 +1,10 @@
|
|||||||
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
|
||||||
|
|||||||
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
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
|||||||
keywords = ["adb", "android", "tcp", "usb"]
|
keywords = ["adb", "android", "tcp", "usb"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/cocool97/adb_client"
|
repository = "https://github.com/cocool97/adb_client"
|
||||||
version = "2.1.6"
|
version = "2.1.10"
|
||||||
|
|
||||||
# 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" }
|
||||||
|
|||||||
@@ -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(())
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ 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,
|
||||||
|
};
|
||||||
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;
|
||||||
@@ -30,11 +33,15 @@ 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 {
|
||||||
|
|||||||
@@ -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)]
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ version.workspace = true
|
|||||||
base64 = { version = "0.22.1" }
|
base64 = { version = "0.22.1" }
|
||||||
bincode = { version = "1.3.3" }
|
bincode = { version = "1.3.3" }
|
||||||
byteorder = { version = "1.5.0" }
|
byteorder = { version = "1.5.0" }
|
||||||
chrono = { version = "0.4.39" }
|
chrono = { version = "0.4.40" }
|
||||||
homedir = { version = "0.3.4" }
|
homedir = { version = "0.3.4" }
|
||||||
image = { version = "0.25.5" }
|
image = { version = "0.25.5" }
|
||||||
lazy_static = { version = "1.5.0" }
|
lazy_static = { version = "1.5.0" }
|
||||||
log = { version = "0.4.22" }
|
log = { version = "0.4.26" }
|
||||||
mdns-sd = { version = "0.13.2" }
|
mdns-sd = { version = "0.13.2" }
|
||||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
||||||
num-traits = { version = "0.2.19" }
|
num-traits = { version = "0.2.19" }
|
||||||
|
|||||||
@@ -38,18 +38,26 @@ impl ADBTcpDevice {
|
|||||||
|
|
||||||
self.get_transport_mut().write_message(message)?;
|
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
|
let message = self.get_transport_mut().read_message()?;
|
||||||
self.get_transport_mut()
|
|
||||||
.read_message()
|
|
||||||
.and_then(|message| message.assert_command(MessageCommand::Stls))?;
|
|
||||||
|
|
||||||
self.get_transport_mut()
|
// Check if client is requesting a secure connection and upgrade it if necessary
|
||||||
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
match message.header().command() {
|
||||||
|
MessageCommand::Stls => {
|
||||||
// Upgrade TCP connection to TLS
|
self.get_transport_mut()
|
||||||
self.get_transport_mut().upgrade_connection()?;
|
.write_message(ADBTransportMessage::new(MessageCommand::Stls, 1, 0, &[]))?;
|
||||||
|
self.get_transport_mut().upgrade_connection()?;
|
||||||
log::debug!("Connection successfully upgraded from TCP to TLS");
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(),
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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}"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()?;
|
||||||
|
|||||||
@@ -7,3 +7,4 @@ mod pair;
|
|||||||
mod reconnect;
|
mod reconnect;
|
||||||
mod server_status;
|
mod server_status;
|
||||||
mod version;
|
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;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
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.
|
/// Represents a new device with more informations.
|
||||||
|
|||||||
@@ -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::{models::AdbServerCommand, ADBTransport, Result, TCPServerTransport};
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
|
|
||||||
/// Represents a device connected to the ADB server.
|
/// Represents a device connected to the ADB server.
|
||||||
#[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 {
|
||||||
|
|||||||
@@ -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()?;
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
|||||||
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)
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ use crate::{
|
|||||||
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)?;
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ use crate::{
|
|||||||
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
|
||||||
|
|||||||
@@ -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))?;
|
||||||
|
|||||||
@@ -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)?;
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ use crate::{
|
|||||||
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)
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
|||||||
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)
|
||||||
|
|||||||
@@ -71,9 +71,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)?;
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
|||||||
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)
|
||||||
|
|||||||
@@ -45,9 +45,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)?;
|
||||||
|
|||||||
@@ -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)?;
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
|||||||
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)
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ use crate::{models::AdbServerCommand, server_device::ADBServerDevice, Result};
|
|||||||
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()))?;
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ use crate::{models::AdbServerCommand, ADBServerDevice, Result};
|
|||||||
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(|_| ())
|
||||||
|
|||||||
@@ -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,26 +1,30 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pyadb_client"
|
|
||||||
description = "Python wrapper for adb_client library"
|
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
description = "Python wrapper for adb_client library"
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
homepage.workspace = true
|
homepage.workspace = true
|
||||||
keywords.workspace = true
|
keywords.workspace = true
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
|
name = "pyadb_client"
|
||||||
|
readme = "README.md"
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
readme = "README.md"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "pyadb_client"
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
name = "pyadb_client"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "stub_gen"
|
|
||||||
doc = false
|
doc = false
|
||||||
|
name = "stub_gen"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
adb_client = { path = "../adb_client" }
|
||||||
anyhow = { version = "1.0.95" }
|
anyhow = { version = "1.0.95" }
|
||||||
adb_client = { version = "2.1.5" }
|
pyo3 = { version = "0.23.4", features = [
|
||||||
pyo3 = { version = "0.23.4", features = ["extension-module", "anyhow", "abi3-py37"] }
|
"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"
|
||||||
|
|||||||
@@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_static_devices_long() {
|
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 {
|
for input in inputs {
|
||||||
DeviceLong::try_from(input.as_bytes().to_vec())
|
DeviceLong::try_from(input.as_bytes().to_vec())
|
||||||
.expect(&format!("cannot parse input: '{input}'"));
|
.expect(&format!("cannot parse input: '{input}'"));
|
||||||
|
|||||||
Reference in New Issue
Block a user