fix(monitor): Log FGS start rejections distinctly with full stack

This commit is contained in:
darken
2026-07-28 23:51:46 +02:00
committed by Matthias Urhahn
parent 28ad09e96d
commit de287fcb66
@@ -1,11 +1,15 @@
package eu.darken.capod.monitor.core.worker
import android.annotation.SuppressLint
import android.app.ForegroundServiceStartNotAllowedException
import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import eu.darken.capod.common.debug.logging.Logging.Priority.VERBOSE
import eu.darken.capod.common.debug.logging.Logging.Priority.WARN
import eu.darken.capod.common.debug.logging.asLog
import eu.darken.capod.common.debug.logging.log
import eu.darken.capod.common.debug.logging.logTag
import eu.darken.capod.common.hasApiLevel
import eu.darken.capod.common.permissions.Permission
import eu.darken.capod.common.startServiceCompat
import javax.inject.Inject
@@ -16,6 +20,7 @@ class MonitorControl @Inject constructor(
@ApplicationContext private val context: Context,
) {
@SuppressLint("NewApi")
fun startMonitor(
forceStart: Boolean = false,
) {
@@ -32,9 +37,13 @@ class MonitorControl @Inject constructor(
context.startServiceCompat(MonitorService.intent(context, forceStart))
log(TAG) { "Monitor start request sent." }
} catch (e: IllegalStateException) {
log(TAG, WARN) { "Failed to start monitor service: ${e.message}" }
if (hasApiLevel(31) && e is ForegroundServiceStartNotAllowedException) {
log(TAG, WARN) { "Start rejected, app is not allowed to start a FGS from the background: ${e.asLog()}" }
} else {
log(TAG, WARN) { "Failed to start monitor service: ${e.asLog()}" }
}
} catch (e: SecurityException) {
log(TAG, WARN) { "Failed to start monitor service, permission issue: ${e.message}" }
log(TAG, WARN) { "Failed to start monitor service, permission issue: ${e.asLog()}" }
}
}