Shared publicly  - 
 
Google: give us BATTERY_STATS back
#androiddev   
If you already have a device with Android 4.4 kitkat on it you may have noticed that your favorite battery stats tool, whether it is BetterBatteryStats, GSam of wakelock detector, does not work.

Well it is not uncommon that new Android versions break a few apps and it usually takes us a few days for your favorite dev to fix things.
But this time is different and the changes are important enough for me to attempt to draw some attention on this matter.

Some context
Android has a service called 'batteryinfo' that collects info about what goes on on your phone. That service is not perfect but provides some pretty good information to our battery monitoring apps: an insight into what drains the battery. 
To communicate with that service an app has (in fact had) just to claim the android.permission.BATTERY_STATS permission. This permission is (was) 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 pretty logical to require it.

What happened
With kitkat starting to ship things happened pretty fast and first feedbacks started to emerge reporting that the aforementioned service could not be contacted. 
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 make 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/platform/frameworks/base.git/+/3714141d287c965ea3451831dd5167f63f8db87b
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 on the android-platform forum to request a clarification on why that change was made (https://groups.google.com/forum/#!topic/android-platform/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/issues/detail?id=61975&thanks=61975&ts=1383910497).

I kindly invite you to upvote this request by staring it (no comment "I vote for this" or "Please undo this" please, but star the issue)
Update 13th of December 2013
Despite almost 800 votes for that feature it was closed as WorksAsIntended by Google without further information.

Why does all this matter
It matters to me as this change broke my app and forced me to spend a lot of time and effort working around this with some dirty hacks.

It also matters to me because it shows the limit of a platform and an organisaion that only pretends to be open source:
- the source code was released but the reason for that change was not communicated
- there is no way to file a pull request to the code (filing an issue and hoping that it will be considered is not the same)
- decisions to make changes are not transparent to non Googlers 

What could be different
Wouldn't it be great if we could try to change that situation and take control?
A dream would come true if popular Android ROM projects could take control of this kind of changes and decide (or not) to revert them in an open process.

I would really like to hear what +CyanogenMod  +OmniROM  +Paranoid Android or other large projects or recognised dev say about that. 
247
32
Robert Steinhöfel's profile photoYathirajan BM's profile photojoakim wennergren's profile photoJoakim Carlsson Kekonius's profile photo
73 comments
 
+Sven Knispel All the links in your post point to pages that don't exist...  I hope this issue succeeds in drawing some attention.
 
Got my vote! I was using these apps frequently as I am beta testing some apps and battery stats are always helpful in doing this.
 
+Andreas Pirkner the good news is BBS 1.15 now works on kitkat. There are limitations though, due to the change
 
Die playstore Version läuft bei mir nicht unter 4.4. Die xda schon... Ist Da ein Unterschied? 
Translate
 
+Patric Kurth auf gplay und wurde die Version 1.15 heute als staged rollout eingestellt und erreicht so nur eine Teilmenge der User. Leider wird aber allen die aktuelle Beschreibung angezeigt. Du musst Dich also nur etwas gedulden. 
Translate
Translate
Translate
 
I gave the issue a star. Hopefully Google does something about this. I used this app a lot to solve issues. I'm hating KitKat without it and I'm not rooting. 
 
I'm seriously considering to avoid KitKat on all my Nexus devices. First there were reports about the removal of App Ops, now this.
No wonder KitKat needs less hardware resources - they simply removed features. ;-)
 
+Alessandro D I never thought I would do this but I recommend that, you root as it's the only way to stay in control
 
Perhaps +Dianne Hackborncan shed some unofficial light? I've found some of her previous posts on battery management in Android to be pretty insightful. 
 
I upvoted the issue you raised. Things like this should not happen. There is no reason to change permissions without at least explaining what triggered this change.
As a developer my self i can understand your frustration. I hope things will change back as they should.
 
+Daniel Chin I have lost faith since she hasn't replied to that precise question in the android-platform forum. 
 
