Add the device lists of scanning to fix the crash issue 65/12265/1
authorWu zheng <wu.zheng@intel.com>
Wed, 13 Nov 2013 07:06:33 +0000 (15:06 +0800)
committerWu zheng <wu.zheng@intel.com>
Wed, 13 Nov 2013 07:06:33 +0000 (15:06 +0800)
Add the device lists of scanning.
So that providing the device lists when UI is needed.

Bluetooth-frwk is stable when it own the list by itself.

If getting from Bluez. Bluetooth-frwk will crash sometime.
The root cause is  message format issues.

Thefefore, Bluetooth-frwk owner the device lists.
Bluetooth-frwk will be more stable.

Change-Id: If69def056791303fdb06f898259f78024607a5fd

bt-service/bt-service-event-receiver.c

index 0683c69..1c29665 100644 (file)
@@ -42,6 +42,7 @@
 static DBusGConnection *manager_conn = NULL;
 static DBusGConnection *obexd_conn = NULL;
 static DBusGConnection *opc_obexd_conn = NULL;
+static GList *g_list = NULL;
 
 static guint event_id;
 
@@ -631,6 +632,8 @@ void _bt_handle_adapter_event(DBusMessage *msg)
        } else if (strcasecmp(member, "InterfacesRemoved") == 0) {
                const char *object_path = NULL;
                char *address;
+               bt_remote_dev_info_t * dev_info;
+               GList * node;
 
                /* Bonding from remote device */
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
@@ -647,6 +650,19 @@ void _bt_handle_adapter_event(DBusMessage *msg)
                        DBUS_TYPE_STRING, &address,
                        DBUS_TYPE_INVALID);
 
+               node = g_list_first(g_list);
+
+               while (node != NULL){
+                       dev_info = (bt_remote_dev_info_t *)node->data;
+                       if (strcasecmp(dev_info->address,
+                                                       address) == 0) {
+                               g_list = g_list_remove(g_list, dev_info);
+                               _bt_free_device_info(dev_info);
+                               break;
+                       }
+                       node = g_list_next(node);
+               }
+
                g_free(address);
        }
 }
@@ -1564,6 +1580,23 @@ static int __bt_get_object_path(DBusMessage *msg, char **path)
        return BLUETOOTH_ERROR_NONE;
 }
 
+static void __bt_devices_list_free()
+{
+       bt_remote_dev_info_t *dev_info;
+       GList *node;
+
+       node = g_list_first(g_list);
+
+       while (node != NULL){
+               dev_info = (bt_remote_dev_info_t *)node->data;
+
+               g_list = g_list_remove(g_list, dev_info);
+               _bt_free_device_info(dev_info);
+
+               node = g_list_next(node);
+       }
+}
+
 static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
                                           DBusMessage *msg, void *data)
 {
@@ -1623,7 +1656,7 @@ static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
                                        &dev_info->uuids, dev_info->uuid_count,
                                        DBUS_TYPE_INVALID);
 
-                               _bt_free_device_info(dev_info);
+                               g_list = g_list_append(g_list, dev_info);
                        }else if (bt_event == BT_MEDIA_TRANSFER_EVENT) {
                                __bt_parse_audio_properties(msg);
                        }
@@ -1643,6 +1676,8 @@ static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
                char *previous = NULL;
                char *current = NULL;
 
+               BT_DBG("NameOwnerChanged");
+
                if (__bt_get_owner_info(msg, &name, &previous, &current)) {
                        BT_ERR("Fail to get the owner info");
                        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -1654,6 +1689,7 @@ static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
                if (strcasecmp(name, "org.bluez") == 0) {
                        BT_DBG("Bluetoothd is terminated");
                        _bt_handle_adapter_removed();
+                       __bt_devices_list_free();
                }
 
                _bt_obex_server_check_allocation(&value);
@@ -2219,43 +2255,29 @@ void _bt_opp_client_event_deinit(void)
 
 void _bt_get_temp_remote_devinfo(void)
 {
-       GArray *devinfo = NULL;
-       bt_remote_dev_info_t dev_info;
-       int result, size, i;
-
-       devinfo = g_array_new(FALSE, FALSE, sizeof(gchar));
+       bt_remote_dev_info_t *dev_info;
+       GList *node;
+       int result = BLUETOOTH_ERROR_NONE;
 
-       result = _bt_get_remote_found_devices(&devinfo);
+       node = g_list_first(g_list);
 
-       if (result != BLUETOOTH_ERROR_NONE)
-       {
-               BT_DBG("_bt_get_temp_remote_devinfo failed with [%d]",result);
-       }
-       else
-       {
-               size = devinfo->len;
-               size = (devinfo->len) / sizeof(bt_remote_dev_info_t);
+       while (node != NULL){
+               dev_info = (bt_remote_dev_info_t *)node->data;
 
-               for (i=0; i<size; i++)
-               {
-                       dev_info = g_array_index(devinfo,
-                                       bt_remote_dev_info_t, i);
+               _bt_send_event(BT_ADAPTER_EVENT,
+                       BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_STRING, &dev_info->address,
+                       DBUS_TYPE_UINT32, &dev_info->class,
+                       DBUS_TYPE_INT16, &dev_info->rssi,
+                       DBUS_TYPE_STRING, &dev_info->name,
+                       DBUS_TYPE_BOOLEAN, &dev_info->paired,
+                       DBUS_TYPE_BOOLEAN, &dev_info->connected,
+                       DBUS_TYPE_BOOLEAN, &dev_info->trust,
+                       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+                       &dev_info->uuids, dev_info->uuid_count,
+                       DBUS_TYPE_INVALID);
 
-                       _bt_send_event(BT_ADAPTER_EVENT,
-                               BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND,
-                               DBUS_TYPE_INT32, &result,
-                               DBUS_TYPE_STRING, &dev_info.address,
-                               DBUS_TYPE_UINT32, &dev_info.class,
-                               DBUS_TYPE_INT16, &dev_info.rssi,
-                               DBUS_TYPE_STRING, &dev_info.name,
-                               DBUS_TYPE_BOOLEAN, &dev_info.paired,
-                               DBUS_TYPE_BOOLEAN, &dev_info.connected,
-                               DBUS_TYPE_BOOLEAN, &dev_info.trust,
-                               DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
-                               &dev_info.uuids, dev_info.uuid_count,
-                               DBUS_TYPE_INVALID);
-               }
+               node = g_list_next(node);
        }
-
-       g_array_free(devinfo, TRUE);
 }