[Adapt] Add error handling of 'Get bonded device info' call to stack 93/79493/1
authorAnupam Roy <anupam.r@samsung.com>
Sun, 10 Jul 2016 13:19:48 +0000 (09:19 -0400)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 11 Jul 2016 12:01:46 +0000 (08:01 -0400)
It is possible that even after successful completion of Bonding,
get bonded device info query to stack gets fails due to internal
stack error. In such case, BT MW need to handle the error in order
to avoid waiting for properties infinitely.
User will get fail popup 'Unable to Bond with Device X'
and can re-attempt to establish bonding.

Also, instead of returning from cb_device_properties_cb in case
of 0 properties, send the event to BT MW to take necessary action.

Change-Id: I56402fe7e281866b4a5e6bb192f81c40864cbd05
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/oal-device-mgr.c
bt-service-adaptation/services/device/bt-service-core-device.c

index 97919e4..31fb831 100755 (executable)
@@ -285,22 +285,28 @@ void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
        gsize size = 0;
        bdstr_t bdstr;
 
-       /*Below code is commented out for handling Get Bonded devices for BLuez case.
-       GetALl properties on a particular device interface can reyurn properties of
-       an unpaired or untrusted device. If We block the below event, Application
-       request (BT_GET_BONDED_DEVICES) will timeout on DBUS */
-#if 0
-       if(BT_STATUS_SUCCESS != status) {
-               BT_ERR("[%s]status: %d", bdt_bd2str((bt_address_t*)bd_addr, &bdstr), status);
-               return;
-       }
-#endif
-       BT_DBG("[%s]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr));
+       BT_DBG("[%s]status: [%d] num properties [%d]", bdt_bd2str((bt_address_t*)bd_addr, &bdstr),
+                       status, num_properties);
+
        dev_info = g_new0(remote_device_t, 1);
        memcpy(dev_info->address.addr, bd_addr->address, 6);
        parse_device_properties(num_properties, properties, dev_info, &adv_info);
 
-       if(num_properties == 1) {
+       if (num_properties == 0) {
+               BT_ERR("!!Unexpected!! num properties is 0 status [%d]", status);
+               /* It is possible that app called get bonded device info for a device
+                  which is not yet bonded or udner bonding, in such case, stack will return no properties.
+                  It is also possible that after bonding is done, BT MW attempted to fetch
+                  bonded device info, but due to internal stack error, 0 properties with status FAIL
+                  are received from stack. In such cases, simply send the event to BT MW
+                  and let it handle this event */
+               event_dev_properties_t *dev_props_event = g_new0(event_dev_properties_t, 1);
+               memcpy(&dev_props_event->device_info,
+                               dev_info, sizeof(remote_device_t));
+               event_data = dev_props_event;
+               event = OAL_EVENT_DEVICE_PROPERTIES;
+               size = sizeof(event_dev_properties_t);
+       } else if (num_properties == 1) {
                /* For one particular property a dedicated event to be sent */
                switch(properties[0].type) {
                case BT_PROPERTY_BDNAME:
index 23c7df7..f8d8df8 100644 (file)
@@ -74,6 +74,7 @@ bt_bond_data_t *trigger_bond_info;
 bt_bond_data_t *trigger_unbond_info;
 bt_pairing_data_t *trigger_pairing_info;
 
+
 typedef enum {
   BT_DEVICE_BOND_STATE_NONE,
   BT_DEVICE_BOND_STATE_CANCEL_DISCOVERY,
@@ -380,15 +381,31 @@ static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
        }
 
        BT_INFO("Bonding successfully completed");
-       /* TODO: Bonding state will be cleaned up & BONDING FINISHED EVENT
+       /* Bonding state will be cleaned up & BONDING FINISHED EVENT
           will be sent only when Properties are fetched from stack
-          Till that time lets not free trigger_bond_info */
-       __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
-                       trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
-
+          Till that time lets not free trigger_bond_info.
+          However it is possible that while fetching device properties, internal
+          stack error can occur which can lead to no valid properties or
+          no properties at all. So in such cases, we must not wait for properties,
+          otherwise, it can lead to infinite wait  */
        _bt_convert_addr_string_to_type(dev_addr.addr,
-                        trigger_bond_info->addr);
-       _bt_device_get_bonded_device_info(&dev_addr);
+                       trigger_bond_info->addr);
+
+       if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
+               BT_DBG("BOnded device info query posted to stack successfully");
+               __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
+                               trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+       } else {
+               BT_DBG("Possibly internal stack error in bonded device info query, perform cleanup");
+               __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
+                               trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+               /* Destroy if at all device got bonded at stack level */
+               device_destroy_bond((bt_address_t *)trigger_bond_info->dev_addr);
+
+               __bt_free_bond_info(BT_DEVICE_BOND_INFO);
+               __bt_free_pairing_info(&trigger_pairing_info);
+       }
+
        BT_INFO("-");
 }
 
@@ -414,6 +431,7 @@ static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
                __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
                __bt_free_pairing_info(&trigger_pairing_info);
        } else if (trigger_bond_info) {
+               BT_ERR("Bonding was removed");
                __bt_device_handle_bond_state();
        }
        BT_INFO("-");
@@ -542,7 +560,6 @@ static void __bt_device_event_handler(int event_type, gpointer event_data)
             BT_INFO("ACL Connected event Received");
             event_dev_conn_status_t* param = event_data;
             __bt_device_acl_state_changed_callback(param, TRUE);
-            __bt_device_handle_bond_removal_event(&(param->address));
             break;
        }
        case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
@@ -992,6 +1009,12 @@ static int __bt_device_handle_bond_state(void)
                break;
        case BT_DEVICE_BOND_STATE_NONE:
                BT_INFO("Create Bond failed!!");
+               if (trigger_bond_info) {
+                       __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
+                                       trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+                       __bt_free_bond_info(BT_DEVICE_BOND_INFO);
+                       __bt_free_pairing_info(&trigger_pairing_info);
+               }
                break;
        default:
                break;