DeviceImpl

public final class DeviceImpl
extends Object implements IDevice

java.lang.Object
   ↳ com.android.tradefed.device.server.DeviceImpl


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

摘要

公共构造函数

DeviceImpl(ClientTracker clientTracer, String serialNumber, IDevice.DeviceState deviceState)

公共方法

boolean arePropertiesSet()

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

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

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

void createForward(int localPort, int remotePort)

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

void createReverse(int remotePort, int localPort)

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

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

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

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

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

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

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

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

void executeShellCommand(String command, IShellOutputReceiver receiver)

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

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

void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse)
void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeout, long maxTimeToOutputResponse, TimeUnit maxTimeUnits)

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

void forceStop(String applicationName)

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

getAbis()

返回此设备支持的 ABI。

ListenableFuture<AvdData> getAvdData()

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

String getAvdName()

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

String getAvdPath()

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

getBattery(long freshnessTime, TimeUnit timeUnit)

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

getBattery()

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

Integer getBatteryLevel(long freshnessMs)

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

Integer getBatteryLevel()

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

ClientImpl getClient(String applicationName)

按应用名称返回 Client

String getClientName(int pid)

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

ClientTracker getClientTracker()
ClientImpl[] getClients()

返回客户端数组。

int getDensity()

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

FileListingService getFileListingService()

返回相应设备的 FileListingService

String getLanguage()

返回用户的语言。

InstallMetrics getLastInstallMetrics()

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

String getMountPoint(String name)

返回装载点。

String getName()

返回此设备的(人性化)名称。

ClientImpl[] getNativeClients()
ClientImpl getNativeClients(String applicationName)
ProfileableClientImpl[] getProfileableClients()

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

getProperties()

返回缓存的设备属性。

String getProperty(String name)

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

String getPropertyCacheOrSync(String name)

getProperty(String)getPropertySync(String) 的组合,用于尝试从缓存中检索属性。

int getPropertyCount()

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

String getPropertySync(String name)

getProperty(String) 的一种变体,它会尝试直接从设备检索给定的属性,而不使用缓存。

String getRegion()

返回用户的地区。

static String getScreenRecorderCommand(String remoteFilePath, ScreenRecorderOptions options)
RawImage getScreenshot()

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

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

返回设备的序列号。

IDevice.DeviceState getState()

返回设备的状态。

SyncService getSyncService()

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

ListenableFuture<String> getSystemProperty(String name)

针对系统属性执行潜在的异步查询。

boolean hasClients()

返回 IDevice 是否包含 Client

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

在设备上安装 Android 应用。

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

在设备上安装 Android 应用。

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

在设备上安装 Android 应用。

void installPackages( apks, boolean reinstall, installOptions)

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

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

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

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

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

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

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

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

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

void installRemotePackages( remoteApks, boolean reinstall, installOptions)

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

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

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

boolean isBootLoader()

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

boolean isEmulator()

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

boolean isOffline()

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

boolean isOnline()

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

boolean isRoot()

查询设备的当前 root 状态。

void kill(String applicationName)

按应用名称终止应用。

void pullFile(String remote, String local)

提取单个文件。

void push(String[] local, String remote)

推送多个文件或目录。

void pushFile(String local, String remote)

推送单个文件。

SocketChannel rawBinder(String service, String[] parameters)

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

SocketChannel rawExec(String executable, String[] parameters)

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

void reboot(String into)

重新启动设备。

void removeForward(int localPort)

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

void removeRemotePackage(String remoteFilePath)

从设备中移除文件。

void removeReverse(int remotePort)

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

boolean root()

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

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

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

boolean supportsFeature(IDevice.HardwareFeature feature)

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

boolean supportsFeature(IDevice.Feature feature)

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

String syncPackageToDevice(String localFilePath)

将文件推送到设备

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

从设备中卸载应用。

String uninstallPackage(String packageName)

从设备中卸载软件包。

公共构造函数

DeviceImpl

public DeviceImpl (ClientTracker clientTracer, 
                String serialNumber, 
                IDevice.DeviceState deviceState)

参数
clientTracer ClientTracker

serialNumber String

deviceState IDevice.DeviceState

公共方法

arePropertiesSet

public boolean arePropertiesSet ()

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

返回
boolean

createForward

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

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

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

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

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

抛出
AdbCommandRejectedException
TimeoutException

createForward

public void createForward (int localPort, 
                int remotePort)

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

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

remotePort int:远程端口。

抛出
AdbCommandRejectedException
TimeoutException

createReverse

public void createReverse (int remotePort, 
                int localPort)

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

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

localPort int:本地端口

抛出
AdbCommandRejectedException
TimeoutException

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

executeShellCommand

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

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

maxTimeToOutputResponse 用作预期设备命令输出的最长等待时间。
在任何时候,如果 shell 命令在超过 maxTimeToOutputResponse 的时间内未输出任何内容,该方法将抛出 ShellCommandUnresponsiveException

对于日志输出等命令,应使用 maxTimeToOutputResponse 值为 0,这意味着该方法永远不会抛出异常,并且会阻塞,直到接收方的 IShellOutputReceiver.isCancelled() 返回 true

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

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

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

maxTimeUnits TimeUnit:非零 maxTimeToOutputResponse 值的单位。

抛出
AdbCommandRejectedException
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
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

public void executeShellCommand (String command, 
                IShellOutputReceiver receiver)

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

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

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

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

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

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

参数
command String

receiver IShellOutputReceiver

maxTimeToOutputResponse int

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

executeShellCommand

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

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

maxTimeToOutputResponse 用作预期设备输出命令时的最长等待时间。
在任何时候,如果 shell 命令在超过 maxTimeToOutputResponse 的时间内未输出任何内容,该方法将抛出 ShellCommandUnresponsiveException

对于日志输出等命令,应使用 maxTimeToOutputResponse 值为 0,这意味着该方法永远不会抛出异常,并且会阻塞,直到接收方的 IShellOutputReceiver.isCancelled() 返回 true

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

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

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

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

maxTimeUnits TimeUnit:非零 maxTimeoutmaxTimeToOutputResponse 值的单位。

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

forceStop

public void forceStop (String applicationName)

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

参数
applicationName String:应用的名称

getAbis

public  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 String getAvdName ()

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

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

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

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

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

getAvdPath

public String getAvdPath ()

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

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

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

getBattery

public  getBattery (long freshnessTime, 
                TimeUnit timeUnit)

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

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

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

timeUnit TimeUnit:freshnessTime 的 ERROR(/TimeUnit)

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

getBattery

public  getBattery ()

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

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

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

getBatteryLevel

public Integer getBatteryLevel (long freshnessMs)

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

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

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

getBatteryLevel

public Integer getBatteryLevel ()

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

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

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

getClient

public ClientImpl getClient (String applicationName)

按应用名称返回 Client

参数
applicationName String:应用的名称

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

getClientName

public String getClientName (int pid)

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

参数
pid int:客户端的 PID。

返回
String

getClientTracker

public ClientTracker getClientTracker ()

返回
ClientTracker

getClients

public ClientImpl[] getClients ()

返回客户端数组。

返回
ClientImpl[]

getDensity

public int getDensity ()

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

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

getFileListingService

public FileListingService getFileListingService ()

返回相应设备的 FileListingService

返回
FileListingService

getLanguage

public String getLanguage ()

返回用户的语言。

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

getLastInstallMetrics

public InstallMetrics getLastInstallMetrics ()

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

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

getMountPoint

public String getMountPoint (String name)

返回装载点。

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

返回
String

getName

public String getName ()

返回相应设备的(人性化)名称。对于 AVD,通常是 AVD 名称;对于设备,则是制造商名称、型号名称和序列号的组合。

返回
String

getNativeClients

public ClientImpl[] getNativeClients ()

返回
ClientImpl[]

getNativeClients

public ClientImpl getNativeClients (String applicationName)

参数
applicationName String

返回
ClientImpl

getProfileableClients

public ProfileableClientImpl[] getProfileableClients ()

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

返回
ProfileableClientImpl[]

getProperties

public  getProperties ()

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

