mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-14 18:26:11 -04:00
fix: Guard MonitorService start against missing Bluetooth permissions
This commit is contained in:
@@ -6,6 +6,7 @@ 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.log
|
||||
import eu.darken.capod.common.debug.logging.logTag
|
||||
import eu.darken.capod.common.permissions.Permission
|
||||
import eu.darken.capod.common.startServiceCompat
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -19,11 +20,21 @@ class MonitorControl @Inject constructor(
|
||||
forceStart: Boolean = false,
|
||||
) {
|
||||
log(TAG, VERBOSE) { "startMonitor(forceStart=$forceStart)" }
|
||||
|
||||
val hasBluetoothPermission =
|
||||
Permission.BLUETOOTH.isGranted(context) || Permission.BLUETOOTH_CONNECT.isGranted(context)
|
||||
if (!hasBluetoothPermission) {
|
||||
log(TAG, WARN) { "Missing Bluetooth permission, not starting monitor service." }
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
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}" }
|
||||
} catch (e: SecurityException) {
|
||||
log(TAG, WARN) { "Failed to start monitor service, permission issue: ${e.message}" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user