IDevice

public interface IDevice
implements IShellEnabledDevice

com.android.ddmlib.IDevice


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

摘要

常量

int CHANGE_BUILD_INFO

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

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:。

abstract void executeShellCommand(String command, IShellOutputReceiver receiver)

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

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

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

此方法已废弃。 使用 executeShellCommand(String,IShellOutputReceiver,long,TimeUnit)。

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

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

default void forceStop(String applicationName)

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

abstract List<String> getAbis()

返回此设备支持的 ABI。

default ListenableFuture<AvdData> getAvdData()

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

abstract String getAvdName()

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

abstract String getAvdPath()

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

abstract Future<Integer> getBattery(long freshnessTime, TimeUnit timeUnit)

返回设备的电池电量(0% 到 100%)。

abstract Future<Integer> getBattery()

返回设备的电池电量(0% 到 100%)。

abstract Integer getBatteryLevel(long freshnessMs)

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

abstract Integer getBatteryLevel()

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

default Integer getBatteryTemperature()

返回设备的电池温度(以摄氏度为单位)。

abstract int getDensity()

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

abstract FileListingService getFileListingService()

返回此设备的 FileListingService。

default Set<String> getHardwareCharacteristics()

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

abstract String getLanguage()

返回用户的语言。

default InstallMetrics getLastInstallMetrics()

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

abstract String getMountPoint(String name)

返回装载点。

abstract Map<String, String> getProperties()

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

abstract String getProperty(String name)

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

abstract String getPropertyCacheOrSync(String name)

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

abstract int getPropertyCount()

此方法已废弃。 实现细节

abstract String getPropertySync(String name)

此方法已废弃。 使用 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 void installPackage(String packageFilePath, boolean reinstall, InstallReceiver receiver, String... extraArgs)

在设备上安装 Android 应用。

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, String... extraArgs)

在设备上安装 Android 应用。

abstract void installPackages(List<File> apks, boolean reinstall, List<String> installOptions, long timeout, TimeUnit timeoutUnit)

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

default void installPackages(List<File> apks, boolean reinstall, List<String> installOptions)

安装由多个 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(List<String> remoteApks, boolean reinstall, List<String> installOptions, long timeout, TimeUnit timeoutUnit)

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

default void installRemotePackages(List<String> remoteApks, boolean reinstall, List<String> installOptions)

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

abstract boolean isBootLoader()

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

abstract boolean isEmulator()

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

abstract boolean isOffline()

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

abstract boolean isOnline()

返回设备是否已准备就绪。

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)

如果设备支持 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_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 网域套接字的命名空间

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

createForward

public abstract void createForward (int localPort, 
                int remotePort)

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

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

remotePort int:远程端口。

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

createReverse

public void createReverse (int remotePort, 
                int localPort)

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

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

localPort int:本地端口

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

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 发送的可选输入流

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException 以防 binder 命令在给定时间内未发送输出。
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

executeShellCommand

public abstract void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

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

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

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

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

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException (如果 shell 命令在给定时间内未发送输出)。
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

executeShellCommand

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

此方法已废弃。
使用 executeShellCommand(String,IShellOutputReceiver,long,TimeUnit)。

参数
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse int

抛出
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

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
IOException
ShellCommandUnresponsiveException
TimeoutException

forceStop

public void forceStop (String applicationName)

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

参数
applicationName String:应用的名称

getAbis

public abstract List<String> getAbis ()

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

返回
List<String> ABI 列表。

getAvdData

public ListenableFuture<AvdData> getAvdData ()

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

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

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

返回
ListenableFuture<AvdData> 设备的 AvdData。

getAvdName

public abstract String getAvdName ()

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

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

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

注意:如果您想控制超时,最好使用 getAvdData()。

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

getAvdPath

public abstract String getAvdPath ()

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

注意:如果您想控制超时,最好使用 getAvdData()。

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

getBattery

public abstract Future<Integer> getBattery (long freshnessTime, 
                TimeUnit timeUnit)

返回设备的电池电量(0% 到 100%)。

