Skip to content

Device: Fix app getting stuck in scanning loop without Bluetooth#428

Merged
d4rken merged 1 commit intomainfrom
fix/podmonitor-infinite-retry-without-bluetooth
Mar 3, 2026
Merged

Device: Fix app getting stuck in scanning loop without Bluetooth#428
d4rken merged 1 commit intomainfrom
fix/podmonitor-infinite-retry-without-bluetooth

Conversation

@d4rken
Copy link
Copy Markdown
Member

@d4rken d4rken commented Mar 3, 2026

What changed

Fixed the app getting stuck in an endless scanning loop on devices without Bluetooth (e.g. emulators). The scanner would retry every 3 seconds forever when Bluetooth permissions couldn't be granted, flooding the log and wasting resources.

Technical Context

  • Root cause: PodMonitor.devices combined missingPermissions and isBluetoothEnabled but only used isBluetoothEnabled to gate scanning — permissions were logged but ignored
  • When BleScanner.startScan() threw SecurityException (missing BLUETOOTH_SCAN), the retryWhen operator always returned true, causing infinite retries with 3-second delay
  • Fix gates scanning on missingPermissions.isEmpty() && isBluetoothEnabled — when permissions are later granted, the combine re-emits and scanning starts naturally
  • Added defense-in-depth: retryWhen now returns false for SecurityException since it requires user action to resolve (unlike transient errors which can legitimately recover)
  • BluetoothManager2 already had proper retry limits (max 3 with backoff) — PodMonitor was the only unbounded retry

… 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.
@d4rken d4rken added the bug Something isn't working label Mar 3, 2026
@d4rken d4rken merged commit 6326f4a into main Mar 3, 2026
9 checks passed
@d4rken d4rken deleted the fix/podmonitor-infinite-retry-without-bluetooth branch March 3, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant