How does Doze/Standby feature affect location updates?

浪子不回头ぞ 提交于 2021-02-05 22:23:08

问题


Does anyone know if a whitelisted app that is holding a partial wake-lock can receive location updates while the device is in Doze or the app is in Standby?

The Android docs (http://developer.android.com/training/monitoring-device-state/doze-standby.html) only state that CPU and network are deferred and do not mention any affect on location updates (i.e. from the LocationManager). Based on this, it would seem that location updates are not affected by Doze/Standby, so if an app is holding a partial wake-lock (to keep the CPU running) then the app should be able to receive location updates.

I've implemented this and tested it and found that an app does not appear to receive location updates in Doze even though it has a partial wake-lock and is whitelisted. Interestingly, when I left the device on my desk overnight running the app with the wake-lock, the battery was nearly empty in the morning, but when repeating with the app without the wake-lock, the battery was nearly full in the morning. So it does appear that the app was running the whole time, but was not receiving location updates.

A little extra background: The app is used for fleet tracking, so we're trying to figure out if there is anyway for an app to have a background service running that reliably receives location updates when running on battery power.

Thanks! -Tom B.


回答1:


Yes, this seems to be another undocumented restriction in Doze mode, as my test logs also show. My guess was that some hardware features like GPS are generally turned off in Doze, but maybe it's the LocationManager being disabled altogether.

As this might just be a severe lack of documentation, the battery drain you mention should definitely not happen in Doze, as that's exactly what Doze is meaning to prevent in the first place.

You may want to file a bug report about all this at https://code.google.com/p/android/issues/list




回答2:


For getting location updates when phone is in idle mode, app should be whitelisted, had partial wake-lock and also should not be on the same locatoin (if you are in the same location you don't need updates). I tested this with Mock Locations, which was giving fake location while phone was on my desk.




回答3:


In my experience location updates are still received when in Doze but only when you use a foreground notification together with the methods you described. Network calls don't work.

Be aware of some stackoverflow posts indicating to just use the permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Your app will be rejected from the play store when you define this permission in your manifest due to "device & network abuse" https://play.google.com/about/privacy-security/device-network-abuse/.

There's also a way to manually request this permission with an intent. I don't know if it's also prohibited that way. The whole whitelisting principle is a little vague to me.



来源:https://stackoverflow.com/questions/33320695/how-does-doze-standby-feature-affect-location-updates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!