电池电量可能会被缓存。仅在自上次成功查询后 freshnessTime 已过期的情况下,才查询设备的电池电量。

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

timeUnit TimeUnit:freshnessTime 的 TimeUnit

返回
Future<Integer> 一个 Future,可用于查询电池电量。如果无法检索电池电量,Future 将返回 ExecutionException。

getBattery

public abstract Future<Integer> getBattery ()

返回设备的电池电量(0% 到 100%)。

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

返回
Future<Integer> Future,可用于查询电池电量。如果无法检索电池电量,Future 将返回 ExecutionException。

getBatteryLevel

public abstract Integer getBatteryLevel (long freshnessMs)

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

返回设备的电池电量(0% 到 100%)。

电池电量可能会被缓存。仅在自上次成功查询后已过去 freshnessMs 毫秒的情况下,才查询设备的电池电量。

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

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

getBatteryLevel

public abstract Integer getBatteryLevel ()

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

返回设备的电池电量(0% 到 100%)。

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

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

抛出
AdbCommandRejectedException
IOException
ShellCommandUnresponsiveException
TimeoutException

getBatteryTemperature

public Integer getBatteryTemperature ()

返回设备的电池温度(以摄氏度为单位)。

返回
Integer 电池温度;如果无法检索,则为 0

getDensity

public abstract int getDensity ()

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

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

getFileListingService

public abstract FileListingService getFileListingService ()

返回此设备的 FileListingService。

返回
FileListingService

getHardwareCharacteristics

public Set<String> getHardwareCharacteristics ()

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

返回
Set<String>

抛出
Exception

getLanguage

public abstract String getLanguage ()

返回用户的语言。

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

getLastInstallMetrics

public InstallMetrics getLastInstallMetrics ()

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

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

getMountPoint

public abstract String getMountPoint (String name)

返回装载点。

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

返回
String

getProperties

public abstract Map<String, String> getProperties ()

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

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

返回
Map<String, String>

getProperty

public abstract String getProperty (String name)

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

注意:如果您想控制超时,最好使用 getSystemProperty(String)。

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

返回
String 该值;如果属性值无法立即获取,则为 null

getPropertyCacheOrSync

public abstract String getPropertyCacheOrSync (String name)

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

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

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

返回
String 该值;如果该属性不存在,则为 null

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException (如果 shell 命令在给定时间内未发送输出)。
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

getPropertyCount

public abstract int getPropertyCount ()

此方法已废弃。
实现细节

返回此设备的属性数量。

返回
int

getPropertySync

public abstract String getPropertySync (String name)

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

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

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

返回
String 该值;如果该属性不存在,则为 null

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
ShellCommandUnresponsiveException (如果 shell 命令在给定时间内未发送输出)。
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

getRegion

public abstract String getRegion ()

返回用户所在的地区。

返回
String 用户所在地区;如果未知,则为 null

getScreenshot

public abstract RawImage getScreenshot ()

截取设备的屏幕截图,并将其作为 RawImage 返回。

返回
RawImage 如果出现问题,则将屏幕截图作为 RawImage 或 null 返回。

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

getScreenshot

public abstract RawImage getScreenshot (long timeout, 
                TimeUnit unit)

参数
timeout long

unit TimeUnit

返回
RawImage

抛出
AdbCommandRejectedException
IOException
TimeoutException

getSerialNumber

public abstract String getSerialNumber ()

返回设备的序列号。

返回
String

getState

public abstract IDevice.DeviceState getState ()

返回设备的状态。

返回
IDevice.DeviceState

getSyncService

