diff --git a/Cargo.toml b/Cargo.toml index b27c33f..7637529 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "adb_client" -version = "0.2.1" +version = "0.3.0" description = "Rust ADB (Android Debug Bridge) client library" keywords = ["adb", "android"] readme = "README.md" @@ -19,7 +19,7 @@ path = "bin/adb_client.rs" required-features = ["adbclient"] [dependencies] -thiserror = { version = "1.0.30", default_features = false } +thiserror = { version = "1.0.31", default_features = false } regex = { version = "1.5.5", default_features = false, features = ["std", "perf", "unicode"] } termios = { version = "0.3.3", default_features = false } diff --git a/README.md b/README.md index 2c1a8c2..42c8cb1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ To launch a command on host device : use adb_client::AdbTcpConnexion; let connexion = AdbTcpConnexion::new(); -connexion.shell_command("df -h"); +connexion.shell_command(None, vec!["df", "-h"]); ``` To get available ADB devices : diff --git a/src/adb_tcp_connexion.rs b/src/adb_tcp_connexion.rs index cf4408f..0ebc200 100644 --- a/src/adb_tcp_connexion.rs +++ b/src/adb_tcp_connexion.rs @@ -192,15 +192,25 @@ impl AdbTcpConnexion { } /// Runs 'command' in a shell on the device, and return its output and error streams. - pub fn shell_command(&self, serial: Option, command: Vec) -> Result<()> { + pub fn shell_command(&self, serial: Option, command: Vec) -> Result<()> { let mut tcp_stream = TcpStream::connect(self.socket_addr)?; match serial { None => Self::send_adb_request(&mut tcp_stream, AdbCommand::TransportAny)?, - Some(serial) => { - Self::send_adb_request(&mut tcp_stream, AdbCommand::TransportSerial(serial))? - } + Some(serial) => Self::send_adb_request( + &mut tcp_stream, + AdbCommand::TransportSerial(serial.to_string()), + )?, } - Self::send_adb_request(&mut tcp_stream, AdbCommand::ShellCommand(command.join(" ")))?; + Self::send_adb_request( + &mut tcp_stream, + AdbCommand::ShellCommand( + command + .iter() + .map(|v| v.to_string()) + .collect::>() + .join(" "), + ), + )?; let buffer_size = 512; loop { @@ -222,7 +232,7 @@ impl AdbTcpConnexion { } /// Starts an interactive shell session on the device. Redirects stdin/stdout/stderr as appropriate. - pub fn shell(&self, serial: Option) -> Result<()> { + pub fn shell(&self, serial: Option) -> Result<()> { let mut adb_termios = ADBTermios::new(std::io::stdin())?; adb_termios.set_adb_termios()?; @@ -232,7 +242,7 @@ impl AdbTcpConnexion { match serial { None => Self::send_adb_request(&mut tcp_stream, AdbCommand::TransportAny)?, Some(serial) => { - Self::send_adb_request(&mut tcp_stream, AdbCommand::TransportSerial(serial))? + Self::send_adb_request(&mut tcp_stream, AdbCommand::TransportSerial(serial.to_string()))? } } Self::send_adb_request(&mut tcp_stream, AdbCommand::Shell)?;