Skip to content

Commit f25718a

Browse files
committed
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.
1 parent 6e9b275 commit f25718a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorService.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,15 @@ class MonitorService : Service() {
114114
return
115115
}
116116

117-
super.onCreate()
117+
try {
118+
super.onCreate()
119+
} catch (e: Exception) {
120+
log(TAG, WARN) { "Hilt DI failed in onCreate(), stopping service: ${e.asLog()}" }
121+
Bugs.report(tag = TAG, "Hilt DI failed in onCreate()", exception = e)
122+
foregroundStartFailed = true
123+
stopSelf()
124+
return
125+
}
118126
log(TAG, VERBOSE) { "onCreate()" }
119127

120128
// Replace early notification with the full one from injected MonitorNotifications.

0 commit comments

Comments
 (0)