Where are the battery capacity files located?


Question

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:




  1. Reading from the sysfs file in the Android file system (/sys/devices/power_supply/battery/charge_full_design).

  2. 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.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes