IDevice

public interface IDevice
implements IShellEnabledDevice

com.android.ddmlib.IDevice


设备。可以是实体设备,也可以是模拟器。

摘要

常量

int CHANGE_BUILD_INFO

设备更改位掩码:build 信息更改。

int CHANGE_CLIENT_LIST

设备更改位掩码:Client 列表更改。

int CHANGE_PROFILEABLE_CLIENT_LIST

设备更改位掩码:ProfileableClient 列表更改。

int CHANGE_STATE

设备更改位掩码:DeviceState 更改。

String FIRST_EMULATOR_SN

第一个已连接模拟器的序列号。

String MNT_DATA

String MNT_EXTERNAL_STORAGE

String MNT_ROOT

String PROP_BUILD_API_LEVEL

String PROP_BUILD_CHARACTERISTICS

String PROP_BUILD_CODENAME

String PROP_BUILD_TAGS

String PROP_BUILD_TYPE

String PROP_BUILD_VERSION

String PROP_BUILD_VERSION_NUMBER

此常量已弃用。 使用 PROP_BUILD_API_LEVEL

String PROP_DEBUGGABLE

String PROP_DEVICE_CPU_ABI

String PROP_DEVICE_CPU_ABI2

String PROP_DEVICE_CPU_ABI_LIST

String PROP_DEVICE_DENSITY

String PROP_DEVICE_EMULATOR_DENSITY

String PROP_DEVICE_LANGUAGE

String PROP_DEVICE_MANUFACTURER

String PROP_DEVICE_MODEL

String PROP_DEVICE_REGION

String RE_EMULATOR_SN

模拟器序列号正则表达式。

String UNKNOWN_PACKAGE

公共方法

abstract boolean arePropertiesSet()

如果已缓存属性,则返回 true

abstract void createForward(int localPort, String remoteSocketName, IDevice.DeviceUnixSocketNamespace namespace)

在本地 TCP 端口和远程 Unix 网域套接字之间创建端口转发。

abstract void createForward(int localPort, int remotePort)

在本地端口和远程端口之间创建端口转发。

default void createReverse(int remotePort, int localPort)

在远程端口和本地端口之间创建端口反向。

default void executeBinderCommand(String[] parameters, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, InputStream is)

在设备上执行 Binder 命令,并将结果发送到 receiver

如果设备操作系统和主机 ADB 服务器都支持 Android Binder Bridge 执行功能,则使用 exec:cmd 调用或更快的 abb_exec:

default void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, InputStream is)

一种 executeShell 命令版本,可接受输入流以通过 stdin 发送。

abstract void executeShellCommand(String command, IShellOutputReceiver receiver)

在设备上执行 shell 命令,并将结果发送到 receiver

这类似于调用 executeShellCommand(command, receiver, DdmPreferences.getTimeOut())

abstract void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)

此方法已弃用。 使用 IShellEnabledDevice.executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, long, TimeUnit)

default void forceStop(String applicationName)

按应用名称强行停止应用。

abstract getAbis()

返回此设备支持的 ABI。

default ListenableFuture<AvdData> getAvdData()

返回有关模拟器正在运行的 AVD 的信息。

abstract String getAvdName()

返回模拟器正在运行的 AVD 的名称。

abstract String getAvdPath()

返回文件系统中虚拟设备的绝对路径。

abstract getBattery(long freshnessTime, TimeUnit timeUnit)

返回设备的电池电量,范围为 0 到 100%。

abstract getBattery()

返回设备的电池电量,范围为 0 到 100%。

abstract Integer getBatteryLevel(long freshnessMs)

此方法已弃用。 使用 getBattery(long, TimeUnit)

abstract Integer getBatteryLevel()

此方法已弃用。 使用 getBattery()

abstract Client getClient(String applicationName)

按应用名称返回 Client

abstract String getClientName(int pid)

按 PID 返回客户端的名称,如果 PID 未知,则返回 null

abstract Client[] getClients()

返回客户端数组。

abstract int getDensity()

通过读取系统属性 PROP_DEVICE_DENSITY 的值,返回设备屏幕的密度桶。

abstract FileListingService getFileListingService()

返回相应设备的 FileListingService

default getHardwareCharacteristics()

返回通过读取 build 特征属性获得的特征。

abstract String getLanguage()

返回用户的语言。

default InstallMetrics getLastInstallMetrics()

