adb_utils/commands/scripting/
wait.rs

1use std::{fmt::Display, process::Command};
2
3use crate::{ADBCommand, ADBResult};
4
5/// Wait for the device to be in the given state
6pub struct ADBWait {
7    shell: Command,
8}
9
10impl ADBWait {
11    pub fn new(transport: Transport, state: State) -> Self {
12        let mut cmd = Command::new("adb");
13        cmd.arg(format!("wait-for-{}-{}", transport, state));
14
15        ADBWait { shell: cmd }
16    }
17}
18
19pub enum Transport {
20    Usb,
21    Local,
22    Any,
23}
24
25impl Display for Transport {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(
28            f,
29            "{}",
30            match self {
31                Transport::Usb => "usb",
32                Transport::Local => "local",
33                Transport::Any => "any",
34            }
35        )
36    }
37}
38
39pub enum State {
40    Bootloader,
41    Device,
42    Disconnect,
43    Recovery,
44    Rescue,
45    Sideload,
46}
47
48impl Display for State {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        write!(
51            f,
52            "{}",
53            match self {
54                State::Bootloader => "bootloader",
55                State::Device => "device",
56                State::Disconnect => "disconnect",
57                State::Recovery => "recovery",
58                State::Rescue => "rescue",
59                State::Sideload => "sideload",
60            }
61        )
62    }
63}
64
65impl ADBCommand for ADBWait {
66    fn build(&mut self) -> Result<&mut Command, String> {
67        Ok(&mut self.shell)
68    }
69
70    fn process_output(&self, output: ADBResult) -> ADBResult {
71        output
72    }
73}