NlpWakeLock and NlpCollectorWakeLock Discussion

PhilipL

Senior Member
Jun 2, 2007
714
523
0
Hi

found this and it's about wakelocks so yeah http://forum.xda-developers.com/showthread.php?t=1827676 thought it might help us understand and have a unified answer on how to maximize our battery lives
Wake-locks are misunderstood unfortunately which can lead to a dead end.

Many apps can show tens or hundreds of wake locks but they haven't caused any battery drain. An app can only have a wake-lock if the phone is already awake. A wake-lock just says, "Hey phone, I'm busy doing something which if you went to sleep now it might cause a problem". For example saving something to a file or downloading/uploading some data which would become corrupt if the phone just went into deep sleep. Many times these wake-locks are taken then released in milliseconds and we were using the phone anyway. Many wake-locks are taken and released because we have turned on the phone to do something with it.

Wake-locks may cause battery drain when an app is badly programmed, for example an app takes a wake-lock but fails to release it. The phone then stays awake, although the screen will go blank and look off, the phone is on and not in sleep mode. The phone then runs down much more quickly over the course of a day or hours because it is actually constantly on. Typically apps are well behaved these days and release the wake lock correctly.

The NlpWakeLock and NlpCollectorWakeLocks are a symptom but not the cause. The cause is location code that runs in Google Play Services that uses the AlarmManager in Android to constantly turn the phone on every few seconds to get a location update. The AlarmManager uses a real-time clock separate from the main CPU and can be told to wake the phone up from deep sleep at X time or every X seconds. Essentially this wake-up is the same as us pressing the power button, except the wake-up keeps the screen off as Android knows it wasn't a user initiated wake-up.

When this alarm runs, the phone wakes up (but screen stays off so we are unaware this is happening), Google Play Services location code gets a message to say "Hey, this is your wake-up call", at that point Google code knows it is time to do a location check. In order to keep the phone awake while this check takes place and data is exchanged with Google services, the NlpWakeLock and NlpCollectorWakeLocks are taken, a location fix is obtained, Google Play Services then sets another alarm for a some seconds later and releases the wake locks. The phone immediately sleeps again, maybe after only a second or so, but is then woken not many seconds later for another location check, and so it goes on.

The problem is the frequency of wake-ups, ideally our phones should sleep and never wake up unless we receive a phone call or text message or turn the phone on to use it. Each time the phone wakes up power is drawn for the CPU to run, and power is also used in the action of transmitting data back to the Google mother-ship and reading from other sensors, and when this happens every few seconds it soon depletes the battery.

There is no bug here. It is all by design. Google needs to get frequent location updates to find out if we are moving and how fast, it can then offer us things related to that, for example how far we might have cycled or walked, or gather info regarding traffic congestion. The end goal is marketing to us based on our activity and location. To do this needs a high sampling rate. Prior to Google working out our current activity which is a fairly new thing, they were just concerned with our location, and typically just fired the phone up every 10 minutes or so to get a location and we didn't notice the power drain as it didn't amount to much.

Google are collecting this activity data whether we use it or not, and that collection is enabled when we Agree to the terms and conditions seen when turning on location services.

I guess the other plan with always collecting this data is to make us accustomed to poorer battery life and it becomes the norm for us. This way Google can come out with some new nifty marketing thing based on our activity and location to raise their profits and tell us it will use no more battery power. Apps like Tasker can sell on the basis of being battery friendly because they use the Google location data for things like Geofencing, and as for most people Google location code is already on and draining the battery will see no extra usage.

The answer is simple, we either all boycott Google until they give us better control over this so we can opt not to share this activity data, but still get the benefit of Wi-Fi location services (unlikely to happen), or we just turn location services off or use GPS only.

Google have nothing to fix, this is all by design.

Regards

Phil
 

the7thson

Senior Member
Sep 20, 2008
554
68
48
Denver, CO
Hi



Wake-locks are misunderstood unfortunately which can lead to a dead end.

Many apps can show tens or hundreds of wake locks but they haven't caused any battery drain. An app can only have a wake-lock if the phone is already awake. A wake-lock just says, "Hey phone, I'm busy doing something which if you went to sleep now it might cause a problem". For example saving something to a file or downloading/uploading some data which would become corrupt if the phone just went into deep sleep. Many times these wake-locks are taken then released in milliseconds and we were using the phone anyway. Many wake-locks are taken and released because we have turned on the phone to do something with it.

Wake-locks may cause battery drain when an app is badly programmed, for example an app takes a wake-lock but fails to release it. The phone then stays awake, although the screen will go blank and look off, the phone is on and not in sleep mode. The phone then runs down much more quickly over the course of a day or hours because it is actually constantly on. Typically apps are well behaved these days and release the wake lock correctly.

The NlpWakeLock and NlpCollectorWakeLocks are a symptom but not the cause. The cause is location code that runs in Google Play Services that uses the AlarmManager in Android to constantly turn the phone on every few seconds to get a location update. The AlarmManager uses a real-time clock separate from the main CPU and can be told to wake the phone up from deep sleep at X time or every X seconds. Essentially this wake-up is the same as us pressing the power button, except the wake-up keeps the screen off as Android knows it wasn't a user initiated wake-up.

When this alarm runs, the phone wakes up (but screen stays off so we are unaware this is happening), Google Play Services location code gets a message to say "Hey, this is your wake-up call", at that point Google code knows it is time to do a location check. In order to keep the phone awake while this check takes place and data is exchanged with Google services, the NlpWakeLock and NlpCollectorWakeLocks are taken, a location fix is obtained, Google Play Services then sets another alarm for a some seconds later and releases the wake locks. The phone immediately sleeps again, maybe after only a second or so, but is then woken not many seconds later for another location check, and so it goes on.

The problem is the frequency of wake-ups, ideally our phones should sleep and never wake up unless we receive a phone call or text message or turn the phone on to use it. Each time the phone wakes up power is drawn for the CPU to run, and power is also used in the action of transmitting data back to the Google mother-ship and reading from other sensors, and when this happens every few seconds it soon depletes the battery.

There is no bug here. It is all by design. Google needs to get frequent location updates to find out if we are moving and how fast, it can then offer us things related to that, for example how far we might have cycled or walked, or gather info regarding traffic congestion. The end goal is marketing to us based on our activity and location. To do this needs a high sampling rate. Prior to Google working out our current activity which is a fairly new thing, they were just concerned with our location, and typically just fired the phone up every 10 minutes or so to get a location and we didn't notice the power drain as it didn't amount to much.

Google are collecting this activity data whether we use it or not, and that collection is enabled when we Agree to the terms and conditions seen when turning on location services.

I guess the other plan with always collecting this data is to make us accustomed to poorer battery life and it becomes the norm for us. This way Google can come out with some new nifty marketing thing based on our activity and location to raise their profits and tell us it will use no more battery power. Apps like Tasker can sell on the basis of being battery friendly because they use the Google location data for things like Geofencing, and as for most people Google location code is already on and draining the battery will see no extra usage.

The answer is simple, we either all boycott Google until they give us better control over this so we can opt not to share this activity data, but still get the benefit of Wi-Fi location services (unlikely to happen), or we just turn location services off or use GPS only.

Google have nothing to fix, this is all by design.

Regards

Phil
That's all fair, but nothing prevents us from wrestling some of this control back from Google over our own phones, which is exactly what we're doing here - many of us successfully I might add.
 

PhilipL

Senior Member
Jun 2, 2007
714
523
0
Hi

That's all fair, but nothing prevents us from wrestling some of this control back from Google over our own phones, which is exactly what we're doing here - many of us successfully I might add.
I quite agree. The more control we can back the better.

At some point I think Microsoft will get hold of all this activity data gathering and use it against Google in the same way they have for Google reading emails.

Regards

Phil
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
turning off location reporting and location history did not fix these wakelocks on my device(while my phone is supposed to be in deep sleep). woke my phone up 98 and 46 times just while i was in the shower

im testing right now, but i think it might have to do with battery saver location mode. i have it on device only now, and am testing it with the screen locked. i will report back

edit - this has seemed to fix my wakelocks during temporary testing(20 minutes, like my shower). i kept google now on and location reporting/history with device mode gps and no wakelocks during brief testing. im gonna test device only gps mode vs my battery saver mode during usage as well as a full nights sleep tonight.

i wonder why some people are getting positive results by just turning off location reporting/history, but i did not. maybe it has to do with distance from cell towers or something that keeps my device up on battery saver mode gps
 
Last edited:

LeoRex

Senior Member
Nov 30, 2012
514
256
0
Leominster MA
Could they just let us pick our update interval????!

Really.... that's all I ask. There is no technical reason, that I can think of, to have Google Now check THAT often.

I know it isn't a bug... It's designed that way. But I like to tinker, and this is a good, juicy, technical problem for me to solve. It's my mana. :)
 

Sensamic

Senior Member
Jul 27, 2010
788
85
0
turning off location reporting and location history did not fix these wakelocks on my device(while my phone is supposed to be in deep sleep). woke my phone up 98 and 46 times just while i was in the shower

im testing right now, but i think it might have to do with battery saver location mode. i have it on device only now, and am testing it with the screen locked. i will report back

edit - this has seemed to fix my wakelocks during temporary testing(20 minutes, like my shower). i kept google now on and location reporting/history with device mode gps and no wakelocks during brief testing. im gonna test device only gps mode vs my battery saver mode during usage as well as a full nights sleep tonight.

i wonder why some people are getting positive results by just turning off location reporting/history, but i did not. maybe it has to do with distance from cell towers or something that keeps my device up on battery saver mode gps
Where are those optiosn to disable location reporting/history? I have my location turned off always. Do I need to do something else to disable those options you mention or disabling location is enough?

Today I woke up and my phone's battery was 0% when last night it was 98%!!! And WIFI was off, sync off, airplane mode on, etc.
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
Where are those optiosn to disable location reporting/history? I have my location turned off always. Do I need to do something else to disable those options you mention or disabling location is enough?

Today I woke up and my phone's battery was 0% when last night it was 98%!!! And WIFI was off, sync off, airplane mode on, etc.
you'll need to look at 'better battery stats' stats/wakelocks if you want to know what really happened. that sounds like a lot of drain though

im pretty sure that once you turn location off, location reporting/history gets disabled too. but you can check this in your location page in settings. it's at the bottom. it will probably be greyed out if it's disabled(like location is for you)
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
so that's lame. using gps only removes the ability to let google now use your location. . .for some reason. so im giving up on google now location features. ill keep it on but with location off and ill use a weather app to get my updates. it's pretty sad that we even have to do that

i will keep working on getting tasker to work at disabling and enabling my gps, but i couldn't get it to work yesterday. positive thoughts!
 
  • Like
Reactions: Remoteconcern

Remoteconcern

Senior Member
May 27, 2011
769
292
0
so that's lame. using gps only removes the ability to let google now use your location. . .for some reason. so im giving up on google now location features. ill keep it on but with location off and ill use a weather app to get my updates. it's pretty sad that we even have to do that

i will keep working on getting tasker to work at disabling and enabling my gps, but i couldn't get it to work yesterday. positive thoughts!
Why not just disable location reporting and history? O understand that's not the point of this thread but it does fix the majority of drain. I keep mine on like this for very very minimal impact on battery.
 

msgfromside3

Senior Member
Nov 23, 2010
741
131
0
so that's lame. using gps only removes the ability to let google now use your location. . .for some reason. so im giving up on google now location features. ill keep it on but with location off and ill use a weather app to get my updates. it's pretty sad that we even have to do that

i will keep working on getting tasker to work at disabling and enabling my gps, but i couldn't get it to work yesterday. positive thoughts!
Just wondering which G Now features are not available by using gps only. It seems weather is okay to me although G Now complains.

Sent from my Nexus 5 using Tapatalk
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
Why not just disable location reporting and history? O understand that's not the point of this thread but it does fix the majority of drain. I keep mine on like this for very very minimal impact on battery.
disabling both location reporting and history does nothing to change my wakelocks when the device is trying to be in deep sleep mode


Just wondering which G Now features are not available by using gps only. It seems weather is okay to me although G Now complains.

Sent from my Nexus 5 using Tapatalk
when i put location to GPS/device only and open google now, instead of seeing my weather widget, it tells me to turn on location for location cards to work
 

LeoRex

Senior Member
Nov 30, 2012
514
256
0
Leominster MA
disabling both location reporting and history does nothing to change my wakelocks when the device is trying to be in deep sleep mode
Those two remove some, not all, location wakelocks. There are two sides; the service that updates the current location, and the apps that access your location. Dropping reporting and history stops the former, but the latter still occurs as the overall location service is still active (but not updating)

There are a bunch of wakelocks in play... the trick is finding which ones can be blocked without screwing up things. I think I'm almost there actually.
 

msgfromside3

Senior Member
Nov 23, 2010
741
131
0
A Weather app may use GPS. Google Now well lose traffic notifications, 'events nearby', directions to your recent searches.... probably more.
Yup. Weather works for me. I dont care about the rest of the location based info so I didn't notice that. Thanks.

Sent from my Nexus 5 using Tapatalk
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
Those two remove some, not all, location wakelocks. There are two sides; the service that updates the current location, and the apps that access your location. Dropping reporting and history stops the former, but the latter still occurs as the overall location service is still active (but not updating)

There are a bunch of wakelocks in play... the trick is finding which ones can be blocked without screwing up things. I think I'm almost there actually.
that sucks :( and very well might be how it is. i just know that i took a shower and the phone had 100 wakelocks from one of these and then 60 wakelocks from the other. in only a 20 minute span. i just want my device to sleep at night. im looking into some tasker automation for this and hoping for the best
 

LeoRex

Senior Member
Nov 30, 2012
514
256
0
Leominster MA
that sucks :( and very well might be how it is. i just know that i took a shower and the phone had 100 wakelocks from one of these and then 60 wakelocks from the other. in only a 20 minute span. i just want my device to sleep at night. im looking into some tasker automation for this and hoping for the best
If you use tasker and Secure Settings, you can toggle Google Location Services when the screen is off (if 4.3 or before). Or you can use Xposed and wakelock terminator to block the wakelocks completely (works really well)...

tasker some won't do it alone
 

Enddo

Senior Member
Oct 31, 2013
1,977
845
143
Atlanta, Ga.
www.AndroidExplained.com
If you use tasker and Secure Settings, you can toggle Google Location Services when the screen is off (if 4.3 or before). Or you can use Xposed and wakelock terminator to block the wakelocks completely (works really well)...

tasker some won't do it alone
yup, i was using secure settings when testing. but im on 4.4.2 of course. i think i got it working on my n4, but it was working like 95% of the time. a couple times when i tested it, location wasn't being turned off.could have been user error.

and i use art, so no xposed for me sadly. but thank you for the suggestions
 

JazzMozz

Senior Member
Dec 21, 2010
237
25
0
yup, i was using secure settings when testing. but im on 4.4.2 of course. i think i got it working on my n4, but it was working like 95% of the time. a couple times when i tested it, location wasn't being turned off.could have been user error.

and i use art, so no xposed for me sadly. but thank you for the suggestions
Mind sharing your settings?

Sent from my Nexus 5 using xda app-developers app
 

LeoRex

Senior Member
Nov 30, 2012
514
256
0
Leominster MA
The consent pop up is a bit of a pain... Only way to get rid of that is to use yet another Xposed module... which doesn't work with KitKat yet.

Without Xposed, there will always be something to annoy you about the process unfortunately.
 

jdec529

Senior Member
May 3, 2012
319
74
0
I have been able to greatly reduce mine by turning lacatiin sharing and history off, location to battery savings and setting up tasker to turn WiFi off when I'm not home. Also have to make sure you have WiFi scanning always available off. In 6 hours I have about 100 wake lock from Google services but its only for a total of 30 seconds. What I feel helped the most was turning WiFi off when I'm not connected to a network and making sure wifi scanning always available off. Try it out and let me know if it helps.

Sent from my Nexus 5 using Tapatalk