装置经理

public class DeviceManager
extends Object implements IDeviceManager

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


概括

嵌套类

class DeviceManager.FastbootDevice

处于快速启动模式的设备的表示。

领域

public static final String UNKNOWN_DISPLAY_STRING

显示未知属性的字符串

protected DeviceMonitorMultiplexer mDvcMon

protected boolean mFastbootEnabled

公共构造函数

DeviceManager ()

应从GlobalConfiguration中检索 DeviceManager

公共方法

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

添加IDeviceMonitor

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

通知管理器侦听器对 fastboot 状态更改感兴趣。

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) init ( IDeviceSelection globalDeviceFilter, globalDeviceMonitors, IManagedTestDeviceFactory deviceFactory)

初始化设备管理器。

void init ( IDeviceSelection globalDeviceFilter, globalDeviceMonitors) init ( IDeviceSelection globalDeviceFilter, globalDeviceMonitors)

初始化设备管理器。

void init ()

初始化设备管理器。

boolean isEmulator (String serial)

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

boolean isFileSystemMountCheckEnabled ()

返回我们是否应该在NativeDeviceStateMonitor中检查文件系统是否已正确安装。

boolean isNullDevice (String serial)

确定给定的序列号是否代表空设备

void killEmulator ( ITestDevice device)

关闭给定的模拟器。

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

启动模拟器的辅助方法。

listAllDevices (boolean shortDescriptor)

返回所有已知设备的设备描述符列表

listAllDevices ()

返回所有已知设备的设备描述符列表

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

mFastboot启用

protected boolean mFastbootEnabled

公共构造函数

装置经理

public DeviceManager ()

应从GlobalConfiguration中检索 DeviceManager

公共方法

添加可用设备

public void addAvailableDevice (IDevice stubDevice)

参数
stubDevice IDevice

添加设备监视器

public void addDeviceMonitor (IDeviceMonitor mon)

添加IDeviceMonitor

参数
mon IDeviceMonitor

添加快速启动设备

public void addFastbootDevice (DeviceManager.FastbootDevice fastbootDevice)

参数
fastbootDevice DeviceManager.FastbootDevice

添加FastbootListener

public void addFastbootListener (IDeviceManager.IFastbootListener listener)

通知管理器侦听器对 fastboot 状态更改感兴趣。

目前,如果存在一个或多个活动侦听器, IDeviceManager将仅监视 fastboot 中的设备。

TODO:这有点像黑客 - 找到更好的解决方案

添加监控TcpFastbootDevice

public void addMonitoringTcpFastbootDevice (String serial, 
                String fastboot_serial)

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

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

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

分配设备

public ITestDevice allocateDevice (IDeviceSelection options, 
                boolean isTemporary)

请求符合特定标准的设备进行测试。

参数
options IDeviceSelection :设备应满足的IDeviceSelection

isTemporary boolean :是否应创建临时 NullDevice。

退货
ITestDevice用于测试的ITestDevice ,如果不可用则为null

分配设备

public ITestDevice allocateDevice (IDeviceSelection options)

请求符合特定标准的设备进行测试。

参数
options IDeviceSelection :设备应满足的IDeviceSelection

退货
ITestDevice用于测试的ITestDevice ,如果不可用则为null

分配设备

public ITestDevice allocateDevice ()

请求物理设备进行测试

退货
ITestDevice用于测试的ITestDevice ,如果不可用则为null

连接到Tcp设备

public ITestDevice connectToTcpDevice (String ipAndPort)

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

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

返回的ITestDevice将在线,但可能不会响应。

请注意,在 tcp 连接的设备上执行诸如重新启动之类的操作,将切断与设备的 tcp 连接,并导致DeviceNotAvailableException

参数
ipAndPort String : 要连接的设备的原始IP地址和端口

退货
ITestDevice如果无法形成 tcp 连接,则返回ITestDevicenull

断开与Tcp设备的连接

public boolean disconnectFromTcpDevice (ITestDevice tcpDevice)

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

将设备切换回 USB 模式并释放它。

参数
tcpDevice ITestDevice :当前处于 tcp 模式的设备,之前通过connectToTcpDevice(String)分配

退货
boolean true如果切换到 USB 模式成功

显示设备信息

public void displayDevicesInfo (PrintWriter stream, 
                boolean includeStub)

输出用户友好的描述,其中包含已知设备的列表、其状态以及常用IDeviceSelection选项的值。

参数
stream PrintWriter : 将描述输出到的ERROR(/PrintWriter)

includeStub boolean :是否也显示存根设备。

在可用设备上执行Cmd

public CommandResult executeCmdOnAvailableDevice (String serial, 
                String command, 
                long timeout, 
                TimeUnit timeUnit)

在可用设备上执行 shell 命令的辅助方法。

参数
serial String :设备序列号。

command String :shell 命令。

timeout long :命令完成的时间量。

timeUnit TimeUnit :超时的单位。

退货
CommandResult一个CommandResult

执行GlobalAdb命令

public String executeGlobalAdbCommand (String... cmdArgs)

执行不针对特定设备的 adb 命令,例如。 '亚行连接'

退货
String如果命令成功则 std 输出,否则为 null。

强制分配设备

public ITestDevice forceAllocateDevice (String serial)

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

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

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

退货
ITestDevice ITestDevice ,如果无法分配则为null

免费设备

public void freeDevice (ITestDevice device, 
                FreeDeviceState deviceState)

将设备放回池中

返回先前未分配的设备的尝试将被忽略。

参数
device ITestDevice :要释放的ITestDevice

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

获取AdbPath

public String getAdbPath ()

返回要使用的 adb 二进制文件的路径。

退货
String

获取Adb版本

public String getAdbVersion ()

获取设备管理器当前使用的 adb 版本。

退货
String

获取设备描述符

public DeviceDescriptor getDeviceDescriptor (String serial)

返回具有给定序列的 DeviceDescriptor。

参数
serial String : 要获取的设备序列号

退货
DeviceDescriptor所选设备的DeviceDescriptor ,如果序列号与已知设备不匹配,则为 null。

获取快速启动路径

public String getFastbootPath ()

返回要使用的 fastboot 二进制文件的路径。

退货
String

在里面

public void init (IDeviceSelection globalDeviceFilter, 
                 globalDeviceMonitors, 
                IManagedTestDeviceFactory deviceFactory)

初始化设备管理器。在调用任何其他方法之前,必须调用此方法一次且仅调用一次。

参数
globalDeviceFilter IDeviceSelection

globalDeviceMonitors

deviceFactory IManagedTestDeviceFactory

在里面

public void init (IDeviceSelection globalDeviceFilter, 
                 globalDeviceMonitors)

初始化设备管理器。在调用任何其他方法之前,必须调用此方法一次且仅调用一次。

参数
globalDeviceFilter IDeviceSelection :设备过滤器

globalDeviceMonitors

在里面

public void init ()

初始化设备管理器。在调用任何其他方法之前,必须调用此方法一次且仅调用一次。

是模拟器

public boolean isEmulator (String serial)

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

参数
serial String

退货
boolean

isFileSystemMountCheckEnabled

public boolean isFileSystemMountCheckEnabled ()

返回我们是否应该在NativeDeviceStateMonitor中检查文件系统是否已正确安装。

退货
boolean

为空设备

public boolean isNullDevice (String serial)

确定给定的序列号是否代表空设备

参数
serial String

退货
boolean

杀死模拟器

public void killEmulator (ITestDevice device)

关闭给定的模拟器。

阻塞直到模拟器从 adb 中消失。如果模拟器已经不可用,则不会有任何效果。

参数
device ITestDevice :代表要关闭的模拟器的ITestDevice

投掷
DeviceNotAvailableException

启动模拟器

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

启动模拟器的辅助方法。

将按照调用者的指定启动模拟器

参数
device ITestDevice :表示分配的模拟器设备的占位符ITestDevice

bootTimeout long :等待模拟器启动的时间(以毫秒为单位)

emulatorArgs :启动模拟器的命令行参数

投掷
DeviceNotAvailableException

列出所有设备

public  listAllDevices (boolean shortDescriptor)

返回所有已知设备的设备描述符列表

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

退货
所有已知设备的DeviceDescriptor列表

列出所有设备

public  listAllDevices ()

返回所有已知设备的设备描述符列表

退货
所有已知设备的DeviceDescriptor列表

重新连接设备到Tcp

public ITestDevice reconnectDeviceToTcp (ITestDevice usbDevice)

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

参数
usbDevice ITestDevice :当前处于 USB 模式的设备

退货
ITestDevice tcp 模式下新分配的ITestDevice ,如果无法形成 tcp 连接则null

投掷
DeviceNotAvailableException

删除设备监视器

public void removeDeviceMonitor (IDeviceMonitor mon)

删除之前添加的IDeviceMonitor 。如果未添加 mon,则无效。

参数
mon IDeviceMonitor

删除FastbootListener

public void removeFastbootListener (IDeviceManager.IFastbootListener listener)

通知管理器侦听器不再对快速启动状态更改感兴趣。

重启AdbBridge

public void restartAdbBridge ()

重新启动(如果调用了stopAdbBridge() ) adb 桥和服务依赖于 adb 连接。

停止AdbBridge

public void stopAdbBridge ()

停止 adb 桥接和依赖 adb 连接的服务。

终止

public void terminate ()

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

这必须在应用程序终止时调用。

终止设备监视器

public void terminateDeviceMonitor ()

停止设备监视器。

终止设备恢复

public void terminateDeviceRecovery ()

停止设备恢复线程。

硬终止

public void terminateHard (String reason)

就像terminateHard()一样。

参数
reason String :给出终止的可选原因。

硬终止

public void terminateHard ()

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

等待第一个设备添加

public boolean waitForFirstDeviceAdded (long timeout)

等待第一个物理设备连接。如果之前连接过设备,则直接返回True。如果没有添加设备,则超时后返回false。

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

退货
boolean