自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
自動在使用者版本上啟用 USB 偵錯功能
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
將使用者版本刷新至裝置後,您必須重新啟用 USB 偵錯功能。OmniLab ATS 可使用 AOA 裝置動作自動執行這個步驟,將一系列 UI 指令傳送至裝置。
記錄 AOA 指令
首先,請使用 WebAOA 指令編輯工具記錄可啟用 USB 偵錯功能的指令清單。
圖 1. 連結至 OmniLab ATS 中的 WebAOA 指令編輯工具。
預設情況下,您也可以前往 http://localhost:8000/webaoa 存取該頁面。
WebAOA 可讓您使用模擬的觸控螢幕操控本機裝置,並記錄 UI 互動情形。
圖 2. 編輯指令,在 WebAOA 中啟用 USB 偵錯功能。
支援四種指令類型:
在觸控螢幕上點選和滑動 (click X Y
和 swipe X1 Y1 DURATION X2 Y2
)
按下裝置按鈕 (back
、home
和 wake
)
輸入文字並按下按鍵組合 (write TEXT
和 key [KEY ...]
)
等待指定的時間長度 (sleep DURATION
)
錄製指令完畢後,您可以將指令複製到剪貼簿或儲存到檔案中。
建立 AOA 裝置動作
如要自動重新啟用 USB 偵錯功能,請將記錄的指令新增至裝置動作。
建立新的裝置動作,然後新增 TF 目標準備工具,並將其類別名稱設為 com.android.tradefed.targetprep.AoaTargetPreparer
。將 WebAOA 中記錄的指令複製到 action
選項。
圖 3. 在 Android 10 GSI 上啟用 USB 偵錯功能的 AOA 裝置動作。
使用 AOA 裝置動作
排定測試執行作業時,請新增 AOA 裝置動作,並直接放在裝置閃燈動作之後。
圖 4. 排定執行作業,以便閃記使用者版本並重新啟用 USB 偵錯功能。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Enable USB debugging on user builds automatically\n\nAfter flashing a user build onto a device, you need to re-enable USB\ndebugging. OmniLab ATS can automate this step using *AOA device actions*, which\nsend a series of UI commands to a device.\n| **Note:** This procedure uses the [Android Open Accessory protocol](/docs/core/interaction/accessories/protocol), which supports Android 4.1+ and doesn't require ADB.\n\nRecord the AOA commands\n-----------------------\n\nFirst, use the *WebAOA command editing tool* to record the list of commands to\nenable USB debugging.\n\n**Figure 1.** Link to the WebAOA command editing tool in OmniLab ATS.\n\nIt is also accessible at \u003chttp://localhost:8000/webaoa\u003e\nby default.\n\nWebAOA lets you manipulate a local device using a simulated touchscreen and\nrecord your UI interactions.\n\n**Figure 2.** Editing the commands for enabling USB debugging in WebAOA.\n\nFour types of commands are supported:\n\n- Clicking and swiping on the touchscreen\n (`click `\u003cvar translate=\"no\"\u003eX\u003c/var\u003e` `\u003cvar translate=\"no\"\u003eY\u003c/var\u003e and\n `swipe `\u003cvar translate=\"no\"\u003eX1\u003c/var\u003e` `\u003cvar translate=\"no\"\u003eY1\u003c/var\u003e` `\u003cvar translate=\"no\"\u003eDURATION\u003c/var\u003e` `\u003cvar translate=\"no\"\u003eX2\u003c/var\u003e` `\u003cvar translate=\"no\"\u003eY2\u003c/var\u003e)\n\n- Pressing device buttons (`back`, `home`, and `wake`)\n\n- Writing text and pressing key combinations\n (`write `\u003cvar translate=\"no\"\u003eTEXT\u003c/var\u003e and\n `key [`\u003cvar translate=\"no\"\u003eKEY\u003c/var\u003e` ...]`)\n\n- Waiting for a specified duration (`sleep `\u003cvar translate=\"no\"\u003eDURATION\u003c/var\u003e)\n\nWhen you are finished recording commands, you can copy them to your clipboard or\nsave them to a file.\n\nCreate an AOA device action\n---------------------------\n\nTo automatically re-enable USB debugging, the recorded commands need to be added\nto a device action.\n\n[Create a new device action](/docs/core/tests/development/android-test-station/ats-user-guide#create-a-new-device-action) and\nadd a TF Target Preparer with its class name set to\n[`com.android.tradefed.targetprep.AoaTargetPreparer`](/reference/tradefed/com/android/tradefed/targetprep/AoaTargetPreparer).\nCopy the commands recorded in WebAOA into its `action` option.\n\n**Figure 3.** AOA device action for enabling USB debugging on Android 10 GSI.\n\nUse an AOA device action\n------------------------\n\nWhen scheduling a test run, add your AOA device action and place it directly\nafter your device-flashing action.\n\n**Figure 4.** Scheduling a run to flash a user build and re-enable USB\ndebugging."]]