From f25718ab2cf9abef3a723e3d98b7464e95142e93 Mon Sep 17 00:00:00 2001 From: darken Date: Fri, 20 Mar 2026 20:12:43 +0100 Subject: [PATCH] fix: Catch Hilt DI failure in MonitorService.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. --- .../darken/capod/monitor/core/worker/MonitorService.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorService.kt b/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorService.kt index 3f3934e2..0439de8b 100644 --- a/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorService.kt +++ b/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorService.kt @@ -114,7 +114,15 @@ class MonitorService : Service() { return } - super.onCreate() + try { + super.onCreate() + } catch (e: Exception) { + log(TAG, WARN) { "Hilt DI failed in onCreate(), stopping service: ${e.asLog()}" } + Bugs.report(tag = TAG, "Hilt DI failed in onCreate()", exception = e) + foregroundStartFailed = true + stopSelf() + return + } log(TAG, VERBOSE) { "onCreate()" } // Replace early notification with the full one from injected MonitorNotifications.