自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
在 TF 中使用设备
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Trade Federation 使用名为 ITestDevice
的抽象类来运行测试。此抽象类可将最通用的 Android 设备具体化:
- 具有序列号
- 具有状态:在线、可用、恢复或不可用
- 有一些可靠性的概念。例如,如果我们运行某个命令,则可以区分命令尚未完成的情况、设备不支持运行命令的情况以及设备在运行命令时变得无响应的情况。
设备类
ITestDevice
的三种主要实现代表三个常见用例。
实体设备
实体设备是一种实际的硬件,通过 USB 或使用 adb 的 TCP 功能连接到 TF 主机。TestDevice 类位于 ddmlib 库的顶部,是一个面向 adb 的 Java 接口。因此,adb devices
中列出的任何实体设备都可以实例化并用作 TestDevice
。
模拟器
模拟器位于其他进程中,因此 TF 会对其进行特殊处理。如需与模拟器交互,请为命令指定 --emulator
参数。如需了解详情,请参阅 LocalSdkBuildProvider 和 SdkAvdPreparer。
无设备
假设您有一个根本不与设备交互的测试。例如,该测试可能只是从某项服务中下载文件,并验证文件本身是否有效。NullDevice 是一个 ITestDevice
,只是一个桩。它具有像 null-device-N
这样的序列号,并且尝试最多的操作是静默空操作或抛出操作。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],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."]]