+Panagiotis Boulougouras this clearly shows the limits of Android not being as open as it is marketed to be. IMHO open does not just mean 'source code thrown at you from time to time' but also transparency about changes and decisions and way for a community to influence decisions. In this case it is also sad as it seems that there is no awareness of how important battery life is for user experience. If I were a consideration conspiration theorist I would say that this change was made on purpose to make sure that user can not find the root cause of their battery drain anymore.
 
This issue has definitely shed new light on the open source aspect of Android. I did not know the situation was like this until now. Makes me wonder what else is like this. 
 
You mention that BBS will now work on KitKat with some dirty hacks. If we revert that single change you linked to, will BBS work as expected?
 
+Adam Farden in a nutshell yes. Due to that change all apps that would communicate with the service up to 4.3 must make changes to accomodate to the new situation and that requires root. The method has not changed and reverting that change would void the need for rooting.
I personally am not a friend of asking users to root their phones because it is a security risk. But in this situation rooting is the only way to get control back.  
 
Thanks, I'm building my own AOSP right now so hopefully I'll be able to use it again on KitKat. This 'fix' is OK for those who already use custom ROMs, but it's gonna get messy when actual devices based on KitKat start coming out.
 
+Adam Farden that is exactly why I have addressed this matter and still have hope that enough devs could revert the change in their repo and take control. To me it is not that much about BBS since I have a fix granting that permission anyway, it's about not letting go the ability to have control of my device. That is the reason I am Android and not iPhone or Windows Phone user.
 
So, because I don't know about another way of asking for my little problem (maybe it's still a feature :-) ), I will try it this way.
I rooted my phone (root is working, cause other apps ask for privileges), but BetterBattery Stats will not ask for these privileges, so in "partial wakelocks" shows only "This stat requires root". 
Maybe is that because Im using ART instead of Dalvik.. so, I will be glad if you explain me if im doing something wrong.
Regards!
 
I was about to ask the same thing. It's not because of ART as I have the same experience with libdvm.so, I guess its just not implemented yet.
 
+Martin Slavík a little OT but I am glad to help: enable the 'root features' in advanced preferences and you will be prompted to grant su rights 
 
Ahh hidden root settings, I don't think I ever looked in the menu before!
 
+Sven Knispel I hate to jump to conspiracy theories, but considering that the worst (and actually, the only) battery draining problems I've had on my S3 have been caused by Google processes and services (especially the calendar sync process's infinite loops, which I've reported over and over again), maybe they are trying to hide their incompetence. :(
 
As a developer learning Android, this type of story does not sit well. +Sven Knispel, thanks for bringing the scenario to light. This practice is a slippery slope that potentially affects many developers in the future should Google decide to make further nontransparent changes such as this. I starred your issue and will follow with interest. 
 
Hi Sven: I'm trying to learn more about batteryinfo and now battery_stats service and I can't find very much information on the web on this subject. I'm trying to write a program that basically does what you see if you go into setting->battery (don't ask me why I'm re-inventing the wheel, it's purely for learning purpose). Your post seems to be the only information on this subject out there. I was wondering if you can point me to some learning material on this subject, it'll be greatly appreciated.
 
You got my star.  Thanks for putting this issue in an arena where ordinary users can have a say.
 
+Cicie Wang sorry for the delayed reply. There is indeed only little information on that matter except the android sources themselve, and the source code of BetterBatteryStats of course.
If you want to see how that API is used by system apps the best place to start would be here: https://github.com/android/platform_packages_apps_settings/blob/master/src/com/android/settings/BatteryInfo.java
The android sources would be here: http://grepcode.com/search/?query=batterystatsimpl
and if you are looking after the way to access that API using reflection this may help: https://github.com/asksven/AndroidCommon/blob/master/src/com/asksven/android/common/privateapiproxies/BatteryStatsProxy.java
 
"there is no way to file a pull request to the code (filing an issue and hoping that it will be considered is not the same)"
Wrong - u can use gerrit to do that.
 
Am using Nexus 4 and on Kitkat. The app does not work. Could you please help me with the procedure to fix it?
 
