ttnmapper / ttnmapper-android-v3

The 3rd rewrite of the Android mapping app
GNU General Public License v3.0
9 stars 8 forks source link

Request GPS in Background permission #29

Closed Belkaar closed 3 years ago

Belkaar commented 3 years ago

Currently the app needs to be in foreground and the phone unlock to get GPS updates. There should be a background location permission you could request to have tha mapping work in the background.

Edit: ACCESS_BACKGROUND_LOCATION

jpmeijers commented 3 years ago

Please see the discussion here: https://github.com/ttnmapper/ttnmapper-android-v3/pull/25

In case you know something we don't please explain, link to documentation, and re-open this issue.

Belkaar commented 3 years ago

As can be seen here: https://developer.android.com/about/versions/oreo/background-location-limits

Caution: If your app starts a foreground service while running in the background on a device that runs Android 11 (API level 30) or higher, your app cannot access location information unless the user has granted the ACCESS_BACKGROUND_LOCATION permission to your app. For more information, view the guidance about the while-in-use restrictions that are associated with foreground services.

All I can tell you it does not work for me. If I put the app in the background for 5 minutes and pull it up again it says "GPS location too old (5 min)"

Maybe you can build an APK with the permission set to side load if its too much of a hassle get it into google play.

jpmeijers commented 3 years ago

The problem is that it is not as simple as adding ACCESS_BACKGROUND_LOCATION to the app. When one adds this permission, the app needs to go through a special review process for "sensitive apps" which is quite tricky. https://support.google.com/googleplay/android-developer/answer/9799150?hl=en

If your app starts a foreground service while running in the background - this is not the case with this app. We start the foreground service while running in the foreground. That's the only reason we are able to get past the limitations from the above.

Most likely the issue is that your phone's vendor has additional power saving options that turns off the location services for apps that aren't whitelisted. Maybe try an app like Strava and see what that does. Maybe Strava is added to a whitelist, in which case you can try the same for TTN Mapper.

A quote from the Wahoo excercise tracking app:

Ensure battery optimizations are disabled for the app Android phones running Android 6.0 or later will kill background apps automatically in certain circumstances. This may affect workout recording and/or device and sensor connectivity. Please ensure the Wahoo app is excluded from Android's "battery optimization" list. Note that some Android devices refer to this as "unmonitored apps" under battery settings.

Also have a look at: https://dontkillmyapp.com/samsung#galaxy-s10

Did you allow to disable "Battery Optimization" when you first started mapping?

jpmeijers commented 3 years ago

Can you maybe reproduce this issue and then directly afterwards export the debug log and email it to me from the app? Maybe there is something else causing the issue on your phone, and if we are lucky the debug log will shed some light on it.

Belkaar commented 3 years ago

I have the app on the "Don't power save" list.

You'll find the log here: https://pastebin.com/jgKukyrW