X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-event-receiver.c;h=335a1ab60ec85bed9e9792b40c11273184c52a9b;hb=5c92ccc658b5dcabc7e247ccda463e5d80f6849c;hp=0f31857f6ea016a68ad1166db9946a33cdb5092d;hpb=39a6cbc0e0b202a9ec628daacc1cd4128912964d;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-event-receiver.c b/bt-service/bt-service-event-receiver.c index 0f31857..335a1ab 100644 --- a/bt-service/bt-service-event-receiver.c +++ b/bt-service/bt-service-event-receiver.c @@ -39,10 +39,11 @@ #include "bt-service-headset-connection.h" #include "bt-service-avrcp-controller.h" #include "bt-service-hid.h" +#include "bt-service-proximity.h" #include "bt-service-opp-client.h" -#ifdef TIZEN_DPM_ENABLE +#ifdef TIZEN_FEATURE_BT_DPM #include "bt-service-dpm.h" #endif @@ -54,6 +55,8 @@ 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; static GList *p_adv_ind_list = NULL; @@ -72,7 +75,7 @@ typedef enum { OBEX_PBAP = (1 << 4), OBEX_IRMC = (1 << 5), OBEX_PCSUITE = (1 << 6), - OBEX_SYNCEVOLUTION = (1 << 7), + OBEX_SYNCEVOLUTION = (1 << 7), OBEX_MAS = (1 << 8), } bluetooth_obex_connection_type_t; @@ -104,7 +107,7 @@ static bt_le_adv_info_t *__bt_get_adv_ind_info(char *addr) retv_if(!addr, NULL); bt_le_adv_info_t *adv_info = NULL; GList *current = g_list_first((GList *)p_adv_ind_list); - while(current && current->data) { + while (current && current->data) { adv_info = (bt_le_adv_info_t *)current->data; if (adv_info && !g_strcmp0(adv_info->addr, addr)) return adv_info; @@ -201,7 +204,7 @@ static gboolean __bt_parse_device_properties(GVariant *item, } else if (strcasecmp(key, "UUIDs") == 0) { char **uuid_value; gsize size = 0; - int i =0; + int i = 0; size = g_variant_get_size(val); if (size > 0) { @@ -251,7 +254,7 @@ static gboolean __bt_parse_interface(GVariant *msg, bt_remote_dev_info_t *dev_info) { char *path = NULL; - GVariant *optional_param; + GVariant *optional_param = NULL; GVariantIter iter; GVariant *child; char *interface_name = NULL; @@ -260,6 +263,8 @@ static gboolean __bt_parse_interface(GVariant *msg, &path, &optional_param); g_variant_iter_init(&iter, optional_param); + retv_if(optional_param == NULL, FALSE); + while ((child = g_variant_iter_next_value(&iter))) { g_variant_get(child, "{&s@a{sv}}", &interface_name, &inner_iter); if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) { @@ -279,10 +284,10 @@ static gboolean __bt_parse_interface(GVariant *msg, } } g_variant_unref(inner_iter); - g_variant_unref(child); + g_variant_unref(child); } - if (optional_param) - g_variant_unref(optional_param); + + g_variant_unref(optional_param); return FALSE; } @@ -305,18 +310,16 @@ void __bt_set_device_values(gboolean connected, int state) { int bt_device_state = VCONFKEY_BT_DEVICE_NONE; - if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) { + if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) BT_ERR("vconf_get_int failed"); - } if (connected == TRUE) bt_device_state |= state; else if (bt_device_state & state) bt_device_state ^= state; - if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) { + if (vconf_set_int(VCONFKEY_BT_DEVICE, bt_device_state) != 0) BT_ERR("vconf_set_int failed"); - } } gboolean _bt_discovery_finished_cb(gpointer user_data) @@ -325,9 +328,8 @@ gboolean _bt_discovery_finished_cb(gpointer user_data) event_id = 0; GVariant *param = NULL; if (_bt_get_discovering_property(DISCOVERY_ROLE_BREDR) == FALSE) { - if (_bt_get_cancel_by_user() == TRUE) { + if (_bt_get_cancel_by_user() == TRUE) result = BLUETOOTH_ERROR_CANCEL_BY_USER; - } _bt_set_cancel_by_user(FALSE); _bt_set_discovery_status(FALSE); @@ -343,18 +345,17 @@ 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) { + if (_bt_get_cancel_by_user() == TRUE) result = BLUETOOTH_ERROR_CANCEL_BY_USER; - } g_list_free_full(p_adv_ind_list, __bt_free_bt_le_adv_info_t); p_adv_ind_list = NULL; _bt_set_cancel_by_user(FALSE); - _bt_disable_all_scanner_status(); + _bt_disable_all_scanner_status(); _bt_set_le_scan_status(FALSE); param = g_variant_new("(i)", result); _bt_send_event(BT_LE_ADAPTER_EVENT, @@ -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); @@ -578,10 +593,16 @@ void _bt_handle_adapter_event(GVariant *msg, const char *member) g_free(address); } else if (strcasecmp(member, BT_HARDWARE_ERROR) == 0) { BT_ERR_C("Hardware error received from BLUEZ"); +/* Don't add the recovery logic into platform */ +#if 0 _bt_recover_adapter(); +#endif } else if (strcasecmp(member, BT_TX_TIMEOUT_ERROR) == 0) { BT_ERR_C("Tx timeout error received from BLUEZ"); +/* Don't add the recovery logic into platform */ +#if 0 _bt_recover_adapter(); +#endif } BT_DBG("-"); } @@ -646,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); @@ -664,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) { @@ -763,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 && @@ -776,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 } @@ -801,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); @@ -808,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; @@ -886,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) { @@ -939,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); @@ -1275,6 +1305,70 @@ static void __bt_media_control_changed_event(GVariant *msg, const char *path) BT_DBG("-"); } +int get_alert_level_enum(const char *alert) +{ + int lvl = -1; + + if (strcmp(alert, "none") == 0) + lvl = BT_PXP_ALERT_NONE; + else if (strcmp(alert, "mild") == 0) + lvl = BT_PXP_ALERT_MILD; + else if (strcmp(alert, "high") == 0) + lvl = BT_PXP_ALERT_HIGH; + + return lvl; +} + +static void _bt_handle_pxp_property_changed_event(GVariant *msg, const char *path, int role) +{ + int result = BLUETOOTH_ERROR_NONE; + int service_type; + int alert_lvl; + GVariantIter value_iter; + char *property = NULL; + char *address; + GVariant *val = NULL; + GVariant *child = NULL; + GVariant *param = NULL; + g_variant_iter_init(&value_iter, msg); + + BT_DBG("+"); + while ((child = g_variant_iter_next_value(&value_iter))) { + g_variant_get(child, "{sv}", &property, &val); + BT_INFO("Property %s", property); + + if ((strcasecmp(property, "LinkLossAlertLevel") == 0) || + (strcasecmp(property, "ImmediateAlertLevel") == 0)) { + char *alert_str = NULL; + + address = g_malloc0(BT_ADDRESS_STRING_SIZE); + _bt_convert_device_path_to_address(path, address); + + if (strcasecmp(property, "LinkLossAlertLevel") == 0) + service_type = BT_PXP_PROPERTY_LLS; + else + service_type = BT_PXP_PROPERTY_IAS; + + g_variant_get(val, "s", &alert_str); + alert_lvl = get_alert_level_enum(alert_str); + + param = g_variant_new("(isiii)", result, address, + role, service_type, alert_lvl); + + /* Send event to application */ + _bt_send_event(BT_DEVICE_EVENT, + BLUETOOTH_EVENT_PXP_PROPERTY_CHANGED, + param); + g_free(address); + g_free(alert_str); + } + g_free(property); + g_variant_unref(child); + g_variant_unref(val); + } + BT_DBG("-"); +} + void _bt_handle_property_changed_event(GVariant *msg, const char *object_path) { char *interface_name = NULL; @@ -1304,6 +1398,10 @@ void _bt_handle_property_changed_event(GVariant *msg, const char *object_path) } else if (strcasecmp(interface_name, BT_GATT_CHAR_INTERFACE) == 0) { __bt_gatt_char_property_changed_event(val, object_path); + } else if (strcasecmp(interface_name, BT_PROXIMITY_REPORTER_INTERFACE) == 0) { + BT_DBG("BT_PROXIMITY_REPORTER_INTERFACE"); + _bt_handle_pxp_property_changed_event(val, + object_path, BT_PXP_REPORTER_ROLE); } g_variant_unref(val); } @@ -1326,13 +1424,13 @@ void __bt_opc_property_changed_event(GVariant *msg, g_variant_get(val, "s", &status); BT_DBG("Status is %s", status); - if (strcasecmp(status, "active") == 0) { + if (strcasecmp(status, "active") == 0) _bt_obex_client_started(path); - } else if (strcasecmp(status, "complete") == 0) { + else if (strcasecmp(status, "complete") == 0) _bt_obex_client_completed(path, TRUE); - } else if (strcasecmp(status, "error") == 0) { + else if (strcasecmp(status, "error") == 0) _bt_obex_client_completed(path, FALSE); - } + g_free(status); } else if (strcasecmp(property, "Transferred") == 0) { guint64 transferred = 0; @@ -1620,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); @@ -1653,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); @@ -1704,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); @@ -1754,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); @@ -1783,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); @@ -1832,7 +1925,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path */ _bt_obex_check_pending_transfer(address); _bt_opp_client_is_sending(&sending); - if(sending == TRUE) + if (sending == TRUE) _bt_opp_client_check_pending_transfer(address); } param = g_variant_new("(isy)", result, address, addr_type); @@ -1844,13 +1937,14 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path int state = 0; char *profile_uuid = NULL; bt_headset_wait_t *wait_list; + bluetooth_device_address_t bd_addr; 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); _bt_convert_addr_string_to_secure_string(secure_address, address); BT_DBG("Address: %s", secure_address); @@ -1865,15 +1959,19 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path bluetooth_device_address_t device_address; gboolean connected; bt_headset_wait_t *wait_list; + guint restricted = 0x0; __bt_set_device_values(TRUE, VCONFKEY_BT_DEVICE_A2DP_HEADSET_CONNECTED); __bt_connection_manager_set_state(address, event); - if (_bt_headset_get_local_connection() == FALSE) - _bt_start_timer_for_connection(address, BT_AUDIO_HSP); - else { + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_HFP_HS, &restricted); + + if (_bt_headset_get_local_connection() == FALSE) { + if (restricted == 0x0) /* not restricted*/ + _bt_start_timer_for_connection(address, BT_AUDIO_HSP); + } else { /* Connection Started from local device therefore no need to * intiate connection for pending profile */ _bt_headset_set_local_connection(FALSE); @@ -1941,7 +2039,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, - wait_list->out_param1); + NULL); } } else if (strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0) { @@ -1992,7 +2090,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_audio_stop_auto_connect(); #endif _bt_add_headset_to_list(BT_AUDIO_A2DP_SOURCE, - BT_STATE_CONNECTED, address); + BT_STATE_CONNECTED, address); _bt_send_event(BT_A2DP_SOURCE_EVENT, event, g_variant_new("(is)", result, address)); } else if (state == BT_PROFILE_STATE_DISCONNECTED) { @@ -2016,7 +2114,7 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, - wait_list->out_param1); + NULL); /* Now free the wait list */ _bt_rel_wait_data(); } @@ -2058,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, @@ -2067,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); @@ -2090,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, @@ -2159,7 +2249,6 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path param); g_free(address); } - } void __bt_set_audio_values(gboolean connected, char *address) @@ -2168,24 +2257,19 @@ void __bt_set_audio_values(gboolean connected, char *address) int bt_device_state = VCONFKEY_BT_DEVICE_NONE; /* Set the headset name */ - if (connected == TRUE) { + if (connected == TRUE) name = _bt_get_bonded_device_name(address); - } else { + else name = g_strdup(""); - } - if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, - name) != 0) { + if (vconf_set_str(VCONFKEY_BT_HEADSET_NAME, name) != 0) BT_ERR("vconf_set_str failed"); - } g_free(name); /* Set the headset state */ - if (vconf_get_int(VCONFKEY_BT_DEVICE, - &bt_device_state) != 0) { + if (vconf_get_int(VCONFKEY_BT_DEVICE, &bt_device_state) != 0) BT_ERR("vconf_get_int failed"); - } #ifdef TIZEN_SUPPORT_DUAL_HF if ((connected == TRUE) && @@ -2196,11 +2280,10 @@ void __bt_set_audio_values(gboolean connected, char *address) bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED; } #else - if (connected == TRUE) { + if (connected == TRUE) bt_device_state |= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED; - } else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) { + else if (bt_device_state & VCONFKEY_BT_DEVICE_HEADSET_CONNECTED) bt_device_state ^= VCONFKEY_BT_DEVICE_HEADSET_CONNECTED; - } #endif if (vconf_set_int(VCONFKEY_BT_DEVICE, @@ -2217,6 +2300,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) GVariant *value = NULL; GVariant *param = NULL; g_variant_get(msg, "(sv)", &property, &value); + bluetooth_device_address_t bd_addr; ret_if(property == NULL); @@ -2226,19 +2310,22 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) int event = BLUETOOTH_EVENT_NONE; bt_headset_wait_t *wait_list; char *address; + guint restricted = 0x0; 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); if (property_flag == TRUE) { event = BLUETOOTH_EVENT_AG_CONNECTED; - if (_bt_headset_get_local_connection() == FALSE) - _bt_start_timer_for_connection(address, BT_AUDIO_A2DP); - else + _bt_get_restrict_profile(&bd_addr, RESTRICTED_PROFILE_A2DP, &restricted); + + if (_bt_headset_get_local_connection() == FALSE) { + if (restricted == 0x0) /* not restricted*/ + _bt_start_timer_for_connection(address, BT_AUDIO_A2DP); + } else _bt_headset_set_local_connection(FALSE); } else { int previous_state; @@ -2273,7 +2360,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) _bt_convert_addr_string_to_type(device_address.addr, wait_list->address); _bt_audio_connect(wait_list->req_id, wait_list->type, - &device_address, wait_list->out_param1); + &device_address, NULL); _bt_rel_wait_data(); } else if (event == BLUETOOTH_EVENT_AG_CONNECTED) { /* Add data to the connected list */ @@ -2343,7 +2430,7 @@ void _bt_handle_headset_event(GVariant *msg, const char *path) if (property) g_free(property); g_variant_unref(value); - } +} void _bt_handle_sink_event(GVariant *msg, const char *path) { @@ -2410,7 +2497,7 @@ void _bt_handle_sink_event(GVariant *msg, const char *path) _bt_audio_connect(wait_list->req_id, wait_list->type, &device_address, - wait_list->out_param1); + NULL); } g_free(address); } else if (strcasecmp(value, "Connected") == 0) { @@ -2572,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 @@ -2583,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; @@ -2620,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); @@ -2674,17 +2758,17 @@ 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 - if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) { + if (g_strcmp0(interface_name, BT_MEDIATRANSPORT_INTERFACE) == 0) bt_event = BT_MEDIA_TRANSFER_EVENT; - } else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) { + else if (g_strcmp0(interface_name, BT_DEVICE_INTERFACE) == 0) bt_event = BT_DEVICE_EVENT; - } else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) { + else if (g_strcmp0(interface_name, BT_PLAYER_CONTROL_INTERFACE) == 0) bt_event = BT_AVRCP_CONTROL_EVENT; - } + if ((bt_event != 0) && (bt_event != BT_MEDIA_TRANSFER_EVENT)) { _bt_handle_adapter_event(parameters, signal_name); if (bt_event == BT_AVRCP_CONTROL_EVENT) { @@ -2713,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(); @@ -2739,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); @@ -3494,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) { @@ -3519,6 +3607,36 @@ static int __bt_init_obexd_receiver(void) return BLUETOOTH_ERROR_NONE; } +gboolean __bt_reinit_obexd_receiver(gpointer user_data) +{ + static int retry_cnt = 0; + int result = BLUETOOTH_ERROR_NONE; + + BT_DBG("+"); + + result = __bt_init_obexd_receiver(); + if (result != BLUETOOTH_ERROR_NONE) { + /* 20 ms * 50 = 10 seconds. During 10 seconds fail to initialize, + then it is not the timing issue. Just can't use the session bus connection */ + if (retry_cnt > 100) { + BT_ERR("Fail to init obexd receiver by 50 times."); + retry_cnt = 0; + session_reinit_timer = 0; + return FALSE; + } + retry_cnt++; + BT_DBG("Retry to initialize the obexd receiver"); + return TRUE; + } + + retry_cnt = 0; + session_reinit_timer = 0; + + BT_DBG("-"); + + return FALSE; +} + /* To receive the event from bluez */ int _bt_init_service_event_receiver(void) { @@ -3530,9 +3648,17 @@ int _bt_init_service_event_receiver(void) retv_if(result != BLUETOOTH_ERROR_NONE, result); result = __bt_init_obexd_receiver(); - if (result != BLUETOOTH_ERROR_NONE) + if (result != BLUETOOTH_ERROR_NONE) { BT_ERR("Fail to init obexd receiver"); + /* Try to re-initialize obexd receiver in the timer */ + if (session_reinit_timer > 0) + g_source_remove(session_reinit_timer); + + session_reinit_timer = g_timeout_add(BT_SESSION_BUS_GET_TIMEOUT, + (GSourceFunc)__bt_reinit_obexd_receiver, NULL); + } + BT_DBG("-"); return BLUETOOTH_ERROR_NONE; @@ -3562,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("-"); }