NativeDeviceStateMonitor

public class NativeDeviceStateMonitor
extends Object implements IDeviceStateMonitor

java.lang.Object
   ↳ com.android.tradefed.device.NativeDeviceStateMonitor
Known Direct Subclasses
DeviceStateMonitor Helper class for monitoring the state of a IDevice


Helper class for monitoring the state of a IDevice with no framework support.

Summary

Constants

String BOOTCOMPLETE_PROP

long MAX_CHECK_POLL_TIME

int MAX_OP_TIME

the maximum operation time in ms for a 'poll for responsiveness' command

String PERM_DENIED_ERROR_PATTERN

Public constructors

NativeDeviceStateMonitor(IDeviceManager mgr, IDevice device, boolean fastbootEnabled)

Public methods

TestDeviceState getDeviceState()

Gets the device state.

String getMountPoint(String mountName)

Returns a mount point.

String getSerialNumber()

Gets the serial number of the device.

boolean isAdbTcp()

void setDefaultAvailableTimeout(long timeoutMs)

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

void setDefaultOnlineTimeout(long timeoutMs)

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

void setIDevice(IDevice newDevice)

Updates the current IDevice.

void setState(TestDeviceState deviceState)

Sets the device current state.

boolean waitForBootComplete(long waitTime)

Blocks until the device's boot complete flag is set

IDevice waitForDeviceAvailable(long waitTime)

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

IDevice waitForDeviceAvailable()

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

boolean waitForDeviceBootloader(long time)

Waits for the device to be in bootloader.

void waitForDeviceBootloaderStateUpdate()

Waits for device bootloader state to be refreshed

boolean waitForDeviceInRecovery(long waitTime)

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

boolean waitForDeviceNotAvailable(long waitTime)

Waits for the device to be not available

IDevice waitForDeviceOnline()

Waits for device to be online using standard boot timeout.

IDevice waitForDeviceOnline(long waitTime)

Waits for device to be online.

boolean waitForDeviceShell(long waitTime)

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

Protected methods

CollectingOutputReceiver createOutputReceiver()

Exposed for testing

long getCheckPollTime()

Exposed for testing

long getCurrentTime()

Exposed for testing

IDevice getIDevice()
boolean postOnlineCheck(long waitTime)

Additional checks to be done on an Online device

boolean waitForStoreMount(long waitTime)

Waits for the device's external store to be mounted.

Constants

BOOTCOMPLETE_PROP

String BOOTCOMPLETE_PROP

Constant Value: "dev.bootcomplete"

MAX_CHECK_POLL_TIME

long MAX_CHECK_POLL_TIME

Constant Value: 30000 (0x0000000000007530)

MAX_OP_TIME

int MAX_OP_TIME

the maximum operation time in ms for a 'poll for responsiveness' command

Constant Value: 10000 (0x00002710)

PERM_DENIED_ERROR_PATTERN

String PERM_DENIED_ERROR_PATTERN

Constant Value: "Permission denied"

Public constructors

NativeDeviceStateMonitor

NativeDeviceStateMonitor (IDeviceManager mgr, 
                IDevice device, 
                boolean fastbootEnabled)

Parameters
mgr IDeviceManager
device IDevice
fastbootEnabled boolean

Public methods

getDeviceState

TestDeviceState getDeviceState ()

Gets the device state.

Returns
TestDeviceState the TestDeviceState of device

getMountPoint

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 getMountPoint(String)

Parameters
mountName String: the name of the mount point
Returns
String the mount point or null

getSerialNumber

String getSerialNumber ()

Gets the serial number of the device.

Returns
String

isAdbTcp

boolean isAdbTcp ()

Returns
boolean

setDefaultAvailableTimeout

void setDefaultAvailableTimeout (long timeoutMs)

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

Parameters
timeoutMs long

setDefaultOnlineTimeout

void setDefaultOnlineTimeout (long timeoutMs)

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

Parameters
timeoutMs long

setIDevice

void setIDevice (IDevice newDevice)

Updates the current IDevice.

setState

void setState (TestDeviceState deviceState)

Sets the device current state.

waitForBootComplete

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

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

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.

waitForDeviceBootloader

boolean waitForDeviceBootloader (long time)

Waits for the device to be in bootloader.

Parameters
time long: the maximum time in ms to wait
Returns
boolean true if device is in bootloader before time expires

waitForDeviceBootloaderStateUpdate

void waitForDeviceBootloaderStateUpdate ()

Waits for device bootloader state to be refreshed

waitForDeviceInRecovery

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.

waitForDeviceNotAvailable

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

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

IDevice waitForDeviceOnline (long waitTime)

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
waitTime long: the maximum time in ms to wait
Returns
IDevice the IDevice if device becomes online before time expires. null otherwise.

waitForDeviceShell

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.

Protected methods

createOutputReceiver

CollectingOutputReceiver createOutputReceiver ()

Exposed for testing

Returns
CollectingOutputReceiver CollectingOutputReceiver

getCheckPollTime

long getCheckPollTime ()

Exposed for testing

Returns
long

getCurrentTime

long getCurrentTime ()

Exposed for testing

Returns
long

getIDevice

IDevice getIDevice ()

Returns
IDevice IDevice associate with the state monitor

postOnlineCheck

boolean postOnlineCheck (long waitTime)

Additional checks to be done on an Online device

Parameters
waitTime long: time in ms to wait before giving up
Returns
boolean true if checks are successful before waitTime expires. false otherwise

waitForStoreMount

boolean waitForStoreMount (long waitTime)

Waits for the device's external store to be mounted.

Parameters
waitTime long: time in ms to wait before giving up
Returns
boolean true if external store is mounted before waitTime expires. false otherwise