Resolve Google Play Services Keep Awake and wakelocks killing your battery

Update 12/22/2014-

I’ve come across another excellent method of resolving these GPS wake locks! As seen in this forum thread here, if you are running into very poor battery performance after running your GPS (for instance if using Waze in the morning on the way into the office, especially if the issue is resolved after a reboot, you should use the ‘rename Gsiff daemon’ method first, before trying the rest below.

You’ll know if you’re impacted when using Wakelock Detector or CPU monitor and you see the ‘gsiff_daemon’ process at the top of the CPU consumption list during a trace.  From my research, the process involved polls for screen rotation and acceleratorometer data when your GPS has been turned on, most likely to allow for highly responsive rotation of the map when using a direction finding app, or to tell if you’re still moving, which would be used to update your location on a fitness tracking app, or things like that.


In addition to being a PowerShell and System Center guy, I also LOVE me some Android. Anyone who has had an Android phone before the modern generation of monster batteries can relate to seeing Google Play Services completely eating up all of their devices battery over the course of the day.

The Problem

omgNoBattery
OMG where’s my battery?!

The reason for this is that for the last year or so, Google has been recommending developers use Google Play Services for Android Device location GPS functionality which allows for Google Play Services to batch GPS requests, hopefully preserving battery life. However, developers still have access to the native Android location APIs which they could leverage to request device location.

Additionally, no aspect of Google Play Services really keeps a developer from lazily asking


while(retval.Equals(False))
{
 Wait.Seconds (15)
 CurrLocation = LocationClient.getLastLocation()
 boolean retval = GeoFence.contains(CurrLocation);

}

Which would effectively wake the phone every 15 seconds to perform a relatively battery expensive GPS current location check. This is super bad practice, as the Dev should calculate the distance to a geoFence and then if distance is greater than $x kilometers, check every 30 mins, if less than 10 km check every 10 and if less than 1 km check every minute or something along those lines.

The Resolution

Fortunately if you’re using Cyanogenmod on your device, you can use the built-in Privacy Guard feature to limit Google Play Services ability to wake the device, which will permit your device to stay asleep unless you’re actively using it. You can also keep Google Play from being able to keep the phone awake, which will allow your device to sleep quicker, preserving battery for Angry Birds and Pandora.

Keep in mind, there are pros and cons to everything.

Option

Pro

Con

Disable ‘Keep Awake’

Device sleeps much faster

Potentially your GPS could sleep while you’re running or driving somewhere, turning off your location

Disable ‘Wake up’

Device stays asleep when you’re not needing it

Expect delayed output for things like Google Now alerts (based on location), weather apps, anything that depends on location could take a while to spin up

So, it’s not my fault if your everything begins to suck once you do this. The easy thing is that you can make changes, then toss your phone in your pocket and check back later and see if there is a noticable improvement in battery life. You will see in the same UI I’ll show below a long listing of how many times permissions were requested and if they were denied or not.

Consider denied events to be your battery life getting longer and longer 🙂

So, step one, go to settings on your device.  Go down to Privacy.

Screenshot_2014-10-06-09-28-48

Go to Privacy Guard

Screenshot_2014-10-06-09-28-54

Click the three dots / hamburger bun / overflow menu and check the box for Show built-in apps.

Screenshot_2014-10-06-09-29-20

Wait…it takes a LOOONG time to list all of the apps.  Browse down to Google Play Services and then long press on the icon.

Screenshot_2014-10-06-09-29-33

Scroll down to the options and based on the pros/cons above, choose your destiny and toggle some of the options.

Screenshot_2014-10-06-09-30-12Screenshot_2014-10-06-09-30-19

So, after a few days, I’ll check back and let you know how much my battery improves.  But for now, I know that I’ve plugged in my device, which skews the graph, but notice how the precipitous drop of my battery curve stops? That’s where I made the changes to my Google Play Services.

omgBatteryAfter

As I learn more about this change and the effects it can have, I’ll periodically update this page.

I welcome your feedback, and please feel free to correct me if you feel I’ve factually erred somewhere.

Advertisements

13 thoughts on “Resolve Google Play Services Keep Awake and wakelocks killing your battery

  1. eric November 26, 2014 / 12:43 am

    thanks!!

  2. mcguolo (@mcguolo) January 15, 2015 / 11:40 am

    Thank you for the suggestion, it is actually saving my battery!
    I’m looking for the app that is constantly calling google play services to “keep awake” my phone. Is there some way to understand which app is that? I freezed nearly all installed apps, but without luck.

    • FoxDeploy January 15, 2015 / 12:54 pm

      Install wake lock detector. It’s a great app for telling what is waking your phone.

  3. Note4user May 28, 2015 / 7:23 am

    Thx for insightful tip. Where can I find this Wake up and Keep awake buttons in Samsung Note4?

    • FoxDeploy May 28, 2015 / 8:15 am

      Sorry buddy, I have the Note 2, still, and have never received Android updates, so I’m not sure what the User Interface looks like for your phone. Keep in mind that you’ll need to have Cyanogen installed to use this method.

  4. Note4user May 28, 2015 / 8:46 am

    Is the issue caused by the regular location tracking ping which uses the GPS which is a big batt zapper? The location tracking keeps a location history which is used by advertizers/apps to monetize. And the keep awake of the location history tracking is default on. Is this the issue and what this trick teies to solve?

  5. Vasile June 9, 2015 / 6:21 am

    Maps application seem to rely on this so I have a lots of Maps crashes complaining about being unable to lock the awake.

  6. medicd June 20, 2015 / 8:53 am

    I’ve got a Note 4 with lollipop and I can’t find this setting. It’s vzw so I can’t root, but I was able to get wakelock detector to work with their workaround. It’s not too clear which app is waking the phone, but Google Play Services is having tons of wake locks.

    • FoxDeploy June 20, 2015 / 9:33 am

      You must have root to disable a system service like Google Play Service. Until you can root, the best you can do is disable both wifi and GPS based location services.

  7. John December 13, 2015 / 1:30 pm

    Hello, I have a Samsung S4 mini and i have been experiencing this sudden drop of battery,i was watching a movie and I didnt touch my phone for hours and when i looked at the phone it was hot like I wasnt able to hold him in my hands and i force restarted him only to find out that the battery is suddenly 0% when it was around 90%….I cant seem to find these settings on my phone so i dont know how to fix the problem,…………….pls help
    oh and I have root…. is there another way to disable Google play services ? ill try to force stop it whenever I can and ill see the results

  8. Rick June 1, 2016 / 10:24 am

    I accidentally put the privacy guard on the whole google play services. now the phone gets restarted always I turln it on. Not even letting me do anything on it. Now it only seems that I will have to factory reset it which will delete all my files as now I cannot even download files on to my PC. (Phone: Oneplus One)
    Need help ASAP. Thanks.

  9. ChPlaya April 7, 2017 / 6:48 am

    oh, thank a lot, i have just installed in my device

Have a code issue? Share your code by going to Gist.github.com and pasting your code there, then post the link here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s