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:
Edits
voltage_now
filenameOn android devices you may have more than one battery, like the backup for RTC or for other peripherals. Did you already cat the type file for all the 3 sysfs entries? for all the 3 you get 'Battery'?
Considering that Android expects several parameters from the battery (see below), i may guess that they are split in those 3 sysfs files you got.
For example the fuel gauge is the hardware component that reads the current flow from/to the battery and calculate the remaining capacity, thus reading the capacity file from it should give you the %, but probably the voltage is read from another file.
Battery params (i.e.: /sys/class/power_supply/my_batt/status):