Skip to content

Bug: Android background location can remain stale for hours until Grid is reopened #325

Description

@HiFiveJazz

Summary

Grid’s Android foreground location service remains active, however the background location updates can stop for hours or nearly a day in my experience. Opening or restarting Grid usually causes an immediate location update.

This DOES NOT appear to be caused by Android killing the service or blocking permissions.

Environment

  • Hardware: Pixel Fold
  • Grid Version: v2.0.1+840
  • Package: app.mygrid.grid
  • Operating System: Android: GrapheneOS
  • Self-hosted Matrix Synapse
  • Location permission: Allow all the time
  • Precise location: Enabled
  • Battery usage: Unrestricted
  • Notifications: Enabled
  • Tracking profile selected: Live

Expected behavior

When the phone begins moving while Grid is in the background, Grid should detect that movement, request a fresh location, and send it to the relevant Matrix rooms. This was emulated with me shaking my phone furiously while the app was open and after I shut off the screen to my device.

Actual behavior

The foreground location service stays active, and Android reports significant-motion events, but Grid remains in isMoving=false. No background location-send sequence appears after the motion event.

Opening Grid triggers a manual location ping and immediately sends the location successfully.

Evidence

I collected evidence using my Pixel Fold and collecting debug information with the app on and with the screen closed to see what might be the cause and here are some snippets of those logs, which I would prefer not to fully post in a open GitHub issue!

1. The foreground location service is active

io.rezivure.libre_location.LocationService

startForegroundCount=1
isForeground=true
types=0x00000008
stopIfKilled=false

foregroundNoti=Notification(
  channel=libre_location_channel
  flags=ONGOING_EVENT|NO_CLEAR|FOREGROUND_SERVICE
)

Android reports the persistent notification, everything good so far:

android.title=Location Sharing
android.text=Active
flags=ONGOING_EVENT|NO_CLEAR|FOREGROUND_SERVICE

So Android is not simply killing the location service.

2. Grid remains in stationary mode

D/LibreLocationMgr: Heartbeat started: interval=900s
D/LibreLocationMgr: Config updated dynamically (isMoving=false)

A 15 minute heartbeat is noted. This is odd since my profile is set to Live, but moving on.

3. Significant motion is detected

While the screen was locked, the phone was shaken:

13:23:55.040 D/AOC:
[SMD] Publishing SMD with activity 3

13:23:55.054 D/LibreMotionDetector:
Significant motion trigger fired

13:23:55.070 D/LibreMotionDetector:
Significant motion trigger fired

13:23:55.074 D/LibreMotionDetector:
Significant motion trigger fired

However, I did not see a subsequent:

Config updated dynamically (isMoving=true)

or any immediate Matrix location-send sequence. Perhaps the algorithm you guys are using isn't triggering off of motion movement but that was an assumption I was making in that this could be cause of why locations may not be updating for me and other users!

4. Foreground/manual sending works immediately

When Grid was opened:

Manual location ping completed

Grid: Found 2 total rooms to process
Sending location to 2 rooms in parallel...

Location event sent to room [REDACTED]
Location event sent to room [REDACTED]

Batch update complete in 296ms

This indicates that:

  • Matrix authentication works
  • the Synapse server is reachable
  • the rooms are joined
  • location events can be sent successfully
  • the failure appears specific to the background update path

5. Possible profile persistence issue

Live was selected and Grid was restarted before testing, but the logs later showed:

Location preset updated to TrackingPreset.balanced

This may be a separate issue, or perhaps I'm not understanding how the app works, but it may or may not or contribute to the background behavior.

Suspected Issue

I suspect that LibreMotionDetector receives significant-motion events correctly while Grid remains in isMoving=false. I don't have enough knowledge on the design philosophy of the app to make a pull request nor do I do any Android development stuff, so if this is a non issue, feel free to roast me and just close this issue. But I was curious as to why this may not be working and this atleast might help you guys get you going on debugging the cause of this bug!

Could you guys verify that a significant-motion callback actually changes the internal moving state and subsequently requests an immediate location?

It would also be useful to check why Live sometimes appears to reload as TrackingPreset.balanced.

Lastly, thank you so much for the development of this app :) you guys are awesome!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions