Modify the privilege for battry RX / TX function
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-audio.c
index 82e288d..7dd091c 100644 (file)
 #include "bt-service-headset-connection.h"
 
 #ifdef TIZEN_SUPPORT_DUAL_HF
+#ifdef TIZEN_PROFILE_WEARABLE
 #define VCONF_KEY_BT_HOST_BT_MAC_ADDR "db/wms/host_bt_mac"
 #endif
+#endif
 
 typedef struct {
        unsigned int type;
@@ -309,41 +311,6 @@ static void __bt_set_headset_disconnection_type(const char *address)
        }
 }
 
-#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
-void _bt_check_already_connected_headset(int type, char *address)
-{
-       GList *node;
-       char connected_address[BT_ADDRESS_STRING_SIZE + 1];
-       bluetooth_device_address_t device_address;
-       int device_count = 0;
-
-       if (address != NULL) {
-               node = g_list_first(g_connected_list);
-               while (node != NULL) {
-                       bt_connected_headset_data_t *connected_device = node->data;
-                       if ((connected_device->type & type) &&
-                               (g_strcmp0(connected_device->device_address, address) != 0)) {
-                               device_count++;
-                               /* Disconnect the earliest(1st) connected headset */
-                               if (device_count == 1) {
-                                       g_strlcpy(connected_address,
-                                               connected_device->device_address,
-                                               BT_ADDRESS_STRING_SIZE + 1);
-                                       BT_DBG("Earliest/First Connected headset %s",
-                                               connected_address);
-                               } else if (device_count == MAX_CONNECTED_HEADSET) {
-                                       _bt_convert_addr_string_to_type(device_address.addr,
-                                               connected_address);
-                                       _bt_audio_disconnect(0, type, &device_address, NULL);
-                                       return;
-                               }
-                       }
-                       node = g_list_next(node);
-               }
-       }
-}
-#endif
-
 gboolean _bt_is_headset_type_connected(int type, char *address)
 {
        GList *node;
@@ -367,27 +334,27 @@ gboolean _bt_is_headset_type_connected(int type, char *address)
 #ifdef TIZEN_SUPPORT_DUAL_HF
 gboolean __bt_is_companion_device(const char *addr)
 {
-       if (TIZEN_PROFILE_WEARABLE) {
-               char *host_device_address = NULL;
-               host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
-
-               if (!host_device_address) {
-                       BT_INFO("Failed to get a companion device address");
-                       return FALSE;
-               }
+#ifdef TIZEN_PROFILE_WEARABLE
+       char *host_device_address = NULL;
+       host_device_address = vconf_get_str(VCONF_KEY_BT_HOST_BT_MAC_ADDR);
 
-               if (g_strcmp0(host_device_address, addr) == 0) {
-                       BT_INFO("Found companion device");
-                       free(host_device_address);
-                       return TRUE;
-               }
+       if (!host_device_address) {
+               BT_INFO("Failed to get a companion device address");
+               return FALSE;
+       }
 
+       if (g_strcmp0(host_device_address, addr) == 0) {
+               BT_INFO("Found companion device");
                free(host_device_address);
-               return FALSE;
-       } else {
-               /* TODO : Need to add companion device check condition for Phone models */
-               return FALSE;
+               return TRUE;
        }
+
+       free(host_device_address);
+       return FALSE;
+#else
+       /* TODO : Need to add companion device check condition for Phone models */
+       return FALSE;
+#endif
 }
 #endif
 
@@ -409,19 +376,8 @@ static int __bt_is_headset_connected(int type, int req_id,
        while (node != NULL) {
                connected_device = node->data;
                if ((connected_device->type & type)) {
-#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
-                       device_count++;
-                       /* Disconnect the earliest(1st) connected headset */
-                       if (device_count == 1)
-                               g_strlcpy(connected_address, connected_device->device_address,
-                                       BT_ADDRESS_STRING_SIZE + 1);
-
-                       if (g_strcmp0(connected_device->device_address, address) == 0)
-                               return BLUETOOTH_ERROR_ALREADY_CONNECT;
-#else
                        g_strlcpy(connected_address, connected_device->device_address,
                                        BT_ADDRESS_STRING_SIZE + 1);
-#endif
 #ifdef TIZEN_SUPPORT_DUAL_HF
                        is_companion_device = __bt_is_companion_device(connected_address);
                        BT_INFO(" is_companion_device[%d]", is_companion_device);
@@ -431,16 +387,9 @@ static int __bt_is_headset_connected(int type, int req_id,
                                break;
                        }
 #else
-#ifdef TIZEN_BT_DUAL_HEADSET_CONNECT
-                       if (device_count == MAX_CONNECTED_HEADSET) {
-                               connected = TRUE;
-                               break;
-                       }
-#else
                        connected = TRUE;
                        break;
 #endif
-#endif
                }
                node = g_list_next(node);
        }
@@ -457,7 +406,7 @@ static int __bt_is_headset_connected(int type, int req_id,
                return BLUETOOTH_ERROR_NOT_CONNECTED;
 #endif
 
-       /* Convert BD adress from string type */
+       /* Convert BD address from string type */
        _bt_convert_addr_string_to_type(device_address.addr, connected_address);
        int value = BLUETOOTH_ERROR_NONE;
        value = _bt_audio_disconnect(0, connected_device->type & type, &device_address, NULL);
@@ -564,6 +513,7 @@ void _bt_add_headset_to_list(int type, int status, const char *address)
        }
 
        connected_device = g_malloc0(sizeof(bt_connected_headset_data_t));
+
        connected_device->device_state = status;
        if ((status == BT_STATE_CONNECTED) || (status == BT_STATE_CONNECTING))
                connected_device->type |= type;
@@ -653,7 +603,7 @@ static gboolean __bt_device_support_uuid(char *remote_address,
        int size;
        int i;
        int j;
-       bluetooth_device_info_t info;
+       bluetooth_device_info_t *info;
        char bond_address[BT_ADDRESS_STRING_SIZE] = { 0 };
        gboolean ret = FALSE;
 
@@ -665,23 +615,23 @@ static gboolean __bt_device_support_uuid(char *remote_address,
        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);
                _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");
                j = 0;
-               while (j != info.service_index) {
+               while (j != info->service_index) {
                        if (type == BT_AUDIO_HSP) {
-                               if (strcmp(info.uuids[j], HFP_HS_UUID) == 0) {
+                               if (strcmp(info->uuids[j], HFP_HS_UUID) == 0) {
                                        BT_INFO("HFP HS UUID exists");
                                        ret = TRUE;
                                        goto end;
                                }
                        } else if (type == BT_AUDIO_A2DP) {
-                               if (strcmp(info.uuids[j], A2DP_SINK_UUID) == 0) {
+                               if (strcmp(info->uuids[j], A2DP_SINK_UUID) == 0) {
                                        BT_INFO("A2DP SINK UUID exists");
                                        ret = TRUE;
                                        goto end;
@@ -742,6 +692,7 @@ int _bt_audio_connect(int request_id, int type,
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
        func_data = g_malloc0(sizeof(bt_audio_function_data_t));
+
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
        func_data->type = type;
@@ -819,8 +770,7 @@ int _bt_audio_connect(int request_id, int type,
        value = __bt_is_headset_connected(type, request_id, address);
 
        if (value == BLUETOOTH_ERROR_ALREADY_CONNECT) {
-               result = BLUETOOTH_ERROR_ALREADY_CONNECT;
-               goto fail;
+               return BLUETOOTH_ERROR_ALREADY_CONNECT;
        } else if (value == BLUETOOTH_ERROR_NOT_CONNECTED) {
                value = __bt_is_headset_connecting(type);
                if (value != BLUETOOTH_ERROR_NONE) {
@@ -842,8 +792,7 @@ int _bt_audio_connect(int request_id, int type,
                /* Add data to the connected list */
                _bt_add_headset_to_list(type, BT_STATE_CONNECTING, address);
        } else if (value == BLUETOOTH_ERROR_IN_PROGRESS) {
-               result = BLUETOOTH_ERROR_IN_PROGRESS;
-               goto fail;
+               return BLUETOOTH_ERROR_IN_PROGRESS;
        }
 
        if (out_param1)
@@ -855,9 +804,6 @@ fail:
                g_array_append_vals(out_param1, address,
                                BT_ADDRESS_STR_LEN);
 
-       g_free(func_data->address);
-       g_free(func_data);
-
        return result;
 }
 
@@ -966,9 +912,6 @@ fail:
                g_array_append_vals(out_param1, address,
                                BT_ADDRESS_STR_LEN);
 
-       g_free(func_data->address);
-       g_free(func_data);
-
        return result;
 }
 
@@ -1223,7 +1166,7 @@ static int __bt_auto_connect_alarm_cb(alarm_id_t alarm_id, void* user_param)
        BT_DBG("result [%d]", result);
 
        if (auto_connect_timer.retry_count <= 0) {
-               BT_INFO("Stopping Auto connect retry");
+               BT_INFO(" ### Stopping Auto connect retry");
                auto_connect_timer.alarm_id = 0;
        } else {
                result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
@@ -1267,7 +1210,7 @@ int _bt_audio_start_auto_connect(gboolean linkloss_flag)
                                                BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS;
 
        if (linkloss_flag) {
-               BT_INFO("Start auto connection after linkloss");
+               BT_INFO(" ### Start auto connection after linkloss");
                result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_LINKLOSS,
                                                __bt_auto_connect_alarm_cb, NULL, &alarm_id);
                if (result != BLUETOOTH_ERROR_NONE)
@@ -1276,7 +1219,7 @@ int _bt_audio_start_auto_connect(gboolean linkloss_flag)
                        auto_connect_timer.alarm_id = alarm_id;
 
        } else {
-               BT_INFO("Start auto connection after BT activated");
+               BT_INFO(" ### Start auto connection after BT activated");
                result = _bt_service_set_alarm(BT_AUTO_CONNECT_TIMEOUT_AFTER_BT_ACTIVATED,
                                                __bt_auto_connect_alarm_cb, NULL, &alarm_id);
                if (result == BLUETOOTH_ERROR_NONE)