Location auto on/off
FMD can automatically turn Location Services on when you trigger a fmd locate
command, and turn it off again afterwards.
This requires granting the WRITE_SECURE_SETTINGS
permission.
This page gives some more background on this feature.
Location auto-on is reliable and should work. Auto-off is best-effort and is not guaranteed to work.
"Location turned on" is not the same as "using location"
"Location toggle on/off" and "an app is actively using location/gps" are related but not the same.
The first is a precondition for the second.
However, just because the toggle is enabled does not mean an app is actively using it. And only if an app is using it should there be a battery impact. Modern versions of Android show you which apps have been recently using the location.
This means: if you want to minimise your exposure, it's good to have location services turned off. But if it's turned on, it is not the end of the world. It's just one additional line of defence. If you have other apps that access the location in the background without you wanting to, you can disable the background location access for those apps in their respective permission settings.
Toggling location services on and off
Most apps cannot toggle the location services on and off.
FMD can only do it if you grant it the WRITE_SECURE_SETTINGS
permission.
Turning on the location is easy. Correctly and reliably turning it off again is hard.
Therefore, auto-off is best-effort and is not guaranteed to work. Of course, we can still have bugs. So feel free to file issues, ideally with reproducible steps.
Below, we explain why turning off is hard. This is related to concurrency and multiple apps running at the same time.
- Concurrency within FMD: what happens if the following three things overlap:
a regular background location upload job, a manually "fmd locate" command from FMD Server,
and an "fmd locate cell" command received via SMS?
These can start executing in any order, and can finish in any order.
- How does FMD know that all its jobs have finished and that it should turn off the location?
- What if one of these jobs is paused by the Android OS to resumed later?
- What happens if one of those background jobs is forcefully aborted by the Android OS? I.e, this job cannot do any clean-up and tell the rest of FMD that it is gone.
- What if the FMD application is force-stopped entirely by the Android OS?
- What if there are other apps on the device that do background location tasks?
What if those also have an auto-on/off feature like FMD?
How do we coordinate with them?
Should FMD keep the location on for them?
What if they turn the location off while FMD is still needing it?
- Currently, this case is not handled by FMD at all.
Recent versions of FMD Android log the jobId
when turning location on/off and starting/stopping jobs.
This should make it easier to trace what's going on and to debug why the location is not being turned off.
For the implementation details of how FMD is trying to solve this problem, see the LocationAutoOnOffHandler.