rust_adb/client/
mod.rs

1use std::collections::HashMap;
2use std::fs::File;
3
4use crate::client::adb_client::AdbClientImpl;
5use std::net::TcpStream;
6use std::thread::JoinHandle;
7
8use crate::error::adb::AdbError;
9
10mod adb_client;
11mod device_client;
12
13pub fn new_adb_client(host: &String, port: i32, bin_path: String) -> Box<dyn AdbClient> {
14    Box::new(AdbClientImpl {
15        host: host.clone(),
16        port: port.clone(),
17        bin_path: bin_path.clone(),
18    })
19}
20
21pub trait AdbClient {
22    fn start_server(&mut self) -> Result<(), AdbError>;
23    fn kill_server(&mut self) -> Result<(), AdbError>;
24    fn restart_server(&mut self) -> Result<(), AdbError>;
25    fn get_connection(&mut self) -> Result<TcpStream, AdbError>;
26    fn get_version(&mut self) -> Result<String, AdbError>;
27    fn disconnect(&mut self, host: String, port: i32) -> Result<(), AdbError>;
28    fn list_devices(&mut self) -> Result<Vec<Device>, AdbError>;
29    fn list_devices_with_path(&mut self) -> Result<Vec<DeviceWithPath>, AdbError>;
30    fn get_device(&mut self, serial_no: String) -> Result<Box<dyn DeviceService>, AdbError>;
31    fn track_devices(
32        &mut self, on_change: fn(Vec<Device>), on_error: fn(AdbError),
33    ) -> Result<JoinHandle<()>, AdbError>;
34}
35
36pub trait DeviceService {
37    fn push(&mut self, content: File, path: String, mode: i32) -> Result<String, AdbError>;
38    fn shell_sync(&mut self, command: &String) -> Result<String, AdbError>;
39    fn shell_async(&mut self, command: &String) -> Result<TcpStream, AdbError>;
40    fn get_packages(&mut self, params: &String) -> Result<Vec<String>, AdbError>;
41    fn get_features(&mut self) -> Result<HashMap<String, String>, AdbError>;
42    fn get_properties(&mut self, params: &String) -> Result<HashMap<String, String>, AdbError>;
43    fn logcat(
44        &mut self, params: &String, consumer: fn(LogEntry), error_handler: fn(AdbError),
45    ) -> Result<JoinHandle<()>, AdbError>;
46}
47
48#[derive(Debug)]
49pub struct Device {
50    pub serial_no: String,
51    pub status: String,
52}
53
54#[derive(Debug)]
55pub struct DeviceWithPath {
56    pub serial_no: String,
57    pub status: String,
58    pub product: String,
59    pub model: String,
60    pub device: String,
61    pub transport_id: String,
62}
63
64#[derive(Debug)]
65pub struct LogEntry {
66    pub pid: u32,
67    pub tid: u32,
68    pub tag: u32,
69    pub sec: u32,
70    pub nsec: u32,
71    pub priority: u32,
72    pub header: Vec<u8>,
73    pub log: Vec<u8>,
74}