Me gustaria que esta aplicacion BATTER BATTERY STATS, salga en español, para Android 4.1.2 .
Cuenta con mi voto, y espero que en proximas actualizaciones, mejore la aplicacion. No estoy de acuerdo que algunas aplicaciones salgan SOLO PARA ROOT, eso es MALO.
PLAY STORE DE GOOGLE, no revisa, que ofrecen cda aplicacion y que ocultan, POR QUE tienen que tener accceso, a nuestra informacion PERSONAL, las aplicaciones Instaladas, NO ESTOY DE ACUERDO COMO USUARIO, me apoyan Usuarios que descargan aplicacionde PLA  STORE.
Translate
 
+Rajesh G sure but I'd need some more info. Could you take this to the bbs thread on xda - developers? 
 
Thats why I loved symbian :) 
Google is certainly becoming a vampire everyday. Its turning into microsoft. Sad but true 
 
I can not see any partial wakelocks on my S3 with 4.4.2 Cm. Root is activated. Any ideas? 
Vivek P
 
Same here. Cyanogenmod 11.0 on i9300 with root activated - still cannot see partial wakelocks...
 
guys, this post is not a support thread. Please go to the XDA thread for support related questions
 
Hello. Are you talking about class ApplucationErrorReport.BatteryInfo ? According to the Android sdk reference it still exists...
 
No this post is about the removal of the BATTERY_STATS permission 
 
Yes but you also mention using a batteryinfo/batterystats service where is it documented?
 
It is not documented except in the source code. If you'd like some pointers I can provide that. 
 
why do you still sell this app in playstore and saying in the info screen that you have to root your smartphone. If i do that, i won't have access to play store anymore. So howcome you're still allowed to sell it thru playstore. I now have paid 2 euro's for an not working app.
 
+Kellie DE this is a little OT and I would prefer to have such queries by mail as it is support-related more than about this post. Still, rooting your phone will not have any impact on you being able to use Google Play. If you have problems using BBS please send me a mail and we will sort it out
 
+Vasanth S I am sorry but this thread is not for support questions. Could you please send me a mail? 
Translate
 
It is really very simple .... Google first and foremost wants to protect its information business.  When apps like your expose how badly Google apps like the play store handle battery Google has two choices.  Fix their apps or prevent your app for telling users which apps are draining battery.

You know which one they chose.   Android handles wakelocks very badly.

Another example is the Play Store.  They don't like people posting bad reviews even when the criticism is valid.  So Google has two choices.  Try to improve the quality of apps on the Play Store, or change the rating system so you can't filter or search for bad reviews any more.

You know which one they chose.
 
Ho letto tutto. Ho provato a scaricare il file zip ma non me lo fa installare. Per chi ha android 4.4 è impossibile. O seguono aggiornamenti o senza root è inutile questa app. Mi dispiace.
Translate
 
I am sorry but I can't understand you. English, German or French would be fine
 
Hi sven, on play store you said " root access is required to have access to all the features of BBS" I am not rooted. What features would I have/not have. Thanks.
 
BTW, on a PC you can click on the previous post from "angelo I" and there is a "Translate" button ;)
 
+mark palmos the short version is: without root you will have no use of BBS on 4.4+, thanks to google. 
 
Hiya, on my note 4 u get a translate option... He said: I read everything. I tried to download the zip file but it makes me install. For those with Android 4.4 is impossible. Or follow updates or without root this app is useless. I'm sorry.
 
Bummer about 4.4... Cheers Mark 
 
the reason Google has obuscated this aspect of android is because it gives clear insight to all the process running as Google services. The incessant logging and location tracking even while services are off. Google is a data hungry monstrosity trying to overcompensate for the "free and open source" by laser targeted ad campaigns. Their competition makes money hand over fist with their proprietary software and devices by people who willingly pay top dollar for stuff that has DRM shoved so far up its ass and will never truly be completely available to them. Google leverages Youtube and android so hard because its all they really got. I know the system works well, but in my opinion, the campaign advertising business model is bullsh. It makes everyone involved a straight sellout
 
how to uninstall?
Translate
Add a comment...