class

TestDevice

extends Object
implements IManagedTestDevice
java.lang.Object
   ↳ com.android.tradefed.device.TestDevice

Class Overview

Default implementation of a ITestDevice

Summary

Constants
String DISMISS_DIALOG_CMD the command used to dismiss a error dialog.
String LIST_PACKAGES_CMD
int MAX_RETRY_ATTEMPTS the default number of command retry attempts to perform
int NONE_RECOVERY_MODE_DELAY The time in ms to wait for a recovery that we skip because of the NONE mode
Public Methods
boolean clearErrorDialogs()
Attempt to dismiss any error dialogs currently displayed on device UI.
void clearLogcat()
Deletes any accumulated logcat data.
boolean connectToWifiNetwork(String wifiSsid, String wifiPsk)
Connects to a wifi network.
boolean connectToWifiNetworkIfNeeded(String wifiSsid, String wifiPsk)
A variant of connectToWifiNetwork(String, String) that only connects if device currently does not have network connectivity.
boolean disconnectFromWifi()
Disconnects from a wifi network.
boolean doesFileExist(String destPath)
Helper method to determine if file on device exists.
boolean enableAdbRoot()
Turns on adb root.
boolean encryptDevice(boolean inplace)
Encrypts the device.
String executeAdbCommand(String... cmdArgs)
Helper method which executes a adb command as a system command.
CommandResult executeFastbootCommand(String... cmdArgs)
Helper method which executes a fastboot command as a system command.
CommandResult executeLongFastbootCommand(String... cmdArgs)
Helper method which executes a long running fastboot command as a system command.
void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputShellResponse, int retryAttempts)
Executes a adb shell command, with more parameters to control command behavior.
String executeShellCommand(String command)
Helper method which executes a adb shell command and returns output as a String.
void executeShellCommand(String command, IShellOutputReceiver receiver)
Executes the given adb shell command, retrying multiple times if command fails.
CommandResult fastbootWipePartition(String partition)
Helper method which wipes a partition for the device.
String getBootloaderVersion()
Convenience method to get the bootloader version of this device.
InputStreamSource getBugreport()
Retrieves a bugreport from the device.
String getBuildFlavor()
Retrieve the build flavor for the device.
String getBuildId()
Retrieve the build the device is currently running.
TestDeviceState getDeviceState()
Get the device's state.
Process getEmulatorProcess()
Return the Process corresponding to this emulator.
long getExternalStoreFreeSpace()
Helper method to determine amount of free space on device external storage.
String getFastbootProductType()
Convenience method to get the product type of this device when its in fastboot mode.
String getFastbootProductVariant()
Convenience method to get the product type of this device when its in fastboot mode.
IFileEntry getFileEntry(String path)
Retrieve a reference to a remote file on device.
IDevice getIDevice()
Returns a reference to the associated ddmlib IDevice.
Set<String> getInstalledPackageNames()
Fetch the application package names present on the device.
String getIpAddress()
Gets the device's IP address.
InputStreamSource getLogcat()
Grabs a snapshot stream of the logcat data.
InputStreamSource getLogcat(int maxBytes)
Grabs a snapshot stream of the last maxBytes of captured logcat data.
InputStreamSource getLogcatDump()
Get a dump of the current logcat for device.
String getMountPoint(String mountName)
Returns a mount point.
List<ITestDevice.MountPointInfo> getMountPointInfo()
Returns a parsed version of the information in /proc/mounts on the device
ITestDevice.MountPointInfo getMountPointInfo(String mountpoint)
Returns a ITestDevice.MountPointInfo corresponding to the specified mountpoint path, or null if that path has nothing mounted or otherwise does not appear in /proc/mounts as a mountpoint.
TestDeviceOptions getOptions()
Fetch the test options for the device.
String getProductType()
Convenience method to get the product type of this device.
String getProductVariant()
Convenience method to get the product variant of this device.
String getProperty(String name)
Retrieve the given cached property value from the device.
String getPropertySync(String name)
Retrieve the given property value from the device.
ITestDevice.RecoveryMode getRecoveryMode()
Get the current recovery mode used for the device.
InputStreamSource getScreenshot()
Grabs a screenshot from the device.
String getSerialNumber()
Convenience method to get serial number of this device.
Set<String> getUninstallablePackageNames()
Fetch the application package names that can be uninstalled.
boolean getUseFastbootErase()
Get whether to use fastboot erase or fastboot format to wipe a partition on the device.
String installPackage(File packageFile, File certFile, boolean reinstall, String... extraArgs)
String installPackage(File packageFile, boolean reinstall, String... extraArgs)
Install an Android package on device.
boolean isAdbRoot()
boolean isAdbTcp()
boolean isDeviceEncrypted()
Returns if the device is encrypted.
boolean isEnableAdbRoot()
boolean isEncryptionSupported()
Returns if encryption is supported on the device.
void nonBlockingReboot()
Issues a command to reboot device and returns on command complete and when device is no longer visible to adb.
void postBootSetup()
Perform instructions to configure device for testing that after every boot.
boolean pullFile(String remoteFilePath, File localFile)
Retrieves a file off device.
File pullFile(String remoteFilePath)
Retrieves a file off device, stores it in a local temporary File, and returns that File.
File pullFileFromExternal(String remoteFilePath)
A convenience method to retrieve a file from the device's external storage, stores it in a local temporary File, and return a reference to that File.
boolean pushDir(File localFileDir, String deviceFilePath)
Recursively push directory contents to device.
boolean pushFile(File localFile, String remoteFilePath)
Push a file to device
boolean pushString(String contents, String remoteFilePath)
Push file created from a string to device
void reboot()
Reboots the device into adb mode.
void rebootIntoBootloader()
Reboots the device into bootloader mode.
void rebootIntoRecovery()
Reboots the device into adb recovery mode.
void rebootUntilOnline()
An alternate to reboot() that only blocks until device is online ie visible to adb.
void recoverDevice()
Attempts to recover device communication.
boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, Collection<ITestRunListener> listeners)
Runs instrumentation tests, and provides device recovery.
boolean runInstrumentationTests(IRemoteAndroidTestRunner runner, ITestRunListener... listeners)
Convenience method for performing runInstrumentationTests(IRemoteAndroidTestRunner, Collection) with one or listeners passed as parameters.
void setDeviceState(TestDeviceState deviceState)
Update the device's state.
void setEmulatorProcess(Process p)
Sets the Process, when this device is an emulator.
void setFastbootEnabled(boolean fastbootEnabled)
Set the fastboot option for the device.
void setIDevice(IDevice newDevice)
Update the IDevice associated with this ITestDevice.
void setOptions(TestDeviceOptions options)
Set the TestDeviceOptions for the device
void setRecovery(IDeviceRecovery recovery)
Set the IDeviceRecovery to use for this device.
void setRecoveryMode(ITestDevice.RecoveryMode mode)
Set the current recovery mode to use for the device.
void setUseFastbootErase(boolean useFastbootErase)
Set whether to use fastboot erase or fastboot format to wipe a partition on the device.
void startLogcat()
Start capturing logcat output from device in the background.
void stopLogcat()
Stop capturing logcat output from device, and discard currently saved logcat data.
String switchToAdbTcp()
Switch device to adb-over-tcp mode.
boolean switchToAdbUsb()
Switch device to adb over usb mode.
boolean syncFiles(File localFileDir, String deviceFilePath)
Incrementally syncs the contents of a local file directory to device.
boolean unencryptDevice()
Unencrypts the device.
String uninstallPackage(String packageName)
Uninstall an Android package from device.
boolean unlockDevice()
Unlocks the device if the device is in an encrypted state.
void waitForDeviceAvailable()
Waits for the device to be responsive and available for testing.
void waitForDeviceAvailable(long waitTime)
Waits for the device to be responsive and available for testing.
boolean waitForDeviceInRecovery(long waitTime)
Blocks for the device to be in the 'adb recovery' state (note this is distinct from IDeviceRecovery).
boolean waitForDeviceNotAvailable(long waitTime)
Blocks for the device to be not available ie missing from adb
void waitForDeviceOnline()
Blocks until device is visible via adb.
void waitForDeviceOnline(long waitTime)
Blocks until device is visible via adb.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.android.tradefed.device.IManagedTestDevice
From interface com.android.tradefed.device.ITestDevice

