From c618d0fa66b892a6f516be6f8a9be792a69c3265 Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Mon, 26 May 2014 15:16:27 +0200 Subject: [PATCH] android/a2dp: Fix removing device on incoming connection Connection state is not changed for incoming connection, i.e. during discovery device is still in disconnected state and in case connection fails for some reason, device won't be removed due to triggered state change disconnected->disconnected which is silently ignored. This patch fixes this problem by changing device state to connecting immediately after signalling channel is connected. This allows device to be removed properly in case something fails and is also consistent with behaviour of Bluedroid. In addition there's new flag added to device which stores information whether we're initiator of connection. This is required because before fix this property was decided based on HAL state which we can't now use since it will be always connecting for both incoming and outgoing connections. --- android/a2dp.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/android/a2dp.c b/android/a2dp.c index 452fdab9f..e65e5a303 100644 --- a/android/a2dp.c +++ b/android/a2dp.c @@ -541,14 +541,12 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err, avdtp_add_disconnect_cb(dev->session, disconnect_cb, dev); + /* Proceed to stream setup if initiator */ if (dev->io) { + int perr; + g_io_channel_unref(dev->io); dev->io = NULL; - } - - /* Proceed to stream setup if initiator */ - if (dev->state == HAL_A2DP_STATE_CONNECTING) { - int perr; perr = avdtp_discover(dev->session, discover_cb, dev); if (perr < 0) { @@ -739,6 +737,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data) } dev = a2dp_device_new(&dst); + bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTING); signaling_connect_cb(chan, err, dev); } -- 2.47.3