add device disappear event 74/29474/2 accepted/tizen/common/20141030.230104 accepted/tizen/ivi/20141107.010905 submit/tizen/20141030.031347 submit/tizen/20141030.072151 submit/tizen_mobile/20141119.000000 submit/tizen_mobile/20141120.000000
authorCorentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
Tue, 28 Oct 2014 09:57:21 +0000 (10:57 +0100)
committerCorentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
Tue, 28 Oct 2014 10:46:55 +0000 (11:46 +0100)
When BlueZ removes some scanned devices, it previously always trigs the
bond destroy event which is sent by API layer.

This fix consists of adding paired devices to g_list and verify paired
device status when removing device interface and so fire device disappeared
or bond destroy events.

This patch is combined with ea4787499cb21d2bfc744aad7b8ba103efe67845 from
platform/core/api/bluetooth API component.

It also removes static attribute from _bt_adapter_set_status() function in
order to update adapter power status in bt-service-event-receiver.

Change-Id: Idd7406b7add402689edaad06590f7c0b4a14bee5
Signed-off-by: Corentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
bt-api/bt-event-handler.c
bt-service/bt-service-adapter.c
bt-service/bt-service-event-receiver.c
bt-service/bt-service-event-sender.c
bt-service/include/bt-service-adapter.h
include/bluetooth-api.h
include/bt-internal-types.h

index f55b748..9cbea92 100644 (file)
@@ -337,6 +337,17 @@ static DBusHandlerResult __bt_adapter_event_filter(DBusConnection *conn,
                                event_info->cb, event_info->user_data);
 
                g_free(device_info);
+       } else if (strcasecmp(member, BT_DEVICE_DISAPPEARED) == 0) {
+               bluetooth_device_info_t *device_info;
+
+               device_info = __bt_get_device_info_in_message(msg, &result);
+               retv_if(device_info == NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
+
+               _bt_common_event_cb(BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED,
+                               result, device_info,
+                               event_info->cb, event_info->user_data);
+               g_free(device_info);
        } else if (strcasecmp(member, BT_BOND_CREATED) == 0) {
                bluetooth_device_info_t *device_info;
 
index 523b266..4ff70f7 100644 (file)
@@ -589,7 +589,7 @@ static void __launch_bt_service(int status, int run_type)
        bundle_free(kb);
 }
 
-static void __bt_adapter_set_status(bt_status_t status)
+void _bt_adapter_set_status(bt_status_t status)
 {
        adapter_status = status;
 }
@@ -741,12 +741,12 @@ void _bt_handle_adapter_added(void)
 
        __bt_set_enabled();
 
-       __bt_adapter_set_status(BT_ACTIVATED);
+       _bt_adapter_set_status(BT_ACTIVATED);
 }
 
 void _bt_handle_adapter_removed(void)
 {
-       __bt_adapter_set_status(BT_DEACTIVATED);
+       _bt_adapter_set_status(BT_DEACTIVATED);
 
        vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
                                (vconf_callback_fn)__bt_phone_name_changed_cb);
@@ -800,7 +800,7 @@ int _bt_enable_adapter(void)
                        return BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED;
        }
 
-       __bt_adapter_set_status(BT_ACTIVATING);
+       _bt_adapter_set_status(BT_ACTIVATING);
 
        proxy = __bt_get_core_proxy();
        if (!proxy)
