[FRWK] Fix Audio Connection/Disconnection logic 03/150403/1
authorAtul Rai <a.rai@samsung.com>
Fri, 15 Sep 2017 10:15:50 +0000 (15:45 +0530)
committerAtul Rai <a.rai@samsung.com>
Fri, 15 Sep 2017 10:15:50 +0000 (15:45 +0530)
Change-Id: I78dd7a4e2850f8a8c8b064dc1f858c0a304e0187
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-service-adaptation/services/audio/a2dp_sink/bt-service-a2dp-sink.c
bt-service-adaptation/services/audio/a2dp_src/bt-service-a2dp-src.c
bt-service-adaptation/services/audio/bt-service-audio.c
bt-service-adaptation/services/include/bt-service-audio-common.h

index 17e9a7c..adeca5b 100644 (file)
@@ -134,10 +134,6 @@ static void __bt_handle_av_source_disconnected_state(bluetooth_device_address_t
 
        _bt_convert_addr_type_to_string(addr, address->addr);
 
-       if (!_bt_is_service_connected(addr, BT_AUDIO_A2DP_SOURCE)) {
-               BT_ERR("A2DP Disconnected for addr[%s], but it is already disconnected..", addr);
-               return;
-       }
        /* Set VCONF status for A2DP Disconnection */
        _bt_set_device_values(FALSE, VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
 
@@ -157,6 +153,12 @@ static void __bt_handle_av_source_disconnected_state(bluetooth_device_address_t
                        /* This means, AV Disconnect request has successfully passed, and real disconnect is completed */
                        BT_INFO("Neither AV Connect or AV Disconnect request is found..means, AV Profile is disconnected");
 
+                       /*
+                        * TODO: Below logic is not required for BT_AUDIO_CONNECT/BT_AUDIO_DISCONNECT.
+                        * But if Tizen supports a device with A2DP Sink and HFP both profiles (BT_AUDIO_HFP_SOURCE)
+                        * then below logic will be required for corresponding connect/disconnect function
+                        */
+#if 0
                        req_info = _bt_get_request_info_data(BT_AUDIO_CONNECT, addr);
                        if (req_info == NULL) {
                                BT_INFO("Audio Connect All request is also Not found..");
@@ -179,10 +181,19 @@ static void __bt_handle_av_source_disconnected_state(bluetooth_device_address_t
                                        BT_INFO("Pending connect is Not found..");
                                }
                        }
+#endif
                        goto check_wait_device;
                } else {
                        BT_ERR("AV Connect request has failed.."); /* DBUS return needed */
                        result = BLUETOOTH_ERROR_INTERNAL;
+
+                       /* Delete waiting device data if present for this device */
+                       wait_device = _bt_get_audio_wait_data();
+                       if (wait_device && strncasecmp(wait_device->address, addr, BT_ADDRESS_STRING_SIZE) == 0) {
+                               _bt_rel_wait_data();
+                               goto dbus_return;
+                       }
+
                        goto check_wait_device;
                }
        } else {
index ec94a7b..5d7273c 100644 (file)
@@ -89,6 +89,7 @@ static void __bt_handle_av_connected_state(bluetooth_device_address_t *address)
 
        connected = _bt_is_headset_type_connected(BT_AUDIO_A2DP, connected_address);
        if (connected) {
+               BT_INFO("connected_address: %s", connected_address);
                if (g_strcmp0(connected_address, addr) != 0) {
                        _bt_convert_addr_string_to_type(
                                        device_address.addr,
@@ -136,10 +137,6 @@ static void __bt_handle_av_disconnected_state(bluetooth_device_address_t *addres
 
        _bt_convert_addr_type_to_string(addr, address->addr);
 
-       if (!_bt_is_service_connected(addr, BT_AUDIO_A2DP)) {
-               BT_ERR("A2DP Disconnected for addr[%s], but it is already disconnected..", addr);
-               return;
-       }
        /* Set VCONF status for A2DP Disconnection */
        _bt_set_device_values(FALSE, VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED);
 
@@ -183,11 +180,25 @@ static void __bt_handle_av_disconnected_state(bluetooth_device_address_t *addres
                                } else {
                                        BT_INFO("Pending connect is Not found..");
                                }
+
+                               /* Delete waiting device data if present for this device */
+                               wait_device = _bt_get_audio_wait_data();
+                               if (wait_device && strncasecmp(wait_device->address, addr, BT_ADDRESS_STRING_SIZE) == 0) {
+                                       _bt_rel_wait_data();
+                                       goto dbus_return;
+                               }
                        }
                        goto check_wait_device;
                } else {
                        BT_ERR("AV Connect request has failed.."); /* DBUS return needed */
                        result = BLUETOOTH_ERROR_INTERNAL;
+                       /* Delete waiting device data if present for this device */
+                       wait_device = _bt_get_audio_wait_data();
+                       if (wait_device && strncasecmp(wait_device->address, addr, BT_ADDRESS_STRING_SIZE) == 0) {
+                               _bt_rel_wait_data();
+                               goto dbus_return;
+                       }
+
                        goto check_wait_device;
                }
        } else {
@@ -201,10 +212,12 @@ check_wait_device:
                goto dbus_return;
        }
 
+       BT_INFO("type: %d, ag_flag: %d, disconnection_type: %d", wait_device->type,
+                       wait_device->ag_flag, wait_device->disconnection_type);
        if (((wait_device->type == BT_AUDIO_ALL) &&
-                                (wait_device->ag_flag == TRUE)) ||
-                                (wait_device->type == BT_AUDIO_A2DP) ||
-                               (wait_device->disconnection_type == BT_AUDIO_A2DP)) {
+                               (wait_device->ag_flag == TRUE)) ||
+                       (wait_device->type == BT_AUDIO_A2DP) ||
+                       (wait_device->disconnection_type & BT_AUDIO_A2DP)) {
                if (g_strcmp0(wait_device->address, addr) != 0) {
                        BT_INFO("Trigger connect for the waiting device [%s], audio type [%d]",
                                        wait_device->address, wait_device->type);
index 6fe8ff2..062759c 100644 (file)
@@ -316,21 +316,7 @@ static int __bt_is_headset_connected(int current_conn_type, const char *address)
        int value = BLUETOOTH_ERROR_NONE;
        BT_DBG("Already connected headset addr  [%s] connected headset type [0x%x] current dev conn type [0x%x]",
                                connected_address, connected_device->type, current_conn_type);
-       if (connected_device->type == BT_AUDIO_ALL) {
-               if (current_conn_type == BT_AUDIO_A2DP_SOURCE) {
-                       disconn_type = BT_AUDIO_A2DP;
-               } else {
-                       disconn_type = connected_device->type & current_conn_type;
-               }
-       } else if (connected_device->type == BT_AUDIO_HFP_SOURCE) {
-               if (current_conn_type == BT_AUDIO_A2DP) {
-                       disconn_type = BT_AUDIO_A2DP_SOURCE;
-               } else {
-                       disconn_type = connected_device->type & current_conn_type;
-               }
-       } else {
-               disconn_type = connected_device->type;
-       }
+       disconn_type = connected_device->type & current_conn_type;
        BT_DBG("Attempt disconnection of Type [0x%x] of already connected device" , disconn_type);
        value = _bt_audio_disconnect(disconn_type, &device_address);
 
@@ -973,6 +959,15 @@ int _bt_audio_disconnect(int type, bluetooth_device_address_t *device_address)
                        BT_ERR("No audio service connected");
                        return BLUETOOTH_ERROR_NOT_CONNECTED;
                }
+       } else if (type == BT_AUDIO_HFP_SOURCE) {
+               if (_bt_is_service_connected(address, BT_AUDIO_A2DP_SOURCE)) {
+                       type = BT_AUDIO_A2DP_SOURCE;
+               } else if (_bt_is_service_connected(address, BT_AUDIO_HSP)) {
+                       type = BT_AUDIO_HSP;
+               } else {
+                       BT_ERR("No audio service connected");
+                       return BLUETOOTH_ERROR_NOT_CONNECTED;
+               }
        }
 
        value = __bt_is_headset_disconnecting(type);
index 8c4e2d7..765343f 100644 (file)
@@ -39,11 +39,11 @@ typedef enum {
 typedef enum {
        BT_AUDIO_HSP = 0x01,    /* HSP Connection */
        BT_AUDIO_A2DP = 0x02,           /* A2DP Source Connection, remote device is A2DP Sink */
-       BT_AUDIO_ALL = 0x03,            /* HSP and A2DP Source Connection */
+       BT_AUDIO_ALL = 0x03,            /* HSP and A2DP Source Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP) */
        BT_AVRCP_TARGET = 0x04, /* AVRCP Target Connection to remote AVRCP controller */
        BT_AVRCP = 0x08,        /* AVRCP ctrl Connection to remote AVRCP target */
        BT_AUDIO_A2DP_SOURCE = 0x10,    /* A2DP Sink Connection, remote device is A2DP Source */
-       BT_AUDIO_HFP_SOURCE = 0x20      /* HSP and A2DP Sink Connection */
+       BT_AUDIO_HFP_SOURCE = 0x11      /* HSP and A2DP Sink Connection (BT_AUDIO_HSP and BT_AUDIO_A2DP_SOURCE)*/
 } bt_audio_type_t;
 
 typedef enum {