to top
public class

DeviceManager

extends Object
implements IDeviceManager @OptionClass(alias = "dmgr", global_namespace = false)
java.lang.Object
   ↳ com.android.tradefed.device.DeviceManager

Summary

Nested Classes
class DeviceManager.FastbootDevice  
Fields
static final IDeviceSelection ANY_DEVICE_OPTIONS a DeviceSelectionOptions that matches any device.
private long mDeviceRecoveryInterval @Option(name = "device-recovery-interval", description = "the interval in ms between attempts to recover unavailable devices.")
private int mNumEmulatorSupported @Option(name = "max-emulators", description = "the maximum number of emulators that can be allocated at one time")
private int mNumNullDevicesSupported @Option(name = "max-null-devices", description = "the maximum number of no device runs that can be allocated at one time.")
private int mNumTcpDevicesSupported @Option(name = "max-tcp-devices", description = "the maximum number of tcp devices that can be allocated at one time")
Public Constructors
DeviceManager()
The DeviceManager should be retrieved from the GlobalConfiguration
Public Methods
void addDeviceMonitor(IDeviceMonitor mon)
void addFastbootListener(IDeviceManager.IFastbootListener listener)
Informs the manager that a listener is interested in fastboot state changes.
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(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)
Output a user-friendly description containing list of known devices, their state, and values for commonly used IDeviceSelection options.
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.

void init(IDeviceSelection globalDeviceFilter, List<IDeviceMonitor> globalDeviceMonitors)
Initialize the device manager.
void init()
Initialize the device manager.
boolean isEmulator(String serial)
Determine if given serial represents a emulator
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, List<String> emulatorArgs)
Helper method to launch emulator.
List<DeviceDescriptor> listAllDevices()
Returns a map of all known devices and their state
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 terminate()
Stops device monitoring services, and terminates the ddm library.
void terminateHard()
Like terminate(), but attempts to forcefully shut down adb as well.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.tradefed.device.IDeviceManager

Fields

static final IDeviceSelection ANY_DEVICE_OPTIONS

a DeviceSelectionOptions that matches any device. Visible for testing.

private long mDeviceRecoveryInterval

private int mNumEmulatorSupported

private int mNumNullDevicesSupported

private int mNumTcpDevicesSupported

Public Constructors

public DeviceManager ()

The DeviceManager should be retrieved from the GlobalConfiguration

Public Methods

public void addDeviceMonitor (IDeviceMonitor mon)

Adds a IDeviceMonitor

Parameters
mon IDeviceMonitor

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

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

public ITestDevice allocateDevice ()

Request a physical device for testing

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

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(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

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

public void displayDevicesInfo (PrintWriter stream)

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

Parameters
stream PrintWriter: the PrintWriter to output the description to

public String executeGlobalAdbCommand (String... cmdArgs)

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

Returns
String

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

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 ERROR(/IDeviceManager.FreeDeviceState). Used to control if device is returned to available device pool.

public void init (IDeviceSelection globalDeviceFilter, List<IDeviceMonitor> 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 List

public void init ()

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

public boolean isEmulator (String serial)

Determine if given serial represents a emulator

Parameters
serial String
Returns
boolean

public boolean isNullDevice (String serial)

Determine if given serial represents a null device

Parameters
serial String
Returns
boolean

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

public void launchEmulator (ITestDevice device, long bootTimeout, IRunUtil runUtil, List<String> 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 List: command line arguments to launch the emulator
Throws
DeviceNotAvailableException

public List<DeviceDescriptor> listAllDevices ()

Returns a map of all known devices and their state

Returns
List<DeviceDescriptor> a list of device serials and their ERROR(/DeviceAllocationState)

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

public void removeDeviceMonitor (IDeviceMonitor mon)

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

Parameters
mon IDeviceMonitor

public void removeFastbootListener (IDeviceManager.IFastbootListener listener)

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

public void terminate ()

Stops device monitoring services, and terminates the ddm library.

This must be called upon application termination.

public void terminateHard ()

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