How is the Android battery health determined?

前端 未结 3 1987
无人及你
无人及你 2020-12-17 02:52

I am not talking about how to read the value.

Rather, I am interested in how the value of BatteryManager.EXTRA_HEALTH is being set.

Does it come from the fir

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-17 03:21

    To be more specific: The battery health is determined by the driver (in the kernel). Said driver exports information via the sys file system (/sys/class/power_supply, to be exact). The Android daemon healthd (as of KK, 4.4.x) picks up this information, and implements an IBatteryPropertiesRegistrar interface on it. It polls continuously (using epoll_wait to run in a timeout loop for periodic updates, as well as netlink notifications for the POWER subsystem - say, for example, if you connect or disconnect a charger). The system's BatteryStatsService then registers a listener with healthd (via binder) and then gets the data that is published by healthd,

    Check out /sys/class/power_supply, and you'll see:

    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
    

    then check out "battery"

    /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
    

    and by looking at the files, all details will be revealed.

提交回复
热议问题