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>
22 #include <notification.h>
23 #include <notification_list.h>
24 #include <notification_text_domain.h>
25 #include <notification_internal.h>
26 #include <bluetooth.h>
27 #include <bundle_internal.h>
29 #include "mobileap_softap.h"
30 #include "mobileap_notification.h"
32 #define MH_NOTI_LAUNCH_PKGNAME "ug-setting-mobileap-efl"
33 #define MH_NOTI_CALLER_PKGNAME "mobileap-agent"
34 #define MH_LOCALE_DOMAIN "ug-setting-mobileap-efl"
35 #define MH_LOCALE_DIR "/usr/ug/res/locale"
38 static int connected_noti_id = 0;
39 static int timeout_noti_id = 0;
41 static int __create_status_noti(const char *content)
44 return MOBILE_AP_ERROR_INVALID_PARAM;
46 notification_error_e ret;
48 ret = notification_status_message_post(content);
49 if (ret != NOTIFICATION_ERROR_NONE) {
50 ERR("notification_status_message_post() is failed : %d\n", ret);
51 return MOBILE_AP_ERROR_INTERNAL;
54 return MOBILE_AP_ERROR_NONE;
57 int _create_timeout_noti(const char *icon_path)
61 notification_h noti = NULL;
62 notification_error_e ret = NOTIFICATION_ERROR_NONE;
63 char *old_icon_path = NULL;
64 char *general_icon_path = NULL;
66 if (timeout_noti_id) {
67 noti = notification_load(MH_NOTI_CALLER_PKGNAME, timeout_noti_id);
69 DBG("Notification can be deleted already\n");
71 ret = notification_get_image(noti,
72 NOTIFICATION_IMAGE_TYPE_ICON, &old_icon_path);
73 if (ret == NOTIFICATION_ERROR_NONE) {
74 if (g_strcmp0(icon_path, old_icon_path))
75 general_icon_path = MH_NOTI_ICON_GENERAL;
78 ret = notification_delete(noti);
79 if (ret != NOTIFICATION_ERROR_NONE) {
80 ERR("Fail to notification_delete [%d]\n", ret);
82 ret = notification_free(noti);
83 if (ret != NOTIFICATION_ERROR_NONE)
84 ERR("Fail to notification_free [%d]\n", ret);
85 return MOBILE_AP_ERROR_INTERNAL;
88 ret = notification_free(noti);
89 if (ret != NOTIFICATION_ERROR_NONE) {
90 ERR("Fail to notification_free [%d]\n", ret);
97 noti = notification_create(NOTIFICATION_TYPE_NOTI);
99 ERR("Fail to notification_create\n");
100 return MOBILE_AP_ERROR_INTERNAL;
103 ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME);
104 if (ret != NOTIFICATION_ERROR_NONE) {
105 ERR("Fail to notification_set_pkgname [%d]\n", ret);
109 ret = notification_set_property(noti,
110 NOTIFICATION_PROP_VOLATILE_DISPLAY);
111 if (ret != NOTIFICATION_ERROR_NONE) {
112 ERR("Fail to notification_set_property [%d]\n", ret);
116 ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
117 if (ret != NOTIFICATION_ERROR_NONE) {
118 ERR("Fail to notification_set_layout [%d]\n", ret);
122 ret = notification_set_image(noti,
123 NOTIFICATION_IMAGE_TYPE_ICON, general_icon_path ?
124 general_icon_path : icon_path);
125 if (ret != NOTIFICATION_ERROR_NONE) {
126 ERR("Fail to notification_set_image [%d]\n", ret);
130 ret = notification_set_text(noti,
131 NOTIFICATION_TEXT_TYPE_TITLE, NULL,
132 MH_STR_CONNECTION_TIMEOUT,
133 NOTIFICATION_VARIABLE_TYPE_NONE);
134 if (ret != NOTIFICATION_ERROR_NONE) {
135 ERR("Fail to notification_set_text [%d]\n", ret);
139 ret = notification_set_text(noti,
140 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
141 MH_STR_CONFIGURE_TETHERING,
142 NOTIFICATION_VARIABLE_TYPE_NONE);
143 if (ret != NOTIFICATION_ERROR_NONE) {
144 ERR("Fail to notification_set_text [%d]\n", ret);
148 ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR);
149 if (ret != NOTIFICATION_ERROR_NONE) {
150 ERR("Fail to notification_set_text_domain [%d]\n", ret);
154 ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME);
155 if (ret != NOTIFICATION_ERROR_NONE) {
156 ERR("Fail to notification_set_application [%d]\n", ret);
160 ret = notification_insert(noti, &timeout_noti_id);
161 if (ret != NOTIFICATION_ERROR_NONE) {
162 ERR("Fail to notification_insert [%d]\n", ret);
166 ret = notification_free(noti);
167 if (ret != NOTIFICATION_ERROR_NONE) {
168 ERR("Fail to notification_free [%d]\n", ret);
173 return MOBILE_AP_ERROR_NONE;
176 ret = notification_free(noti);
177 if (ret != NOTIFICATION_ERROR_NONE)
178 ERR("Fail to notification_free [%d]\n", ret);
180 return MOBILE_AP_ERROR_INTERNAL;
183 int _delete_timeout_noti(void)
185 notification_error_e ret = NOTIFICATION_ERROR_NONE;
186 notification_list_h noti_list = NULL;
187 notification_list_h l = NULL;
188 notification_h noti = NULL;
189 notification_ly_type_e layout;
193 ret = notification_get_detail_list(MH_NOTI_CALLER_PKGNAME,
194 NOTIFICATION_GROUP_ID_NONE,
195 NOTIFICATION_PRIV_ID_NONE,
198 if (ret != NOTIFICATION_ERROR_NONE) {
199 ERR("Fail to notification_get_detail_list\n");
200 return MOBILE_AP_ERROR_INTERNAL;
203 if (noti_list == NULL) {
204 return MOBILE_AP_ERROR_NONE;
207 for (l = noti_list; l; l = notification_list_get_next(l)) {
208 noti = notification_list_get_data(l);
212 ret = notification_get_layout(noti, &layout);
213 if (ret == NOTIFICATION_ERROR_NONE &&
214 layout == NOTIFICATION_LY_NOTI_EVENT_SINGLE) {
215 DBG("Found timeout noti\n");
216 notification_delete(noti);
220 notification_free_list(noti_list);
224 return MOBILE_AP_ERROR_NONE;
227 int _create_connected_noti(int count, const char *icon_path)
230 notification_h noti = NULL;
231 notification_error_e ret = NOTIFICATION_ERROR_NONE;
234 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
236 ERR("Fail to notification_create\n");
237 return MOBILE_AP_ERROR_INTERNAL;
240 ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME);
241 if (ret != NOTIFICATION_ERROR_NONE) {
242 ERR("Fail to notification_set_pkgname [%d]\n", ret);
246 ret = notification_set_property(noti,
247 NOTIFICATION_PROP_DISABLE_AUTO_DELETE |
248 NOTIFICATION_PROP_VOLATILE_DISPLAY);
249 if (ret != NOTIFICATION_ERROR_NONE) {
250 ERR("Fail to notification_set_property [%d]\n", ret);
255 bundle_add(b, "caller", "notification");
258 appsvc_set_pkgname(b, "ug-setting-mobileap-efl");
261 ret = notification_set_execute_option(noti,
262 NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b);
263 if (ret != NOTIFICATION_ERROR_NONE) {
264 ERR("Failed to notification_set_execute_option");
268 ERR("Successfully added notification");
270 ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
271 if (ret != NOTIFICATION_ERROR_NONE) {
272 ERR("Fail to notification_set_image [%d]\n", ret);
276 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
277 if (ret != NOTIFICATION_ERROR_NONE) {
278 ERR("Fail to notification_set_image [%d]\n", ret);
282 ret = notification_set_text(noti,
283 NOTIFICATION_TEXT_TYPE_TITLE, NULL,
285 NOTIFICATION_VARIABLE_TYPE_NONE);
286 if (ret != NOTIFICATION_ERROR_NONE) {
287 ERR("Fail to notification_set_text [%d]\n", ret);
291 ret = notification_set_text(noti,
292 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
293 MH_STR_CONNECTED_DEV,
294 NOTIFICATION_VARIABLE_TYPE_INT, count,
295 NOTIFICATION_VARIABLE_TYPE_NONE);
296 if (ret != NOTIFICATION_ERROR_NONE) {
297 ERR("Fail to notification_set_text [%d]\n", ret);
301 ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR);
302 if (ret != NOTIFICATION_ERROR_NONE) {
303 ERR("Fail to notification_set_text_domain [%d]\n", ret);
307 ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME);
308 if (ret != NOTIFICATION_ERROR_NONE) {
309 ERR("Fail to notification_set_application [%d]\n", ret);
313 ret = notification_set_display_applist(noti,
314 NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
315 if (ret != NOTIFICATION_ERROR_NONE) {
316 ERR("Fail to notification_set_display_applist [%d]\n", ret);
320 ret = notification_insert(noti, &connected_noti_id);
321 if (ret != NOTIFICATION_ERROR_NONE) {
322 ERR("Fail to notification_insert [%d]\n", ret);
326 ret = notification_free(noti);
327 if (ret != NOTIFICATION_ERROR_NONE) {
328 ERR("Fail to notification_free [%d]\n", ret);
333 return MOBILE_AP_ERROR_NONE;
338 ret = notification_free(noti);
339 if (ret != NOTIFICATION_ERROR_NONE)
340 ERR("Fail to notification_free [%d]\n", ret);
341 return MOBILE_AP_ERROR_INTERNAL;
344 int _update_connected_noti(int count, const char *icon_path)
348 notification_h noti = NULL;
349 notification_error_e ret = NOTIFICATION_ERROR_NONE;
351 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
353 ERR("notification_load is failed\n");
354 return MOBILE_AP_ERROR_INTERNAL;
357 ret = notification_set_image(noti,
358 NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
359 if (ret != NOTIFICATION_ERROR_NONE) {
360 ERR("Fail to notification_set_image [%d]\n", ret);
364 ret = notification_set_text(noti,
365 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
366 MH_STR_CONNECTED_DEV,
367 NOTIFICATION_VARIABLE_TYPE_INT, count,
368 NOTIFICATION_VARIABLE_TYPE_NONE);
369 if (ret != NOTIFICATION_ERROR_NONE) {
370 ERR("Fail to notification_set_text [%d]\n", ret);
374 ret = notification_update(noti);
375 if (ret != NOTIFICATION_ERROR_NONE) {
376 ERR("Fail to notification_update [%d]\n", ret);
380 ret = notification_free(noti);
381 if (ret != NOTIFICATION_ERROR_NONE) {
382 ERR("Fail to notification_free [%d]\n", ret);
383 return MOBILE_AP_ERROR_INTERNAL;
387 return MOBILE_AP_ERROR_NONE;
390 ret = notification_free(noti);
391 if (ret != NOTIFICATION_ERROR_NONE) {
392 ERR("Fail to notification_free [%d]\n", ret);
395 return MOBILE_AP_ERROR_INTERNAL;
398 int _delete_connected_noti(void)
401 notification_h noti = NULL;
402 notification_error_e ret;
404 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
406 ERR("notification_load is failed\n");
407 connected_noti_id = 0;
408 return MOBILE_AP_ERROR_INTERNAL;
410 connected_noti_id = 0;
412 ret = notification_delete(noti);
413 if (ret != NOTIFICATION_ERROR_NONE) {
414 ERR("Fail to notification_delete [%d]\n", ret);
416 ret = notification_free(noti);
417 if (ret != NOTIFICATION_ERROR_NONE)
418 ERR("Fail to notification_free [%d]\n", ret);
419 return MOBILE_AP_ERROR_INTERNAL;
422 ret = notification_free(noti);
423 if (ret != NOTIFICATION_ERROR_NONE) {
424 ERR("Fail to notification_free [%d]\n", ret);
425 return MOBILE_AP_ERROR_INTERNAL;
429 return MOBILE_AP_ERROR_NONE;
432 void _create_tethering_active_noti(void)
434 int active_count = 0;
436 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
439 if (_mobileap_is_enabled(MOBILE_AP_STATE_BT))
442 if (_mobileap_is_enabled(MOBILE_AP_STATE_USB))
445 if (active_count == 1)
446 __create_status_noti(_("IDS_MOBILEAP_BODY_TETHERING_ACTIVE_ABB"));
451 void _create_bt_tethering_active_noti(void)
454 bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
459 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI) &&
460 !_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
461 str1 = MH_STR_TETHERING_ACTIVE;
462 __create_status_noti(str1);
465 ret = bt_adapter_get_visibility(&mode, &duration);
466 if (ret != BT_ERROR_NONE) {
467 ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret);
470 if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) {
471 str2 = MH_STR_BT_VISIBILITY;
472 __create_status_noti(str2);