ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ 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 ซึ่งต้องใช้ USB HAL v2.0 และพร้อมใช้งานในอุปกรณ์ที่ใช้ Android 13 ขึ้นไป ใช้ API นี้เพื่อรีเซ็ตการเชื่อมต่อ USB กับโฮสต์ที่เชื่อมต่ออยู่
ค้นหา HAL ของ USB และ API ของ HAL
ผู้ผลิตอุปกรณ์ต้องใช้ 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 ให้ใช้เส้นทางต่อไปนี้เพื่อค้นหา API ในส่วนไฟล์ส่วนหัว AIDL เส้นทางนี้ยังเป็นจุดแรกเข้าของเฟรมเวิร์ก Android สําหรับ API ด้วย
android.hardware.usb
:
<aosp>/core/java/android/hardware/usb
ติดตั้งใช้งาน HAL ของ USB
หากต้องการใช้งาน USB HAL API ให้ใช้สิ่งต่อไปนี้
เวอร์ชัน USB HAL ที่ถูกต้อง ไม่จำเป็นต้องมีการใช้ UI ของระบบ
USB AIDL HAL สำหรับ USB Port Reset API โดยรีเซ็ตการเชื่อมต่อ 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 ตัวอย่างขั้นตอนโค้ด API ของพอร์ต USB รีเซ็ต
ตรวจสอบการติดตั้งใช้งาน
USB HAL แต่ละเวอร์ชันและ API ที่เกี่ยวข้องจะเชื่อมโยงกับชุดทดสอบของผู้ให้บริการ (VTS)
USB Port Reset API
หากต้องการดูเคสทดสอบ VTS สำหรับ USB Port Reset API ให้ไปที่
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
กรณีทดสอบ VTS สำหรับ USB HAL v1.2 เป็นกรณีทดสอบฝั่งโฮสต์ที่คุณสามารถใช้เพื่อดำเนินการเหล่านี้
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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 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."]]