public abstract SyncService getSyncService ()

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

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

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果与 adb 的连接失败。

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, 
                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:非零 maxTimeout 和 maxTimeToOutputResponse 值的单位。

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 abstract void installPackages (List<File> apks, 
                boolean reinstall, 
                List<String> installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

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

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

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

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

timeout long:安装超时

timeoutUnit TimeUnit:与超时参数对应的 TimeUnit

抛出
InstallException 如果安装失败,

installPackages

public void installPackages (List<File> apks, 
                boolean reinstall, 
                List<String> installOptions)

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

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

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

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

抛出
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:非零 maxTimeout 和 maxTimeToOutputResponse 值的单位。

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

抛出
InstallException 如果安装失败,

installRemotePackages

public void installRemotePackages (List<String> remoteApks, 
                boolean reinstall, 
                List<String> installOptions, 
                long timeout, 
                TimeUnit timeoutUnit)

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

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

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

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

timeout long:安装超时

timeoutUnit TimeUnit:与超时参数对应的 TimeUnit

抛出
InstallException 如果安装失败,

installRemotePackages

public void installRemotePackages (List<String> remoteApks, 
                boolean reinstall, 
                List<String> installOptions)

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

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

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

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

抛出
InstallException 如果安装失败,

isBootLoader

public abstract boolean isBootLoader ()

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

返回
boolean true(如果 getState() 返回 DeviceState.BOOTLOADER)。

isEmulator

public abstract boolean isEmulator ()

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

返回
boolean

isOffline

public abstract boolean isOffline ()

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

返回
boolean true(如果 getState() 返回 DeviceState.OFFLINE)。

isOnline

public abstract boolean isOnline ()

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

返回
boolean true(如果 getState() 返回 DeviceState.ONLINE)。

isRoot

public abstract boolean isRoot ()

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

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

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令,则会返回此错误。
TimeoutException 以防连接超时。
IOException
ShellCommandUnresponsiveException

kill

public void kill (String applicationName)

按应用名称终止应用。这只会销毁 activity,而不会影响其在 Android 系统中的状态。

参数
applicationName String:应用的名称

pullFile

public abstract void pullFile (String remote, 
                String local)

拉取单个文件。

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

local String:本地目标位置。

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
SyncException 以防出现同步异常。
TimeoutException (如果从设备读取响应时超时)。
IOException 如果发生 IO 异常。

推送

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

推送多个文件或目录。

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

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

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

pushFile

public abstract void pushFile (String local, 
                String remote)

推送单个文件。

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

remote String:远程文件路径

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

rawBinder

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

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

SocketChannel 的所有权会转让给调用方,使用后必须明确关闭。

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

parameters String:binder 命令的参数

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

抛出
AdbCommandRejectedException
IOException
TimeoutException

rawExec

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

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

SocketChannel 的所有权会转让给调用方,使用后必须明确关闭。

参数
executable String

parameters String

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

抛出
AdbCommandRejectedException
IOException
TimeoutException

重新启动

public abstract void reboot (String into)

重新启动设备。

参数
into String:要重新启动到的引导加载程序名称,或 null(仅重新启动设备)。

抛出
TimeoutException 以防连接超时。
DeviceNotAvailableException 如果设备在重启后不可用,则会失败。
java.io.IOException
IOException

removeForward

public void removeForward (int localPort)

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

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

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

removeForward

public void removeForward (int localPort, 
                int remotePort)

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

参数
localPort int

remotePort int

抛出
AdbCommandRejectedException
IOException
TimeoutException

removeForward

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

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

参数
localPort int

remoteSocketName String

namespace IDevice.DeviceUnixSocketNamespace

抛出
AdbCommandRejectedException
IOException
TimeoutException

removeRemotePackage

public abstract void removeRemotePackage (String remoteFilePath)

从设备中移除文件。

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

抛出
InstallException 如果安装失败,

removeReverse

public void removeReverse (int remotePort)

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

参数
remotePort int:远程端口。

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

root

public abstract boolean root ()

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

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

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令,则会返回此错误。
ShellCommandUnresponsiveException 如果无法查询根状态。
TimeoutException 以防连接超时。
java.io.IOException
IOException

startScreenRecorder

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

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

参数
remoteFilePath String

options ScreenRecorderOptions

receiver IShellOutputReceiver

抛出
AdbCommandRejectedException
IOException
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 文件在设备上的目标路径

抛出
AdbCommandRejectedException 如果 adb 拒绝该命令
SyncException 如果将软件包推送到设备时出错。
TimeoutException 以防连接超时。
IOException 如果连接发生 I/O 错误。

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 如果卸载失败,则会显示此消息。