4 * Copyright (c) 2013 Intel Corporation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include "bt-service-agent-notification.h"
23 error_to_string(notification_error_e error)
25 if (error == NOTIFICATION_ERROR_INVALID_DATA)
26 return "NOTIFICATION_ERROR_INVALID_DATA";
27 if (error == NOTIFICATION_ERROR_NO_MEMORY)
28 return "NOTIFICATION_ERROR_NO_MEMORY";
29 if (error == NOTIFICATION_ERROR_FROM_DB)
30 return "NOTIFICATION_ERROR_FROM_DB";
31 if (error == NOTIFICATION_ERROR_ALREADY_EXIST_ID)
32 return "NOTIFICATION_ERROR_ALREADY_EXIST_ID";
33 if (error == NOTIFICATION_ERROR_FROM_DBUS)
34 return "NOTIFICATION_ERROR_FROM_DBUS";
35 if (error == NOTIFICATION_ERROR_NOT_EXIST_ID)
36 return "NOTIFICATION_ERROR_NOT_EXIST_ID";
37 if (error == NOTIFICATION_ERROR_IO)
38 return "NOTIFICATION_ERROR_IO";
39 if (error == NOTIFICATION_ERROR_SERVICE_NOT_READY)
40 return "NOTIFICATION_ERROR_SERVICE_NOT_READY";
41 if (error == NOTIFICATION_ERROR_NONE)
42 return "NOTIFICATION_ERROR_NONE";
44 return "UNHANDLED ERROR";
48 __notification_set_text(notification_h noti, char *title, char *body)
50 notification_error_e err = NOTIFICATION_ERROR_NONE;
52 err = notification_set_text( noti, NOTIFICATION_TEXT_TYPE_TITLE,
54 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
55 if (err != NOTIFICATION_ERROR_NONE) {
56 BT_ERR("Unable to set notification title: %s", error_to_string(err));
60 err = notification_set_text( noti, NOTIFICATION_TEXT_TYPE_CONTENT,
62 NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
63 if (err != NOTIFICATION_ERROR_NONE) {
64 BT_ERR("Unable to set notification content: %s", error_to_string(err));
71 notification_launch(bundle * user_data)
74 const char *device_name = NULL;
75 const char *passkey = NULL;
76 const char *file = NULL;
77 const char *event_type = NULL;
81 notification_error_e err = NOTIFICATION_ERROR_NONE;
83 event_type = bundle_get_val(user_data, "event-type");
84 BT_DBG("create notification for '%s' event", event_type);
86 notif = notification_new(NOTIFICATION_TYPE_NOTI,
87 NOTIFICATION_GROUP_ID_NONE,
88 NOTIFICATION_PRIV_ID_NONE);
90 BT_ERR("Failed to create notification: %s", error_to_string(err));
94 err = notification_set_pkgname(notif, "bluetooth-frwk-bt-service");
95 if (err != NOTIFICATION_ERROR_NONE) {
96 BT_ERR("Unable to set pkgname: %s", error_to_string(err));
100 err = notification_set_image(notif, NOTIFICATION_IMAGE_TYPE_ICON, BT_ICON);
101 if (err != NOTIFICATION_ERROR_NONE) {
102 BT_ERR("Unable to set notification icon path: %s", error_to_string(err));
107 * Pass the full bundle to the notification
109 err = notification_set_execute_option(notif, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, user_data);
110 if (err != NOTIFICATION_ERROR_NONE) {
111 BT_ERR("Unable to set notification icon path: %s", error_to_string(err));
115 if(!strcasecmp(event_type, "pin-request")) {
116 device_name = (gchar*) bundle_get_val(user_data, "device-name");
118 title = g_strdup_printf("Bluetooth pairing request");
119 body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
121 ret = __notification_set_text(notif, title, body);
125 } else if (!strcasecmp(event_type, "passkey-confirm-request")){
126 device_name = (gchar*) bundle_get_val(user_data, "device-name");
127 passkey = (gchar*) bundle_get_val(user_data, "passkey");
129 title = g_strdup_printf("Bluetooth passkey confirm request");
130 body = g_strdup_printf("Confirm passkey is %s to pair with %s", passkey, device_name);
132 ret = __notification_set_text(notif, title, body);
136 } else if (!strcasecmp(event_type, "passkey-request")) {
137 device_name = (gchar*) bundle_get_val(user_data, "device-name");
139 title = g_strdup_printf("Bluetooth pairing request");
140 body = g_strdup_printf("Enter PIN to pair with %s (Try 0000 or 1234)", device_name);
142 ret = __notification_set_text(notif, title, body);
146 } else if (!strcasecmp(event_type, "passkey-display-request")) {
147 device_name = (gchar*) bundle_get_val(user_data, "device-name");
148 passkey = (gchar*) bundle_get_val(user_data, "passkey");
150 title = g_strdup_printf("Bluetooth passkey display request");
151 body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
153 ret = __notification_set_text(notif, title, body);
157 } else if (!strcasecmp(event_type, "authorize-request")) {
158 device_name = (gchar*) bundle_get_val(user_data, "device-name");
160 title = g_strdup_printf("Bluetooth authorize request");
161 body = g_strdup_printf("Allow %s to connect?", device_name);
163 ret = __notification_set_text(notif, title, body);
167 } else if (!strcasecmp(event_type, "app-confirm-request")) {
168 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
169 BT_DBG("app-confirm-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
171 } else if (!strcasecmp(event_type, "push-authorize-request")) {
172 file = (gchar*) bundle_get_val(user_data, "file");
173 device_name = (gchar*) bundle_get_val(user_data, "device-name");
175 title = g_strdup_printf("Bluetooth push authorize request");
176 body = g_strdup_printf("Receive %s from %s?", file, device_name);
178 ret = __notification_set_text(notif, title, body);
182 } else if (!strcasecmp(event_type, "confirm-overwrite-request")) {
183 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed*/
184 BT_DBG("confirm-overwrite-request even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
186 } else if (!strcasecmp(event_type, "keyboard-passkey-request")) {
187 device_name = (gchar*) bundle_get_val(user_data, "device-name");
188 passkey = (gchar*) bundle_get_val(user_data, "passkey");
190 title = g_strdup_printf("Bluetooth keyboard passkey request");
191 body = g_strdup_printf("Enter %s on %s to pair", passkey, device_name);
193 ret = __notification_set_text(notif, title, body);
197 } else if (!strcasecmp(event_type, "bt-information")) {
198 /* FIXME Seems to be an osp mechanism so not implemented to be confirmed */
199 BT_DBG("bt-information even_type seems to be an osp mechanism so not implemented in gnome environment; to be confirmed");
201 } else if (!strcasecmp(event_type, "exchange-request")) {
202 device_name = (gchar*) bundle_get_val(user_data, "device-name");
204 title = g_strdup_printf("Bluetooth exchange request");
205 body = g_strdup_printf("exchange-request from %s", device_name);
207 ret = __notification_set_text(notif, title, body);
210 } else if (!strcasecmp(event_type, "phonebook-request")) {
211 device_name = bundle_get_val(user_data, "device-name");
213 title = g_strdup_printf("Bluetooth phonebook request");
214 body = g_strdup_printf("Allow %s phonebook access", device_name);
216 ret = __notification_set_text(notif, title, body);
220 } else if (!strcasecmp(event_type, "message-request")) {
221 device_name = bundle_get_val(user_data, "device-name");
223 title = g_strdup_printf("Bluetooth keyboard passkey request");
224 body = g_strdup_printf("Allow %s to access messages?", device_name);
226 ret = __notification_set_text(notif, title, body);
234 err = notification_insert(notif, NULL);
235 if (err != NOTIFICATION_ERROR_NONE) {
236 BT_ERR("Unable to insert notification: %s\n", error_to_string(err));