Skip to content

feat(tracker): resilient user-session restart + previous-exit classification#222

Draft
adsamcik wants to merge 1 commit into
dev/v10from
feat/resilient-session-restart
Draft

feat(tracker): resilient user-session restart + previous-exit classification#222
adsamcik wants to merge 1 commit into
dev/v10from
feat/resilient-session-restart

Conversation

@adsamcik

Copy link
Copy Markdown
Owner

Summary

Process-death resilience follow-ups from the tracking-architecture review (P0). Two focused, low-risk changes.

1. START_REDELIVER_INTENT for user sessions

On dev/v10, TrackerService returns START_STICKY for user-initiated sessions. After a system kill, START_STICKY re-creates the service with a null intent, so the original ARG_IS_USER_INITIATED flag is lost and the code must fall back to in-memory recovery (sessionInfo / controller.sessionInfoFlow), which is gone after a full process kill.

Switching to START_REDELIVER_INTENT makes Android re-deliver the original start intent (with its extras) on restart, so the session resumes with the correct flags. This is the pattern OsmAnd's NavigationService uses. Auto-tracking sessions remain START_NOT_STICKY (re-triggered by ActivityWatcherService).

2. ApplicationExitInfo previous-exit classification

Application now queries ActivityManager.getHistoricalProcessExitReasons() (API 30+) at startup and logs the previous exit reason, distinguishing abnormal terminations (LOW_MEMORY / SIGNALED / CRASH / CRASH_NATIVE / ANR) from normal ones (USER_REQUESTED, USER_STOPPED, OTHER). Defensive try/catch (some OEM builds throw).

This makes OEM/low-memory kills observable in crash reports and is the foundation for:

  • crash-informed recovery (drain the durable signal buffer after an abnormal kill), and
  • respecting a user-requested force-stop instead of auto-restarting.

Verification

  • ./gradlew :app:compileDebugKotlinBUILD SUCCESSFUL.
  • Unit tests not run locally (engine JUnit5+Robolectric "No instrumentation registered"); CI will run them.

Follow-up (filed separately)

The heavier P0 item — a durable active-session descriptor + an onTaskRemoved/onDestroy restart watchdog (GPSLogger RestarterReceiver pattern) + wiring ApplicationExitInfo into an automatic WAL-drain worker — is tracked as a separate issue because it needs on-device validation (restart-loop / battery safety) that can't be done from a compile check.

Notes

Draft — opened for review.

…ication

- TrackerService: return START_REDELIVER_INTENT (was START_STICKY) for
  user-initiated sessions so Android re-delivers the original start intent
  (carrying ARG_IS_USER_INITIATED) after a system kill, instead of a null
  intent that forces in-memory fallback recovery.
- Application: classify the previous process exit via ApplicationExitInfo
  (API 30+) and log abnormal terminations (LOW_MEMORY/SIGNALED/CRASH/ANR)
  vs normal ones. Foundation for crash-informed recovery and for respecting
  user-requested force-stops.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant