更具体地说:电池健康状况由驱动程序(在内核中)确定。所述驱动程序通过 sys 文件系统(准确地说是 /sys/class/power_supply)导出信息。Android 守护程序 healthd(截至 KK,4.4.x)获取此信息,并在其上实现 IBatteryPropertiesRegistrar 接口。它连续轮询(使用 epoll_wait 在超时循环中运行以进行定期更新,以及 POWER 子系统的 netlink 通知 - 例如,如果您连接或断开充电器)。然后系统的 BatteryStatsService 向 healthd 注册一个监听器(通过 binder),然后获取 healthd 发布的数据,
查看 /sys/class/power_supply,您将看到:
lrwxrwxrwx root root 1970-02-05 14:20 ac -> ../../devices/f9923000.i2c/i2c-84/84-006b/power_supply/ac
lrwxrwxrwx root root 1970-02-05 14:20 batt_therm -> ../../devices/battery_tm_ctrl.78/power_supply/batt_therm
lrwxrwxrwx root root 1970-02-05 14:20 battery -> ../../devices/f9923000.i2c/i2c-84/84-0036/power_supply/battery
lrwxrwxrwx root root 1970-02-05 14:20 touch -> ../../devices/virtual/power_supply/touch
lrwxrwxrwx root root 1970-02-05 14:20 usb -> ../../devices/msm_dwc3/power_supply/usb
lrwxrwxrwx root root 1970-02-05 14:20 wireless -> ../../devices/bq51013b_wlc.77/power_supply/wireless
然后查看“电池”
/sys/devices/f9923000.i2c/i2c-84/84-0036/power_supply/battery:
-r--r--r-- root root 4096 2014-02-26 13:26 capacity
-r--r--r-- root root 4096 2014-02-26 13:26 charge_full_design
-r--r--r-- root root 4096 2014-02-26 13:26 current_now
lrwxrwxrwx root root 2014-02-26 13:26 device -> ../../../84-0036
-r--r--r-- root root 4096 2014-02-26 13:26 health
drwxr-xr-x root root 2014-02-26 13:26 power
-r--r--r-- root root 4096 2014-02-26 13:26 present
-r--r--r-- root root 4096 2014-02-26 13:26 status
lrwxrwxrwx root root 2014-02-26 13:26 subsystem -> ../../../../../../class/power_supply
-r--r--r-- root root 4096 2014-02-26 13:26 technology
-r--r--r-- root root 4096 2014-02-26 13:26 temp
-r--r--r-- root root 4096 2014-02-26 13:26 type
-rw-r--r-- root root 4096 2014-02-26 13:26 uevent
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_max_design
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_min_design
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_now
通过查看文件,所有细节都将被揭示。