2 * ug-setting-bluetooth-efl
4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * GirishAshok Joshi <girish.joshi@samsung.com>
8 * DoHyun Pyun <dh79.pyun@samsung.com>
10 * Licensed under the Flora License, Version 1.1 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.tizenopensource.org/license
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
25 #include <vconf-keys.h>
26 #include <bluetooth.h>
27 #include <efl_extension.h>
31 #include "bt-main-ug.h"
32 #include "bt-main-view.h"
34 #include "bt-widget.h"
35 #include "bt-string-define.h"
36 #include "bt-ipc-handler.h"
37 #include "bt-resource.h"
38 #include "bt-net-connection.h"
39 #include "syspopup_caller.h"
40 #include "bt-callback.h"
42 /**********************************************************************
44 ***********************************************************************/
46 static Eina_Bool __bt_cb_auto_discovery(void *data)
51 bt_ug_data *ugd = NULL;
53 retv_if(data == NULL, ECORE_CALLBACK_CANCEL);
55 ugd = (bt_ug_data *)data;
57 retv_if((elm_win_focus_get(ugd->win_main) == FALSE), ECORE_CALLBACK_CANCEL);
59 _bt_main_remove_all_searched_devices(ugd);
61 if (TIZEN_FEATURE_BT_HOG) {
62 ret = bt_adapter_le_start_scan((bt_adapter_le_scan_result_cb)_bt_cb_new_le_device_found, (void *)ugd);
64 ugd->is_le_discovery_started = TRUE;
65 BT_DBG("LE Discovery started");
67 BT_ERR("LE Discovery failed : Error Cause[%d]", ret);
71 ret = bt_adapter_start_device_discovery();
73 ugd->op_status = BT_SEARCHING;
74 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
76 if (ugd->searched_title == NULL)
77 _bt_main_add_searched_title(ugd);
79 BT_ERR("Discovery failed : Error Cause[%d]", ret);
83 return ECORE_CALLBACK_CANCEL;
86 static void __bt_cb_enable(int result, void *data)
91 bt_ug_data *ugd = NULL;
95 ugd = (bt_ug_data *)data;
97 if (ugd->op_status == BT_ACTIVATED) {
98 BT_DBG("Already enabled state");
102 if (result != BT_ERROR_NONE) {
103 BT_ERR("Failed to enable Bluetooth [%d]", result);
104 ugd->op_status = BT_DEACTIVATED;
105 _bt_update_genlist_item(ugd->onoff_item);
108 ugd->op_status = BT_ACTIVATED;
109 elm_genlist_item_item_class_update(ugd->onoff_item,
111 _bt_update_genlist_item(ugd->onoff_item);
112 ugd->aul_pairing_req = FALSE;
115 if (vconf_get_int(BT_FILE_VISIBLE_TIME, &timeout) != 0)
116 BT_ERR("Fail to get the timeout value");
118 _bt_util_change_discoverable_mode(ugd, TRUE);
120 _bt_util_set_phone_name();
122 if (!ugd->device_name_item)
123 _bt_main_add_device_name_item(ugd, ugd->main_genlist);
125 if (ugd->empty_status_item) {
126 elm_object_item_del(ugd->empty_status_item);
127 ugd->empty_status_item = NULL;
130 if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
131 g_idle_add((GSourceFunc) _bt_idle_destroy_ug, ugd);
133 } else if (ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY) {
137 ugd->scan_btn = _bt_main_create_scan_button(ugd);
139 _bt_update_genlist_item(ugd->paired_title);
140 _bt_update_genlist_item(ugd->searched_title);
142 /* In the NFC case, we don't need to display the paired device */
143 if (ugd->bt_launch_mode != BT_LAUNCH_USE_NFC)
144 _bt_main_draw_paired_devices(ugd);
146 if (!ecore_idler_add(__bt_cb_auto_discovery, ugd))
147 BT_ERR("idler can not be added\n\n");
152 static void __bt_cb_disable(int result, void *data)
155 bt_ug_data *ugd = NULL;
156 ret_if(data == NULL);
158 ugd = (bt_ug_data *)data;
161 if (ugd->op_status == BT_DEACTIVATED) {
162 BT_DBG("Already disabled state");
166 if (ugd->help_more_popup) {
167 evas_object_del(ugd->help_more_popup);
168 ugd->help_more_popup = NULL;
172 evas_object_del(ugd->popup);
176 if (ugd->rename_popup) {
177 evas_object_del(ugd->rename_popup);
178 ugd->rename_popup = NULL;
179 ugd->rename_entry = NULL;
182 if (result != BT_ERROR_NONE) {
183 BT_ERR("Failed to disable Bluetooth [%d]", result);
184 ugd->op_status = BT_ACTIVATED;
186 /* Delete profile view */
187 if (ugd->profile_vd != NULL) {
188 elm_naviframe_item_pop(ugd->navi_bar);
189 ugd->profile_vd = NULL;
192 if (ugd->timeout_id) {
193 g_source_remove(ugd->timeout_id);
197 ugd->op_status = BT_DEACTIVATED;
199 evas_object_del(ugd->scan_btn);
200 ugd->scan_btn = NULL;
201 elm_genlist_item_item_class_update(ugd->onoff_item,
204 if (ugd->device_name_item) {
205 elm_object_item_del(ugd->device_name_item);
206 ugd->device_name_item = NULL;
209 if (ugd->bt_launch_mode != BT_LAUNCH_VISIBILITY &&
210 ugd->bt_launch_mode != BT_LAUNCH_ONOFF) {
211 elm_object_disabled_set(ugd->scan_btn, EINA_FALSE);
212 _bt_main_remove_all_paired_devices(ugd);
213 _bt_main_remove_all_searched_devices(ugd);
216 if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
217 ret = _bt_idle_destroy_ug((void *)ugd);
218 if (ret != BT_UG_ERROR_NONE)
219 BT_DBG("fail to destory ug");
224 _bt_update_genlist_item(ugd->onoff_item);
225 _bt_update_genlist_item(ugd->paired_title);
226 _bt_update_genlist_item(ugd->searched_title);
231 static void __bt_cb_search_completed(int result, void *data)
235 bt_ug_data *ugd = NULL;
237 ret_if(data == NULL);
239 ugd = (bt_ug_data *)data;
241 if (ugd->op_status == BT_SEARCHING)
242 ugd->op_status = BT_ACTIVATED;
244 ugd->is_discovery_started = FALSE;
246 elm_object_text_set(ugd->scan_btn, BT_STR_SCAN);
248 _bt_update_genlist_item(ugd->paired_title);
249 _bt_update_genlist_item(ugd->searched_title);
251 if (ugd->searched_device == NULL ||
252 eina_list_count(ugd->searched_device) == 0) {
253 /* Don't add the no device item, if no device item already exist */
254 ret_if(ugd->no_device_item != NULL);
256 if (ugd->op_status != BT_DEACTIVATED)
257 ugd->no_device_item = _bt_main_add_no_device_found(ugd);
259 _bt_update_genlist_item(ugd->no_device_item);
265 static bool __bt_cb_match_discovery_type(unsigned int major_class,
266 unsigned int service_class,
271 bt_device_major_mask_t major_mask = BT_DEVICE_MAJOR_MASK_MISC;
273 if (mask == 0x000000)
276 BT_DBG("mask: %x", mask);
278 BT_DBG("service_class: %x", service_class);
280 /* Check the service_class */
281 if (service_class & mask)
284 /* Check the major class */
285 switch (major_class) {
286 case BT_MAJOR_DEV_CLS_COMPUTER:
287 major_mask = BT_DEVICE_MAJOR_MASK_COMPUTER;
289 case BT_MAJOR_DEV_CLS_PHONE:
290 major_mask = BT_DEVICE_MAJOR_MASK_PHONE;
292 case BT_MAJOR_DEV_CLS_LAN_ACCESS_POINT:
293 major_mask = BT_DEVICE_MAJOR_MASK_LAN_ACCESS_POINT;
295 case BT_MAJOR_DEV_CLS_AUDIO:
296 major_mask = BT_DEVICE_MAJOR_MASK_AUDIO;
298 case BT_MAJOR_DEV_CLS_PERIPHERAL:
299 major_mask = BT_DEVICE_MAJOR_MASK_PERIPHERAL;
301 case BT_MAJOR_DEV_CLS_IMAGING:
302 major_mask = BT_DEVICE_MAJOR_MASK_IMAGING;
304 case BT_MAJOR_DEV_CLS_WEARABLE:
305 major_mask = BT_DEVICE_MAJOR_MASK_WEARABLE;
307 case BT_MAJOR_DEV_CLS_TOY:
308 major_mask = BT_DEVICE_MAJOR_MASK_TOY;
310 case BT_MAJOR_DEV_CLS_HEALTH:
311 major_mask = BT_DEVICE_MAJOR_MASK_HEALTH;
314 major_mask = BT_DEVICE_MAJOR_MASK_MISC;
318 BT_DBG("major_mask: %x", major_mask);
320 if (mask & major_mask)
328 static void __bt_cb_new_device_found(bt_adapter_device_discovery_info_s *info,
333 bt_ug_data *ugd = NULL;
334 bt_dev_t *dev = NULL;
335 bt_device_info_s *device_info = NULL;
337 ret_if(info == NULL);
338 ret_if(data == NULL);
340 ugd = (bt_ug_data *)data;
341 ret_if(ugd->op_status != BT_SEARCHING);
343 BT_DBG("major_device_class: %d", info->bt_class.major_device_class);
344 BT_DBG("minor_device_class: %d", info->bt_class.minor_device_class);
345 BT_DBG("major_service_class_mask: %d", info->bt_class.major_service_class_mask);
347 /* Check the service_class */
348 if (__bt_cb_match_discovery_type(
349 info->bt_class.major_device_class,
350 info->bt_class.major_service_class_mask,
351 ugd->search_type) == FALSE) {
352 BT_DBG("No matched device type");
356 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
358 The Class of Device field shall be set to the following:
359 1. Mandatory to set the ¡®Rendering¡¯ bit for the SNK and the ¡®Capturing¡¯ bit for the SRC in the Service Class field.
361 #if 0 /* The below code also filters other devices that is not A2DP source role, so it is disabled in the tizen platform */
362 retm_if(!(info->bt_class.major_service_class_mask & BT_COD_SC_CAPTURING),
363 "Display A2DP source only in A2DP sink role. Skip this device");
367 if (info->is_bonded == TRUE) {
368 BT_DBG("Paired device found");
369 if (_bt_main_check_and_update_device(ugd->paired_device,
370 info->remote_address,
371 info->remote_name) >= 0) {
372 /* Update all realized items */
373 elm_genlist_realized_items_update(ugd->main_genlist);
377 device_info = (bt_device_info_s *)g_malloc0(sizeof(bt_device_info_s));
378 /* Fix : NULL_RETURNS */
379 if (device_info == NULL)
382 device_info->bt_class = info->bt_class;
383 device_info->remote_address = g_strdup(info->remote_address);
384 device_info->remote_name = g_strdup(info->remote_name);
385 device_info->service_count = info->service_count;
387 if (info->service_uuid != NULL && info->service_count > 0) {
388 device_info->service_uuid = g_new0(char *, info->service_count + 1);
390 for (i = 0; i < info->service_count; i++)
391 device_info->service_uuid[i] = g_strdup(info->service_uuid[i]);
393 dev = _bt_main_create_paired_device_item(device_info);
395 for (i = 0; i < info->service_count; i++)
396 g_free(device_info->service_uuid[i]);
398 g_free(device_info->remote_address);
399 g_free(device_info->remote_name);
402 retm_if(!dev, "create paired device item fail!");
404 dev->ugd = (void *)ugd;
406 if (_bt_main_is_matched_profile(ugd->search_type,
407 info->bt_class.major_device_class,
408 info->bt_class.major_service_class_mask,
410 info->bt_class.minor_device_class) == TRUE) {
411 if (_bt_main_add_paired_device(ugd, dev) != NULL) {
413 eina_list_append(ugd->paired_device, dev);
416 BT_ERR("Device class and search type do not match");
419 if (_bt_main_check_and_update_device(ugd->paired_device,
420 info->remote_address,
421 info->remote_name) >= 0) {
422 _bt_update_device_list(ugd);
427 if (ugd->searched_device == NULL)
428 _bt_update_genlist_item(ugd->searched_title);
430 if (_bt_main_check_and_update_device(ugd->searched_device,
431 info->remote_address,
432 info->remote_name) >= 0) {
433 _bt_update_device_list(ugd);
435 dev = _bt_main_create_searched_device_item((void *)info);
437 BT_ERR("Create new device item failed");
441 if (_bt_main_is_matched_profile(ugd->search_type,
445 dev->minor_class) == TRUE) {
446 if (_bt_main_add_searched_device(ugd, dev) == NULL) {
447 BT_ERR("Fail to add the searched device");
451 ugd->searched_device =
452 eina_list_append(ugd->searched_device, dev);
455 BT_DBG("Searched device does not match the profile");
463 static void __bt_retry_pairing_cb(void *data,
464 Evas_Object *obj, void *event_info)
467 ret_if(obj == NULL || data == NULL);
469 bt_ug_data *ugd = (bt_ug_data *)data;
470 const char *event = elm_object_text_get(obj);
473 BT_DBG("delete popup");
474 evas_object_del(ugd->popup);
478 if ((!g_strcmp0(event, BT_STR_RETRY) || (!g_strcmp0(event, BT_STR_OK))) &&
479 _bt_main_request_pairing_with_effect(ugd,
480 ugd->searched_item) != BT_UG_ERROR_NONE) {
481 ugd->searched_item = NULL;
483 if (!g_strcmp0(event, BT_STR_CANCEL))
484 ugd->op_status = BT_ACTIVATED;
489 /**********************************************************************
491 ***********************************************************************/
493 void _bt_cb_state_changed(int result,
494 bt_adapter_state_e adapter_state,
497 BT_INFO("bluetooth %s", adapter_state == BT_ADAPTER_ENABLED ?
498 "enabled" : "disabled");
500 if (adapter_state == BT_ADAPTER_ENABLED)
501 __bt_cb_enable(result, user_data);
503 __bt_cb_disable(result, user_data);
506 void _bt_cb_new_le_device_found(int result, bt_adapter_le_device_scan_result_info_s *info, void *data)
510 bt_ug_data *ugd = NULL;
511 bt_dev_t *dev = NULL;
512 char *remote_name = NULL;
515 ret_if(info == NULL);
516 ret_if(data == NULL);
518 ugd = (bt_ug_data *)data;
519 ret_if(ugd->op_status != BT_SEARCHING);
521 ret = bt_adapter_le_get_scan_result_device_name(info, BT_ADAPTER_LE_PACKET_ADVERTISING, &remote_name);
522 if (ret != BT_ERROR_NONE)
523 BT_ERR("Fail to get le device name");
525 if (ugd->searched_device == NULL)
526 _bt_update_genlist_item(ugd->searched_title);
528 if (_bt_main_check_and_update_device(ugd->searched_device,
529 info->remote_address,
531 _bt_update_device_list(ugd);
533 dev = _bt_main_create_searched_le_device_item((void *)info);
535 BT_ERR("Create new device item failed");
540 if (_bt_main_add_searched_device(ugd, dev) == NULL) {
541 BT_ERR("Fail to add the searched device");
546 ugd->searched_device =
547 eina_list_append(ugd->searched_device, dev);
554 void _bt_cb_discovery_state_changed(int result,
555 bt_adapter_device_discovery_state_e discovery_state,
556 bt_adapter_device_discovery_info_s *discovery_info,
559 bt_ug_data *ugd = NULL;
563 ret_if(user_data == NULL);
565 ugd = (bt_ug_data *)user_data;
567 if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_STARTED) {
568 BT_INFO("BR/EDR discovery started");
569 ugd->is_discovery_started = TRUE;
570 /*Now enable the Scan button, so that user may call cancel discovery */
571 elm_object_disabled_set(ugd->scan_btn, EINA_FALSE);
572 } else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FOUND)
573 __bt_cb_new_device_found(discovery_info, user_data);
574 else if (discovery_state == BT_ADAPTER_DEVICE_DISCOVERY_FINISHED) {
575 BT_INFO("BR/EDR discovery finished");
576 if (!TIZEN_FEATURE_BT_HOG) {
577 ret_if(ugd->is_discovery_started == FALSE);
579 ret_if((ugd->is_discovery_started == FALSE) && (ugd->is_le_discovery_started == FALSE));
581 if (ugd->is_le_discovery_started == TRUE) {
582 ret = bt_adapter_le_stop_scan();
584 ugd->is_le_discovery_started = FALSE;
587 __bt_cb_search_completed(result, user_data);
588 if (ugd->op_status == BT_PAIRING)
589 elm_object_disabled_set(ugd->scan_btn, EINA_TRUE);
591 elm_object_disabled_set(ugd->scan_btn, EINA_FALSE);
593 BT_ERR("Unknown device discovery state");
597 void _bt_cb_visibility_mode_changed
598 (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data)
601 bt_ug_data *ugd = NULL;
603 ugd = (bt_ug_data *)user_data;
605 if (visibility_mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE &&
606 result == BT_ERROR_NONE &&
607 ugd->ug_status != BT_UG_PAUSE &&
608 ugd->ug_status != BT_UG_DESTORY) {
609 BT_DBG("visibility is turned off. turn on again!");
610 _bt_util_change_discoverable_mode(ugd, TRUE);
615 void _bt_cb_gatt_connection_state_changed(int result, bool connected, char *remote_address, void *user_data)
619 bt_ug_data *ugd = NULL;
620 bt_dev_t *dev = NULL;
622 bt_address_t address = { { 0 } };
624 ret_if(user_data == NULL);
625 _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address);
627 /* TODO : Other GATT scenario should be considered.
628 In this case, only HOG scenario is considered */
629 connected_type = BT_LE_HID_CONNECTED;
632 ugd = (bt_ug_data *)user_data;
633 ret_if(ugd->op_status == BT_DEACTIVATING);
635 if (ugd->op_status == BT_PAIRING)
636 ugd->op_status = BT_ACTIVATED;
637 /* In the NFC cas, we don't need to display the paired device */
638 if (ugd->bt_launch_mode == BT_LAUNCH_USE_NFC)
641 dev = _bt_main_get_dev_info_by_address(ugd->searched_device, remote_address);
642 if (dev == NULL && ugd->searched_item != NULL)
643 dev = _bt_main_get_dev_info(ugd->searched_device, ugd->searched_item);
645 elm_object_disabled_set(ugd->scan_btn, EINA_FALSE);
648 if (result != BT_ERROR_NONE)
649 BT_ERR("Failed to GATT connect with device [%d]", result);
651 BT_DBG("LE Connected");
653 BT_DBG("LE Disconnected");
656 _bt_ipc_update_connected_status(ugd, connected_type,
657 connected, result, &address);
660 void _bt_cb_bonding_created(int result, bt_device_info_s *dev_info,
665 bt_ug_data *ugd = NULL;
666 bt_dev_t *dev = NULL;
667 Evas_Object *btn1 = NULL;
668 Evas_Object *btn2 = NULL;
670 ret_if(dev_info == NULL);
671 ret_if(user_data == NULL);
673 ugd = (bt_ug_data *)user_data;
674 ret_if(ugd->op_status == BT_DEACTIVATING);
676 if (ugd->op_status == BT_PAIRING)
677 ugd->op_status = BT_ACTIVATED;
679 /* Enable UG to send another pairing request */
680 ugd->aul_pairing_req = FALSE;
682 /* In the NFC cas, we don't need to display the paired device */
683 if (ugd->bt_launch_mode == BT_LAUNCH_USE_NFC)
686 dev = _bt_main_get_dev_info_by_address(ugd->searched_device,
687 dev_info->remote_address);
689 if (dev == NULL && ugd->searched_item != NULL)
690 dev = _bt_main_get_dev_info(ugd->searched_device, ugd->searched_item);
692 if (TIZEN_FEATURE_BT_HOG) {
694 if (dev->is_le_device)
695 BT_DBG("it is the le device");
697 BT_DBG("it is not le device");
699 BT_DBG("dev is null");
704 elm_object_disabled_set(ugd->scan_btn, EINA_FALSE);
706 if (result != BT_ERROR_NONE) {
707 BT_ERR("Failed to pair with device [%d]", result);
708 retm_if(dev == NULL, "dev is NULL");
710 dev->status = BT_IDLE;
712 elm_genlist_item_item_class_update(dev->genlist_item,
713 ugd->searched_device_itc);
714 _bt_update_genlist_item((Elm_Object_Item *)dev->genlist_item);
717 BT_ERR("Authentication Failed");
718 if (_bt_util_is_battery_low() == TRUE) {
719 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
720 } else if (result != BT_ERROR_NOT_IN_PROGRESS
721 && result != BT_ERROR_CANCELLED){
722 ugd->op_status = BT_PAIRING;
724 _bt_main_popup_del_cb(ugd, NULL, NULL);
726 ugd->popup_data.type = BT_POPUP_PAIRING_ERROR;
727 ugd->popup_data.data = g_strdup(dev->name);
728 ugd->popup = _bt_create_popup(ugd, NULL, ugd, 0);
729 retm_if(ugd->popup == NULL, "fail to create popup!");
731 btn1 = elm_button_add(ugd->popup);
732 elm_object_style_set(btn1, "popup");
733 elm_object_domain_translatable_text_set(
735 PKGNAME, "IDS_BR_SK_CANCEL");
736 elm_object_part_content_set(ugd->popup, "button1", btn1);
737 evas_object_smart_callback_add(btn1,
738 "clicked", __bt_retry_pairing_cb, ugd);
740 btn2 = elm_button_add(ugd->popup);
741 elm_object_style_set(btn2, "popup");
742 elm_object_domain_translatable_text_set(
744 PKGNAME, "IDS_ST_BUTTON_RETRY");
745 elm_object_part_content_set(ugd->popup, "button2", btn2);
746 evas_object_smart_callback_add(btn2,
747 "clicked", __bt_retry_pairing_cb, ugd);
749 eext_object_event_callback_add(ugd->popup,
751 _bt_back_btn_popup_del_cb, ugd);
752 evas_object_show(ugd->popup);
756 bt_dev_t *new_dev = NULL;
757 Elm_Object_Item *item = NULL;
758 void *profile = NULL;
760 if (_bt_main_check_and_update_device(ugd->paired_device,
761 dev_info->remote_address,
762 dev_info->remote_name) >= 0) {
763 _bt_update_device_list(ugd);
766 /* Remove the item in searched dialogue */
767 _bt_main_remove_searched_device(ugd, dev);
770 /* Add the item in paired dialogue group */
771 new_dev = _bt_main_create_paired_device_item(dev_info);
772 if (new_dev == NULL) {
773 BT_ERR("new_dev is NULL");
777 if (TIZEN_FEATURE_BT_HOG) {
778 if (dev->is_le_device)
779 new_dev->is_le_device = TRUE;
781 new_dev->is_le_device = FALSE;
784 #ifndef TIZEN_BT_A2DP_SINK_ENABLE
785 profile = _bt_get_registered_net_profile(ugd->connection,
789 _bt_set_profile_state_changed_cb(profile, new_dev);
791 if (_bt_main_is_matched_profile(ugd->search_type,
792 new_dev->major_class,
793 new_dev->service_class,
795 new_dev->minor_class) == TRUE) {
796 item = _bt_main_add_paired_device_on_bond(ugd, new_dev);
798 BT_ERR("Device did not match search type");
799 _bt_util_free_device_item(new_dev);
805 eina_list_append(ugd->paired_device, new_dev);
809 /* Don't try to auto-connect in the network case */
810 if (profile == NULL && ugd->searched_item != NULL) {
811 if (_bt_main_is_connectable_device(new_dev))
812 _bt_main_connect_device(ugd, new_dev);
814 BT_DBG("Net profile exists");
815 int connected = _bt_util_is_profile_connected(
816 BT_NETWORK_SERVER_CONNECTED,
818 bt_address_t address = { { 0 } };
819 new_dev->connected_mask |=
820 connected ? BT_NETWORK_CONNECTED : 0x00;
821 memcpy(address.bd_addr, new_dev->bd_addr,
822 BT_ADDRESS_LENGTH_MAX);
824 _bt_ipc_update_connected_status(user_data,
825 BT_NETWORK_CONNECTED,
826 connected, BT_UG_ERROR_NONE,
830 ugd->searched_item = NULL;
831 ugd->paired_item = item;
839 void _bt_cb_bonding_destroyed(int result, char *remote_address,
844 bt_ug_data *ugd = NULL;
845 bt_dev_t *item = NULL;
848 retm_if(remote_address == NULL, "Invalid argument: param is NULL\n");
849 retm_if(user_data == NULL, "Invalid argument: param is NULL\n");
851 ugd = (bt_ug_data *)user_data;
853 EINA_LIST_FOREACH(ugd->paired_device, l, item) {
857 if (g_strcmp0(item->addr_str, remote_address) == 0) {
858 item->status = BT_IDLE;
860 if (result != BT_ERROR_NONE) {
861 BT_ERR("Failed to unbond: [%d]", result);
866 _bt_profile_delete_view(item->ugd);
868 _bt_main_remove_paired_device(ugd, item);
869 item->connected_mask = 0x00;
870 item->is_connected = 0x00;
871 item->genlist_item = NULL;
873 if (item->net_profile != NULL) {
874 BT_INFO("unset profile state change callback");
875 _bt_unset_profile_state_changed_cb(item->net_profile);
876 item->net_profile = NULL;
879 if (ugd->no_device_item) {
880 elm_object_item_del(ugd->no_device_item);
881 ugd->no_device_item = NULL;
884 if (_bt_main_add_searched_device(ugd, item) != NULL) {
885 ugd->searched_device = eina_list_append(
886 ugd->searched_device, item);
893 if (ugd->paired_device == NULL && ugd->op_status != BT_PAIRING) {
894 if (!ecore_idler_add(__bt_cb_auto_discovery, ugd))
895 BT_ERR("idler can not be added\n\n");
902 void _bt_cb_service_searched(int result, bt_device_sdp_info_s *sdp_info,
908 bt_ug_data *ugd = NULL;
909 bt_service_class_t service_mask = 0;
910 bt_dev_t *item = NULL;
911 Evas_Object *btn = NULL;
913 ret_if(user_data == NULL);
915 ugd = (bt_ug_data *)user_data;
917 ugd->op_status = BT_ACTIVATED;
919 BT_DBG("Result: %d", result);
921 item = _bt_main_get_dev_info_by_address(ugd->paired_device,
922 sdp_info->remote_address);
925 item = _bt_main_get_dev_info(ugd->paired_device, ugd->paired_item);
928 ugd->waiting_service_response = FALSE;
932 item->status = BT_IDLE;
933 _bt_update_genlist_item((Elm_Object_Item *)item->genlist_item);
935 if (result == BT_ERROR_NONE) {
936 bt_device_get_service_mask_from_uuid_list(
937 sdp_info->service_uuid,
938 sdp_info->service_count,
941 if (sdp_info->service_uuid != NULL && sdp_info->service_count > 0) {
943 _bt_util_free_device_uuids(item);
944 item->uuids = g_new0(char *, sdp_info->service_count + 1);
946 for (i = 0; i < sdp_info->service_count; i++)
947 item->uuids[i] = g_strdup(sdp_info->service_uuid[i]);
949 item->uuid_count = sdp_info->service_count;
952 item->service_list = service_mask;
954 if (ugd->waiting_service_response == TRUE)
955 _bt_main_connect_device(ugd, item);
957 BT_ERR("Failed to get the service list [%d]", result);
959 if (ugd->waiting_service_response == TRUE) {
960 _bt_main_popup_del_cb(ugd, NULL, NULL);
962 ugd->popup_data.type = BT_POPUP_GET_SERVICE_LIST_ERROR;
963 ugd->popup = _bt_create_popup(ugd,
964 _bt_main_popup_del_cb, ugd, 2);
965 retm_if(ugd->popup == NULL, "fail to create popup!");
966 ugd->back_cb = _bt_util_launch_no_event;
968 btn = elm_button_add(ugd->popup);
969 elm_object_style_set(btn, "popup");
970 elm_object_domain_translatable_text_set(
972 PKGNAME, "IDS_BR_SK_CANCEL");
973 elm_object_part_content_set(ugd->popup, "button1", btn);
974 evas_object_smart_callback_add(btn, "clicked",
975 (Evas_Smart_Cb)_bt_main_popup_del_cb, ugd);
976 eext_object_event_callback_add(ugd->popup, EEXT_CALLBACK_BACK,
977 _bt_main_popup_del_cb, ugd);
979 evas_object_show(ugd->popup);
984 ugd->waiting_service_response = FALSE;
989 void _bt_cb_hid_state_changed(int result, bool connected,
990 const char *remote_address,
995 ret_if(!remote_address);
996 bt_ug_data *ugd = (bt_ug_data *)user_data;
997 ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED);
999 bt_address_t address = { { 0 } };
1001 BT_INFO("Bluetooth HID Event [%d] [%d]", result, connected);
1003 _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address);
1005 _bt_ipc_update_connected_status(user_data, BT_HID_CONNECTED,
1006 connected, result, &address);
1010 void _bt_cb_audio_state_changed(int result, bool connected,
1011 const char *remote_address,
1012 bt_audio_profile_type_e type,
1017 ret_if(!remote_address);
1018 bt_ug_data *ugd = (bt_ug_data *)user_data;
1019 ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED);
1021 bt_address_t address = { { 0 } };
1024 BT_INFO("Bluetooth Audio Event [%d] [%d] [%0x]", result, connected, type);
1026 if (type == BT_AUDIO_PROFILE_TYPE_A2DP)
1027 connected_type = BT_STEREO_HEADSET_CONNECTED;
1028 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
1029 else if (type == BT_AUDIO_PROFILE_TYPE_A2DP_SINK)
1030 connected_type = BT_MUSIC_PLAYER_CONNECTED;
1033 connected_type = BT_HEADSET_CONNECTED;
1035 _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address);
1037 if (ugd->bt_launch_mode == BT_LAUNCH_CONNECT_AUDIO_SOURCE) {
1040 b = bundle_create();
1041 retm_if(!b, "Unable to create bundle");
1043 bundle_add_str(b, "event-type", "terminate");
1045 ret = syspopup_launch("bt-syspopup", b);
1047 BT_ERR("Popup launch failed...retry %d", ret);
1049 if (connected && result == BT_ERROR_NONE) {
1050 _bt_ug_destroy(ugd, (void *)&result);
1055 if (connected == 1) {
1056 if (ugd->popup != NULL) {
1057 char *bd_addr = evas_object_data_get(ugd->popup, "bd_addr");
1058 if (bd_addr != NULL) {
1059 if (g_strcmp0(bd_addr, remote_address) == 0) {
1060 evas_object_del(ugd->popup);
1066 _bt_ipc_update_connected_status(user_data, connected_type,
1067 connected, result, &address);
1071 void _bt_cb_device_connection_state_changed(bool connected,
1072 bt_device_connection_info_s *conn_info,
1078 bt_ug_data *ugd = NULL;
1079 bt_dev_t *dev = NULL;
1081 ugd = (bt_ug_data *)user_data;
1082 dev = _bt_main_get_dev_info_by_address(ugd->paired_device, conn_info->remote_address);
1083 retm_if(dev == NULL, "dev is NULL");
1085 BT_INFO("device connection state changed: Connected %d", connected);
1086 if (!connected && ugd->disconn_req == true) {
1087 ugd->disconn_req = false;
1088 if (dev->status != BT_DEV_UNPAIRING)
1089 dev->status = BT_IDLE;
1090 _bt_sort_paired_device_list(ugd, dev, dev->is_connected);
1091 _bt_update_genlist_item((Elm_Object_Item *) dev->genlist_item);
1095 void _bt_cb_adapter_name_changed(char *device_name, void *user_data)
1099 DBG_SECURE("Name: [%s]", device_name);
1104 void _bt_cb_nap_state_changed(bool connected, const char *remote_address,
1105 const char *interface_name, void *user_data)
1109 ret_if(!remote_address);
1110 bt_ug_data *ugd = (bt_ug_data *)user_data;
1111 ret_if(ugd->op_status == BT_DEACTIVATING || ugd->op_status == BT_DEACTIVATED);
1113 bt_address_t address = { { 0 } };
1115 BT_INFO("Bluetooth NAP Event [%d]", connected);
1116 DBG_SECURE("interface = %s", interface_name);
1118 _bt_util_addr_string_to_addr_type(address.bd_addr, remote_address);
1120 _bt_ipc_update_connected_status(user_data, BT_NETWORK_CONNECTED,
1121 connected, BT_UG_ERROR_NONE, &address);
1125 void _bt_retry_connection_cb(void *data,
1126 Evas_Object *obj, void *event_info)
1129 ret_if(obj == NULL || data == NULL);
1131 bt_dev_t *dev = (bt_dev_t *)data;
1132 bt_ug_data *ugd = dev->ugd;
1133 const char *event = elm_object_text_get(obj);
1136 BT_DBG("delete popup");
1137 _bt_update_genlist_item((Elm_Object_Item *)dev->genlist_item);
1138 evas_object_del(ugd->popup);
1142 if (!g_strcmp0(event, BT_STR_RETRY))
1143 _bt_main_connect_device(ugd, dev);