to top
public interface

IDeviceManager

com.android.tradefed.device.IDeviceManager
Known Indirect Subclasses

Class Overview

Interface for managing the set of available devices for testing.

Summary

Nested Classes
interface IDeviceManager.IFastbootListener A listener for fastboot state changes. 
Public Methods
abstract void addDeviceMonitor(IDeviceMonitor mon)
abstract void addFastbootListener(IDeviceManager.IFastbootListener listener)
Informs the manager that a listener is interested in fastboot state changes.
abstract ITestDevice allocateDevice()
Request a physical device for testing
abstract ITestDevice allocateDevice(IDeviceSelection options)
Request a device for testing that meets certain criteria.
abstract 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.

abstract boolean disconnectFromTcpDevice(ITestDevice tcpDevice)
Disconnect from an adb-over-tcp connected device.
abstract void displayDevicesInfo(PrintWriter printWriter)
Output a user-friendly description containing list of known devices, their state, and values for commonly used IDeviceSelection options.
abstract ITestDevice forceAllocateDevice(String serial)
Rudely allocate a device, even if its not currently available.
abstract void freeDevice(ITestDevice device, FreeDeviceState state)
Return a device to the pool

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

abstract void init()
Initialize the device manager.
abstract void init(IDeviceSelection globalDeviceFilter, List<IDeviceMonitor> deviceMonitors)
Initialize the device manager with a device filter.
abstract boolean isEmulator(String serial)
Determine if given serial represents a emulator
abstract boolean isNullDevice(String serial)
Determine if given serial represents a null device
abstract void killEmulator(ITestDevice device)
Shut down the given emulator.
abstract void launchEmulator(ITestDevice device, long bootTimeout, IRunUtil runUtil, List<String> emulatorArgs)
Helper method to launch emulator.
abstract List<DeviceDescriptor> listAllDevices()
Returns a map of all known devices and their state
abstract 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).
abstract void removeDeviceMonitor(IDeviceMonitor mon)
Removes a previously added IDeviceMonitor.
abstract void removeFastbootListener(IDeviceManager.IFastbootListener listener)
Informs the manager that a listener is no longer interested in fastboot state changes.
abstract void terminate()
Stops device monitoring services, and terminates the ddm library.
abstract void terminateHard()
Like terminate(), but attempts to forcefully shut down adb as well.

Public Methods

public abstract void addDeviceMonitor (IDeviceMonitor mon)

public abstract 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 abstract ITestDevice allocateDevice ()

Request a physical device for testing

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

public abstract ITestDevice allocateDevice (IDeviceSelection options)

Request a device for testing that meets certain criteria.

Parameters
options the IDeviceSelection the device should meet.
Returns
  • a ITestDevice for testing, or null if one is not available

public abstract 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 the original ip address and port of the device to connect to
Returns
  • the ITestDevice or null if a tcp connection could not be formed

public abstract boolean disconnectFromTcpDevice (ITestDevice tcpDevice)

Disconnect from an adb-over-tcp connected device.

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

Parameters
tcpDevice the device currently in tcp mode, previously allocated via connectToTcpDevice(String)
Returns
  • true if switch to usb mode was successful

public abstract void displayDevicesInfo (PrintWriter printWriter)

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

Parameters
printWriter the PrintWriter to output the description to

public abstract 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 the device serial to allocate
Returns

public abstract void freeDevice (ITestDevice device, FreeDeviceState state)

Return a device to the pool

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

Parameters
device the ITestDevice to free
state the ERROR(/IDeviceManager.FreeDeviceState). Used to control if device is returned to available device pool.

public abstract void init ()

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

public abstract void init (IDeviceSelection globalDeviceFilter, List<IDeviceMonitor> deviceMonitors)

Initialize the device manager with a device filter. This filter can be used to instruct the DeviceManager to ignore certain connected devices.

Parameters
globalDeviceFilter the device filter

public abstract boolean isEmulator (String serial)

Determine if given serial represents a emulator

public abstract boolean isNullDevice (String serial)

Determine if given serial represents a null device

public abstract 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 the ITestDevice representing emulator to shut down
Throws
DeviceNotAvailableException if emulator fails to shut down

public abstract 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 the placeholder ITestDevice representing allocated emulator device
bootTimeout the time in ms to wait for the emulator to boot
emulatorArgs command line arguments to launch the emulator
Throws
DeviceNotAvailableException if emulator fails to boot or come online

public abstract List<DeviceDescriptor> listAllDevices ()

Returns a map of all known devices and their state

Returns

public abstract 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 the device currently in usb mode
Returns
  • the newly allocated ITestDevice in tcp mode or null if a tcp connection could not be formed
Throws
DeviceNotAvailableException if the connection with usbDevice was lost and could not be recovered

public abstract void removeDeviceMonitor (IDeviceMonitor mon)

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

public abstract void removeFastbootListener (IDeviceManager.IFastbootListener listener)

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

public abstract void terminate ()

Stops device monitoring services, and terminates the ddm library.

This must be called upon application termination.

See Also

public abstract void terminateHard ()

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