Multiple Battery entries in /sys/class/power_supply on Android

aschmied picture aschmied · Oct 28, 2014 · Viewed 8.6k times · Source

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:

  1. why are there multiple entries here with type=battery?
  2. how do I distinguish them in a general way?
  3. which one should I be using?

Edits

  • fixed typo in voltage_now filename
  • emphasize that type=Battery for all three devices

Answer

Luca Faggianelli picture Luca Faggianelli · Dec 16, 2014

On 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):

  • status: Charging, Discharging, Not charging, Full, Unknown
  • health (string): Cold, Death, Good, Overheat, Over voltage, Unspecified failure, Unknown
  • present (int): 1 when present
  • capacity (int): 97 for 97%
  • voltage_now (in uV) or batt_volt (in mV): 4205000 for 4205000 uV = 4.205 V
  • temp or batt_temp (in tenth of °C): 305 for 30.5°C
  • technology (string): Li-ion