DeviceManager

public class DeviceManager
extends Object implements IDeviceManager

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


Summary

Nested classes

class DeviceManager.FastbootDevice

Representation of a device in Fastboot mode. 

Fields

public static final String UNKNOWN_DISPLAY_STRING

Display string for unknown properties

protected DeviceMonitorMultiplexer mDvcMon

protected boolean mFastbootEnabled

Public constructors

DeviceManager()

The DeviceManager should be retrieved from the GlobalConfiguration

Public methods

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

Adds a IDeviceMonitor

void addFastbootListener(IDeviceManager.IFastbootListener listener)

Informs the manager that a listener is interested in fastboot state changes.

void addMonitoringTcpFastbootDevice(String serial, String fastboot_serial)

Add a device to fastboot monitor.

ITestDevice allocateDevice(IDeviceSelection options, boolean isTemporary)

Request a device for testing that meets certain criteria.

ITestDevice allocateDevice(IDeviceSelection options)

Request a device for testing that meets certain criteria.

ITestDevice allocateDevice()

Request a physical device for testing

ITestDevice connectToTcpDevice(String ipAndPort)

Connect to a device with adb-over-tcp

This method allocates a new device, which should eventually be freed via disconnectFromTcpDevice(com.android.tradefed.device.ITestDevice)

The returned ITestDevice will be online, but may not be responsive.

boolean disconnectFromTcpDevice(ITestDevice tcpDevice)

Disconnect from an adb-over-tcp connected device.

void displayDevicesInfo(PrintWriter stream, boolean includeStub)

Output a user-friendly description containing list of known devices, their state, and values for commonly used IDeviceSelection options.

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

A helper method to execute shell command on available device.

String executeGlobalAdbCommand(String... cmdArgs)

Execute a adb command not targeted to a particular device eg.

ITestDevice forceAllocateDevice(String serial)

Rudely allocate a device, even if its not currently available.

void freeDevice(ITestDevice device, FreeDeviceState deviceState)

Return a device to the pool

Attempts to return a device that hasn't been previously allocated will be ignored.

String getAdbPath()

Returns the path to the adb binary to use.

String getAdbVersion()

Get the adb version currently in use by the device manager.

DeviceDescriptor getDeviceDescriptor(String serial)

Returns the DeviceDescriptor with the given serial.

String getFastbootPath()

Returns the path to the fastboot binary to use.

void init(IDeviceSelection globalDeviceFilter, globalDeviceMonitors, IManagedTestDeviceFactory deviceFactory)

Initialize the device manager.

void init(IDeviceSelection globalDeviceFilter, globalDeviceMonitors)

Initialize the device manager.

void init()

Initialize the device manager.

boolean isEmulator(String serial)

Determine if given serial represents a emulator

boolean isFileSystemMountCheckEnabled()

Returns whether or not we should check in NativeDeviceStateMonitor the file system is mounted properly.

boolean isNullDevice(String serial)

Determine if given serial represents a null device

void killEmulator(ITestDevice device)

Shut down the given emulator.

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

Helper method to launch emulator.

listAllDevices(boolean shortDescriptor)

Returns a list of DeviceDescriptors for all known devices

listAllDevices()

Returns a list of DeviceDescriptors for all known devices

ITestDevice reconnectDeviceToTcp(ITestDevice usbDevice)

A helper method that switches the given usb device to adb-over-tcp mode, and then connects to it via connectToTcpDevice(String).

void removeDeviceMonitor(IDeviceMonitor mon)

Removes a previously added IDeviceMonitor.

void removeFastbootListener(IDeviceManager.IFastbootListener listener)

Informs the manager that a listener is no longer interested in fastboot state changes.

void restartAdbBridge()

Restart (if stopAdbBridge() was called) adb bridge and services depend on adb connections.

void stopAdbBridge()

Stop adb bridge and services depend on adb connections.

void terminate()

Stops device monitoring services, and terminates the ddm library.

void terminateDeviceMonitor()

Stop the Device Monitors.

void terminateDeviceRecovery()

Stops the device recovery thread.

void terminateHard(String reason)

Like terminateHard().

void terminateHard()

Like terminate(), but attempts to forcefully shut down adb as well.

boolean waitForFirstDeviceAdded(long timeout)

Wait until a first physical device is connected.

Fields

UNKNOWN_DISPLAY_STRING

public static final String UNKNOWN_DISPLAY_STRING

Display string for unknown properties

mDvcMon

protected DeviceMonitorMultiplexer mDvcMon

mFastbootEnabled

protected boolean mFastbootEnabled

Public constructors

DeviceManager

public DeviceManager ()

The DeviceManager should be retrieved from the GlobalConfiguration

Public methods

addAvailableDevice

public void addAvailableDevice (IDevice stubDevice)

Parameters
stubDevice IDevice

addDeviceMonitor

public void addDeviceMonitor (IDeviceMonitor mon)

Adds a IDeviceMonitor

Parameters
mon IDeviceMonitor

addFastbootListener

public void addFastbootListener (IDeviceManager.IFastbootListener listener)

Informs the manager that a listener is interested in fastboot state changes.

Currently a IDeviceManager will only monitor devices in fastboot if there are one or more active listeners.

TODO: this is a bit of a hack - find a better solution

addMonitoringTcpFastbootDevice

public void addMonitoringTcpFastbootDevice (String serial, 
                String fastboot_serial)

Add a device to fastboot monitor. The fastboot monitor will use 'fastboot_serial' to communicate with the device.

Parameters
serial String: the device's serial number.

fastboot_serial String: the device's fastboot mode serial number.

allocateDevice

public ITestDevice allocateDevice (IDeviceSelection options, 
                boolean isTemporary)

Request a device for testing that meets certain criteria.

Parameters
options IDeviceSelection: the IDeviceSelection the device should meet.

isTemporary boolean: whether or not a temporary NullDevice should be created.

Returns
ITestDevice a ITestDevice for testing, or null if one is not available

allocateDevice

public ITestDevice allocateDevice (IDeviceSelection options)

Request a device for testing that meets certain criteria.

Parameters
options IDeviceSelection: the IDeviceSelection the device should meet.

Returns
ITestDevice a ITestDevice for testing, or null if one is not available

allocateDevice

public ITestDevice allocateDevice ()

Request a physical device for testing

Returns
ITestDevice a ITestDevice for testing, or null if one is not available

connectToTcpDevice

public ITestDevice connectToTcpDevice (String ipAndPort)

Connect to a device with adb-over-tcp

This method allocates a new device, which should eventually be freed via disconnectFromTcpDevice(com.android.tradefed.device.ITestDevice)

The returned ITestDevice will be online, but may not be responsive.

Note that performing action such as a reboot on a tcp connected device, will sever the tcp connection to the device, and result in a DeviceNotAvailableException

Parameters
ipAndPort String: the original ip address and port of the device to connect to

Returns
ITestDevice the ITestDevice or null if a tcp connection could not be formed

disconnectFromTcpDevice

public boolean disconnectFromTcpDevice (ITestDevice tcpDevice)

Disconnect from an adb-over-tcp connected device.

Switches the device back to usb mode, and frees it.

Parameters
tcpDevice ITestDevice: the device currently in tcp mode, previously allocated via connectToTcpDevice(String)

Returns
boolean true if switch to usb mode was successful

displayDevicesInfo

public void displayDevicesInfo (PrintWriter stream, 
                boolean includeStub)

Output a user-friendly description containing list of known devices, their state, and values for commonly used IDeviceSelection options.

Parameters
stream PrintWriter: the ERROR(/PrintWriter) to output the description to

includeStub boolean: Whether or not to display stub devices too.

executeCmdOnAvailableDevice

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

A helper method to execute shell command on available device.

Parameters
serial String: The device serial.

command String: The shell command.

timeout long: The amount of time for the command to complete.

timeUnit TimeUnit: The unit for the timeout.

Returns
CommandResult A CommandResult.

executeGlobalAdbCommand

public String executeGlobalAdbCommand (String... cmdArgs)

Execute a adb command not targeted to a particular device eg. 'adb connect'

Returns
String std output if the command succeedm null otherwise.

forceAllocateDevice

public ITestDevice forceAllocateDevice (String serial)

Rudely allocate a device, even if its not currently available.

Will have no effect if device is already allocated.

Parameters
serial String: the device serial to allocate

Returns
ITestDevice the ITestDevice, or null if it could not be allocated

freeDevice

public void freeDevice (ITestDevice device, 
                FreeDeviceState deviceState)

Return a device to the pool

Attempts to return a device that hasn't been previously allocated will be ignored.

Parameters
device ITestDevice: the ITestDevice to free

deviceState FreeDeviceState: the FreeDeviceState. Used to control if device is returned to available device pool.

getAdbPath

public String getAdbPath ()

Returns the path to the adb binary to use.

