IDeviceStateMonitor

public interface IDeviceStateMonitor

com.android.tradefed.device.IDeviceStateMonitor


Provides facilities for monitoring the state of a IDevice.

A device is currently considered "available" if and only if four events are true: 1. Device is online aka visible via DDMS/adb (waitForDeviceOnline() 2. Device has dev.bootcomplete flag set (@link #waitForBootComplete(long)} 3. Device's package manager is responsive (may be inop) 4. Device's external storage is mounted 3. & 4. being part of waitForDeviceAvailable().

Summary

Public methods

default void attachFinalState(TestDeviceState finalState)

Attach a final state to abort waitForDeviceState if reached.

abstract TestDeviceState getDeviceState()

Gets the device state.

abstract String getFastbootSerialNumber()

Gets the fastboot mode serial number.

abstract String getMountPoint(String mountName)

Returns a mount point.

abstract String getSerialNumber()

Gets the serial number of the device.

abstract boolean isAdbTcp()
abstract void setDefaultAvailableTimeout(long timeoutMs)

Set the time in ms to wait for a device to be available in waitForDeviceAvailable().

abstract void setDefaultOnlineTimeout(long timeoutMs)

Set the time in ms to wait for a device to be online in waitForDeviceOnline().

abstract void setFastbootSerialNumber(String serial)

Sets the fastboot mode serial number.

abstract void setIDevice(IDevice device)

Updates the current IDevice.

abstract void setState(TestDeviceState deviceState)

Sets the device current state.

abstract boolean waitForBootComplete(long waitTime)

Blocks until the device's boot complete flag is set

abstract IDevice waitForDeviceAvailable(long waitTime)

Waits for the device to be responsive and available for testing.

abstract IDevice waitForDeviceAvailable()

Waits for the device to be responsive and available for testing.

default IDevice waitForDeviceAvailableInRecoverPath(long waitTime)

Special variant of waitForDeviceAvailable(long) to be called during recovery path to tailor the handling.

abstract boolean waitForDeviceBootloader(long waitTime)

Waits for the device to be in bootloader.

abstract void waitForDeviceBootloaderStateUpdate()

Waits for device bootloader state to be refreshed

abstract boolean waitForDeviceFastbootd(String fastbootPath, long waitTime)

Waits for the device to be in fastbootd.

abstract IDevice waitForDeviceInRecovery()

Waits for the device to be in Recovery mode using standard boot timeout.

abstract boolean waitForDeviceInRecovery(long waitTime)

Waits for the device to be in the 'adb recovery' state

abstract boolean waitForDeviceInSideload(long waitTime)

Waits for the device to be in the 'adb sideload' state

abstract boolean waitForDeviceNotAvailable(long waitTime)

Waits for the device to be not available

abstract IDevice waitForDeviceOnline()

Waits for device to be online using standard boot timeout.

abstract IDevice waitForDeviceOnline(long time)

Waits for device to be online.

abstract boolean waitForDeviceShell(long waitTime)

Waits for device to be responsive to a basic adb shell command.

Public methods

attachFinalState

public void attachFinalState (TestDeviceState finalState)

Attach a final state to abort waitForDeviceState if reached.

Parameters
finalState TestDeviceState

getDeviceState

public abstract TestDeviceState getDeviceState ()

Gets the device state.

Returns
TestDeviceState the TestDeviceState of device

getFastbootSerialNumber

public abstract String getFastbootSerialNumber ()

Gets the fastboot mode serial number.

Returns
String

getMountPoint

public abstract String getMountPoint (String mountName)

Returns a mount point.

Queries the device directly if the cached info in IDevice is not available.

TODO: move this behavior to IDevice#getMountPoint(String)

Parameters
mountName String: the name of the mount point

Returns
String the mount point or null

Throws
DeviceNotAvailableException

getSerialNumber

public abstract String getSerialNumber ()

Gets the serial number of the device.

Returns
String

isAdbTcp

public abstract boolean isAdbTcp ()

Returns
boolean true if device is connected to adb via tcp

setDefaultAvailableTimeout

public abstract void setDefaultAvailableTimeout (long timeoutMs)

Set the time in ms to wait for a device to be available in waitForDeviceAvailable().

Parameters
timeoutMs long

setDefaultOnlineTimeout

public abstract void setDefaultOnlineTimeout (long timeoutMs)

Set the time in ms to wait for a device to be online in waitForDeviceOnline().

Parameters
timeoutMs long

setFastbootSerialNumber

public abstract void setFastbootSerialNumber (String serial)

Sets the fastboot mode serial number.

Parameters
serial String

setIDevice

public abstract void setIDevice (IDevice device)

Updates the current IDevice.

setState

public abstract void setState (TestDeviceState deviceState)

Sets the device current state.

waitForBootComplete

public abstract boolean waitForBootComplete (long waitTime)

Blocks until the device's boot complete flag is set

Parameters
waitTime long: the amount in ms to wait

Returns
boolean

waitForDeviceAvailable

public abstract IDevice waitForDeviceAvailable (long waitTime)

Waits for the device to be responsive and available for testing. Currently this means that the package manager and external storage are available.

Parameters
waitTime long: the time in ms to wait

Returns
IDevice the IDevice if device becomes online before time expires. null otherwise.

waitForDeviceAvailable

public abstract IDevice waitForDeviceAvailable ()

Waits for the device to be responsive and available for testing.

Equivalent to waitForDeviceAvailable(long), but uses default device boot timeout.

Returns
IDevice the IDevice if device becomes online before time expires. null otherwise.

waitForDeviceAvailableInRecoverPath

public IDevice waitForDeviceAvailableInRecoverPath (long waitTime)

Special variant of waitForDeviceAvailable(long) to be called during recovery path to tailor the handling.

Parameters
waitTime long

Returns
IDevice

Throws
DeviceNotAvailableException if the device turns unavailable.

waitForDeviceBootloader

public abstract boolean waitForDeviceBootloader (long waitTime)

Waits for the device to be in bootloader.

Parameters
waitTime long: the maximum time in ms to wait

Returns
boolean true if device is in bootloader before time expires

waitForDeviceBootloaderStateUpdate

public abstract void waitForDeviceBootloaderStateUpdate ()

Waits for device bootloader state to be refreshed

waitForDeviceFastbootd

public abstract boolean waitForDeviceFastbootd (String fastbootPath, 
                long waitTime)

Waits for the device to be in fastbootd.

Parameters
fastbootPath String: the path of the fastboot binary to use.

waitTime long: the maximum time in ms to wait

Returns
boolean true if device is in fastbootd before time expires

waitForDeviceInRecovery

public abstract IDevice waitForDeviceInRecovery ()

Waits for the device to be in Recovery mode using standard boot timeout.

Returns
IDevice the IDevice if device becomes recovery before time expires. null otherwise.

waitForDeviceInRecovery

public abstract boolean waitForDeviceInRecovery (long waitTime)

Waits for the device to be in the 'adb recovery' state

Parameters
waitTime long: the maximum time in ms to wait

Returns
boolean True if the device is in Recovery before the timeout, False otherwise.

waitForDeviceInSideload

public abstract boolean waitForDeviceInSideload (long waitTime)

Waits for the device to be in the 'adb sideload' state

Parameters
waitTime long: the maximum time in ms to wait

Returns
boolean True if the device is in sideload before the timeout, False otherwise.

waitForDeviceNotAvailable

public abstract boolean waitForDeviceNotAvailable (long waitTime)

Waits for the device to be not available

Parameters
waitTime long: the maximum time in ms to wait

Returns
boolean true if device becomes unavailable

waitForDeviceOnline

public abstract IDevice waitForDeviceOnline ()

Waits for device to be online using standard boot timeout.

Note: this method will return once device is visible via DDMS. It does not guarantee that the device is actually responsive to adb commands - use waitForDeviceAvailable() instead.

Returns
IDevice the IDevice if device becomes online before time expires. null otherwise.

waitForDeviceOnline

public abstract IDevice waitForDeviceOnline (long time)

Waits for device to be online.

Note: this method will return once device is visible via DDMS. It does not guarantee that the device is actually responsive to adb commands - use waitForDeviceAvailable() instead.

Parameters
time long: the maximum time in ms to wait

Returns
IDevice the IDevice if device becomes online before time expires. null otherwise.

waitForDeviceShell

public abstract boolean waitForDeviceShell (long waitTime)

Waits for device to be responsive to a basic adb shell command.

Parameters
waitTime long: the time in ms to wait

Returns
boolean true if device becomes responsive before waitTime elapses.