FORUMS
Remove All Ads from XDA

Give us BATTERY_STATS back

4,748 posts
Thanks Meter: 17,408
 
By chamonix, Recognized Contributor on 16th November 2013, 10:57 AM
Post Reply Email Thread
If you already got your Nexus 5 or installed a custom Kitkat ROM you already have noticed that your favorite battery stats tool, whether it is BetterBatteryStats, GSam of wakelock detector, does not work.

Well it is not uncommon for some API to be changed so when a new Android version comes out it usually takes us a few days to get hands on a device and fix things.
But this time is different and important enough for me to take time to summarize the situation.

A little history
Android has a service called 'batteryinfo' that collects a lot of info about what goes on on your phone. That service is not perfect but it provides some pretty important information about what is important to our battery monitoring apps: an insight into what drains our battery.
Our apps communicate with that service and therefore claim the android.permission.BATTERY_STATS permission protecting the access to that service. This permission is of the category "dangerous", notifying users of the fact that they should check why an app requires that permission. For a battery monitoring app it is logical to require it.

This change of course impacts devs as their apps became unusable with that release with no perspective for a fix without an expensive workaround (as e.g. already implemented in BetterBatteryStats 1.15+).

But more alarming, it prevents users to get an insight in what drains their battery and make decisions to keep or drop apps depending on the 'cost' in terms of battery life!
If I was a conspiration theorist I may believe that this change was made on purpose to prevent users from seeing how all the pre-installed apps - including those from google - affect their user experience by reducing the battery life / usability.

What happened
With kitkat starting to ship things happened pretty fast and first feedbacks started to emerge reporting that the service could not be contacted. It took me some time to get hands on a kitkat phone (in fact I flashed my gnex with an inofficial ROM and had to make sure that the errors I got were not cause by that ROM and corresponded to the behavior on a Nexus 5.

After some research two changes in 4.4 are responsible for the problem:
1. batteryinfo was renamed to batterystats
2. the BATTERY_STATS permission has been unavailable to apps (moved from protectionLevel 'dangerous' to 'signature|system'
This is the change preventing apps to be granted that permission: https://android.googlesource.com/pla...5167f63f8db87b
As you can see the change refers to an issue number but this issue is not documented in the public tracker (welcome to not-really-open-source).

I have posted a request on the android-platform forum to request a clarification on why that change was made (https://groups.google.com/forum/#!to...rm/f-7Td9aeFKY) but DID NOT GET ANY satisfying feedback. Therefore I have filed an issue in the public bug tracker for this change to be rolled back (https://code.google.com/p/android/is...&ts=1383910497).

I kindly invite you to upvote this request by staring it.
Please star it, adding a comment "I vote for this" or "Please undo this" to the thread does not do any good:
- comments are not counted, only stars
- that forum is not there to express opinions, it's for bug reports and requests. Unrelated matters like opinion will have no other result than annying the reader.


What devs should know
1. BATTERY_STATS has been moved to protectionLevel=18 (signature|system) and is not accessible to apps anymore
2. On KitKat copying an app to /system/app does not grant protectionLevel=18 anymore. This has been changed in KitKat and the target directory to gain those rights is /system/priv-apps
3. The service delivering battery stats was called 'batteryinfo' in previous Android version and is called 'batterystats' in KitKat

[update 2013-11-16]
*dream out loud*
In an open source world the community owns the source right? Wouldn't it be cool if some senior android devs would review this change and - assuming there is no good reason for it - would revert it in their fork to provide their users with what I believe is an important feature?
[/update]
The Following 56 Users Say Thank You to chamonix For This Useful Post: [ View ] Gift chamonix Ad-Free
 
 
19th November 2013, 08:13 AM |#2  
chamonix's Avatar
OP Recognized Contributor
Berlin
Thanks Meter: 17,408
 
10101010
More
I really would like to hear from some senior devs maintaining a repo about the idea of taking control and reverting that change
The Following 2 Users Say Thank You to chamonix For This Useful Post: [ View ] Gift chamonix Ad-Free
21st November 2013, 10:20 PM |#3  
chamonix's Avatar
OP Recognized Contributor
Berlin
Thanks Meter: 17,408
 
10101010
More
Google has release 4.4_r1.2 and still no joy.

Changes are here:
https://android.googlesource.com/pla...droid-4.4_r1.2
The Following 3 Users Say Thank You to chamonix For This Useful Post: [ View ] Gift chamonix Ad-Free
1st December 2013, 03:15 PM |#4  
Member
Flag Austin
Thanks Meter: 56
 
More
Re-enable BATTERY_STATS in a custom ROM
I wrote up a post in another thread about what a ROM developer can do to re-enable Battery Stats (non-root) in a custom Rom. Very simple, but wanted to point it out should anybody be wondering...

http://forum.xda-developers.com/show...3&postcount=26
The Following 2 Users Say Thank You to gsamtan For This Useful Post: [ View ] Gift gsamtan Ad-Free
7th June 2016, 02:17 PM |#5  
oF2pks's Avatar
Senior Member
Thanks Meter: 287
 
More
For CM2016' KitKats only
Quote:
Originally Posted by chamonix

I really would like to hear from some senior devs maintaining a repo about the idea of taking control and reverting that change

http://forum.xda-developers.com/andr...ghtly-t3393825
Does it make sense ?
Thanks for any help.
30th June 2016, 11:05 PM |#6  
chamonix's Avatar
OP Recognized Contributor
Berlin
Thanks Meter: 17,408
 
10101010
More
Quote:
Originally Posted by oF2pks

http://forum.xda-developers.com/andr...ghtly-t3393825
Does it make sense ?
Thanks for any help.

Can you help me understanding what this mod/change is about? My suggestion was about reverting a change that was made by google to restrict the access to a certain permission. You link is to a post with a title suggesting something like blocking the ability for apps to hold wakelocks. Such a stunt would be a really bad idea IMHO but maybe I missed an important point
The Following User Says Thank You to chamonix For This Useful Post: [ View ] Gift chamonix Ad-Free
1st July 2016, 12:57 AM |#7  
oF2pks's Avatar
Senior Member
Thanks Meter: 287
 
More
idea of taking control
Quote:
Originally Posted by chamonix

suggesting something like blocking the ability for apps to hold wakelocks. Such a stunt would be a really bad idea IMHO

Thanks for feedback; i'm real fan of wakelock-blocker's theory, and was wondering if :
- is it useful ?
- can it help user to take control on any kind of restriction ?
I found that completely awesome under KK (static use) but i was very disappointed on testing with LP (anarchic behaviour). BetterbatteryStats was the best observer i found around, and i thought that both were complementary; indeed Beanstalk did use use both with KK: wakelock-blocker' mod and performance/wakelock(similar to your top-app) from Omnirom. But with Omnirom, the mod was rejected : https://gerrit.omnirom.org/#/c/9266/ ; to quote you ("some senior devs maintaining a repo about the idea of taking control"), this link show how much they do ?
Recently, I discover that Beanstalk (6?) was pushing this complementary further forward: https://github.com/scotthartbti/andr...6d5f12f028736b
I hope there was not too much confusion or loose in my first post and i believe BetterBatteryStats is a better option that can be toggled at any time. (I won't get a lot of thanks with my KK thread....)
Post Reply Subscribe to Thread

Tags
battery_stats kitkat

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes