eldade / UIDeviceListener

Obtain power information (battery health, charger details) for iOS without any private APIs.
GNU General Public License v3.0
240 stars 38 forks source link

Is it possible to calculate battery usage when the device is charging? #5

Open zhuominjie opened 7 years ago

zhuominjie commented 7 years ago

When plugged in, the battery will increase. Is it possible to calculate battery usage when the device is charging? How?

eldade commented 7 years ago

I've spent some time looking into this and concluded it wouldn't be possible based on the information currently available from this interface. Having spent some time hacking the gas gauge chips on iDevice batteries, I can tell you that I do not believe the device has the information at all.

Basically, while you DO know the wattage/amperage of the plugged-in adapter, the InstantAmperage key is calculated by the gas gauge chip attached to the battery.

InstantAmperage indicates the current going into the battery while charging, but the current is usually lesser than the maximum current available from the adapter because the charging algorithm almost always sets charging current to lower than the available current (for safety, prolonged battery life, etc.)

In the very early stages of charging (when the battery is less than 30-50% full), you might be able to guess by subtracting the power adapter's amperage from InstantAmperage, but this wouldn't work on every device. For example, an iPhone plugged into an >2A adapter just wouldn't use all of that juice, so InstantAmperage would be useless.

One tip I can provide is that the ChargerConfiguration key provides the current desired charging amperage, in mA. As the battery fills up it drops in several "steps", like 3 or 4 steps until the battery is full. It is not accurate though, so not usable for this purpose.

zhuominjie commented 7 years ago

Thanks for your informative answer. It's seems a impossible mission. Another question, please. I want to get App battery usage for internal test. iOS 8 provides the private framework to get 'powerLog', although not quite precise. Do you know any other way to get App battery usage in most iOS system?