自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Tradefed 中的裝置分配
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
開始測試 (例如檢測設備測試) 時,可能需要裝置才能正常執行。或者,測試 (例如某些 Java 單元測試) 可能完全不需要裝置。其他測試可能甚至需要多部裝置 (例如手機 + 手錶測試)。在所有這些情況下,裝置管理員都會負責為測試分配必要的裝置,以便測試能正常執行。我們稱這個階段為裝置分配或裝置選取步驟。
分配作業是由 DeviceSelectionOptions 驅動,可讓測試宣告裝置所需的任何屬性,包括:
使用實體裝置
這是會分配給所有未指定任何裝置屬性的測試的預設設定。系統會選取標示為「可用」的隨機實體裝置,並指派給測試。
不使用任何裝置
如果測試不需要任何裝置,則可在指令列上指定 --null-device
或 -n
,或是在設定 XML 中指定 <option name="null-device" value="true" />
。這會分配代表未配置任何裝置的 Stub 預留位置 NullDevice。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Device allocation in Tradefed\n\nWhen starting a test (for example, an instrumentation test), it might need a\ndevice to be able to run properly. Or the test (such as some Java unit tests)\nmight not need a device at all. Still others or might even need multi-devices\n(like phone + watch tests). In all those cases, the Device Manager is\nresponsible for allocating the required devices to the test so it runs\nproperly. We call this phase the *device allocation* or *device selection* step.\n\nThe allocation is driven by\n[DeviceSelectionOptions](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/device/DeviceSelectionOptions.java)\nthat allow a test to declare any properties it needs from a device, including:\n\n- Battery level\n- Device type\n- Product type\n- Serial number\n\nUse real devices\n----------------\n\nThis is the default setting that will be allocated to all tests that don't\nspecify any device properties. A physical random device marked\n[AVAILABLE](/docs/core/tests/tradefed/architecture/device-manager#allocation_states)\nwill be picked and assigned to the test.\n\nUse no devices\n--------------\n\nWhen no devices are needed by the test, it can specify `--null-device` or `-n`\non its command line, or `\u003coption name=\"null-device\" value=\"true\" /\u003e` in its\nconfiguration XML. This allocates a stub placeholder NullDevice that\nrepresents no device was allocated."]]