fix(monitor): Gate BLE scanning on permission state and stop retrying on SecurityException

PodMonitor's retryWhen always returned true, causing infinite 3-second retry loops when BLUETOOTH_SCAN permission was missing (e.g. on emulators). Now the scan flow checks missingPermissions before starting, and SecurityException aborts retries since it requires user action.
This commit is contained in:
darken
2026-03-03 20:52:32 +00:00
committed by Matthias Urhahn
parent abb189f43c
commit 6326f4a5b9
@@ -59,8 +59,7 @@ class PodMonitor @Inject constructor(
bluetoothManager.isBluetoothEnabled
) { missingPermissions, isBluetoothEnabled ->
log(TAG) { "devices: missingPermissions=$missingPermissions, isBluetoothEnabled=$isBluetoothEnabled" }
// We just want to retrigger if permissions change.
isBluetoothEnabled
missingPermissions.isEmpty() && isBluetoothEnabled
}
.flatMapLatest { isReady ->
if (!isReady) {
@@ -76,9 +75,14 @@ class PodMonitor @Inject constructor(
flowOf(sortPodsToInterest(devices))
}
.retryWhen { cause, attempt ->
log(TAG, WARN) { "PodMonitor failed (attempt=$attempt), will retry: ${cause.asLog()}" }
delay(3000)
true
if (cause is SecurityException) {
log(TAG, WARN) { "PodMonitor failed due to missing permission, not retrying: ${cause.asLog()}" }
false
} else {
log(TAG, WARN) { "PodMonitor failed (attempt=$attempt), will retry: ${cause.asLog()}" }
delay(3000)
true
}
}
.onStart { emit(emptyList()) }
.replayingShare(appScope)