Looking for a mod to make the battery indicator more accurate

ubergeek77

Senior Member
Oct 30, 2015
233
77
0
Ever since the March update, my Pixel 3 XL's battery indicator in the status bar has been horrendously inaccurate. This is really annoying, as it always shows as having 10-12% less battery than the actual physical battery charge. If it ever reaches 0% and shuts down, if I were to, say, boot into TWRP, I'd see I still have about 11% battery remaining. Across all the phones I've owned over the years, I've never seen such a severe battery level mismatch before. I've never seen greater than a 2% difference in any phone I've owned.

I use the Advanced Charging Controller Magisk module to regulate how much my battery charges. Charging your phone too much is proven to damage your battery over time, so I like to set ACC up so that my phone never charges past 41%.

I first noticed this problem when my battery would stop charging past 31%. After digging deeper, I found that the battery level produced by "dumpsys battery" (used by the status bar indicator) does not match the actual battery level, which can be read from a kernel control file at "/sys/class/power_supply/capacity."

As a side note, is your battery indicator also incorrect? Try checking it running these commands as root, and compare the values. Maybe this affects you too:

cat /sys/class/power_supply/battery/capacity

dumpsys battery

(The number you're looking for in the "dumpsys" command is the number next to "level." If it doesn't match, and it's less than what's written to the capacity file, then you also suffer from this issue).

I've asked the ACC developer what can be done about this, and apparently not much, besides having ACC "pretend" the battery is offset by a user specified battery level. But in my case, I would just be charging my actual battery to 51%, even though it would display as 41%, and I don't want to do that. I tried fixing it by clearing my battery stats, charging to 100%, and etc, and it actually made matters worse for me - the status bar indicator now remains at 12% less than the actual battery level. No matter what, this value appears to be linear - it doesn't seem to be any more or less correct depending on how charged the battery is. It's always 12% less, unless you get beyond 88%. Then the statusbar pretends to charge, even though a voltage monitor will show that it is not charging.

I can "force" the statusbar to read as the most accurate battery level by running this command in the background in a root shell:

while sleep 15; do dumpsys battery set level $(cat /sys/class/power_supply/battery/capacity); done

This manually sets the battery level via dumpsys according to what the actual battery level is. But this has some limitations.

I'm using a while loop because setting a value like this is permanent - if I don't either continually set it or unset it, my phone will think my battery level hasn't dropped below the last set value.

However, more importantly, setting a value via dumpsys disables monitoring of other battery stats, such as voltage, temperature, current, whether or not the battery is charging, the charge counter, and etc. Just running a script like that isn't a good solution.

So since I have nowhere else to ask, is there any kind of root mod or something that can be made to force the phone to use the correct battery level? I don't know why this started happening since the March update, but it is extremely annoying, and I'd like to put an end to it as soon as possible.

Any insights to mods or tweaks that can be done to fix this would be greatly appreciated.
 
Last edited:
  • Like
Reactions: odontastic

masri1987

Senior Member
Jun 27, 2010
5,912
804
0
Honolulu, Hawaii
so im at 5%, but in /sys/class/power_supply/capacity it says 0 .... not sure what's real anymore

I'm gonna charge up to 100% and see for myself what "full capacity" is like
 
Last edited:

superchilpil

Senior Member
Sep 26, 2009
4,266
1,423
0
28
Texas
If I remember correctly Lithium batteries actually last longer if kept above the 60% range and taken off the charger when they're completely full or maybe a few percent before. It's the lower end of the battery percentage that actually damages the battery if it's kept there for too long. The lower the voltage the higher the resistance in the battery, this is going to cause heat in the battery, so the way you're charging your battery is most likely damaging. I might be wrong but battery tech has changed over the years, and some old misconceptions still exist.


My guess about the amount of difference in the battery display vs percentage is to protect people from this reason. To keep them off of the lower end of the battery because it's damaging to the battery and under the wrong circumstances it could cause the battery to overheat.


Sent from my Pixel 3 XL using Tapatalk
 

masri1987

Senior Member
Jun 27, 2010
5,912
804
0
Honolulu, Hawaii
My guess about the amount of difference in the battery display vs percentage is to protect people from this reason. To keep them off of the lower end of the battery because it's damaging to the battery and under the wrong circumstances it could cause the battery to overheat.


Sent from my Pixel 3 XL using Tapatalk

While I can see that , i'm currently @ 100% in status bar, but 98% in the capacity file. and it won't go above that currently.

This kind of makes sense given how the battery jumps erratically from 100% to 98-06% too when discharging
 

Tulsadiver

Recognized Contributor
Jul 11, 2013
7,761
5,476
253
While I can see that , i'm currently @ 100% in status bar, but 98% in the capacity file. and it won't go above that currently.

This kind of makes sense given how the battery jumps erratically from 100% to 98-06% too when discharging
What are you calling the capacity file? Battery in settings?
 

masri1987

Senior Member
Jun 27, 2010
5,912
804
0
Honolulu, Hawaii
So, just FYI, this is probably why i found charging it in TWRP to be the most accurate...

When i charge my phone up to 100% in twrp, i boot up phone, look at the capacity file and it reflects spot on what the status bar says, and it continues to do that throughout entire discharge.
 

ubergeek77

Senior Member
Oct 30, 2015
233
77
0
If I remember correctly Lithium batteries actually last longer if kept above the 60% range and taken off the charger when they're completely full or maybe a few percent before. It's the lower end of the battery percentage that actually damages the battery if it's kept there for too long. The lower the voltage the higher the resistance in the battery, this is going to cause heat in the battery, so the way you're charging your battery is most likely damaging. I might be wrong but battery tech has changed over the years, and some old misconceptions still exist.


My guess about the amount of difference in the battery display vs percentage is to protect people from this reason. To keep them off of the lower end of the battery because it's damaging to the battery and under the wrong circumstances it could cause the battery to overheat.
The OP of the ACC discussion thread has some good links to studies done on Li-Ion batteries. It's a long read, but the summary is that you'll want to keep your temperatures as low as possible, and the battery itself between 30% to 80%. There are also some factors related to voltage that I don't really understand, but I do know that ACC manages the charging voltage to reduce strain while charging. The recommendation by the ACC developer for longevity is ~41%. That is within the 30% to 80% range, and I trust his judgement.

As for the other concerns in this thread, I don't think the difference in numbers serves any functional purpose other than to be annoying. It turns out that the one shutdown I had previously must have been a fluke, because now the battery in the statusbar will just sit there at 1% while the actual battery capacity ticks down, before forcefully shutting off at around 2% actual capacity. I don't even get the graceful "battery is empty, shutting down" message anymore.

Because the battery level reported by the capacity file is closer to zero than the statusbar one (simply because it shut down when that number was closest to zero), I'm inclined to believe it's the more accurate measurement. It's totally unrealistic to believe that the last 1% of the battery lasts as long as the previous 10%.

I can understand Google making the battery report a lesser number in order to protect the battery from the user, but that argument doesn't work if the phone just sits at 1% forever until it shuts down, which it has been doing for me. And the difference in numbers is just insane. Just today, the statusbar reported 2%, when the system reported 17%. A fifteen percent difference is absolutely absurd. I can understand a modest 3-5%, but this is just ridiculous.

I'm hoping there is a clever solution for this soon, or that the April update addresses it, because it's driving me crazy.
 
Last edited:
  • Like
Reactions: odontastic

smartymcfly

Senior Member
Sep 15, 2012
715
213
0
Why would you only charge your battery to 40%? I understand to prolong the life of the battery, but to what extent is going to do that.

You are shortening the amount of time needed between chargin. How much time does the battery last before you need to charge it again when you only charge it 40%?


If I am misunderstanding this, I think it would make more sense to keep the charge between 40%-80%.... Even if this is the case, how long does a charge last when you only use about 40% of it's capacity?
 

superchilpil

Senior Member
Sep 26, 2009
4,266
1,423
0
28
Texas
The OP of the ACC discussion thread has some good links to studies done on Li-Ion batteries. It's a long read, but the summary is that you'll want to keep your temperatures as low as possible, and the battery itself between 30% to 80%. There are also some factors related to voltage that I don't really understand, but I do know that ACC manages the charging voltage to reduce strain while charging. The recommendation by the ACC developer for longevity is ~41%. That is within the 30% to 80% range, and I trust his judgement.

As for the other concerns in this thread, I don't think the difference in numbers serves any functional purpose other than to be annoying. It turns out that the one shutdown I had previously must have been a fluke, because now the battery in the statusbar will just sit there at 1% while the actual battery capacity ticks down, before forcefully shutting off at around 2% actual capacity. I don't even get the graceful "battery is empty, shutting down" message anymore.

Because the battery level reported by the capacity file is closer to zero than the statusbar one (simply because it shut down when that number was closest to zero), I'm inclined to believe it's the more accurate measurement. It's totally unrealistic to believe that the last 1% of the battery lasts as long as the previous 10%.

I can understand Google making the battery report a lesser number in order to protect the battery from the user, but that argument doesn't work if the phone just sits at 1% forever until it shuts down, which it has been doing for me. And the difference in numbers is just insane. Just today, the statusbar reported 2%, when the system reported 17%. A fifteen percent difference is absolutely absurd. I can understand a modest 3-5%, but this is just ridiculous.

I'm hoping there is a clever solution for this soon, or that the April update addresses it, because it's driving me crazy.
While I agree it's absurd if it in fact is showing a 15% difference, but where is the proof that such a thing is occuring?

I've read a few articles that talk in depth about lithium ion and the takeaway is to charge your device TO 75-80% and remove it at 30. Charging to 40% and completely discharging it is in fact damaging the OP's device and that's what I was trying to say.

Sent from my Pixel 3 XL using Tapatalk
 

ubergeek77

Senior Member
Oct 30, 2015
233
77
0
While I agree it's absurd if it in fact is showing a 15% difference, but where is the proof that such a thing is occuring?
I've already given proof. The proof is that the battery value produced by running "dumpsys battery" does not match the actual battery value, as read by the kernel, under "/sys/class/power_supply/battery/capacity." For clarification, the statusbar uses the value output by "dumpsys battery," which has been the incorrect value for me for almost a month now. SO's Pixel 3 XL is doing the exact same thing.

Further proof is that this offset doesn't serve any functional purpose. You would think that this kind of offset would be a way to protect the battery from the user, but that argument only works if the phone shuts itself down before the actual capacity reaches zero. That doesn't happen.

Instead, once the statusbar reaches 1%, it will just stay there indefinitely until the phone doesn't have enough voltage to keep itself on.

For example, let's say I'm monitoring the battery level in a terminal. When my statusbar says 2%, the kernel reads the battery as being 16%. It takes 10 minutes for the statusbar to reach 1%, and at the same time, the kernel battery reading will show 15%.

However, in a further 10 minutes, the phone does not shut off. Instead, the kernel battery reading will continue to tick down - 14%, 13%, ... 8%, 7%, etc - until the phone shuts off due to low voltage. During this time, the statusbar will continue to display 1%, despite the fact that the actual battery level is depleting.

No graceful shutdown, and the statusbar never reaches 0%. As such, I no longer see the "Battery Empty, shutting off" message where the phone shuts itself down gracefully.
 

odontastic

Member
Aug 30, 2011
40
17
28
I've kept my Pixel 3 XL updated with the latest updates and Kirisakura kernel. ACC (default settings) and my battery was doing fine until around the March update when I started a difference in reported battery level between the status bar and system that worsened and grew to 15% or more (I don't exactly remember). Also the status bar battery level would hang at 1% for a ridiculously long time. After uninstalling ACC and a several of charging cycles it got better (and the April update). Now my difference is 3%.
 
Last edited:

Bryanx86

Senior Member
Apr 8, 2016
769
328
0
RockNRoll
Is this why my phone shuts down at 14% battery level? I'll get a notification my battery is dying, check it, it'll be between 12-15% battery left, shut down 30 seconds later, and I can't reboot bc battery is dead. When I plug it in, then boot back up, it only says it is at 2 or 3%. I'm locked down bl because I thought maybe some root apps were messing with it, and I've even tried on q beta, but still early shutdown issue. Not really bothersome as I get 7 hrs or better screen on time, but it is curious....
 

Topse

Senior Member
Dec 3, 2013
401
744
123
Pforzheim
Is this why my phone shuts down at 14% battery level? I'll get a notification my battery is dying, check it, it'll be between 12-15% battery left, shut down 30 seconds later, and I can't reboot bc battery is dead. When I plug it in, then boot back up, it only says it is at 2 or 3%. I'm locked down bl because I thought maybe some root apps were messing with it, and I've even tried on q beta, but still early shutdown issue. Not really bothersome as I get 7 hrs or better screen on time, but it is curious....
I have a similar situation. It starts with 20-25%.
I think this started for me with q.
I wiped my device and flashed factory image to a/b slot. About 3 times .
How is your device going?

RMA is on the way....
 
Last edited: