droidrun_core/driver/
mod.rs1pub mod android;
4pub mod recording;
5
6use std::collections::HashSet;
7use std::path::Path;
8
9use async_trait::async_trait;
10use serde::{Deserialize, Serialize};
11
12use crate::error::Result;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct AppInfo {
17 pub package: String,
18 pub label: String,
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct Point {
24 pub x: i32,
25 pub y: i32,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30pub enum Action {
31 Tap,
32 Swipe,
33 InputText,
34 PressKey,
35 Drag,
36 StartApp,
37 InstallApp,
38 Screenshot,
39 GetUiTree,
40 GetDate,
41 GetApps,
42 ListPackages,
43}
44
45#[async_trait]
50pub trait DeviceDriver: Send + Sync {
51 async fn connect(&mut self) -> Result<()>;
55
56 async fn ensure_connected(&mut self) -> Result<()>;
58
59 async fn tap(&self, x: i32, y: i32) -> Result<()>;
63
64 async fn swipe(
66 &self,
67 x1: i32,
68 y1: i32,
69 x2: i32,
70 y2: i32,
71 duration_ms: u32,
72 ) -> Result<()>;
73
74 async fn input_text(&self, text: &str, clear: bool) -> Result<bool>;
76
77 async fn press_key(&self, keycode: i32) -> Result<()>;
79
80 async fn drag(
82 &self,
83 x1: i32,
84 y1: i32,
85 x2: i32,
86 y2: i32,
87 duration_ms: u32,
88 ) -> Result<()>;
89
90 async fn start_app(&self, package: &str, activity: Option<&str>) -> Result<String>;
94
95 async fn install_app(&self, path: &Path) -> Result<String>;
97
98 async fn get_apps(&self, include_system: bool) -> Result<Vec<AppInfo>>;
100
101 async fn list_packages(&self, include_system: bool) -> Result<Vec<String>>;
103
104 async fn screenshot(&self, hide_overlay: bool) -> Result<Vec<u8>>;
108
109 async fn get_ui_tree(&self) -> Result<serde_json::Value>;
111
112 async fn get_date(&self) -> Result<String>;
114
115 fn supported_actions(&self) -> &HashSet<Action>;
119}