Audio: Handle Profile Connection in progress error 70/250170/2
authorAnupam Roy <anupam.r@samsung.com>
Sun, 20 Dec 2020 17:01:39 +0000 (22:31 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 22 Dec 2020 12:28:08 +0000 (17:58 +0530)
Currently, bt-service does not check
if connection request for same device is
already under progress. This allows queuing
up multiple same requests in pending request list.
At the time of replying DBUS context, only one
request is returned & other requests are not freed.
In this patch, BLUETOOTH_ERROR_IN_PROGRESS error
is returned if same profile connection request
is pending.

Change-Id: I1e8ea43d8dc06e73b928c099bab8efc992b4125d
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-service/services/audio/bt-service-audio.c
bt-service/services/bt-request-handler.c
bt-service/services/include/bt-service-audio-common.h

index 9ebe68d..d251f57 100644 (file)
@@ -138,7 +138,8 @@ void _bt_add_headset_to_list(int type, int status, const char *address)
        bt_connected_headset_data_t *device;
        GList *node;
 
-       BT_DBG("_bt_add_headset_to_list \n");
+       BT_INFO("_bt_add_headset_to_list: Address [%s] Profile Type [%d] Connect status [%d]\n",
+               address, type, status);
 
        node = g_list_first(g_connected_list);
        while (node != NULL) {
@@ -290,6 +291,33 @@ static int __bt_is_headset_connecting(int type)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_audio_is_profile_connection_in_progress(int service_function,
+               bluetooth_device_address_t *address)
+{
+       invocation_info_t *req_info;
+       char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
+
+       BT_INFO("+");
+
+       if (!address)
+               return BLUETOOTH_ERROR_INTERNAL;
+
+       _bt_convert_addr_type_to_string(addr,
+                       (unsigned char *)address->addr);
+
+       /* Check if any application has posted same Connection Request already */
+       req_info = _bt_get_request_info_data(service_function, (char*) addr);
+       if (!req_info) {
+               BT_INFO("Connection can proceed");
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_INFO("Got Pending Audio Profile Connect Request[%d] for addr[%s]",
+                       service_function, addr);
+
+       return BLUETOOTH_ERROR_IN_PROGRESS;
+}
+
 static int __bt_is_headset_connected(int current_conn_type, const char *address)
 {
        gboolean connected = FALSE;
@@ -304,12 +332,12 @@ static int __bt_is_headset_connected(int current_conn_type, const char *address)
        /* Check if any other headset is connected */
        GList *node = NULL;
 
-       BT_DBG("Checking if any Headset connected or not: current device [%s] current audio type [%s]",
+       BT_INFO("Checking if any Headset connected or not: current device [%s] current audio type [%s]",
                        address, __convert_audio_type_to_string(current_conn_type));
        node = g_list_first(g_connected_list);
        while (node != NULL) {
                connected_device = node->data;
-               BT_DBG("A Device is already connected found in list [%s] audio type [%s]",
+               BT_INFO("A Device is already connected found in list [%s] audio type [%s]",
                                connected_device->device_address, __convert_audio_type_to_string(connected_device->type));
                if ((connected_device->type & current_conn_type)) {
                        g_strlcpy(connected_address, connected_device->device_address,
@@ -445,6 +473,7 @@ static int __bt_process_audio_profile_connect(bt_audio_type_t type, bluetooth_de
        }
 
        if (result == BLUETOOTH_ERROR_NONE) {
+               BT_INFO("Set Profile Connecting state");
                _bt_headset_set_local_connection(TRUE);
                /* Add data to the connected list */
                _bt_add_headset_to_list(type, BT_STATE_CONNECTING, addr);
@@ -994,6 +1023,8 @@ int _bt_audio_connect(int type,    bluetooth_device_address_t *device_address)
        if (ret == BLUETOOTH_ERROR_NONE) {
                BT_INFO("Waiting for disconnection...");
        } else if (ret == BLUETOOTH_ERROR_NOT_CONNECTED) {
+               BT_INFO("Proceed for connection: Type [%d] Address [%s]",
+                       type, address);
                ret = __bt_process_audio_profile_connect(type, device_address);
                if (ret != BLUETOOTH_ERROR_NONE) {
                        BT_ERR("Failed with %d", ret);
index 57b570f..ad3562b 100644 (file)
@@ -1621,9 +1621,13 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AV_CONNECT, &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AUDIO_A2DP, &address);
 
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("AV Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1641,9 +1645,13 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AUDIO_ALL, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AUDIO_CONNECT, &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AUDIO_ALL, &address);
 
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Audio All Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1701,9 +1709,13 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AUDIO_HSP, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AG_CONNECT, &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AUDIO_HSP, &address);
 
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("AG Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1743,8 +1755,14 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AV_SOURCE_CONNECT,
+                               &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AUDIO_A2DP_SOURCE, &address);
+
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("A2DP Source Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1783,8 +1801,14 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_hf_connect(&address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_HF_CONNECT,
+                               &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_hf_connect(&address);
+
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("HF Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1823,8 +1847,14 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_TARGET_CONNECT,
+                               &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AVRCP_TARGET, &address);
+
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("AVRCP Target Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
@@ -1863,8 +1893,14 @@ int __bt_bluez_request(int function_name,
                __bt_service_get_parameters(in_param1,
                                &address, sizeof(bluetooth_device_address_t));
 
-               result = _bt_audio_connect(BT_AVRCP, &address);
+               result = _bt_audio_is_profile_connection_in_progress(BT_AVRCP_CONTROL_CONNECT,
+                               &address);
+
+               if (result == BLUETOOTH_ERROR_NONE)
+                       result = _bt_audio_connect(BT_AVRCP, &address);
+
                if (result != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("AVRCP Control Connect Request has failed to execute");
                        char addr[BT_ADDRESS_STRING_SIZE];
                        _bt_convert_addr_type_to_string(addr, address.addr);
                        g_array_append_vals(*out_param1, addr, BT_ADDRESS_STRING_SIZE);
index 95a549f..f8a7fbe 100644 (file)
@@ -94,6 +94,8 @@ int _bt_audio_initialize(bt_service_module_t module);
 
 int _bt_audio_connect(int type, bluetooth_device_address_t *device_address);
 
+int _bt_audio_is_profile_connection_in_progress(int req_type, bluetooth_device_address_t *address);
+
 int _bt_audio_disconnect(int type, bluetooth_device_address_t *device_address);
 
 gboolean _bt_is_service_connected(char* address, int type);