1use std::io::prelude::*;
2
3use super::client::*;
4use crate::result::*;
5
6pub trait AdbShell {
7 fn shell_exec(&mut self, cmd: &str) -> AdbResult<Vec<u8>>;
8}
9
10impl AdbShell for AdbConnection {
11 fn shell_exec(&mut self, cmd: &str) -> AdbResult<Vec<u8>> {
12 let stream = self.open_stream(&format!("shell:{}", cmd))?;
13 let mut buf = vec![];
14
15 loop {
16 let packet = stream.recv()?;
17 match packet.command {
18 Command::A_WRTE => {
19 buf.write_all(&packet.payload)?;
20 stream.send_ok()?;
21 }
22 Command::A_CLSE => {
23 break;
24 }
25 cmd => return Err(AdbError::UnexpectedCommand(cmd)),
26 }
27 }
28
29 Ok(buf)
30 }
31}