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.
26 #include <vconf-internal-setting-keys.h>
29 #include <dbus/dbus.h>
30 #include <notification.h>
31 #include <efl_extension.h>
32 #include <device/power.h>
33 #include <gesture_recognition.h>
37 #include <setting-cfg.h>
40 #include "bt-main-ug.h"
42 #include "bt-widget.h"
43 #include "bt-main-view.h"
44 #include "bt-ipc-handler.h"
46 #include "bt-resource.h"
47 #include "bt-callback.h"
48 #include "bt-string-define.h"
49 #include "bt-net-connection.h"
50 #include "bluetooth_internal.h"
52 #define TOGGLE_OFF "0"
54 #ifndef __TIZEN_OPEN__
55 #define S_FINDER_TOGGLE_DATA "s_finder_setting_check_value_set"
58 #define BT_AUTO_CONNECT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
60 static void __on_destroy(ui_gadget_h ug, app_control_h service, void *priv);
62 extern int power_wakeup(bool dim);
65 /**********************************************************************
67 ***********************************************************************/
69 static void bt_ug_change_language(bt_ug_data *ugd)
75 if (ugd->profile_vd) {
76 if (ugd->profile_vd->genlist)
77 elm_genlist_realized_items_update(
78 ugd->profile_vd->genlist);
80 if (ugd->profile_vd->navi_it)
81 elm_object_item_text_set(ugd->profile_vd->navi_it,
85 if (ugd->main_genlist)
86 elm_genlist_realized_items_update(ugd->main_genlist);
89 elm_object_item_text_set(ugd->navi_it, BT_STR_BLUETOOTH);
91 if (ugd->op_status == BT_SEARCHING)
92 elm_object_text_set(ugd->scan_btn, BT_STR_STOP);
94 elm_object_text_set(ugd->scan_btn, BT_STR_SCAN);
98 _bt_set_popup_text(ugd, ugd->popup);
103 static void __bt_ug_release_memory(bt_ug_data *ugd)
107 bt_dev_t *dev = NULL;
109 Eina_List *l_next = NULL;
112 ret_if(ugd->main_genlist == NULL);
114 elm_genlist_clear(ugd->main_genlist);
115 evas_object_del(ugd->main_genlist);
116 ugd->main_genlist = NULL;
118 /* Release paired device items */
119 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, dev) {
121 eina_list_remove_list(ugd->paired_device, l);
122 _bt_util_free_device_item(dev);
125 /* Release searched device items */
126 EINA_LIST_FOREACH_SAFE(ugd->searched_device, l, l_next, dev) {
127 ugd->searched_device =
128 eina_list_remove_list(ugd->searched_device, l);
129 _bt_util_free_device_item(dev);
132 if (ugd->device_name_itc) {
133 elm_genlist_item_class_free(ugd->device_name_itc);
134 ugd->device_name_itc = NULL;
137 if (ugd->rename_entry_itc) {
138 elm_genlist_item_class_free(ugd->rename_entry_itc);
139 ugd->rename_entry_itc = NULL;
142 if (ugd->rename_desc_itc) {
143 elm_genlist_item_class_free(ugd->rename_desc_itc);
144 ugd->rename_desc_itc = NULL;
147 if (ugd->paired_title_itc) {
148 elm_genlist_item_class_free(ugd->paired_title_itc);
149 ugd->paired_title_itc = NULL;
152 if (ugd->searched_title_itc) {
153 elm_genlist_item_class_free(ugd->searched_title_itc);
154 ugd->searched_title_itc = NULL;
157 if (ugd->paired_device_itc) {
158 elm_genlist_item_class_free(ugd->paired_device_itc);
159 ugd->paired_device_itc = NULL;
162 if (ugd->searched_device_itc) {
163 elm_genlist_item_class_free(ugd->searched_device_itc);
164 ugd->searched_device_itc = NULL;
167 if (ugd->no_device_itc) {
168 elm_genlist_item_class_free(ugd->no_device_itc);
169 ugd->no_device_itc = NULL;
173 elm_genlist_item_class_free(ugd->on_itc);
178 elm_genlist_item_class_free(ugd->off_itc);
182 if (ugd->popup_bundle) {
183 free(ugd->popup_bundle);
184 ugd->popup_bundle = NULL;
188 _bt_main_popup_del_cb(ugd, NULL, NULL);
190 if (ugd->popup_timer) {
191 g_source_remove(ugd->popup_timer);
192 ugd->popup_timer = 0;
196 evas_object_del(ugd->base);
203 #ifndef __TIZEN_OPEN__
204 void __bt_motion_shake_cb(gesture_type_e motion,
205 const gesture_data_h event_data,
207 gesture_error_e error,
212 bt_ug_data *ugd = NULL;
213 gesture_event_e event;
216 ret_if(data == NULL);
217 ret_if(event_data == NULL);
218 ret_if(error != GESTURE_ERROR_NONE);
220 ugd = (bt_ug_data *)data;
222 if (motion == GESTURE_SHAKE) {
223 ret = gesture_get_event(data, &event);
224 ret_if(ret != GESTURE_ERROR_NONE);
226 if (event == GESTURE_SHAKE_DETECTED) {
227 BT_DBG("Scan devices");
228 ret = power_wakeup(0);
230 BT_ERR("Power wakeup failed [%d]", ret);
232 _bt_main_scan_device(ugd);
240 static void __bt_main_vconf_change_cb(keynode_t *key, void *data)
242 retm_if(NULL == key, "key is NULL");
243 retm_if(NULL == data, "data is NULL");
244 bt_ug_data *ugd = (bt_ug_data *)data;
246 char *vconf_name = vconf_keynode_get_name(key);
248 if (!g_strcmp0(vconf_name, VCONFKEY_SETAPPL_DEVICE_NAME_STR)) {
249 char *name_value = NULL;
250 name_value = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
251 retm_if(!name_value, "Get string is failed");
252 BT_INFO("name : %s", name_value);
254 if (ugd->device_name_item && g_strcmp0(ugd->phone_name, name_value)) {
255 _bt_update_genlist_item(ugd->device_name_item);
256 _bt_update_genlist_item(ugd->rename_entry_item);
260 BT_ERR("vconf_name is error");
264 static int __bt_initialize_view(bt_ug_data *ugd)
266 if (ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY)
267 _bt_main_draw_visibility_view(ugd);
268 else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF)
269 _bt_main_draw_onoff_view(ugd);
271 _bt_main_draw_list_view(ugd);
276 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
277 static void __bt_free_device_info(bt_dev_t *dev)
284 for (i = 0; i < dev->uuid_count ; i++) {
286 g_free(dev->uuids[i]);
287 dev->uuids[i] = NULL;
298 static void __bt_free_paired_device(bt_ug_data *ugd)
301 retm_if(!ugd, "ad is NULL!");
302 retm_if(!ugd->paired_device, "paired_device is NULL!");
305 Eina_List *l_next = NULL;
306 bt_dev_t *dev = NULL;
308 EINA_LIST_FOREACH_SAFE(ugd->paired_device, l, l_next, dev) {
309 __bt_free_device_info(dev);
312 eina_list_free(ugd->paired_device);
313 ugd->paired_device = NULL;
317 static bool __bt_cb_adapter_create_paired_device_list
318 (bt_device_info_s *device_info, void *user_data)
321 bt_dev_t *dev = NULL;
322 gboolean connected = FALSE;
323 bt_ug_data *ugd = NULL;
324 unsigned int service_class;
327 ugd = (bt_ug_data *)user_data;
328 retv_if(ugd == NULL, false);
330 dev = _bt_main_create_paired_device_item(device_info);
331 retv_if(!dev, false);
333 dev->ugd = (void *)ugd;
335 service_class = dev->service_class;
337 if (_bt_main_is_matched_profile(ugd->search_type,
341 dev->minor_class) == TRUE) {
343 if (dev->service_list & BT_SC_HFP_SERVICE_MASK ||
344 dev->service_list & BT_SC_HSP_SERVICE_MASK ||
345 dev->service_list & BT_SC_A2DP_SERVICE_MASK) {
346 connected = _bt_util_is_profile_connected(BT_HEADSET_CONNECTED,
348 dev->connected_mask |= connected ? BT_HEADSET_CONNECTED : 0x00;
350 connected = _bt_util_is_profile_connected(BT_STEREO_HEADSET_CONNECTED,
352 dev->connected_mask |=
353 connected ? BT_STEREO_HEADSET_CONNECTED : 0x00;
356 if (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) {
357 connected = _bt_util_is_profile_connected(BT_MUSIC_PLAYER_CONNECTED,
359 dev->connected_mask |=
360 connected ? BT_MUSIC_PLAYER_CONNECTED : 0x00;
363 dev->status = BT_IDLE;
364 dev->ugd = (void *)ugd;
365 dev->is_bonded = TRUE;
367 eina_list_append(ugd->paired_device, dev);
368 _bt_update_device_list(ugd);
370 BT_ERR("Device class and search type do not match");
378 static void __bt_get_paired_devices(bt_ug_data *ugd)
383 __bt_free_paired_device(ugd);
384 if (bt_adapter_foreach_bonded_device(
385 __bt_cb_adapter_create_paired_device_list,
386 (void *)ugd) != BT_ERROR_NONE) {
387 BT_ERR("bt_adapter_foreach_bonded_device() failed");
394 static int __bt_get_paired_device_count(bt_ug_data *ugd)
397 retvm_if(!ugd, 0, "ugd is NULL!");
398 __bt_get_paired_devices(ugd);
399 retvm_if(!ugd->paired_device, 0, "paired_device is NULL!");
400 int count = eina_list_count(ugd->paired_device);
401 //BT_DBG("paired device count : %d", count);
405 static void __bt_create_autoconnect_popup(bt_dev_t *dev)
412 retm_if(!b, "Unable to create bundle");
414 bundle_add_str(b, "event-type", "music-auto-connect-request");
416 ret = syspopup_launch("bt-syspopup", b);
418 BT_ERR("Popup launch failed...retry %d", ret);
424 static void __bt_auto_connect(bt_ug_data *ugd)
427 if (__bt_get_paired_device_count(ugd) == 1) {
428 BT_DBG("Launch mode is %d", ugd->bt_launch_mode);
430 bt_dev_t *dev = eina_list_nth(ugd->paired_device, 0);
432 BT_ERR("dev is NULL");
433 __on_destroy(ugd->ug, NULL, ugd);
437 /* Check whether the only paired device is Headset */
438 if (dev->service_list & BT_SC_A2DP_SOURCE_SERVICE_MASK) {
439 BT_DBG("Remote device support A2DP Source");
440 _bt_main_connect_device(ugd, dev);
441 BT_DBG("dev->status : %d", dev->status);
442 if (dev->status == BT_CONNECTING) {
443 __bt_create_autoconnect_popup(dev);
449 if (__bt_initialize_view(ugd) < 0) {
450 app_control_h service = NULL;
451 BT_ERR("__bt_initialize_view failed");
452 service = __bt_main_get_connection_result(ugd, FALSE);
453 _bt_ug_destroy(ugd, (void *)service);
459 static Eina_Bool __bt_launch_idler(void *data)
462 BT_DBG("UG_LAUNCH_PROFILING");
466 bt_ug_data *ugd = NULL;
468 retv_if(data == NULL, ECORE_CALLBACK_CANCEL);
470 ugd = (bt_ug_data *)data;
472 /* Set event callbacks */
473 #ifndef __TIZEN_OPEN__
474 char *toggle_data = NULL;
475 bt_adapter_state_e value;
478 #ifdef TIZEN_BT_A2DP_SINK_ENABLE
479 if (ugd->bt_launch_mode == BT_LAUNCH_CONNECT_AUDIO_SOURCE) {
480 if (bt_audio_initialize() != BT_ERROR_NONE)
481 BT_ERR("bt_audio_initialize() failed");
482 __bt_auto_connect(ugd);
485 __bt_initialize_view(ugd);
487 err = _bt_ipc_register_popup_event_signal(ugd);
488 if (err != BT_UG_ERROR_NONE)
489 BT_ERR("_bt_ipc_register_popup_event_signal failed: %d", err);
491 if (bt_audio_initialize() != BT_ERROR_NONE)
492 BT_ERR("bt_audio_initialize() failed");
493 if (_bt_create_net_connection(&ugd->connection) != BT_UG_ERROR_NONE)
494 BT_ERR("_bt_create_net_connection fail");
497 bt_adapter_set_state_changed_cb(_bt_cb_state_changed, (void *)ugd);
498 if (ret != BT_ERROR_NONE)
499 BT_ERR("bt_adapter_set_state_changed_cb failed");
501 if (ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY ||
502 ugd->bt_launch_mode == BT_LAUNCH_ONOFF) {
503 /* Don't need to register callback */
504 return ECORE_CALLBACK_CANCEL;
508 bt_audio_set_connection_state_changed_cb(_bt_cb_audio_state_changed,
510 if (ret != BT_ERROR_NONE)
511 BT_ERR("audio set connection state callback failed");
513 ret = bt_device_set_connection_state_changed_cb
514 (_bt_cb_device_connection_state_changed, (void *)ugd);
516 if (ret != BT_ERROR_NONE)
517 BT_ERR("device set connection state callback failed");
520 bt_adapter_set_device_discovery_state_changed_cb
521 (_bt_cb_discovery_state_changed, (void *)ugd);
522 if (ret != BT_ERROR_NONE)
523 BT_ERR("adapter set device discovery state callback failed");
525 if (TIZEN_FEATURE_BT_HOG) {
526 ret = bt_gatt_set_connection_state_changed_cb
527 ((bt_gatt_connection_state_changed_cb)_bt_cb_gatt_connection_state_changed, (void *)ugd);
528 if (ret != BT_ERROR_NONE)
529 BT_ERR("gatt set connection state callback failed");
532 ret = bt_adapter_set_visibility_mode_changed_cb
533 (_bt_cb_visibility_mode_changed, (void *)ugd);
534 if (ret != BT_ERROR_NONE)
535 BT_ERR("adapter set device visibility mode callback failed");
537 ret = bt_device_set_bond_created_cb(_bt_cb_bonding_created,
539 if (ret != BT_ERROR_NONE)
540 BT_ERR("bt_device_set_bond_created_cb failed");
542 ret = bt_device_set_bond_destroyed_cb(_bt_cb_bonding_destroyed,
544 if (ret != BT_ERROR_NONE)
545 BT_ERR("bt_device_set_bond_destroyed_cb failed");
547 ret = bt_device_set_service_searched_cb(_bt_cb_service_searched,
549 if (ret != BT_ERROR_NONE)
550 BT_ERR("bt_device_set_service_searched_cb failed");
552 ret = bt_adapter_set_name_changed_cb(_bt_cb_adapter_name_changed,
554 if (ret != BT_ERROR_NONE)
555 BT_ERR("bt_adapter_set_name_changed_cb failed");
557 ret = bt_hid_host_initialize(_bt_cb_hid_state_changed, (void *)ugd);
558 if (ret != BT_ERROR_NONE)
559 BT_ERR("bt_hid_host_initialize failed");
561 ret = bt_nap_set_connection_state_changed_cb(_bt_cb_nap_state_changed,
563 if (ret != BT_ERROR_NONE)
564 BT_ERR("bt_nap_set_connection_state_changed_cb failed");
566 #ifndef __TIZEN_OPEN__
567 if (app_control_get_extra_data(ugd->service, S_FINDER_TOGGLE_DATA,
568 &toggle_data) == APP_CONTROL_ERROR_NONE) {
570 if (bt_adapter_get_state(&value) == BT_ERROR_NONE) {
571 if (g_strcmp0(toggle_data, TOGGLE_OFF) == 0 &&
572 value == BT_ADAPTER_ENABLED) {
573 ret = _bt_main_disable_bt(ugd);
574 if (ret != BT_ERROR_NONE)
575 BT_ERR("_bt_main_disable_bt fail!");
576 } else if (g_strcmp0(toggle_data, TOGGLE_ON) == 0 &&
577 value == BT_ADAPTER_DISABLED) {
578 ret = _bt_main_enable_bt(ugd);
579 if (ret != BT_ERROR_NONE)
580 BT_ERR("_bt_main_enable_bt fail!");
588 /* In the NFC case, we don't need to display the paired device */
589 if (ugd->op_status == BT_ACTIVATED &&
590 ugd->bt_launch_mode != BT_LAUNCH_USE_NFC) {
591 _bt_main_draw_paired_devices(ugd);
592 } else if (ugd->op_status == BT_DEACTIVATED &&
593 ugd->bt_launch_mode != BT_LAUNCH_NORMAL) {
594 _bt_main_enable_bt(ugd);
597 /* In the NFC case, we don't need to display the paired device */
598 if (ugd->op_status == BT_ACTIVATED &&
599 ugd->bt_launch_mode != BT_LAUNCH_USE_NFC &&
600 ugd->bt_launch_mode != BT_LAUNCH_ONOFF) {
601 if (_bt_util_is_battery_low() == FALSE) {
603 if (TIZEN_FEATURE_BT_HOG) {
604 ret = bt_adapter_le_start_scan((bt_adapter_le_scan_result_cb)_bt_cb_new_le_device_found, (void *)ugd);
606 ugd->is_le_discovery_started = TRUE;
607 BT_DBG("LE Discovery started");
609 BT_ERR("LE Discovery failed : Error Cause[%d]", ret);
612 ret = bt_adapter_start_device_discovery();
614 ugd->op_status = BT_SEARCHING;
615 elm_object_text_set(ugd->scan_btn,
618 if (ugd->searched_title == NULL)
619 _bt_main_add_searched_title
623 ("Operation failed : Error Cause[%d]",
629 BT_DBG("UG_LAUNCH_PROFILING");
630 return ECORE_CALLBACK_CANCEL;
633 static void *__on_create(ui_gadget_h ug, enum ug_mode mode, app_control_h service,
638 bt_ug_data *ugd = NULL;
639 BT_DBG("UG_LAUNCH_PROFILING");
640 #ifndef __TIZEN_OPEN__
644 retv_if(!ug || !priv, NULL);
646 ugd = (bt_ug_data *)priv;
649 bindtextdomain(PKGNAME, LOCALEDIR);
651 ugd->win_main = ug_get_window();
653 if (!ugd->win_main) {
654 __on_destroy(ug, NULL, ugd);
658 _bt_main_init_status(ugd, service);
659 BT_DBG("ugd->bt_launch_mode : %d", ugd->bt_launch_mode);
661 #ifndef __TIZEN_OPEN__
663 bool supported = false;
665 ret = gesture_is_supported(GESTURE_SHAKE, &supported);
666 if (ret != GESTURE_ERROR_NONE) {
667 BT_ERR("gesture_is_supported failed : %d", ret);
670 BT_ERR("gesture is not supported");
672 ret = gesture_create(&handle);
673 if (ret != GESTURE_ERROR_NONE) {
674 BT_ERR("gesture_create failed : %d", ret);
676 ugd->handle = handle;
677 ret = gesture_start_recognition(handle, GESTURE_SHAKE,
678 GESTURE_OPTION_DEFAULT, __bt_motion_shake_cb, ugd);
679 if (ret != GESTURE_ERROR_NONE) {
680 BT_ERR("gesture_start_recognition failed : %d", ret);
681 gesture_release(handle);
688 ugd->service = service;
690 ugd->base = _bt_main_base_layout_create(ugd->win_main, ugd);
692 __on_destroy(ug, NULL, ugd);
695 /* Add layout for custom styles */
696 elm_theme_extension_add(NULL, BT_GENLIST_EDJ);
699 if (ugd->bt_launch_mode == BT_LAUNCH_VISIBILITY)
700 _bt_main_draw_visibility_view(ugd);
701 else if (ugd->bt_launch_mode == BT_LAUNCH_ONOFF)
702 _bt_main_draw_onoff_view(ugd);
704 _bt_main_draw_list_view(ugd);
707 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
708 __bt_main_vconf_change_cb, ugd);
711 BT_ERR("vconf_notify_key_changed failed");
713 // ugd->visibility_changed_by_ug = FALSE;
714 ugd->ug_status = BT_UG_CREATE;
716 BT_DBG("UG_LAUNCH_PROFILING");
721 static void __on_start(ui_gadget_h ug, app_control_h service, void *priv)
724 BT_DBG("UG_LAUNCH_PROFILING");
726 bt_ug_data *ugd = NULL;
730 /* Tizen 2.4's setting supports auto rotate mode */
732 elm_win_wm_rotation_preferred_rotation_set(ugd->win_main, 0);
735 if (!ecore_idler_add(__bt_launch_idler, ugd))
736 BT_ERR("idler can not be added");
737 _bt_util_change_discoverable_mode(ugd, TRUE);
738 ugd->ug_status = BT_UG_START;
739 BT_DBG("UG_LAUNCH_PROFILING");
744 static void __on_pause(ui_gadget_h ug, app_control_h service, void *priv)
747 BT_DBG("UG_LAUNCH_PROFILING");
748 bt_ug_data *ugd = NULL;
750 retm_if(priv == NULL, "Invalid argument: priv is NULL");
754 ugd = (bt_ug_data *)priv;
756 if (ugd->op_status == BT_SEARCHING)
757 bt_adapter_stop_device_discovery();
759 _bt_util_change_discoverable_mode(ugd, FALSE);
761 ugd->ug_status = BT_UG_PAUSE;
766 static void __on_resume(ui_gadget_h ug, app_control_h service, void *priv)
769 BT_DBG("UG_LAUNCH_PROFILING");
771 bt_ug_data *ugd = NULL;
773 retm_if(priv == NULL, "Invalid argument: priv is NULL");
775 BT_INFO("Resume UG");
777 ugd = (bt_ug_data *)priv;
780 ecore_timer_del(ugd->timer);
783 ugd->timer = ecore_timer_add(2, _bt_timer_change_discoverable_mode, ugd);
785 ugd->ug_status = BT_UG_RESUME;
790 static void __on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
794 bt_ug_data *ugd = NULL;
802 ugd->ug_status = BT_UG_DESTORY;
805 ecore_timer_del(ugd->timer);
809 if (ugd->request_timer) {
810 ecore_timer_del(ugd->request_timer);
811 ugd->request_timer = NULL;
814 if (ugd->timeout_id) {
815 g_source_remove(ugd->timeout_id);
819 if (ugd->network_timer) {
820 ecore_timer_del(ugd->network_timer);
821 ugd->network_timer = NULL;
824 /* This has been added before cancel discovery so as to
825 prevent device addition till cancel discovery */
826 err = bt_adapter_unset_device_discovery_state_changed_cb();
827 if (err != BT_ERROR_NONE)
828 BT_ERR("unset of device discovery state cb failed: %d", err);
829 if (ugd->op_status == BT_SEARCHING) {
830 err = bt_adapter_stop_device_discovery();
831 if (err != BT_ERROR_NONE)
832 BT_ERR("Stop device discovery failed: %d", err);
835 err = bt_adapter_unset_state_changed_cb();
836 if (err != BT_ERROR_NONE)
837 BT_ERR("unset of state change cb failed: %d", err);
839 err = bt_device_unset_bond_created_cb();
840 if (err != BT_ERROR_NONE)
841 BT_ERR("unset of bond creation cb failed: %d", err);
843 err = bt_device_unset_bond_destroyed_cb();
844 if (err != BT_ERROR_NONE)
845 BT_ERR("unset of bond destroyed cb failed: %d", err);
847 err = bt_device_unset_service_searched_cb();
848 if (err != BT_ERROR_NONE)
849 BT_ERR("unset of service search cb failed: %d", err);
851 err = bt_audio_unset_connection_state_changed_cb();
852 if (err != BT_ERROR_NONE)
853 BT_ERR("unset audio connection state cb failed: %d", err);
855 err = bt_device_unset_connection_state_changed_cb();
856 if (err != BT_ERROR_NONE)
857 BT_ERR("unset device connection state cb failed: %d", err);
859 err = bt_adapter_unset_name_changed_cb();
860 if (err != BT_ERROR_NONE)
861 BT_ERR("unset name change cb failed: %d", err);
863 err = bt_hid_host_deinitialize();
864 if (err != BT_ERROR_NONE)
865 BT_ERR("bt_hid_host_deinitialize failed: %d", err);
867 err = bt_audio_deinitialize();
868 if (err != BT_ERROR_NONE)
869 BT_ERR("bt_audio_deinitialize failed: %d", err);
871 err = bt_nap_unset_connection_state_changed_cb();
872 if (err != BT_ERROR_NONE)
873 BT_ERR("bt_nap_unset_connection_state_changed_cb err=%d", err);
875 _bt_util_change_discoverable_mode(ugd, FALSE);
877 err = bt_deinitialize();
878 if (err != BT_ERROR_NONE)
879 BT_ERR("bt_deinitialize failed: %d", err);
881 if (ugd->connection) {
882 err = _bt_destroy_net_connection(ugd->connection);
883 if (err != BT_UG_ERROR_NONE)
884 BT_ERR("_bt_destroy_net_connection failed: %d", err);
886 ugd->connection = NULL;
889 err = vconf_ignore_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
890 (vconf_callback_fn) __bt_main_vconf_change_cb);
893 BT_ERR("vconf_ignore_key_changed failed");
895 err = _bt_ipc_unregister_popup_event_signal(ugd);
896 if (err != BT_UG_ERROR_NONE)
897 BT_ERR("_bt_ipc_unregister_popup_event_signal failed: %d", err);
899 _bt_util_destroy_dpm_context(ugd);
901 __bt_ug_release_memory(ugd);
903 #ifndef __TIZEN_OPEN__
905 gesture_release(ugd->handle);
912 static void __on_message(ui_gadget_h ug, app_control_h msg, app_control_h service,
919 static void __on_event(ui_gadget_h ug, enum ug_event event, app_control_h service,
924 bt_ug_data *ugd = NULL;
926 ret_if(priv == NULL);
928 ugd = (bt_ug_data *)priv;
930 BT_INFO("Event : %d", event);
933 case UG_EVENT_LOW_MEMORY:
935 case UG_EVENT_LOW_BATTERY:
936 if (_bt_util_is_battery_low() == FALSE)
939 if (ugd->op_status == BT_SEARCHING)
940 bt_adapter_stop_device_discovery();
942 _bt_main_create_information_popup(ugd, BT_STR_LOW_BATTERY);
944 case UG_EVENT_LANG_CHANGE:
945 bt_ug_change_language(ugd);
953 static void __on_key_event(ui_gadget_h ug, enum ug_key_event event,
954 app_control_h service, void *priv)
958 bt_ug_data *ugd = NULL;
960 BT_INFO("Key event UG : %d", event);
962 ugd = (bt_ug_data *)priv;
965 case UG_KEY_EVENT_END:
966 _bt_ug_destroy(ugd, NULL);
974 /**********************************************************************
976 ***********************************************************************/
978 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
981 BT_DBG("UG_LAUNCH_PROFILING");
983 bt_ug_data *ugd = NULL;
988 ugd = calloc(1, sizeof(bt_ug_data));
992 ops->create = __on_create;
993 ops->start = __on_start;
994 ops->pause = __on_pause;
995 ops->resume = __on_resume;
996 ops->destroy = __on_destroy;
997 ops->message = __on_message;
998 ops->event = __on_event;
999 ops->key_event = __on_key_event;
1001 ops->opt = UG_OPT_INDICATOR_ENABLE;
1004 return BT_UG_ERROR_NONE;
1007 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
1023 UG_MODULE_API int setting_plugin_reset(app_control_h service, void *priv)
1030 ret = bt_initialize();
1032 if (ret != BT_ERROR_NONE) {
1033 BT_ERR("Fail to init BT %d", ret);
1037 ret = bt_adapter_reset();
1039 if (ret != BT_ERROR_NONE) {
1040 BT_ERR("Fail to reset adapter: %d", ret);
1044 ret = bt_deinitialize();
1046 if (ret != BT_ERROR_NONE)
1047 BT_ERR("Fail to deinit BT: %d", ret);
1053 void _bt_ug_destroy(void *data, void *result)
1057 bt_ug_data *ugd = NULL;
1059 BT_INFO("Destroy UG");
1061 ret_if(data == NULL);
1063 ugd = (bt_ug_data *)data;
1066 ug_send_result(ugd->ug, result);
1069 ret = ug_destroy_me(ugd->ug);
1072 BT_ERR("Fail to destroy me");
1077 #ifndef __TIZEN_OPEN__
1078 #ifdef TIZEN_REDWOOD
1080 static bt_setting_cfg_node_t s_cfg_node_array_bt[] = {
1081 {"IDS_BT_BODY_BLUETOOTH", NULL,
1082 "viewtype:frontpage;tab:first;keyword:IDS_BT_BODY_BLUETOOTH",
1083 Cfg_Item_Pos_Level0, 0, 0, Cfg_Item_View_Node_Toggle, NULL},
1084 {"IDS_BT_BODY_VISIBLE", NULL,
1085 "viewtype:frontpage;tab:first;keyword:IDS_BT_BODY_VISIBLE",
1086 Cfg_Item_Pos_Level0, 0, 0, BT_CFG_ITEM_VIEW_NODE, NULL},
1089 UG_MODULE_API int setting_plugin_search_init(app_control_h service,
1090 void *priv, char **applocale)
1093 BT_DBG("ug-bluetooth-efl DB search code: SETTING_SEARCH");
1095 Eina_List **pplist = NULL;
1097 int size = sizeof(s_cfg_node_array_bt)/sizeof(s_cfg_node_array_bt[0]);
1099 *applocale = strdup(PKGNAME);
1100 pplist = (Eina_List **)priv;
1102 for (i = 0; i < size; i++) {
1103 bt_setting_cfg_node_t *node =
1104 (bt_setting_cfg_node_t *)setting_plugin_search_item_add(
1105 s_cfg_node_array_bt[i].key_name,
1106 s_cfg_node_array_bt[i].ug_args,
1107 NULL, s_cfg_node_array_bt[i].item_type,
1108 s_cfg_node_array_bt[i].data);
1109 *pplist = eina_list_append(*pplist, node);
1115 /**************************************************************
1116 toggle state get/set function for "bluetooth status"
1117 ************************************************************/
1119 int get_display_ug_state(Cfg_Item_State *stat, void *data)
1124 int ret = vconf_get_int(VCONFKEY_BT_STATUS, &value);
1125 retvm_if(ret != 0, ret, "fail to get vconf key!");
1127 if (value == VCONFKEY_BT_STATUS_OFF)
1128 *stat = Cfg_Item_Off;
1130 *stat = Cfg_Item_On;
1137 int set_display_ug_state(Cfg_Item_State stat, void *item, void *data)
1143 if (stat == Cfg_Item_On)
1144 value = VCONFKEY_BT_STATUS_ON;
1146 value = VCONFKEY_BT_STATUS_OFF;
1148 ret = vconf_set_int(VCONFKEY_BT_STATUS, value);
1149 retvm_if(ret != 0, ret, "fail to set vconf key!");
1156 int set_display_ug_update_ui(Cfg_Item_State stat, void* data)
1165 cfg_func_table opt_tab_bluetooth = {
1166 .get_item_state = get_display_ug_state,
1167 .set_item_state = set_display_ug_state,
1168 .set_item_update_ui = set_display_ug_update_ui,
1171 UG_MODULE_API int setting_plugin_search_query_ops(char *str_id,
1175 BT_DBG(">> get tfunc operation via plugin-model 1");
1176 if (str_id && !g_strcmp0(str_id, _("IDS_BT_BODY_BLUETOOTH")))
1177 *tfunc_obj = (void*)&opt_tab_bluetooth;