Struct ADBDevice

Source
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

Source

pub fn new(id: &str, status: impl Into<DeviceStatus>) -> Self

创建新设备实例

Source

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}
Source

pub fn with_name(self, name: &str) -> Self

设置设备名称

Source

pub fn with_model(self, model: &str) -> Self

设置设备模型

Source

pub fn with_product(self, product: &str) -> Self

设置设备产品信息

Source

pub fn with_transport_id(self, transport_id: &str) -> Self

设置传输 ID

Source

pub fn add_property(self, key: &str, value: &str) -> Self

添加设备属性

Trait Implementations§

Source§

impl Clone for ADBDevice

Source§

fn clone(&self) -> ADBDevice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ADBDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ADBDevice

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ADBDevice

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,