Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
API đặt lại cổng USB
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Để hỗ trợ API Lớp trừu tượng phần cứng (HAL) USB, nhà sản xuất thiết bị phải triển khai phiên bản HAL USB tương ứng. Để sử dụng USB HAL API, bạn cần có một ứng dụng đặc quyền của hệ thống.
USB HAL hỗ trợ API đặt lại cổng USB, yêu cầu USB HAL v2.0 và có sẵn cho các thiết bị chạy Android 13 trở lên. Sử dụng API này để đặt lại kết nối USB với máy chủ đã kết nối.
Tìm USB HAL và các API của HAL đó
Nhà sản xuất thiết bị phải triển khai USB HAL để hỗ trợ các API.
Để tìm cách triển khai mặc định của USB HAL, hãy sử dụng các đường dẫn sau:
Phiên bản AIDL (mới nhất):
<aosp>/hardware/interfaces/usb/gadget/1.2/default/
Để tìm tệp tiêu đề giao diện phần cứng, hãy sử dụng đường dẫn sau:
Phiên bản AIDL (mới nhất):
<aosp>/hardware/interfaces/usb/gadget/1.2/IUsbGadget.hal
Để tìm các API, hãy sử dụng đường dẫn sau để định vị các API trong tệp tiêu đề AIDL. Đường dẫn này cũng là điểm truy cập Khung Android cho API:
android.hardware.usb
:
<aosp>/core/java/android/hardware/usb
Triển khai USB HAL
Để làm việc với USB HAL API, hãy triển khai:
Sửa phiên bản USB HAL. Không cần triển khai giao diện người dùng hệ thống.
USB AIDL HAL cho USB Port Reset API (API đặt lại cổng USB) bằng cách đặt lại kết nối USB giữa thiết bị mục tiêu và máy chủ.
Tìm hiểu về cấu trúc USB HAL API
USB HAL API được tích hợp vào gói android.hardware.usb
và tận dụng USB HAL để tương tác với thiết bị. Thông tin chi tiết về cấu trúc của API được cung cấp trong hình dưới đây.
API đặt lại cổng USB
Hình sau đây minh hoạ luồng mã của API đặt lại cổng USB trong một khung, bao gồm cả việc triển khai USB HAL.
Hình 1.1 Quy trình mã API mẫu về việc cắm lại cổng USB.
Xác thực cách triển khai
Mỗi phiên bản USB HAL và API tương ứng được liên kết với một trường hợp kiểm thử trong Bộ kiểm thử nhà cung cấp (VTS).
API đặt lại cổng USB
Để tìm trường hợp kiểm thử VTS cho API Đặt lại cổng USB, hãy truy cập vào:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
Trường hợp kiểm thử VTS cho USB HAL v1.2 là một trường hợp kiểm thử phía máy chủ mà bạn có thể sử dụng để thực hiện các thao tác này.
Để gọi API đặt lại cổng USB, hãy sử dụng lệnh adb shell
(#svc usb resetUsbPort
).
Xác nhận rằng thiết bị đang được kiểm thử (DUT) có thể ngắt kết nối và kết nối lại.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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."]]