A partire dal 27 marzo 2025, ti consigliamo di utilizzare android-latest-release
anziché aosp-main
per compilare e contribuire ad AOSP. Per ulteriori informazioni, vedi Modifiche ad AOSP.
API USB Port Reset
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Per supportare l'API HAL (Hardware Abstraction Layer) USB, i produttori di dispositivi devono implementare la versione HAL USB corrispondente. Per utilizzare l'API HAL USB, è necessaria un'app con privilegi di sistema.
L'HAL USB supporta l'API USB Port Reset, che richiede l'HAL USB 2.0 ed è disponibile per i dispositivi con Android 13 e versioni successive. Utilizza questa API per reimpostare la connessione USB con l'host connesso.
Trovare l'HAL USB e le relative API
I produttori di dispositivi devono implementare l'HAL USB per supportare le API.
Per trovare l'implementazione predefinita dell'HAL USB, utilizza i seguenti percorsi:
Versione AIDL (ultima):
<aosp>/hardware/interfaces/usb/gadget/1.2/default/
Per trovare il file dell'intestazione dell'interfaccia hardware, utilizza il seguente percorso:
Versione AIDL (ultima):
<aosp>/hardware/interfaces/usb/gadget/1.2/IUsbGadget.hal
Per trovare le API, utilizza il seguente percorso per individuarle nel
file di intestazione AIDL. Questo percorso è anche il punto di ingresso del framework Android per l'API:
android.hardware.usb
:
<aosp>/core/java/android/hardware/usb
Implementa l'HAL USB
Per utilizzare l'API HAL USB, implementa:
Versione corretta dell'HAL USB. Non è richiesta l'implementazione dell'interfaccia utente di sistema.
HAL AIDL USB per l'API USB Port Reset reimpostando la connessione USB tra il dispositivo di destinazione e l'host.
Informazioni sull'architettura dell'API HAL USB
L'API HAL USB è integrata nel pacchetto android.hardware.usb
e sfrutta l'HAL USB per interagire con il dispositivo. I dettagli sull'architettura dell'API sono riportati nella figura seguente.
API USB Port Reset
La figura seguente illustra il flusso di codice dell'API USB Port Reset in un framework, inclusa l'implementazione dell'HAL USB.
Figura 1.1 Esempio di flusso di codice dell'API di reinserimento della porta USB.
Convalidare l'implementazione
Ogni versione dell'HAL USB e la relativa API sono associate a uno scenario di test nel Vendor Test Suite (VTS).
API USB Port Reset
Per trovare lo scenario di test VTS per l'API USB Port Reset, vai a:
<aosp>/test/vts-testcase/hal/usb/gadget/V1_2/
Il test case VTS per la versione 1.2 dell'HAL USB è un test case lato host che puoi utilizzare per eseguire queste azioni.
Per richiamare l'API USB Port Reset, utilizza il comando adb shell
(#svc usb resetUsbPort
).
Verifica che il dispositivo in prova (DUT) possa scollegarsi e ricollegarsi.
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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."]]