Returns
String

getAdbVersion

public String getAdbVersion ()

Get the adb version currently in use by the device manager.

Returns
String

getDeviceDescriptor

public DeviceDescriptor getDeviceDescriptor (String serial)

Returns the DeviceDescriptor with the given serial.

Parameters
serial String: serial number for the device to get

Returns
DeviceDescriptor the DeviceDescriptor for the selected device, or null if the serial does not match a known device.

getFastbootPath

public String getFastbootPath ()

Returns the path to the fastboot binary to use.

Returns
String

init

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

Initialize the device manager. This must be called once and only once before any other methods are called.

Parameters
globalDeviceFilter IDeviceSelection

globalDeviceMonitors

deviceFactory IManagedTestDeviceFactory

init

public void init (IDeviceSelection globalDeviceFilter, 
                 globalDeviceMonitors)

Initialize the device manager. This must be called once and only once before any other methods are called.

Parameters
globalDeviceFilter IDeviceSelection: the device filter

globalDeviceMonitors

init

public void init ()

Initialize the device manager. This must be called once and only once before any other methods are called.

isEmulator

public boolean isEmulator (String serial)

Determine if given serial represents a emulator

Parameters
serial String

Returns
boolean

isFileSystemMountCheckEnabled

public boolean isFileSystemMountCheckEnabled ()

Returns whether or not we should check in NativeDeviceStateMonitor the file system is mounted properly.

Returns
boolean

isNullDevice

public boolean isNullDevice (String serial)

Determine if given serial represents a null device

Parameters
serial String

Returns
boolean

killEmulator

public void killEmulator (ITestDevice device)

Shut down the given emulator.

Blocks until emulator disappears from adb. Will have no effect if emulator is already not available.

Parameters
device ITestDevice: the ITestDevice representing emulator to shut down

Throws
DeviceNotAvailableException

launchEmulator

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

Helper method to launch emulator.

Will launch the emulator as specified by the caller

Parameters
device ITestDevice: the placeholder ITestDevice representing allocated emulator device

bootTimeout long: the time in ms to wait for the emulator to boot

emulatorArgs : command line arguments to launch the emulator

Throws
DeviceNotAvailableException

listAllDevices

public  listAllDevices (boolean shortDescriptor)

Returns a list of DeviceDescriptors for all known devices

Parameters
shortDescriptor boolean: whether to limit descriptors to minimum info

Returns
a list of DeviceDescriptor for all known devices

listAllDevices

public  listAllDevices ()

Returns a list of DeviceDescriptors for all known devices

Returns
a list of DeviceDescriptor for all known devices

reconnectDeviceToTcp

public ITestDevice reconnectDeviceToTcp (ITestDevice usbDevice)

A helper method that switches the given usb device to adb-over-tcp mode, and then connects to it via connectToTcpDevice(String).

Parameters
usbDevice ITestDevice: the device currently in usb mode

Returns
ITestDevice the newly allocated ITestDevice in tcp mode or null if a tcp connection could not be formed

Throws
DeviceNotAvailableException

removeDeviceMonitor

public void removeDeviceMonitor (IDeviceMonitor mon)

Removes a previously added IDeviceMonitor. Has no effect if mon has not been added.

Parameters
mon IDeviceMonitor

removeFastbootListener

public void removeFastbootListener (IDeviceManager.IFastbootListener listener)

Informs the manager that a listener is no longer interested in fastboot state changes.

restartAdbBridge

public void restartAdbBridge ()

Restart (if stopAdbBridge() was called) adb bridge and services depend on adb connections.

stopAdbBridge

public void stopAdbBridge ()

Stop adb bridge and services depend on adb connections.

terminate

public void terminate ()

Stops device monitoring services, and terminates the ddm library.

This must be called upon application termination.

terminateDeviceMonitor

public void terminateDeviceMonitor ()

Stop the Device Monitors.

terminateDeviceRecovery

public void terminateDeviceRecovery ()

Stops the device recovery thread.

terminateHard

public void terminateHard (String reason)

Like terminateHard().

Parameters
reason String: optional reason given for the termination.

terminateHard

public void terminateHard ()

Like terminate(), but attempts to forcefully shut down adb as well.

waitForFirstDeviceAdded

public boolean waitForFirstDeviceAdded (long timeout)

Wait until a first physical device is connected. If a device was connected before, it returns directly True. If no device was added, it returns false after timeout.

Parameters
timeout long: time to wait in millisecond before returning false.

Returns
boolean