از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
API تنظیم مجدد پورت USB
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
برای پشتیبانی از USB Hardware Abstraction Layer (HAL) API، سازندگان دستگاه باید نسخه USB HAL مربوطه را پیاده سازی کنند. برای استفاده از USB HAL API، یک برنامه دارای امتیاز سیستم مورد نیاز است.
USB HAL از API بازنشانی پورت USB پشتیبانی میکند، که به USB HAL نسخه 2.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ها، از مسیر زیر برای یافتن APIها در زیر فایل هدر AIDL استفاده کنید. این مسیر همچنین نقطه ورودی Android Framework برای API است:
android.hardware.usb
: <aosp>/core/java/android/hardware/usb
USB HAL را اجرا کنید
برای کار با USB HAL API، موارد زیر را اجرا کنید:
نسخه صحیح USB HAL. هیچ پیاده سازی UI سیستم مورد نیاز نیست.
USB AIDL HAL برای درگاه USB Reset API با تنظیم مجدد اتصال USB بین دستگاه مورد نظر و میزبان.
معماری USB HAL API را درک کنید
USB HAL API در بسته android.hardware.usb
تعبیه شده است و از USB HAL برای تعامل با دستگاه استفاده می کند. جزئیات در مورد معماری API در شکل زیر ارائه شده است.
API تنظیم مجدد پورت USB
شکل زیر جریان کد API بازنشانی پورت USB را در یک چارچوب، از جمله اجرای USB HAL نشان میدهد.

شکل 1.1 نمونه جریان کد API Reseat پورت USB.
اجرای خود را تأیید کنید
هر نسخه USB HAL و API مربوط به آن با یک مورد آزمایشی در مجموعه تست فروشنده (VTS) مرتبط است.
API تنظیم مجدد پورت USB
برای یافتن مورد آزمایشی VTS برای API تنظیم مجدد پورت USB، به آدرس زیر بروید:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
کیس تست VTS برای USB HAL v1.2 یک کیس تست سمت میزبان است که می توانید برای انجام این اقدامات از آن استفاده کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]