Modify the privilege for battry RX / TX function
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-headset-connection.c
old mode 100755 (executable)
new mode 100644 (file)
index bb76def..e489422
@@ -88,6 +88,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
        _bt_convert_addr_type_to_string(remote_address, conn_info->dev_info.device_address.addr);
        if (p_connection_list == NULL) {
                BT_INFO("None of device connected and this hasbeen triggered");
+               g_free(conn_info);
                return FALSE;
        }
        if (conn_info->connection_type == BT_AUDIO_A2DP) {
@@ -97,6 +98,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
                if (list == NULL) {
                        BT_INFO("Head Set didn't initiated a2dp connection");
                        BT_INFO("local device initiating A2DP connection");
+
                        _bt_audio_connect(0, BT_AUDIO_A2DP,
                                        &conn_info->dev_info.device_address, NULL);
                } else {
@@ -110,6 +112,7 @@ gboolean connect_remote_media_audio(gpointer user_data)
                if (list == NULL) {
                        BT_INFO("Headset didn't initiated HFP connection");
                        BT_INFO("local device intiating HFP Connection");
+
                        _bt_audio_connect(0, BT_AUDIO_HSP,
                                        &conn_info->dev_info.device_address, NULL);
                } else {
@@ -125,19 +128,22 @@ void _bt_get_bluetooth_device_info(char *remote_address, bluetooth_device_info_t
        GArray *dev_list = NULL;
        int size = 0;
        int i = 0;
-       bluetooth_device_info_t info;
+       bluetooth_device_info_t *info;
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
-       dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+
        if (device == NULL)
                return;
+
+       dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
+
        _bt_get_bonded_devices(&dev_list);
        size = (dev_list->len) / sizeof(bluetooth_device_info_t);
        for (i = 0; i < size; i++) {
-               info = g_array_index(dev_list, bluetooth_device_info_t, i);
-               _bt_convert_addr_type_to_string(bond_address, info.device_address.addr);
+               info = &g_array_index(dev_list, bluetooth_device_info_t, i);
+               _bt_convert_addr_type_to_string(bond_address, info->device_address.addr);
                if (strcmp(bond_address, remote_address) == 0) {
                        BT_INFO("Match found");
-                       memcpy(device, &info, sizeof(bluetooth_device_info_t));
+                       memcpy(device, info, sizeof(bluetooth_device_info_t));
                        g_array_free(dev_list, TRUE);
                        return;
                }
@@ -168,33 +174,33 @@ void _bt_start_timer_for_connection(char *remote_address, int connection_type)
        int size;
        int i;
        int j;
-       bluetooth_device_info_t info;
+       bluetooth_device_info_t *info;
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        dev_list = g_array_new(FALSE, FALSE, sizeof(gchar));
        _bt_get_bonded_devices(&dev_list);
        size = (dev_list->len) / sizeof(bluetooth_device_info_t);
 
        for (i = 0; i < size; i++) {
-               info = g_array_index(dev_list, bluetooth_device_info_t, i);
+               info = &g_array_index(dev_list, bluetooth_device_info_t, i);
                j = 0;
                _bt_convert_addr_type_to_string(bond_address,
-                               info.device_address.addr);
+                               info->device_address.addr);
                if (strcmp(bond_address, remote_address) != 0)
                        continue;
                BT_INFO("Device address Matched");
 
-               while (j != info.service_index) {
-                       BT_INFO("UUID %s", info.uuids[j]);
+               while (j != info->service_index) {
+                       BT_INFO("UUID %s", info->uuids[j]);
                        if (connection_type == BT_AUDIO_A2DP) {
-                               if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) {
+                               if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) {
                                        BT_INFO("Remote Device has A2DP Sink Support start timer");
-                                       _bt_headset_add_timer_function(BT_AUDIO_A2DP, &info);
+                                       _bt_headset_add_timer_function(BT_AUDIO_A2DP, info);
                                        goto end;
                                }
                        } else {
-                               if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) {
+                               if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) {
                                        BT_INFO("Remote Device has HFP Sink Support start timer");
-                                       _bt_headset_add_timer_function(BT_AUDIO_HSP, &info);
+                                       _bt_headset_add_timer_function(BT_AUDIO_HSP, info);
                                        goto end;
                                }
                        }
@@ -207,10 +213,11 @@ end:
 
 void __bt_connection_manager_set_state(char *remote_address, int event)
 {
-       bt_connection_node_info_t *info = g_new0(bt_connection_node_info_t, 1);
+       bt_connection_node_info_t *info;
 
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        if (event == BLUETOOTH_EVENT_AG_CONNECTED) {
+               info = g_new0(bt_connection_node_info_t, 1);
                info->state = BLUETOOTH_HFP_CONNECTED;
                _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
                _bt_convert_addr_type_to_string(bond_address,
@@ -234,6 +241,7 @@ void __bt_connection_manager_set_state(char *remote_address, int event)
                p_connection_list = g_list_remove(p_connection_list, h_conn);
                g_free(h_conn);
        } else if (event == BLUETOOTH_EVENT_AV_CONNECTED) {
+               info = g_new0(bt_connection_node_info_t, 1);
                info->state = BLUETOOTH_A2DP_CONNECTED;
                _bt_get_bluetooth_device_info(remote_address, &info->dev_info);
                _bt_convert_addr_type_to_string(bond_address,