2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * 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.
22 #include <syspopup_caller.h>
24 #include <bundle_internal.h>
27 #include "bluetooth-api.h"
29 #define BT_AGENT_SYSPOPUP_MAX_ATTEMPT 3
30 #define BT_MAX_EVENT_STR_LENGTH 50
31 #define BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
33 #ifdef TIZEN_FEATURE_BT_DPM
34 int bt_launch_dpm_popup(char *mode)
40 retv_if(b == NULL, BLUETOOTH_ERROR_INTERNAL);
42 bundle_add(b, "mode", mode);
44 ret = syspopup_launch(BT_DPM_SYSPOPUP, b);
47 BT_ERR("Popup launch failed: %d\n", ret);
55 static gboolean _bt_syspopup_timer_cb(gpointer user_data)
59 retv_if(user_data == NULL, FALSE);
61 b = (bundle *)user_data;
63 ret = syspopup_launch("bt-syspopup", b);
65 BT_ERR("Sorry!! Cannot launch popup return = %d, Retrying...", ret);
67 BT_DBG("Hurray!!! Finally Popup launched");
70 return (ret < 0) ? TRUE : FALSE;
74 static gboolean _bt_agent_system_popup_timer_cb(gpointer user_data)
77 static int retry_count;
78 bundle *b = (bundle *)user_data;
79 retv_if(user_data == NULL, FALSE);
83 ret = syspopup_launch("bt-syspopup", b);
85 BT_ERR("Sorry! Can't launch popup, ret=%d, Re-try[%d] time..",
87 if (retry_count >= BT_AGENT_SYSPOPUP_MAX_ATTEMPT) {
88 BT_ERR("Sorry!! Max retry %d reached", retry_count);
94 BT_DBG("Hurray!! Finally Popup launched");
99 return (ret < 0) ? TRUE : FALSE;
102 int bt_launch_system_popup(bt_agent_event_type_t event_type,
103 const char *device_name,
104 const unsigned char *auth_info,
106 const char *filename,
107 const char *agent_path)
111 char event_str[BT_MAX_EVENT_STR_LENGTH + 1];
115 BT_ERR("Launching system popup failed");
119 bundle_add(b, "device-name", device_name);
120 bundle_add(b, "auth-info", (const char *)auth_info);
121 bundle_add(b, "passkey", passkey);
122 bundle_add(b, "file", filename);
123 bundle_add(b, "agent-path", agent_path);
125 switch (event_type) {
126 case BT_AGENT_EVENT_PIN_REQUEST:
127 g_strlcpy(event_str, "pin-request", sizeof(event_str));
130 case BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST:
131 g_strlcpy(event_str, "passkey-confirm-request",
135 case BT_AGENT_EVENT_PASSKEY_REQUEST:
136 g_strlcpy(event_str, "passkey-request", sizeof(event_str));
139 case BT_AGENT_EVENT_PASSKEY_DISPLAY_REQUEST:
140 g_strlcpy(event_str, "passkey-display-request",
144 case BT_AGENT_EVENT_AUTHORIZE_REQUEST:
145 g_strlcpy(event_str, "authorize-request",
149 case BT_AGENT_EVENT_CONFIRM_MODE_REQUEST:
150 g_strlcpy(event_str, "confirm-mode-request",
154 case BT_AGENT_EVENT_FILE_RECEIVED:
155 g_strlcpy(event_str, "file-received", sizeof(event_str));
158 case BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST:
159 g_strlcpy(event_str, "keyboard-passkey-request",
163 case BT_AGENT_EVENT_TERMINATE:
164 g_strlcpy(event_str, "terminate", sizeof(event_str));
167 case BT_AGENT_EVENT_EXCHANGE_REQUEST:
168 g_strlcpy(event_str, "exchange-request", sizeof(event_str));
171 case BT_AGENT_EVENT_PBAP_REQUEST:
172 g_strlcpy(event_str, "phonebook-request", sizeof(event_str));
175 case BT_AGENT_EVENT_MAP_REQUEST:
176 g_strlcpy(event_str, "message-request", sizeof(event_str));
179 case BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE:
180 g_strlcpy(event_str, "remote-legacy-pair-failed", sizeof(event_str));
184 BT_ERR("Invalid event type");
190 bundle_add(b, "event-type", event_str);
192 ret = syspopup_launch("bt-syspopup", b);
194 BT_ERR("Popup launch failed...retry %d", ret);
196 g_timeout_add(BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS,
197 (GSourceFunc)_bt_agent_system_popup_timer_cb, b);
202 BT_INFO("_bt_agent_launch_system_popup");
206 gboolean bt_launch_unable_to_pairing_syspopup(int result)
216 bundle_add(b, "event-type", "unable-to-pairing");
218 if (result == BLUETOOTH_ERROR_TIMEOUT)
219 bundle_add(b, "error", "timeout");
220 else if (result == BLUETOOTH_ERROR_AUTHENTICATION_FAILED)
221 bundle_add(b, "error", "authfailed");
223 bundle_add(b, "error", "error");
225 ret = syspopup_launch("bt-syspopup", b);
227 BT_ERR("Popup launch failed...retry %d \n", ret);
228 g_timeout_add(200, (GSourceFunc) _bt_syspopup_timer_cb,
239 void bt_destroy_popup_all(void)
241 syspopup_destroy_all();
245 extern struct bluetooth_headed_plugin_t headed_plugin
246 __attribute__ ((visibility("default")));
247 struct bluetooth_headed_plugin_t headed_plugin = {
248 #ifdef TIZEN_FEATURE_BT_DPM
253 bt_launch_system_popup,
254 bt_destroy_popup_all,
255 bt_launch_unable_to_pairing_syspopup