自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
USB Port Reset API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需支持 USB Hardware Abstraction Layer (HAL) API,设备制造商必须实现相应的 USB HAL 版本。如需使用 USB HAL API,需要一个具有系统特权的应用。
USB HAL 支持 USB Port Reset API,该 API 要求实现 USB HAL v2.0,适用于搭载 Android 13 及更高版本的设备。使用该 API 可以重置与所连主机之间的 USB 连接。
查找 USB HAL 及其 API
设备制造商必须实现 USB HAL 才能支持这些 API。
如需查找 USB HAL 的默认实现,请使用以下路径:
版本 AIDL(最新):<aosp>/hardware/interfaces/usb/gadget/1.2/default/
如需查找硬件接口头文件,请使用以下路径:
版本 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 版本。不需要实现系统界面。
用于 USB Port Reset API 的 USB AIDL HAL(通过重置目标设备与主机之间的 USB 连接)。
了解 USB HAL API 架构
USB HAL API 内置在 android.hardware.usb
软件包中,并利用 USB HAL 与设备进行交互。下图展示了该 API 的架构相关细节。
USB Port Reset API
下图展示了框架中 USB Port Reset API 的代码流,包括 USB HAL 的实现。
图 1.1 USB Port Reseat API 代码流示例。
验证您的实现
每个 USB HAL 版本及其对应的 API 都与供应商测试套件 (VTS) 中的测试用例关联。
USB Port Reset API
如需查找 USB Port Reset API 的 VTS 测试用例,请前往:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
为 USB HAL v1.2 实现的 VTS 测试用例是一种主机端测试用例,可供您用来执行这些操作。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-17。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-03-17。"],[],[],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."]]