executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
void
executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeoutForCommand, long maxTimeToOutputShellResponse, TimeUnit timeUnit, int retryAttempts)
Fetch a device property, from the ddmlib cache by default, and falling back to either `adb
shell getprop` or `fastboot getvar` depending on whether the device is in Fastboot or not.
IDeviceMonitor: the IDeviceMonitor to inform of allocation state changes.
Can be null
Public methods
checkApiLevelAgainstNextRelease
public boolean checkApiLevelAgainstNextRelease (int strictMinLevel)
Parameters
strictMinLevel
int
Returns
boolean
Throws
DeviceNotAvailableException
checkConnectivity
public boolean checkConnectivity ()
Returns
boolean
Throws
DeviceNotAvailableException
clearErrorDialogs
public boolean clearErrorDialogs ()
Returns
boolean
Throws
DeviceNotAvailableException
clearLastConnectedWifiNetwork
public void clearLastConnectedWifiNetwork ()
clearLogcat
public void clearLogcat ()
connectToWifiNetwork
public boolean connectToWifiNetwork (String wifiSsid,
String wifiPsk)
Parameters
wifiSsid
String
wifiPsk
String
Returns
boolean
Throws
DeviceNotAvailableException
connectToWifiNetwork
public boolean connectToWifiNetwork (String wifiSsid,
String wifiPsk,
boolean scanSsid)
Parameters
wifiSsid
String
wifiPsk
String
scanSsid
boolean
Returns
boolean
Throws
DeviceNotAvailableException
connectToWifiNetworkIfNeeded
public boolean connectToWifiNetworkIfNeeded (String wifiSsid,
String wifiPsk,
boolean scanSsid)
Parameters
wifiSsid
String
wifiPsk
String
scanSsid
boolean
Returns
boolean
Throws
DeviceNotAvailableException
connectToWifiNetworkIfNeeded
public boolean connectToWifiNetworkIfNeeded (String wifiSsid,
String wifiPsk)
Parameters
wifiSsid
String
wifiPsk
String
Returns
boolean
Throws
DeviceNotAvailableException
createUser
public int createUser (String name,
boolean guest,
boolean ephemeral)
Parameters
name
String
guest
boolean
ephemeral
boolean
Returns
int
Throws
DeviceNotAvailableException
createUser
public int createUser (String name)
Parameters
name
String
Returns
int
Throws
DeviceNotAvailableException
createUserNoThrow
public int createUserNoThrow (String name)
Parameters
name
String
Returns
int
Throws
DeviceNotAvailableException
deleteFile
public void deleteFile (String deviceFilePath)
Parameters
deviceFilePath
String
Throws
DeviceNotAvailableException
deviceSoftRestarted
public boolean deviceSoftRestarted (ProcessInfo prevSystemServerProcess)
Parameters
prevSystemServerProcess
ProcessInfo
Returns
boolean
Throws
DeviceNotAvailableException
deviceSoftRestartedSince
public boolean deviceSoftRestartedSince (long utcEpochTime,
TimeUnit timeUnit)
Parameters
utcEpochTime
long
timeUnit
TimeUnit
Returns
boolean
Throws
DeviceNotAvailableException
disableAdbRoot
public boolean disableAdbRoot ()
Returns
boolean
Throws
DeviceNotAvailableException
disableKeyguard
public void disableKeyguard ()
Throws
DeviceNotAvailableException
disableNetworkMonitor
public boolean disableNetworkMonitor ()
Returns
boolean
Throws
DeviceNotAvailableException
disconnectFromWifi
public boolean disconnectFromWifi ()
Returns
boolean
Throws
DeviceNotAvailableException
doesFileExist
public boolean doesFileExist (String deviceFilePath)
Parameters
deviceFilePath
String
Returns
boolean
Throws
DeviceNotAvailableException
dumpHeap
public File dumpHeap (String process,
String devicePath)
Parameters
process
String
devicePath
String
Returns
File
Throws
DeviceNotAvailableException
enableAdbRoot
public boolean enableAdbRoot ()
Returns
boolean
Throws
DeviceNotAvailableException
enableNetworkMonitor
public boolean enableNetworkMonitor ()
Returns
boolean
Throws
DeviceNotAvailableException
encryptDevice
public boolean encryptDevice (boolean inplace)
Parameters
inplace
boolean
Returns
boolean
Throws
DeviceNotAvailableException
executeAdbCommand
public String executeAdbCommand (long timeout,
String... cmdArgs)
Parameters
timeout
long
cmdArgs
String
Returns
String
Throws
DeviceNotAvailableException
executeAdbCommand
public String executeAdbCommand (String... cmdArgs)
Parameters
cmdArgs
String
Returns
String
Throws
DeviceNotAvailableException
executeFastbootCommand
public CommandResult executeFastbootCommand (String... cmdArgs)
Parameters
cmdArgs
String
Returns
CommandResult
Throws
DeviceNotAvailableException
executeFastbootCommand
public CommandResult executeFastbootCommand (long timeout,
String... cmdArgs)
Parameters
timeout
long
cmdArgs
String
Returns
CommandResult
Throws
DeviceNotAvailableException
executeLongFastbootCommand
public CommandResult executeLongFastbootCommand (String... cmdArgs)
Parameters
cmdArgs
String
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellCommand
public String executeShellCommand (String command)
Parameters
command
String
Returns
String
Throws
DeviceNotAvailableException
executeShellCommand
public void executeShellCommand (String command,
IShellOutputReceiver receiver,
long maxTimeToOutputShellResponse,
TimeUnit timeUnit,
int retryAttempts)
Parameters
command
String
receiver
IShellOutputReceiver
maxTimeToOutputShellResponse
long
timeUnit
TimeUnit
retryAttempts
int
Throws
DeviceNotAvailableException
executeShellCommand
public void executeShellCommand (String command,
IShellOutputReceiver receiver,
long maxTimeoutForCommand,
long maxTimeToOutputShellResponse,
TimeUnit timeUnit,
int retryAttempts)
Parameters
command
String
receiver
IShellOutputReceiver
maxTimeoutForCommand
long
maxTimeToOutputShellResponse
long
timeUnit
TimeUnit
retryAttempts
int
Throws
DeviceNotAvailableException
executeShellCommand
public void executeShellCommand (String command,
IShellOutputReceiver receiver)
Parameters
command
String
receiver
IShellOutputReceiver
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd)
Parameters
cmd
String
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
OutputStream pipeToOutput)
Parameters
cmd
String
pipeToOutput
OutputStream
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
File pipeAsInput)
Parameters
cmd
String
pipeAsInput
File
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
long maxTimeoutForCommand,
TimeUnit timeUnit,
int retryAttempts)
Parameters
cmd
String
maxTimeoutForCommand
long
timeUnit
TimeUnit
retryAttempts
int
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
long maxTimeoutForCommand,
TimeUnit timeUnit)
Parameters
cmd
String
maxTimeoutForCommand
long
timeUnit
TimeUnit
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
File pipeAsInput,
OutputStream pipeToOutput,
long maxTimeoutForCommand,
TimeUnit timeUnit,
int retryAttempts)
Parameters
cmd
String
pipeAsInput
File
pipeToOutput
OutputStream
maxTimeoutForCommand
long
timeUnit
TimeUnit
retryAttempts
int
Returns
CommandResult
Throws
DeviceNotAvailableException
executeShellV2Command
public CommandResult executeShellV2Command (String cmd,
File pipeAsInput,
OutputStream pipeToOutput,
OutputStream pipeToError,
long maxTimeoutForCommand,
TimeUnit timeUnit,
int retryAttempts)
Parameters
cmd
String
pipeAsInput
File
pipeToOutput
OutputStream
pipeToError
OutputStream
maxTimeoutForCommand
long
timeUnit
TimeUnit
retryAttempts
int
Returns
CommandResult
Throws
DeviceNotAvailableException
fastbootWipePartition
public CommandResult fastbootWipePartition (String partition)
Parameters
partition
String
Returns
CommandResult
Throws
DeviceNotAvailableException
getActiveApexes
public getActiveApexes ()
Returns
Throws
DeviceNotAvailableException
getAllSettings
public getAllSettings (String namespace)
Parameters
namespace
String
Returns
Throws
DeviceNotAvailableException
getAllocationState
public DeviceAllocationState getAllocationState ()
Returns
DeviceAllocationState
getAndroidId
public String getAndroidId (int userId)
Parameters
userId
int
Returns
String
Throws
DeviceNotAvailableException
getAndroidIds
public getAndroidIds ()
Returns
Throws
DeviceNotAvailableException
getApiLevel
public int getApiLevel ()
Returns
int
Throws
DeviceNotAvailableException
getAppPackageInfo
public PackageInfo getAppPackageInfo (String packageName)
Parameters
packageName
String
Returns
PackageInfo
Throws
DeviceNotAvailableException
getAppPackageInfos
public getAppPackageInfos ()
Returns
Throws
DeviceNotAvailableException
getBasebandVersion
public String getBasebandVersion ()
Returns
String
Throws
DeviceNotAvailableException
getBattery
public Integer getBattery ()
Returns
Integer
getBooleanProperty
public boolean getBooleanProperty (String name,
boolean defaultValue)
Parameters
name
String
defaultValue
boolean
Returns
boolean
Throws
DeviceNotAvailableException
getBootHistory
public getBootHistory ()
Returns
Throws
DeviceNotAvailableException
getBootHistorySince
public getBootHistorySince (long utcEpochTime,
TimeUnit timeUnit)
Parameters
utcEpochTime
long
timeUnit
TimeUnit
Returns
Throws
DeviceNotAvailableException
getBootloaderVersion
public String getBootloaderVersion ()
Returns
String
Throws
DeviceNotAvailableException
getBugreport
public InputStreamSource getBugreport ()
Returns
InputStreamSource
getBugreportz
public InputStreamSource getBugreportz ()
Returns
InputStreamSource
getBuildAlias
public String getBuildAlias ()
Returns
String
Throws
DeviceNotAvailableException
getBuildFlavor
public String getBuildFlavor ()
Returns
String
Throws
DeviceNotAvailableException
getBuildId
public String getBuildId ()
Returns
String
Throws
DeviceNotAvailableException
getBuildSigningKeys
public String getBuildSigningKeys ()
Returns
String
Throws
DeviceNotAvailableException
getCachedDeviceDescriptor
public DeviceDescriptor getCachedDeviceDescriptor ()
Returns
DeviceDescriptor
getChildren
public String[] getChildren (String path)
Parameters
path
String
Returns
String[]
Throws
DeviceNotAvailableException
getCurrentFoldableState
public DeviceFoldableState getCurrentFoldableState ()
public String installPackageForUser (File packageFile,
boolean reinstall,
int userId,
String... extraArgs)
Parameters
packageFile
File
reinstall
boolean
userId
int
extraArgs
String
Returns
String
Throws
DeviceNotAvailableException
installPackageForUser
public String installPackageForUser (File packageFile,
boolean reinstall,
boolean grantPermissions,
int userId,
String... extraArgs)
Parameters
packageFile
File
reinstall
boolean
grantPermissions
boolean
userId
int
extraArgs
String
Returns
String
Throws
DeviceNotAvailableException
isAdbRoot
public boolean isAdbRoot ()
Returns
boolean
Throws
DeviceNotAvailableException
isAdbTcp
public boolean isAdbTcp ()
Returns
boolean
isAppEnumerationSupported
public boolean isAppEnumerationSupported ()
Returns
boolean
Throws
DeviceNotAvailableException
isDeviceEncrypted
public boolean isDeviceEncrypted ()
Returns
boolean
Throws
DeviceNotAvailableException
isDirectory
public boolean isDirectory (String path)
Parameters
path
String
Returns
boolean
Throws
DeviceNotAvailableException
isEnableAdbRoot
public boolean isEnableAdbRoot ()
Returns
boolean
true if adb root should be enabled on device
isEncryptionSupported
public boolean isEncryptionSupported ()
Returns
boolean
Throws
DeviceNotAvailableException
isExecutable
public boolean isExecutable (String fullPath)
Parameters
fullPath
String
Returns
boolean
Throws
DeviceNotAvailableException
isFastbootEnabled
public boolean isFastbootEnabled ()
Returns
boolean
isHeadless
public boolean isHeadless ()
Returns
boolean
Throws
DeviceNotAvailableException
isMultiUserSupported
public boolean isMultiUserSupported ()
Returns
boolean
Throws
DeviceNotAvailableException
isPackageInstalled
public boolean isPackageInstalled (String packageName,
String userId)
Parameters
packageName
String
userId
String
Returns
boolean
Throws
DeviceNotAvailableException
isPackageInstalled
public boolean isPackageInstalled (String packageName)
Parameters
packageName
String
Returns
boolean
Throws
DeviceNotAvailableException
isRuntimePermissionSupported
public boolean isRuntimePermissionSupported ()
Returns
boolean
Throws
DeviceNotAvailableException
isStateBootloaderOrFastbootd
public boolean isStateBootloaderOrFastbootd ()
Returns
boolean
isUserRunning
public boolean isUserRunning (int userId)
Parameters
userId
int
Returns
boolean
Throws
DeviceNotAvailableException
isUserSecondary
public boolean isUserSecondary (int userId)
Parameters
userId
int
Returns
boolean
Throws
DeviceNotAvailableException
isWifiEnabled
public boolean isWifiEnabled ()
Returns
boolean
Throws
DeviceNotAvailableException
listDisplayIds
public listDisplayIds ()
Returns
Throws
DeviceNotAvailableException
listUsers
public listUsers ()
Returns
Throws
DeviceNotAvailableException
logBugreport
public boolean logBugreport (String dataName,
ITestLogger listener)
Parameters
dataName
String
listener
ITestLogger
Returns
boolean
logOnDevice
public void logOnDevice (String tag,
Log.LogLevel level,
String format,
Object... args)
Parameters
tag
String
level
Log.LogLevel
format
String
args
Object
nonBlockingReboot
public void nonBlockingReboot ()
Throws
DeviceNotAvailableException
postAdbRootAction
public void postAdbRootAction ()
Override if the device needs some specific actions to be taken after adb root and before the
device is back online.
Default implementation doesn't include any addition actions.
adb root is not guaranteed to be enabled at this stage.
Throws
DeviceNotAvailableException
postAdbUnrootAction
public void postAdbUnrootAction ()
Override if the device needs some specific actions to be taken after adb unroot and before
the device is back online.
Default implementation doesn't include any additional actions.
adb root is not guaranteed to be disabled at this stage.
Throws
DeviceNotAvailableException
postBootSetup
public void postBootSetup ()
Throws
DeviceNotAvailableException
postInvocationTearDown
public void postInvocationTearDown (Throwable exception)
Parameters
exception
Throwable
preInvocationSetup
public void preInvocationSetup (IBuildInfo info,
MultiMap<String, String> attributes)
Parameters
info
IBuildInfo
attributes
MultiMap
Throws
DeviceNotAvailableException
TargetSetupError
pullDir
public boolean pullDir (String deviceFilePath,
File localDir)
Parameters
deviceFilePath
String
localDir
File
Returns
boolean
Throws
DeviceNotAvailableException
pullFile
public boolean pullFile (String remoteFilePath,
File localFile)
Parameters
remoteFilePath
String
localFile
File
Returns
boolean
Throws
DeviceNotAvailableException
pullFile
public File pullFile (String remoteFilePath)
Parameters
remoteFilePath
String
Returns
File
Throws
DeviceNotAvailableException
pullFileContents
public String pullFileContents (String remoteFilePath)
Parameters
remoteFilePath
String
Returns
String
Throws
DeviceNotAvailableException
pullFileFromExternal
public File pullFileFromExternal (String remoteFilePath)
Parameters
remoteFilePath
String
Returns
File
Throws
DeviceNotAvailableException
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath,
excludedDirectories)
Parameters
localFileDir
File
deviceFilePath
String
excludedDirectories
Returns
boolean
Throws
DeviceNotAvailableException
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath)
Parameters
localFileDir
File
deviceFilePath
String
Returns
boolean
Throws
DeviceNotAvailableException
pushFile
public boolean pushFile (File localFile,
String remoteFilePath)
Parameters
localFile
File
remoteFilePath
String
Returns
boolean
Throws
DeviceNotAvailableException
pushString
public boolean pushString (String contents,
String remoteFilePath)
Parameters
contents
String
remoteFilePath
String
Returns
boolean
Throws
DeviceNotAvailableException
reboot
public void reboot (String reason)
Parameters
reason
String
Throws
DeviceNotAvailableException
reboot
public void reboot ()
Throws
DeviceNotAvailableException
rebootIntoBootloader
public void rebootIntoBootloader ()
Throws
DeviceNotAvailableException
rebootIntoFastbootd
public void rebootIntoFastbootd ()
Throws
DeviceNotAvailableException
rebootIntoRecovery
public void rebootIntoRecovery ()
Throws
DeviceNotAvailableException
rebootIntoSideload
public void rebootIntoSideload ()
Throws
DeviceNotAvailableException
rebootIntoSideload
public void rebootIntoSideload (boolean autoReboot)
Parameters
autoReboot
boolean
Throws
DeviceNotAvailableException
rebootUntilOnline
public void rebootUntilOnline ()
Throws
DeviceNotAvailableException
rebootUntilOnline
public void rebootUntilOnline (String reason)
Parameters
reason
String
Throws
DeviceNotAvailableException
rebootUserspace
public void rebootUserspace ()
Throws
DeviceNotAvailableException
rebootUserspaceUntilOnline
public void rebootUserspaceUntilOnline ()
Throws
DeviceNotAvailableException
recoverDevice
public void recoverDevice ()
Attempts to recover device communication.
Throws
DeviceNotAvailableException
if device is no longer available
remountSystemWritable
public void remountSystemWritable ()
Throws
DeviceNotAvailableException
remountVendorWritable
public void remountVendorWritable ()
Throws
DeviceNotAvailableException
removeAdmin
public boolean removeAdmin (String componentName,
int userId)
Parameters
componentName
String
userId
int
Returns
boolean
Throws
DeviceNotAvailableException
removeOwners
public void removeOwners ()
Throws
DeviceNotAvailableException
removeUser
public boolean removeUser (int userId)
Parameters
userId
int
Returns
boolean
Throws
DeviceNotAvailableException
resetContentProviderSetup
public void resetContentProviderSetup ()
Reset the flag for content provider setup in order to trigger it again.
runInstrumentationTests
public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner,
ITestLifeCycleReceiver... listeners)
Parameters
runner
IRemoteAndroidTestRunner
listeners
ITestLifeCycleReceiver
Returns
boolean
Throws
DeviceNotAvailableException
runInstrumentationTests
public boolean runInstrumentationTests (IRemoteAndroidTestRunner runner,
listeners)
Parameters
runner
IRemoteAndroidTestRunner
listeners
Returns
boolean
Throws
DeviceNotAvailableException
runInstrumentationTestsAsUser
public boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner,
int userId,
ITestLifeCycleReceiver... listeners)
Parameters
runner
IRemoteAndroidTestRunner
userId
int
listeners
ITestLifeCycleReceiver
Returns
boolean
Throws
DeviceNotAvailableException
runInstrumentationTestsAsUser
public boolean runInstrumentationTestsAsUser (IRemoteAndroidTestRunner runner,
int userId,
listeners)
Parameters
runner
IRemoteAndroidTestRunner
userId
int
listeners
Returns
boolean
Throws
DeviceNotAvailableException
setConfiguration
public void setConfiguration (IConfiguration configuration)
Fetch a device property, from the ddmlib cache by default, and falling back to either `adb
shell getprop` or `fastboot getvar` depending on whether the device is in Fastboot or not.
Parameters
propName
String: The name of the device property as returned by `adb shell getprop`
fastbootVar
String: The name of the equivalent fastboot variable to query. if null,
fastboot query will not be attempted
description
String: A simple description of the variable. First letter should be capitalized.
Returns
String
A string, possibly null or empty, containing the value of the given property
Return true if local file is newer than remote file. IFileEntry being
accurate to the minute, in case of equal times, the file will be considered newer.
Parameters
localFile
File
entry
IFileEntry
Returns
boolean
performDeviceAction
protected boolean performDeviceAction (String actionDescription,
com.android.tradefed.device.NativeDevice.DeviceAction action,
int retryAttempts)
Performs an action on this device. Attempts to recover device and optionally retry command
if action fails.
Parameters
actionDescription
String: a short description of action to be performed. Used for logging
purposes only.
action
com.android.tradefed.device.NativeDevice.DeviceAction: the action to be performed
retryAttempts
int: the retry attempts to make for action if it fails but
recovery succeeds
Returns
boolean
true if action was performed successfully
Throws
DeviceNotAvailableException
if recovery attempt fails or max attempts done without
success
postAdbReboot
protected void postAdbReboot ()
Possible extra actions that can be taken after a reboot.
Throws
DeviceNotAvailableException
prePostBootSetup
protected void prePostBootSetup ()
Allows each device type (AndroidNativeDevice, TestDevice) to override this method for
specific post boot setup.
Throws
DeviceNotAvailableException
setClock
protected void setClock (Clock clock)
Set the Clock instance to use.
Parameters
clock
Clock
setLogStartDelay
protected void setLogStartDelay (int delay)
Sets the time in ms to wait before starting logcat capture for a online device.
Parameters
delay
int: the delay in ms
waitForDeviceNotAvailable
protected void waitForDeviceNotAvailable (String operationDesc,
long time)
Parameters
operationDesc
String
time
long
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-07-06 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]