-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: USB shell command, WIP for other commands
- Loading branch information
Showing
16 changed files
with
394 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::io::Write; | ||
|
||
use crate::Result; | ||
|
||
/// Trait representing all features available on both [`ADBServerDevice`] and [`ADBUSBDevice`] | ||
pub trait ADBDeviceExt { | ||
/// Runs 'command' in a shell on the device, and write its output and error streams into [`output`]. | ||
fn shell_command<S: ToString, W: Write>( | ||
&mut self, | ||
command: impl IntoIterator<Item = S>, | ||
output: W, | ||
) -> Result<()>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::io::{Read, Write}; | ||
|
||
use crate::{ | ||
models::{AdbServerCommand, HostFeatures}, | ||
ADBDeviceExt, ADBServerDevice, Result, RustADBError, | ||
}; | ||
|
||
impl ADBDeviceExt for ADBServerDevice { | ||
fn shell_command<S: ToString, W: Write>( | ||
&mut self, | ||
command: impl IntoIterator<Item = S>, | ||
mut output: W, | ||
) -> Result<()> { | ||
let supported_features = self.host_features()?; | ||
if !supported_features.contains(&HostFeatures::ShellV2) | ||
&& !supported_features.contains(&HostFeatures::Cmd) | ||
{ | ||
return Err(RustADBError::ADBShellNotSupported); | ||
} | ||
|
||
let serial = self.identifier.clone(); | ||
self.connect()? | ||
.send_adb_request(AdbServerCommand::TransportSerial(serial))?; | ||
self.get_transport_mut() | ||
.send_adb_request(AdbServerCommand::ShellCommand( | ||
command | ||
.into_iter() | ||
.map(|v| v.to_string()) | ||
.collect::<Vec<_>>() | ||
.join(" "), | ||
))?; | ||
|
||
const BUFFER_SIZE: usize = 4096; | ||
loop { | ||
let mut buffer = [0; BUFFER_SIZE]; | ||
match self | ||
.get_transport_mut() | ||
.get_raw_connection()? | ||
.read(&mut buffer) | ||
{ | ||
Ok(size) => { | ||
if size == 0 { | ||
return Ok(()); | ||
} else { | ||
output.write_all(&buffer[..size])?; | ||
} | ||
} | ||
Err(e) => { | ||
return Err(RustADBError::IOError(e)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.