Background
My current device Huawei Honor 6 comes with a 3100 mAh battery. I was therefore surprised to see 3C Toolbox Pro report the capacity as 4000 mAh.
I mailed the developer of the app and his reply was on these lines
In Android, one can get the stock hard-coded battery capacity from battery profiles, an hidden API in Android. That’s the one of the 2 sources the app uses.
The other source is in the kernel, usually under /sys/devices/power_supply/battery/charge_full_design
( To know the path on your device, from 3C Toolbox, tap request support from Help and support menu. An email will be generated to the developer having information about your device, including battery_info.txt. This file amongst other things specifies the path of second source )
So, the battery capacity and state of battery as reported in percentage depends on from which of these two sources it is being read and the two sources could hold different values (In my case, it was the stock ROM shipped with wrong capacity in the battery profiles)
This explanation fits in well with battery capacity being reported differently by apps as also mismatched battery readings using an extended battery (Note: These two questions are of '14 vintage and based on the location of battery files as mentioned, I have answered)
Question
I have been scouring the net, various forums, Android Developers etc to get an authoritative source for this rather than a mail communication. This would help me understand better and also answer such questions with a good reference
Can someone point to an authoritative source that supports or offers an alternative explanation ?
Edit: I am looking for generic information , not specific to my device
Answer
I think the answer in the email is legit, here's why:
All of the following information is based on the Google Nexus 5, but the general procedure should apply for all Android phones.
The mail describes two possible sources for an app developer to get the information on how high the battery charge is on full capcity:
- Reading from the sysfs file in the Android file system (/sys/devices/power_supply/battery/charge_full_design).
- Using the Android private API. Private in this case means that only system apps (from Google) have access to this information. But an app developer can use a few tricks (described here) to get access to this information too.
Both of these methods have their own source for the "charge at full capacity" value.
1.: In the Nexus 5 this file is created by the driver responsible for handling the chip (Maxim MAX17048) which measures the remaining capcity on the battery. The source code of this driver can be found here. The driver uses additional files to get device specific information. This information is fixed and usually provided by the smartphone manufacturer. The file used for the driver in the Nexus 5 also contains a value called fcc-mah
. You will get the content of this value if you read from the /sys/devices/power_supply/battery/charge_full_design file in the Nexus 5.
2.: Another way is provided by the private Android API. This API uses power profiles to know how much energy every component approximately consumes. The Google documentation says:
Device manufacturers must provide a component power profile that defines the current consumption value for the component and the approximate battery drain caused by the component over time. This profile is defined in platform/frameworks/base/core/res/res/xml/power_profile.xml. For guidance on these settings, see Power Values.
The power_profile.xml
also holds a value called battery.capacity
which can be read via the API. This value also holds the maximum capacity of the battery.
To get the power_profile.xml
for your device, do the following:
- Use ADB to get the the framework-res.apk:
adb pull /system/framework/framework-res.apk
- Follow these instructions to get a readable version of
power_profile.xml
- Path to the extracted file is:
framework-res/res/xml/power_profile.xml
So depending on how a developer chooses to get the "charge at full capacity" value, he may get different results. Especially when I look at the driver file for the Huawei Honor 6, one can see that there are different values depending on the used battery type.
One could assume that a lazy manufacturer does not update the files in the driver or the power profile appropriately for the used battery, which in return causes the different values.
Form a developers perspective the second method is more attractive and easier to implement (again, see this answer). The first method needs access to the Android file system and root privileges.
No comments:
Post a Comment