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 | |
---|---|
long |
MAX_CHECK_POLL_TIME
|
int |
MAX_OP_TIME
the maximum operation time in ms for a 'poll for responsiveness' command |
Fields | |
---|---|
protected
static
final
String |
PERM_DENIED_ERROR_PATTERN
|
Public constructors | |
---|---|
NativeDeviceStateMonitor(IDeviceManager mgr, IDevice device, boolean fastbootEnabled)
|
Public methods | |
---|---|
void
|
attachFinalState(TestDeviceState finalState)
Attach a final state to abort waitForDeviceState if reached. |
TestDeviceState
|
getDeviceState()
Gets the device state. |
String
|
getFastbootSerialNumber()
Gets the fastboot mode serial number. |
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 |
void
|
setDefaultOnlineTimeout(long timeoutMs)
Set the time in ms to wait for a device to be online in |
void
|
setFastbootSerialNumber(String serial)
Set the fastboot mode serial number. |
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. |
IDevice
|
waitForDeviceAvailableInRecoverPath(long waitTime)
Special variant of |
boolean
|
waitForDeviceBootloader(long time)
Waits for the device to be in bootloader. |
void
|
waitForDeviceBootloaderStateUpdate()
Waits for device bootloader state to be refreshed |
boolean
|
waitForDeviceFastbootd(String fastbootPath, long time)
Waits for the device to be in fastbootd. |
IDevice
|
waitForDeviceInRecovery()
Waits for the device to be in Recovery mode using standard boot timeout. |
boolean
|
waitForDeviceInRecovery(long waitTime)
Waits for the device to be in the 'adb recovery' state |
boolean
|
waitForDeviceInSideload(long waitTime)
Waits for the device to be in the 'adb sideload' 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
MAX_CHECK_POLL_TIME
protected static final long MAX_CHECK_POLL_TIME
Constant Value: 3000 (0x0000000000000bb8)
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)
Fields
PERM_DENIED_ERROR_PATTERN
protected static final String PERM_DENIED_ERROR_PATTERN
Public constructors
NativeDeviceStateMonitor
public NativeDeviceStateMonitor (IDeviceManager mgr, IDevice device, boolean fastbootEnabled)
Parameters | |
---|---|
mgr |
IDeviceManager |
device |
IDevice |
fastbootEnabled |
boolean |
Public methods
attachFinalState
public void attachFinalState (TestDeviceState finalState)
Attach a final state to abort waitForDeviceState if reached.
Parameters | |
---|---|
finalState |
TestDeviceState |
getDeviceState
public TestDeviceState getDeviceState ()
Gets the device state.
Returns | |
---|---|
TestDeviceState |
the TestDeviceState of device |
getFastbootSerialNumber
public String getFastbootSerialNumber ()
Gets the fastboot mode serial number.
Returns | |
---|---|
String |
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 |
Throws | |
---|---|
DeviceNotAvailableException |
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 |
setFastbootSerialNumber
public void setFastbootSerialNumber (String serial)
Set the fastboot mode serial number.
Parameters | |
---|---|
serial |
String |
setIDevice
public void setIDevice (IDevice newDevice)
Updates the current IDevice.
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 towaitForDeviceAvailable(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 |
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
waitForDeviceFastbootd
public boolean waitForDeviceFastbootd (String fastbootPath, long time)
Waits for the device to be in fastbootd.
Parameters | |
---|---|
fastbootPath |
String : the path of the fastboot binary to use. |
time |
long : the maximum time in ms to wait |
Returns | |
---|---|
boolean |
true if device is in fastbootd before time expires |
waitForDeviceInRecovery
public 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 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 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 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 - usewaitForDeviceAvailable()
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 - usewaitForDeviceAvailable()
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 |
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 |
Throws | |
---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
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 |
Throws | |
---|---|
DeviceNotAvailableException |