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

PublicAPI: GPS won't activate, when tracking starts while screen is off #1653

Open
2 tasks done
v-schaefer opened this issue Aug 4, 2023 · 14 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@v-schaefer
Copy link

I use OpenTracks in combination with Gadgedbridge and a Fossil HR watch.
Whenever I start a training on my watch (for example cycling or running) and my phone is in standby, OpenTracks doesn't activate GPS.
The message title in the statusbar stays stuck at "starting GPS" and my training will get recorded without GPS. The phone also doesn't show the symbol that an app is accessing GPS.
However if my phone is on (for example at the homescreen) and I start a new training from my watch, then GPS gets started immediately, the phone shows that GPS is getting accessed by an app and everything works fine.

All battery optimization options on Android are disabled for OpenTracks.

...

Checklist

  • Consulted [https://dontkillmyapp.com/]
  • Power management: battery optimization is disabled for OpenTracks

Technical information

  • Device: OnePlus 7T Pro
  • OS: Stock Android 12 ROM
  • OpenTracks version: v4.6.2 (from fdroid)
  • OpenTracks commit id (only for nightly builds): -
@v-schaefer v-schaefer added the potential bug A bug that could not (yet) be reproduced label Aug 4, 2023
@dennisguse
Copy link
Member

Would you be able to record a video (with a 2nd device) of what is happening?
... and also a logcat?

What is technically happening:

  • intent send:
  • ... Android starts an OpenTracks activity
  • ... activity starts a foreground service

This may be problematic due to:

@v-schaefer
Copy link
Author

I've recorded a logcat and from what it looks like, it is no problem to create a foreground service while in standby, but the access to GPS is denied then:
logcat.txt

To better understand what I'm doing, I've also recorded it with a second phone.
It's a bit blurry, but you can still spot what's relevant:

First Situation: Phone is on the homescreen - when the training starts, you can see the GPS-Icon on the right side of the status bar and GPS gets locked quickly:

Phone_at_homescreen.mp4

Second: The phone is in standby when the training starts. After powering on, you can see that there's no GPS-Icon in the status bar and OpenTracks is stuck on "starting GPS":

Phone_in_standby.mp4

@dennisguse
Copy link
Member

Location access denied.

Are you able to add (and request) the location background permission?

2023-08-06 19:13:10.905 10566-10566 GPSManager              de.dennisguse.opentracks             E  Not started.
2023-08-06 19:13:10.907  2595-4182  OplusLbsRepairer        system_server                        V  location access denied

@dennisguse dennisguse added bug Something isn't working and removed potential bug A bug that could not (yet) be reproduced labels Aug 6, 2023
@v-schaefer
Copy link
Author

I've tested it with the ACCESS_BACKGROUND_LOCATION permission and now it works fine!
To make things easier, I've created a PR with my modifications: #1658
Thanks for your help in pointing that out so quickly!

@v-schaefer
Copy link
Author

Fixed with 3910837

@dennisguse dennisguse reopened this Aug 22, 2023
@dennisguse
Copy link
Member

Sadly, requesting ACCESS_BACKGROUND_LOCATION is broken.
Removing this change for now.

Likely the actual issue is: https://stackoverflow.com/questions/66475027/activityresultlauncher-with-requestmultiplepermissions-contract-doesnt-show-per

@v-schaefer
Copy link
Author

Sorry to hear that.
We only need the location in background, if the public API is activated, right?
Maybe we should only ask for that permission, if the public API is enabled.

On a fresh install the app would then ask for all permissions except ACCESS_BACKGROUND_LOCATION and as soon as the public api gets enabled, it would only ask for that additional permission.
Just to be safe and make it less hacky, we could check, what permissions we will ask for and only ask for ACCESS_BACKGROUND_LOCATION, if that's the only permission we will ask for (because all others are already granted).

What do you think?

@dennisguse
Copy link
Member

Sounds like a good plan.

@dennisguse
Copy link
Member

And this one becomes related; #1259

@v-schaefer
Copy link
Author

Hmm.. I guess the whole permission requester class will need a bit of refactoring to get both the background-access and permissions on demand running...
I tried to do that, but this seems way above my knowledge - android permissions are more complicated than I thought :(

@dennisguse
Copy link
Member

@v-schaefer what did you try?
What was your plan?
And how can I help?

@v-schaefer
Copy link
Author

First I tried splitting up the permission request to first request everything except GPS background permission and after that only the GPS background permission.
I've done that by editing requestRequiredPermissions() in the TrackListActivity.
First I tried to just add a second PermissionRequester for the GPS background permission after the first one, which resulted in all permissions being requested at once and therefor no GPS background permission being requested.
After that I tried to request all permissions except GPS background and then open a dialog box that explains why the GPS background permission is needed and request that permission when the user clicks on "OK"... I think that this will be the right way to go, but my implementation didn't work... By clicking on OK the whole app crashed (with something like it's not allowed to start a second Activity instance).
I'm fairly new to android apps and I'm sure that we're on the right track with that idea, but at the same time it was just some spaghetti-code to test my idea and I don't think it would help if I would contribute that non-working code...

@dennisguse
Copy link
Member

Sounds like a good plan.
In addition, we could do this at two places: once when enabling the PublicAPI as well as when in StartRecording (aka when PublicAPI is triggered). In TrackListActivity, the background permission could be removed.

To request these permissions in the same activity: no clue how this is done as I never tried this :D
I am at the moment rather busy with things, but I can support you with reviews.

PS/ I would skip implementing UI elements for this.
Not really necessary and way too much effort.

@dennisguse dennisguse changed the title GPS won't activate, when tracking starts while screen is off PublicAPI: GPS won't activate, when tracking starts while screen is off Oct 11, 2023
@sgofferj
Copy link

I'm seeing a similar issue (I think). I'm starting recording from Home Assistant by sending an intent through the HomeAssistant app to Tasker and Tasker sends the intent to OT when I leave the house with my dogs. I think, at least in my phone, it's a deep sleep issue. When I turn the phone on, even if I turn it off straight afterwards, the recording starts straight away. However, if I forget that, I get the notification from the Home Assistant app that I'm on a dogwalk but it takes between 30 seconds and forever for OT to fire up.

App information

  • ID: de.dennisguse.opentracks.nightly
  • Version: 5483 v4.9.2-17-g8f9ba046c

Device information

  • Brand: ulefone
  • Device: Armor_3
  • Model: Armor_3
  • Id: O11019
  • Product: Armor_3

Firmware

  • SDK: 27
  • Release: 8.1.0
  • Incremental: 1535356309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants