From fd20ef050072994c97b25c1525ea58f27c1a0d93 Mon Sep 17 00:00:00 2001 From: darken Date: Fri, 17 Apr 2026 21:43:01 +0200 Subject: [PATCH] fix(bluetooth): Keep connectedDevices retrying while BLUETOOTH_CONNECT is missing --- .../common/bluetooth/BluetoothManager2.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/darken/capod/common/bluetooth/BluetoothManager2.kt b/app/src/main/java/eu/darken/capod/common/bluetooth/BluetoothManager2.kt index dcb51333..0bb4226b 100644 --- a/app/src/main/java/eu/darken/capod/common/bluetooth/BluetoothManager2.kt +++ b/app/src/main/java/eu/darken/capod/common/bluetooth/BluetoothManager2.kt @@ -268,11 +268,19 @@ class BluetoothManager2 @Inject constructor( } .retryWhen { cause, attempt -> log(TAG, WARN) { "connectedDevices Flow failed (attempt ${attempt + 1}): $cause" } - if (attempt < 3) { - delay(1000 * (attempt + 1)) // 1s, 2s, 3s exponential backoff - true // Retry - } else { - false // Give up after 3 attempts + when { + // BLUETOOTH_CONNECT not granted (or revoked). Keep retrying — the next + // attempt will succeed as soon as the user grants it. Terminating here + // would leave the stateIn StateFlow serving a stale emptyList() forever. + cause is SecurityException -> { + delay(3_000L) + true + } + attempt < 3 -> { + delay(1000 * (attempt + 1)) + true + } + else -> false } } .catch { e ->