3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <dbus/dbus.h>
20 #include <dbus/dbus-glib.h>
21 #include <dbus/dbus-glib-lowlevel.h>
24 #include <notification.h>
25 #include <bluetooth.h>
27 #include "mobileap_softap.h"
28 #include "mobileap_notification.h"
30 #define MH_NOTI_LAUNCH_PKGNAME "setting-mobileap-efl"
31 #define MH_NOTI_CALLER_PKGNAME "mobileap-agent"
32 #define MH_LOCALE_DOMAIN "ug-setting-mobileap-efl"
33 #define MH_LOCALE_DIR "/usr/ug/res/locale"
36 static int connected_noti_id = 0;
37 static int timeout_noti_id = 0;
39 static int __create_status_noti(const char *content)
42 return MOBILE_AP_ERROR_INVALID_PARAM;
44 notification_error_e ret;
46 ret = notification_status_message_post(content);
47 if (ret != NOTIFICATION_ERROR_NONE) {
48 ERR("notification_status_message_post() is failed : %d\n", ret);
49 return MOBILE_AP_ERROR_INTERNAL;
52 return MOBILE_AP_ERROR_NONE;
55 int _create_timeout_noti(const char *icon_path)
59 notification_h noti = NULL;
60 notification_error_e ret = NOTIFICATION_ERROR_NONE;
61 char *old_icon_path = NULL;
62 char *general_icon_path = NULL;
64 if (timeout_noti_id) {
65 noti = notification_load(MH_NOTI_CALLER_PKGNAME, timeout_noti_id);
67 DBG("Notification can be deleted already\n");
69 ret = notification_get_image(noti,
70 NOTIFICATION_IMAGE_TYPE_ICON, &old_icon_path);
71 if (ret == NOTIFICATION_ERROR_NONE) {
72 if (g_strcmp0(icon_path, old_icon_path))
73 general_icon_path = MH_NOTI_ICON_GENERAL;
76 ret = notification_delete(noti);
77 if (ret != NOTIFICATION_ERROR_NONE) {
78 ERR("Fail to notification_delete [%d]\n", ret);
80 ret = notification_free(noti);
81 if (ret != NOTIFICATION_ERROR_NONE)
82 ERR("Fail to notification_free [%d]\n", ret);
83 return MOBILE_AP_ERROR_INTERNAL;
86 ret = notification_free(noti);
87 if (ret != NOTIFICATION_ERROR_NONE) {
88 ERR("Fail to notification_free [%d]\n", ret);
95 noti = notification_create(NOTIFICATION_TYPE_NOTI);
97 ERR("Fail to notification_create\n");
98 return MOBILE_AP_ERROR_INTERNAL;
101 ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME);
102 if (ret != NOTIFICATION_ERROR_NONE) {
103 ERR("Fail to notification_set_pkgname [%d]\n", ret);
107 ret = notification_set_property(noti,
108 NOTIFICATION_PROP_VOLATILE_DISPLAY);
109 if (ret != NOTIFICATION_ERROR_NONE) {
110 ERR("Fail to notification_set_property [%d]\n", ret);
114 ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
115 if (ret != NOTIFICATION_ERROR_NONE) {
116 ERR("Fail to notification_set_layout [%d]\n", ret);
120 ret = notification_set_image(noti,
121 NOTIFICATION_IMAGE_TYPE_ICON, general_icon_path ?
122 general_icon_path : icon_path);
123 if (ret != NOTIFICATION_ERROR_NONE) {
124 ERR("Fail to notification_set_image [%d]\n", ret);
128 ret = notification_set_text(noti,
129 NOTIFICATION_TEXT_TYPE_TITLE, NULL,
130 MH_STR_CONNECTION_TIMEOUT,
131 NOTIFICATION_VARIABLE_TYPE_NONE);
132 if (ret != NOTIFICATION_ERROR_NONE) {
133 ERR("Fail to notification_set_text [%d]\n", ret);
137 ret = notification_set_text(noti,
138 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
139 MH_STR_CONFIGURE_TETHERING,
140 NOTIFICATION_VARIABLE_TYPE_NONE);
141 if (ret != NOTIFICATION_ERROR_NONE) {
142 ERR("Fail to notification_set_text [%d]\n", ret);
146 ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR);
147 if (ret != NOTIFICATION_ERROR_NONE) {
148 ERR("Fail to notification_set_text_domain [%d]\n", ret);
152 ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME);
153 if (ret != NOTIFICATION_ERROR_NONE) {
154 ERR("Fail to notification_set_application [%d]\n", ret);
158 ret = notification_insert(noti, &timeout_noti_id);
159 if (ret != NOTIFICATION_ERROR_NONE) {
160 ERR("Fail to notification_insert [%d]\n", ret);
164 ret = notification_free(noti);
165 if (ret != NOTIFICATION_ERROR_NONE) {
166 ERR("Fail to notification_free [%d]\n", ret);
171 return MOBILE_AP_ERROR_NONE;
174 ret = notification_free(noti);
175 if (ret != NOTIFICATION_ERROR_NONE)
176 ERR("Fail to notification_free [%d]\n", ret);
178 return MOBILE_AP_ERROR_INTERNAL;
181 int _delete_timeout_noti(void)
183 notification_error_e ret = NOTIFICATION_ERROR_NONE;
184 notification_list_h noti_list = NULL;
185 notification_list_h l = NULL;
186 notification_h noti = NULL;
187 notification_ly_type_e layout;
191 ret = notification_get_detail_list(MH_NOTI_CALLER_PKGNAME,
192 NOTIFICATION_GROUP_ID_NONE,
193 NOTIFICATION_PRIV_ID_NONE,
196 if (ret != NOTIFICATION_ERROR_NONE) {
197 ERR("Fail to notification_get_detail_list\n");
198 return MOBILE_AP_ERROR_INTERNAL;
201 if (noti_list == NULL) {
202 return MOBILE_AP_ERROR_NONE;
205 for (l = noti_list; l; l = notification_list_get_next(l)) {
206 noti = notification_list_get_data(l);
210 ret = notification_get_layout(noti, &layout);
211 if (ret == NOTIFICATION_ERROR_NONE &&
212 layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE) {
213 DBG("Found timeout noti\n");
214 notification_delete(noti);
218 notification_free_list(noti_list);
222 return MOBILE_AP_ERROR_NONE;
225 int _create_connected_noti(int count, const char *icon_path)
228 notification_h noti = NULL;
229 notification_error_e ret = NOTIFICATION_ERROR_NONE;
232 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
234 ERR("Fail to notification_create\n");
235 return MOBILE_AP_ERROR_INTERNAL;
238 ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME);
239 if (ret != NOTIFICATION_ERROR_NONE) {
240 ERR("Fail to notification_set_pkgname [%d]\n", ret);
244 ret = notification_set_property(noti,
245 NOTIFICATION_PROP_DISABLE_AUTO_DELETE |
246 NOTIFICATION_PROP_VOLATILE_DISPLAY);
247 if (ret != NOTIFICATION_ERROR_NONE) {
248 ERR("Fail to notification_set_property [%d]\n", ret);
253 bundle_add(b, "caller", "notification");
255 appsvc_set_pkgname(b, "setting-mobileap-efl");
257 ret = notification_set_execute_option(noti,
258 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b);
259 if (ret != NOTIFICATION_ERROR_NONE) {
260 ERR("Failed to notification_set_execute_option");
264 ERR("Successfully added notification");
266 ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
267 if (ret != NOTIFICATION_ERROR_NONE) {
268 ERR("Fail to notification_set_image [%d]\n", ret);
272 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
273 if (ret != NOTIFICATION_ERROR_NONE) {
274 ERR("Fail to notification_set_image [%d]\n", ret);
278 ret = notification_set_text(noti,
279 NOTIFICATION_TEXT_TYPE_TITLE, NULL,
281 NOTIFICATION_VARIABLE_TYPE_NONE);
282 if (ret != NOTIFICATION_ERROR_NONE) {
283 ERR("Fail to notification_set_text [%d]\n", ret);
287 ret = notification_set_text(noti,
288 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
289 MH_STR_CONNECTED_DEV,
290 NOTIFICATION_VARIABLE_TYPE_INT, count,
291 NOTIFICATION_VARIABLE_TYPE_NONE);
292 if (ret != NOTIFICATION_ERROR_NONE) {
293 ERR("Fail to notification_set_text [%d]\n", ret);
297 ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR);
298 if (ret != NOTIFICATION_ERROR_NONE) {
299 ERR("Fail to notification_set_text_domain [%d]\n", ret);
303 ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME);
304 if (ret != NOTIFICATION_ERROR_NONE) {
305 ERR("Fail to notification_set_application [%d]\n", ret);
309 ret = notification_set_display_applist(noti,
310 NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
311 if (ret != NOTIFICATION_ERROR_NONE) {
312 ERR("Fail to notification_set_display_applist [%d]\n", ret);
316 ret = notification_insert(noti, &connected_noti_id);
317 if (ret != NOTIFICATION_ERROR_NONE) {
318 ERR("Fail to notification_insert [%d]\n", ret);
322 ret = notification_free(noti);
323 if (ret != NOTIFICATION_ERROR_NONE) {
324 ERR("Fail to notification_free [%d]\n", ret);
329 return MOBILE_AP_ERROR_NONE;
334 ret = notification_free(noti);
335 if (ret != NOTIFICATION_ERROR_NONE)
336 ERR("Fail to notification_free [%d]\n", ret);
337 return MOBILE_AP_ERROR_INTERNAL;
340 int _update_connected_noti(int count, const char *icon_path)
344 notification_h noti = NULL;
345 notification_error_e ret = NOTIFICATION_ERROR_NONE;
347 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
349 ERR("notification_load is failed\n");
350 return MOBILE_AP_ERROR_INTERNAL;
353 ret = notification_set_image(noti,
354 NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
355 if (ret != NOTIFICATION_ERROR_NONE) {
356 ERR("Fail to notification_set_image [%d]\n", ret);
360 ret = notification_set_text(noti,
361 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
362 MH_STR_CONNECTED_DEV,
363 NOTIFICATION_VARIABLE_TYPE_INT, count,
364 NOTIFICATION_VARIABLE_TYPE_NONE);
365 if (ret != NOTIFICATION_ERROR_NONE) {
366 ERR("Fail to notification_set_text [%d]\n", ret);
370 ret = notification_update(noti);
371 if (ret != NOTIFICATION_ERROR_NONE) {
372 ERR("Fail to notification_update [%d]\n", ret);
376 ret = notification_free(noti);
377 if (ret != NOTIFICATION_ERROR_NONE) {
378 ERR("Fail to notification_free [%d]\n", ret);
379 return MOBILE_AP_ERROR_INTERNAL;
383 return MOBILE_AP_ERROR_NONE;
386 ret = notification_free(noti);
387 if (ret != NOTIFICATION_ERROR_NONE) {
388 ERR("Fail to notification_free [%d]\n", ret);
391 return MOBILE_AP_ERROR_INTERNAL;
394 int _delete_connected_noti(void)
397 notification_h noti = NULL;
398 notification_error_e ret;
400 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
402 ERR("notification_load is failed\n");
403 connected_noti_id = 0;
404 return MOBILE_AP_ERROR_INTERNAL;
406 connected_noti_id = 0;
408 ret = notification_delete(noti);
409 if (ret != NOTIFICATION_ERROR_NONE) {
410 ERR("Fail to notification_delete [%d]\n", ret);
412 ret = notification_free(noti);
413 if (ret != NOTIFICATION_ERROR_NONE)
414 ERR("Fail to notification_free [%d]\n", ret);
415 return MOBILE_AP_ERROR_INTERNAL;
418 ret = notification_free(noti);
419 if (ret != NOTIFICATION_ERROR_NONE) {
420 ERR("Fail to notification_free [%d]\n", ret);
421 return MOBILE_AP_ERROR_INTERNAL;
425 return MOBILE_AP_ERROR_NONE;
428 void _create_tethering_active_noti(void)
430 int active_count = 0;
432 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
435 if (_mobileap_is_enabled(MOBILE_AP_STATE_BT))
438 if (_mobileap_is_enabled(MOBILE_AP_STATE_USB))
441 if (active_count == 1)
442 __create_status_noti(_("IDS_COM_BODY_TETHERING_ENABLED"));
447 void _create_bt_tethering_active_noti(void)
450 bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
457 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI) &&
458 !_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
459 str1 = MH_STR_TETHERING_ACTIVE;
460 __create_status_noti(str1);
463 ret = bt_adapter_get_visibility(&mode, &duration);
464 if (ret != BT_ERROR_NONE) {
465 ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret);
468 if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) {
469 str2 = MH_STR_BT_VISIBILITY;
470 __create_status_noti(str2);