NativeDeviceStateMonitor

public class NativeDeviceStateMonitor
extends Object implements IDeviceStateMonitor

java.lang.Object
   ↳ com.android.tradefed.device.NativeDeviceStateMonitor


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

static final String BOOTCOMPLETE_PROP

Constant Value: "dev.bootcomplete"

MAX_CHECK_POLL_TIME

protected static final long MAX_CHECK_POLL_TIME

Constant Value: 30000 (0x0000000000007530)

MAX_OP_TIME

protected static final int MAX_OP_TIME

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

Constant Value: 10000 (0x00002710)

PERM_DENIED_ERROR_PATTERN

protected static final String PERM_DENIED_ERROR_PATTERN

Constant Value: "Permission denied"

Public constructors

NativeDeviceStateMonitor

public NativeDeviceStateMonitor (IDeviceManager mgr, 
                IDevice device, 
                boolean fastbootEnabled)

Parameters
mgr IDeviceManager

device IDevice

fastbootEnabled boolean

Public methods

getDeviceState

public TestDeviceState getDeviceState ()

Gets the device state.

Returns
TestDeviceState the TestDeviceState of device

getMountPoint

public 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

getSerialNumber

public String getSerialNumber ()

Gets the serial number of the device.

Returns
String

isAdbTcp

public boolean isAdbTcp ()

Returns
boolean

setDefaultAvailableTimeout

public void setDefaultAvailableTimeout (long timeoutMs)

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

Parameters
timeoutMs long

setDefaultOnlineTimeout

public void setDefaultOnlineTimeout (long timeoutMs)

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

Parameters
timeoutMs long

setIDevice

public void setIDevice (IDevice newDevice)

Updates the current IDevice.

setState

public void setState (TestDeviceState deviceState)

Sets the device current state.

waitForBootComplete

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

public 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

public void waitForDeviceBootloaderStateUpdate ()

Waits for device bootloader state to be refreshed

waitForDeviceInRecovery

public 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

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

public 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

protected CollectingOutputReceiver createOutputReceiver ()

Exposed for testing

Returns
CollectingOutputReceiver CollectingOutputReceiver

getCheckPollTime

protected long getCheckPollTime ()

Exposed for testing

Returns
long

getCurrentTime

protected long getCurrentTime ()

Exposed for testing

Returns
long

getIDevice

protected IDevice getIDevice ()

Returns
IDevice IDevice associate with the state monitor

postOnlineCheck

protected 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

protected 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