החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
USB Port Reset API
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי לתמוך ב-API של שכבת ההפשטה של חומרת ה-USB (HAL), יצרני המכשירים חייבים להטמיע את גרסת ה-HAL המתאימה של USB. כדי להשתמש ב-USB HAL API, נדרשת אפליקציה עם הרשאות מערכת.
ה-HAL של USB תומך ב-USB Port Reset API, שדורש USB HAL v2.0 וזמין במכשירים עם Android 13 ואילך. אפשר להשתמש ב-API הזה כדי לאפס את חיבור ה-USB למארח המחובר.
איך למצוא את ה-HAL של USB ואת ממשקי ה-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/include/android/. הנתיב הזה הוא גם נקודת הכניסה של ה-API ל-Android Framework:
android.hardware.usb
:
<aosp>/core/java/android/hardware/usb
הטמעת ה-HAL של USB
כדי לעבוד עם USB HAL API, צריך להטמיע את:
גרסת USB HAL נכונה. אין צורך בהטמעה של ממשק משתמש מערכת.
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 התואם שלה משויכים לתרחיש בדיקה ב-Vendor Test Suite (VTS).
USB Port Reset API
כדי למצוא את תרחיש הבדיקה של VTS לממשק ה-API לאיפוס יציאת USB, עוברים אל:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
תרחיש הבדיקה של VTS עבור USB HAL v1.2 הוא תרחיש בדיקה בצד המארח שאפשר להשתמש בו כדי לבצע את הפעולות האלה.
כדי להפעיל את ה-API לאיפוס יציאת USB, משתמשים בפקודה adb shell
(#svc usb resetUsbPort
).
מוודאים שהמכשיר שנבדק (DUT) יכול להתנתק ולהתחבר מחדש.
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. 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."]]