获取有关此设备上最近一次安装的信息。

abstract String getMountPoint(String name)

返回装载点。

default ProfileableClient[] getProfileableClients()

返回可分析的客户端数组。

abstract getProperties()

此方法已弃用。 请改用 IShellEnabledDevice.getSystemProperty(String)

abstract String getProperty(String name)

一种便捷方法,尝试通过 IShellEnabledDevice.getSystemProperty(String) 以非常短的等待时间检索属性,并吞下异常。

abstract String getPropertyCacheOrSync(String name)

此方法已弃用。 请改用 IShellEnabledDevice.getSystemProperty(String)

abstract int getPropertyCount()

此方法已弃用。 实现细节

abstract String getPropertySync(String name)

此方法已弃用。 使用 IShellEnabledDevice.getSystemProperty(String)

abstract String getRegion()

返回用户的地区。

abstract RawImage getScreenshot()

拍摄设备屏幕截图,并以 RawImage 形式返回。

abstract RawImage getScreenshot(long timeout, TimeUnit unit)
abstract String getSerialNumber()

返回设备的序列号。

abstract IDevice.DeviceState getState()

返回设备的状态。

abstract SyncService getSyncService()

返回一个 SyncService 对象,用于将文件推送到设备或从设备拉取文件。

abstract boolean hasClients()

返回 IDevice 是否包含 Client

abstract void installPackage(String packageFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)

在设备上安装 Android 应用。

abstract void installPackage(String packageFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)

在设备上安装 Android 应用。

abstract void installPackage(String packageFilePath, boolean reinstall, String... extraArgs)

在设备上安装 Android 应用。

default void installPackages( apks, boolean reinstall, installOptions)

安装由多个 APK 文件(一个主软件包和 0 到 n 个拆分软件包)组成的 Android 应用,并使用默认超时时间

abstract void installPackages( apks, boolean reinstall, installOptions, long timeout, TimeUnit timeoutUnit)

安装由多个 APK 文件(一个主软件包和 0 到 n 个拆分软件包)组成的 Android 应用