Constants

static final String DISMISS_DIALOG_CMD

the command used to dismiss a error dialog. Currently sends a DPAD_CENTER key event

Constant Value: "input keyevent 23"

static final String LIST_PACKAGES_CMD

Constant Value: "pm list packages -f"

static final int MAX_RETRY_ATTEMPTS

the default number of command retry attempts to perform

Constant Value: 2 (0x00000002)

static final int NONE_RECOVERY_MODE_DELAY

The time in ms to wait for a recovery that we skip because of the NONE mode

Constant Value: 1000 (0x000003e8)

Public Methods

public boolean clearErrorDialogs ()

Attempt to dismiss any error dialogs currently displayed on device UI.

Returns
  • true if no dialogs were present or dialogs were successfully cleared. false otherwise.

public void clearLogcat ()

Deletes any accumulated logcat data.

This is useful for cases when you want to ensure getLogcat() only returns log data produced after a certain point (such as after flashing a new device build, etc).

public boolean connectToWifiNetwork (String wifiSsid, String wifiPsk)

Connects to a wifi network.

Turns on wifi and blocks until a successful connection is made to the specified wifi network.

Parameters
wifiSsid the wifi ssid to connect to
wifiPsk PSK passphrase or null if unencrypted
Returns
  • true if connected to wifi network successfully. false otherwise

