Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions adb_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ fn run_command(mut device: Box<dyn ADBDeviceExt>, command: DeviceCommands) -> AD
device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?;
}
} else {
let commands: Vec<&str> = commands.iter().map(String::as_str).collect();
device.shell_command(&commands, &mut std::io::stdout())?;
device.shell_command(&commands.join(" "), &mut std::io::stdout())?;
}
}
DeviceCommands::Pull {
Expand Down
5 changes: 4 additions & 1 deletion adb_cli/src/models/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use super::RebootTypeCommand;
#[derive(Parser, Debug)]
pub enum DeviceCommands {
/// Spawn an interactive shell or run a list of commands on the device
Shell { commands: Vec<String> },
Shell {
#[arg(trailing_var_arg = true)]
commands: Vec<String>,
},
/// Pull a file from device
Pull { source: String, destination: String },
/// Push a file on device
Expand Down
18 changes: 7 additions & 11 deletions adb_client/src/adb_device_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{RebootType, Result};
/// Trait representing all features available on ADB devices.
pub trait ADBDeviceExt {
/// Runs command in a shell on the device, and write its output and error streams into output.
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()>;
fn shell_command(&mut self, command: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()>;

/// Starts an interactive shell session on the device.
/// Input data is read from reader and write to writer.
Expand Down Expand Up @@ -50,16 +50,12 @@ pub trait ADBDeviceExt {
) -> Result<Vec<u8>> {
let mut output = Vec::new();
self.shell_command(
&[
"am",
"start",
&format!(
"{}/{}.{}",
package.as_ref(),
package.as_ref(),
activity.as_ref()
),
],
&format!(
"am start {}/{}.{}",
package.as_ref(),
package.as_ref(),
activity.as_ref()
),
&mut output,
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

impl<T: ADBMessageTransport> ADBDeviceExt for ADBMessageDevice<T> {
#[inline]
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
fn shell_command(&mut self, command: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
self.shell_command(command, output)
}

Expand Down
8 changes: 6 additions & 2 deletions adb_client/src/message_devices/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ use crate::{

impl<T: ADBMessageTransport> ADBMessageDevice<T> {
/// Runs 'command' in a shell on the device, and write its output and error streams into output.
pub(crate) fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
pub(crate) fn shell_command(
&mut self,
command: &dyn AsRef<str>,
output: &mut dyn Write,
) -> Result<()> {
let session = self.open_session(&ADBLocalCommand::ShellCommand(
command.join(" "),
command.as_ref().to_string(),
Vec::new(),
))?;

Expand Down
2 changes: 1 addition & 1 deletion adb_client/src/message_devices/tcp/adb_tcp_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ADBTcpDevice {

impl ADBDeviceExt for ADBTcpDevice {
#[inline]
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
fn shell_command(&mut self, command: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
self.inner.shell_command(command, output)
}

Expand Down
2 changes: 1 addition & 1 deletion adb_client/src/message_devices/usb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use adb_client::{usb::ADBUSBDevice, ADBDeviceExt};
let vendor_id = 0x04e8;
let product_id = 0x6860;
let mut device = ADBUSBDevice::new(vendor_id, product_id).expect("cannot find device");
device.shell_command(&["df", "-h"], &mut std::io::stdout());
device.shell_command(&"df -h", &mut std::io::stdout());
```

## Push a file to the device
Expand Down
2 changes: 1 addition & 1 deletion adb_client/src/message_devices/usb/adb_usb_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl ADBUSBDevice {

impl ADBDeviceExt for ADBUSBDevice {
#[inline]
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
fn shell_command(&mut self, command: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
self.inner.shell_command(command, output)
}

Expand Down
2 changes: 1 addition & 1 deletion adb_client/src/server_device/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use adb_client::{server::ADBServer, ADBDeviceExt};

let mut server = ADBServer::default();
let mut device = server.get_device().expect("cannot get device");
device.shell_command(&["df", "-h"], &mut std::io::stdout());
device.shell_command(&"df -h", &mut std::io::stdout());
```

## Push a file to the device
Expand Down
5 changes: 2 additions & 3 deletions adb_client/src/server_device/adb_server_device_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::ADBServerDevice;
const BUFFER_SIZE: usize = 65535;

impl ADBDeviceExt for ADBServerDevice {
fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
fn shell_command(&mut self, command: &dyn AsRef<str>, output: &mut dyn Write) -> Result<()> {
let supported_features = self.host_features()?;
if !supported_features.contains(&HostFeatures::ShellV2)
&& !supported_features.contains(&HostFeatures::Cmd)
Expand All @@ -25,7 +25,6 @@ impl ADBDeviceExt for ADBServerDevice {

// Prepare shell command arguments
let mut args = Vec::new();
let command_string = command.join(" ");

// Add v2 mode if supported
if supported_features.contains(&HostFeatures::ShellV2) {
Expand All @@ -41,7 +40,7 @@ impl ADBDeviceExt for ADBServerDevice {
// Send the request
self.transport
.send_adb_request(&ADBCommand::Local(ADBLocalCommand::ShellCommand(
command_string,
command.as_ref().to_string(),
args,
)))?;

Expand Down
2 changes: 1 addition & 1 deletion adb_client/src/server_device/commands/logcat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ impl<W: Write> Write for LogFilter<W> {
impl ADBServerDevice {
/// Get logs from device
pub fn get_logs<W: Write>(&mut self, output: W) -> Result<()> {
self.shell_command(&["exec logcat"], &mut LogFilter::new(output))
self.shell_command(&"exec logcat", &mut LogFilter::new(output))
}
}
6 changes: 2 additions & 4 deletions pyadb_client/src/adb_server_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ impl PyADBServerDevice {
}

/// Run shell commands on device and return the output (stdout + stderr merged)
#[expect(clippy::needless_pass_by_value)]
pub fn shell_command(&mut self, commands: Vec<String>) -> Result<Vec<u8>> {
pub fn shell_command(&mut self, command: &str) -> Result<Vec<u8>> {
let mut output = Vec::new();
let commands: Vec<&str> = commands.iter().map(|x| &**x).collect();
self.0.shell_command(&commands, &mut output)?;
self.0.shell_command(&command, &mut output)?;
Ok(output)
}

Expand Down
6 changes: 2 additions & 4 deletions pyadb_client/src/adb_usb_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ impl PyADBUSBDevice {
}

/// Run shell commands on device and return the output (stdout + stderr merged)
#[expect(clippy::needless_pass_by_value)]
pub fn shell_command(&mut self, commands: Vec<String>) -> Result<Vec<u8>> {
pub fn shell_command(&mut self, command: &str) -> Result<Vec<u8>> {
let mut output = Vec::new();
let commands: Vec<&str> = commands.iter().map(|x| &**x).collect();
self.0.shell_command(&commands, &mut output)?;
self.0.shell_command(&command, &mut output)?;
Ok(output)
}

Expand Down
Loading