feat: adb custom path (#101)

---------

Co-authored-by: LIAUD Corentin <corentinliaud26@gmail.com>
This commit is contained in:
Cendy
2025-03-12 23:26:13 +07:00
committed by GitHub
parent cdf062c3e1
commit 886adfa392
2 changed files with 18 additions and 4 deletions

View File

@@ -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 {

View File

@@ -15,6 +15,9 @@ pub struct ADBServer {
pub(crate) socket_addr: Option<SocketAddrV4>,
/// adb-server start envs
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 {
@@ -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<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>) {
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");
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()?;