Struct ADB

Source
pub struct ADB {
    pub config: ADBConfig,
    /* private fields */
}
Expand description

ADB 主结构体

Fields§

§config: ADBConfig

Implementations§

Source§

impl ADB

Source

pub fn new(config: Option<ADBConfig>) -> Self

创建新的 ADB 实例

Source

pub fn adb_path(&self) -> &PathBuf

获取 ADB 路径

Source§

impl ADB

Source

pub fn with_retry<F, T>(&self, f: F) -> ADBResult<T>
where F: Fn() -> ADBResult<T>,

使用指数退避策略重试操作

Source

pub fn with_timeout<F, T>(&self, f: F) -> ADBResult<T>
where F: FnOnce() -> ADBResult<T> + Send + 'static, T: Send + 'static,

带超时的操作执行

Source

pub fn check_adb(&self) -> ADBResult<String>

检查 ADB 是否可用并获取版本

Source

pub fn list_devices(&self) -> ADBResult<Vec<ADBDevice>>

列出可用设备

Source

pub fn connect(&self, ip: &str, port: u16) -> ADBResult<()>

连接到远程设备

Source

pub fn disconnect(&self, ip: &str, port: Option<u16>) -> ADBResult<()>

断开与远程设备的连接

Source

pub fn disconnect_all(&self) -> ADBResult<()>

断开所有远程连接

Source

pub fn shell(&self, device_id: &str, command: &str) -> ADBResult<String>

在设备上执行 shell 命令

Source

pub fn shell_no_wait(&self, device_id: &str, command: &str) -> ADBResult<()>

执行 shell 命令但不等待完成

Source

pub fn find_device_by_ip(&self, ip: &str) -> ADBResult<Option<String>>

通过 IP 地址查找设备

Source

pub fn get_prop(&self, device_id: &str, prop_name: &str) -> ADBResult<String>

获取设备属性

Source

pub fn set_prop( &self, device_id: &str, prop_name: &str, prop_value: &str, ) -> ADBResult<()>

设置设备属性

Source

pub fn get_all_props( &self, device_id: &str, ) -> ADBResult<HashMap<String, String>>

获取设备所有属性

Source

pub fn is_device_online(&self, device_id: &str) -> ADBResult<bool>

检查设备是否在线

Source

pub fn restart_server(&self) -> ADBResult<()>

重启 ADB 服务器

Source

pub fn run_command(&self, args: &[&str]) -> ADBResult<String>

执行任意 ADB 命令

Source

pub fn wait_for_device( &self, device_id: &str, timeout_ms: Option<u64>, ) -> ADBResult<bool>

等待设备连接

Source

pub fn get_server_version(&self) -> ADBResult<u32>

获取 ADB 服务器版本

Source

pub fn get_pid_optimized( &self, device_id: &str, package_name: &str, ) -> ADBResult<Option<i32>>

优化版的进程 ID 获取

Source

pub fn is_package_running_optimized( &self, device_id: &str, package_name: &str, ) -> ADBResult<(bool, Option<i32>)>

检查包是否运行的优化版本

Source§

impl ADB

Source

pub fn get_package_info( &self, device_id: &str, package_name: &str, ) -> ADBResult<PackageInfo>

获取包信息 (增强版本)

Source

pub fn get_package_info_enhanced( &self, device_id: &str, package_name: &str, ) -> ADBResult<PackageInfo>

获取包信息 (增强版本)

Source

pub fn is_package_running( &self, device_id: &str, package_name: &str, ) -> ADBResult<(bool, Option<i32>)>

检查包是否运行

Source

pub fn get_pid( &self, device_id: &str, package_name: &str, ) -> ADBResult<Option<i32>>

获取进程 ID

Source

pub fn start_app_and_wait( &self, device_id: &str, package_name: &str, activity: Option<&str>, timeout_secs: Option<u64>, ) -> ADBResult<bool>

