mendhak/gpslogger

"GPSLogger running" Notification persists in v119

Closed this issue · 15 comments

Working with GPSLogger v119 on a Pixel 4a 5G w/Android 12.

Since the last update (v119), I often have a GPSLogger notification stick around in the notification area - see screenshot below. When opening GPSLogger, it is not logging in any way, but the notification still persists.

image

Any ideas on how to fix this?

The notification will appear when you open the app - that's been that way for a long time, because of the way the OS loves killing the service. But, what about when the app isn't open, is that what you mean, you are you still seeing that notification even without logging running? How do you normally exit or close the app, is it back button, or task view/swipe away, or home button?

It might be related to this commit as the handling of pause/stop to halt the background service (and notification) is supposedly not needed anymore, and I was trying to address complaints about the service being killed off randomly.

I've got Android 12 as well, but Pixel 3A XL, and in both cases - back button as well as task manager swipe, the notification should disappear. Can you try those two specific gestures/buttons and see if you observe the same thing

OK - I left out an important part of the story.

I never manually start or close the app, but I'm rather controlling trip recording via the built-in TASKER_COMMAND Action. I'm passing immediatestart=true and immediatestop=true for starting/stopping a recording in one of the automated task graphs.
(Actually using the Llamalabs "Automate" app instead of Tasker, but I doubt this matters)

In that case, what is the notification expected to do?

Aaaaaaaah thanks for that extra info! OK I'll need to do a bit of testing here. I would expect stop to remove that notification, so I'll have to see what is being missed out.

I tried this for a day or two but I've not been able to recreate the problem. I even used Llama Automate, and I'm seeing that the notification appears when I start logging, disappears when I stop logging. Is there anything else you're doing around the app's automation?

I've done some guesswork to restore a deleted method in the code, you could have a test with the APK here to see if the problem disappears. https://github.com/mendhak/gpslogger/releases/tag/v120-rc1

Note that the APK is not compatible with F-Droid so if you install it you will lose all previous GPSLogger data.

I've attached the Automate "flow" if you'd like to check, but I only send a TASKER_COMMAND at two distinct points in the flow, nothing else.

I'll give it a go with the custom APK - I only have some custom profile to re-configure, so happy to help. Will keep you posted.

time-car-ride-bluetooth

OK - been running the APK for a few days, but I'm still seeing the persistent notifications.

Would it help to switch on debug logging, and send you a log after some time?

Sure you can try a debug log. That might help, or it might only probe that 'something' is restarting the service but not indicate what.

The notification related code is now just as it was before v119 so I wonder if there's something else at play.

OK - I switched on debug logging yesterday @ 11am and had it run for about a full day (until about 1pm today). I've included it as attachment (I did mask the actual location data): debuglog.2022-01-02.txt.zip

Actual car trips during this time:

  • 11:16:22 → 12:07:50 , logged without problems
  • 17:52:42 → 18:47:15 , logged without problems

I noticed incorrect "GPSLogger is still running" notifications in the late afternoon, and also at night around 6AM. In both cases, not sure when exactly the notification appeared. In any case, GPSLogger was not actually logging anything at that time.

I sniffed through the logs, but I'm not too familiar with GPSLogger internals to make complete sense of it.
Some things that stand out:

  • 15:06:09 → a "Stop logging now" intent received, out of the blue. I definitely was not near the car at that point, so no clue where this one came from.
  • a number of "GpsLoggingService is being destroyed by Android OS" mentions, although GPSLogger is allowed "unrestricted" battery use and location access at any time. Is that normal?

All in all, didn't get too much wiser from this myself.

Do you see any clues?

OK - a few more days of logging, and things got clearer.

Everytime a false "GPSLogger is still running" notification appears, I see these events logged:

12:26:27 DEBUG AppSettings.onCreate:47 - Log4J configured
12:26:27 DEBUG AppSettings.onCreate:51 - EventBus configured
12:26:27 DEBUG AppSettings.onCreate:62 - Job Queue configured
12:26:27 DEBUG AppSettings$1.d:93 - [priority_mq] looking for next message at time 1641554787663721669
12:26:27 DEBUG AppSettings$1.d:93 - flushing messages at time 1641554787663721669
12:26:27 DEBUG AppSettings$1.d:93 - [priority_mq] next delayed job null
12:26:27 DEBUG AppSettings$1.v:109 - joq idle. running:? true
12:26:27 DEBUG AppSettings$1.d:93 - Job queue idle. next job at: null
12:26:27 DEBUG AppSettings$1.d:93 - [priority_mq] did on idle post a message? false
...

... and so on.

These events appear randomly, out of the blue - I'm not using GPSLogger in any way at that time.

Does this indicate that GPSLogger got killed in the background, and it's restarting?l

I've had a look through and I'm understanding the same thing and there aren't any real clues. Something is causing it to start, but there is no way to know what that is.

The AppSettings.onCreate is usually the first bit of code that is executed when the application is started. It might be invoked by another application or directly by opening the app.

There are quite a few 'sudden' instances of this appearing in the logs.

The 18:47 portion is a good example. I can see that the app dutifully stopped and stayed quiet. Then at 22:02:26 it is suddenly revived. The log messages after that are simply the job queue process checking if there's any work to do. At 06:07 there's a set of logs as though the app has been opened again, I think it might be the onResume event.

The message "GpsLoggingService is being destroyed by Android OS" can mean that it's being killed because it's not being used. It should normally happen when the app stops logging or user exits the app while it's not logging. In the code I'm also removing the notification as soon as that happens so I can't figure out why you're seeing it.

Is there anything significant about 6:07, is it close to the sunrise time where you live and is the OS switching between day night themes and poking applications as it does that?

Does this still happen if Automate/Tasker is stopped on the phone?

Just quick status update - no clarity as to what could trigger these notifications.

Currently exploring logcat to see whether I can spot something useful/informative in there...

I have also noticed this happening. Can't figure out what's causing it, but so far it's only happened while charging the phone

I've done a little more digging. I'm wondering if it's as simple as this line here in the documentation

stopForeground
Remove this service from foreground state, allowing it to be killed if more memory is needed. This does not stop the service from running (for that you use stopSelf() or related methods), just takes it out of the foreground state.

I've just been using stopForeground(), I didn't call stopSelf()! So in this commit, I'm adding a call to stopSelf() just after stopForeground().

It'll help if anyone is able to test this, I've added an APK here to test with. https://github.com/mendhak/gpslogger/releases/tag/v122-rc2
Note that this APK is not compatible with the F-Droid version. If you install it you will lose all GPSLogger data.

I'll need to have a think about where the 'stopLogging' gets called from to see if this produces any unexpected behaviors. I don't think it should but it's an old codebase, and I now expect the unexpected.

Been running v122-rc2 for a couple of days and haven't noticed the Notification returning.

Version 122 is on F-Droid and the releases. I'm going to close this thread because I think this will have solved the phantom notification issue. But if it does reappear we can continue in this thread and reopen it.