Give us BATTERY_STATS back

Search This thread

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro
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/pl...it/+/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 a request 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.
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]
 
Last edited:

chamonix

Recognized Contributor
Nov 7, 2008
5,048
19,623
Berlin
Google Pixel 6 Pro

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
 
  • Like
Reactions: oF2pks

oF2pks

Senior Member
May 22, 2016
819
1,116
idea of taking control

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/and...mmit/5fb687ae0940a12c8f7c9e457b6d5f12f028736b
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....)
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 56
    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/pl...it/+/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 a request 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.
    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]
    3
    Google has release 4.4_r1.2 and still no joy.

    Changes are here:
    https://android.googlesource.com/platform/frameworks/base/+/android-4.4_r1.2
    2
    I really would like to hear from some senior devs maintaining a repo about the idea of taking control and reverting that change
    2
    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://xdaforums.com/showpost.php?p=48029013&postcount=26
    1

    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