启动一个应用并等待直到完全启动

Source

pub fn start_app( &self, device_id: &str, package_name: &str, activity: Option<&str>, ) -> ADBResult<bool>

启动应用程序

Source

pub fn stop_app(&self, device_id: &str, package_name: &str) -> ADBResult<()>

强制停止应用程序

Source

pub fn install_app(&self, device_id: &str, apk_path: &str) -> ADBResult<()>

安装应用程序

Source

pub fn uninstall_app( &self, device_id: &str, package_name: &str, ) -> ADBResult<()>

卸载应用程序

Source

pub fn uninstall_app_smart( &self, device_id: &str, package_name: &str, keep_data: bool, ) -> ADBResult<()>

智能卸载应用(清除数据和缓存)

Source

pub fn list_packages( &self, device_id: &str, only_system: bool, only_third_party: bool, ) -> ADBResult<Vec<String>>

获取设备上已安装的应用列表

Source§

impl ADB

Source

pub fn pull( &self, device_id: &str, device_path: &str, local_path: &str, options: Option<TransferOptions>, ) -> ADBResult<()>

文件拉取

Source

pub fn push( &self, device_id: &str, local_path: &str, device_path: &str, options: Option<TransferOptions>, ) -> ADBResult<()>

文件推送

Source

pub fn push_large_file( &self, device_id: &str, local_path: &str, device_path: &str, options: Option<TransferOptions>, ) -> ADBResult<()>

分块推送大文件

Source

pub fn file_exists(&self, device_id: &str, path: &str) -> ADBResult<bool>

文件存在性检查

Source

pub fn get_file_size(&self, device_id: &str, path: &str) -> ADBResult<u64>

获取文件/目录大小

Source

pub fn create_directory(&self, device_id: &str, path: &str) -> ADBResult<()>

创建目录

Source

pub fn remove_path( &self, device_id: &str, path: &str, recursive: bool, ) -> ADBResult<()>

删除文件或目录

Source

pub fn copy_on_device( &self, device_id: &str, src_path: &str, dst_path: &str, ) -> ADBResult<()>

复制设备上的文件

Source

pub fn move_on_device( &self, device_id: &str, src_path: &str, dst_path: &str, ) -> ADBResult<()>

移动设备上的文件

Source

pub fn list_directory( &self, device_id: &str, path: &str, ) -> ADBResult<Vec<String>>

列出目录内容

Source

pub fn get_file_mtime(&self, device_id: &str, path: &str) -> ADBResult<String>

获取文件最后修改时间

Source

pub fn get_available_space(&self, device_id: &str, path: &str) -> ADBResult<u64>

检查设备上的可用空间

Source

pub fn compute_md5(&self, device_id: &str, path: &str) -> ADBResult<String>

计算文件或目录的 MD5 校验和

Source

pub fn write_text_to_file( &self, device_id: &str, path: &str, content: &str, ) -> ADBResult<()>

写入文本到设备上的文件

Source

pub fn read_text_from_file( &self, device_id: &str, path: &str, ) -> ADBResult<String>

读取设备上文件的文本内容

Source

pub fn compare_files( &self, device_id: &str, local_path: &str, device_path: &str, ) -> ADBResult<bool>

比较本地文件和设备文件是否相同

Source

pub fn sync_directory_to_device( &self, device_id: &str, local_dir: &str, device_dir: &str, exclude_patterns: Option<&[&str]>, ) -> ADBResult<()>

同步目录 (本地到设备)

Source§

impl ADB

Source

pub fn enable_remote_debugging( &self, device_id: &str, port: u16, ) -> ADBResult<String>

启用设备远程调试

Source

pub fn get_device_architecture(&self, device_id: &str) -> ADBResult<String>

获取设备架构

Source

pub fn start_frida_server( &self, device_id: &str, frida_server_path: &str, port: u16, server_name: Option<&str>, use_root: Option<bool>, ) -> ADBResult<()>

在设备上启动 Frida 服务器

Source

pub fn stop_frida_server( &self, device_id: &str, server_name: Option<&str>, ) -> ADBResult<()>

停止在设备上运行的 Frida 服务器

Source

pub fn reboot(&self, device_id: &str) -> ADBResult<()>

重启设备到正常模式

Source

pub fn reboot_recovery(&self, device_id: &str) -> ADBResult<()>

重启设备到恢复模式

Source

pub fn reboot_bootloader(&self, device_id: &str) -> ADBResult<()>

重启设备到引导加载程序模式

Source§

impl ADB

Source

pub fn take_screenshot( &self, device_id: &str, output_path: &str, ) -> ADBResult<()>

从设备截图

Source

pub fn record_screen( &self, device_id: &str, output_path: &str, duration_secs: u32, size: Option<&str>, ) -> ADBResult<()>

录制设备屏幕

§参数
  • device_id - 设备 ID
  • output_path - 本地输出路径
  • duration_secs - 录制时长(秒),最大 180 秒
  • size - 可选的分辨率,格式 “widthxheight”
Source

pub fn capture_logs( &self, device_id: &str, tag: Option<&str>, priority: &str, ) -> ADBResult<String>

从设备捕获日志

Source

pub fn watch_logs( &self, device_id: &str, tag: Option<&str>, priority: &str, ) -> ADBResult<()>

实时查看日志(返回立即执行的命令)

Source

pub fn clear_logs(&self, device_id: &str) -> ADBResult<()>

清除日志

Source§

impl ADB

Source

pub fn forward( &self, device_id: &str, local_port: u16, device_port: u16, ) -> ADBResult<()>

将本地端口转发到设备端口

Source

pub fn remove_forward(&self, local_port: u16) -> ADBResult<()>

移除端口转发

Source

pub fn remove_all_forwards(&self) -> ADBResult<()>

移除所有端口转发

Source

pub fn list_forwards(&self) -> ADBResult<String>

列出所有端口转发

Source

pub fn reverse( &self, device_id: &str, remote_port: u16, local_port: u16, ) -> ADBResult<()>

反向端口转发(设备到主机)

Source

pub fn remove_reverse(&self, device_id: &str, remote_port: u16) -> ADBResult<()>

移除反向端口转发

Source

pub fn remove_all_reverses(&self, device_id: &str) -> ADBResult<()>

移除所有反向端口转发

Source§

impl ADB

Source

pub fn create_resource_manager(&self, device_id: &str) -> ResourceManager

创建资源管理器

Source

pub fn with_resources<F, T>(&self, device_id: &str, f: F) -> ADBResult<T>
where F: FnOnce(&mut ResourceManager) -> ADBResult<T>,

使用资源管理器执行操作

Source

pub fn take_screenshot_managed( &self, device_id: &str, output_path: &str, ) -> ADBResult<()>

优化的截图功能(使用资源管理器)

Source

pub fn record_screen_managed( &self, device_id: &str, output_path: &str, duration_secs: u32, size: Option<&str>, ) -> ADBResult<()>

优化的屏幕录制功能(使用资源管理器)

Source

pub fn with_temp_file<F, T>( &self, device_id: &str, prefix: &str, suffix: &str, f: F, ) -> ADBResult<T>
where F: FnOnce(&str) -> ADBResult<T>,

使用临时文件执行操作

Source§

impl ADB

Source

pub fn parallel_shell( &self, device_ids: &[&str], command: &str, ) -> HashMap<String, ADBResult<String>>

在多个设备上并行执行 shell 命令

§参数
  • device_ids - 设备 ID 列表
  • command - 要执行的 shell 命令
§返回值

返回一个 HashMap,键为设备 ID,值为命令执行结果

Source

pub fn parallel_install_app( &self, device_ids: &[&str], apk_path: &str, ) -> HashMap<String, ADBResult<()>>

