2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing,
11 * software distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <appcore-efl.h>
21 #include <vconf-keys.h>
25 #include <bluetooth-api.h>
27 #include <linux/input.h>
29 #include "bt-syspopup.h"
31 static void __bluetooth_delete_input_view(struct bt_popup_appdata *ad);
32 static void __bluetooth_win_del(void *data);
34 static int __bluetooth_term(bundle *b, void *data)
36 BT_DBG("System-popup: terminate");
40 static int __bluetooth_timeout(bundle *b, void *data)
42 BT_DBG("System-popup: timeout");
46 syspopup_handler handler = {
47 .def_term_fn = __bluetooth_term,
48 .def_timeout_fn = __bluetooth_timeout
51 /* Cleanup objects to avoid mem-leak */
52 static void __bluetooth_cleanup(struct bt_popup_appdata *ad)
58 evas_object_del(ad->popup);
63 evas_object_del(ad->win_main);
67 if (ad->agent_proxy) {
68 g_object_unref(ad->agent_proxy);
69 ad->agent_proxy = NULL;
73 static void __bluetooth_notify_event(void)
77 BT_DBG("Notify event");
79 result = feedback_initialize();
80 if (result != FEEDBACK_ERROR_NONE) {
81 BT_ERR("feedback_initialize error : %d", result);
85 result = feedback_play(FEEDBACK_PATTERN_GENERAL);
86 BT_DBG("ret value : %d", result);
88 result = feedback_deinitialize();
89 if (result != FEEDBACK_ERROR_NONE) {
90 BT_DBG("feedback_initialize error : %d", result);
95 static void __bluetooth_parse_event(struct bt_popup_appdata *ad, const char *event_type)
97 if (!strcasecmp(event_type, "pin-request"))
98 ad->event_type = BT_EVENT_PIN_REQUEST;
99 else if (!strcasecmp(event_type, "passkey-confirm-request"))
100 ad->event_type = BT_EVENT_PASSKEY_CONFIRM_REQUEST;
101 else if (!strcasecmp(event_type, "passkey-request"))
102 ad->event_type = BT_EVENT_PASSKEY_REQUEST;
103 else if (!strcasecmp(event_type, "authorize-request"))
104 ad->event_type = BT_EVENT_AUTHORIZE_REQUEST;
105 else if (!strcasecmp(event_type, "app-confirm-request"))
106 ad->event_type = BT_EVENT_APP_CONFIRM_REQUEST;
107 else if (!strcasecmp(event_type, "push-authorize-request"))
108 ad->event_type = BT_EVENT_PUSH_AUTHORIZE_REQUEST;
109 else if (!strcasecmp(event_type, "confirm-overwrite-request"))
110 ad->event_type = BT_EVENT_CONFIRM_OVERWRITE_REQUEST;
111 else if (!strcasecmp(event_type, "keyboard-passkey-request"))
112 ad->event_type = BT_EVENT_KEYBOARD_PASSKEY_REQUEST;
113 else if (!strcasecmp(event_type, "bt-information"))
114 ad->event_type = BT_EVENT_INFORMATION;
115 else if (!strcasecmp(event_type, "exchange-request"))
116 ad->event_type = BT_EVENT_EXCHANGE_REQUEST;
117 else if (!strcasecmp(event_type, "phonebook-request"))
118 ad->event_type = BT_EVENT_PHONEBOOK_REQUEST;
119 else if (!strcasecmp(event_type, "message-request"))
120 ad->event_type = BT_EVENT_MESSAGE_REQUEST;
122 ad->event_type = 0x0000;
126 static void __bluetooth_request_to_cancel(void)
128 bluetooth_cancel_bonding();
131 static void __bluetooth_remove_all_event(struct bt_popup_appdata *ad)
133 switch (ad->event_type) {
134 case BT_EVENT_PIN_REQUEST:
136 dbus_g_proxy_call_no_reply(ad->agent_proxy,
138 G_TYPE_UINT, BT_AGENT_CANCEL,
139 G_TYPE_STRING, "", G_TYPE_INVALID,
145 case BT_EVENT_KEYBOARD_PASSKEY_REQUEST:
147 __bluetooth_request_to_cancel();
151 case BT_EVENT_PASSKEY_CONFIRM_REQUEST:
153 dbus_g_proxy_call_no_reply(ad->agent_proxy,
155 G_TYPE_UINT, BT_AGENT_CANCEL,
156 G_TYPE_INVALID, G_TYPE_INVALID);
160 case BT_EVENT_PASSKEY_REQUEST:
162 dbus_g_proxy_call_no_reply(ad->agent_proxy,
164 G_TYPE_UINT, BT_AGENT_CANCEL,
165 G_TYPE_STRING, "", G_TYPE_INVALID,
170 case BT_EVENT_PASSKEY_DISPLAY_REQUEST:
174 case BT_EVENT_AUTHORIZE_REQUEST:
176 dbus_g_proxy_call_no_reply(ad->agent_proxy,
178 G_TYPE_UINT, BT_AGENT_CANCEL,
179 G_TYPE_INVALID, G_TYPE_INVALID);
183 case BT_EVENT_APP_CONFIRM_REQUEST:
185 DBusMessage *msg = NULL;
188 msg = dbus_message_new_signal(
189 BT_SYS_POPUP_IPC_RESPONSE_OBJECT,
190 BT_SYS_POPUP_INTERFACE,
191 BT_SYS_POPUP_METHOD_RESPONSE);
193 /* For timeout rejection is sent to be handled in
197 dbus_message_append_args(msg,
198 DBUS_TYPE_INT32, &response,
201 e_dbus_message_send(ad->EDBusHandle,
202 msg, NULL, -1, NULL);
204 dbus_message_unref(msg);
208 case BT_EVENT_PUSH_AUTHORIZE_REQUEST:
209 case BT_EVENT_EXCHANGE_REQUEST:
211 dbus_g_proxy_call_no_reply(ad->obex_proxy,
213 G_TYPE_UINT, BT_AGENT_CANCEL,
214 G_TYPE_INVALID, G_TYPE_INVALID);
218 case BT_EVENT_CONFIRM_OVERWRITE_REQUEST:
220 dbus_g_proxy_call_no_reply(ad->obex_proxy,
222 G_TYPE_UINT, BT_AGENT_CANCEL,
223 G_TYPE_INVALID, G_TYPE_INVALID);
231 __bluetooth_win_del(ad);
234 static int __bluetooth_keydown_cb(void *data, int type, void *event_info)
236 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
237 Ecore_Event_Key *ev = event_info;
239 if (!g_strcmp0(ev->keyname, KEY_END) || !g_strcmp0(ev->keyname, KEY_SELECT)) {
240 BT_DBG("Key [%s]", ev->keyname);
241 /* remove_all_event(); */
243 if (!g_strcmp0(ev->keyname, KEY_END)) {
244 __bluetooth_remove_all_event(ad);
251 static int __bluetooth_request_timeout_cb(void *data)
253 struct bt_popup_appdata *ad;
258 ad = (struct bt_popup_appdata *)data;
260 BT_DBG("Request time out, Canceling reqeust");
262 /* Destory UI and timer */
264 ecore_timer_del(ad->timer);
268 __bluetooth_remove_all_event(ad);
272 static void __bluetooth_input_request_cb(void *data,
273 Evas_Object *obj, void *event_info)
275 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
276 const char *event = elm_object_text_get(obj);
278 char *input_text = NULL;
279 char *convert_input_text = NULL;
284 /* BT_EVENT_PIN_REQUEST / BT_EVENT_PASSKEY_REQUEST */
286 input_text = (char *)elm_entry_entry_get(ad->entry);
290 elm_entry_markup_to_utf8(input_text);
293 if (!g_strcmp0(event, BT_STR_OK))
298 if (convert_input_text == NULL)
301 BT_DBG("PIN/Passkey[%s] event[%d] response[%d]",
302 convert_input_text, ad->event_type, response);
306 if (ad->event_type == BT_EVENT_PIN_REQUEST) {
307 dbus_g_proxy_call_no_reply(ad->agent_proxy,
309 G_TYPE_UINT, BT_AGENT_ACCEPT,
315 dbus_g_proxy_call_no_reply(ad->agent_proxy,
317 G_TYPE_UINT, BT_AGENT_ACCEPT,
324 BT_DBG("Cancel case");
325 if (ad->event_type == BT_EVENT_PIN_REQUEST) {
326 dbus_g_proxy_call_no_reply(ad->agent_proxy,
328 G_TYPE_UINT, BT_AGENT_CANCEL,
333 dbus_g_proxy_call_no_reply(ad->agent_proxy,
335 G_TYPE_UINT, BT_AGENT_CANCEL,
342 __bluetooth_delete_input_view(ad);
344 free(convert_input_text);
346 __bluetooth_win_del(ad);
349 static void __bluetooth_input_cancel_cb(void *data,
350 Evas_Object *obj, void *event_info)
352 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
354 bluetooth_cancel_bonding();
356 __bluetooth_win_del(ad);
359 static void __bluetooth_passkey_confirm_cb(void *data,
360 Evas_Object *obj, void *event_info)
362 if (obj == NULL || data == NULL)
365 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
366 const char *event = elm_object_text_get(obj);
368 if (!g_strcmp0(event, BT_STR_OK)) {
369 dbus_g_proxy_call_no_reply(ad->agent_proxy, "ReplyConfirmation",
370 G_TYPE_UINT, BT_AGENT_ACCEPT,
371 G_TYPE_INVALID, G_TYPE_INVALID);
373 dbus_g_proxy_call_no_reply(ad->agent_proxy, "ReplyConfirmation",
374 G_TYPE_UINT, BT_AGENT_CANCEL,
375 G_TYPE_INVALID, G_TYPE_INVALID);
378 evas_object_del(obj);
380 __bluetooth_win_del(ad);
383 static int __bluetooth_init_app_signal(struct bt_popup_appdata *ad)
389 ad->EDBusHandle = e_dbus_bus_get(DBUS_BUS_SYSTEM);
390 if (!ad->EDBusHandle) {
391 BT_ERR("e_dbus_bus_get failed \n ");
394 BT_DBG("e_dbus_bus_get success \n ");
395 e_dbus_request_name(ad->EDBusHandle,
396 BT_SYS_POPUP_IPC_NAME, 0, NULL, NULL);
401 static void __bluetooth_app_confirm_cb(void *data,
402 Evas_Object *obj, void *event_info)
404 BT_DBG("__bluetooth_app_confirm_cb ");
405 if (obj == NULL || data == NULL)
408 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
409 const char *event = elm_object_text_get(obj);
411 DBusMessage *msg = NULL;
414 msg = dbus_message_new_signal(BT_SYS_POPUP_IPC_RESPONSE_OBJECT,
415 BT_SYS_POPUP_INTERFACE,
416 BT_SYS_POPUP_METHOD_RESPONSE);
418 if (!g_strcmp0(event, BT_STR_YES) || !g_strcmp0(event, BT_STR_OK))
423 dbus_message_append_args(msg,
424 DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
426 e_dbus_message_send(ad->EDBusHandle, msg, NULL, -1, NULL);
427 dbus_message_unref(msg);
429 evas_object_del(obj);
431 __bluetooth_win_del(ad);
434 static void __bluetooth_authorization_request_cb(void *data,
438 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
439 if (obj == NULL || ad == NULL)
442 const char *event = elm_object_text_get(obj);
444 if (!g_strcmp0(event, BT_STR_YES)) {
445 dbus_g_proxy_call_no_reply(ad->agent_proxy, "ReplyAuthorize",
446 G_TYPE_UINT, BT_AGENT_ACCEPT,
447 G_TYPE_INVALID, G_TYPE_INVALID);
449 dbus_g_proxy_call_no_reply(ad->agent_proxy, "ReplyAuthorize",
450 G_TYPE_UINT, BT_AGENT_CANCEL,
451 G_TYPE_INVALID, G_TYPE_INVALID);
454 __bluetooth_win_del(ad);
457 static void __bluetooth_push_authorization_request_cb(void *data,
461 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
462 if (obj == NULL || ad == NULL)
465 const char *event = elm_object_text_get(obj);
467 if (!g_strcmp0(event, BT_STR_YES))
468 dbus_g_proxy_call_no_reply(ad->obex_proxy, "ReplyAuthorize",
469 G_TYPE_UINT, BT_AGENT_ACCEPT,
470 G_TYPE_INVALID, G_TYPE_INVALID);
472 dbus_g_proxy_call_no_reply(ad->obex_proxy, "ReplyAuthorize",
473 G_TYPE_UINT, BT_AGENT_CANCEL,
474 G_TYPE_INVALID, G_TYPE_INVALID);
476 __bluetooth_win_del(ad);
479 static void __bluetooth_ime_hide(void)
481 Ecore_IMF_Context *imf_context = NULL;
482 imf_context = ecore_imf_context_add(ecore_imf_context_default_id_get());
484 ecore_imf_context_input_panel_hide(imf_context);
487 static void __bluetooth_entry_change_cb(void *data, Evas_Object *obj,
490 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
491 char *input_text = NULL;
492 char *convert_input_text = NULL;
493 char *output_text = NULL;
496 input_text = (char *)elm_entry_entry_get(obj);
499 convert_input_text = elm_entry_markup_to_utf8(input_text);
500 if (convert_input_text) {
501 text_length = strlen(convert_input_text);
503 if (text_length == 0) {
504 elm_object_disabled_set(ad->edit_field_save_btn,
506 elm_object_signal_emit(ad->editfield,
507 "elm,state,eraser,hide",
510 elm_object_disabled_set(ad->edit_field_save_btn,
512 elm_object_signal_emit(ad->editfield,
513 "elm,state,eraser,show",
517 if (ad->event_type == BT_EVENT_PASSKEY_REQUEST) {
518 if (text_length > BT_PK_MLEN) {
519 text_length = BT_PK_MLEN;
520 convert_input_text[BT_PK_MLEN] = '\0';
522 elm_entry_utf8_to_markup
523 (convert_input_text);
525 elm_entry_entry_set(obj, output_text);
526 elm_entry_cursor_end_set(obj);
530 if (text_length > BT_PIN_MLEN) {
531 text_length = BT_PIN_MLEN;
532 convert_input_text[BT_PIN_MLEN] = '\0';
534 elm_entry_utf8_to_markup
535 (convert_input_text);
537 elm_entry_entry_set(obj, output_text);
538 elm_entry_cursor_end_set(obj);
542 free(convert_input_text);
547 static void __bluetooth_entry_focused_cb(void *data, Evas_Object *obj,
550 if (!elm_entry_is_empty(obj))
551 elm_object_signal_emit(data, "elm,state,eraser,show", "elm");
553 elm_object_signal_emit(data, "elm,state,guidetext,hide", "elm");
556 static void __bluetooth_entry_unfocused_cb(void *data, Evas_Object *obj,
559 if (elm_entry_is_empty(obj))
560 elm_object_signal_emit(data, "elm,state,guidetext,show", "elm");
562 elm_object_signal_emit(data, "elm,state,eraser,hide", "elm");
565 static void __bluetooth_eraser_clicked_cb(void* data, Evas_Object* obj,
566 const char* emission, const char* source)
568 elm_entry_entry_set(data, "");
571 static void __bluetooth_check_chagned_cb(void *data, Evas_Object *obj,
574 Eina_Bool state = EINA_FALSE;
579 state = elm_check_state_get(obj);
580 elm_entry_password_set(data, !state);
583 static void __bluetooth_draw_popup(struct bt_popup_appdata *ad,
584 const char *title, char *btn1_text,
585 char *btn2_text, void (*func) (void *data,
586 Evas_Object *obj, void *event_info))
588 char temp_str[BT_TITLE_STR_MAX_LEN+BT_TEXT_EXTRA_LEN] = { 0 };
592 BT_DBG("__bluetooth_draw_popup");
594 ad->popup = elm_popup_add(ad->win_main);
595 evas_object_size_hint_weight_set(ad->popup, EVAS_HINT_EXPAND,
598 elm_object_style_set(ad->popup, "transparent");
601 snprintf(temp_str, BT_TITLE_STR_MAX_LEN+BT_TEXT_EXTRA_LEN,
602 "<align=center>%s</align>", title);
603 elm_object_text_set(ad->popup, temp_str);
606 if ((btn1_text != NULL) && (btn2_text != NULL)) {
607 btn1 = elm_button_add(ad->popup);
608 elm_object_style_set(btn1, "popup_button/default");
609 elm_object_text_set(btn1, btn1_text);
610 elm_object_part_content_set(ad->popup, "button1", btn1);
611 evas_object_smart_callback_add(btn1, "clicked", func, ad);
613 btn2 = elm_button_add(ad->popup);
614 elm_object_style_set(btn2, "popup_button/default");
615 elm_object_text_set(btn2, btn2_text);
616 elm_object_part_content_set(ad->popup, "button2", btn2);
617 evas_object_smart_callback_add(btn2, "clicked", func, ad);
618 } else if (btn1_text != NULL) {
619 btn1 = elm_button_add(ad->popup);
620 elm_object_style_set(btn1, "popup_button/default");
621 elm_object_text_set(btn1, btn1_text);
622 elm_object_part_content_set(ad->popup, "button1", btn1);
623 evas_object_smart_callback_add(btn1, "clicked", func, ad);
626 evas_object_show(ad->popup);
627 evas_object_show(ad->win_main);
629 BT_DBG("__bluetooth_draw_popup END");
632 static void __bluetooth_draw_input_view(struct bt_popup_appdata *ad,
633 const char *title, const char *text,
635 (void *data, Evas_Object *obj, void *event_info))
637 Evas_Object *conformant = NULL;
638 Evas_Object *content = NULL;
639 Evas_Object *layout = NULL;
640 Evas_Object *passpopup = NULL;
641 Evas_Object *label = NULL;
642 Evas_Object *editfield = NULL;
643 Evas_Object *entry = NULL;
644 Evas_Object *check = NULL;
645 Evas_Object *l_button = NULL;
646 Evas_Object *r_button = NULL;
648 if (ad == NULL || ad->win_main == NULL) {
649 BT_ERR("Invalid parameter");
653 evas_object_show(ad->win_main);
655 conformant = elm_conformant_add(ad->win_main);
656 if (conformant == NULL) {
657 BT_ERR("conformant is NULL");
660 ad->popup = conformant;
662 elm_win_conformant_set(ad->win_main, EINA_TRUE);
663 elm_win_resize_object_add(ad->win_main, conformant);
664 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
665 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
666 evas_object_show(conformant);
668 content = elm_layout_add(conformant);
669 elm_object_content_set(conformant, content);
671 passpopup = elm_popup_add(content);
672 elm_object_part_text_set(passpopup, "title,text", title);
674 elm_object_style_set(passpopup, "transparent");
676 layout = elm_layout_add(passpopup);
677 elm_layout_file_set(layout, CUSTOM_POPUP_PATH, "popup_checkview_image");
678 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
680 label = elm_label_add(passpopup);
681 elm_object_style_set(label, "popup/default");
682 elm_label_line_wrap_set(label, ELM_WRAP_CHAR);
683 elm_object_text_set(label, text);
684 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
685 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
686 evas_object_show(label);
688 editfield = elm_layout_add(passpopup);
689 elm_layout_theme_set(editfield, "layout", "editfield", "default");
690 evas_object_size_hint_weight_set(editfield, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
691 evas_object_size_hint_align_set(editfield, EVAS_HINT_FILL, EVAS_HINT_FILL);
692 ad->editfield = editfield;
694 entry = elm_entry_add(passpopup);
695 elm_entry_single_line_set(entry, EINA_TRUE);
696 elm_entry_scrollable_set(entry, EINA_TRUE);
697 elm_entry_prediction_allow_set(entry, EINA_FALSE);
698 elm_entry_password_set(entry, TRUE);
699 elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
700 elm_object_part_content_set(editfield, "elm.swallow.content", entry);
703 evas_object_smart_callback_add(entry, "changed",
704 __bluetooth_entry_change_cb,
707 evas_object_smart_callback_add(entry, "focused",
708 __bluetooth_entry_focused_cb,
711 evas_object_smart_callback_add(entry, "unfocused",
712 __bluetooth_entry_unfocused_cb,
715 elm_object_signal_callback_add(editfield, "elm,eraser,clicked", "elm",
716 (Edje_Signal_Cb)__bluetooth_eraser_clicked_cb,
719 evas_object_show(entry);
720 evas_object_show(editfield);
722 check = elm_check_add(passpopup);
723 elm_object_text_set(check, BT_STR_SHOW_PASSWORD);
724 elm_object_focus_allow_set(check, EINA_FALSE);
725 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND,
727 evas_object_size_hint_align_set(check, EVAS_HINT_FILL,
729 evas_object_smart_callback_add(check, "changed",
730 __bluetooth_check_chagned_cb, entry);
731 evas_object_show(check);
733 l_button = elm_button_add(ad->win_main);
734 elm_object_style_set(l_button, "popup_button/default");
735 elm_object_text_set(l_button, BT_STR_OK);
736 elm_object_part_content_set(passpopup, "button1", l_button);
737 evas_object_smart_callback_add(l_button, "clicked", func, ad);
738 elm_object_disabled_set(l_button, EINA_TRUE);
740 ad->edit_field_save_btn = l_button;
742 r_button = elm_button_add(ad->win_main);
743 elm_object_style_set(r_button, "popup_button/default");
744 elm_object_text_set(r_button, BT_STR_CANCEL);
745 elm_object_part_content_set(passpopup, "button2", r_button);
746 evas_object_smart_callback_add(r_button, "clicked", func, ad);
748 elm_object_part_content_set(layout, "elm.swallow.content", label);
749 elm_object_part_content_set(layout, "elm.swallow.entry", editfield);
750 elm_object_part_content_set(layout, "elm.swallow.end", check);
752 evas_object_show(layout);
753 evas_object_show(content);
754 evas_object_show(passpopup);
755 elm_object_content_set(passpopup, layout);
756 elm_object_focus_set(entry, EINA_TRUE);
759 static void __bluetooth_delete_input_view(struct bt_popup_appdata *ad)
761 __bluetooth_ime_hide();
764 static DBusGProxy* __bluetooth_create_agent_proxy(DBusGConnection *conn,
767 return dbus_g_proxy_new_for_name(conn, "org.projectx.bt", path,
771 /* AUL bundle handler */
772 static int __bluetooth_launch_handler(struct bt_popup_appdata *ad,
773 void *reset_data, const char *event_type)
775 bundle *kb = (bundle *) reset_data;
776 char view_title[BT_TITLE_STR_MAX_LEN] = { 0 };
777 char text[BT_GLOBALIZATION_STR_LENGTH] = { 0 };
779 const char *device_name = NULL;
780 const char *passkey = NULL;
781 const char *file = NULL;
782 const char *agent_path;
783 char *conv_str = NULL;
785 BT_DBG("__bluetooth_launch_handler");
787 if (!reset_data || !event_type)
790 if (!strcasecmp(event_type, "pin-request")) {
791 device_name = bundle_get_val(kb, "device-name");
792 agent_path = bundle_get_val(kb, "agent-path");
794 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
795 if (!ad->agent_proxy)
799 conv_str = elm_entry_utf8_to_markup(device_name);
801 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
802 "%s", BT_STR_BLUETOOTH_PAIRING_REQUEST);
804 snprintf(text, BT_GLOBALIZATION_STR_LENGTH,
805 BT_STR_ENTER_PIN_TO_PAIR, conv_str);
810 /* Request user inputted PIN for basic pairing */
811 __bluetooth_draw_input_view(ad, view_title, text,
812 __bluetooth_input_request_cb);
813 } else if (!strcasecmp(event_type, "passkey-confirm-request")) {
814 device_name = bundle_get_val(kb, "device-name");
815 passkey = bundle_get_val(kb, "passkey");
816 agent_path = bundle_get_val(kb, "agent-path");
818 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
819 if (!ad->agent_proxy)
822 if (device_name && passkey) {
823 conv_str = elm_entry_utf8_to_markup(device_name);
825 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
826 BT_STR_CONFIRM_PASSKEY_PS_TO_PAIR_WITH_PS,
829 BT_DBG("title: %s", view_title);
834 __bluetooth_draw_popup(ad, view_title,
835 BT_STR_OK, BT_STR_CANCEL,
836 __bluetooth_passkey_confirm_cb);
838 timeout = BT_ERROR_TIMEOUT;
840 } else if (!strcasecmp(event_type, "passkey-request")) {
841 const char *device_name = NULL;
843 device_name = bundle_get_val(kb, "device-name");
844 agent_path = bundle_get_val(kb, "agent-path");
846 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
847 if (!ad->agent_proxy)
851 conv_str = elm_entry_utf8_to_markup(device_name);
853 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
854 "%s", BT_STR_BLUETOOTH_PAIRING_REQUEST);
856 snprintf(text, BT_GLOBALIZATION_STR_LENGTH,
857 BT_STR_ENTER_PIN_TO_PAIR, conv_str);
862 /* Request user inputted Passkey for basic pairing */
863 __bluetooth_draw_input_view(ad, view_title, text,
864 __bluetooth_input_request_cb);
866 } else if (!strcasecmp(event_type, "passkey-display-request")) {
867 device_name = bundle_get_val(kb, "device-name");
868 passkey = bundle_get_val(kb, "passkey");
870 if (device_name && passkey) {
871 conv_str = elm_entry_utf8_to_markup(device_name);
873 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
874 BT_STR_ENTER_PS_ON_PS_TO_PAIR, passkey, conv_str);
876 BT_DBG("title: %s", view_title);
881 __bluetooth_draw_popup(ad, view_title,
883 __bluetooth_input_cancel_cb);
885 timeout = BT_ERROR_TIMEOUT;
887 } else if (!strcasecmp(event_type, "authorize-request")) {
888 timeout = BT_AUTHORIZATION_TIMEOUT;
890 device_name = bundle_get_val(kb, "device-name");
891 agent_path = bundle_get_val(kb, "agent-path");
893 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
894 if (!ad->agent_proxy)
898 conv_str = elm_entry_utf8_to_markup(device_name);
900 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
901 BT_STR_ALLOW_PS_TO_CONNECT_Q, conv_str);
906 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
907 __bluetooth_authorization_request_cb);
908 } else if (!strcasecmp(event_type, "app-confirm-request")) {
909 BT_DBG("app-confirm-request");
910 timeout = BT_AUTHORIZATION_TIMEOUT;
912 const char *title = NULL;
913 const char *type = NULL;
915 title = bundle_get_val(kb, "title");
916 type = bundle_get_val(kb, "type");
921 if (strcasecmp(type, "twobtn") == 0) {
922 __bluetooth_draw_popup(ad, title, BT_STR_YES, BT_STR_NO,
923 __bluetooth_app_confirm_cb);
924 } else if (strcasecmp(type, "onebtn") == 0) {
925 timeout = BT_NOTIFICATION_TIMEOUT;
926 __bluetooth_draw_popup(ad, title, BT_STR_YES, NULL,
927 __bluetooth_app_confirm_cb);
928 } else if (strcasecmp(type, "none") == 0) {
929 timeout = BT_NOTIFICATION_TIMEOUT;
930 __bluetooth_draw_popup(ad, title, NULL, NULL,
931 __bluetooth_app_confirm_cb);
933 } else if (!strcasecmp(event_type, "push-authorize-request")) {
934 timeout = BT_AUTHORIZATION_TIMEOUT;
936 device_name = bundle_get_val(kb, "device-name");
937 file = bundle_get_val(kb, "file");
940 conv_str = elm_entry_utf8_to_markup(device_name);
942 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
943 BT_STR_RECEIVE_PS_FROM_PS_Q, file, conv_str);
948 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
949 __bluetooth_push_authorization_request_cb);
950 } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
951 timeout = BT_AUTHORIZATION_TIMEOUT;
953 file = bundle_get_val(kb, "file");
955 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
956 BT_STR_OVERWRITE_FILE_Q, file);
958 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
959 __bluetooth_app_confirm_cb);
960 } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
961 device_name = bundle_get_val(kb, "device-name");
962 passkey = bundle_get_val(kb, "passkey");
964 if (device_name && passkey) {
965 conv_str = elm_entry_utf8_to_markup(device_name);
967 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
968 BT_STR_ENTER_PS_ON_PS_TO_PAIR, passkey, conv_str);
970 BT_DBG("title: %s", view_title);
975 __bluetooth_draw_popup(ad, view_title,
977 __bluetooth_input_cancel_cb);
979 timeout = BT_ERROR_TIMEOUT;
981 } else if (!strcasecmp(event_type, "bt-information")) {
982 BT_DBG("bt-information");
983 timeout = BT_NOTIFICATION_TIMEOUT;
985 const char *title = NULL;
986 const char *type = NULL;
988 title = bundle_get_val(kb, "title");
989 type = bundle_get_val(kb, "type");
992 if (strlen(title) > 255)
997 if (strcasecmp(type, "onebtn") == 0) {
998 __bluetooth_draw_popup(ad, title, BT_STR_OK, NULL,
999 __bluetooth_app_confirm_cb);
1000 } else if (strcasecmp(type, "none") == 0) {
1001 __bluetooth_draw_popup(ad, title, NULL, NULL,
1002 __bluetooth_app_confirm_cb);
1004 } else if (!strcasecmp(event_type, "exchange-request")) {
1005 timeout = BT_AUTHORIZATION_TIMEOUT;
1007 device_name = bundle_get_val(kb, "device-name");
1008 agent_path = bundle_get_val(kb, "agent-path");
1010 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
1011 if (!ad->agent_proxy)
1015 conv_str = elm_entry_utf8_to_markup(device_name);
1017 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
1018 BT_STR_EXCHANGE_OBJECT_WITH_PS_Q, conv_str);
1023 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
1024 __bluetooth_authorization_request_cb);
1025 } else if (!strcasecmp(event_type, "phonebook-request")) {
1026 timeout = BT_AUTHORIZATION_TIMEOUT;
1028 device_name = bundle_get_val(kb, "device-name");
1029 agent_path = bundle_get_val(kb, "agent-path");
1031 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
1032 if (!ad->agent_proxy)
1036 conv_str = elm_entry_utf8_to_markup(device_name);
1038 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
1039 BT_STR_ALLOW_PS_PHONEBOOK_ACCESS_Q, conv_str);
1044 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
1045 __bluetooth_authorization_request_cb);
1046 } else if (!strcasecmp(event_type, "message-request")) {
1047 timeout = BT_AUTHORIZATION_TIMEOUT;
1049 device_name = bundle_get_val(kb, "device-name");
1050 agent_path = bundle_get_val(kb, "agent-path");
1052 ad->agent_proxy = __bluetooth_create_agent_proxy(ad->conn, agent_path);
1053 if (!ad->agent_proxy)
1057 conv_str = elm_entry_utf8_to_markup(device_name);
1059 snprintf(view_title, BT_TITLE_STR_MAX_LEN,
1060 BT_STR_ALLOW_PS_TO_ACCESS_MESSAGES_Q, conv_str);
1065 __bluetooth_draw_popup(ad, view_title, BT_STR_YES, BT_STR_NO,
1066 __bluetooth_authorization_request_cb);
1071 if (ad->event_type != BT_EVENT_FILE_RECEIVED && timeout != 0) {
1072 ad->timer = ecore_timer_add(timeout, (Ecore_Task_Cb)
1073 __bluetooth_request_timeout_cb,
1080 static void __bluetooth_win_del(void *data)
1082 struct bt_popup_appdata *ad = (struct bt_popup_appdata *)data;
1084 __bluetooth_cleanup(ad);
1089 static Evas_Object *__bluetooth_create_win(const char *name)
1093 eo = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
1095 elm_win_title_set(eo, name);
1096 elm_win_borderless_set(eo, EINA_TRUE);
1102 static void __bluetooth_session_init(struct bt_popup_appdata *ad)
1104 DBusGConnection *conn = NULL;
1109 conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
1112 BT_ERR("ERROR: Can't get on system bus [%s]",
1120 ad->obex_proxy = dbus_g_proxy_new_for_name(conn,
1121 "org.bluez.frwk_agent",
1122 "/org/obex/ops_agent",
1123 "org.openobex.Agent");
1124 if (!ad->obex_proxy)
1125 BT_ERR("Could not create obex dbus proxy");
1127 if (!__bluetooth_init_app_signal(ad))
1128 BT_ERR("__bt_syspopup_init_app_signal failed");
1131 static int __bluetooth_create(void *data)
1133 struct bt_popup_appdata *ad = data;
1134 Evas_Object *win = NULL;
1136 BT_DBG("__bluetooth_create() start.\n");
1139 win = __bluetooth_create_win(PACKAGE);
1144 /* init internationalization */
1145 if (appcore_set_i18n(BT_COMMON_PKG, BT_COMMON_RES) < 0)
1149 ad->event_handle = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
1150 (Ecore_Event_Handler_Cb)
1151 __bluetooth_keydown_cb,
1154 __bluetooth_session_init(ad);
1159 static int __bluetooth_terminate(void *data)
1161 struct bt_popup_appdata *ad = data;
1163 __bluetooth_ime_hide();
1166 dbus_g_connection_unref(ad->conn);
1170 if (ad->event_handle)
1171 ecore_event_handler_del(ad->event_handle);
1174 evas_object_del(ad->popup);
1177 evas_object_del(ad->win_main);
1180 ad->win_main = NULL;
1185 static int __bluetooth_pause(void *data)
1191 static int __bluetooth_resume(void *data)
1197 static int __bluetooth_reset(bundle *b, void *data)
1199 struct bt_popup_appdata *ad = data;
1200 const char *event_type = NULL;
1203 BT_DBG("__bluetooth_reset()\n");
1206 BT_ERR("App data is NULL\n");
1211 event_type = bundle_get_val(b, "event-type");
1213 if (event_type != NULL) {
1214 if (!strcasecmp(event_type, "terminate")) {
1215 __bluetooth_win_del(ad);
1219 if (syspopup_has_popup(b)) {
1220 /* Destroy the existing popup*/
1221 __bluetooth_cleanup(ad);
1223 ad->win_main = __bluetooth_create_win(PACKAGE);
1224 if (ad->win_main == NULL)
1228 __bluetooth_parse_event(ad, event_type);
1230 elm_win_alpha_set(ad->win_main, EINA_TRUE);
1232 ret = syspopup_create(b, &handler, ad->win_main, ad);
1234 BT_ERR("syspopup_create err");
1235 __bluetooth_remove_all_event(ad);
1237 ret = __bluetooth_launch_handler(ad,
1241 __bluetooth_remove_all_event(ad);
1243 __bluetooth_notify_event();
1245 /* Change LCD brightness */
1246 ret = pm_change_state(LCD_NORMAL);
1248 BT_ERR("Fail to change LCD");
1251 BT_ERR("event type is NULL \n");
1257 EXPORT int main(int argc, char *argv[])
1259 struct bt_popup_appdata ad;
1260 struct appcore_ops ops = {
1261 .create = __bluetooth_create,
1262 .terminate = __bluetooth_terminate,
1263 .pause = __bluetooth_pause,
1264 .resume = __bluetooth_resume,
1265 .reset = __bluetooth_reset,
1268 memset(&ad, 0x0, sizeof(struct bt_popup_appdata));
1271 return appcore_efl_main(PACKAGE, &argc, &argv, &ops);