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.
Work with devices in TF
Stay organized with collections
Save and categorize content based on your preferences.
Trade Federation uses an abstraction called
ITestDevice
to
run tests. This abstraction objectifies the lowest-common-denominator Android device:
- It has a serial number
- It has a state: Online, Available, Recovery, or Not Available
- It has some notion of reliability. For instance, if we run a command, we can differentiate
between the case where the command hasn't finished yet, the case where the device doesn't support
running commands, and the case where the device has become unresponsive while running the
command.
Device classes
The three primary implementations of ITestDevice
represent three common
usecases.
Physical device
This is an actual piece of hardware, connected to the TF host machine either by USB, or by using
adb's TCP feature. The TestDevice class sits atop the ddmlib library, which is a Java interface to adb. So any
physical device listed in adb devices
can be instantiated and used as a
TestDevice
.
Emulator
Emulators are handled specially by TF because they live in another process. To interact with an
Emulator, specify the --emulator
argument for the command. See
LocalSdkBuildProvider and
SdkAvdPreparer for more info.
No device
Suppose you have a test that doesn't interact with a device at all. For instance, it might just
download a file from some service and verify that the file itself is valid. The
NullDevice is an ITestDevice
that is just a stub. It has a serial number like
null-device-N
, and most attempted operations either no-op silently or throw.
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 2024-08-26 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 2024-08-26 UTC."],[],[],null,["# Work with devices in TF\n\nTrade Federation uses an abstraction called\n[ITestDevice](/reference/com/android/tradefed/device/ITestDevice) to\nrun tests. This abstraction objectifies the lowest-common-denominator Android device:\n\n- It has a serial number\n- It has a state: Online, Available, Recovery, or Not Available\n- It has some notion of reliability. For instance, if we run a command, we can differentiate between the case where the command hasn't finished yet, the case where the device doesn't support running commands, and the case where the device has become unresponsive while running the command.\n\nDevice classes\n--------------\n\nThe three primary implementations of `ITestDevice` represent three common\nusecases.\n\n### Physical device\n\nThis is an actual piece of hardware, connected to the TF host machine either by USB, or by using\nadb's TCP feature. The [TestDevice](/reference/com/android/tradefed/device/TestDevice) class sits atop the ddmlib library, which is a Java interface to adb. So any\nphysical device listed in `adb devices` can be instantiated and used as a\n`TestDevice`.\n\n### Emulator\n\nEmulators are handled specially by TF because they live in another process. To interact with an\nEmulator, specify the `--emulator` argument for the command. See\n[LocalSdkBuildProvider](/reference/com/android/tradefed/build/LocalSdkBuildProvider) and\n[SdkAvdPreparer](/reference/com/android/tradefed/targetprep/SdkAvdPreparer) for more info.\n\n### No device\n\nSuppose you have a test that doesn't interact with a device at all. For instance, it might just\ndownload a file from some service and verify that the file itself is valid. The\n[NullDevice](/reference/com/android/tradefed/device/NullDevice) is an `ITestDevice` that is just a stub. It has a serial number like\n`null-device-N`, and most attempted operations either no-op silently or throw."]]