Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
Stay organized with collections
Save and categorize content based on your preferences.
TestDevice
public
class
TestDevice
extends NativeDevice
Known indirect subclasses
|
Implementation of a ITestDevice
for a full stack android device
Summary
Fields |
public
static
final
String |
DISMISS_KEYGUARD_CMD
Commands that can be used to dismiss the keyguard.
|
Public methods |
boolean
|
clearErrorDialogs()
|
int
|
createUser(String name)
|
int
|
createUser(String name, boolean guest, boolean ephemeral)
|
int
|
createUserNoThrow(String name)
|
void
|
disableKeyguard()
|
boolean
|
doesFileExist(String deviceFilePath)
|
File
|
dumpHeap(String process, String devicePath)
|
|
getActiveApexes()
|
|
getAllSettings(String namespace)
|
String
|
getAndroidId(int userId)
|
|
getAndroidIds()
|
PackageInfo
|
getAppPackageInfo(String packageName)
|
|
getAppPackageInfos()
|
DeviceFoldableState
|
getCurrentFoldableState()
|
int
|
getCurrentUser()
|
|
getFoldableStates()
|
|
getInstalledPackageNames()
|
KeyguardControllerState
|
getKeyguardState()
|
|
getMainlineModuleInfo()
|
int
|
getMaxNumberOfRunningUsersSupported()
|
int
|
getMaxNumberOfUsersSupported()
|
Integer
|
getPrimaryUserId()
|
InputStreamSource
|
getScreenshot()
|
InputStreamSource
|
getScreenshot(String format, boolean rescale)
|
InputStreamSource
|
getScreenshot(String format)
|
InputStreamSource
|
getScreenshot(long displayId)
|
String
|
getSetting(String namespace, String key)
|
String
|
getSetting(int userId, String namespace, String key)
|
|
getUninstallablePackageNames()
|
int
|
getUserFlags(int userId)
|
|
getUserInfos()
|
int
|
getUserSerialNumber(int userId)
|
boolean
|
hasFeature(String feature)
|
String
|
installPackage(File packageFile, boolean reinstall, String... extraArgs)
|
String
|
installPackage(File packageFile, File certFile, boolean reinstall, String... extraArgs)
|
String
|
installPackage(File packageFile, boolean reinstall, boolean grantPermissions, String... extraArgs)
|
String
|
installPackageForUser(File packageFile, boolean reinstall, boolean grantPermissions, int userId, String... extraArgs)
|
String
|
installPackageForUser(File packageFile, boolean reinstall, int userId, String... extraArgs)
|
String
|
installPackages( packageFiles, boolean reinstall, String... extraArgs)
|
String
|
installPackages( packageFiles, boolean reinstall, boolean grantPermissions, String... extraArgs)
|
String
|
installPackagesForUser( packageFiles, boolean reinstall, boolean grantPermissions, int userId, String... extraArgs)
|
String
|
installPackagesForUser( packageFiles, boolean reinstall, int userId, String... extraArgs)
|
String
|
installRemotePackages( remoteApkPaths, boolean reinstall, boolean grantPermissions, String... extraArgs)
|
String
|
installRemotePackages( remoteApkPaths, boolean reinstall, String... extraArgs)
|
boolean
|
isAppEnumerationSupported()
|
boolean
|
isMultiUserSupported()
|
boolean
|
isPackageInstalled(String packageName)
|
boolean
|
isPackageInstalled(String packageName, String userId)
|
boolean
|
isUserRunning(int userId)
|
boolean
|
isUserSecondary(int userId)
|
|
listDisplayIds()
|
|
listUsers()
|
void
|
postInvocationTearDown(Throwable exception)
|
boolean
|
removeAdmin(String componentName, int userId)
|
void
|
removeOwners()
|
boolean
|
removeUser(int userId)
|
boolean
|
setDeviceOwner(String componentName, int userId)
|
void
|
setSetting(String namespace, String key, String value)
|
void
|
setSetting(int userId, String namespace, String key, String value)
|
boolean
|
startUser(int userId)
|
boolean
|
startUser(int userId, boolean waitFlag)
|
boolean
|
stopUser(int userId, boolean waitFlag, boolean forceFlag)
|
boolean
|
stopUser(int userId)
|
boolean
|
switchUser(int userId)
|
boolean
|
switchUser(int userId, long timeout)
|
String
|
uninstallPackage(String packageName)
|
String
|
uninstallPackageForUser(String packageName, int userId)
|
Fields
DISMISS_KEYGUARD_CMD
public static final String DISMISS_KEYGUARD_CMD
Commands that can be used to dismiss the keyguard.
Public constructors
TestDevice
public TestDevice (IDevice device,
IDeviceStateMonitor stateMonitor,
IDeviceMonitor allocationMonitor)
Public methods
clearErrorDialogs
public boolean clearErrorDialogs ()
Throws |
DeviceNotAvailableException |
|
createUser
public int createUser (String name)
Throws |
DeviceNotAvailableException |
|
createUser
public int createUser (String name,
boolean guest,
boolean ephemeral)
Parameters |
name |
String |
guest |
boolean |
ephemeral |
boolean |
Throws |
DeviceNotAvailableException |
|
createUserNoThrow
public int createUserNoThrow (String name)
Throws |
DeviceNotAvailableException |
|
disableKeyguard
public void disableKeyguard ()
Throws |
DeviceNotAvailableException |
|
doesFileExist
public boolean doesFileExist (String deviceFilePath)
Parameters |
deviceFilePath |
String |
Throws |
DeviceNotAvailableException |
|
dumpHeap
public File dumpHeap (String process,
String devicePath)
Parameters |
process |
String |
devicePath |
String |
Throws |
DeviceNotAvailableException |
|
getActiveApexes
public getActiveApexes ()
Throws |
DeviceNotAvailableException |
|
getAllSettings
public getAllSettings (String namespace)
Parameters |
namespace |
String |
Throws |
DeviceNotAvailableException |
|
getAndroidId
public String getAndroidId (int userId)
Throws |
DeviceNotAvailableException |
|
getAndroidIds
public getAndroidIds ()
Throws |
DeviceNotAvailableException |
|
getAppPackageInfo
public PackageInfo getAppPackageInfo (String packageName)
Parameters |
packageName |
String |
Throws |
DeviceNotAvailableException |
|
getAppPackageInfos
public getAppPackageInfos ()
Throws |
DeviceNotAvailableException |
|
getCurrentFoldableState
public DeviceFoldableState getCurrentFoldableState ()
Returns |
DeviceFoldableState |
|
Throws |
DeviceNotAvailableException |
|
getCurrentUser
public int getCurrentUser ()
Throws |
DeviceNotAvailableException |
|
getFoldableStates
public getFoldableStates ()
Throws |
DeviceNotAvailableException |
|
getInstalledPackageNames
public getInstalledPackageNames ()
Throws |
DeviceNotAvailableException |
|
getKeyguardState
public KeyguardControllerState getKeyguardState ()
Returns |
KeyguardControllerState |
|
Throws |
DeviceNotAvailableException |
|
getMainlineModuleInfo
public getMainlineModuleInfo ()
Throws |
DeviceNotAvailableException |
|
public int getMaxNumberOfRunningUsersSupported ()
Throws |
DeviceNotAvailableException |
|
public int getMaxNumberOfUsersSupported ()
Throws |
DeviceNotAvailableException |
|
getPrimaryUserId
public Integer getPrimaryUserId ()
Throws |
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot ()
Returns |
InputStreamSource |
|
Throws |
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (String format,
boolean rescale)
Parameters |
format |
String |
rescale |
boolean |
Returns |
InputStreamSource |
|
Throws |
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (String format)
Returns |
InputStreamSource |
|
Throws |
DeviceNotAvailableException |
|
getScreenshot
public InputStreamSource getScreenshot (long displayId)
Parameters |
displayId |
long |
Returns |
InputStreamSource |
|
Throws |
DeviceNotAvailableException |
|
getSetting
public String getSetting (String namespace,
String key)
Parameters |
namespace |
String |
key |
String |
Throws |
DeviceNotAvailableException |
|
getSetting
public String getSetting (int userId,
String namespace,
String key)
Parameters |
userId |
int |
namespace |
String |
key |
String |
Throws |
DeviceNotAvailableException |
|
getUninstallablePackageNames
public getUninstallablePackageNames ()
Throws |
DeviceNotAvailableException |
|
getUserFlags
public int getUserFlags (int userId)
Throws |
DeviceNotAvailableException |
|
getUserInfos
public getUserInfos ()
Throws |
DeviceNotAvailableException |
|
getUserSerialNumber
public int getUserSerialNumber (int userId)
Throws |
DeviceNotAvailableException |
|
hasFeature
public boolean hasFeature (String feature)
Parameters |
feature |
String |
Throws |
DeviceNotAvailableException |
|
installPackage
public String installPackage (File packageFile,
boolean reinstall,
String... extraArgs)
Parameters |
packageFile |
File |
reinstall |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackage
public String installPackage (File packageFile,
File certFile,
boolean reinstall,
String... extraArgs)
Parameters |
packageFile |
File |
certFile |
File |
reinstall |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackage
public String installPackage (File packageFile,
boolean reinstall,
boolean grantPermissions,
String... extraArgs)
Parameters |
packageFile |
File |
reinstall |
boolean |
grantPermissions |
boolean |
extraArgs |
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 |
Throws |
DeviceNotAvailableException |
|
installPackageForUser
public String installPackageForUser (File packageFile,
boolean reinstall,
int userId,
String... extraArgs)
Parameters |
packageFile |
File |
reinstall |
boolean |
userId |
int |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackages
public String installPackages ( packageFiles,
boolean reinstall,
String... extraArgs)
Parameters |
packageFiles |
|
reinstall |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackages
public String installPackages ( packageFiles,
boolean reinstall,
boolean grantPermissions,
String... extraArgs)
Parameters |
packageFiles |
|
reinstall |
boolean |
grantPermissions |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackagesForUser
public String installPackagesForUser ( packageFiles,
boolean reinstall,
boolean grantPermissions,
int userId,
String... extraArgs)
Parameters |
packageFiles |
|
reinstall |
boolean |
grantPermissions |
boolean |
userId |
int |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installPackagesForUser
public String installPackagesForUser ( packageFiles,
boolean reinstall,
int userId,
String... extraArgs)
Parameters |
packageFiles |
|
reinstall |
boolean |
userId |
int |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installRemotePackages
public String installRemotePackages ( remoteApkPaths,
boolean reinstall,
boolean grantPermissions,
String... extraArgs)
Parameters |
remoteApkPaths |
|
reinstall |
boolean |
grantPermissions |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
installRemotePackages
public String installRemotePackages ( remoteApkPaths,
boolean reinstall,
String... extraArgs)
Parameters |
remoteApkPaths |
|
reinstall |
boolean |
extraArgs |
String |
Throws |
DeviceNotAvailableException |
|
isAppEnumerationSupported
public boolean isAppEnumerationSupported ()
Throws |
DeviceNotAvailableException |
|
isMultiUserSupported
public boolean isMultiUserSupported ()
Throws |
DeviceNotAvailableException |
|
isPackageInstalled
public boolean isPackageInstalled (String packageName)
Parameters |
packageName |
String |
Throws |
DeviceNotAvailableException |
|
isPackageInstalled
public boolean isPackageInstalled (String packageName,
String userId)
Parameters |
packageName |
String |
userId |
String |
Throws |
DeviceNotAvailableException |
|
isUserRunning
public boolean isUserRunning (int userId)
Throws |
DeviceNotAvailableException |
|
isUserSecondary
public boolean isUserSecondary (int userId)
Throws |
DeviceNotAvailableException |
|
listDisplayIds
public listDisplayIds ()
Throws |
DeviceNotAvailableException |
|
listUsers
public listUsers ()
Throws |
DeviceNotAvailableException |
|
postInvocationTearDown
public void postInvocationTearDown (Throwable exception)
Parameters |
exception |
Throwable |
removeAdmin
public boolean removeAdmin (String componentName,
int userId)
Parameters |
componentName |
String |
userId |
int |
Throws |
DeviceNotAvailableException |
|
removeOwners
public void removeOwners ()
Throws |
DeviceNotAvailableException |
|
removeUser
public boolean removeUser (int userId)
Throws |
DeviceNotAvailableException |
|
setDeviceOwner
public boolean setDeviceOwner (String componentName,
int userId)
Parameters |
componentName |
String |
userId |
int |
Throws |
DeviceNotAvailableException |
|
setSetting
public void setSetting (String namespace,
String key,
String value)
Parameters |
namespace |
String |
key |
String |
value |
String |
Throws |
DeviceNotAvailableException |
|
setSetting
public void setSetting (int userId,
String namespace,
String key,
String value)
Parameters |
userId |
int |
namespace |
String |
key |
String |
value |
String |
Throws |
DeviceNotAvailableException |
|
startUser
public boolean startUser (int userId)
Throws |
DeviceNotAvailableException |
|
startUser
public boolean startUser (int userId,
boolean waitFlag)
Parameters |
userId |
int |
waitFlag |
boolean |
Throws |
DeviceNotAvailableException |
|
stopUser
public boolean stopUser (int userId,
boolean waitFlag,
boolean forceFlag)
Parameters |
userId |
int |
waitFlag |
boolean |
forceFlag |
boolean |
Throws |
DeviceNotAvailableException |
|
stopUser
public boolean stopUser (int userId)
Throws |
DeviceNotAvailableException |
|
switchUser
public boolean switchUser (int userId)
Throws |
DeviceNotAvailableException |
|
switchUser
public boolean switchUser (int userId,
long timeout)
Parameters |
userId |
int |
timeout |
long |
Throws |
DeviceNotAvailableException |
|
uninstallPackage
public String uninstallPackage (String packageName)
Parameters |
packageName |
String |
Throws |
DeviceNotAvailableException |
|
uninstallPackageForUser
public String uninstallPackageForUser (String packageName,
int userId)
Parameters |
packageName |
String |
userId |
int |
Throws |
DeviceNotAvailableException |
|
Protected methods
doAdbReboot
protected void doAdbReboot (NativeDevice.RebootMode rebootMode,
String reason)
Perform a adb reboot.
Parameters |
rebootMode |
NativeDevice.RebootMode : a mode of this reboot. |
reason |
String : for this reboot. |
Throws |
DeviceNotAvailableException |
|
getCheckNewUserSleep
protected long getCheckNewUserSleep ()
Exposed for testing.
getHostCurrentTime
protected long getHostCurrentTime ()
Exposed for testing
prePostBootSetup
protected void prePostBootSetup ()
Allows each device type (AndroidNativeDevice, TestDevice) to override this method for
specific post boot setup.
Throws |
DeviceNotAvailableException |
|
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-08-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-08-03 UTC."],[],[]]