自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
USB 連接埠重設 API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要支援 USB 硬體抽象層 (HAL) API,裝置製造商必須實作對應的 USB HAL 版本。如要使用 USB HAL API,您必須使用具備系統權限的應用程式。
USB HAL 支援 USB 連接埠重設 API,但必須使用 USB HAL 2.0,且適用於搭載 Android 13 以上版本的裝置。使用這個 API 重設與已連結主機的 USB 連線。
尋找 USB HAL 和其 API
裝置製造商必須實作 USB HAL,才能支援這些 API。
如要找出 USB HAL 的預設實作項目,請使用下列路徑:
Version AIDL (最新版本):
<aosp>/hardware/interfaces/usb/gadget/1.2/default/
如要找出硬體介面標頭檔案,請使用下列路徑:
Version AIDL (最新版本):
<aosp>/hardware/interfaces/usb/gadget/1.2/IUsbGadget.hal
如要找出 API,請使用下列路徑,在 AIDL 標頭檔案下找到 API。這個路徑也是 API 的 Android 架構進入點:
android.hardware.usb
:
<aosp>/core/java/android/hardware/usb
實作 USB HAL
如要使用 USB HAL API,請實作以下項目:
正確的 USB HAL 版本。不需要實作系統 UI。
透過重設目標裝置和主機之間的 USB 連線,為 USB Port Reset API 提供 USB AIDL HAL。
瞭解 USB HAL API 架構
USB HAL API 已內建於 android.hardware.usb
套件中,並利用 USB HAL 與裝置互動。下圖詳細說明 API 的架構。
USB 連接埠重設 API
下圖說明架構中 USB Port Reset API 的程式碼流程,包括 USB HAL 的實作方式。
圖 1.1 USB 連接埠重置 API 程式碼流程範例。
驗證導入狀態
每個 USB HAL 版本及其對應的 API 都會與供應商測試套件 (VTS) 中的測試案例相關聯。
USB 連接埠重設 API
如要查看 USB Port Reset API 的 VTS 測試案例,請前往:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
USB HAL 1.2 版的 VTS 測試案例是主機端測試案例,可用於執行這些動作。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# USB Port Reset API\n\nTo support the USB Hardware Abstraction Layer (HAL) API, device manufacturers\nmust implement the corresponding USB HAL version. To use the USB HAL API, a\nsystem-privileged app is required.\n\nThe USB HAL supports the USB Port Reset API, which requires USB HAL v2.0 and is\navailable for devices running Android 13 and higher. Use this API to reset the\nUSB connection with the connected host.\n\nFind the USB HAL and its APIs\n-----------------------------\n\nDevice manufacturers must implement the USB HAL to support the APIs.\n\n1. To find the default implementation of USB HAL, use the following paths:\n\n **Version AIDL (latest):**\n [`\u003caosp\u003e/hardware/interfaces/usb/gadget/1.2/default/`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/usb/gadget/1.2/default/)\n2. To find the hardware interface header file, use the following path:\n\n **Version AIDL (latest):**\n [`\u003caosp\u003e/hardware/interfaces/usb/gadget/1.2/IUsbGadget.hal`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/usb/gadget/1.2/IUsbGadget.hal)\n3. To find the APIs, use the following path to locate the APIs under the\n AIDL header file. This path is also the Android Framework entry point for the API:\n\n `android.hardware.usb`:\n [`\u003caosp\u003e/core/java/android/hardware/usb`](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/java/android/hardware/usb/IUsbManager.aidl)\n\nImplement the USB HAL\n---------------------\n\nTo work with the USB HAL API, implement the:\n\n1. Correct USB HAL version. No system UI implementation is required.\n\n2. USB AIDL HAL for the USB Port Reset API by resetting the USB connection between the target device and the host.\n\nUnderstand the USB HAL API architecture\n---------------------------------------\n\nThe USB HAL API is built into the `android.hardware.usb` package and leverages the USB HAL to interact with the device. Details about the architecture for the API is provided in the figure below.\n\n### USB Port Reset API\n\nThe following figure illustrates the code flow of the USB Port Reset API in a framework, including the implementation of the USB HAL.\n\n**Figure 1.1** Sample USB Port Reseat API code flow.\n\nValidate your implementation\n----------------------------\n\nEach USB HAL version and its corresponding API is associated with a test case in\nthe Vendor Test Suite (VTS).\n\n### USB Port Reset API\n\nTo find the VTS test case for the USB Port Reset API, go to:\n\n[`\u003caosp\u003e/test/vts-testcase/hal/usb/gadget/V1_2/`](https://android.googlesource.com/platform/test/vts-testcase/hal/+/refs/heads/android16-release/usb/gadget/V1_2)\n\nThe VTS test case for USB HAL v1.2 is a host-side test case you can use to\nperform these actions.\n\n- To invoke the USB Port Reset API, use the `adb shell`\n command (`#svc usb resetUsbPort`).\n\n- Confirm that the device under test (DUT) can disconnect and reconnect."]]