返回

getProperty

public String getProperty (String name)

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

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

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

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

getPropertyCacheOrSync

public String getPropertyCacheOrSync (String name)

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

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

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

getPropertyCount

public int getPropertyCount ()

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

返回
int

getPropertySync

public String getPropertySync (String name)

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

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

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

getRegion

public String getRegion ()

返回用户的地区。

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

getScreenRecorderCommand

public static String getScreenRecorderCommand (String remoteFilePath, 
                ScreenRecorderOptions options)

参数
remoteFilePath String

options ScreenRecorderOptions

返回
String

getScreenshot

public RawImage getScreenshot ()

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

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

抛出
AdbCommandRejectedException
TimeoutException

getScreenshot

public RawImage getScreenshot (long timeout, 
                TimeUnit unit)

参数
timeout long

unit TimeUnit

返回
RawImage

抛出
AdbCommandRejectedException
TimeoutException

getSerialNumber

public String getSerialNumber ()

返回设备的序列号。

返回
String

getState

public IDevice.DeviceState getState ()

返回设备的状态。

返回
IDevice.DeviceState

getSyncService

public SyncService getSyncService ()

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

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

抛出
AdbCommandRejectedException
TimeoutException

getSystemProperty

public ListenableFuture<String> getSystemProperty (String name)

针对系统属性执行潜在的异步查询。

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

返回
ListenableFuture<String> ListenableFuture. ERROR(get/Future#get() get) 可能会返回 null。

hasClients

public boolean hasClients ()

返回 IDevice 是否包含 Client

返回
boolean

installPackage

public 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 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 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 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 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 void installRemotePackage (String remoteFilePath, 
                boolean reinstall, 
                String... extraArgs)

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

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

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

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

抛出
InstallException

installRemotePackage

public 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 boolean isBootLoader ()

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

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

isEmulator

public boolean isEmulator ()

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

返回
boolean

isOffline

public boolean isOffline ()

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

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

isOnline

public boolean isOnline ()

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

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

isRoot

public boolean isRoot ()

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

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

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

终止

public void kill (String applicationName)

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

参数
applicationName String:应用的名称

pullFile

public void pullFile (String remote, 
                String local)

提取单个文件。

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

local String:本地目的地。

抛出
AdbCommandRejectedException
SyncException
TimeoutException

推送

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

推送多个文件或目录。

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

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

抛出
AdbCommandRejectedException
SyncException
TimeoutException

pushFile

public void pushFile (String local, 
                String remote)

推送单个文件。

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

remote String:远程文件路径

抛出
AdbCommandRejectedException
SyncException
TimeoutException

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 void reboot (String into)

重新启动设备。

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

抛出
AdbCommandRejectedException
TimeoutException

removeForward

public void removeForward (int localPort)

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

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

抛出
AdbCommandRejectedException
TimeoutException

removeRemotePackage

public void removeRemotePackage (String remoteFilePath)

从设备中移除文件。

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

抛出
InstallException

removeReverse

public void removeReverse (int remotePort)

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

参数
remotePort int:远程端口。

抛出
AdbCommandRejectedException
TimeoutException

root

public boolean root ()

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

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

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

startScreenRecorder

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

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

参数
remoteFilePath String

options ScreenRecorderOptions

receiver IShellOutputReceiver

抛出
AdbCommandRejectedException
ShellCommandUnresponsiveException
TimeoutException

supportsFeature

public boolean supportsFeature (IDevice.HardwareFeature feature)

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

参数
feature IDevice.HardwareFeature

返回
boolean

supportsFeature

public boolean supportsFeature (IDevice.Feature feature)

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

参数
feature IDevice.Feature

返回
boolean

syncPackageToDevice

public String syncPackageToDevice (String localFilePath)

将文件推送到设备

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

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

抛出
AdbCommandRejectedException
SyncException
TimeoutException

toString

public String toString ()

返回
String

uninstallApp

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

从设备中卸载应用。

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

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

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

抛出
InstallException

uninstallPackage

public String uninstallPackage (String packageName)

从设备中卸载软件包。

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

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

抛出
InstallException