FORUMS
Remove All Ads from XDA

[XPOSED MODULE][MOD] Enable BATTERY_STATS In KitKat

44 posts
Thanks Meter: 56
 
Post Reply Email Thread
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/is...etail?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.getStati stics() 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: https://github.com/GSamLabs/EnableBa...tatsPermission

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.
https://github.com/rovo89/XposedBrid...pment-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/GSamBatt...-RootCompanion

Where do I download it?

I've attached the APK to this thread, but will also make it available in the Xposed modules repo.
Attached Files
File Type: apk EnableBatteryStatsPermission_1.2.apk - [Click for QR Code] (15.0 KB, 12804 views)
The Following 33 Users Say Thank You to gsamtan For This Useful Post: [ View ] Gift gsamtan Ad-Free
 
 
9th November 2013, 05:21 PM |#2  
OP Member
Flag Austin
Thanks Meter: 56
 
More
Reserved for future use
Apps confirmed to work with this mod - I'll attempt to keep this list updated as I hear about others...
  • GSam Battery Monitor
  • BetterBatteryStats
  • Wakelock Detector
The Following 2 Users Say Thank You to gsamtan For This Useful Post: [ View ] Gift gsamtan Ad-Free
9th November 2013, 05:31 PM |#3  
ahrion's Avatar
Forum Moderator / Recognized Developer
Thanks Meter: 3,364
 
More
How does one make an Xposed module for a framework that isn't even compatible yet? Better yet, how does one test it?

Sent from my LG-E980 using Tapatalk
9th November 2013, 05:51 PM |#4  
OP Member
Flag Austin
Thanks Meter: 56
 
More
Quote:
Originally Posted by ahrion

How does one make an Xposed module for a framework that isn't even compatible yet? Better yet, how does one test it?

Sent from my LG-E980 using Tapatalk

Fair question - this module is independent of KitKat per se. It works just fine on JellyBean, and other older android versions to enable test, although in the apk I posted it restricts it to KitKat only via the manifest.

One of the goals of this thread - in addition to helping users, is to help developers of monitoring apps with an alternative while we await a decision from Google as to whether they'll restore the battery_stats permission.
10th November 2013, 01:33 AM |#5  
jayRokk's Avatar
Senior Member
Flag Rack City
Thanks Meter: 2,237
 
More
Xposed doesn't work with Kit Kat.
This is useless and misleading.
Change the title.

Sent from my Nexus 4 using xda app-developers app
The Following User Says Thank You to jayRokk For This Useful Post: [ View ] Gift jayRokk Ad-Free
24th November 2013, 12:35 AM |#6  
Jephre's Avatar
Senior Member
Thanks Meter: 37
 
More
It works now, the beta just came out.
24th November 2013, 12:45 AM |#7  
crazyguns's Avatar
Senior Member
Flag Northampton
Thanks Meter: 43
 
Donate to Me
More
Not sure if this module works as it should, my battery monitor widget still shows n/a for screen on time.. Other modules like notification mod and xblast work so xposed is working..

Running cataclysm 4.4 rooted of course

-Nexus 5 32gb
24th November 2013, 02:21 AM |#8  
jayRokk's Avatar
Senior Member
Flag Rack City
Thanks Meter: 2,237
 
More
Quote:
Originally Posted by crazyguns

Not sure if this module works as it should, my battery monitor widget still shows n/a for screen on time.. Other modules like notification mod and xblast work so xposed is working..

Running cataclysm 4.4 rooted of course

-Nexus 5 32gb

Now it does work.
For the other guy going crazy over comment, please check my posting date. At the time xposed and all xposed modules were not working.





Quote:
Originally Posted by Jephre

It works now, the beta just came out.



Sent from my Nexus 4 using xda app-developers app
25th November 2013, 12:39 AM |#9  
OP Member
Flag Austin
Thanks Meter: 56
 
More
Quote:
Originally Posted by crazyguns

Not sure if this module works as it should, my battery monitor widget still shows n/a for screen on time.. Other modules like notification mod and xblast work so xposed is working..

Running cataclysm 4.4 rooted of course

-Nexus 5 32gb

I posted a new update (1.1) that also hooks the ServiceManager.getService method which will allow apps using the old 'batteryinfo' service to work. I've confirmed this works with a few different apps now...so pull the latest and give it another try...
The Following 2 Users Say Thank You to gsamtan For This Useful Post: [ View ] Gift gsamtan Ad-Free
25th November 2013, 12:51 AM |#10  
crazyguns's Avatar
Senior Member
Flag Northampton
Thanks Meter: 43
 
Donate to Me
More
Can confirm it works!

-Nexus 5 32gb
25th November 2013, 01:04 AM |#11  
schwartz.matthew.e's Avatar
Senior Member
Thanks Meter: 143
 
More
Quote:
Originally Posted by crazyguns

Can confirm it works!



-Nexus 5 32gb

Mine works as well on my s4. Running vanilla 4.4 aosp.

Sent from my SCH-I545 using Tapatalk
Post Reply Subscribe to Thread

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

Advanced Search
Display Modes