From 886adfa392467ffcde7eb9f3144122ec9fb5df20 Mon Sep 17 00:00:00 2001 From: Cendy <57063107+CLOEI@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:26:13 +0700 Subject: [PATCH] feat: adb custom path (#101) --------- Co-authored-by: LIAUD Corentin --- adb_cli/src/main.rs | 2 +- adb_client/src/server/adb_server.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/adb_cli/src/main.rs b/adb_cli/src/main.rs index 1eb2434..7e0a856 100644 --- a/adb_cli/src/main.rs +++ b/adb_cli/src/main.rs @@ -36,7 +36,7 @@ fn main() -> Result<()> { // 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()); + ADBServer::start(&HashMap::default(), &None); } let device = match server_command.serial { diff --git a/adb_client/src/server/adb_server.rs b/adb_client/src/server/adb_server.rs index 1b9453c..d649348 100644 --- a/adb_client/src/server/adb_server.rs +++ b/adb_client/src/server/adb_server.rs @@ -15,6 +15,9 @@ pub struct ADBServer { pub(crate) socket_addr: Option, /// adb-server start envs pub(crate) envs: HashMap, + /// Path to adb binary + /// If not set, will use adb from PATH + pub(crate) adb_path: Option, } impl ADBServer { @@ -24,13 +27,24 @@ impl ADBServer { transport: None, socket_addr: Some(address), 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) -> Self { + Self { + transport: None, + socket_addr: Some(address), + envs: HashMap::new(), + adb_path, } } /// Start an instance of `adb-server` - pub fn start(envs: &HashMap) { + pub fn start(envs: &HashMap, adb_path: &Option) { // ADB Server is local, we start it if not already running - let mut command = Command::new("adb"); + 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); @@ -79,7 +93,7 @@ impl ADBServer { }; if is_local_ip { - Self::start(&self.envs); + Self::start(&self.envs, &self.adb_path); } transport.connect()?;