Google is committed to advancing racial equity for Black communities. See how.

Implementing the USB Port Reset API

The USB Port Reset API is a system API available in the Android Open Source Project (AOSP) for devices running Android 11 or higher. Use it to reset the USB gadget connection with the connected host. To support the USB Port Reset API, device manufacturers must implement USB Gadget HAL V1.1. To use the USB Port Reset API, a system privileged app is required.

Finding USB Gadget HAL v1.1 and USB Port Reset API

Device manufacturers must implement USB Gadget HAL v1.1 to support the USB Port Reset API.

  1. To find the default implementation of USB Gadget HAL v.1.1, use the following path: <aosp>/hardware/interfaces/usb/gadget/1.1/default/
  2. To find the hardware interface header file, use the following path: <aosp>/hardware/interfaces/usb/gadget/1.1/IUsbGadget.hal
  3. To find the USB Port Reset API, use this path to locate the API under the AIDL header file. This path is also the Android Framework entry point for the USB Port Reset API:
    <aosp>/core/java/android/hardware/usb

Implementing Gadget HAL v1.1

To support the USB Port Reset API, you must implement the USB Gadget HAL v1.1. No system UI implementation is required. To implement USB Gadget HAL v1.1 for USB Port Reset API, reset the USB connection between the target device and the host.

USB Port Reset API code flow

The figure below illustrates the code flow of the USB Port Reset API in a framework, including the implementation of the USB Gadget HAL.

USB Reset API

Figure 1. Example USB Port Reset API code flow

Validation

Follow this path to find the VTS test case implemented for the USB Port Reset API:

<aosp>/test/vts-testcase/hal/usb/gadget/V1_1/

The VTS test case for USB Port Reset API is a host-side test case that lets you perform the following actions:

  • Invoke the USB Port Reset API using adb shell command (#svc usb resetUsbGadget).
  • Check if the device under test (DUT) can disconnect and reconnect.