Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

power management - How is the Android battery health determined?

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 firmware? Manufacturer specific?

What determines these values?

int BATTERY_HEALTH_COLD 
int BATTERY_HEALTH_DEAD 
int BATTERY_HEALTH_GOOD 
int BATTERY_HEALTH_OVERHEAT 
int BATTERY_HEALTH_OVER_VOLTAGE 
int BATTERY_HEALTH_UNKNOWN  
int BATTERY_HEALTH_UNSPECIFIED_FAILURE

Thanks, Simon

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...