Fix svace 2.2 version issues
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-event-receiver.c
index 639e932..335a1ab 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "bt-service-opp-client.h"
 
-#ifdef TIZEN_DPM_ENABLE
+#ifdef TIZEN_FEATURE_BT_DPM
 #include "bt-service-dpm.h"
 #endif
 
@@ -55,6 +55,7 @@ static GDBusConnection *opc_obexd_conn;
 static GList *p_cache_list = NULL;
 
 static guint event_id;
+static guint le_scan_event_id = 0;
 static guint session_reinit_timer;
 guint nap_connected_device_count = 0;
 static guint hid_connected_device_count = 0;
@@ -344,7 +345,7 @@ gboolean _bt_discovery_finished_cb(gpointer user_data)
 static gboolean __bt_le_discovery_finished_cb(gpointer user_data)
 {
        int result = BLUETOOTH_ERROR_NONE;
-       event_id = 0;
+       le_scan_event_id = 0;
        GVariant *param = NULL;
        if (_bt_get_discovering_property(DISCOVERY_ROLE_LE) == FALSE) {
                if (_bt_get_cancel_by_user() == TRUE)
@@ -430,6 +431,22 @@ static void __bt_device_remote_connected_properties(
        BT_DBG("-");
 }
 
+gboolean __bt_handle_is_flight_mode_enabled(void)
+{
+#ifdef TIZEN_FEATURE_FLIGHTMODE_ENABLED
+       int is_flight_mode = 0;
+       int ret = -1;
+
+       ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &is_flight_mode);
+       if (ret != 0)
+               BT_ERR("vconf_get_bool failed");
+
+       return (is_flight_mode == 0) ? FALSE : TRUE;
+#else
+       return FALSE;
+#endif
+}
+
 void _bt_handle_adapter_event(GVariant *msg, const char *member)
 {
        BT_DBG("+");
@@ -468,8 +485,6 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member)
 
                /* Bonding from remote device */
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               if (address == NULL)
-                       return;
 
                g_variant_get(msg, "(&o)", &object_path);
 
@@ -652,7 +667,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                BLUETOOTH_EVENT_LE_DISCOVERY_STARTED,
                                param);
                        } else {
-                               ret_if(event_id > 0);
+                               ret_if(le_scan_event_id > 0);
 
                                adapter_proxy = _bt_get_adapter_proxy();
                                ret_if(adapter_proxy == NULL);
@@ -670,7 +685,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                if (ret)
                                        g_variant_unref(ret);
 
-                               event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
+                               le_scan_event_id = g_timeout_add(BT_DISCOVERY_FINISHED_DELAY,
                                                (GSourceFunc)__bt_le_discovery_finished_cb, NULL);
                                }
                } else if (strcasecmp(property, "Name") == 0) {
@@ -769,12 +784,15 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        g_variant_get(val, "b", &powered);
                        BT_DBG("Powered = %d", powered);
                        if (powered == FALSE) {
-#ifdef USB_BLUETOOTH
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
                                _bt_handle_adapter_removed();
 #else
                                if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_state) == 0 &&
                                bt_state != VCONFKEY_BT_STATUS_OFF) {
-                                       _bt_disable_adapter();
+                                       if (__bt_handle_is_flight_mode_enabled() == FALSE)
+                                               _bt_disable_adapter();
+                                       else
+                                               _bt_handle_adapter_removed();
                                }
 #endif
                                if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_state) == 0 &&
@@ -782,7 +800,7 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                        _bt_set_le_disabled(BLUETOOTH_ERROR_NONE);
                                }
                        } else {
-#ifdef USB_BLUETOOTH
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
                                _bt_handle_adapter_added();
 #endif
                        }
@@ -807,6 +825,9 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                        char *value = NULL;
                        GVariantIter *iter = NULL;
                        g_variant_get(val, "as", &iter);
+
+                       ret_if(iter == NULL);
+
                        while (g_variant_iter_loop(iter, "s", &name)) {
                                BT_DBG("name = %s", name);
                                g_variant_iter_loop(iter, "s", &value);
@@ -814,8 +835,8 @@ static void __bt_adapter_property_changed_event(GVariant *msg, const char *path)
                                if (FALSE == _bt_update_le_feature_support(name, value))
                                        BT_INFO("Fail to update LE feature info");
                        }
-                       if (iter)
-                               g_variant_iter_free(iter);
+
+                       g_variant_iter_free(iter);
                } else if (strcasecmp(property, "IpspInitStateChanged") == 0) {
                        gboolean ipsp_initialized = FALSE;
 
@@ -892,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) {
@@ -945,9 +969,9 @@ static void __bt_device_property_changed_event(GVariant *msg, const char *path)
                        if (remote_dev_info->addr_type == 0) {
                                BT_DBG("Name %s", remote_dev_info->name);
 
-#ifdef TIZEN_DPM_ENABLE
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+#ifdef TIZEN_FEATURE_BT_DPM
+                               _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);
 
@@ -1378,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);
 }
@@ -1698,7 +1718,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        gboolean connected = FALSE;
                        char *address;
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
                        g_variant_get(msg, "(b)", &connected);
@@ -1731,7 +1750,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        }
 
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
 
@@ -1782,7 +1800,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                        ret_if(_bt_is_device_creating() == TRUE);
 
                        address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-                       ret_if(address == NULL);
 
                        _bt_convert_device_path_to_address(path, address);
 
