pub struct ADBDevice {
pub id: String,
pub name: String,
pub model: Option<String>,
pub product: Option<String>,
pub transport_id: Option<String>,
pub status: DeviceStatus,
pub properties: Option<HashMap<String, String>>,
}
Expand description
ADB 设备结构体
Fields§
§id: String
§name: String
§model: Option<String>
§product: Option<String>
§transport_id: Option<String>
§status: DeviceStatus
§properties: Option<HashMap<String, String>>
Implementations§
Source§impl ADBDevice
impl ADBDevice
Sourcepub fn new(id: &str, status: impl Into<DeviceStatus>) -> Self
pub fn new(id: &str, status: impl Into<DeviceStatus>) -> Self
创建新设备实例
Sourcepub fn is_online(&self) -> bool
pub fn is_online(&self) -> bool
检查设备是否在线
Examples found in repository?
examples/basic_usage.rs (line 26)
3fn main() -> ADBResult<()> {
4 // 创建配置
5 let config = ADBConfig::default();
6
7 // 创建 ADB 实例
8 let adb = ADB::new(Some(config));
9
10 // 检查 ADB 是否可用
11 match adb.check_adb() {
12 Ok(version) => println!("ADB 版本: {}", version),
13 Err(e) => {
14 eprintln!("ADB 不可用: {}", e);
15 return Err(e);
16 }
17 }
18
19 // 列出连接的设备
20 let devices = adb.list_devices()?;
21 println!("发现 {} 个设备:", devices.len());
22
23 for device in &devices {
24 println!(" ID: {}, 名称: {}, 状态: {}", device.id, device.name, device.status);
25
26 if device.is_online() {
27 // 获取设备属性
28 let android_version = adb.get_prop(&device.id, "ro.build.version.release")?;
29 println!(" Android 版本: {}", android_version);
30
31 // 列出已安装的第三方应用
32 let apps = adb.list_packages(&device.id, false, true)?;
33 println!(" 已安装的第三方应用数量: {}", apps.len());
34
35 if !apps.is_empty() {
36 let app = &apps[0];
37 println!(" 获取应用信息: {}", app);
38
39 // 获取应用信息
40 if let Ok(info) = adb.get_package_info(&device.id, app) {
41 if let Some(version) = &info.version_name {
42 println!(" 版本: {}", version);
43 }
44 println!(" 权限数量: {}", info.permissions.len());
45 }
46
47 // 检查应用是否在运行
48 let (running, pid) = adb.is_package_running(&device.id, app)?;
49 if running {
50 println!(" 应用正在运行, PID: {:?}", pid);
51 } else {
52 println!(" 应用未运行");
53 }
54 }
55 }
56 }
57
58 Ok(())
59}
Sourcepub fn with_model(self, model: &str) -> Self
pub fn with_model(self, model: &str) -> Self
设置设备模型
Sourcepub fn with_product(self, product: &str) -> Self
pub fn with_product(self, product: &str) -> Self
设置设备产品信息
Sourcepub fn with_transport_id(self, transport_id: &str) -> Self
pub fn with_transport_id(self, transport_id: &str) -> Self
设置传输 ID
Sourcepub fn add_property(self, key: &str, value: &str) -> Self
pub fn add_property(self, key: &str, value: &str) -> Self
添加设备属性
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ADBDevice
impl<'de> Deserialize<'de> for ADBDevice
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ADBDevice
impl RefUnwindSafe for ADBDevice
impl Send for ADBDevice
impl Sync for ADBDevice
impl Unpin for ADBDevice
impl UnwindSafe for ADBDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more