@@ -16,6 +16,7 @@ import com.juul.kable.gatt.Callback
1616import com.juul.kable.logs.Logging
1717import kotlinx.coroutines.flow.MutableSharedFlow
1818import kotlinx.coroutines.flow.MutableStateFlow
19+ import kotlinx.io.IOException
1920import kotlin.coroutines.CoroutineContext
2021import kotlin.time.Duration
2122
@@ -36,7 +37,7 @@ internal fun BluetoothDevice.connect(
3637 logging : Logging ,
3738 threadingStrategy : ThreadingStrategy ,
3839 disconnectTimeout : Duration ,
39- ): Connection ? {
40+ ): Connection {
4041 val callback = Callback (state, mtu, onCharacteristicChanged, logging, address)
4142 val threading = threadingStrategy.acquire()
4243
@@ -52,17 +53,12 @@ internal fun BluetoothDevice.connect(
5253 ? : connectGattCompat(context, true , callback, transport.intValue)
5354
5455 else -> connectGattCompat(context, autoConnect, callback, transport.intValue)
55- }
56+ } ? : throw IOException ( " Binder remote-invocation error " )
5657 } catch (t: Throwable ) {
5758 threading.release()
5859 throw t
5960 }
6061
61- if (bluetoothGatt == null ) {
62- threading.release()
63- return null
64- }
65-
6662 return Connection (coroutineContext, bluetoothGatt, threading, callback, services, disconnectTimeout, logging)
6763}
6864
0 commit comments