public boolean connectToWifiNetworkIfNeeded (String wifiSsid, String wifiPsk)

A variant of connectToWifiNetwork(String, String) that only connects if device currently does not have network connectivity.

Returns
  • true if connected to wifi network successfully. false otherwise

public boolean disconnectFromWifi ()

Disconnects from a wifi network.

Removes all networks from known networks list and disables wifi.

Returns
  • true if disconnected from wifi network successfully. false if disconnect failed.

public boolean doesFileExist (String destPath)

Helper method to determine if file on device exists.

Parameters
destPath the absolute path of file on device to check
Returns
  • true if file exists, false otherwise.

public boolean enableAdbRoot ()

Turns on adb root.

Enabling adb root may cause device to disconnect from adb. This method will block until device is available.

Returns
  • true if successful.

public boolean encryptDevice (boolean inplace)

Encrypts the device.

Encrypting the device may be done inplace or with a wipe. Inplace encryption will not wipe any data on the device but normally takes a couple orders of magnitude longer than the wipe.

This method will reboot the device if it is not already encrypted and will block until device is online. Also, it will not decrypt the device after the reboot. Therefore, the device might not be fully booted and/or ready to be tested when this method returns.

Parameters
inplace if the encryption process should take inplace and the device should not be wiped.
Returns
  • true if successful.
Throws
DeviceNotAvailableException
UnsupportedOperationException

public String executeAdbCommand (String... cmdArgs)

Helper method which executes a adb command as a system command.

executeShellCommand(String) should be used instead wherever possible, as that method provides better failure detection and performance.

Parameters
cmdArgs the adb command and arguments to run
Returns
  • the stdout from command. null if command failed to execute.

public CommandResult executeFastbootCommand (String... cmdArgs)

Helper method which executes a fastboot command as a system command.

Expected to be used when device is already in fastboot mode.

Parameters
cmdArgs the fastboot command and arguments to run
Returns
  • the CommandResult containing output of command
Throws
DeviceNotAvailableException
UnsupportedOperationException

public CommandResult executeLongFastbootCommand (String... cmdArgs)

Helper method which executes a long running fastboot command as a system command.

Identical to executeFastbootCommand(String) except uses a longer timeout.

Parameters
cmdArgs the fastboot command and arguments to run
Returns
  • the CommandResult containing output of command
Throws
DeviceNotAvailableException
UnsupportedOperationException

public void executeShellCommand (String command, IShellOutputReceiver receiver, int maxTimeToOutputShellResponse, int retryAttempts)

Executes a adb shell command, with more parameters to control command behavior.

Parameters
command the adb shell command to run
receiver the IShellOutputReceiver to direct shell output to.
maxTimeToOutputShellResponse the maximum amount of time during which the command is allowed to not output any response.
retryAttempts the maximum number of times to retry command if it fails due to a exception. DeviceNotResponsiveException will be thrown if retryAttempts are performed without success.

