AirGuard icon indicating copy to clipboard operation
AirGuard copied to clipboard

Use Androids passive locationlistener to improve Batterylife

Open Casey1979 opened this issue 1 year ago • 5 comments

Please use the passive locationlistener instead of fused, gps or network location for reduced power consumption. Trigger scans when a locationupdate was received and the duration from the last scan is convenient. Request a locationupdate on your own only when a tracker was found and the last update too long ago to be acceptable. The location toggle in the settings could be renamed to lowpower location, to switch between passive and fused location. Also please stop any powermanagement circumventions like with the foreground service when in low power location mode (or when Airguard wasn't unrestricted by the user anyway) so that Android can handle Airguard with the most powermanagement efficiency even if it might lead to less frequent scans.

This change will probably massively reduce the power consumption from about 6% to less than 2% without harming the detection much if at all. It will probably lead to even more locationupdates than the ones currently requested by just Airguard on its own which could even be useful to trigger more scans while still using less power than before. Also just for the purpose of tracking detection people only need to know from about where to about where the tracking happened and not the exact locations the trackers were found. Only the approximate path where the tracking happened is interesting which will likely even be more detailed than the current 15 minute updates of Airguards own location scanning. Since trackers might not be detected on every scan the start and end locations of the tracking are most likely inaccurate anyway.

Please consider doing this change so that Airguard won't have any noticeable impact on the batterylife anymore while still providing a comparably good and useful detection in the background. An Airguard beta program in the Google playstore might also make sense to test such changes in the wild.

Thank you for the past work and already good app.

Casey1979 avatar Nov 11 '24 21:11 Casey1979

Hi Casey,

How does the background location listener work in Android? We did not read about it when we were implementing the app. One thing that we realized though is that accurate location data is very important. Imagine your last location is 5 min ago and you find a tracker now. In that 5 minutes you could have traveled kilometers by car, which would make it much harder for the user to identify if this tracker is following you or if it was in the meeting you attended 5 minutes ago.

If you can send me more details on the implementation (documentation link is fine) than we can look into it and test it. Aside from battery issues, getting an accurate location currently takes way too long and sometimes fails entirely, which also makes tracking detection less accurate.

Sn0wfreezeDev avatar Nov 12 '24 08:11 Sn0wfreezeDev

Hi, this is the link for the passive Locationprovider https://developer.android.com/reference/android/location/LocationManager#PASSIVE_PROVIDER "A special location provider for receiving locations without actively initiating a location fix. This location provider is always present." "This provider can be used to passively receive location updates when other applications or services request them without actually requesting the locations yourself. This provider will only return locations generated by other providers."

https://developer.android.com/about/versions/oreo/background-location-limits?hl=en "Use a passive location listener, which may receive faster location updates if there are foreground apps requesting location updates at a faster rate."

This may be of interest as well https://developer.android.com/develop/sensors-and-location/location/battery?hl=en

The beauty of it is that you passively receive locationupdates requested by other apps and services after they are ready with no cost attributed to you. You may receive them a bit unsteady but probably more than often enough to be of good use. And if the location should match the scan why not just let the locationupdates drive the scans instead of asking for the location before the scan which currently involves network and gps activity as well as waiting time which makes the app comparably expensive batterywise. Currently i disabled the use of the location in Airguards settings and set the permission to "Allow only while using this app" Which results in no noticeable battery usage attributed to Airguard anymore on a Google Pixel with Android 15. With the passive location updates we could have both at once, locations and efficiency.

For an app that is supposed to do its work silently and efficiently in the background until the user needs to be alerted the passive location listener seems to be an at least optionally perfect way to go.

Thank you for taking a look at this possible impvovement.

Casey1979 avatar Nov 12 '24 09:11 Casey1979

Just want to add that AirGuard has a pro rata battery consumption of 44% at night while the phone is at idle (not moved or used) and flightmode is turned on. That's not much in battery percentage terms, but a reduction would nevertheless be appreciated. First Beta of Android 16.

Perhaps the automatic activation of the low power scan mode could further optimize consumption under certain circumstances? (Couldn't find any detailed/technical description of the regular scan or low power scan mode?)

philblue1 avatar Feb 02 '25 11:02 philblue1

The battery consumption gets caused almost entirely by Airguards location requests and the fact that it does that strictly every 15 minutes no matter what by using a foreground service which helps it to wake up often even when the device is in doze mode and Airguards battery setting is kept at optimized instead of unrestricted.

If you want to reduce Airguards power consumption you can switch off the location usage in the expert settings and then set Airguards location permission to only when in use in the App permissions. You will see that Airguard still logs scans about every 15 minutes but causes a lot less battery consumption anymore.

Low power scan mode vs normal mode makes a negligible difference. From my understanding Aiguard handles the BLE scans itself according to its needs in normal mode while it asks the system to perform a scan and gets the result back in low power mode where the scan gets performed with standard parameters which are usable but not optimal for a reliable detection of trackers.

That is why i would still like to see the following changes: -No usage of a foreground service when the app runs as battery optimized so that powersaving features like doze mode work better -Usage of passive location listening where received locations drive the scans so that Aiguard doesn't cause additional battery drain

No idea though if the branch got rejected and abandoned after testing or if we might still see the changes in a release version.

Casey1979 avatar Feb 02 '25 15:02 Casey1979

It definitely makes sense for an app to use as less battery as possible that's expected to work mostly in the background. With location on, currently its battery usage is more than some frequently used apps.

jayb-g avatar Mar 06 '25 06:03 jayb-g