Introduction
The Power HAL and USB HAL represent two fundamental control planes for device hardware. The Power HAL manages CPU frequencies and thermal profiles to balance performance and battery life, while the USB HAL manages the physical Type-C port modes and data roles.
Power HAL - Power Hints, Modes
The Android framework cannot natively know the optimal CPU frequency scaling for every specific Qualcomm, MediaTek, or Tensor SoC. The IPower HAL bridges this gap using "Power Hints."
When the user touches the screen, SurfaceFlinger or ActivityManager sends an INTERACTION hint to the Power HAL. The vendor implementation immediately ramps up the CPU frequency to ensure smooth scrolling. When a game is launched, the framework sends a SUSTAINED_PERFORMANCE mode flag, telling the HAL to cap peak frequencies to prevent thermal throttling over long sessions.
// Example of framework sending a hint to the Power HAL
Return<void> sendHint(PowerHint hint, int32_t data);
PowerAdvisor
Introduced in recent Android versions, PowerAdvisor is a framework component within SurfaceFlinger that attempts to predict the exact amount of CPU time needed for the next display frame. It communicates with the Power HAL to dynamically scale the CPU frequency precisely to meet the 16.6ms (60Hz) or 8.3ms (120Hz) deadline, minimizing wasted clock cycles and saving battery.
USB HAL - Gadget Function Control
When you plug an Android device into a PC, it can act as a charging device, a MTP file storage drive, a MIDI keyboard, or an ADB debug bridge. The IUsbGadget HAL handles this switching.
When the user selects "File Transfer" from the notification shade, UsbDeviceManager calls the HAL to unbind the current USB functions and bind the MTP kernel driver to the USB controller.
// AIDL USB Gadget interface
interface IUsbGadget {
void setCurrentUsbFunctions(in long functions, in IUsbGadgetCallback callback, in long timeout);
}
USB Port Change Notification
Modern USB Type-C ports are incredibly complex. A single port must negotiate Power Delivery (PD) contracts (e.g., pulling 9V/2A from a charger) and determine Data Roles (Host vs. Device).
The IUsb HAL provides an event-driven mechanism. When a cable is plugged in, the kernel's Type-C driver detects the physical resistor changes. The vendor USB daemon reads this from sysfs and fires an asynchronous callback via the HAL to UsbPortManager in the framework, triggering the UI prompts and charging logic.