public String executeShellCommand (String command)

Helper method which executes a adb shell command and returns output as a String.

Parameters
command the adb shell command to run
Returns
  • the shell output

public void executeShellCommand (String command, IShellOutputReceiver receiver)

Executes the given adb shell command, retrying multiple times if command fails.

A simpler form of executeShellCommand(String, IShellOutputReceiver, int, int) with default values.

Parameters
command the adb shell command to run
receiver the IShellOutputReceiver to direct shell output to.

public CommandResult fastbootWipePartition (String partition)

Helper method which wipes a partition for the device.

If getUseFastbootErase() is true, then fastboot erase will be used to wipe the partition. The device must then create a filesystem the next time the device boots. Otherwise, fastboot format is used which will create a new filesystem on the device.

Expected to be used when device is already in fastboot mode.

Parameters
partition the partition to wipe
Returns
  • the CommandResult containing output of command

public String getBootloaderVersion ()

Convenience method to get the bootloader version of this device.

Will attempt to retrieve bootloader version from the device's current state. (ie if device is in fastboot mode, it will attempt to retrieve version from fastboot)

Returns
  • the String bootloader version or null if it cannot be dounf
Throws
UnsupportedOperationException
DeviceNotAvailableException

public InputStreamSource getBugreport ()

Retrieves a bugreport from the device.

The implementation of this is guaranteed to continue to work on a device without an sdcard (or where the sdcard is not yet mounted).

Returns
  • An InputStreamSource which will produce the bugreport contents on demand. In case of failure, the InputStreamSource will produce an empty InputStream.

public String getBuildFlavor ()

Retrieve the build flavor for the device.

Returns
  • the build flavor or null if it could not be retrieved

public String getBuildId ()

Retrieve the build the device is currently running.

Returns

public TestDeviceState getDeviceState ()

Get the device's state.

public Process getEmulatorProcess ()

Return the Process corresponding to this emulator.

Returns

public long getExternalStoreFreeSpace ()

Helper method to determine amount of free space on device external storage.

Returns
  • the amount of free space in KB

public String getFastbootProductType ()

Convenience method to get the product type of this device when its in fastboot mode.

This method should only be used if device should be in fastboot. Its a bit safer variant than the generic getProductType() method in this case, because ITestDevice will know to recover device into fastboot if device is in incorrect state or is unresponsive.

Returns
  • the String product type name or null if it cannot be determined
Throws
DeviceNotAvailableException
UnsupportedOperationException

public String getFastbootProductVariant ()

Convenience method to get the product type of this device when its in fastboot mode.

This method should only be used if device should be in fastboot. Its a bit safer variant than the generic getProductType() method in this case, because ITestDevice will know to recover device into fastboot if device is in incorrect state or is unresponsive.

Returns
  • the String product type name or null if it cannot be determined
Throws
DeviceNotAvailableException
UnsupportedOperationException

public IFileEntry getFileEntry (String path)

Retrieve a reference to a remote file on device.

Parameters
path the file path to retrieve. Can be an absolute path or path relative to '/'. (ie both "/system" and "system" syntax is supported)
Returns
  • the IFileEntry or null if file at given path cannot be found

public IDevice getIDevice ()

Returns a reference to the associated ddmlib IDevice.

A new IDevice may be allocated by DDMS each time the device disconnects and reconnects from adb. Thus callers should not keep a reference to the IDevice, because that reference may become stale.

Returns

public Set<String> getInstalledPackageNames ()

Fetch the application package names present on the device.

Returns
  • Set of String package names currently installed on the device.

public String getIpAddress ()

Gets the device's IP address.

Returns
  • the device's IP address, or null if device has no IP address

public InputStreamSource getLogcat ()

Grabs a snapshot stream of the logcat data.

Works in two modes:

  • If the logcat is currently being captured in the background, will return up to getMaxLogcatDataSize() bytes of the current contents of the background logcat capture
  • Otherwise, will return a static dump of the logcat data if device is currently responding

  • public InputStreamSource getLogcat (int maxBytes)

    Grabs a snapshot stream of the last maxBytes of captured logcat data.

    Useful for cases when you want to capture frequent snapshots of the captured logcat data without incurring the potentially big disk space penalty of getting the entire getLogcat() snapshot.

    Parameters
    maxBytes the maximum amount of data to return. Should be an amount that can comfortably fit in memory

    public InputStreamSource getLogcatDump ()

    Get a dump of the current logcat for device. Unlike getLogcat(), this method will always return a static dump of the logcat.

    Has the disadvantage that nothing will be returned if device is not reachable.

    Returns
    • a InputStreamSource of the logcat data. An empty stream is returned if fail to capture logcat data.

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

    Parameters
    mountName the name of the mount point
    Returns
    • the mount point or null

    public List<ITestDevice.MountPointInfo> getMountPointInfo ()

    Returns a parsed version of the information in /proc/mounts on the device

    Returns

    public ITestDevice.MountPointInfo getMountPointInfo (String mountpoint)

    Returns a ITestDevice.MountPointInfo corresponding to the specified mountpoint path, or null if that path has nothing mounted or otherwise does not appear in /proc/mounts as a mountpoint.

    Returns

    public TestDeviceOptions getOptions ()

    Fetch the test options for the device.

    Returns

    public String getProductType ()

    Convenience method to get the product type of this device.

    This method will work if device is in either adb or fastboot mode.

    Returns
    • the String product type name or null if it cannot be determined

    public String getProductVariant ()

    Convenience method to get the product variant of this device.

    This method will work if device is in either adb or fastboot mode.

    Returns
    • the String product variant name or null if it cannot be determined

    public String getProperty (String name)

    Retrieve the given cached property value from the device.

    Note this method should only be used for read-only properties that won't change after device comes online. For volatile properties, use getPropertySync(String)

    Parameters
    name the property name
    Returns
    • the property value or null if it does not exist

    public String getPropertySync (String name)

    Retrieve the given property value from the device.

    Note this method performs a live query against device. Its recommended to use getProperty(String) instead for read-only properties.

    Parameters
    name the property name
    Returns
    • the property value or null if it does not exist

    public ITestDevice.RecoveryMode getRecoveryMode ()

    Get the current recovery mode used for the device.

    Returns
    • the current recovery mode used for the device.

    public InputStreamSource getScreenshot ()

    Grabs a screenshot from the device.

    Returns
    • a InputStreamSource of the screenshot in png format, or null if the screenshot was not successful.

    public String getSerialNumber ()

    Convenience method to get serial number of this device.

    Returns

    public Set<String> getUninstallablePackageNames ()

    Fetch the application package names that can be uninstalled. This is presently defined as non-system packages, and updated system packages.

    Returns
    • Set of uninstallable String package names currently installed on the device.

    public boolean getUseFastbootErase ()

    Get whether to use fastboot erase or fastboot format to wipe a partition on the device.

    Returns
    • true if fastboot erase will be used or false if fastboot format will be used.

    public String installPackage (File packageFile, File certFile, boolean reinstall, String... extraArgs)

    public String installPackage (File packageFile, boolean reinstall, String... extraArgs)

    Install an Android package on device.

    Parameters
    packageFile the apk file to install
    reinstall true if a reinstall should be performed
    extraArgs optional extra arguments to pass. See 'adb shell pm install --help' for available options.
    Returns
    • a String with an error code, or null if success.

    public boolean isAdbRoot ()

    public boolean isAdbTcp ()

    public boolean isDeviceEncrypted ()

    Returns if the device is encrypted.

    Returns
    • true if the device is encrypted.

    public boolean isEnableAdbRoot ()

    Returns
    • true if adb root should be enabled on device

    public boolean isEncryptionSupported ()

    Returns if encryption is supported on the device.

    Returns
    • true if the device supports encryption.

    public void nonBlockingReboot ()

    Issues a command to reboot device and returns on command complete and when device is no longer visible to adb.

    public void postBootSetup ()

    Perform instructions to configure device for testing that after every boot.

    Should be called after device is fully booted/available

    In normal circumstances this method doesn't need to be called explicitly, as implementations should perform these steps automatically when performing a reboot.

    Where it may need to be called is when device reboots due to other events (eg when a fastboot update command has completed)

    public boolean pullFile (String remoteFilePath, File localFile)

    Retrieves a file off device.

    Parameters
    remoteFilePath the absolute path to file on device.
    localFile the local file to store contents in. If non-empty, contents will be replaced.
    Returns
    • true if file was retrieved successfully. false otherwise.

    public File pullFile (String remoteFilePath)

    Retrieves a file off device, stores it in a local temporary File, and returns that File.

    Parameters
    remoteFilePath the absolute path to file on device.
    Returns
    • A File containing the contents of the device file, or null if the copy failed for any reason (including problems with the host filesystem)

    public File pullFileFromExternal (String remoteFilePath)

    A convenience method to retrieve a file from the device's external storage, stores it in a local temporary File, and return a reference to that File.

    Parameters
    remoteFilePath the path to file on device, relative to the device's external storage mountpoint
    Returns
    • A File containing the contents of the device file, or null if the copy failed for any reason (including problems with the host filesystem)

    public boolean pushDir (File localFileDir, String deviceFilePath)

    Recursively push directory contents to device.

    Parameters
    localFileDir the local directory to push
    deviceFilePath the absolute file path of the remote destination
    Returns
    • true if file was pushed successfully. false otherwise.

    public boolean pushFile (File localFile, String remoteFilePath)

    Push a file to device

    Parameters
    localFile the local file to push
    remoteFilePath the remote destination absolute file path
    Returns
    • true if file was pushed successfully. false otherwise.

    public boolean pushString (String contents, String remoteFilePath)

    Push file created from a string to device

    Parameters
    contents the contents of the file to push
    remoteFilePath the remote destination absolute file path
    Returns
    • true if string was pushed successfully. false otherwise.

    public void reboot ()

    Reboots the device into adb mode.

    Blocks until device becomes available.

    public void rebootIntoBootloader ()

    Reboots the device into bootloader mode.

    Blocks until device is in bootloader mode.

    Throws
    DeviceNotAvailableException
    UnsupportedOperationException

    public void rebootIntoRecovery ()

    Reboots the device into adb recovery mode.

    Blocks until device enters recovery

    public void rebootUntilOnline ()

    An alternate to reboot() that only blocks until device is online ie visible to adb.

    public void recoverDevice ()

    Attempts to recover device communication.

    Throws
    DeviceNotAvailableException if device is not longer available

    public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, Collection<ITestRunListener> listeners)

    Runs instrumentation tests, and provides device recovery.

    If connection with device is lost before test run completes, and recovery succeeds, all listeners will be informed of testRunFailed and "false" will be returned. The test command will not be rerun.. It is left to callers to retry if necessary.

    If connection with device is lost before test run completes, and recovery fails, all listeners will be informed of testRunFailed and DeviceNotAvailableException will be thrown.

    Parameters
    runner the IRemoteAndroidTestRunner which runs the tests
    listeners the test result listeners
    Returns
    • true if test command completed. false if it failed to complete due to device communication exception, but recovery succeeded

    public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner, ITestRunListener... listeners)

    Convenience method for performing runInstrumentationTests(IRemoteAndroidTestRunner, Collection) with one or listeners passed as parameters.

    Parameters
    runner the IRemoteAndroidTestRunner which runs the tests
    listeners the test result listener(s)
    Returns
    • true if test command completed. false if it failed to complete, but recovery succeeded

    public void setDeviceState (TestDeviceState deviceState)

    Update the device's state.

    Parameters
    deviceState the TestDeviceState

    public void setEmulatorProcess (Process p)

    Sets the Process, when this device is an emulator.

    public void setFastbootEnabled (boolean fastbootEnabled)

    Set the fastboot option for the device. Should be set when device is first allocated.

    Parameters
    fastbootEnabled whether fastboot is available for the device or not

    public void setIDevice (IDevice newDevice)

    Update the IDevice associated with this ITestDevice.

    The new IDevice must refer the same physical device as the current reference. This method will be called if DDMS has allocated a new IDevice

    Parameters
    newDevice the IDevice

    public void setOptions (TestDeviceOptions options)

    Set the TestDeviceOptions for the device

    public void setRecovery (IDeviceRecovery recovery)

    Set the IDeviceRecovery to use for this device. Should be set when device is first allocated.

    Parameters
    recovery the IDeviceRecovery

    public void setRecoveryMode (ITestDevice.RecoveryMode mode)

    Set the current recovery mode to use for the device.

    Used to control what recovery method to use when a device communication problem is encountered. Its recommended to only use this method sparingly when needed (for example, when framework is down, etc

    Parameters
    mode whether 'recover till online only' mode should be on or not.

    public void setUseFastbootErase (boolean useFastbootErase)

    Set whether to use fastboot erase or fastboot format to wipe a partition on the device.

    Parameters
    useFastbootErase true if fastboot erase should be used or false if fastboot format should be used.

    public void startLogcat ()

    Start capturing logcat output from device in the background.

    Will have no effect if logcat output is already being captured. Data can be later retrieved via getLogcat.

    When the device is no longer in use, stopLogcat() must be called.

    public void stopLogcat ()

    Stop capturing logcat output from device, and discard currently saved logcat data.

    Will have no effect if logcat output is not being captured.

    public String switchToAdbTcp ()

    Switch device to adb-over-tcp mode.

    Returns
    • the tcp serial number or null if device could not be switched

    public boolean switchToAdbUsb ()

    Switch device to adb over usb mode.

    Returns
    • true if switch was successful, false otherwise.

    public boolean syncFiles (File localFileDir, String deviceFilePath)

    Incrementally syncs the contents of a local file directory to device.

    Decides which files to push by comparing timestamps of local files with their remote equivalents. Only 'newer' or non-existent files will be pushed to device. Thus overhead should be relatively small if file set on device is already up to date.

    Hidden files (with names starting with ".") will be ignored.

    Example usage: syncFiles("/tmp/files", "/sdcard") will created a /sdcard/files directory if it doesn't already exist, and recursively push the /tmp/files contents to /sdcard/files.

    Parameters
    localFileDir the local file directory containing files to recursively push.
    deviceFilePath the remote destination absolute file path root. All directories in thos file path must be readable. ie pushing to /data/local/tmp when adb is not root will fail
    Returns
    • true if files were synced successfully. false otherwise.

    public boolean unencryptDevice ()

    Unencrypts the device.

    Unencrypting the device may cause device to be wiped and may reboot device. This method will block until device is available and ready for testing. Requires fastboot inorder to wipe the userdata partition.

    Returns
    • true if successful.
    Throws
    DeviceNotAvailableException
    UnsupportedOperationException

    public String uninstallPackage (String packageName)

    Uninstall an Android package from device.

    Parameters
    packageName the Android package to uninstall
    Returns
    • a String with an error code, or null if success.

    public boolean unlockDevice ()

    Unlocks the device if the device is in an encrypted state.

    This method may restart the framework but will not call postBootSetup(). Therefore, the device might not be fully ready to be tested when this method returns.

    Returns
    • true if successful or if the device is unencrypted.
    Throws
    DeviceNotAvailableException
    UnsupportedOperationException

    public void waitForDeviceAvailable ()

    Waits for the device to be responsive and available for testing. Uses default timeout.

    public void waitForDeviceAvailable (long waitTime)

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

    Parameters
    waitTime the time in ms to wait

    public boolean waitForDeviceInRecovery (long waitTime)

    Blocks for the device to be in the 'adb recovery' state (note this is distinct from IDeviceRecovery).

    Parameters
    waitTime the time in ms to wait
    Returns
    • true if device boots into recovery before time expires. false otherwise

    public boolean waitForDeviceNotAvailable (long waitTime)

    Blocks for the device to be not available ie missing from adb

    Parameters
    waitTime the time in ms to wait
    Returns
    • true if device becomes not available before time expires. false otherwise

    public void waitForDeviceOnline ()

    Blocks until device is visible via adb. Uses default timeout

    Note the device may not necessarily be responsive to commands on completion. Use waitForDeviceAvailable() instead.

    public void waitForDeviceOnline (long waitTime)

    Blocks until device is visible via adb.

    Note the device may not necessarily be responsive to commands on completion. Use waitForDeviceAvailable() instead.

    Parameters
    waitTime the time in ms to wait