abstract void installRemotePackage(String remoteFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

abstract void installRemotePackage(String remoteFilePath, boolean reinstall, String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

abstract void installRemotePackage(String remoteFilePath, boolean reinstall, InstallReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits, String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

default void installRemotePackages( remoteApks, boolean reinstall, installOptions)

在设备上安装由多个本地 APK 文件组成的 Android 应用,并使用默认超时时间

default void installRemotePackages( remoteApks, boolean reinstall, installOptions, long timeout, TimeUnit timeoutUnit)

安装由多个本地 APK 文件组成的 Android 应用

abstract boolean isBootLoader()

返回设备是否处于引导加载程序模式。

abstract boolean isEmulator()

如果设备是模拟器,则返回 true

abstract boolean isOffline()

如果设备处于离线状态,则返回此值。

abstract boolean isOnline()

如果设备已准备就绪,则返回 true。

abstract boolean isRoot()

查询设备的当前 root 状态。

default void kill(String applicationName)

按应用名称终止应用。

abstract void pullFile(String remote, String local)

提取单个文件。

default void push(String[] local, String remote)

推送多个文件或目录。

abstract void pushFile(String local, String remote)

推送单个文件。

default SocketChannel rawBinder(String service, String[] parameters)

在远程设备上调用 Android Binder Bridge 服务。

default SocketChannel rawExec(String executable, String[] parameters)

在远程设备上调用 host:exec 服务。

abstract void reboot(String into)

重新启动设备。

default void removeForward(int localPort)

移除本地端口与远程端口之间的端口转发。

default void removeForward(int localPort, int remotePort)

此方法已弃用。 使用 removeForward(int)

default void removeForward(int localPort, String remoteSocketName, IDevice.DeviceUnixSocketNamespace namespace)

此方法已弃用。 使用 removeForward(int)

abstract void removeRemotePackage(String remoteFilePath)

从设备中移除文件。

default void removeReverse(int remotePort)

移除远程端口与本地端口之间的端口反转。

abstract boolean root()

要求 adb 守护程序在设备上成为 root 用户。

abstract void startScreenRecorder(String remoteFilePath, ScreenRecorderOptions options, IShellOutputReceiver receiver)

如果设备支持 IDevice.Feature.SCREEN_RECORD,则在设备上启动屏幕录制。

abstract boolean supportsFeature(IDevice.HardwareFeature feature)

返回相应设备是否支持给定的硬件功能。

abstract boolean supportsFeature(IDevice.Feature feature)

返回相应设备是否支持给定的软件功能。

abstract String syncPackageToDevice(String localFilePath)

将文件推送到设备

abstract String uninstallApp(String applicationID, String... extraArgs)

从设备中卸载应用。

abstract String uninstallPackage(String packageName)

从设备中卸载软件包。

常量

CHANGE_BUILD_INFO

public static final int CHANGE_BUILD_INFO

设备更改位掩码:build 信息更改。

常量值: 4 (0x00000004)

CHANGE_CLIENT_LIST

public static final int CHANGE_CLIENT_LIST

设备更改位掩码:Client 列表更改。

常量值: 2 (0x00000002)

CHANGE_PROFILEABLE_CLIENT_LIST

public static final int CHANGE_PROFILEABLE_CLIENT_LIST

设备更改位掩码:ProfileableClient 列表更改。

常量值: 8 (0x00000008)

CHANGE_STATE

public static final int CHANGE_STATE

设备更改位掩码:DeviceState 更改。

常量值: 1 (0x00000001)

FIRST_EMULATOR_SN

public static final String FIRST_EMULATOR_SN

第一个已连接模拟器的序列号。

常量值: “emulator-5554”

MNT_DATA

public static final String MNT_DATA

常量值: "ANDROID_DATA"

MNT_EXTERNAL_STORAGE

public static final String MNT_EXTERNAL_STORAGE

常量值: "EXTERNAL_STORAGE"

MNT_ROOT

public static final String MNT_ROOT

常量值: "ANDROID_ROOT"

PROP_BUILD_API_LEVEL

public static final String PROP_BUILD_API_LEVEL

常量值: “ro.build.version.sdk”

PROP_BUILD_CHARACTERISTICS

public static final String PROP_BUILD_CHARACTERISTICS

常量值: "ro.build.characteristics"

PROP_BUILD_CODENAME

public static final String PROP_BUILD_CODENAME

常量值: “ro.build.version.codename”

PROP_BUILD_TAGS

public static final String PROP_BUILD_TAGS

常量值: “ro.build.tags”

PROP_BUILD_TYPE

public static final String PROP_BUILD_TYPE

常量值: “ro.build.type”

PROP_BUILD_VERSION

public static final String PROP_BUILD_VERSION

常量值: “ro.build.version.release”

PROP_BUILD_VERSION_NUMBER

public static final String PROP_BUILD_VERSION_NUMBER

此常量已弃用。
使用 PROP_BUILD_API_LEVEL

常量值: “ro.build.version.sdk”

PROP_DEBUGGABLE

public static final String PROP_DEBUGGABLE

常量值: “ro.debuggable”

PROP_DEVICE_CPU_ABI

public static final String PROP_DEVICE_CPU_ABI

常量值: “ro.product.cpu.abi”

PROP_DEVICE_CPU_ABI2

public static final String PROP_DEVICE_CPU_ABI2

常量值: “ro.product.cpu.abi2”

PROP_DEVICE_CPU_ABI_LIST

public static final String PROP_DEVICE_CPU_ABI_LIST

常量值: "ro.product.cpu.abilist"

PROP_DEVICE_DENSITY

public static final String PROP_DEVICE_DENSITY

常量值: "ro.sf.lcd_density"

PROP_DEVICE_EMULATOR_DENSITY

public static final String PROP_DEVICE_EMULATOR_DENSITY

常量值: "qemu.sf.lcd_density"

PROP_DEVICE_LANGUAGE

public static final String PROP_DEVICE_LANGUAGE

常量值: “persist.sys.language”

PROP_DEVICE_MANUFACTURER

public static final String PROP_DEVICE_MANUFACTURER

常量值: “ro.product.manufacturer”

PROP_DEVICE_MODEL

public static final String PROP_DEVICE_MODEL

常量值: “ro.product.model”

PROP_DEVICE_REGION

public static final String PROP_DEVICE_REGION

常量值: “persist.sys.country”

RE_EMULATOR_SN

public static final String RE_EMULATOR_SN

模拟器序列号正则表达式。

常量值: "emulator-(\d+)"

UNKNOWN_PACKAGE

public static final String UNKNOWN_PACKAGE

常量值: ""

公共方法

arePropertiesSet

public abstract boolean arePropertiesSet ()

如果已缓存属性,则返回 true

返回
boolean

createForward

public abstract void createForward (int localPort, 
                String remoteSocketName, 
                IDevice.DeviceUnixSocketNamespace namespace)

在本地 TCP 端口和远程 Unix 网域套接字之间创建端口转发。

参数
localPort int:要转发的本地端口

remoteSocketName String:设备上创建的 Unix 网域套接字的名称

namespace IDevice.DeviceUnixSocketNamespace:创建 Unix 网域套接字的命名空间

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

createForward

public abstract void createForward (int localPort, 
                int remotePort)

在本地端口和远程端口之间创建端口转发。

参数
localPort int:要转发的本地端口

remotePort int:远程端口。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

createReverse

public void createReverse (int remotePort, 
                int localPort)

在远程端口和本地端口之间创建端口反向。

参数
remotePort int:要反向的远程端口。

localPort int:本地端口

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

executeBinderCommand

public void executeBinderCommand (String[] parameters, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                InputStream is)

在设备上执行 Binder 命令,并将结果发送到 receiver

如果设备操作系统和主机 ADB 服务器都支持 Android Binder Bridge 执行功能,则使用 exec:cmd 调用或更快的 abb_exec:

参数
parameters String:要执行的 binder 命令

receiver IShellOutputReceiver:将接收 binder 命令输出的 IShellOutputReceiver

maxTimeToOutputResponse long

maxTimeUnits TimeUnit

is InputStream:通过 stdin 发送的可选输入流

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException 以防 binder 命令在给定时间内未发送输出。
如果连接出现 I/O 错误,则为 true。

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                InputStream is)

executeShell 命令的一个版本,可以接受输入流并通过 stdin 发送。

参数
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse long

maxTimeUnits TimeUnit

is InputStream

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

在设备上执行 shell 命令,并将结果发送到 receiver

这类似于调用 executeShellCommand(command, receiver, DdmPreferences.getTimeOut())

参数
command String:要执行的 shell 命令

receiver IShellOutputReceiver:将接收 shell 命令输出的 IShellOutputReceiver

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException 以防 shell 命令在给定时间内未发送输出。
如果连接出现 I/O 错误,则为 true。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver, 
                int maxTimeToOutputResponse)

此方法已弃用。
使用 IShellEnabledDevice.executeShellCommand(String, com.android.ddmlib.IShellOutputReceiver, long, TimeUnit)

参数
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse int

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

forceStop

public void forceStop (String applicationName)

按应用名称强行停止应用。这会移除所有待处理的闹钟和排队的计算。

参数
applicationName String:应用的名称

getAbis

public abstract  getAbis ()

返回相应设备支持的 ABI。ABI 按首选顺序排序,第一个 ABI 是最首选的。

返回
ABI 列表。

getAvdData

public ListenableFuture<AvdData> getAvdData ()

返回有关模拟器正在运行的 AVD 的信息。

AvdData.getName 是 AVD 的名称,如果没有,则为 null

如果这是实体设备、模拟器控制台子命令失败或模拟器的版本低于 30.0.18,则 AvdData.getPath 为 AVD 路径或 null

返回
ListenableFuture<AvdData> 设备的 AvdData

getAvdName

public abstract String getAvdName ()

返回模拟器正在运行的 AVD 的名称。

仅当 isEmulator() 返回 true 时,此值才有效。

如果模拟器未运行任何 AVD(例如,它正在从 Android 源代码树 build 运行),此方法将返回“<build>”。

注意:如果您想控制超时时间,建议使用 getAvdData()

返回
String AVD 的名称,如果没有,则为 null

getAvdPath

public abstract String getAvdPath ()

返回文件系统中虚拟设备的绝对路径。路径取决于操作系统;在 Linux 上,路径将使用 / 作为名称分隔符,而在 Windows 上,路径将使用 \ 作为分隔符。

注意:如果您想控制超时时间,建议使用 getAvdData()

返回
String AVD 路径;如果这是实体设备,则为 null;模拟器控制台子命令失败;或者模拟器的版本低于 30.0.18

getBattery

public abstract  getBattery (long freshnessTime, 
                TimeUnit timeUnit)

返回设备的电池电量,范围为 0 到 100%。

电池电量可能会被缓存。仅当自上次成功查询以来 freshnessTime 已过期时,才查询设备的电池电量。

参数
freshnessTime long:所需的电池电量新近度

timeUnit TimeUnit:freshnessTime 的 ERROR(/TimeUnit)

返回
可用于查询电池电量的 ERROR(/Future)。如果无法检索电池电量,则相应 Future 将返回 ERROR(/ExecutionException)

getBattery

public abstract  getBattery ()

返回设备的电池电量,范围为 0 到 100%。

电池电量可能会被缓存。仅当自上次成功查询以来已过去 5 分钟时,才查询设备的电池电量。

返回
可用于查询电池电量的 ERROR(/Future)。如果无法检索电池电量,则相应 Future 将返回 ERROR(/ExecutionException)

getBatteryLevel

public abstract Integer getBatteryLevel (long freshnessMs)

此方法已弃用。
使用 getBattery(long, TimeUnit)

返回设备的电池电量,范围为 0 到 100%。

电池电量可能会被缓存。仅当自上次成功查询以来已过去 freshnessMs 毫秒时,才查询设备的电池电量。

返回
Integer 电池电量,如果无法检索到电池电量,则为 null

抛出
com.android.ddmlib.ShellCommandUnresponsiveException
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

getBatteryLevel

public abstract Integer getBatteryLevel ()

此方法已弃用。
使用 getBattery()

返回设备的电池电量,范围为 0 到 100%。

电池电量可能会被缓存。仅当自上次成功查询以来已过去 5 分钟时,才查询设备的电池电量。

返回
Integer 电池电量,如果无法检索到电池电量,则为 null

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

getClient

public abstract Client getClient (String applicationName)

按应用名称返回 Client

参数
applicationName String:应用的名称

返回
Client Client 对象;如果未找到匹配项,则返回 null

getClientName

public abstract String getClientName (int pid)

按 PID 返回客户端的名称,如果 PID 未知,则返回 null

参数
pid int:客户端的 PID。

返回
String

getClients

public abstract Client[] getClients ()

返回客户端数组。

返回
Client[]

getDensity

public abstract int getDensity ()

通过读取系统属性 PROP_DEVICE_DENSITY 的值,返回设备屏幕的密度桶。

返回
int 密度,如果无法确定,则为 -1。

getFileListingService

public abstract FileListingService getFileListingService ()

返回相应设备的 FileListingService

返回
FileListingService

getHardwareCharacteristics

public  getHardwareCharacteristics ()

返回通过读取 build 特征属性获得的特征。

返回

getLanguage

public abstract String getLanguage ()

返回用户的语言。

返回
String 用户的语言,如果未知,则为 null

getLastInstallMetrics

public InstallMetrics getLastInstallMetrics ()

获取有关相应设备上最近一次安装的信息。

返回
InstallMetrics 描述安装的 InstallMetrics 指标。

getMountPoint

public abstract String getMountPoint (String name)

返回装载点。

参数
name String:要返回的挂载点的名称

返回
String

getProfileableClients

public ProfileableClient[] getProfileableClients ()

返回可分析的客户端数组。

返回
ProfileableClient[]

getProperties

public abstract  getProperties ()

此方法已弃用。
请改用 IShellEnabledDevice.getSystemProperty(String)

返回缓存的设备属性。它包含“getprop”的整个输出

返回

getProperty

public abstract String getProperty (String name)

一种便捷方法,尝试通过 IShellEnabledDevice.getSystemProperty(String) 检索属性,等待时间非常短,并会捕获异常。

注意:如果您想控制超时时间,建议使用 IShellEnabledDevice.getSystemProperty(String)

参数
name String:要返回的值的名称。

返回
String 该值或 null(如果属性值无法立即获取)

getPropertyCacheOrSync

public abstract String getPropertyCacheOrSync (String name)

此方法已弃用。
请改用 IShellEnabledDevice.getSystemProperty(String)

getProperty(String)getPropertySync(String) 的组合,用于尝试从缓存中检索属性。如果未找到,将同步尝试直接查询设备,并在成功时重新填充缓存。

参数
name String:要返回的值的名称。

返回
String 值或 null(如果属性不存在)

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException 以防 shell 命令在给定时间内未发送输出。
如果连接出现 I/O 错误,则为 true。

getPropertyCount

public abstract int getPropertyCount ()

此方法已弃用。
实现细节

返回相应设备的属性数量。

返回
int

getPropertySync

public abstract String getPropertySync (String name)

此方法已弃用。
使用 IShellEnabledDevice.getSystemProperty(String)

getProperty(String) 的一种变体,它会尝试直接从设备检索给定的属性,而不使用缓存。此方法应(仅)用于任何易失性属性。

参数
name String:要返回的值的名称。

返回
String 值或 null(如果属性不存在)

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException 以防 shell 命令在给定时间内未发送输出。
如果连接出现 I/O 错误,则为 true。

getRegion

public abstract String getRegion ()

返回用户的地区。

返回
String 用户的地区,如果未知,则为 null

getScreenshot

public abstract RawImage getScreenshot ()

拍摄设备屏幕截图,并以 RawImage 形式返回。

返回
RawImage 如果出现问题,则将屏幕截图标记为 RawImagenull

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

getScreenshot

public abstract RawImage getScreenshot (long timeout, 
                TimeUnit unit)

参数
timeout long

unit TimeUnit

返回
RawImage

抛出
AdbCommandRejectedException
TimeoutException

getSerialNumber

public abstract String getSerialNumber ()

返回设备的序列号。

返回
String

getState

public abstract IDevice.DeviceState getState ()

返回设备的状态。

返回
IDevice.DeviceState

getSyncService

public abstract SyncService getSyncService ()

返回一个 SyncService 对象,用于将文件推送到设备或从设备拉取文件。

返回
SyncService null 如果无法创建 SyncService。如果 adb 因 IDevice 无效(或已断开连接)而拒绝打开连接,就会发生这种情况。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
与 adb 的连接失败。

hasClients

public abstract boolean hasClients ()

返回 IDevice 是否包含 Client

返回
boolean

installPackage

public abstract void installPackage (String packageFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                String... extraArgs)

在设备上安装 Android 应用。这是一个辅助方法,它将 syncPackageToDevice、installRemotePackage 和 removePackage 步骤结合在一起

参数
packageFilePath String:要安装的本地主机上文件的绝对文件系统路径

reinstall boolean:如果应重新安装应用,则设置为 true

receiver InstallReceiver:用于监控安装并获取最终状态的 InstallReceiver

maxTimeout long:命令返回的最长超时时间。值为 0 表示不会应用最大超时时间。

maxTimeToOutputResponse long:允许命令在最长多长时间内不输出任何响应。值为 0 表示该方法将无限期等待(直到 receiver 取消执行)命令输出,并且永远不会抛出异常。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的单位。

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installPackage

public abstract void installPackage (String packageFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                String... extraArgs)

在设备上安装 Android 应用。这是一个辅助方法,它将 syncPackageToDevice、installRemotePackage 和 removePackage 步骤结合在一起

参数
packageFilePath String:要安装的本地主机上文件的绝对文件系统路径

reinstall boolean:如果应重新安装应用,则设置为 true

receiver InstallReceiver:用于监控安装并获取最终状态的 InstallReceiver

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installPackage

public abstract void installPackage (String packageFilePath, 
                boolean reinstall, 
                String... extraArgs)

在设备上安装 Android 应用。这是一个辅助方法,它将 syncPackageToDevice、installRemotePackage 和 removePackage 步骤结合在一起

参数
packageFilePath String:要安装的本地主机上文件的绝对文件系统路径

reinstall boolean:如果应重新安装应用,则设置为 true

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installPackages

public void installPackages ( apks, 
                boolean reinstall, 
                 installOptions)

安装由多个 APK 文件(一个主软件包和 0 到 n 个拆分软件包)组成的 Android 应用,并使用默认超时时间

参数
apks :要安装的 APK 列表(1 个主 APK + 0 到 n 个拆分 APK)

reinstall boolean:如果应重新安装应用,则设置为 true

installOptions :要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installPackages

public abstract void installPackages ( apks, 
                boolean reinstall, 
                 installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

安装由多个 APK 文件(一个主软件包和 0 到 n 个拆分软件包)组成的 Android 应用

参数
apks :要安装的 APK 列表(1 个主 APK + 0 到 n 个拆分 APK)

reinstall boolean:如果应重新安装应用,则设置为 true

installOptions :要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

timeout long:安装超时

timeoutUnit TimeUnit:与超时参数对应的 ERROR(/TimeUnit)

抛出
InstallException 如果安装失败。

installRemotePackage

public abstract void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

参数
remoteFilePath String:设备上软件包文件的绝对文件路径

reinstall boolean:如果应重新安装应用,则设置为 true

receiver InstallReceiver:用于监控安装并获取最终状态的 InstallReceiver

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installRemotePackage

public abstract void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

参数
remoteFilePath String:设备上软件包文件的绝对文件路径

reinstall boolean:如果应重新安装应用,则设置为 true

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installRemotePackage

public abstract void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                InstallReceiver receiver, 
                long maxTimeout, 
                long maxTimeToOutputResponse, 
                TimeUnit maxTimeUnits, 
                String... extraArgs)

安装已推送到设备上临时位置的应用软件包。

参数
remoteFilePath String:设备上软件包文件的绝对文件路径

reinstall boolean:如果应重新安装应用,则设置为 true

receiver InstallReceiver:用于监控安装并获取最终状态的 InstallReceiver

maxTimeout long:命令返回的最长超时时间。值为 0 表示不会应用最大超时时间。

maxTimeToOutputResponse long:允许命令在最长多长时间内不输出任何响应。值为 0 表示该方法将无限期等待(直到 receiver 取消执行)命令输出,并且永远不会抛出异常。

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的单位。

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installRemotePackages

public void installRemotePackages ( remoteApks, 
                boolean reinstall, 
                 installOptions)

在设备上安装由多个本地 APK 文件组成的 Android 应用,并使用默认超时时间

参数
remoteApks :设备上要安装的 APK 文件路径列表

reinstall boolean:如果应重新安装应用,则设置为 true

installOptions :要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

抛出
InstallException 如果安装失败。

installRemotePackages

public void installRemotePackages ( remoteApks, 
                boolean reinstall, 
                 installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

安装由多个本地 APK 文件组成的 Android 应用

参数
remoteApks :要安装的设备上的 APK 文件路径列表

reinstall boolean:如果应重新安装应用,则设置为 true

installOptions :要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

timeout long:安装超时

timeoutUnit TimeUnit:与超时参数对应的 ERROR(/TimeUnit)

抛出
InstallException 如果安装失败。

isBootLoader

public abstract boolean isBootLoader ()

返回设备是否处于引导加载程序模式。

返回
boolean 如果 getState() 返回 DeviceState.BOOTLOADER,则为 true

isEmulator

public abstract boolean isEmulator ()

如果设备是模拟器,则返回 true

返回
boolean

isOffline

public abstract boolean isOffline ()

如果设备处于离线状态,则返回。

返回
boolean 如果 getState() 返回 DeviceState.OFFLINE,则为 true

isOnline

public abstract boolean isOnline ()

如果设备已准备就绪,则返回。

返回
boolean 如果 getState() 返回 DeviceState.ONLINE,则为 true

isRoot

public abstract boolean isRoot ()

查询设备的当前 root 状态。如需了解详情,请参阅“adb root”。

返回
boolean 如果 adb 守护程序以 root 身份运行,则为 true,否则为 false。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令。
ShellCommandUnresponsiveException

终止

public void kill (String applicationName)

按应用名称终止应用。这只会销毁 activity,而将其状态单独留在 Android 系统中。

参数
applicationName String:应用的名称

pullFile

public abstract void pullFile (String remote, 
                String local)

提取单个文件。

参数
remote String:远程文件的完整路径

local String:本地目的地。

抛出
以防出现 IO 异常。
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 如果从设备读取响应时发生超时,则返回此值。
SyncException 在出现同步异常时。

推送

public void push (String[] local, 
                String remote)

推送多个文件或目录。

参数
local String:要推送的本地文件

remote String:表示目录的远程路径

抛出
如果连接出现 I/O 错误
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 如果从设备读取响应时发生超时
SyncException 如果某些文件无法推送

pushFile

public abstract void pushFile (String local, 
                String remote)

推送单个文件。

参数
local String:本地文件路径。

remote String:远程文件路径

抛出
如果连接出现 I/O 错误
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 如果从设备读取响应时发生超时
SyncException 如果无法推送文件

rawBinder

public SocketChannel rawBinder (String service, 
                String[] parameters)

在远程设备上调用 Android Binder Bridge 服务。返回一个已连接到设备 binder 命令的套接字通道。

SocketChannel 的所有权已放弃给调用方,必须在使用后显式关闭。

参数
service String:要连接的 Android 服务的名称

parameters String:绑定器命令的参数

返回
SocketChannel 连接到设备上正在执行的进程的 SocketChannel。使用后。

抛出
AdbCommandRejectedException
TimeoutException

rawExec

public SocketChannel rawExec (String executable, 
                String[] parameters)

在远程设备上调用 host:exec 服务。返回已连接到执行进程的套接字渠道。请注意,exec 服务不会区分 stdout 和 stderr,因此从套接字读取的任何内容都可能来自任一输出,并且可能会交错显示。

SocketChannel 的所有权已放弃给调用方,必须在使用后显式关闭。

参数
executable String

parameters String

返回
SocketChannel 连接到设备上正在执行的进程的 SocketChannel。使用后。

抛出
AdbCommandRejectedException
TimeoutException

重新启动

public abstract void reboot (String into)

重新启动设备。

参数
into String:要重启进入的引导加载程序名称,或 null 以仅重启设备。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
IOException

removeForward

public void removeForward (int localPort)

移除本地端口与远程端口之间的端口转发。

参数
localPort int:要转发的本地端口

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

removeForward

public void removeForward (int localPort, 
                int remotePort)

此方法已弃用。
使用 removeForward(int)

参数
localPort int

remotePort int

抛出
AdbCommandRejectedException
TimeoutException

removeForward

public void removeForward (int localPort, 
                String remoteSocketName, 
                IDevice.DeviceUnixSocketNamespace namespace)

此方法已弃用。
使用 removeForward(int)

参数
localPort int

remoteSocketName String

namespace IDevice.DeviceUnixSocketNamespace

抛出
AdbCommandRejectedException
TimeoutException

removeRemotePackage

public abstract void removeRemotePackage (String remoteFilePath)

从设备中移除文件。

参数
remoteFilePath String:要移除的文件的设备路径

抛出
InstallException 如果安装失败。

removeReverse

public void removeReverse (int remotePort)

移除远程端口与本地端口之间的端口反转。

参数
remotePort int:远程端口。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。

root

public abstract boolean root ()

请求 adb 守护程序在设备上成为 root 用户。此操作可能会静默失败,并且只能在开发者 build 上成功。如需了解详情,请参阅“adb root”。

返回
boolean 如果 adb 守护程序以 root 身份运行,则为 true,否则为 false。

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令。
ShellCommandUnresponsiveException 如果无法查询根状态。
IOException

startScreenRecorder

public abstract void startScreenRecorder (String remoteFilePath, 
                ScreenRecorderOptions options, 
                IShellOutputReceiver receiver)

如果设备支持 IDevice.Feature.SCREEN_RECORD,则在设备上启动屏幕录制。

参数
remoteFilePath String

options ScreenRecorderOptions

receiver IShellOutputReceiver

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

supportsFeature

public abstract boolean supportsFeature (IDevice.HardwareFeature feature)

返回相应设备是否支持给定的硬件功能。

参数
feature IDevice.HardwareFeature

返回
boolean

supportsFeature

public abstract boolean supportsFeature (IDevice.Feature feature)

返回相应设备是否支持给定的软件功能。

参数
feature IDevice.Feature

返回
boolean

syncPackageToDevice

public abstract String syncPackageToDevice (String localFilePath)

将文件推送到设备

参数
localFilePath String:本地主机上文件的绝对路径

返回
String String 设备上文件的目标路径

抛出
TimeoutException 在连接超时的情况下。
AdbCommandRejectedException 如果 adb 拒绝该命令
如果连接出现 I/O 错误,则为 true。
SyncException 如果在将软件包推送到设备期间发生错误,则会返回此值。

uninstallApp

public abstract String uninstallApp (String applicationID, 
                String... extraArgs)

从设备中卸载应用。

参数
applicationID String:要卸载的 Android 应用 ID

extraArgs String:要传递的可选额外实参。如需了解可用选项,请参阅“adb shell pm install --help”。

返回
String 一个包含错误代码的 String,如果成功,则为 null

抛出
InstallException 如果卸载失败。

uninstallPackage

public abstract String uninstallPackage (String packageName)

从设备中卸载软件包。

参数
packageName String:要卸载的 Android 应用 ID

返回
String 一个包含错误代码的 String,如果成功,则为 null

抛出
InstallException 如果卸载失败。