Introduction to the Thermal HAL
As mobile SoCs become more powerful, managing heat dissipation is critical. Overheating can cause physical damage, degrade battery lifespan, and create an uncomfortable user experience. The Thermal Hardware Abstraction Layer (HAL) provides Android with a unified interface to monitor device temperatures and initiate throttling measures.
The IThermal HAL Interface
The IThermal interface (defined in AIDL or HIDL) allows the Android framework's ThermalManagerService to communicate with vendor-specific thermal management hardware.
Core Responsibilities
- Temperature Reporting: Reading current temperatures from various thermistors across the device (CPU cores, GPU, battery, skin surface).
- Cooling Device Control: Interacting with hardware cooling mechanisms, such as adjusting fan speeds (if present) or applying hardware-level power limits.
- Threshold Callbacks: Notifying the framework when specific temperature thresholds are crossed.
// hardware/interfaces/thermal/aidl/android/hardware/thermal/IThermal.aidl
package android.hardware.thermal;
@VintfStability
interface IThermal {
Temperature[] getTemperatures();
Temperature[] getTemperaturesWithType(in TemperatureType type);
CoolingDevice[] getCoolingDevices();
void registerThermalChangedCallback(in IThermalChangedCallback callback);
}
Thermal Sensor Reporting
The HAL classifies temperatures into different TemperatureType categories:
CPU: CPU core temperatures.GPU: Graphics processor temperatures.BATTERY: Battery cell temperature (critical for charging safety).SKIN: The surface temperature of the device (critical for user comfort).
Each sensor reports its current value along with a ThrottlingSeverity level, ranging from NONE to SHUTDOWN.
Thermal Throttling Callbacks
Polling sensors constantly wastes power. Instead, the Thermal HAL uses an asynchronous callback mechanism.
When the HAL detects that a sensor's temperature has crossed a predefined threshold, it triggers the IThermalChangedCallback. The ThermalManagerService receives this event and takes action based on the severity.
- LIGHT/MODERATE: The framework may inform apps to scale back work.
- SEVERE: The framework begins aggressive throttling. CPU frequencies are capped, screen brightness is reduced, and background processes are killed.
- CRITICAL/EMERGENCY: Hardware components are severely limited to prevent damage.
- SHUTDOWN: The system immediately powers off to save the hardware.
The ThermalManager API
Applications can react to thermal throttling to provide a smoother user experience, rather than crashing or lagging unexpectedly.
Listening for Thermal Status
Developers can use the PowerManager to register a OnThermalStatusChangedListener.
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
powerManager.addThermalStatusListener(new PowerManager.OnThermalStatusChangedListener() {
@Override
public void onThermalStatusChanged(int status) {
switch (status) {
case PowerManager.THERMAL_STATUS_SEVERE:
// Device is very hot.
// Action: Reduce frame rate, disable heavy post-processing effects,
// pause background downloads.
disableHighQualityGraphics();
break;
case PowerManager.THERMAL_STATUS_NONE:
// Device has cooled down.
restoreNormalGraphics();
break;
}
}
});
By integrating with the Thermal API, games and intensive applications can proactively reduce their workload, helping the device cool down faster while avoiding forced framework-level throttling which often results in a janky user experience.