fix: Trigger AAP connection when classic Bluetooth connects

initialConnect() only ran on profile changes, so if the L2CAP connection failed at service start (device not yet connected), it was never retried. Now also triggers on connectedDevices changes.

Also fix reconnect BLE address comparison: was comparing BLE RPA with bonded BR/EDR address (never matches), now uses profile address.
This commit is contained in:
darken
2026-03-31 19:17:09 +02:00
committed by Matthias Urhahn
parent 71638c13ab
commit dc2e318374
2 changed files with 38 additions and 3 deletions
@@ -12,6 +12,7 @@ import eu.darken.capod.pods.core.apple.aap.AapPodState
import eu.darken.capod.profiles.core.DeviceProfilesRepo
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
@@ -33,7 +34,10 @@ class AapAutoConnect @Inject constructor(
reconnectOnDisconnect(),
)
private fun initialConnect(): Flow<Unit> = profilesRepo.profiles
private fun initialConnect(): Flow<Unit> = combine(
profilesRepo.profiles,
bluetoothManager.connectedDevices,
) { profiles, _ -> profiles }
.map { profiles ->
val bondedDevices = bluetoothManager.bondedDevices().first()
@@ -88,7 +92,7 @@ class AapAutoConnect @Inject constructor(
// Check if still visible in BLE
val bleDevices = blePodMonitor.devices.first()
if (bleDevices.none { it.address == address }) {
if (bleDevices.none { it.meta?.profile?.address == address }) {
log(TAG) { "AAP reconnect: $address no longer visible in BLE, stopping" }
break
}