Enable BATTERY_STATS for KitKat

    Why is this needed? / Do I need this?

Are you running KitKat or later? Is your battery monitor of choice working? If so, you do not need this. If not, it likely will do the trick - if it does not, contact the battery monitor developer and ask that they read the 'Developers' section of this app.

Google decided to change the BATTERY_STATS permission to be signature|system, which on KitKat means an app cannot access battery statistics. Functions such as identifying which apps are consuming more resources than others will not function. https://code.google.com/p/android/issues/detail?id=61975

Alternatively, copy your app into /system/priv-app which will provide the app access to BATTERY_STATS. Google also changed the name of the service however, so if your app hasn't been updated for KitKat, then using this XPosed module is the best way to go.

    What does this do?

This uses the Xposed framework to provide an alternate implementation of the com.android.server.am.BatteryStatsService.getStatistics() method which will not enforce that the calling application have the BATTERY_STATS permission.

In addition, this allows legacy apps who use the 'batteryinfo' service rather than the 'batterystats' service to continue to function, since the only change was in the name.

    How do I install this?

This mod requires that your device is rooted, that the Xposed framework is installed, and that this module is enabled via the Xposed installer app. After a phone reboot, your battery monitoring apps should start to work as they did before KitKat rolled around.

1. You must have ROOT on your phone. If you do not, this is not for you.
2. Install this package
3. Download and install the Xposed installer if you do not yet have it: XDA Thread
4. Install the “Framework" in the "Xposed Installer" and activate "Enable BatteryStats Permission" in "Modules".
5. Reboot
6. Run your battery monitor of choice.

This app does not 'launch', so don't be surprised to not see any way to start this app.

    Is this safe?

Yes - the code is open source, and very simple. Do keep in mind however that the Xposed framework allows you to enable modules that may be very dangerous - but this module is not one of them. You can find the source here: [url]https://github.com/GSamLabs/EnableBatteryStatsPermission[/url]

    I'm a developer, but my app still doesn't work in KitKat!

Check your logcat. Google also changed how network statistics were retrieved,
removing some methods and replacing them with others (getTcpBytesReceived was
removed for example).

    I'm a developer, can I pull this code directly into my app?

Yes - by all means. Follow the great tutorial that the Xposed author has, and feel free to copy HookGetStatisticsMethodCall class directly into your app. You can find the Xposed tutorial here, along with links to their XDA thread. https://github.com/rovo89/XposedBridge/wiki/Development-tutorial.

That said - I recommend simply copying your app into /system/priv-app/, or using a helper app similar (or identical) to: https://github.com/GSamLabs/GSamBatteryMonitor-RootCompanion

    Where do I download it?

I've attached the APK to this thread (http://forum.xda-developers.com/showthread.php?p=47809546), but will also make it available in the Xposed modules repo.

Version name: 
Release type: 
Stable (low risk of bugs)
Number of downloads: 
224,095 in total · 0 in the last 24 hours
MD5 checksum: 

Removed debug logging to avoid flooding the logs

Version name: 
Release type: 
Stable (low risk of bugs)
Number of downloads: 
11,281 in total · 0 in the last 24 hours
MD5 checksum: 
Version name: 
Release type: 
Stable (low risk of bugs)
Number of downloads: 
11,998 in total · 0 in the last 24 hours
MD5 checksum: