Implementing USB HAL

The Android O release moves handling of USB commands out of init scripts and into a native USB daemon for better configuration and code reliability. For the Gadget function configuration, init scripts (property triggers) are used to perform device-specific gadget operations.

In previous releases, these device-specific configurations were achieved through device-specific init scripts (using property triggers). Moving to a Hardware Abstraction Layer (HAL) design results in a much cleaner implementation that solves these problems:

  1. Operations such as writes to the kernel sysfs nodes could fail but not be propagated back to the frameworks code that sets the property trigger. As a result, frameworks incorrectly assumes the operations have succeeded even though they have silently failed.
  2. init scripts have a limited number of operations that could be executed.

HAL and Treble

The device-specific init scripts were used as a substitution for HAL layers to perform device-specific USB operations. USB (through ADB) is a primary interface for debugging system issues. Having a native daemon to perform USB configuration eliminates the dependency on the framework code so even if the framework crashes USB should be running.

Under the Treble model also introduced in Android O, all of the HALs are isolated from System services and are required to run in their own native daemons. This eliminates the requirement to have an exclusive USB daemon as the HAL layer nicely doubles as a USB daemon.

The default HAL implementation takes care of all pre-O devices. Therefore, there wouldn't be any device-specific work for the pre-O devices. O uses the HAL interface to query the status of USB ports and to perform data role and power role swaps.

Implementation

New USB HAL interface needs to be implemented on every device launching on O. The default implementation should take care of Pre-O devices. The default implementation is sufficient if the device uses the dual_role_usb class to report type-c port status. Trivial changes might be required in device-specific USB scripts to transfer ownership of the typc-c nodes to system.

No new platform APIs are introduced.

Validation

VTS will test the new USB HAL.