Skip to content

Fix: Prevent crash from dependency injection failure in monitoring service#458

Merged
d4rken merged 1 commit intomainfrom
fix/monitor-service-di-crash
Mar 20, 2026
Merged

Fix: Prevent crash from dependency injection failure in monitoring service#458
d4rken merged 1 commit intomainfrom
fix/monitor-service-di-crash

Conversation

@d4rken
Copy link
Member

@d4rken d4rken commented Mar 20, 2026

What changed

Prevented a potential crash that could happen if the monitoring service's dependency injection fails during startup. Instead of crashing the entire app, the service now stops gracefully and reports the error.

Technical Context

  • MonitorService.onCreate() already calls startForeground() before super.onCreate() (Hilt DI) to satisfy the FGS timeout. However, if DI then throws (e.g., SecurityException from Bluetooth access, DataStore I/O failure, or the app being started in a restricted context like backup/restore), the unhandled exception crashes the process.
  • Wrapping super.onCreate() in try-catch lets the service stop cleanly via stopSelf() while the foreground notification is still up — satisfying the system's FGS requirement without killing the app.
  • The DI failure is reported via Bugs.report() so it surfaces in crash analytics rather than being silently swallowed.
  • Complements Fix: Reduce foreground service timeout crash on cold start #451 which addresses the premature FGS timer start from App.onCreate().

Wrap super.onCreate() (Hilt injection) in try-catch to prevent

DI failures from crashing the process. The service is already

foreground at this point, so a graceful stopSelf() satisfies the

FGS timeout requirement without killing the app.
@d4rken d4rken added the bug Something isn't working label Mar 20, 2026
@d4rken d4rken merged commit f25718a into main Mar 20, 2026
10 checks passed
@d4rken d4rken deleted the fix/monitor-service-di-crash branch March 20, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant