Skip to main content

adb_lib/
adb.rs

1use std::process::{Command, Output};
2
3pub struct Adb {
4    adb_path: String,
5}
6
7impl Adb {
8    pub fn new(adb_path: &str) -> Self {
9        Adb {
10            adb_path: adb_path.to_string(),
11        }
12    }
13
14    pub fn execute(&self, args: &[&str]) -> Result<Output, std::io::Error> {
15        Command::new(&self.adb_path)
16            .args(args)
17            .output()
18    }
19
20    pub fn devices(&self) -> Result<String, std::io::Error> {
21        let output = self.execute(&["devices"])?;
22        Ok(String::from_utf8_lossy(&output.stdout).to_string())
23    }
24
25    pub fn install(&self, apk_path: &str) -> Result<String, std::io::Error> {
26        let output = self.execute(&["install", apk_path])?;
27        Ok(String::from_utf8_lossy(&output.stdout).to_string())
28    }
29
30    pub fn uninstall(&self, package_name: &str) -> Result<String, std::io::Error> {
31        let output = self.execute(&["uninstall", package_name])?;
32        Ok(String::from_utf8_lossy(&output.stdout).to_string())
33    }
34}