owntracks / android

OwnTracks Android App
http://owntracks.org
Eclipse Public License 1.0
1.34k stars 474 forks source link

OwnTracks Not Updating Location When App Is Whitelisted #992

Open ghost opened 3 years ago

ghost commented 3 years ago

I have always used OwnTracks in Significant Monitoring Mode. Lately, it has not been updating the location when I move. The app has been whitelisted for battery usage. Location interval (not move mode) is set to 25 seconds. I have not drawn any correlation to what could be causing this and would thing it would be an android core or setting issue at best.

Are there any other steps I could try in order to correct this problem?

Settings

growse commented 3 years ago

Does the blue dot move when you have the app in the foreground?

Does this only affect significant-mode, or do you see the same lack of updates in move mode?

ghost commented 3 years ago

From what I've experienced, when I open the application to the foreground, it will behave normally. This seems to happen when OwnTracks hasn't been touched in a while. Is there anything else that needs to be whitelisted?

I don't use move mode so I can't answer.

growse commented 3 years ago

There's a couple of data points it might be useful to gather if you get a chance:

1) If you put the app in move mode and then send it to background, do you then see the updates stop at some point in the future? 2) With OT in significant changes mode, when you see the updates stop being posted, does opening another app that grabs a high accuracy location (e.g. Google Maps) cause a location update from OT?

I don't have a Samsung device to test with, but Samsung have something of a reputation for killing background processes / apps (https://dontkillmyapp.com/), and I'm nervous that such a behaviour could effectively kill the thread that's waiting for location updates.

ghost commented 3 years ago

Thanks for the reply. Give me a little bit of time to test.

ghost commented 3 years ago

I did a little testing, not quite what you are looking for, but when I reboot my phone, OT does not show the location in the drawer, just shows significant monitoring mode. If I open Waze or Google Maps, the address does not populate. I haven't tried moving when this has happened to see if it will start tracking.

If I open OT, the address will populate.

Also, I did look at the logs, and saw something about stale locations. In the config, my stale location is set to 0.0.

I will keep posting updates, but this is what I have so far.

Stale Locations Drawer

growse commented 3 years ago

Ah, this issue sounds similar to #976 - on the latest version of Android, the background service doesn't receive locations if it's been started in the background (e.g. on boot, or after an upgrade).

As per the other issue, the next release will show a notification explicitly stating that location updates are paused until the user explicitly starts the app, allowing locations to be received.

ghost commented 3 years ago

Thanks! Here is my workaround using MacroDroid. When my phone boots, force a new instance of OT.

Using this method, it does not open OT in the foreground which is desirable.

Not sure if it is possible to include the logic in your code, to when OT is set to start automatically after a phone boot, force a new instance when it opens.

MacroDroid Settings

growse commented 3 years ago

I'm not sure what you mean by a "new instance". On boot, isn't any instance of any app started is going to be "new"?

The problem with receiving locations after OT gets started automatically on boot is that Google restricts locations being sent to apps that have been started in the background. Listening to a boot intent and starting a service very much counts as starting "in the background". Do you know what intent Macrodroid is sending to start OT as configured in your screenshot?

ghost commented 3 years ago

No idea what intent is being sent. Would you like me to find out?

growse commented 3 years ago

If you can, that might be useful. I keep meaning to do some experiments to determine how Google determines that a service has been started in the "background". I guess that some intents count as background and others don't but I've yet to find a list.

ghost commented 3 years ago

Intent.ACTION_MAIN was the action I was provided by the developer. Though one thing I learned was even it a new instance of the application was launched, it still does not push the location until I either fully open the app or push the upload button. Is it possible to add an option to automatically push location every x minutes? Is there an intent that could be used to push the location?

growse commented 3 years ago

Sending the action org.owntracks.android.SEND_LOCATION_USER to the service should do the same thing as pressing the user location report button.

growse commented 3 years ago

I'm having some trouble reproducing this. I installed Macrodroid onto the emulator running the latest android version and configured a macro like this:

image

I then disabled "Start on boot" in OT and rebooted the emulator. As I expected Macrodroid started OT in the foreground (including with blue dot and sending locations) once the device had booted.

Did I miss something trying to replicate this?

ghost commented 3 years ago

I tried mine by not disabling OT to Start on Boot, when doing so my location will appear in the tray using the MacroDroid Logic, I would go places and my location would not update.

So I added an intent to report the location when I plug in and Android Auto starts.

Next, I am trying a new way. When disable start when device boots on OT and use MacroDroid to handle it for me by launching OT to see how that works out.

growse commented 3 years ago

It's probably worth mentioning that the SEND_LOCATION_USER intent only sends the latest location that the OT process actually has. If it's not been delivered anything by the OS (because started in background on Android 11), then there's nothing to send.