public class

DeviceManager

extends Object
implements IDeviceManager
java.lang.Object
   ↳ com.android.tradefed.device.DeviceManager

Class Overview

Summary

Public Methods
void addFastbootListener(IDeviceManager.IFastbootListener listener)
Informs the manager that a listener is interested in fastboot state changes.
ITestDevice allocateDevice(long timeout)
Request a physical device for testing, waiting for timeout ms until one becomes available.
ITestDevice allocateDevice()
Request a physical device for testing, waiting indefinitely until one becomes available.
ITestDevice allocateDevice(long timeout, IDeviceSelection options)
Request a device for testing that meets certain criteria.
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, IDeviceManager.FreeDeviceState deviceState)
Return a device to the pool

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

synchronized Collection<String> getAllocatedDevices()
Diagnostic method that returns a list of the devices currently allocated for testing.
synchronized Collection<String> getAvailableDevices()
Diagnostic method that returns a list of the devices available for allocation.
synchronized static IDeviceManager getInstance()
Return the IDeviceManager singleton, creating if necessary.
synchronized Collection<String> getUnavailableDevices()
Diagnostic method that returns a list of the devices currently visible via adb, but not deemed available for allocation.
void init()
Initialize the device manager.
synchronized void init(IDeviceSelection globalDeviceFilter)
Initialize the device manager.
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.
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 removeFastbootListener(IDeviceManager.IFastbootListener listener)
Informs the manager that a listener is no longer interested in fastboot state changes.
void setEnableLogcat(boolean enableLogcat)
Toggle whether allocated devices should capture logcat in background
synchronized void terminate()
Stops device monitoring services, and terminates the ddm library.
synchronized 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

Public Methods

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 (long timeout)

Request a physical device for testing, waiting for timeout ms until one becomes available.

Parameters
timeout max time in ms to wait for a device to become available.
Returns
  • a ITestDevice for testing, or null if timeout expired before one became available

public ITestDevice allocateDevice ()

Request a physical device for testing, waiting indefinitely until one becomes available.

Returns

public ITestDevice allocateDevice (long timeout, IDeviceSelection options)

Request a device for testing that meets certain criteria.

Parameters
timeout max time in ms to wait for a device to become available.
options the IDeviceSelection the device should meet.
Returns
  • a ITestDevice for testing, or null if timeout expired before one became 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 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 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 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 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'

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

public void freeDevice (ITestDevice device, IDeviceManager.FreeDeviceState deviceState)

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
deviceState the IDeviceManager.FreeDeviceState. Used to control if device is returned to available device pool.

public synchronized Collection<String> getAllocatedDevices ()

Diagnostic method that returns a list of the devices currently allocated for testing.

Returns

public synchronized Collection<String> getAvailableDevices ()

Diagnostic method that returns a list of the devices available for allocation.

Returns

public static synchronized IDeviceManager getInstance ()

Return the IDeviceManager singleton, creating if necessary.

public synchronized Collection<String> getUnavailableDevices ()

Diagnostic method that returns a list of the devices currently visible via adb, but not deemed available for allocation.

Returns

public void init ()

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

public synchronized void init (IDeviceSelection globalDeviceFilter)

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

Parameters
globalDeviceFilter the device filter

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 the ITestDevice representing emulator to shut down

public void launchEmulator (ITestDevice device, long bootTimeout, IRunUtil runUtil, List<String> emulatorArgs)

Helper method to launch emulator.

Will launch the emulator on the port specified in the allocated ITestDevice. Blocks until emulator launches successfully.

Parameters
device the placeholder ITestDevice representing allocated emulator device

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 the device currently in usb mode
Returns
  • the newly allocated ITestDevice in tcp mode or null if a tcp connection could not be formed

public void removeFastbootListener (IDeviceManager.IFastbootListener listener)

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

public void setEnableLogcat (boolean enableLogcat)

Toggle whether allocated devices should capture logcat in background

public synchronized void terminate ()

Stops device monitoring services, and terminates the ddm library.

This must be called upon application termination.

public synchronized void terminateHard ()

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