AOSP Framework & Internals
2 min read

Battery & Charging Driver

Learn how the Linux power supply class manages fuel gauges and fast charging ICs to report battery health to Android.

Power management is the most critical aspect of mobile hardware design. An Android phone has a highly volatile lithium-ion battery that must be carefully monitored to prevent damage or fire during fast charging.

The Linux kernel abstracts battery monitoring and charging hardware using the Power Supply Class.

The Power Supply Class

The Power Supply Class provides a standard, unified interface in /sys/class/power_supply/. The Android BatteryService (a core Java framework service) constantly reads from these sysfs nodes to update the battery icon in your status bar.

# View all registered power supplies on the device (battery, usb, wireless)
adb shell ls /sys/class/power_supply/

# Read the current battery capacity percentage directly from the kernel
adb shell cat /sys/class/power_supply/battery/capacity

The Hardware Components

A typical smartphone battery architecture consists of two distinct hardware chips, each requiring its own Linux driver.

1. The Fuel Gauge Driver

The Fuel Gauge is a specialized chip connected to the battery terminals that precisely measures voltage, current flow (coulomb counting), and temperature.

  • Driver Duty: The fuel gauge driver's only job is to read these I2C registers and report accurate numbers to the Power Supply framework (e.g., "Capacity is at 84%", "Temperature is 32C").

2. The Charger Driver (PMIC)

The Charger IC (often part of the larger Power Management IC, or PMIC) physically routes electricity from the USB port into the battery cells.

  • Driver Duty: The charger driver must enforce strict safety limits. If the battery temperature exceeds 45C, the driver must instantly throttle the charging current to prevent thermal runaway.
// Conceptual driver snippet throttling charge current based on temperature
int current_temp = fuel_gauge_get_temp();

if (current_temp > 450) { // 45.0 Celsius
    // Throttle to slow charging (500mA)
    pmic_set_charge_current(500);
} else {
    // Enable fast charging (3000mA)
    pmic_set_charge_current(3000);
}

Android Framework Integration

The kernel does not decide when to turn on Battery Saver mode or when to notify the user of a low battery; it merely reports the raw physical data.

  1. The kernel driver updates the sysfs nodes.
  2. The native Android healthd daemon (or modern Health HAL) reads the sysfs nodes and triggers an event.
  3. The Java BatteryService receives the event and broadcasts an ACTION_BATTERY_CHANGED intent to the rest of the OS.
  4. The System UI receives the intent and redraws the battery icon in the top right corner of your screen.