Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable background location support in osm build #1255

Merged
merged 1 commit into from
Jul 28, 2022

Conversation

bemdark
Copy link

@bemdark bemdark commented Jul 24, 2022

Fixes #1199

Doesn't request background location from the user (as there is no good UI for it), but if you enable it yourself in the settings, owntracks doesn't have to be started manually when rebooting the phone.

@growse
Copy link
Collaborator

growse commented Jul 28, 2022

Thanks for this - been meaning to get around to looking at this.

Hopefully later on we can have the OSS flavour actually request background permission as well, but that'll take a bit more thinking about.

@growse growse merged commit bc14c2c into owntracks:master Jul 28, 2022
@bemdark
Copy link
Author

bemdark commented Jul 28, 2022

Well it's not like it was lot of work, basically I just added the permission to the manifest.
I have tried it though and added the permission via the settings, and it seems to work without changing anything else (I am not really well-versed in how background and foreground services work and how they differ). I added the permission and after restarting the phone I received locations from my phone on another device without ever actually starting OwnTracks manually.

I tried how it looks like to request the background permission - you just get a small warning in the bottom that some permissions are missing and a "Fix" button that sends you to the settings (OwnTracks app details page), so I'm not sure if that's worth implementing at all (I think I'd rather implement it like disabling battery optimization on gms).

@growse
Copy link
Collaborator

growse commented Jul 28, 2022

Often the hardest part is figuring out the smallest useful change, and this certainly nicely meets that definition :)

Asking permissions gets a bit interesting because of how the user expectations overlay on top of what the app is acutally doing. The reason we use a foreground service (has a persistent notification) is that if we use a background service, then we need both the background permission and locations won't be delivered very often. From https://developer.android.com/training/location/background#limit-updates:

If background location access is essential for your app, keep in mind that Android preserves device battery life by setting background location limits on devices that run Android 8.0 (API level 26) and higher. On these versions of Android, if your app is running in the background, it can receive location updates only a few times each hour.

So even if the user asks for location access "all the time", we still need to run a foreground service.

In theory, this then means that the only thing that background permission is giving you is the auto-start ability, so it potentially only makes sense to ask for it if the user requests the "auto start on boot" preference (although this is on by default).

However I have a strong suspicion that other device manufacturers potentially provide a different location experience to Activities / Foreground services depending on whether background location permission is granted (they shouldn't). If that's the case, then it makes sense to always ask for it, and maybe throw up a warning / explanation dialog if the user grants location permission but denies background location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants