自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
在 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 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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."]]