Skip to content

Commit 01e4134

Browse files
wxitcodecocool97
authored andcommitted
Refactor shell command handling to support v2
1 parent 0443065 commit 01e4134

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

adb_client/src/models/adb_server_command.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pub(crate) enum AdbServerCommand {
2626
Install(u64),
2727
WaitForDevice(WaitForDeviceState, WaitForDeviceTransport),
2828
// Local commands
29-
ShellCommand(String),
30-
Shellv2Command(String),
29+
ShellCommand(Vec<String>, String),
3130
Shell,
3231
FrameBuffer,
3332
Sync,
@@ -52,14 +51,14 @@ impl Display for AdbServerCommand {
5251
AdbServerCommand::TrackDevices => write!(f, "host:track-devices"),
5352
AdbServerCommand::TransportAny => write!(f, "host:transport-any"),
5453
AdbServerCommand::TransportSerial(serial) => write!(f, "host:transport:{serial}"),
55-
AdbServerCommand::ShellCommand(command) => match std::env::var("TERM") {
56-
Ok(term) => write!(f, "shell,TERM={term},raw:{command}"),
57-
Err(_) => write!(f, "shell,raw:{command}"),
58-
},
59-
AdbServerCommand::Shellv2Command(command) => match std::env::var("TERM") {
60-
Ok(term) => write!(f, "shell,v2,TERM={term},raw:{command}"),
61-
Err(_) => write!(f, "shell,raw:{command}"),
62-
},
54+
AdbServerCommand::ShellCommand(args, command) => {
55+
let args_s = args.join(",");
56+
write!(
57+
f,
58+
"shell{}{args_s},raw:{command}",
59+
if args.is_empty() { "" } else { "," }
60+
)
61+
}
6362
AdbServerCommand::Shell => match std::env::var("TERM") {
6463
Ok(term) => write!(f, "shell,TERM={term},raw:"),
6564
Err(_) => write!(f, "shell,raw:"),

adb_client/src/server_device/adb_server_device_commands.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,23 @@ impl ADBDeviceExt for ADBServerDevice {
2222

2323
self.set_serial_transport()?;
2424

25-
let cmd = command.join(" ");
26-
let server_command = if supported_features.contains(&HostFeatures::ShellV2) {
27-
AdbServerCommand::Shellv2Command(cmd)
28-
} else {
29-
AdbServerCommand::ShellCommand(cmd)
30-
};
31-
32-
self.transport.send_adb_request(server_command)?;
25+
// Prepare shell command arguments
26+
let mut args = Vec::new();
27+
let command_string = command.join(" ");
28+
29+
// Add v2 mode if supported
30+
if supported_features.contains(&HostFeatures::ShellV2) {
31+
args.push("v2".to_string());
32+
}
33+
34+
// Include terminal information if available
35+
if let Ok(term) = std::env::var("TERM") {
36+
args.push(format!("TERM={term}"));
37+
}
38+
39+
// Send the request
40+
self.transport
41+
.send_adb_request(AdbServerCommand::ShellCommand(args, command_string))?;
3342

3443
loop {
3544
let mut buffer = [0; BUFFER_SIZE];

0 commit comments

Comments
 (0)