Skip to content

Tracking resilience: durable session descriptor + restart watchdog (P0) #225

Description

@adsamcik

Context

Follow-up to the tracking-architecture review (P0) and PR #222.

PR #222 switched user-initiated sessions to START_REDELIVER_INTENT (so Android re-delivers the original intent after a system kill) and added ApplicationExitInfo exit classification. That covers the common system-kill-and-redeliver path, but two gaps remain that need on-device validation before merging (restart-loop / battery safety can't be checked from a compile):

Remaining work

  1. Durable active-session descriptor. Persist the active session (user-initiated / ambient / tier) to a durable store (e.g. TrackingTogglesDataStore or a small dedicated DataStore) on start, clear it on graceful stop. Use it in TrackerService.onStartCommand's null-intent path so a user session can resume even when START_REDELIVER_INTENT did not redeliver (e.g. after a full process death where the in-memory sessionInfo / controller.sessionInfoFlow are gone).
  2. Restart watchdog. In onTaskRemoved() / onDestroy(), for user-initiated sessions, broadcast to a TrackerRestartReceiver that calls startForegroundService() (a BroadcastReceiver.onReceive is an allowed FGS-start context). Pattern: GPSLogger RestarterReceiver.
  3. Crash-informed recovery wiring. Use the ApplicationExitInfo reason added in PR feat(tracker): resilient user-session restart + previous-exit classification #222: on REASON_LOW_MEMORY/SIGNALED/CRASH/ANR → enqueue an expedited WAL-drain OneTimeWorkRequest so orphaned pending_signal rows are flushed even if TrackerService does not restart; on REASON_USER_REQUESTEDsuppress auto-restart.
  4. ApplicationStartInfo.wasForceStopped() (API 35+) guard in BootReceiver/startup to skip auto-restart and lock re-arming after a user force-stop.

Validation required (adb)

  • am force-stop → must NOT auto-restart (respect user).
  • kill $(pidof …) / am kill → user session restarts via watchdog; WAL drained, no restart loop.
  • reboot → locks restored; tracking re-armed via PendingIntent.
  • dumpsys deviceidle force-idle → FGS survives.

References

Reference: report sections P0; GPSLogger RestarterReceiver, OsmAnd NavigationService.onTaskRemoved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions