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;
231 noti = notification_create(NOTIFICATION_TYPE_ONGOING);
233 ERR("Fail to notification_create\n");
234 return MOBILE_AP_ERROR_INTERNAL;
237 ret = notification_set_pkgname(noti, MH_NOTI_CALLER_PKGNAME);
238 if (ret != NOTIFICATION_ERROR_NONE) {
239 ERR("Fail to notification_set_pkgname [%d]\n", ret);
243 ret = notification_set_property(noti,
244 NOTIFICATION_PROP_DISABLE_AUTO_DELETE |
245 NOTIFICATION_PROP_VOLATILE_DISPLAY);
246 if (ret != NOTIFICATION_ERROR_NONE) {
247 ERR("Fail to notification_set_property [%d]\n", ret);
251 ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
252 if (ret != NOTIFICATION_ERROR_NONE) {
253 ERR("Fail to notification_set_image [%d]\n", ret);
257 ret = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
258 if (ret != NOTIFICATION_ERROR_NONE) {
259 ERR("Fail to notification_set_image [%d]\n", ret);
263 ret = notification_set_text(noti,
264 NOTIFICATION_TEXT_TYPE_TITLE, NULL,
266 NOTIFICATION_VARIABLE_TYPE_NONE);
267 if (ret != NOTIFICATION_ERROR_NONE) {
268 ERR("Fail to notification_set_text [%d]\n", ret);
272 ret = notification_set_text(noti,
273 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
274 MH_STR_CONNECTED_DEV,
275 NOTIFICATION_VARIABLE_TYPE_INT, count,
276 NOTIFICATION_VARIABLE_TYPE_NONE);
277 if (ret != NOTIFICATION_ERROR_NONE) {
278 ERR("Fail to notification_set_text [%d]\n", ret);
282 ret = notification_set_text_domain(noti, MH_LOCALE_DOMAIN, MH_LOCALE_DIR);
283 if (ret != NOTIFICATION_ERROR_NONE) {
284 ERR("Fail to notification_set_text_domain [%d]\n", ret);
288 ret = notification_set_application(noti, MH_NOTI_LAUNCH_PKGNAME);
289 if (ret != NOTIFICATION_ERROR_NONE) {
290 ERR("Fail to notification_set_application [%d]\n", ret);
294 ret = notification_set_display_applist(noti,
295 NOTIFICATION_DISPLAY_APP_ALL ^ NOTIFICATION_DISPLAY_APP_INDICATOR);
296 if (ret != NOTIFICATION_ERROR_NONE) {
297 ERR("Fail to notification_set_display_applist [%d]\n", ret);
301 ret = notification_insert(noti, &connected_noti_id);
302 if (ret != NOTIFICATION_ERROR_NONE) {
303 ERR("Fail to notification_insert [%d]\n", ret);
307 ret = notification_free(noti);
308 if (ret != NOTIFICATION_ERROR_NONE) {
309 ERR("Fail to notification_free [%d]\n", ret);
314 return MOBILE_AP_ERROR_NONE;
317 ret = notification_free(noti);
318 if (ret != NOTIFICATION_ERROR_NONE)
319 ERR("Fail to notification_free [%d]\n", ret);
320 return MOBILE_AP_ERROR_INTERNAL;
323 int _update_connected_noti(int count, const char *icon_path)
327 notification_h noti = NULL;
328 notification_error_e ret = NOTIFICATION_ERROR_NONE;
330 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
332 ERR("notification_load is failed\n");
333 return MOBILE_AP_ERROR_INTERNAL;
336 ret = notification_set_image(noti,
337 NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
338 if (ret != NOTIFICATION_ERROR_NONE) {
339 ERR("Fail to notification_set_image [%d]\n", ret);
343 ret = notification_set_text(noti,
344 NOTIFICATION_TEXT_TYPE_CONTENT, NULL,
345 MH_STR_CONNECTED_DEV,
346 NOTIFICATION_VARIABLE_TYPE_INT, count,
347 NOTIFICATION_VARIABLE_TYPE_NONE);
348 if (ret != NOTIFICATION_ERROR_NONE) {
349 ERR("Fail to notification_set_text [%d]\n", ret);
353 ret = notification_update(noti);
354 if (ret != NOTIFICATION_ERROR_NONE) {
355 ERR("Fail to notification_update [%d]\n", ret);
359 ret = notification_free(noti);
360 if (ret != NOTIFICATION_ERROR_NONE) {
361 ERR("Fail to notification_free [%d]\n", ret);
362 return MOBILE_AP_ERROR_INTERNAL;
366 return MOBILE_AP_ERROR_NONE;
369 ret = notification_free(noti);
370 if (ret != NOTIFICATION_ERROR_NONE) {
371 ERR("Fail to notification_free [%d]\n", ret);
374 return MOBILE_AP_ERROR_INTERNAL;
377 int _delete_connected_noti(void)
380 notification_h noti = NULL;
381 notification_error_e ret;
383 noti = notification_load(MH_NOTI_CALLER_PKGNAME, connected_noti_id);
385 ERR("notification_load is failed\n");
386 connected_noti_id = 0;
387 return MOBILE_AP_ERROR_INTERNAL;
389 connected_noti_id = 0;
391 ret = notification_delete(noti);
392 if (ret != NOTIFICATION_ERROR_NONE) {
393 ERR("Fail to notification_delete [%d]\n", ret);
395 ret = notification_free(noti);
396 if (ret != NOTIFICATION_ERROR_NONE)
397 ERR("Fail to notification_free [%d]\n", ret);
398 return MOBILE_AP_ERROR_INTERNAL;
401 ret = notification_free(noti);
402 if (ret != NOTIFICATION_ERROR_NONE) {
403 ERR("Fail to notification_free [%d]\n", ret);
404 return MOBILE_AP_ERROR_INTERNAL;
408 return MOBILE_AP_ERROR_NONE;
411 void _create_tethering_active_noti(void)
413 int active_count = 0;
415 if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
418 if (_mobileap_is_enabled(MOBILE_AP_STATE_BT))
421 if (_mobileap_is_enabled(MOBILE_AP_STATE_USB))
424 if (active_count == 1)
425 __create_status_noti(_("IDS_MOBILEAP_BODY_TETHERING_ACTIVE_ABB"));
430 void _create_bt_tethering_active_noti(void)
433 bt_adapter_visibility_mode_e mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
440 if (!_mobileap_is_enabled(MOBILE_AP_STATE_WIFI) &&
441 !_mobileap_is_enabled(MOBILE_AP_STATE_USB)) {
442 str1 = MH_STR_TETHERING_ACTIVE;
443 __create_status_noti(str1);
446 ret = bt_adapter_get_visibility(&mode, &duration);
447 if (ret != BT_ERROR_NONE) {
448 ERR("bt_adapter_get_visibility is failed 0x[%X]\n", ret);
451 if (mode == BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE) {
452 str2 = MH_STR_BT_VISIBILITY;
453 __create_status_noti(str2);