在多个设备上并行安装应用

§参数
  • device_ids - 设备 ID 列表
  • apk_path - APK 文件路径
§返回值

返回一个 HashMap,键为设备 ID,值为安装结果

Source

pub fn parallel_uninstall_app( &self, device_ids: &[&str], package_name: &str, ) -> HashMap<String, ADBResult<()>>

在多个设备上并行卸载应用

§参数
  • device_ids - 设备 ID 列表
  • package_name - 包名
§返回值

返回一个 HashMap,键为设备 ID,值为卸载结果

Source

pub fn parallel_start_app( &self, device_ids: &[&str], package_name: &str, activity: Option<&str>, ) -> HashMap<String, ADBResult<bool>>

在多个设备上并行启动应用

§参数
  • device_ids - 设备 ID 列表
  • package_name - 包名
  • activity - 可选的 Activity 名称
§返回值

返回一个 HashMap,键为设备 ID,值为启动结果

Source

pub fn parallel_stop_app( &self, device_ids: &[&str], package_name: &str, ) -> HashMap<String, ADBResult<()>>

在多个设备上并行停止应用

§参数
  • device_ids - 设备 ID 列表
  • package_name - 包名
§返回值

返回一个 HashMap,键为设备 ID,值为停止结果

Source

pub fn parallel_get_package_info( &self, device_ids: &[&str], package_name: &str, ) -> HashMap<String, ADBResult<PackageInfo>>

在多个设备上并行获取包信息

§参数
  • device_ids - 设备 ID 列表
  • package_name - 包名
§返回值

返回一个 HashMap,键为设备 ID,值为包信息

Source

pub fn parallel_push( &self, device_ids: &[&str], local_path: &str, device_path: &str, ) -> HashMap<String, ADBResult<()>>

在多个设备上并行执行推送文件操作

§参数
  • device_ids - 设备 ID 列表
  • local_path - 本地文件路径
  • device_path - 设备上的目标路径
§返回值

返回一个 HashMap,键为设备 ID,值为推送结果

Source

pub fn parallel_pull( &self, operations: &[(String, String, String)], ) -> HashMap<String, ADBResult<()>>

在多个设备上并行执行拉取文件操作

§参数
  • operations - 设备 ID 和文件路径的组合列表,每项包含(设备 ID, 设备文件路径, 本地目标路径)
§返回值

返回一个 HashMap,键为设备 ID,值为拉取结果

Source

pub fn filter_online_devices( &self, device_ids: &[&str], ) -> ADBResult<Vec<String>>

检查多个设备是否在线

§参数
  • device_ids - 设备 ID 列表
§返回值

返回在线设备的列表

Source

pub fn on_all_online_devices<F, T>( &self, operation: F, ) -> ADBResult<HashMap<String, ADBResult<T>>>
where F: Fn(&str) -> ADBResult<T> + Send + Sync, T: Send,

在所有在线设备上执行操作

§参数
  • operation - 要执行的操作闭包
§返回值

返回在线设备的操作结果

Source

pub fn parallel_commands( &self, device_ids: &[&str], commands: &[&str], ) -> HashMap<String, Vec<ADBResult<String>>>

在所有指定设备上并行执行多个命令

Source

pub fn start_app_on_all_devices( &self, package_name: &str, activity: Option<&str>, ) -> ADBResult<HashMap<String, ADBResult<bool>>>

在所有在线设备上启动同一应用

Source

pub fn stop_app_on_all_devices( &self, package_name: &str, ) -> ADBResult<HashMap<String, ADBResult<()>>>

在所有在线设备上停止同一应用

Trait Implementations§

Source§

impl Clone for ADB

Source§

fn clone(&self) -> ADB

Returns a copy 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 ADB

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for ADB

§

impl RefUnwindSafe for ADB

§

impl Send for ADB

§

impl Sync for ADB

§

impl Unpin for ADB

§

impl UnwindSafe for ADB

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