@@ -811,7 +811,7 @@ int _bt_enable_adapter(void)
                                        G_TYPE_INVALID,
                                        G_TYPE_INVALID) == FALSE) {
 
-               __bt_adapter_set_status(BT_DEACTIVATED);
+               _bt_adapter_set_status(BT_DEACTIVATED);
 
                if (err != NULL) {
                        BT_ERR("Bt core call failed: [%s]", err->message);
@@ -851,7 +851,7 @@ int _bt_disable_adapter(void)
                        return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
        }
 
-       __bt_adapter_set_status(BT_DEACTIVATING);
+       _bt_adapter_set_status(BT_DEACTIVATING);
 
        proxy = __bt_get_core_proxy();
        if (!proxy)
@@ -860,7 +860,7 @@ int _bt_disable_adapter(void)
        if (dbus_g_proxy_call(proxy, "DisableAdapter", NULL,
                                       G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
                BT_ERR("Bt core call failed");
-               __bt_adapter_set_status(BT_ACTIVATED);
+               _bt_adapter_set_status(BT_ACTIVATED);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
index def6528..e175a40 100644 (file)
@@ -709,8 +709,13 @@ void __bt_adapter_property_changed_event(DBusMessageIter *msg_iter, const char *
                dbus_message_iter_recurse(&dict_iter, &value_iter);
                dbus_message_iter_get_basic(&value_iter, &power);
 
-               power_event = (power == TRUE) ? BLUETOOTH_EVENT_ENABLED :
-                               BLUETOOTH_EVENT_DISABLED;
+               if (power == TRUE) {
+                       power_event = BLUETOOTH_EVENT_ENABLED;
+                       _bt_adapter_set_status(BT_ACTIVATED);
+               } else {
+                       power_event = BLUETOOTH_EVENT_DISABLED;
+                       _bt_adapter_set_status(BT_DEACTIVATED);
+               }
 
                BT_ERR("send power state: %d", power);
                /* Send event to application */
@@ -872,6 +877,7 @@ void __bt_device_property_changed_event(DBusMessageIter *msg_iter, const char *p
 
                        GList *node;
                        bt_remote_dev_info_t *dev_info;
+                       bt_remote_dev_info_t *new_dev_info;
 
                        dbus_message_iter_recurse(&dict_iter, &value_iter);
                        dbus_message_iter_get_basic(&value_iter, &paired);
@@ -903,12 +909,19 @@ void __bt_device_property_changed_event(DBusMessageIter *msg_iter, const char *p
                                if (strcasecmp(dev_info->address, address) == 0) {
                                        g_list = g_list_remove(g_list, dev_info);
                                        _bt_free_device_info(dev_info);
+
+                                       new_dev_info =  _bt_get_remote_device_info(address);
+                                       if (new_dev_info == NULL) {
+                                               g_free(address);
+                                               return;
+                                       }
+                                       g_list = g_list_append(g_list, new_dev_info);
                                }
                                node = g_list_next(node);
                        }
 
                        if (_bt_is_device_creating() == TRUE) {
-                               BT_DBG("Try to Pair by me");
+                               BT_DBG("Try to Pair by me or already paired");
                        } else {
                                _bt_send_event(BT_ADAPTER_EVENT,
                                        BLUETOOTH_EVENT_BONDING_FINISHED,
@@ -1643,18 +1656,34 @@ static DBusHandlerResult __bt_manager_event_filter(DBusConnection *conn,
 
                                _bt_convert_device_path_to_address(object_path, address);
 
-                               _bt_send_event(BT_ADAPTER_EVENT,
-                                       BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
-                                       DBUS_TYPE_INT32, &result,
-                                       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) {
+                                       if (strcasecmp(dev_info->address, address) == 0) {
+                                               if (dev_info->paired) {
+                                                       BT_DBG("send bt bond destroy event");
+                                                       _bt_send_event(BT_ADAPTER_EVENT,
+                                                               BLUETOOTH_EVENT_BONDED_DEVICE_REMOVED,
+                                                               DBUS_TYPE_INT32, &result,
+                                                               DBUS_TYPE_STRING, &address,
+                                                               DBUS_TYPE_INVALID);
+                                               } else {
+                                                       BT_DBG("Bluez removes device %s, send device disappear event", dev_info->name);
+                                                       _bt_send_event(BT_ADAPTER_EVENT,
+                                                               BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED,
+                                                               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);
+                                               }
                                                g_list = g_list_remove(g_list, dev_info);
                                                _bt_free_device_info(dev_info);
                                                break;
@@ -2260,23 +2289,26 @@ void _bt_get_temp_remote_devinfo(void)
 
        node = g_list_first(g_list);
 
-       while (node != NULL){
+       while (node != NULL) {
                dev_info = (bt_remote_dev_info_t *)node->data;
-
-               _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);
-
+               /* do not search paired devices.
+                * Paired devices are in g_list in order to trig device disappear
+                * or remove bonding events */
+               if (!dev_info->paired) {
+                       _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);
        }
 }
index 1b64048..1856d53 100644 (file)
@@ -97,6 +97,9 @@ int _bt_send_event(int event_type, int event, int type, ...)
        case BLUETOOTH_EVENT_REMOTE_DEVICE_FOUND:
                signal = BT_DEVICE_FOUND;
                break;
+       case BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED:
+               signal = BT_DEVICE_DISAPPEARED;
+               break;
        case BLUETOOTH_EVENT_DISCOVERY_FINISHED:
                signal = BT_DISCOVERY_FINISHED;
                break;
index cbe40e0..079e238 100644 (file)
@@ -84,6 +84,8 @@ gboolean _bt_get_discovering_property(void);
 
 unsigned int _bt_get_discoverable_timeout_property(void);
 
+void _bt_adapter_set_status(bt_status_t status);
+
 bt_status_t _bt_adapter_get_status(void);
 
 void _bt_handle_flight_mode_noti(void);
index abdd30c..d006dc7 100644 (file)
@@ -242,6 +242,7 @@ typedef enum {
        BLUETOOTH_EVENT_DEVICE_AUTHORIZED,          /**< Bluetooth event authorize device */
        BLUETOOTH_EVENT_DEVICE_UNAUTHORIZED,        /**< Bluetooth event unauthorize device */
        BLUETOOTH_EVENT_DISCOVERABLE_TIMEOUT_CHANGED,  /**< Bluetooth event mode changed */
+       BLUETOOTH_EVENT_REMOTE_DEVICE_DISAPPEARED, /**< Bluetooth event remote device disappeared*/
 
        BLUETOOTH_EVENT_SERVICE_SEARCHED = BLUETOOTH_EVENT_SDP_BASE,
                                                    /**< Bluetooth event serice search base id */
index 838d780..abede65 100644 (file)
@@ -215,6 +215,7 @@ typedef struct {
 #define BT_DISCOVERY_STARTED "DiscoveryStarted"
 #define BT_DISCOVERY_FINISHED "DiscoveryFinished"
 #define BT_DEVICE_FOUND "DeviceFound"
+#define BT_DEVICE_DISAPPEARED "DeviceDisappeared"
 #define BT_DEVICE_CONNECTED "DeviceConnected"
 #define BT_DEVICE_DISCONNECTED "DeviceDisconnected"
 #define BT_BOND_CREATED "BondCreated"