@@ -1832,7 +1849,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                g_variant_get(msg, "(y)", &addr_type);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
                dev_name = _bt_get_bonded_device_name(address);
@@ -1861,7 +1877,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                result = disc_reason;
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
 
@@ -1927,7 +1942,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                g_variant_get(msg, "(si)", &profile_uuid, &state);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               ret_if(address == NULL);
 
                _bt_convert_device_path_to_address(path, address);
                _bt_convert_addr_string_to_type(bd_addr.addr, address);
@@ -2142,8 +2156,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                ret_if(_bt_is_le_scanning() == FALSE);
 
                le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
-               if (le_dev_info == NULL)
-                       return;
 
                g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
                                                &le_dev_info->addr_type,
@@ -2151,6 +2163,9 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                &le_dev_info->rssi,
                                                &le_dev_info->adv_data_len,
                                                &value);
+
+               ret_if(value == NULL);
+
                _bt_convert_device_path_to_address(path, le_dev_info->address);
 
                buffer_len = g_variant_get_size(value);
@@ -2174,21 +2189,12 @@ 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));
-                       if (adv_info == NULL) {
-                               _bt_free_le_device_info(le_dev_info);
-                               g_variant_unref(value);
-                               return;
-                       }
 
                        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);
-                       if (adv_info->data) {
-                               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,
@@ -2242,25 +2248,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
                                                event,
                                                param);
                g_free(address);
-       } else if (strcasecmp(member, "iBeaconReport") == 0) {
-               bt_remote_ibeacon_dev_info_t *ibeacon_dev_info = NULL;
-
-               ret_if(_bt_is_le_scanning() == FALSE);
-
-               ibeacon_dev_info = g_malloc0(sizeof(bt_remote_ibeacon_dev_info_t));
-               if (ibeacon_dev_info == NULL)
-                       return;
-
-               g_variant_get(msg, "(syuusuuy)", &ibeacon_dev_info->address,
-                                               &ibeacon_dev_info->addr_type,
-                                               &ibeacon_dev_info->company_id,
-                                               &ibeacon_dev_info->ibeacon_type,
-                                               &ibeacon_dev_info->uuid,
-                                               &ibeacon_dev_info->major_id,
-                                               &ibeacon_dev_info->minor_id,
-                                               &ibeacon_dev_info->measured_power);
-               _bt_send_ibeacon_scan_result_event(ibeacon_dev_info);
-               g_free(ibeacon_dev_info);
        }
 }
 
@@ -2327,8 +2314,6 @@ void _bt_handle_headset_event(GVariant *msg, const char *path)
                g_variant_get(value, "b", &property_flag);
 
                address = g_malloc0(BT_ADDRESS_STRING_SIZE);
-               if (address == NULL)
-                       return;
 
                _bt_convert_device_path_to_address(path, address);
                _bt_convert_addr_string_to_type(bd_addr.addr, address);
@@ -2674,7 +2659,7 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                g_variant_get(parameters, "(&o@a{sa{sv}})", &obj_path, &value);
 
                if (strcasecmp(obj_path, BT_BLUEZ_HCI_PATH) == 0) {
-#ifdef USB_BLUETOOTH
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
                        BT_DBG("Enable Adapter");
                        _bt_enable_adapter();
 #else
@@ -2685,18 +2670,15 @@ 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);
 
                                cache_info = g_malloc0(sizeof(bt_cache_info_t));
-                               ret_if(cache_info == NULL);
 
                                dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
-                               if (dev_info == NULL) {
-                                       __bt_free_cache_info(cache_info);
-                                       return;
-                               }
 
                                cache_info->dev_info = dev_info;
 
@@ -2722,9 +2704,9 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                                         */
                                        dev_info->name = g_strdup(dev_info->address);
 
-#ifdef TIZEN_DPM_ENABLE
-                               if (_bt_dpm_get_bluetooth_desktop_connectivity_state() ==
-                                                       DPM_RESTRICTED) {
+#ifdef TIZEN_FEATURE_BT_DPM
+                               _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);
@@ -2776,7 +2758,7 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                }
                g_variant_unref(value);
        } else if (strcasecmp(signal_name, "InterfacesRemoved") == 0) {
-#ifdef USB_BLUETOOTH
+#ifdef TIZEN_FEATURE_BT_USB_DONGLE
                BT_DBG("InterfacesRemoved");
                _bt_handle_adapter_removed();
 #endif
@@ -2815,7 +2797,7 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
                }
 
                if (strcasecmp(name, BT_BLUEZ_NAME) == 0) {
-                       BT_DBG("Bluetoothd is terminated");
+                       BT_INFO_C("### Bluetoothd is terminated");
                        if (_bt_adapter_get_status() == BT_ACTIVATED)
                                 _bt_disable_cb();
 
@@ -2841,6 +2823,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);
@@ -3596,7 +3582,7 @@ fail:
 static int __bt_init_obexd_receiver(void)
 {
        BT_DBG("+");
-#ifndef TIZEN_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
+#ifndef TIZEN_PROFILE_TV /* TODO: obexd doesn't work in TV profile. It should be resolved later. */
        GError *error = NULL;
 
        if (obexd_conn == NULL) {
@@ -3702,6 +3688,10 @@ void _bt_deinit_service_event_receiver(void)
                g_source_remove(event_id);
        event_id = 0;
 
+       if (le_scan_event_id > 0)
+               g_source_remove(le_scan_event_id);
+       le_scan_event_id = 0;
+
        BT_DBG("-");
 }