Recover bluetoothd crash
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index 616d446..ced268a 100644 (file)
@@ -913,6 +913,9 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
        GVariant *param = NULL;
        bt_remote_dev_info_t *remote_dev_info;
        g_variant_iter_init(&value_iter, msg);
+#ifdef TIZEN_FEATURE_BT_DPM
+       int desktop_state = DPM_BT_ERROR;
+#endif
        while ((g_variant_iter_loop(&value_iter, "{sv}", &property, &val))) {
                BT_DBG("Property %s", property);
                if (strcasecmp(property, "Connected") == 0) {
@@ -968,8 +971,8 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                                BT_DBG("Name %s", remote_dev_info->name);
 
 #ifdef TIZEN_FEATURE_BT_DPM
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+                               _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+                               if (desktop_state == DPM_RESTRICTED) {
                                        bluetooth_device_class_t device_class;
                                        _bt_divide_device_class(&device_class, remote_dev_info->class);
 
@@ -1399,10 +1402,6 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path)
                BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE");
                _bt_handle_pxp_property_changed_event(val,
                                        object_path, BT_PXP_REPORTER_ROLE);
-       } else if (strcasecmp(interface_name, BT_PROXIMITY_MONITOR_INTERFACE) == 0) {
-               BT_DBG("BT_PROXIMITY_MONITOR_INTERFACE");
-               _bt_handle_pxp_property_changed_event(val,
-                                       object_path, BT_PXP_MONITOR_ROLE);
        }
        g_variant_unref(val);
 }
@@ -2190,12 +2189,13 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
 
                if (le_dev_info->adv_type != BT_LE_ADV_SCAN_RSP) {       /* ADV_IND */
                        adv_info = g_malloc0(sizeof(bt_le_adv_info_t));
-
                        adv_info->addr = g_strdup(le_dev_info->address);
                        adv_info->addr_type = le_dev_info->addr_type;
                        adv_info->rssi = le_dev_info->rssi;
                        adv_info->data_len = le_dev_info->adv_data_len;
                        adv_info->data = g_malloc0(le_dev_info->adv_data_len);
+                       memcpy(adv_info->data, le_dev_info->adv_data,
+                                       le_dev_info->adv_data_len);
 
                        if (__bt_add_adv_ind_info(adv_info) == 0) {
                                adv_info->timer_id = g_timeout_add(1000,
@@ -2671,7 +2671,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                        if (bt_event == BT_DEVICE_EVENT) {
                                bt_cache_info_t *cache_info;
                                bt_remote_dev_info_t *dev_info;
-
+#ifdef TIZEN_FEATURE_BT_DPM
+                               int desktop_state = DPM_BT_ERROR;
+#endif
                                ret_if(_bt_is_discovering() == FALSE &&
                                                _bt_is_le_scanning() == FALSE);
 
@@ -2704,8 +2706,8 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                                        dev_info->name = g_strdup(dev_info->address);
 
 #ifdef TIZEN_FEATURE_BT_DPM
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+                               _bt_dpm_get_bluetooth_desktop_connectivity_state(&desktop_state);
+                               if (desktop_state == DPM_RESTRICTED) {
                                        bluetooth_device_class_t device_class;
                                        _bt_divide_device_class(&device_class, dev_info->class);
                                        BT_DBG("[%s]device_class.major_class : %d", dev_info->name, device_class.major_class);
@@ -2797,9 +2799,11 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
 
                if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
                        BT_INFO_C("### Bluetoothd is terminated");
-                       if (_bt_adapter_get_status() == BT_ACTIVATED)
-                                _bt_disable_cb();
-
+                       if (_bt_adapter_get_status() != BT_DEACTIVATING &&
+                               _bt_adapter_get_status() != BT_DEACTIVATED) {
+                               BT_INFO_C("### Recover it");
+                               _bt_recover_adapter();
+                       }
                        _bt_handle_adapter_removed();
                        __bt_devices_list_free();
                }
@@ -2822,6 +2826,10 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                _bt_stop_advertising_by_terminated_process(name);
                /* Stop LE Scan */
                _bt_stop_le_scan(name);
+
+               /* Stop the Proximity reporter service */
+               _bt_proximity_reporter_stop_by_terminated_process(name);
+
                g_free(name);
                g_free(previous);
                g_free(current);