diff options
Diffstat (limited to 'src/libraries/bt-callback.c')
-rw-r--r-- | src/libraries/bt-callback.c | 592 |
1 files changed, 480 insertions, 112 deletions
diff --git a/src/libraries/bt-callback.c b/src/libraries/bt-callback.c index 05e2314..5f5ae27 100644 --- a/src/libraries/bt-callback.c +++ b/src/libraries/bt-callback.c @@ -1,18 +1,25 @@ /* - * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Flora License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://floralicense.org/license/ - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* ug-setting-bluetooth-efl +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Contact: Hocheol Seo <hocheol.seo@samsung.com> +* GirishAshok Joshi <girish.joshi@samsung.com> +* DoHyun Pyun <dh79.pyun@samsung.com> +* +* Licensed under the Flora License, Version 1.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.tizenopensource.org/license +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*/ #include <vconf.h> #include <vconf-keys.h> @@ -46,27 +53,19 @@ static Eina_Bool __bt_cb_auto_discovery(void *data) retv_if((elm_win_focus_get(ugd->win_main) == FALSE), ECORE_CALLBACK_CANCEL); - /* If there is no paired devices, device searching starts. */ - if (ugd->search_req == TRUE || - eina_list_count(ugd->paired_device) == 0 || - ugd->bt_launch_mode == BT_LAUNCH_SEND_FILE) { - _bt_main_remove_all_searched_devices(ugd); + _bt_main_remove_all_searched_devices(ugd); - ret = bt_adapter_start_discover_devices(BT_ADAPTER_DEVICE_DISCOVERY_BREDR); - if (!ret) { - ugd->op_status = BT_SEARCHING; - elm_object_text_set(ugd->scan_btn, BT_STR_STOP);; - _bt_update_genlist_item(ugd->status_item); + ret = bt_adapter_start_device_discovery(); + if (!ret) { + ugd->op_status = BT_SEARCHING; + elm_object_text_set(ugd->scan_btn, BT_STR_STOP); - if (ugd->searched_title == NULL) + if (ugd->searched_title == NULL) _bt_main_add_searched_title(ugd); - } else { - BT_DBG("Discovery failed : Error Cause[%d]", ret); - } + } else { + BT_ERR("Discovery failed : Error Cause[%d]", ret); } - ugd->search_req = FALSE; - FN_END; return ECORE_CALLBACK_CANCEL; } @@ -82,23 +81,26 @@ static void __bt_cb_enable(int result, void *data) ugd = (bt_ug_data *)data; + elm_object_disabled_set(ugd->onoff_btn, EINA_FALSE); if (ugd->op_status == BT_ACTIVATED) { BT_DBG("Already enabled state"); return; } if (result != BT_ERROR_NONE) { - BT_DBG("Failed to enable Bluetooth : Error Cause[%d]", result); + BT_ERR("Failed to enable Bluetooth [%d]", result); ugd->op_status = BT_DEACTIVATED; - _bt_update_genlist_item(ugd->status_item); + _bt_update_genlist_item(ugd->onoff_item); + _bt_main_add_empty_description(ugd); return; } else { ugd->op_status = BT_ACTIVATED; + _bt_update_genlist_item(ugd->onoff_item); ugd->aul_pairing_req = FALSE; } if (vconf_get_int(BT_VCONF_VISIBLE_TIME, &timeout) != 0) { - BT_DBG("Fail to get the timeout value"); + BT_ERR("Fail to get the timeout value"); } if (timeout == BT_ALWAYS_ON) { @@ -110,16 +112,32 @@ static void __bt_cb_enable(int result, void *data) _bt_util_set_phone_name(); - if(ugd->visible_item) - elm_object_item_disabled_set(ugd->visible_item, EINA_FALSE); + if(!ugd->device_name_item) + _bt_main_add_device_name_item(ugd, ugd->main_genlist); + + if(!ugd->visible_item) + _bt_main_add_visible_item(ugd, ugd->main_genlist); + + if (ugd->empty_status_item) { + elm_object_item_del(ugd->empty_status_item); + ugd->empty_status_item = NULL; + } + + if (ugd->turning_on_item) { + elm_object_item_del(ugd->turning_on_item); + ugd->turning_on_item = NULL; + } - _bt_update_genlist_item(ugd->status_item); _bt_update_genlist_item(ugd->visible_item); - _bt_update_genlist_item(ugd->visibility_status_item); - ret_if(ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY); + if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) { + g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd); + return; + } else if (ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY) { + return; + } - elm_object_disabled_set(ugd->scan_btn, EINA_FALSE); + ugd->scan_btn = _bt_main_create_scan_button(ugd); _bt_update_genlist_item(ugd->paired_title); _bt_update_genlist_item(ugd->searched_title); @@ -128,7 +146,7 @@ static void __bt_cb_enable(int result, void *data) if (ugd->bt_launch_mode != BT_LAUNCH_USE_NFC) _bt_main_draw_paired_devices(ugd); - if ( !ecore_idler_add(__bt_cb_auto_discovery, ugd)) + if (!ecore_idler_add(__bt_cb_auto_discovery, ugd)) BT_ERR("idler can not be added\n\n"); FN_END; @@ -138,26 +156,42 @@ static void __bt_cb_disable(int result, void *data) { FN_START; bt_ug_data *ugd = NULL; - ret_if(data == NULL); ugd = (bt_ug_data *)data; + int ret = 0; + elm_object_disabled_set(ugd->onoff_btn, EINA_FALSE); if (ugd->op_status == BT_DEACTIVATED) { BT_DBG("Already disabled state"); return; } + if (ugd->help_more_popup) { + evas_object_del(ugd->help_more_popup); + ugd->help_more_popup = NULL; + } + if (ugd->popup) { evas_object_del(ugd->popup); ugd->popup = NULL; } + if (ugd->visibility_popup) { + evas_object_del(ugd->visibility_popup); + ugd->visibility_popup = NULL; + } + + if (ugd->rename_popup) { + evas_object_del(ugd->rename_popup); + ugd->rename_popup = NULL; + } + if (result != BT_ERROR_NONE) { - BT_DBG("Failed to enable Bluetooth : Error Cause[%d]", result); + BT_ERR("Failed to enable Bluetooth [%d]", result); ugd->op_status = BT_ACTIVATED; - } else { + } else { /* Delete profile view */ if (ugd->profile_vd != NULL) { elm_naviframe_item_pop(ugd->navi_bar); @@ -178,7 +212,8 @@ static void __bt_cb_disable(int result, void *data) ugd->selected_radio = 0; } - elm_object_text_set(ugd->scan_btn, BT_STR_SCAN); + evas_object_del(ugd->scan_btn); + ugd->scan_btn = NULL; if (ugd->visible_item && EINA_TRUE == elm_genlist_item_expanded_get( ugd->visible_item)) { @@ -186,20 +221,34 @@ static void __bt_cb_disable(int result, void *data) EINA_FALSE); } - if(ugd->visible_item) - elm_object_item_disabled_set(ugd->visible_item, EINA_TRUE); + if(ugd->visible_item) { + elm_object_item_del(ugd->visible_item); + ugd->visible_item = NULL; + } - if (ugd->bt_launch_mode != BT_LAUNCH_VISIBILITY) { - elm_object_disabled_set(ugd->scan_btn, - EINA_FALSE); + if(ugd->device_name_item) { + elm_object_item_del(ugd->device_name_item); + ugd->device_name_item = NULL; + } + if (ugd->bt_launch_mode != BT_LAUNCH_VISIBILITY && + ugd->bt_launch_mode != BT_LAUNCH_ONOFF) { + elm_object_disabled_set(ugd->scan_btn, EINA_FALSE); _bt_main_remove_all_paired_devices(ugd); _bt_main_remove_all_searched_devices(ugd); } + if (ugd->empty_status_item == NULL) { + _bt_main_add_empty_description(ugd); + } + if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) { + ret = _bt_idle_destroy_ug((void *)ugd); + if (ret != BT_UG_ERROR_NONE) + BT_DBG("fail to destory ug"); + return; + } } - _bt_update_genlist_item(ugd->status_item); + _bt_update_genlist_item(ugd->onoff_item); _bt_update_genlist_item(ugd->visible_item); - _bt_update_genlist_item(ugd->visibility_status_item); _bt_update_genlist_item(ugd->paired_title); _bt_update_genlist_item(ugd->searched_title); @@ -219,9 +268,10 @@ static void __bt_cb_search_completed(int result, void *data) if (ugd->op_status == BT_SEARCHING) ugd->op_status = BT_ACTIVATED; + ugd->is_discovery_started = FALSE; + elm_object_text_set(ugd->scan_btn, BT_STR_SCAN); - _bt_update_genlist_item(ugd->status_item); _bt_update_genlist_item(ugd->paired_title); _bt_update_genlist_item(ugd->searched_title); @@ -229,12 +279,13 @@ static void __bt_cb_search_completed(int result, void *data) eina_list_count(ugd->searched_device) == 0) { /* Don't add the no device item, if no device item already exist */ ret_if(ugd->no_device_item != NULL); - ugd->no_device_item = _bt_main_add_no_device_found(ugd); + if (ugd->op_status != BT_DEACTIVATED) { + ugd->no_device_item = _bt_main_add_no_device_found(ugd); + } _bt_update_genlist_item(ugd->no_device_item); } - FN_END; } @@ -309,11 +360,13 @@ static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info, bt_ug_data *ugd = NULL; bt_dev_t *dev = NULL; - + bt_device_info_s *device_info = NULL; + int i; ret_if(info == NULL); ret_if(data == NULL); ugd = (bt_ug_data *)data; + ret_if(ugd->op_status != BT_SEARCHING); /* Check the service_class */ if (__bt_cb_match_discovery_type( @@ -329,6 +382,55 @@ static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info, if (_bt_main_check_and_update_device(ugd->paired_device, info->remote_address, info->remote_name) >= 0) { + /* Update all realized items */ + elm_genlist_realized_items_update(ugd->main_genlist); + return; + } + + device_info = (bt_device_info_s *)g_malloc0(sizeof(bt_device_info_s)); + device_info->bt_class = info->bt_class; + device_info->remote_address = g_strdup(info->remote_address); + device_info->remote_name = g_strdup(info->remote_name); + device_info->service_count = info->service_count; + + if (info->service_uuid != NULL && info->service_count > 0) { + device_info->service_uuid = g_new0(char *, info->service_count + 1); + + for (i = 0; i < info->service_count; i++) { + device_info->service_uuid[i] = g_strdup(info->service_uuid[i]); + } + } + dev = _bt_main_create_paired_device_item(device_info); + + for (i = 0; i < info->service_count; i++) { + g_free(device_info->service_uuid[i]); + } + + g_free(device_info->remote_address); + g_free(device_info->remote_name); + g_free(device_info); + + retm_if (!dev, "create paired device item fail!"); + + dev->ugd = (void *)ugd; + + if (_bt_main_is_matched_profile(ugd->search_type, + info->bt_class.major_device_class, + info->bt_class.major_service_class_mask, + ugd->service, + info->bt_class.minor_device_class) == TRUE) { + if (_bt_main_add_paired_device(ugd, dev) != NULL) { + ugd->paired_device = + eina_list_append(ugd->paired_device, dev); + } + } else { + BT_ERR("Device class and search type do not match"); + free(dev); + } + + if (_bt_main_check_and_update_device(ugd->paired_device, + info->remote_address, + info->remote_name) >= 0) { _bt_update_device_list(ugd); } return; @@ -344,16 +446,17 @@ static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info, } else { dev = _bt_main_create_searched_device_item((void *)info); if (NULL == dev) { - BT_DBG("Create new device item failed \n"); + BT_ERR("Create new device item failed"); return; } if (_bt_main_is_matched_profile(ugd->search_type, dev->major_class, dev->service_class, - ugd->service) == TRUE) { + ugd->service, + dev->minor_class) == TRUE) { if (_bt_main_add_searched_device(ugd, dev) == NULL) { - BT_DBG("Fail to add the searched device \n"); + BT_ERR("Fail to add the searched device"); return; } @@ -361,7 +464,7 @@ static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info, eina_list_append(ugd->searched_device, dev); } else { - BT_DBG("Searched device does not match the profile\n"); + BT_DBG("Searched device does not match the profile"); free(dev); } } @@ -369,6 +472,68 @@ static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info, FN_END; } +static gboolean __bt_cb_visible_timeout_cb(gpointer user_data) +{ + FN_START; + + bt_ug_data *ugd = NULL; + time_t current_time; + int time_diff; + + ugd = (bt_ug_data *)user_data; + /* Get the current time */ + time(¤t_time); + + /* Calculate time elapsed from remain_time */ + time_diff = difftime(current_time, ugd->start_time); + BT_DBG("Time difference in seconds %d", time_diff); + + /* Update UI */ + if (ugd->remain_time <= time_diff) { + g_source_remove(ugd->timeout_id); + ugd->timeout_id = 0; + ugd->visibility_timeout = 0; + ugd->remain_time = 0; + ugd->selected_radio = 0; + + elm_genlist_realized_items_update(ugd->main_genlist); + + return FALSE; + } + + elm_genlist_item_fields_update(ugd->visible_item, "elm.text.sub", + ELM_GENLIST_ITEM_FIELD_TEXT); + + FN_END; + return TRUE; +} + +static void __bt_retry_pairing_cb(void *data, + Evas_Object *obj, void *event_info) +{ + FN_START; + ret_if (obj == NULL || data == NULL); + + bt_ug_data *ugd = (bt_ug_data *)data; + const char *event = elm_object_text_get(obj); + + if (ugd->popup) { + BT_DBG("delete popup"); + evas_object_del(ugd->popup); + ugd->popup = NULL; + } + + if ((!g_strcmp0(event, BT_STR_RETRY) || (!g_strcmp0(event, BT_STR_OK))) && + _bt_main_request_pairing_with_effect(ugd, + ugd->searched_item) != BT_UG_ERROR_NONE) { + ugd->searched_item = NULL; + } + if (!g_strcmp0(event, BT_STR_CANCEL)) + ugd->op_status = BT_ACTIVATED; + FN_END; +} + + /********************************************************************** * Common Functions ***********************************************************************/ @@ -377,14 +542,13 @@ void _bt_cb_state_changed(int result, bt_adapter_state_e adapter_state, void *user_data) { - FN_START; + BT_INFO("bluetooth %s", adapter_state == BT_ADAPTER_ENABLED ? + "enabled" : "disabled"); if (adapter_state == BT_ADAPTER_ENABLED) __bt_cb_enable(result, user_data); else __bt_cb_disable(result, user_data); - - FN_END; } void _bt_cb_discovery_state_changed(int result, @@ -392,15 +556,112 @@ void _bt_cb_discovery_state_changed(int result, bt_adapter_device_discovery_info_s *discovery_info, void *user_data) { - FN_START; + bt_ug_data *ugd = NULL; ret_if(user_data == NULL); - if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) + ugd = (bt_ug_data *)user_data; + + if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_STARTED) { + BT_INFO("BR/EDR discovery started"); + ugd->is_discovery_started = TRUE; + /*Now enable the Scan button, so that user may call cancel discovery */ + elm_object_disabled_set(ugd->scan_btn, EINA_FALSE); + } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND) __bt_cb_new_device_found(discovery_info, user_data); - else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) + else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) { + BT_INFO("BR/EDR discovery finished"); + ret_if(ugd->is_discovery_started == FALSE); + __bt_cb_search_completed(result, user_data); + if (ugd->op_status == BT_PAIRING) + elm_object_disabled_set(ugd->scan_btn, EINA_TRUE); + else + elm_object_disabled_set(ugd->scan_btn, EINA_FALSE); + } else + BT_ERR("Unknown device discovery state"); + +} +void _bt_cb_visibility_mode_changed + (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data) +{ + FN_START; + + ret_if(user_data == NULL); + bt_ug_data *ugd = (bt_ug_data *)user_data; + bt_adapter_state_e bt_state = BT_ADAPTER_DISABLED; + bt_adapter_visibility_mode_e mode = + BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE; + int remain_time = 0; + int ret = 0; + + if(ugd->visibility_changed_by_ug) { + ugd->visibility_changed_by_ug = FALSE; + FN_END; + return; + } +BT_DBG(""); + if (bt_adapter_get_state(&bt_state) != BT_ERROR_NONE) { + BT_ERR("bt_adapter_get_state() failed."); + return; + } + + if (bt_state != BT_ADAPTER_DISABLED) { + if (bt_adapter_get_visibility(&mode, &remain_time) != + BT_ERROR_NONE) { + BT_ERR("bt_adapter_get_visibility() failed."); + return; + } + } + + if (visibility_mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) { + ugd->visible = FALSE; + ugd->visibility_timeout = 0; + ugd->selected_radio = 0; + } else if (visibility_mode == BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE) { + ugd->visible = TRUE; + ugd->visibility_timeout = -1; + ugd->selected_radio = 4; + } else { + /* BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE */ + /* Need to add the code for getting timeout */ + ret = vconf_get_int(BT_VCONF_VISIBLE_TIME, &ugd->visibility_timeout); + if (ret != 0) { + BT_ERR("Failt to get the timeout value"); + } +BT_DBG(""); + + ugd->remain_time = remain_time; + + if (ugd->remain_time > 0) { + + if (ugd->timeout_id) { + g_source_remove(ugd->timeout_id); + ugd->timeout_id = 0; + } + /* Set current time snapshot */ + time(&(ugd->start_time)); + ugd->timeout_id = g_timeout_add(BT_VISIBILITY_TIMEOUT, + (GSourceFunc) + __bt_cb_visible_timeout_cb, + ugd); + } else { + ugd->visibility_timeout = 0; + } + } + + + if(ugd->visible_item) { + elm_genlist_item_fields_update(ugd->visible_item, + "elm.text.sub", + ELM_GENLIST_ITEM_FIELD_TEXT); + elm_genlist_item_fields_update(ugd->visible_item, + "elm.text.multiline", + ELM_GENLIST_ITEM_FIELD_TEXT); + + elm_radio_value_set(ugd->radio_main, ugd->selected_radio); + } FN_END; } @@ -411,11 +672,15 @@ void _bt_cb_bonding_created(int result, bt_device_info_s *dev_info, bt_ug_data *ugd = NULL; bt_dev_t *dev = NULL; + Evas_Object *btn1 = NULL; + Evas_Object *btn2 = NULL; + char temp[BT_DISCONNECT_TEXT_LENGTH] = { 0 }; ret_if(dev_info == NULL); ret_if(user_data == NULL); ugd = (bt_ug_data *)user_data; + ret_if(ugd->op_status == BT_DEACTIVATING); if (ugd->op_status == BT_PAIRING) ugd->op_status = BT_ACTIVATED; @@ -434,17 +699,48 @@ void _bt_cb_bonding_created(int result, bt_device_info_s *dev_info, dev = _bt_main_get_dev_info(ugd->searched_device, ugd->searched_item); if (result != BT_ERROR_NONE) { - BT_DBG("Failed to pair with device : Error Cause[%d]", result); + BT_ERR("Failed to pair with device [%d]", result); retm_if(dev == NULL, "dev is NULL\n"); dev->status = BT_IDLE; + + elm_genlist_item_item_class_update(dev->genlist_item, + ugd->searched_device_itc); _bt_update_genlist_item((Elm_Object_Item *)dev->genlist_item); - if (result != BT_ERROR_CANCELLED) { - if (_bt_util_is_battery_low() == TRUE) { - _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY); - } + BT_ERR("Authentication Failed"); + if (_bt_util_is_battery_low() == TRUE) { + _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY); + } else if (result != BT_ERROR_NOT_IN_PROGRESS){ + ugd->op_status = BT_PAIRING; + snprintf(temp, sizeof(temp), + BT_STR_UNABLE_TO_PAIR_WITH_PS, dev->name); + + ugd->popup = _bt_create_popup(ugd->win_main, + BT_STR_BLUETOOTH_ERROR, + temp, + NULL, ugd, 0); + + btn1 = elm_button_add(ugd->popup); + elm_object_style_set(btn1, "popup"); + elm_object_text_set(btn1, BT_STR_CANCEL); + elm_object_part_content_set(ugd->popup, "button1", btn1); + evas_object_smart_callback_add(btn1, + "clicked", __bt_retry_pairing_cb, ugd); + + btn2 = elm_button_add(ugd->popup); + elm_object_style_set(btn2, "popup"); + elm_object_text_set(btn2, BT_STR_RETRY); + elm_object_part_content_set(ugd->popup, "button2", btn2); + evas_object_smart_callback_add(btn2, + "clicked", __bt_retry_pairing_cb, ugd); + + ea_object_event_callback_add(ugd->popup, + EA_CALLBACK_BACK, + _bt_back_btn_popup_del_cb, ugd); + evas_object_show(ugd->popup); } + } else { bt_dev_t *new_dev = NULL; Elm_Object_Item *item = NULL; @@ -469,18 +765,32 @@ void _bt_cb_bonding_created(int result, bt_device_info_s *dev_info, if (profile) _bt_set_profile_state_changed_cb(profile, new_dev); - item = _bt_main_add_paired_device(ugd, new_dev); + item = _bt_main_add_paired_device_on_bond(ugd, new_dev); if (item) { ugd->paired_device = eina_list_append(ugd->paired_device, new_dev); - _bt_update_paired_item_style(ugd); } /* Don't try to auto-connect in the network case */ if (profile == NULL) { _bt_main_connect_device(ugd, new_dev); + } else { + BT_DBG("Net profile exists"); + int connected = _bt_util_is_profile_connected( + BT_NETWORK_SERVER_CONNECTED, + new_dev->bd_addr); + bt_address_t address = { { 0 } }; + new_dev->connected_mask |= + connected ? BT_NETWORK_CONNECTED : 0x00; + memcpy(address.bd_addr, new_dev->bd_addr, + BT_ADDRESS_LENGTH_MAX); + + _bt_ipc_update_connected_status(user_data, + BT_NETWORK_CONNECTED, + connected, BT_UG_ERROR_NONE, + &address); } ugd->searched_item = NULL; @@ -500,10 +810,10 @@ void _bt_cb_bonding_destroyed(int result, char *remote_address, FN_START; bt_ug_data *ugd = NULL; - bt_dev_t *new_item = NULL; bt_dev_t *item = NULL; Eina_List *l = NULL; int i; + int ret; retm_if(remote_address == NULL, "Invalid argument: param is NULL\n"); retm_if(user_data == NULL, "Invalid argument: param is NULL\n"); @@ -514,7 +824,7 @@ void _bt_cb_bonding_destroyed(int result, char *remote_address, ugd->op_status = BT_ACTIVATED; if (result != BT_ERROR_NONE) { - BT_DBG("Failed to unbond: [%d]", result); + BT_ERR("Failed to unbond: [%d]", result); return; } @@ -523,43 +833,39 @@ void _bt_cb_bonding_destroyed(int result, char *remote_address, break; if (g_strcmp0(item->addr_str, remote_address) == 0) { - new_item = calloc(1, sizeof(bt_dev_t)); - if (new_item == NULL) - break; - - memcpy(new_item, item, sizeof(bt_dev_t)); - - if (item->uuids && item->uuid_count > 0) { - new_item->uuids = g_new0(char *, item->uuid_count + 1); - - for (i = 0; i < item->uuid_count; i++) { - new_item->uuids[i] = g_strdup(item->uuids[i]); - } - } - - new_item->uuid_count = item->uuid_count; + if (ugd->profile_vd) + _bt_profile_delete_view(item->ugd); _bt_main_remove_paired_device(ugd, item); + item->connected_mask = 0x00; + item->is_connected = 0x00; + item->genlist_item = NULL; + if (item->net_profile != NULL) { + BT_INFO("unset profile state change callback"); + _bt_unset_profile_state_changed_cb(item->net_profile); + item->net_profile = NULL; + } if (ugd->no_device_item) { elm_object_item_del(ugd->no_device_item); ugd->no_device_item = NULL; } - if (_bt_main_add_searched_device(ugd, new_item) != NULL) { + if (_bt_main_add_searched_device(ugd, item) != NULL) { ugd->searched_device = eina_list_append( - ugd->searched_device, new_item); - - _bt_update_searched_item_style(ugd); + ugd->searched_device, item); } - if (ugd->profile_vd) - _bt_profile_delete_view(new_item->ugd); - break; } } + if (ugd->paired_device == NULL) { + if (!ecore_idler_add(__bt_cb_auto_discovery, ugd)) + BT_ERR("idler can not be added\n\n"); + + } + FN_END; } @@ -597,7 +903,7 @@ void _bt_cb_service_searched(int result, bt_device_sdp_info_s *sdp_info, _bt_update_genlist_item((Elm_Object_Item *)item->genlist_item); if (result == BT_ERROR_NONE) { - _bt_util_get_service_mask_from_uuid_list( + bt_device_get_service_mask_from_uuid_list( sdp_info->service_uuid, sdp_info->service_count, &service_mask); @@ -620,7 +926,7 @@ void _bt_cb_service_searched(int result, bt_device_sdp_info_s *sdp_info, _bt_main_connect_device(ugd, item); } } else { - BT_DBG("Failed to get the service list [%d]", result); + BT_ERR("Failed to get the service list [%d]", result); if (ugd->waiting_service_response == TRUE) { if (ugd->popup) { @@ -628,8 +934,7 @@ void _bt_cb_service_searched(int result, bt_device_sdp_info_s *sdp_info, ugd->popup = NULL; } - ugd->popup = - _bt_create_popup(ugd->win_main, BT_STR_ERROR, + ugd->popup = _bt_create_popup(ugd->win_main, BT_STR_BLUETOOTH_ERROR, BT_STR_UNABLE_TO_GET_THE_SERVICE_LIST, _bt_main_popup_del_cb, ugd, 2); ugd->back_cb = _bt_util_launch_no_event; @@ -642,6 +947,9 @@ void _bt_cb_service_searched(int result, bt_device_sdp_info_s *sdp_info, (Evas_Smart_Cb)_bt_main_popup_del_cb, ugd); ea_object_event_callback_add(ugd->popup, EA_CALLBACK_BACK, _bt_main_popup_del_cb, ugd); + + evas_object_show(ugd->popup); + } } @@ -655,10 +963,14 @@ void _bt_cb_hid_state_changed(int result, bool connected, void *user_data) { FN_START; + ret_if(!user_data); + ret_if(!remote_address); + bt_ug_data *ugd = (bt_ug_data *)user_data; + ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED); bt_address_t address = { { 0 } }; - BT_DBG("Bluetooth HID Event [%d] Received", result); + BT_INFO("Bluetooth HID Event [%d] [%d]", result, connected); _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address); @@ -673,11 +985,15 @@ void _bt_cb_audio_state_changed(int result, bool connected, void *user_data) { FN_START; + ret_if(!user_data); + ret_if(!remote_address); + bt_ug_data *ugd = (bt_ug_data *)user_data; + ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED); bt_address_t address = { { 0 } }; int connected_type; - BT_DBG("Bluetooth Audio Event [%d] Received", result); + BT_INFO("Bluetooth Audio Event [%d] [%d] [%0x]", result, connected, type); if (type == BT_AUDIO_PROFILE_TYPE_A2DP) connected_type = BT_STEREO_HEADSET_CONNECTED; @@ -685,26 +1001,50 @@ void _bt_cb_audio_state_changed(int result, bool connected, connected_type = BT_HEADSET_CONNECTED; _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address); - + if (connected == 1) { + if(ugd->popup != NULL) { + char *bd_addr = evas_object_data_get(ugd->popup, "bd_addr"); + if (bd_addr != NULL) { + if (g_strcmp0(bd_addr, remote_address) == 0) { + evas_object_del(ugd->popup); + ugd->popup = NULL; + } + } + } + } _bt_ipc_update_connected_status(user_data, connected_type, connected, result, &address); FN_END; } -void _bt_cb_adapter_name_changed(char *device_name, void *user_data) +void _bt_cb_device_connection_state_changed(bool connected, + bt_device_connection_info_s *conn_info, + void *user_data) { FN_START; + ret_if(!user_data); - bt_ug_data *ugd; - - DBG_SECURE("Name: [%s]", device_name); - - ret_if(user_data == NULL); + bt_ug_data *ugd = NULL; + bt_dev_t *dev = NULL; ugd = (bt_ug_data *)user_data; + dev = _bt_main_get_dev_info_by_address(ugd->paired_device, conn_info->remote_address); + retm_if(dev == NULL, "dev is NULL"); - elm_genlist_item_fields_update(ugd->status_item, "elm.text.2", - ELM_GENLIST_ITEM_FIELD_TEXT); + BT_INFO("device connection state changed: Connected %d", connected); + if (!connected && ugd->disconn_req == true) { + ugd->disconn_req = false; + dev->status = BT_IDLE; + _bt_sort_paired_device_list(ugd, dev, dev->is_connected); + _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item); + } + FN_END; +} +void _bt_cb_adapter_name_changed(char *device_name, void *user_data) +{ + FN_START; + + DBG_SECURE("Name: [%s]", device_name); FN_END; } @@ -713,10 +1053,15 @@ void _bt_cb_nap_state_changed(bool connected, const char *remote_address, const char *interface_name, void *user_data) { FN_START; + ret_if(!user_data); + ret_if(!remote_address); + bt_ug_data *ugd = (bt_ug_data *)user_data; + ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED); bt_address_t address = { { 0 } }; - DBG_SECURE("interface = %s\n", interface_name); + BT_INFO("Bluetooth NAP Event [%d]", connected); + DBG_SECURE("interface = %s", interface_name); _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address); @@ -725,3 +1070,26 @@ void _bt_cb_nap_state_changed(bool connected, const char *remote_address, FN_END; } +void _bt_retry_connection_cb(void *data, + Evas_Object *obj, void *event_info) +{ + FN_START; + ret_if (obj == NULL || data == NULL); + + bt_dev_t *dev = (bt_dev_t *)data; + bt_ug_data *ugd = dev->ugd; + const char *event = elm_object_text_get(obj); + + if (ugd->popup) { + BT_DBG("delete popup"); + _bt_update_genlist_item((Elm_Object_Item *)dev->genlist_item); + evas_object_del(ugd->popup); + ugd->popup = NULL; + } + + if (!g_strcmp0(event, BT_STR_RETRY)) { + _bt_main_connect_device(ugd, dev); + } + + FN_END; +} |