From 0f8e441a929aede05a33de3f7359ae3af1b7092e Mon Sep 17 00:00:00 2001 From: darken Date: Thu, 20 Jan 2022 16:07:11 +0100 Subject: [PATCH] Fix crash on profile service disconnect --- .../eu/darken/capod/common/bluetooth/BluetoothManager2.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 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 c6405eb1..164703ea 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 @@ -16,10 +16,10 @@ import eu.darken.capod.common.debug.logging.Logging.Priority.* import eu.darken.capod.common.debug.logging.log import eu.darken.capod.common.debug.logging.logTag import eu.darken.capod.pods.core.apple.protocol.ContinuityProtocol -import kotlinx.coroutines.CancellationException import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch +import java.io.IOException import java.util.* import javax.inject.Inject import javax.inject.Singleton @@ -77,7 +77,7 @@ class BluetoothManager2 @Inject constructor( override fun onServiceDisconnected(profile: Int) { log(TAG, WARN) { "onServiceDisconnected(profile=$profile" } - throw CancellationException("BluetoothProfile service disconnected (profile=$profile)") + close(IOException("BluetoothProfile service disconnected (profile=$profile)")) } }, profile) @@ -90,6 +90,7 @@ class BluetoothManager2 @Inject constructor( } } + private fun monitorDevicesForProfile( profile: Int = BluetoothProfile.HEADSET ): Flow> = getBluetoothProfile(profile).flatMapLatest { bluetoothProfile ->