DeviceManager
public
class
DeviceManager
extends Object
implements
IDeviceManager
| java.lang.Object | |
| ↳ | com.android.tradefed.device.DeviceManager |
摘要
嵌套类 | |
|---|---|
class |
DeviceManager.FastbootDevice
处于 Fastboot 模式的设备的表示形式。 |
常量 | |
|---|---|
String |
UNKNOWN_DISPLAY_STRING
未知属性的显示字符串 |
字段 | |
|---|---|
protected
DeviceMonitorMultiplexer |
mDvcMon
|
protected
boolean |
mFastbootEnabled
|
公共构造函数 | |
|---|---|
DeviceManager()
应从 |
|
公共方法 | |
|---|---|
void
|
addAvailableDevice(IDevice stubDevice)
|
void
|
addAvailableNativeDevice(IDevice stubDevice)
|
void
|
addDeviceMonitor(IDeviceMonitor mon)
添加了 |
void
|
addFastbootDevice(DeviceManager.FastbootDevice fastbootDevice)
|
void
|
addFastbootListener(IDeviceManager.IFastbootListener listener)
通知管理器,监听器对快速启动状态变化感兴趣。 |
void
|
addMonitoringTcpFastbootDevice(String serial, String fastbootSerial)
向 fastboot 监控器添加设备。 |
ITestDevice
|
allocateDevice(IDeviceSelection options, boolean isTemporary)
请求满足特定条件的设备以进行测试。 |
ITestDevice
|
allocateDevice(IDeviceSelection options)
请求满足特定条件的设备以进行测试。 |
ITestDevice
|
allocateDevice()
申请实体设备以进行测试 |
ITestDevice
|
connectToTcpDevice(String ipAndPort)
通过 adb-over-tcp 连接到设备
此方法会分配一个新设备,该设备最终应通过
返回的 |
boolean
|
disconnectFromTcpDevice(ITestDevice tcpDevice)
断开与通过 adb-over-tcp 连接的设备的连接。 |
void
|
displayDevicesInfo(PrintWriter stream, boolean includeStub)
输出包含已知设备列表、设备状态和常用 |
CommandResult
|
executeCmdOnAvailableDevice(String serial, String command, long timeout, TimeUnit timeUnit)
一种在可用设备上执行 shell 命令的辅助方法。 |
String
|
executeGlobalAdbCommand(String... cmdArgs)
执行未定位到特定设备的 adb 命令,例如 |
ITestDevice
|
forceAllocateDevice(String serial)
粗略地分配设备,即使该设备目前不可用。 |
void
|
freeDevice(ITestDevice device, FreeDeviceState deviceState)
将设备返回到池中 尝试返回之前未分配的设备将被忽略。 |
String
|
getAdbPath()
返回要使用的 adb 二进制文件的路径。 |
String
|
getAdbVersion()
获取设备管理器当前使用的 adb 版本。 |
DeviceDescriptor
|
getDeviceDescriptor(String serial)
返回具有指定序列号的 DeviceDescriptor。 |
String
|
getFastbootPath()
返回要使用的 fastboot 二进制文件的路径。 |
void
|
init(IDeviceSelection globalDeviceFilter,
初始化设备管理器。 |
void
|
init(IDeviceSelection globalDeviceFilter,
初始化设备管理器。 |
void
|
init()
初始化设备管理器。 |
boolean
|
isEmulator(String serial)
确定给定的序列号是否表示模拟器 |
boolean
|
isFileSystemMountCheckEnabled()
返回是否应检查 |
boolean
|
isNullDevice(String serial)
确定给定的序列是否表示空设备 |
void
|
killEmulator(ITestDevice device)
关闭指定的模拟器。 |
void
|
launchEmulator(ITestDevice device, long bootTimeout, IRunUtil runUtil,
用于启动模拟器的辅助方法。 |
|
listAllDevices(boolean shortDescriptor)
返回所有已知设备的 DeviceDescriptor 列表 |
|
listAllDevices()
返回所有已知设备的 DeviceDescriptor 列表 |
ITestDevice
|
reconnectDeviceToTcp(ITestDevice usbDevice)
一种辅助方法,用于将给定的 USB 设备切换到 adb-over-tcp 模式,然后通过 |
void
|
removeDeviceMonitor(IDeviceMonitor mon)
移除之前添加的 |
void
|
removeFastbootListener(IDeviceManager.IFastbootListener listener)
通知管理器,监听器不再关注 fastboot 状态变化。 |
void
|
removeMonitoringTcpFastbootDevice(String serial)
|
void
|
restartAdbBridge()
重启(如果调用了 |
void
|
stopAdbBridge()
停止 adb 网桥和依赖于 adb 连接的服务。 |
void
|
terminate()
停止设备监控服务,并终止 ddm 库。 |
void
|
terminateDeviceMonitor()
停止设备监控器。 |
void
|
terminateDeviceRecovery()
停止设备恢复线程。 |
void
|
terminateHard(String reason)
与 |
void
|
terminateHard()
与 |
boolean
|
waitForFirstDeviceAdded(long timeout)
等待直到第一个实体设备连接成功。 |
常量
UNKNOWN_DISPLAY_STRING
public static final String UNKNOWN_DISPLAY_STRING
未知属性的显示字符串
常量值: "unknown"
字段
mFastbootEnabled
protected boolean mFastbootEnabled
公共构造函数
公共方法
addAvailableNativeDevice
public void addAvailableNativeDevice (IDevice stubDevice)
| 参数 | |
|---|---|
stubDevice |
IDevice |
addDeviceMonitor
public void addDeviceMonitor (IDeviceMonitor mon)
添加了 IDeviceMonitor
| 参数 | |
|---|---|
mon |
IDeviceMonitor |
addFastbootDevice
public void addFastbootDevice (DeviceManager.FastbootDevice fastbootDevice)
| 参数 | |
|---|---|
fastbootDevice |
DeviceManager.FastbootDevice |
addFastbootListener
public void addFastbootListener (IDeviceManager.IFastbootListener listener)
通知管理器,监听器对 fastboot 状态变化感兴趣。
目前,如果有一个或多个活跃的监听器,IDeviceManager 将仅监控 fastboot 中的设备。
TODO:这有点像是一种临时解决方案 - 找到更好的解决方案
addMonitoringTcpFastbootDevice
public void addMonitoringTcpFastbootDevice (String serial,
String fastbootSerial)向 fastboot 监控器添加设备。fastboot 监控器将使用“fastboot_serial”与设备通信。
| 参数 | |
|---|---|
serial |
String:设备的序列号。 |
fastbootSerial |
String:设备的 fastboot 模式序列号。 |
allocateDevice
public ITestDevice allocateDevice (IDeviceSelection options, boolean isTemporary)
请求满足特定条件的设备以进行测试。
| 参数 | |
|---|---|
options |
IDeviceSelection:设备应满足的 IDeviceSelection。 |
isTemporary |
boolean:是否应创建临时 NullDevice。 |
| 返回 | |
|---|---|
ITestDevice |
用于测试的 ITestDevice,如果没有,则为 null |
allocateDevice
public ITestDevice allocateDevice (IDeviceSelection options)
请求满足特定条件的设备以进行测试。
| 参数 | |
|---|---|
options |
IDeviceSelection:设备应满足的 IDeviceSelection。 |
| 返回 | |
|---|---|
ITestDevice |
用于测试的 ITestDevice,如果没有,则为 null |
allocateDevice
public ITestDevice allocateDevice ()
申请实体设备以进行测试
| 返回 | |
|---|---|
ITestDevice |
用于测试的 ITestDevice,如果没有,则为 null |
connectToTcpDevice
public ITestDevice connectToTcpDevice (String ipAndPort)
通过 adb-over-tcp 连接到设备
此方法会分配一个新设备,该设备最终应通过 disconnectFromTcpDevice(com.android.tradefed.device.ITestDevice) 释放
返回的 ITestDevice 将处于在线状态,但可能无响应。
请注意,对已连接 tcp 的设备执行重启等操作会断开与该设备的 tcp 连接,并导致 DeviceNotAvailableException
| 参数 | |
|---|---|
ipAndPort |
String:要连接的设备的原始 IP 地址和端口 |
| 返回 | |
|---|---|
ITestDevice |
如果无法建立 TCP 连接,则为 ITestDevice 或 null |
disconnectFromTcpDevice
public boolean disconnectFromTcpDevice (ITestDevice tcpDevice)
断开与通过 adb-over-tcp 连接的设备的连接。
将设备切换回 USB 模式,并释放设备。
| 参数 | |
|---|---|
tcpDevice |
ITestDevice:当前处于 TCP 模式的设备,之前通过 connectToTcpDevice(String) 分配 |
| 返回 | |
|---|---|
boolean |
如果切换到 USB 模式成功,则为 true |
displayDevicesInfo
public void displayDevicesInfo (PrintWriter stream,
boolean includeStub)输出包含已知设备列表、设备状态以及常用 IDeviceSelection 选项值的用户友好型说明。
| 参数 | |
|---|---|
stream |
PrintWriter:用于输出说明的 ERROR(/PrintWriter) |
includeStub |
boolean:是否也显示桩设备。 |
executeCmdOnAvailableDevice
public CommandResult executeCmdOnAvailableDevice (String serial, String command, long timeout, TimeUnit timeUnit)
用于在可用设备上执行 shell 命令的辅助方法。
| 参数 | |
|---|---|
serial |
String:设备序列号。 |
command |
String:shell 命令。 |
timeout |
long:命令完成所需的时间。 |
timeUnit |
TimeUnit:超时时间的单位。 |
| 返回 | |
|---|---|
CommandResult |
CommandResult。 |
executeGlobalAdbCommand
public String executeGlobalAdbCommand (String... cmdArgs)
执行未针对特定设备的 adb 命令,例如:“adb connect”
| 返回 | |
|---|---|
String |
如果命令成功,则为标准输出;否则为 null。 |
forceAllocateDevice
public ITestDevice forceAllocateDevice (String serial)
粗略地分配设备,即使设备目前不可用。
如果设备已分配,则不会有任何效果。
| 参数 | |
|---|---|
serial |
String:要分配的设备序列号 |
| 返回 | |
|---|---|
ITestDevice |
ITestDevice;如果无法分配,则为 null |
freeDevice
public void freeDevice (ITestDevice device, FreeDeviceState deviceState)
将设备返回到池中
尝试返回之前未分配的设备将被忽略。
| 参数 | |
|---|---|
device |
ITestDevice:要释放的 ITestDevice |
deviceState |
FreeDeviceState:FreeDeviceState。用于控制设备是否返回到可用设备池。 |
getAdbPath
public String getAdbPath ()
返回要使用的 adb 二进制文件的路径。
| 返回 | |
|---|---|
String |
|
getAdbVersion
public String getAdbVersion ()
获取设备管理器当前使用的 adb 版本。
| 返回 | |
|---|---|
String |
|
getDeviceDescriptor
public DeviceDescriptor getDeviceDescriptor (String serial)
返回具有指定序列号的 DeviceDescriptor。
| 参数 | |
|---|---|
serial |
String:要获取的设备的序列号 |
| 返回 | |
|---|---|
DeviceDescriptor |
所选设备的 DeviceDescriptor,如果序列号与已知设备不匹配,则为 null。 |
getFastbootPath
public String getFastbootPath ()
返回要使用的 fastboot 二进制文件的路径。
| 返回 | |
|---|---|
String |
|
init
public void init (IDeviceSelection globalDeviceFilter,globalDeviceMonitors, IManagedTestDeviceFactory deviceFactory)
初始化设备管理器。必须在调用任何其他方法之前调用此方法一次且仅一次。
| 参数 | |
|---|---|
globalDeviceFilter |
IDeviceSelection |
globalDeviceMonitors |
|
deviceFactory |
IManagedTestDeviceFactory |
init
public void init (IDeviceSelection globalDeviceFilter,globalDeviceMonitors)
初始化设备管理器。必须在调用任何其他方法之前调用此方法一次且仅一次。
| 参数 | |
|---|---|
globalDeviceFilter |
IDeviceSelection:设备过滤条件 |
globalDeviceMonitors |
|
init
public void init ()
初始化设备管理器。必须在调用任何其他方法之前调用此方法一次且仅一次。
isEmulator
public boolean isEmulator (String serial)
确定给定的序列号是否表示模拟器
| 参数 | |
|---|---|
serial |
String |
| 返回 | |
|---|---|
boolean |
|
isFileSystemMountCheckEnabled
public boolean isFileSystemMountCheckEnabled ()
返回是否应检查 NativeDeviceStateMonitor 中的文件系统是否已正确装载。
| 返回 | |
|---|---|
boolean |
|
isNullDevice
public boolean isNullDevice (String serial)
确定给定的序列是否表示 null 设备
| 参数 | |
|---|---|
serial |
String |
| 返回 | |
|---|---|
boolean |
|
killEmulator
public void killEmulator (ITestDevice device)
关闭指定的模拟器。
阻塞,直到模拟器从 adb 中消失。如果模拟器已不可用,则不会有任何影响。
| 参数 | |
|---|---|
device |
ITestDevice:表示要关闭的模拟器的 ITestDevice |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
launchEmulator
public void launchEmulator (ITestDevice device, long bootTimeout, IRunUtil runUtil,emulatorArgs)
用于启动模拟器的辅助方法。
将按照调用方的指定启动模拟器
| 参数 | |
|---|---|
device |
ITestDevice:表示已分配的模拟器设备的占位符 ITestDevice |
bootTimeout |
long:等待模拟器启动的时间(以毫秒为单位) |
emulatorArgs |
:用于启动模拟器的命令行实参 |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
listAllDevices
publiclistAllDevices (boolean shortDescriptor)
返回所有已知设备的 DeviceDescriptor 列表
| 参数 | |
|---|---|
shortDescriptor |
boolean:是否将描述符限制为最少信息 |
| 返回 | |
|---|---|
|
所有已知设备的 DeviceDescriptor 列表 |
listAllDevices
publiclistAllDevices ()
返回所有已知设备的 DeviceDescriptor 列表
| 返回 | |
|---|---|
|
所有已知设备的 DeviceDescriptor 列表 |
reconnectDeviceToTcp
public ITestDevice reconnectDeviceToTcp (ITestDevice usbDevice)
一种辅助方法,用于将给定的 USB 设备切换到 adb-over-tcp 模式,然后通过 connectToTcpDevice(String) 连接到该设备。
| 参数 | |
|---|---|
usbDevice |
ITestDevice:当前处于 USB 模式的设备 |
| 返回 | |
|---|---|
ITestDevice |
在 TCP 模式下新分配的 ITestDevice,或者在无法建立 TCP 连接的情况下新分配的 null |
| 抛出 | |
|---|---|
DeviceNotAvailableException |
|
removeDeviceMonitor
public void removeDeviceMonitor (IDeviceMonitor mon)
移除之前添加的 IDeviceMonitor。如果尚未添加 mon,则此参数无效。
| 参数 | |
|---|---|
mon |
IDeviceMonitor |
removeFastbootListener
public void removeFastbootListener (IDeviceManager.IFastbootListener listener)
通知管理器,监听器不再关注 fastboot 状态变化。
removeMonitoringTcpFastbootDevice
public void removeMonitoringTcpFastbootDevice (String serial)
| 参数 | |
|---|---|
serial |
String |
stopAdbBridge
public void stopAdbBridge ()
停止 adb 桥接和依赖于 adb 连接的服务。
终止
public void terminate ()
停止设备监控服务,并终止 ddm 库。
必须在应用终止时调用此方法。
terminateDeviceMonitor
public void terminateDeviceMonitor ()
停止设备监控器。
terminateDeviceRecovery
public void terminateDeviceRecovery ()
停止设备恢复线程。
terminateHard
public void terminateHard (String reason)
与 terminateHard() 类似。
| 参数 | |
|---|---|
reason |
String:终止的可选原因。 |
waitForFirstDeviceAdded
public boolean waitForFirstDeviceAdded (long timeout)
等待,直到连接上第一个实体设备。如果设备之前已连接,则直接返回 True。如果未添加任何设备,则在超时后返回 false。
| 参数 | |
|---|---|
timeout |
long:在返回 false 之前等待的时间(以毫秒为单位)。 |
| 返回 | |
|---|---|
boolean |
|