I am trying to read battery information from an NDK app. The only way I know to accomplish this is to read the values out /sys/class/power_supply
. My difficulty is that I find multiple entries with type "Battery" and I don't know which one to use.
On a Nexus 10 with KitKat 4.4.4 I see:
$ ls /sys/class/power_supply
ds2784-fuelgauge
manta-battery
smb347-battery
# other non-battery entries
With type=Battery for all three. For example:
$ cat /sys/class/power_supply/ds2784-fuelgauge/type
Battery
In the Android BatteryManager
code they just iterate through the battery devices and take the first one that has the entry they want (http://androidxref.com/4.4.4_r1/xref/system/core/healthd/BatteryMonitor.cpp). However, on my Nexus 10 they have different values. For example, for ds2784-fuelgauge/voltage_now
and smb347-battery/voltage_now
:
$ cat ds2784-fuelgauge/voltage_now
4153100
$ cat smb347-battery/voltage_now
4300000
ds2784-fuelgauge/voltage_now
seems to be updated regularly (e.g. it changes when I start a compute-heavy task), but smb347-battery/voltage_now
seems to be fixed. I see a similar effect when I compare ds2784-fuelgauge/current_now
and smb347-battery/current_now
.
My questions are:
- why are there multiple entries here with type=battery?
- how do I distinguish them in a general way?
- which one should I be using?
Edits
- fixed typo in
voltage_now
filename - emphasize that type=Battery for all three devices