DeviceManager

public class DeviceManager
extends Object implements IDeviceManager

java.lang.Object
   ↳ com.android.tradefed.device.DeviceManager


摘要

嵌套类

class DeviceManager.FastbootDevice

处于 Fastboot 模式的设备的表示法。 

字段

public static final String UNKNOWN_DISPLAY_STRING

显示未知属性的字符串

protected DeviceMonitorMultiplexer mDvcMon

protected boolean mFastbootEnabled

公共构造函数

DeviceManager()

应从 GlobalConfiguration 检索 DeviceManager

公共方法

void addAvailableDevice(IDevice stubDevice)
void addAvailableNativeDevice(IDevice stubDevice)
void addDeviceMonitor(IDeviceMonitor mon)

添加了 IDeviceMonitor

void addFastbootDevice(DeviceManager.FastbootDevice fastbootDevice)
void addFastbootListener(IDeviceManager.IFastbootListener listener)

告知管理器监听器对快速启动状态变化感兴趣。

void addMonitoringTcpFastbootDevice(String serial, String fastboot_serial)

向 fastboot 监控器添加了设备。

ITestDevice allocateDevice(IDeviceSelection options, boolean isTemporary)

请求用于测试且符合特定条件的设备。

ITestDevice allocateDevice(IDeviceSelection options)

请求用于测试且符合特定条件的设备。

ITestDevice allocateDevice()

申请实体设备以进行测试

ITestDevice connectToTcpDevice(String ipAndPort)

使用 adb-over-tcp 连接到设备

此方法会分配一个新设备,该设备最终应通过 disconnectFromTcpDevice(com.android.tradefed.device.ITestDevice) 释放

返回的 ITestDevice 将处于在线状态,但可能无响应。

boolean disconnectFromTcpDevice(ITestDevice tcpDevice)

断开与 adb-over-tcp 连接的设备的连接。

void displayDevicesInfo(PrintWriter stream, boolean includeStub)

输出方便用户理解的说明,其中包含已知设备的列表、其状态以及常用 IDeviceSelection 选项的值。

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, globalDeviceMonitors, IManagedTestDeviceFactory deviceFactory)

初始化设备管理器。

void init(IDeviceSelection globalDeviceFilter, globalDeviceMonitors)

初始化设备管理器。

void init()

初始化设备管理器。

boolean isEmulator(String serial)

确定给定序列是否代表模拟器

boolean isFileSystemMountCheckEnabled()

返回是否应在 NativeDeviceStateMonitor 中检查文件系统是否已正确挂载。

boolean isNullDevice(String serial)

确定给定序列号是否表示 null 设备

void killEmulator(ITestDevice device)

关闭给定模拟器。

void launchEmulator(ITestDevice device, long bootTimeout, IRunUtil runUtil, emulatorArgs)

用于启动模拟器的辅助方法。

listAllDevices(boolean shortDescriptor)

返回所有已知设备的 DeviceDescriptor 列表

listAllDevices()

返回所有已知设备的 DeviceDescriptor 列表

ITestDevice reconnectDeviceToTcp(ITestDevice usbDevice)

一种辅助方法,用于将给定 USB 设备切换到 adb-over-tcp 模式,然后通过 connectToTcpDevice(String) 连接到该设备。

void removeDeviceMonitor(IDeviceMonitor mon)

移除之前添加的 IDeviceMonitor

void removeFastbootListener(IDeviceManager.IFastbootListener listener)

告知管理器监听器不再对快速启动状态变化感兴趣。

void restartAdbBridge()

重启(如果调用了 stopAdbBridge())adb 桥接,并且服务依赖于 adb 连接。

void stopAdbBridge()

停止 adb 桥接,并停止依赖于 adb 连接的服务。

void terminate()

停止设备监控服务,并终止 ddm 库。

void terminateDeviceMonitor()

停止设备监视器。

void terminateDeviceRecovery()

停止设备恢复线程。

void terminateHard(String reason)

terminateHard() 类似。

void terminateHard()

terminate() 类似,但还会尝试强制关闭 adb。

boolean waitForFirstDeviceAdded(long timeout)

等待第一个实体设备连接。

字段

UNKNOWN_DISPLAY_STRING

public static final String UNKNOWN_DISPLAY_STRING

显示不明属性的字符串

mDvcMon

protected DeviceMonitorMultiplexer mDvcMon

mFastbootEnabled

protected boolean mFastbootEnabled

公共构造函数

DeviceManager

public DeviceManager ()

应从 GlobalConfiguration 检索 DeviceManager

公共方法

addAvailableDevice

public void addAvailableDevice (IDevice stubDevice)

参数
stubDevice IDevice

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)

告知管理器监听器对快速启动状态变化感兴趣。

目前,只有在存在一个或多个活跃监听器的情况下,IDeviceManager 才会监控快速启动中的设备。

TODO:这有点像是黑客行为 - 请找出更好的解决方案

addMonitoringTcpFastbootDevice

public void addMonitoringTcpFastbootDevice (String serial, 
                String fastboot_serial)

向 fastboot 监控器添加了设备。fastboot 监视器将使用“fastboot_serial”与设备通信。

参数
serial String:设备的序列号。

fastboot_serial String:设备的快速启动模式序列号。

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 连接,则为 ITestDevicenull

disconnectFromTcpDevice

public boolean disconnectFromTcpDevice (ITestDevice tcpDevice)

断开与通过 TCP 连接的 adb 设备的连接。

将设备切换回 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 如果命令成功,则输出 std;否则输出 null。

forceAllocateDevice

public ITestDevice forceAllocateDevice (String serial)

粗鲁地分配设备,即使设备目前不可用。

如果设备已分配,则不会产生任何影响。

参数
serial String:要分配的设备序列号

返回
ITestDevice ITestDevice,如果无法分配则为 null

freeDevice

public void freeDevice (ITestDevice device, 
                FreeDeviceState deviceState)

将设备退回池

系统会忽略尝试返回之前未分配的设备。

参数
device ITestDevice:要释放的 ITestDevice

deviceState FreeDeviceStateFreeDeviceState。用于控制是否将设备返回到可用设备池。

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

public  listAllDevices (boolean shortDescriptor)

返回所有已知设备的 DeviceDescriptor 列表

参数
shortDescriptor boolean:是否将描述符限制为最少信息

返回
所有已知设备的 DeviceDescriptor 列表

listAllDevices

public  listAllDevices ()

返回所有已知设备的 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)

告知管理器监听器不再对快速启动状态变化感兴趣。

restartAdbBridge

public void restartAdbBridge ()

重启(如果调用了 stopAdbBridge())adb 桥接,并且服务依赖于 adb 连接。

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:终止交易的可选原因。

terminateHard

public void terminateHard ()

terminate() 类似,但还会尝试强行关闭 adb。

waitForFirstDeviceAdded

public boolean waitForFirstDeviceAdded (long timeout)

等待第一个实体设备连接。如果设备之前已连接,则会直接返回 True。如果未添加任何设备,则会在超时后返回 false。

参数
timeout long:在返回 false 之前等待的时间(以毫秒为单位)。

返回
boolean