0c2ecf261bd796893233b2ed013beab942f6ebaf
[platform/core/connectivity/net-popup.git] / src / net-popup.c
1 /*
2 *  net-popup
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5 *
6 * Licensed under the Flora License, Version 1.1 (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
9 *
10 * http://www.tizenopensource.org/license
11 *
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.
17 *
18 */
19
20 #include <glib.h>
21 #include <stdio.h>
22 #if 0
23 #include <Ecore_X.h>
24 #endif
25 #include <syspopup.h>
26 #include <notification.h>
27 #include <notification_list.h>
28 #include <notification_text_domain.h>
29 #include <app.h>
30 #include <app_control.h>
31 #include <appsvc.h>
32 #include <vconf.h>
33 #include <vconf-keys.h>
34 #include <gio/gio.h>
35 #include <dbus/dbus.h>
36 #include <efl_extension.h>
37 #include <tzplatform_config.h>
38 #include <vpn_service.h>
39 #include <vpn_service_internal.h>
40 #include <stc.h>
41 #include <stc_internal.h>
42
43 #include "net-popup.h"
44 #include "net-popup-vpn.h"
45 #include "net-popup-strings.h"
46
47 #define NET_WIFIQS_APPID        "net.wifi-qs"
48 #define DATA_USAGE_APPID        "org.tizen.setting"
49 #define WIFI_EFL_UG             "wifi-efl-ug"
50
51 #define LOCALEDIR                       "/usr/share/locale"
52 #define NETPOPUP_EDJ    tzplatform_mkpath(TZ_SYS_RO_UG, "/res/edje/net-popup/netpopup-custom.edj")
53 #define QP_PRELOAD_NOTI_ICON_PATH       tzplatform_mkpath(TZ_SYS_RO_APP, "/org.tizen.quickpanel/shared/res/noti_icons/Wi-Fi")
54
55 #define STC_NOTI_DATA_USAGE_ICON_PATH   "/usr/share/icons/"
56 #define STC_NOTI_DATA_USAGE_ICON_NAME   "stc_noti_datausage.png"
57
58 #define NETCONFIG_NOTIFICATION_WIFI_ICON \
59                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range.png")
60 #define NETCONFIG_NOTIFICATION_WIFI_ICON_LITE \
61                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range_ongoing.png")
62 #define NETCONFIG_NOTIFICATION_WIFI_CAPTIVE_ICON \
63                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/B03_notify_Wi-fi_range.png")
64 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON \
65                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/Q02_Notification_wifi_in_range.png")
66 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON_LITE \
67                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range.png")
68 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE \
69                 dgettext(PACKAGE, "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE")
70 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT \
71                 dgettext(PACKAGE, "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT")
72 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE \
73                 dgettext(PACKAGE, "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB")
74 #define NETCONFIG_NOTIFICATION_IP_CONFLICT_TITLE \
75                 dgettext(PACKAGE, "IDS_IP_CONFLICT")
76 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT "\"%s\""
77
78 #define STC_NOTIFICATION_WARNING_TITLE \
79                 dgettext(PACKAGE, "IDS_COM_BODY_DATA_USAGE_WARNING")
80 #define STC_NOTIFICATION_WARNING_CONTENT \
81                 dgettext(PACKAGE, "IDS_SM_SBODY_TAP_HERE_TO_VIEW_YOUR_DATA_USAGE_ABB")
82 #define STC_NOTIFICATION_RESTRICTION_OK_TITLE \
83                 dgettext(PACKAGE, "IDS_SM_HEADER_MOBILE_DATA_TURNED_OFF_ABB2")
84 #define STC_NOTIFICATION_RESTRICTION_OK_CONTENT \
85                 dgettext(PACKAGE, "IDS_SM_SBODY_TAP_HERE_TO_TURN_IT_ON_AGAIN_ABB")
86 #define STC_NOTIFICATION_RESTRICTION_ON_TITLE \
87                 dgettext(PACKAGE, "IDS_SM_TMBODY_MOBILE_DATA_LIMIT_EXCEEDED_ABB")
88
89 #define STC_TOTAL_DATACALL "TOTAL_DATACALL"
90 #define STC_TOTAL_WIFI "TOTAL_WIFI"
91 #define STC_TOTAL_BLUETOOTH "TOTAL_BLUETOOTH"
92
93 #define USER_RESP_LEN 30
94 #define ICON_PATH_LEN 128
95 #define RESP_REMAIN_CONNECTED                           "RESP_REMAIN_CONNECTED"
96 #define RESP_WIFI_TETHERING_OFF                         "RESP_TETHERING_TYPE_WIFI_OFF"
97 #define RESP_WIFI_AP_TETHERING_OFF                      "RESP_TETHERING_TYPE_WIFI_AP_OFF"
98 #define RESP_TETHERING_ON                                       "RESP_TETHERING_ON"
99 #define CAPTIVE_PORTAL_LOGIN "Login required to access Internet"
100 #define CAPTIVE_PORTAL_LOGIN_ERROR "Login not completed. Disconnected active Wifi"
101
102 static Ecore_Event_Handler *ecore_event_evas_handler;
103 static Ecore_Event_Handler *ecore_event_evas_quick_panel_handler;
104
105 #define BUF_SIZE 1024
106 long sizes[] = {1073741824, 1048576, 1024, 0};
107 char *units[] = {"GB", "MB", "KB", "B"};
108
109 static app_control_h g_req_handle = NULL;
110 static char *resp_popup_mode = NULL;
111
112 static GDBusConnection *conn = NULL;
113 static GDBusProxy *proxy = NULL;
114
115 /* vpn-service popup */
116 static char *iface_name = NULL;
117
118 /* data roaming popup */
119 static Eina_Bool turn_on_roaming = FALSE;
120 static Eina_Bool do_not_show_popup = FALSE;
121
122 /* data usage popup */
123 static char *data_usage_app_id = NULL;
124 static char *data_usage_iftype = NULL;
125
126 static int __net_popup_show_notification(app_control_h request, void *data);
127 static int __toast_popup_show(app_control_h request, void *data);
128 static int __net_popup_show_popup(app_control_h request, void *data);
129 static void __net_popup_show_warning_noti(app_control_h request, void *data);
130 static void __net_popup_show_restriction_noti(app_control_h request, void *data);
131 static void __net_popup_add_found_ap_noti(void);
132 static void __net_popup_del_found_ap_noti(void);
133 static void __net_popup_add_portal_noti(app_control_h request);
134 static void __net_popup_del_portal_noti(void);
135 static void __net_popup_show_popup_with_user_resp(app_control_h request, void *data);
136 static void __net_popup_show_vpn_popup(app_control_h request, void *data);
137 static int _net_popup_send_user_resp(char *resp, Eina_Bool state);
138 static int __net_popup_show_network_error_popup(app_control_h request, void *data);
139 static void __net_popup_add_ip_conflict_noti(app_control_h request);
140 static void __net_popup_del_ip_conflict_noti(void);
141
142 GDBusProxy *__net_popup_init_dbus(void)
143 {
144         log_print(NET_POPUP, "__net_popup_init_dbus()\n");
145
146         GError *err = NULL;
147
148         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
149         if (err != NULL) {
150                 g_error_free(err);
151                 return NULL;
152         }
153
154         proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
155                         "net.netpopup",
156                         "/Netpopup",
157                         "net.netpopup",
158                         NULL, &err);
159
160         if (proxy == NULL) {
161                 g_object_unref(conn);
162                 conn = NULL;
163         }
164
165         return proxy;
166 }
167
168 void __net_popup_deinit_dbus(void)
169 {
170         log_print(NET_POPUP, "__net_popup_deinit_dbus()\n");
171
172         if (proxy) {
173                 g_object_unref(proxy);
174                 proxy = NULL;
175         }
176
177         if (conn) {
178                 g_object_unref(conn);
179                 conn = NULL;
180         }
181
182         return;
183 }
184
185 int __net_popup_send_dbus_msg(const char *resp)
186 {
187         log_print(NET_POPUP, "__net_popup_send_dbus_msg()\n");
188
189         if (conn == NULL || resp == NULL)
190                 return -1;
191
192         GDBusConnection *gconn = NULL;
193         GVariant *msg = NULL;
194         char *module = "wifi";
195         GError *err = NULL;
196
197         gconn = g_bus_get_sync(DBUS_BUS_SYSTEM, NULL, &err);
198         if (err != NULL) {
199                 g_error_free(err);
200                 err = NULL;
201                 return -1;
202         }
203
204         msg = g_variant_new("(ss)", module, resp);
205         g_dbus_connection_emit_signal(gconn, NULL, "/Org/Tizen/Quickpanel",
206                         "org.tizen.quickpanel", "ACTIVITY", msg, &err);
207         if (err) {
208                 g_error_free(err);
209                 return -1;
210         }
211
212         g_variant_unref(msg);
213
214         if (gconn)
215                 g_object_unref(gconn);
216
217
218         return 0;
219 }
220
221 void __net_popup_send_data_usage_msg(const char *app_id,
222         const char *iftype)
223 {
224         log_print(NET_POPUP, "__net_popup_send_data_usage_msg()\n");
225
226         int ret = STC_ERROR_NONE;
227         stc_h stc = NULL;
228         stc_restriction_rule_h rule = NULL;
229
230         ret = stc_initialize(&stc);
231         if (ret != STC_ERROR_NONE) {
232                 log_print(NET_POPUP, "Failed to get operation ret= %d\n", ret);
233                 return;
234         }
235
236         ret = stc_restriction_rule_create(stc, &rule);
237         if (ret != STC_ERROR_NONE) {
238                 log_print(NET_POPUP, "Failed to create restriction rule ret= %d\n", ret);
239                 return;
240         }
241
242         ret = stc_restriction_rule_set_app_id(rule, app_id);
243         if (ret != STC_ERROR_NONE) {
244                 log_print(NET_POPUP, "Failed to set application ID ret= %d\n", ret);
245                 return;
246         }
247
248         ret = stc_restriction_rule_set_iface_type(rule, iftype[0] - '0');
249         if (ret != STC_ERROR_NONE) {
250                 log_print(NET_POPUP, "Failed to set interface type ret= %d\n", ret);
251                 return;
252         }
253
254         ret = stc_unset_restriction(stc, rule);
255         if (ret != STC_ERROR_NONE) {
256                 log_print(NET_POPUP, "Failed to unset restriction ret= %d\n", ret);
257                 return;
258         }
259
260         log_print(NET_POPUP, "Success to unset restriction\n");
261         return;
262 }
263
264 static bool __net_popup_create(void *data)
265 {
266         log_print(NET_POPUP, "__net_popup_create()\n");
267
268         bindtextdomain(PACKAGE, LOCALEDIR);
269
270         return true;
271 }
272
273 static void __net_popup_terminate(void *data)
274 {
275         log_print(NET_POPUP, "__net_popup_terminate()\n");
276
277         if (ecore_event_evas_handler) {
278                 ecore_event_handler_del(ecore_event_evas_handler);
279                 ecore_event_evas_handler = NULL;
280         }
281
282         if (ecore_event_evas_quick_panel_handler) {
283                 ecore_event_handler_del(ecore_event_evas_quick_panel_handler);
284                 ecore_event_evas_quick_panel_handler = NULL;
285         }
286
287         if (g_req_handle) {
288                 app_control_destroy(g_req_handle);
289                 g_req_handle = NULL;
290         }
291
292         if (resp_popup_mode) {
293                 free(resp_popup_mode);
294                 resp_popup_mode = NULL;
295         }
296
297         if (iface_name) {
298                 free(iface_name);
299                 iface_name = NULL;
300         }
301
302         return;
303 }
304
305 static void __net_popup_pause(void *data)
306 {
307         log_print(NET_POPUP, "__net_popup_pause()\n");
308 }
309
310 static void __net_popup_resume(void *data)
311 {
312         return;
313 }
314
315 static Eina_Bool __key_release_event_cb(void *data, int type,
316                 void *event)
317 {
318         log_print(NET_POPUP, "__key_release_event_cb()\n");
319
320         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *) event;
321
322         if (!ev)
323                 return ECORE_CALLBACK_RENEW;
324
325         if (!ev->keyname)
326                 return ECORE_CALLBACK_RENEW;
327
328         log_print(NET_POPUP, "key_release : %s", ev->keyname);
329         if (g_strcmp0(ev->keyname, "XF86Phone") == 0 ||
330                         g_strcmp0(ev->keyname, "XF86Stop") == 0) {
331                 elm_exit();
332         }
333
334         return ECORE_CALLBACK_DONE;
335 }
336
337 #if 0
338 static Eina_Bool _ecore_event_client_message_cb(void *data, int type,
339                                                  void *event)
340 {
341         Ecore_X_Event_Client_Message *ev = event;
342
343         if (ev->message_type == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_STATE) {
344                 if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF)
345                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF");
346                 else if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON)
347                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON");
348         }
349         return ECORE_CALLBACK_RENEW;
350 }
351 #endif
352
353 static void __net_popup_service_cb(app_control_h request, void *data)
354 {
355         log_print(NET_POPUP, "__net_popup_service_cb()\n");
356
357         int ret = 0;
358         char *operation = NULL;
359         char *type = NULL;
360
361         if (ecore_event_evas_handler == NULL) {
362                 ecore_event_evas_handler = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
363                                 __key_release_event_cb, NULL);
364         }
365
366         ret = app_control_get_operation(request, &operation);
367         if (APP_CONTROL_ERROR_NONE != ret)
368                 log_print(NET_POPUP, "Failed to get operation ret= %d", ret);
369
370         if (operation != NULL && g_str_equal(operation, APP_CONTROL_OPERATION_SETTING_VPN)) {
371                 app_control_clone(&g_req_handle, request);
372                 __net_popup_show_vpn_popup(request, data);
373                 if (operation) {
374                         free(operation);
375                         operation = NULL;
376                 }
377                 return;
378         }
379
380         if (operation) {
381                 free(operation);
382                 operation = NULL;
383         }
384
385         ret = app_control_get_extra_data(request, "_SYSPOPUP_TYPE_", &type);
386         if (APP_CONTROL_ERROR_NONE != ret) {
387                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_TYPE_ ret = %d", ret);
388                 g_free(type);
389                 elm_exit();
390                 return;
391         }
392
393         log_print(NET_POPUP, "type = %s\n", type);
394
395         if (g_str_equal(type, "notification")) {
396                 __net_popup_show_notification(request, data);
397                 elm_exit();
398         } else if (g_str_equal(type, "toast_popup")) {
399                 __toast_popup_show(request, data);
400         } else if (g_str_equal(type, "popup")) {
401                 __net_popup_show_popup(request, data);
402         } else if (g_str_equal(type, "warning_noti")) {
403                 __net_popup_show_warning_noti(request, data);
404                 elm_exit();
405         } else if (g_str_equal(type, "restriction_noti")) {
406                 __net_popup_show_restriction_noti(request, data);
407         } else if (g_str_equal(type, "add_found_ap_noti")) {
408                 __net_popup_add_found_ap_noti();
409                 elm_exit();
410         } else if (g_str_equal(type, "del_found_ap_noti")) {
411                 __net_popup_del_found_ap_noti();
412                 elm_exit();
413         } else if (g_str_equal(type, "add_portal_noti")) {
414                 __net_popup_add_portal_noti(request);
415                 elm_exit();
416         } else if (g_str_equal(type, "del_portal_noti")) {
417                 __net_popup_del_portal_noti();
418                 elm_exit();
419         } else if (g_str_equal(type, "add_ip_conflict_noti")) {
420                 __net_popup_add_ip_conflict_noti(request);
421                 elm_exit();
422         } else if (g_str_equal(type, "del_ip_conflict_noti")) {
423                 __net_popup_del_ip_conflict_noti();
424                 elm_exit();
425         } else if (g_str_equal(type, "popup_user_resp")) {
426                 app_control_clone(&g_req_handle, request);
427                 __net_popup_show_popup_with_user_resp(request, data);
428         } else if (g_str_equal(type, "network_error_popup")) {
429                 __net_popup_show_network_error_popup(request, data);
430         } else {
431                 __net_popup_show_notification(request, data);
432                 elm_exit();
433         }
434
435         g_free(type);
436
437         return;
438 }
439
440 static void __net_popup_set_orientation(Evas_Object *win)
441 {
442         log_print(NET_POPUP, "__net_popup_set_orientation()\n");
443
444         int rots[4] = { 0, 90, 180, 270 };
445
446         if (!elm_win_wm_rotation_supported_get(win))
447                 return;
448
449         elm_win_wm_rotation_available_rotations_set(win, rots, 4);
450 }
451
452 static Evas_Object* __net_popup_create_win(void)
453 {
454         log_print(NET_POPUP, "__net_popup_create_win()\n");
455
456         Evas_Object *win = NULL;
457         Evas *e = NULL;
458         Ecore_Evas *ee = NULL;
459 #if 0
460         int w, h;
461 #endif
462
463         win = elm_win_add(NULL, PACKAGE, ELM_WIN_NOTIFICATION);
464
465         e = evas_object_evas_get(win);
466         ee = ecore_evas_ecore_evas_get(e);
467         ecore_evas_name_class_set(ee, "APP_POPUP", "APP_POPUP");
468
469         elm_win_alpha_set(win, EINA_TRUE);
470         elm_win_borderless_set(win, EINA_TRUE);
471 #if 0
472         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
473         evas_object_resize(win, w, h);
474         utilx_set_system_notification_level(ecore_x_display_get(),
475                                 elm_win_xwindow_get(win),
476                                 UTILX_NOTIFICATION_LEVEL_LOW);
477 #endif
478
479         __net_popup_set_orientation(win);
480
481         return win;
482 }
483
484 static void __launch_app_control(char *operation)
485 {
486         app_control_h app_control;
487
488         app_control_create(&app_control);
489         if (app_control == NULL) {
490                 log_print(NET_POPUP, "Failed to create app control handle");
491                 return;
492         }
493
494         app_control_set_operation(app_control, operation);
495         if (app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE)
496                 log_print(NET_POPUP, "Succeeded to launch %s", operation);
497         else
498                 log_print(NET_POPUP, "Failed to launch %s", operation);
499
500         app_control_destroy(app_control);
501 }
502
503 static void __data_roaming_check_changed_cb(void* data, Evas_Object* obj, void* event_info)
504 {
505         turn_on_roaming = elm_check_state_get(obj);
506         log_print(NET_POPUP, "Romaing(%d)", turn_on_roaming);
507 }
508
509 static void __do_not_show_check_changed_cb(void* data, Evas_Object* obj, void* event_info)
510 {
511         do_not_show_popup = elm_check_state_get(obj);
512         log_print(NET_POPUP, "Do not show again(%d)", do_not_show_popup);
513 }
514
515 static void _ok_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
516 {
517         log_print(NET_POPUP, "_ok_button_clicked_cb()\n");
518
519         if (data)
520                 evas_object_del(data);
521         elm_exit();
522 }
523
524 static void _cancel_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
525 {
526         log_print(NET_POPUP, "_cancel_button_clicked_cb()");
527
528         if (data)
529                 evas_object_del(data);
530
531         elm_exit();
532 }
533
534 static void _wifi_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
535 {
536         log_print(NET_POPUP, "_wifi_button_clicked_cb()");
537
538         __launch_app_control(APP_CONTROL_OPERATION_SETTING_WIFI);
539
540         if (data)
541                 evas_object_del(data);
542
543         elm_exit();
544 }
545
546 static void _settings_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
547 {
548         log_print(NET_POPUP, "_settings_button_clicked_cb()");
549
550         __launch_app_control(APP_CONTROL_OPERATION_SETTING);
551
552         if (data)
553                 evas_object_del(data);
554
555         elm_exit();
556 }
557
558 static void _retry_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
559 {
560         log_print(NET_POPUP, "_retry_button_clicked_cb()");
561
562         int ret = vconf_set_bool(VCONFKEY_3G_ENABLE, 1);
563         if (ret)
564                 log_print(NET_POPUP, "Failed to enable mobile data");
565
566         if (data)
567                 evas_object_del(data);
568
569         elm_exit();
570 }
571
572 static void _data_raoming_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
573 {
574         log_print(NET_POPUP, "_data_roaming_button_clicked_cb()");
575
576         int ret = vconf_set_bool(VCONFKEY_SETAPPL_STATE_DATA_ROAMING_BOOL, turn_on_roaming);
577         if (ret)
578                 log_print(NET_POPUP, "Failed to enable mobile data");
579
580         if (data)
581                 evas_object_del(data);
582
583         elm_exit();
584 }
585
586 static void _connect_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
587 {
588         log_print(NET_POPUP, "_connect_button_clicked_cb()");
589
590         int ret = vconf_set_bool(VCONFKEY_3G_ENABLE, 1);
591         if (ret)
592                 log_print(NET_POPUP, "Failed to enable mobile data");
593
594         if (data)
595                 evas_object_del(data);
596
597         elm_exit();
598 }
599
600 static void _timeout_cb(void *data, Evas_Object *obj, void *event_info)
601 {
602         log_print(NET_POPUP, "_timeout_cb()\n");
603
604         evas_object_del(obj);
605
606         elm_exit();
607 }
608
609 static int __toast_popup_show(app_control_h request, void *data)
610 {
611         log_print(NET_POPUP, "__toast_popup_show()\n");
612
613         char buf[ALERT_STR_LEN_MAX] = "";
614         int ret = 0;
615         char *mode = NULL;
616         Evas_Object *twin = NULL;
617         Evas_Object *tpop = NULL;
618         char *ap_name = NULL;
619         char *restricted_type = NULL;
620
621         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
622         if (ret != APP_CONTROL_ERROR_NONE) {
623                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
624                 g_free(mode);
625                 elm_exit();
626                 return 0;
627         }
628
629         log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
630
631         twin = __net_popup_create_win();
632         tpop = elm_popup_add(twin);
633         elm_object_style_set(tpop, "toast");
634         evas_object_size_hint_weight_set(tpop, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
635
636         elm_popup_timeout_set(tpop, 2.0);
637
638         evas_object_smart_callback_add(tpop, "timeout", _timeout_cb, twin);
639         if (strcmp(mode, "wrong password") == 0) {
640                 log_print(NET_POPUP, "alert wrong password\n");
641
642                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_ERR_WRONG_PASSWORD);
643         } else if (strcmp(mode, "no ap found") == 0) {
644                 log_print(NET_POPUP, "alert no ap found\n");
645
646                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_NO_AP_FOUND);
647         } else if (strcmp(mode, "unable to connect") == 0) {
648                 log_print(NET_POPUP, "alert no ap found\n");
649
650                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_ERR_CONNECT);
651         } else if (strcmp(mode, "wifi connected") == 0) {
652                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
653
654                 if (APP_CONTROL_ERROR_NONE != ret) {
655                         log_print(NET_POPUP, "Failed to get _AP_NAME_ ret = %d", ret);
656                         g_free(mode);
657                         return 0;
658                 }
659
660                 if (ap_name != NULL)
661                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
662                 else
663                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
664                 log_print(NET_POPUP, "alert wifi connected\n");
665                 g_free(ap_name);
666         } else if (strcmp(mode, "warn threshold crossed") == 0) {
667                 char *app_id = NULL;
668
669                 ret = app_control_get_extra_data(request, "_APP_ID_", &app_id);
670
671                 if (APP_CONTROL_ERROR_NONE != ret) {
672                         log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
673                         g_free(mode);
674                         return 0;
675                 }
676
677                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_WARNING);
678
679                 log_print(NET_POPUP, "alert warn threshold crossed [%s]\n", app_id);
680                 g_free(app_id);
681         } else if (strcmp(mode, "security restriction") == 0) {
682                 ret = app_control_get_extra_data(request, "_RESTRICTED_TYPE_", &restricted_type);
683                 if (APP_CONTROL_ERROR_NONE != ret) {
684                         log_print(NET_POPUP, "Failed to get _RESTRICTED_TYPE_ ret = %d", ret);
685                         g_free(mode);
686                         return 0;
687                 }
688
689                 if (strcmp(restricted_type, "wifi") == 0)
690                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_RESTRICTED_USE_WIFI);
691                 else if (strcmp(restricted_type, "wifi tethering") == 0)
692                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_WIFI_TETHERING);
693                 else if (strcmp(restricted_type, "bt tethering") == 0)
694                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_BT_TETHERING);
695                 else if (strcmp(restricted_type, "usb tethering") == 0)
696                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_USB_TETHERING);
697
698                 log_print(NET_POPUP, "alert security restriction\n");
699                 g_free(restricted_type);
700         } else
701                 log_print(NET_POPUP, "%s\n", mode);
702
703         elm_object_text_set(tpop, buf);
704         evas_object_show(tpop);
705         evas_object_show(twin);
706         g_free(mode);
707
708         return 0;
709 }
710
711 static int __net_popup_show_notification(app_control_h request, void *data)
712 {
713         log_print(NET_POPUP, "__net_popup_show_notification()\n");
714
715         int ret = 0;
716         char *mode = NULL;
717         char buf[ALERT_STR_LEN_MAX] = "";
718         char *ap_name = NULL;
719
720         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
721
722         if (APP_CONTROL_ERROR_NONE != ret) {
723                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_");
724                 return 0;
725         }
726
727         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
728
729         if (strcmp(mode, "connected") == 0) {
730                 notification_status_message_post(ALERT_STR_MOBILE_NETWORKS_CHARGE);
731                 log_print(NET_POPUP, "alert 3g\n");
732         } else if (strcmp(mode, "fail to connect") == 0) {
733                 notification_status_message_post(ALERT_STR_ERR_UNAVAILABLE);
734                 log_print(NET_POPUP, "alert err\n");
735         } else if (strcmp(mode, "unable to connect") == 0) {
736                 notification_status_message_post(ALERT_STR_ERR_CONNECT);
737                 log_print(NET_POPUP, "alert unable to connect\n");
738         } else if (strcmp(mode, "wrong password") == 0) {
739                 notification_status_message_post(ALERT_STR_ERR_WRONG_PASSWORD);
740                 log_print(NET_POPUP, "alert wrong password\n");
741         } else if (strcmp(mode, "not support") == 0) {
742                 notification_status_message_post(ALERT_STR_ERR_NOT_SUPPORT);
743                 log_print(NET_POPUP, "alert not support\n");
744         } else if (strcmp(mode, "wifi restricted") == 0) {
745                 notification_status_message_post(ALERT_STR_RESTRICTED_USE_WIFI);
746                 log_print(NET_POPUP, "alert wifi restricted\n");
747         } else if (strcmp(mode, "no ap found") == 0) {
748                 notification_status_message_post(ALERT_STR_NO_AP_FOUND);
749                 log_print(NET_POPUP, "alert no ap found\n");
750         } else if (strcmp(mode, "Lengthy Password") == 0) {
751                 notification_status_message_post(ALERT_STR_LENGHTY_PASSWORD);
752                 log_print(NET_POPUP, "Password entered crosses 64 bytes\n");
753         } else if (strcmp(mode, "Portal Login") == 0) {
754                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN);
755                 log_print(NET_POPUP, "Please login to access Internet\n");
756         } else if (strcmp(mode, "Portal Login Error") == 0) {
757                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN_ERROR);
758                 log_print(NET_POPUP, "Login not completed. Disconnected Wifi\n");
759         } else if (strcmp(mode, "wifi connected") == 0) {
760                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
761
762                 if (APP_CONTROL_ERROR_NONE != ret) {
763                         log_print(NET_POPUP, "Failed to get _AP_NAME_ ret = %d", ret);
764                         g_free(mode);
765                         return 0;
766                 }
767
768                 if (ap_name != NULL)
769                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
770                 else
771                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
772
773                 notification_status_message_post(buf);
774
775                 log_print(NET_POPUP, "alert wifi connected\n");
776                 g_free(ap_name);
777         } else if (strcmp(mode, "warn threshold crossed") == 0) {
778                 char buf[ALERT_STR_LEN_MAX] = "";
779                 char *app_id = NULL;
780
781                 ret = app_control_get_extra_data(request, "_APP_ID_", &app_id);
782
783                 if (APP_CONTROL_ERROR_NONE != ret) {
784                         log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
785                         g_free(mode);
786                         return 0;
787                 }
788
789                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_WARNING);
790
791                 notification_status_message_post(buf);
792
793                 log_print(NET_POPUP, "alert warn threshold crossed [%s]\n", app_id);
794                 g_free(app_id);
795         } else {
796                 notification_status_message_post(mode);
797                 log_print(NET_POPUP, "%s\n", mode);
798         }
799         g_free(mode);
800
801         return 0;
802 }
803
804 static int _net_popup_send_user_resp(char *resp, Eina_Bool state)
805 {
806         log_print(NET_POPUP, "_net_popup_send_user_resp()\n");
807
808         int ret = 0;
809         app_control_h reply = NULL;
810         char checkbox_str[USER_RESP_LEN] = { '\0', };
811
812         log_print(NET_POPUP, "Send the user response to the caller");
813         ret = app_control_create(&reply);
814         if (APP_CONTROL_ERROR_NONE != ret) {
815                 log_print(NET_POPUP, "Failed to create service ret = %d", ret);
816                 app_control_destroy(g_req_handle);
817                 g_req_handle = NULL;
818
819                 return false;
820         }
821
822         if (TRUE == state)
823                 g_strlcpy(checkbox_str, "TRUE", USER_RESP_LEN);
824         else
825                 g_strlcpy(checkbox_str, "FALSE", USER_RESP_LEN);
826
827         log_print(NET_POPUP, "Checkbox_str[%s]", checkbox_str);
828
829         ret = app_control_add_extra_data(reply, "_SYSPOPUP_RESP_", resp);
830         if (APP_CONTROL_ERROR_NONE == ret) {
831                 ret = app_control_add_extra_data(reply, "_SYSPOPUP_CHECKBOX_RESP_",
832                                 checkbox_str);
833                 if (APP_CONTROL_ERROR_NONE == ret) {
834                         ret = app_control_reply_to_launch_request(reply, g_req_handle,
835                                         APP_CONTROL_RESULT_SUCCEEDED);
836                         if (APP_CONTROL_ERROR_NONE == ret) {
837                                 log_print(NET_POPUP, "Service reply success");
838                                 ret = TRUE;
839                         } else {
840                                 log_print(NET_POPUP, "Service reply failed ret = %d", ret);
841                         }
842                 } else {
843                         log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
844                 }
845         } else {
846                 log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
847         }
848
849         app_control_destroy(reply);
850         app_control_destroy(g_req_handle);
851         g_req_handle = NULL;
852
853         return ret;
854 }
855
856 static Evas_Object *__net_popup_create_checkview_layout(Evas_Object *parent)
857 {
858         Evas_Object *layout = NULL;
859
860         layout = elm_layout_add(parent);
861         elm_layout_file_set(layout, NETPOPUP_EDJ, "popup_checkview");
862         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
863         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, 1.0);
864         elm_object_content_set(parent, layout);
865
866         return layout;
867 }
868
869 static Evas_Object *__net_popup_create_label(Evas_Object *parent)
870 {
871         Evas_Object *label = NULL;
872
873         label = elm_label_add(parent);
874         elm_object_style_set(label, "popup/default");
875         elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
876         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
877         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
878         evas_object_show(label);
879
880         return label;
881 }
882
883 static Evas_Object *__net_popup_create_cancel_button(Evas_Object *parent)
884 {
885         Evas_Object *btn = NULL;
886
887         btn = elm_button_add(parent);
888         elm_object_style_set(btn, "popup");
889         elm_object_text_set(btn, ALERT_STR_CANCEL);
890         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
891         evas_object_smart_callback_add(btn, "clicked", _cancel_button_clicked_cb, parent);
892
893         return btn;
894 }
895
896 static Evas_Object *__net_popup_create_wifi_button(Evas_Object *parent)
897 {
898         Evas_Object *btn = NULL;
899
900         btn = elm_button_add(parent);
901         elm_object_style_set(btn, "popup");
902         elm_object_text_set(btn, ALERT_STR_WIFI);
903         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
904         evas_object_smart_callback_add(btn, "clicked", _wifi_button_clicked_cb, parent);
905
906         return btn;
907 }
908
909 static Evas_Object *__net_popup_create_settings_button(Evas_Object *parent)
910 {
911         Evas_Object *btn = NULL;
912
913         btn = elm_button_add(parent);
914         elm_object_style_set(btn, "popup");
915         elm_object_text_set(btn, ALERT_STR_SETTINGS);
916         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
917         evas_object_smart_callback_add(btn, "clicked", _settings_button_clicked_cb, parent);
918
919         return btn;
920 }
921
922 static Evas_Object *__net_popup_create_retry_button(Evas_Object *parent)
923 {
924         Evas_Object *btn = NULL;
925
926         btn = elm_button_add(parent);
927         elm_object_style_set(btn, "popup");
928         elm_object_text_set(btn, ALERT_STR_RETRY);
929         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
930         evas_object_smart_callback_add(btn, "clicked", _retry_button_clicked_cb, parent);
931
932         return btn;
933 }
934
935 static Evas_Object *__net_popup_create_data_roaming_button(Evas_Object *parent)
936 {
937         Evas_Object *btn = NULL;
938
939         btn = elm_button_add(parent);
940         elm_object_style_set(btn, "popup");
941         elm_object_text_set(btn, ALERT_STR_OK);
942         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
943         evas_object_smart_callback_add(btn, "clicked", _data_raoming_button_clicked_cb, parent);
944
945         return btn;
946 }
947
948 static Evas_Object *__net_popup_create_connect_button(Evas_Object *parent)
949 {
950         Evas_Object *btn = NULL;
951
952         btn = elm_button_add(parent);
953         elm_object_style_set(btn, "popup");
954         elm_object_text_set(btn, ALERT_STR_VPN_CONNECT_BUTTON);
955         evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
956         evas_object_smart_callback_add(btn, "clicked", _connect_button_clicked_cb, parent);
957
958         return btn;
959 }
960
961 static int __net_popup_show_network_error_popup(app_control_h request, void *data)
962 {
963         log_print(NET_POPUP, "__net_popup_show_network_error_popup()\n");
964
965         Evas_Object *win;
966         Evas_Object *popup;
967         Evas_Object *layout;
968         Evas_Object *label;
969         Evas_Object *check;
970         Evas_Object *btn1, *btn2, *btn3;
971         int ret = 0;
972         char *mode = NULL;
973
974         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
975         if (APP_CONTROL_ERROR_NONE != ret) {
976                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
977                 g_free(mode);
978                 elm_exit();
979                 return 0;
980         }
981
982         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
983
984         win = __net_popup_create_win();
985         popup = elm_popup_add(win);
986         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
987
988         if (strcmp(mode, "connect_to_mobile_network") == 0) {
989                 elm_object_part_text_set(popup, "title,text", ALERT_STR_CONNECT_TO_MOBILE_NETWORK);
990                 layout = __net_popup_create_checkview_layout(popup);
991                 label = __net_popup_create_label(layout);
992                 elm_object_text_set(label, ALERT_STR_ROAMING_WITH_PAYMENT);
993                 elm_object_part_content_set(layout, "elm.swallow.content", label);
994                 check = elm_check_add(popup);
995                 elm_object_style_set(check, "popup");
996                 elm_object_part_content_set(layout, "elm.swallow.end", check);
997                 elm_object_text_set(check, ALERT_STR_DO_NOT_SHOW_AGAIN);
998                 elm_check_state_set(check, EINA_FALSE);
999                 evas_object_smart_callback_add(check, "changed",
1000                                 __do_not_show_check_changed_cb, NULL);
1001                 btn1 = __net_popup_create_cancel_button(popup);
1002                 elm_object_part_content_set(popup, "button1", btn1);
1003                 btn2 = __net_popup_create_connect_button(popup);
1004                 elm_object_part_content_set(popup, "button2", btn2);
1005         } else {
1006                 elm_object_part_text_set(popup, "title,text", ALERT_STR_NO_NETWORK_CONNECTION);
1007                 if (strcmp(mode, "flight_mode") == 0) {
1008                         elm_object_text_set(popup, ALERT_STR_CANT_CONNECT_TO_MOBILE);
1009                         btn1 = __net_popup_create_cancel_button(popup);
1010                         elm_object_part_content_set(popup, "button1", btn1);
1011                         btn2 = __net_popup_create_wifi_button(popup);
1012                         elm_object_part_content_set(popup, "button2", btn2);
1013                         btn3 = __net_popup_create_settings_button(popup);
1014                         elm_object_part_content_set(popup, "button3", btn3);
1015                 } else if (strcmp(mode, "mobile_data_is_turned_off") == 0) {
1016                         elm_object_text_set(popup, ALERT_STR_MOBILE_DATA_IS_TURNED_OFF);
1017                         btn1 = __net_popup_create_cancel_button(popup);
1018                         elm_object_part_content_set(popup, "button1", btn1);
1019                         btn2 = __net_popup_create_wifi_button(popup);
1020                         elm_object_part_content_set(popup, "button2", btn2);
1021                         btn3 = __net_popup_create_settings_button(popup);
1022                         elm_object_part_content_set(popup, "button3", btn3);
1023                 } else if (strcmp(mode, "no_mobile_networks") == 0) {
1024                         elm_object_text_set(popup, ALERT_STR_NO_MOBILE_NETWORKS);
1025                         btn1 = __net_popup_create_cancel_button(popup);
1026                         elm_object_part_content_set(popup, "button1", btn1);
1027                         btn2 = __net_popup_create_retry_button(popup);
1028                         elm_object_part_content_set(popup, "button2", btn2);
1029                 } else if (strcmp(mode, "roaming_with_check") == 0) {
1030                         layout = __net_popup_create_checkview_layout(popup);
1031                         label = __net_popup_create_label(layout);
1032                         elm_object_text_set(label, ALERT_STR_ROAMING_WITH_PAYMENT);
1033                         elm_object_part_content_set(layout, "elm.swallow.content", label);
1034                         check = elm_check_add(popup);
1035                         elm_object_style_set(check, "popup");
1036                         elm_object_part_content_set(layout, "elm.swallow.end", check);
1037                         elm_object_text_set(check, ALERT_STR_TURN_ON_DATA_ROAMING);
1038                         elm_check_state_set(check, EINA_FALSE);
1039                         evas_object_smart_callback_add(check, "changed",
1040                                         __data_roaming_check_changed_cb, NULL);
1041                         btn1 = __net_popup_create_data_roaming_button(popup);
1042                         elm_object_part_content_set(popup, "button1", btn1);
1043                 } else if (strcmp(mode, "roaming_with_settings") == 0) {
1044                         elm_object_text_set(popup, ALERT_STR_ROAMING);
1045                         btn1 = __net_popup_create_cancel_button(popup);
1046                         elm_object_part_content_set(popup, "button1", btn1);
1047                         btn2 = __net_popup_create_wifi_button(popup);
1048                         elm_object_part_content_set(popup, "button2", btn2);
1049                         btn3 = __net_popup_create_settings_button(popup);
1050                         elm_object_part_content_set(popup, "button3", btn3);
1051                 }
1052         }
1053
1054         evas_object_show(popup);
1055         evas_object_show(win);
1056         g_free(mode);
1057
1058         return 0;
1059 }
1060
1061 void _tethering_wifi_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
1062 {
1063         log_print(NET_POPUP, "_tethering_wifi_btn_yes_cb()\n");
1064
1065         bool result = FALSE;
1066         Evas_Object *popup = (Evas_Object *)data;
1067
1068         __net_popup_init_dbus();
1069         __net_popup_send_dbus_msg("progress_off");
1070         __net_popup_deinit_dbus();
1071
1072         result = _net_popup_send_user_resp(RESP_WIFI_TETHERING_OFF, FALSE);
1073         if (true != result)
1074                 log_print(NET_POPUP, "Failed to send user response ");
1075
1076         if (popup)
1077                 evas_object_del(popup);
1078
1079         elm_exit();
1080 }
1081
1082 void _tethering_wifi_ap_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
1083 {
1084         log_print(NET_POPUP, "_tethering_wifi_ap_btn_yes_cb()\n");
1085
1086         bool result = FALSE;
1087         Evas_Object *popup = (Evas_Object *)data;
1088
1089         __net_popup_init_dbus();
1090         __net_popup_send_dbus_msg("progress_off");
1091         __net_popup_deinit_dbus();
1092
1093         result = _net_popup_send_user_resp(RESP_WIFI_AP_TETHERING_OFF, FALSE);
1094         if (true != result)
1095                 log_print(NET_POPUP, "Failed to send user response ");
1096
1097         if (popup)
1098                 evas_object_del(popup);
1099
1100         elm_exit();
1101 }
1102
1103 static void _vpn_send_result(int result)
1104 {
1105         log_print(NET_POPUP, "Send the result of vpn-service to the caller");
1106
1107         int ret = 0;
1108         app_control_h reply = NULL;
1109         app_control_result_e resp_code;
1110
1111         ret = app_control_create(&reply);
1112         if (APP_CONTROL_ERROR_NONE != ret) {
1113                 log_print(NET_POPUP, "Failed to create service ret = %d", ret);
1114                 app_control_destroy(g_req_handle);
1115                 g_req_handle = NULL;
1116                 return;
1117         }
1118
1119         if (result == VPNSVC_ERROR_NONE)
1120                 resp_code = APP_CONTROL_RESULT_SUCCEEDED;
1121         else if (result == VPNSVC_ERROR_CANCELED)
1122                 resp_code = APP_CONTROL_RESULT_CANCELED;
1123         else
1124                 resp_code = APP_CONTROL_RESULT_FAILED;
1125
1126         ret = app_control_add_extra_data(reply, APP_CONTROL_DATA_TEXT, __get_vpn_error_message(result));
1127         if (APP_CONTROL_ERROR_NONE == ret) {
1128                 ret = app_control_reply_to_launch_request(reply, g_req_handle, resp_code);
1129                 if (APP_CONTROL_ERROR_NONE == ret)
1130                         log_print(NET_POPUP, "Service reply success");
1131                 else
1132                         log_print(NET_POPUP, "Service reply failed ret = %d", ret);
1133         } else {
1134                 log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
1135         }
1136
1137         app_control_destroy(reply);
1138         app_control_destroy(g_req_handle);
1139         g_req_handle = NULL;
1140
1141         return;
1142 }
1143
1144 void _vpn_btn_connect_cb(void *data, Evas_Object *obj, void *event_info)
1145 {
1146         log_print(NET_POPUP, "_vpn_btn_connect_cb()");
1147         Evas_Object *popup = (Evas_Object *)data;
1148         int ret = VPNSVC_ERROR_NONE;
1149
1150         ret = _vpnsvc_up(iface_name);
1151         _vpn_send_result(ret);
1152
1153         if (iface_name) {
1154                 g_free(iface_name);
1155                 iface_name = NULL;
1156         }
1157         if (popup)
1158                 evas_object_del(popup);
1159         if (obj)
1160                 evas_object_del(obj);
1161
1162         elm_exit();
1163 }
1164
1165 void _vpn_btn_disconnect_cb(void *data, Evas_Object *obj, void *event_info)
1166 {
1167         log_print(NET_POPUP, "_vpn_btn_disconnect_cb()");
1168         Evas_Object *popup = (Evas_Object *)data;
1169         int ret = VPNSVC_ERROR_NONE;
1170
1171         ret = _vpnsvc_down(iface_name);
1172         _vpn_send_result(ret);
1173
1174         if (iface_name) {
1175                 g_free(iface_name);
1176                 iface_name = NULL;
1177         }
1178         if (popup)
1179                 evas_object_del(popup);
1180         if (obj)
1181                 evas_object_del(obj);
1182
1183         elm_exit();
1184 }
1185
1186 void _vpn_btn_no_cb(void *data, Evas_Object *obj, void *event_info)
1187 {
1188         log_print(NET_POPUP, "_vpn_btn_no_cb()");
1189         Evas_Object *popup = (Evas_Object *)data;
1190
1191         _vpn_send_result(VPNSVC_ERROR_CANCELED);
1192
1193         if (iface_name) {
1194                 g_free(iface_name);
1195                 iface_name = NULL;
1196         }
1197         if (popup)
1198                 evas_object_del(popup);
1199         if (obj)
1200                 evas_object_del(obj);
1201
1202         elm_exit();
1203 }
1204
1205 void _btn_no_cb(void *data, Evas_Object *obj, void *event_info)
1206 {
1207         log_print(NET_POPUP, "_btn_no_cb()\n");
1208
1209         bool result = FALSE;
1210         Evas_Object *popup = (Evas_Object *)data;
1211
1212         result = _net_popup_send_user_resp(RESP_TETHERING_ON, FALSE);
1213         if (true != result)
1214                 log_print(NET_POPUP, "Failed to send user response ");
1215
1216         if (popup)
1217                 evas_object_del(popup);
1218
1219         elm_exit();
1220 }
1221
1222 static void __data_usage_notification(notification_type_e type,
1223         notification_ly_type_e ly_type, const char *title_text, const char *title_key,
1224         const char *content_text, const char *content_key, const char *launch_appid)
1225 {
1226         int ret = 0;
1227         int noti_flags = 0;
1228         char icon_path[ICON_PATH_LEN];
1229         notification_h noti = NULL;
1230         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1231         app_control_h service_handle = NULL;
1232
1233         noti = notification_create(type);
1234         if (noti == NULL) {
1235                 log_print(NET_POPUP, "Failed to create notification");
1236                 return;
1237         }
1238
1239         noti_err = notification_set_time(noti, time(NULL));
1240         if (noti_err != NOTIFICATION_ERROR_NONE) {
1241                 log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
1242                 goto error;
1243         }
1244
1245         g_snprintf(icon_path, sizeof(icon_path), "%s%s",
1246                 STC_NOTI_DATA_USAGE_ICON_PATH, STC_NOTI_DATA_USAGE_ICON_NAME);
1247         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
1248         if (noti_err != NOTIFICATION_ERROR_NONE) {
1249                 log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
1250                 goto error;
1251         }
1252
1253         noti_err = notification_set_layout(noti, ly_type);
1254         if (noti_err != NOTIFICATION_ERROR_NONE) {
1255                 log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
1256                 goto error;
1257         }
1258
1259         noti_err = notification_set_text_domain(noti, PACKAGE,
1260                         LOCALEDIR);
1261         if (noti_err != NOTIFICATION_ERROR_NONE) {
1262                 log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
1263                 goto error;
1264         }
1265
1266         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1267                         title_text, title_key,
1268                         NOTIFICATION_VARIABLE_TYPE_NONE);
1269         if (noti_err != NOTIFICATION_ERROR_NONE) {
1270                 log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
1271                 goto error;
1272         }
1273
1274         if (content_text) {
1275                 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1276                                 content_text, content_key,
1277                                 NOTIFICATION_VARIABLE_TYPE_NONE);
1278                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1279                         log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
1280                         goto error;
1281                 }
1282         }
1283
1284         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY |
1285                 NOTIFICATION_DISPLAY_APP_TICKER | NOTIFICATION_DISPLAY_APP_INDICATOR;
1286         noti_err = notification_set_display_applist(noti, noti_flags);
1287         if (noti_err != NOTIFICATION_ERROR_NONE) {
1288                 log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
1289                 goto error;
1290         }
1291
1292         if (launch_appid) {
1293                 ret = app_control_create(&service_handle);
1294                 log_print(NET_POPUP, "Service create ret[%d]", ret);
1295                 if (ret != APP_CONTROL_ERROR_NONE)
1296                         goto error;
1297
1298                 ret = app_control_set_app_id(service_handle, launch_appid);
1299                 log_print(NET_POPUP, "Service set app id ret = %d", ret);
1300                 if (ret != APP_CONTROL_ERROR_NONE)
1301                         goto error;
1302
1303                 ret = app_control_add_extra_data(service_handle, "caller", "notification");
1304                 log_print(NET_POPUP, "Service data addition ret = %d", ret);
1305                 if (ret != APP_CONTROL_ERROR_NONE)
1306                         goto error;
1307
1308                 noti_err = notification_set_launch_option(noti,
1309                                 NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1310                 if (noti_err != NOTIFICATION_ERROR_NONE) {
1311                         log_print(NET_POPUP, "Failed to notification_set_launch_option");
1312                         goto error;
1313                 }
1314         }
1315
1316         noti_err = notification_post(noti);
1317         if (noti_err != NOTIFICATION_ERROR_NONE) {
1318                 log_print(NET_POPUP, "Failed to insert notification[error# is %d]", noti_err);
1319                 goto error;
1320         }
1321
1322         log_print(NET_POPUP, "Successfully added notification");
1323
1324 error:
1325
1326         if (noti != NULL)
1327                 notification_free(noti);
1328 }
1329
1330 static void __data_usage_btn_on_cb(void *data, Evas_Object *obj, void *event_info)
1331 {
1332         log_print(NET_POPUP, "__data_usage_btn_on_cb()");
1333         Evas_Object *popup = (Evas_Object *)data;
1334
1335         __net_popup_init_dbus();
1336         __net_popup_send_data_usage_msg(data_usage_app_id, data_usage_iftype);
1337         __net_popup_deinit_dbus();
1338
1339         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1340                 NOTIFICATION_LY_ONGOING_EVENT,
1341                 STC_NOTIFICATION_RESTRICTION_ON_TITLE,
1342                 "IDS_SM_TMBODY_MOBILE_DATA_LIMIT_EXCEEDED_ABB",
1343                 NULL, NULL, NULL);
1344
1345         if (popup)
1346                 evas_object_del(popup);
1347         if (obj)
1348                 evas_object_del(obj);
1349
1350         g_free(data_usage_app_id);
1351         g_free(data_usage_iftype);
1352
1353         elm_exit();
1354 }
1355
1356 static void __data_usage_btn_ok_cb(void *data, Evas_Object *obj, void *event_info)
1357 {
1358         log_print(NET_POPUP, "__data_usage_btn_ok_cb()");
1359         Evas_Object *popup = (Evas_Object *)data;
1360
1361         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1362                 NOTIFICATION_LY_ONGOING_EVENT,
1363                 STC_NOTIFICATION_RESTRICTION_OK_TITLE,
1364                 "IDS_SM_HEADER_MOBILE_DATA_TURNED_OFF_ABB2",
1365                 STC_NOTIFICATION_RESTRICTION_OK_CONTENT,
1366                 "IDS_SM_SBODY_TAP_HERE_TO_TURN_IT_ON_AGAIN_ABB",
1367                 DATA_USAGE_APPID);
1368
1369         if (popup)
1370                 evas_object_del(popup);
1371         if (obj)
1372                 evas_object_del(obj);
1373
1374         g_free(data_usage_app_id);
1375         g_free(data_usage_iftype);
1376
1377         elm_exit();
1378 }
1379
1380 static void __net_popup_show_popup_with_user_resp(app_control_h request,
1381                 void *data)
1382 {
1383         log_print(NET_POPUP, "__net_popup_show_popup_with_user_resp()\n");
1384
1385         Evas_Object *win;
1386         Evas_Object *popup;
1387         Evas_Object *layout;
1388         Evas_Object *label;
1389         Evas_Object *btn1;
1390         Evas_Object *btn2;
1391         int ret = 0;
1392
1393         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &resp_popup_mode);
1394         if (APP_CONTROL_ERROR_NONE != ret)
1395                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
1396
1397         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", resp_popup_mode);
1398
1399         win = __net_popup_create_win();
1400         evas_object_show(win);
1401
1402         popup = elm_popup_add(win);
1403         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
1404                         EVAS_HINT_EXPAND);
1405
1406         if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0 ||
1407                         g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0) {
1408                 log_print(NET_POPUP, "Drawing Wi-Fi Tethering OFF popup");
1409
1410                 __net_popup_init_dbus();
1411                 elm_object_part_text_set(popup, "title,text", ALERT_STR_WIFI);
1412
1413                 layout = elm_layout_add(popup);
1414                 elm_layout_file_set(layout, NETPOPUP_EDJ, "popup");
1415                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
1416                                 EVAS_HINT_EXPAND);
1417
1418                 __net_popup_send_dbus_msg("progress_on");
1419                 label = elm_label_add(popup);
1420                 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
1421                 elm_object_text_set(label, ALERT_STR_WIFI_MOBILE_AP_ON);
1422                 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
1423                                 EVAS_HINT_EXPAND);
1424                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1425                 evas_object_show(label);
1426
1427                 elm_object_part_content_set(layout, "elm.swallow.content", label);
1428                 evas_object_show(layout);
1429                 elm_object_style_set(label, "popup/default");
1430                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _btn_no_cb, popup);
1431                 elm_object_content_set(popup, label);
1432
1433                 btn1 = elm_button_add(popup);
1434                 elm_object_style_set(btn1, "popup");
1435                 elm_object_text_set(btn1, ALERT_STR_CANCEL);
1436                 elm_object_part_content_set(popup, "button1", btn1);
1437                 evas_object_smart_callback_add(btn1, "clicked",
1438                                         _btn_no_cb, popup);
1439
1440                 btn2 = elm_button_add(popup);
1441                 elm_object_style_set(btn2, "popup");
1442                 elm_object_text_set(btn2, ALERT_STR_OK);
1443                 elm_object_part_content_set(popup, "button2", btn2);
1444
1445                 if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0)
1446                         evas_object_smart_callback_add(btn2, "clicked",
1447                                 _tethering_wifi_btn_yes_cb, popup);
1448                 else if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0)
1449                         evas_object_smart_callback_add(btn2, "clicked",
1450                                 _tethering_wifi_ap_btn_yes_cb, popup);
1451
1452                 evas_object_show(popup);
1453                 evas_object_show(win);
1454                 __net_popup_deinit_dbus();
1455         }
1456 }
1457
1458 static void __net_popup_show_vpn_popup(app_control_h request, void *data)
1459 {
1460         Evas_Object *win;
1461         Evas_Object *popup;
1462         Evas_Object *button1;
1463         Evas_Object *button2;
1464         char *type = NULL;
1465         char *title = NULL;
1466         char *content = NULL;
1467         char *ok_btn = NULL;
1468         void *ok_cb = NULL;
1469
1470         log_print(NET_POPUP, "__net_popup_show_vpn_popup");
1471
1472         int ret = app_control_get_extra_data(request, APP_CONTROL_DATA_TYPE, &type);
1473         if (APP_CONTROL_ERROR_NONE != ret) {
1474                 log_print(NET_POPUP, "Failed to get APP_CONTROL_DATA_TYPE ret = %d", ret);
1475                 elm_exit();
1476                 return;
1477         }
1478
1479         ret = app_control_get_extra_data(request, APP_CONTROL_DATA_NAME, &iface_name);
1480         if (APP_CONTROL_ERROR_NONE != ret) {
1481                 log_print(NET_POPUP, "Failed to get APP_CONTROL_DATA_NAME ret = %d", ret);
1482                 elm_exit();
1483                 return;
1484         }
1485         log_print(NET_POPUP, "type(%s) name(%s)", type, iface_name);
1486
1487         if (strcmp(type, "up") == 0) {
1488                 title = ALERT_STR_VPN_CONNECT_TITLE;
1489                 content = ALERT_STR_VPN_CONNECT_CONTENT;
1490                 ok_btn = ALERT_STR_VPN_CONNECT_BUTTON;
1491                 ok_cb = _vpn_btn_connect_cb;
1492         } else if (strcmp(type, "down") == 0) {
1493                 title = ALERT_STR_VPN_DISCONNECT_TITLE;
1494                 content = ALERT_STR_VPN_DISCONNECT_CONTENT;
1495                 ok_btn = ALERT_STR_VPN_DISCONNECT_BUTTON;
1496                 ok_cb = _vpn_btn_disconnect_cb;
1497         } else {
1498                 log_print(NET_POPUP, "Invalid appcontrol value");
1499                 elm_exit();
1500                 return;
1501         }
1502
1503         log_print(NET_POPUP, "title(%s) content(%s) ok(%s)", title, content, ok_btn);
1504
1505         win = __net_popup_create_win();
1506
1507         popup = elm_popup_add(win);
1508         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1509
1510         elm_object_text_set(popup, content);
1511         elm_object_part_text_set(popup, "title,text", title);
1512
1513         /* Cancel button */
1514         button1 = elm_button_add(popup);
1515         elm_object_style_set(button1, "bottom");
1516         elm_object_text_set(button1, ALERT_STR_CANCEL);
1517         elm_object_part_content_set(popup, "button1", button1);
1518         evas_object_smart_callback_add(button1, "clicked", _vpn_btn_no_cb, popup);
1519
1520         /* OK button */
1521         button2 = elm_button_add(popup);
1522         elm_object_style_set(button2, "bottom");
1523         elm_object_text_set(button2, ok_btn);
1524         elm_object_part_content_set(popup, "button2", button2);
1525         evas_object_smart_callback_add(button2, "clicked", ok_cb, popup);
1526
1527         evas_object_show(popup);
1528         evas_object_show(win);
1529
1530         return;
1531 }
1532
1533 static void __net_popup_show_warning_noti(app_control_h request, void *data)
1534 {
1535         log_print(NET_POPUP, "__net_popup_show_warning_noti()\n");
1536
1537         int ret = app_control_get_extra_data(request, "_APP_ID_", &data_usage_app_id);
1538         if (APP_CONTROL_ERROR_NONE != ret) {
1539                 log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
1540                 elm_exit();
1541                 return;
1542         }
1543
1544         if (strcmp(data_usage_app_id, STC_TOTAL_DATACALL) &&
1545                 strcmp(data_usage_app_id, STC_TOTAL_WIFI) &&
1546                 strcmp(data_usage_app_id, STC_TOTAL_BLUETOOTH)) {
1547                 log_print(NET_POPUP, "It's not total data usage [%s]", data_usage_app_id);
1548                 g_free(data_usage_app_id);
1549                 elm_exit();
1550                 return;
1551         }
1552
1553         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1554                 NOTIFICATION_LY_ONGOING_EVENT,
1555                 STC_NOTIFICATION_WARNING_TITLE,
1556                 "IDS_COM_BODY_DATA_USAGE_WARNING",
1557                 STC_NOTIFICATION_WARNING_CONTENT,
1558                 "IDS_SM_SBODY_TAP_HERE_TO_VIEW_YOUR_DATA_USAGE_ABB",
1559                 DATA_USAGE_APPID);
1560 }
1561
1562 static void __net_popup_show_restriction_noti(app_control_h request, void *data)
1563 {
1564         Evas_Object *win;
1565         Evas_Object *popup;
1566         Evas_Object *button1;
1567         Evas_Object *button2;
1568         char *title = NULL;
1569         char *content = NULL;
1570         char *limit = NULL;
1571         char *on_btn = NULL;
1572         char *ok_btn = NULL;
1573         char buf[ALERT_STR_LEN_MAX] = "";
1574
1575         log_print(NET_POPUP, "__net_popup_show_data_usage_popup");
1576
1577         int ret = app_control_get_extra_data(request, "_APP_ID_", &data_usage_app_id);
1578         if (APP_CONTROL_ERROR_NONE != ret) {
1579                 log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
1580                 elm_exit();
1581                 return;
1582         }
1583
1584         if (strcmp(data_usage_app_id, STC_TOTAL_DATACALL) &&
1585                 strcmp(data_usage_app_id, STC_TOTAL_WIFI) &&
1586                 strcmp(data_usage_app_id, STC_TOTAL_BLUETOOTH)) {
1587                 log_print(NET_POPUP, "It's not total data usage [%s]", data_usage_app_id);
1588                 g_free(data_usage_app_id);
1589                 elm_exit();
1590                 return;
1591         }
1592
1593         ret = app_control_get_extra_data(request, "_IF_TYPE_", &data_usage_iftype);
1594         if (APP_CONTROL_ERROR_NONE != ret) {
1595                 log_print(NET_POPUP, "Failed to get _IF_TYPE_ ret = %d", ret);
1596                 g_free(data_usage_app_id);
1597                 elm_exit();
1598                 return;
1599         }
1600
1601         ret = app_control_get_extra_data(request, "_RESTRICTION_LIMIT_", &limit);
1602         if (APP_CONTROL_ERROR_NONE != ret) {
1603                 log_print(NET_POPUP, "Failed to get _RESTRICTION_LIMIT_ ret = %d", ret);
1604                 g_free(data_usage_app_id);
1605                 g_free(data_usage_iftype);
1606                 elm_exit();
1607                 return;
1608         }
1609
1610         title = ALERT_STR_DATA_USAGE_TITLE;
1611         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_CONTENT, limit);
1612         content = buf;
1613         on_btn = ALERT_STR_DATA_USAGE_TURN_ON_BUTTON;
1614         ok_btn = ALERT_STR_OK;
1615
1616         log_print(NET_POPUP, "title(%s) content(%s) app_id(%s) iftype(%s) limit(%s)",
1617                 title, content, data_usage_app_id, data_usage_iftype, limit);
1618
1619         win = __net_popup_create_win();
1620
1621         popup = elm_popup_add(win);
1622         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1623
1624         elm_object_text_set(popup, content);
1625         elm_object_part_text_set(popup, "title,text", title);
1626
1627         /* ON button */
1628         button1 = elm_button_add(popup);
1629         elm_object_style_set(button1, "bottom");
1630         elm_object_text_set(button1, on_btn);
1631         elm_object_part_content_set(popup, "button1", button1);
1632         evas_object_smart_callback_add(button1, "clicked", __data_usage_btn_on_cb, popup);
1633
1634         /* OK button */
1635         button2 = elm_button_add(popup);
1636         elm_object_style_set(button2, "bottom");
1637         elm_object_text_set(button2, ok_btn);
1638         elm_object_part_content_set(popup, "button2", button2);
1639         evas_object_smart_callback_add(button2, "clicked", __data_usage_btn_ok_cb, popup);
1640
1641         evas_object_show(popup);
1642         evas_object_show(win);
1643
1644         return;
1645 }
1646
1647 static int __net_popup_show_popup(app_control_h request, void *data)
1648 {
1649         log_print(NET_POPUP, "__net_popup_show_popup()\n");
1650
1651         Evas_Object *win;
1652         Evas_Object *popup;
1653         Evas_Object *button;
1654         int ret = 0;
1655         char *mode = NULL;
1656
1657         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
1658         if (APP_CONTROL_ERROR_NONE != ret) {
1659                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
1660                 g_free(mode);
1661                 elm_exit();
1662                 return 0;
1663         }
1664
1665         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
1666
1667         win = __net_popup_create_win();
1668
1669         popup = elm_popup_add(win);
1670         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1671         if (strcmp(mode, "connected") == 0) {
1672                 elm_object_text_set(popup, ALERT_STR_MOBILE_NETWORKS_CHARGE);
1673                 log_print(NET_POPUP, "alert 3g\n");
1674         } else if (strcmp(mode, "fail to connect") == 0) {
1675                 elm_object_text_set(popup, ALERT_STR_ERR_UNAVAILABLE);
1676                 log_print(NET_POPUP, "alert err\n");
1677         } else if (strcmp(mode, "unable to connect") == 0) {
1678                 elm_object_text_set(popup, ALERT_STR_ERR_CONNECT);
1679                 log_print(NET_POPUP, "alert unable to connect\n");
1680         } else if (strcmp(mode, "wrong password") == 0) {
1681                 elm_object_text_set(popup, ALERT_STR_ERR_WRONG_PASSWORD);
1682                 log_print(NET_POPUP, "alert wrong password\n");
1683         } else if (strcmp(mode, "not support") == 0) {
1684                 elm_object_text_set(popup, ALERT_STR_ERR_NOT_SUPPORT);
1685                 log_print(NET_POPUP, "alert not support\n");
1686         } else if (strcmp(mode, "wifi restricted") == 0) {
1687                 elm_object_text_set(popup, ALERT_STR_RESTRICTED_USE_WIFI);
1688                 log_print(NET_POPUP, "alert wifi restricted\n");
1689         } else if (strcmp(mode, "no ap found") == 0) {
1690                 elm_object_text_set(popup, ALERT_STR_NO_AP_FOUND);
1691                 log_print(NET_POPUP, "alert no ap found\n");
1692         } else if (strcmp(mode, "wifi connected") == 0) {
1693                 char buf[ALERT_STR_LEN_MAX] = "";
1694                 char *ap_name = NULL;
1695
1696                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
1697
1698                 if (ap_name != NULL)
1699                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
1700                 else
1701                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
1702
1703                 elm_object_text_set(popup, buf);
1704
1705                 log_print(NET_POPUP, "alert wifi connected\n");
1706                 g_free(ap_name);
1707         } else {
1708                 elm_object_text_set(popup, mode);
1709                 log_print(NET_POPUP, "%s\n", mode);
1710         }
1711
1712         button = elm_button_add(popup);
1713         elm_object_style_set(button, "popup");
1714         elm_object_text_set(button, ALERT_STR_OK);
1715         elm_object_part_content_set(popup, "button1", button);
1716         evas_object_smart_callback_add(button, "clicked", _ok_button_clicked_cb, popup);
1717         evas_object_show(popup);
1718         evas_object_show(win);
1719         g_free(mode);
1720
1721         return 0;
1722 }
1723
1724 static void __net_popup_add_found_ap_noti(void)
1725 {
1726         log_print(NET_POPUP, "__net_popup_add_found_ap_noti()\n");
1727
1728         int ret = 0, noti_flags = 0;
1729         char icon_path[ICON_PATH_LEN];
1730         notification_h noti = NULL;
1731         notification_list_h noti_list = NULL;
1732         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1733         app_control_h service_handle = NULL;
1734
1735         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
1736                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
1737         if (noti_list != NULL) {
1738                 notification_free_list(noti_list);
1739                 return;
1740         }
1741
1742         noti = notification_create(NOTIFICATION_TYPE_ONGOING);
1743         if (noti == NULL) {
1744                 log_print(NET_POPUP, "Failed to create notification");
1745                 return;
1746         }
1747
1748         noti_err = notification_set_time(noti, time(NULL));
1749         if (noti_err != NOTIFICATION_ERROR_NONE) {
1750                 log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
1751                 goto error;
1752         }
1753
1754         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
1755         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
1756         if (noti_err != NOTIFICATION_ERROR_NONE) {
1757                 log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
1758                 goto error;
1759         }
1760
1761         noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
1762         if (noti_err != NOTIFICATION_ERROR_NONE) {
1763                 log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
1764                 goto error;
1765         }
1766
1767         noti_err = notification_set_text_domain(noti, PACKAGE,
1768                         LOCALEDIR);
1769         if (noti_err != NOTIFICATION_ERROR_NONE) {
1770                 log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
1771                 goto error;
1772         }
1773
1774         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1775                         NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE,
1776                         "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE",
1777                         NOTIFICATION_VARIABLE_TYPE_NONE);
1778         if (noti_err != NOTIFICATION_ERROR_NONE) {
1779                 log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
1780                 goto error;
1781         }
1782
1783         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1784                         NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT,
1785                         "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT",
1786                         NOTIFICATION_VARIABLE_TYPE_NONE);
1787         if (noti_err != NOTIFICATION_ERROR_NONE) {
1788                 log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
1789                 goto error;
1790         }
1791
1792         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
1793         noti_err = notification_set_display_applist(noti, noti_flags);
1794         if (noti_err != NOTIFICATION_ERROR_NONE) {
1795                 log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
1796                 goto error;
1797         }
1798
1799         ret = app_control_create(&service_handle);
1800         log_print(NET_POPUP, "Service create ret[%d]", ret);
1801         if (ret != APP_CONTROL_ERROR_NONE)
1802                 goto error;
1803
1804         ret = app_control_set_app_id(service_handle, NET_WIFIQS_APPID);
1805         log_print(NET_POPUP, "Service set app id ret = %d", ret);
1806         if (ret != APP_CONTROL_ERROR_NONE)
1807                 goto error;
1808
1809         ret = app_control_add_extra_data(service_handle, "caller", "notification");
1810         log_print(NET_POPUP, "Service data addition ret = %d", ret);
1811         if (ret != APP_CONTROL_ERROR_NONE)
1812                 goto error;
1813
1814         noti_err = notification_set_launch_option(noti,
1815                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1816         if (noti_err != NOTIFICATION_ERROR_NONE) {
1817                 log_print(NET_POPUP, "Failed to notification_set_launch_option");
1818                 goto error;
1819         }
1820
1821         noti_err = notification_post(noti);
1822         if (noti_err != NOTIFICATION_ERROR_NONE) {
1823                 log_print(NET_POPUP, "Failed to insert notification[error# is %d]", noti_err);
1824                 goto error;
1825         }
1826
1827         log_print(NET_POPUP, "Successfully added notification");
1828
1829 error:
1830
1831         if (noti != NULL)
1832                 notification_free(noti);
1833 }
1834
1835 static void __net_popup_del_found_ap_noti(void)
1836 {
1837         log_print(NET_POPUP, "__net_popup_del_found_ap_noti()\n");
1838
1839         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1840
1841         noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
1842         if (noti_err != NOTIFICATION_ERROR_NONE) {
1843                 log_print(NET_POPUP, "fail to notification_delete_by_priv_id");
1844                 return;
1845         }
1846
1847         log_print(NET_POPUP, "Successfully deleted notification");
1848 }
1849
1850 static void __net_popup_add_ip_conflict_noti(app_control_h request)
1851 {
1852         log_print(NET_POPUP, "__net_popup_add_portal_noti()\n");
1853
1854         int ret = 0;
1855         int noti_flags = 0;
1856         char *mac = NULL;
1857         char icon_path[ICON_PATH_LEN];
1858         notification_h noti = NULL;
1859         app_control_h service_handle = NULL;
1860         notification_list_h noti_list = NULL;
1861         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1862
1863         ret = app_control_get_extra_data(request, "_MAC_ADDRESS_", &mac);
1864
1865         if (mac == NULL || ret != APP_CONTROL_ERROR_NONE) {
1866                 log_print(NET_POPUP, "Failed to retrieve mac address!!");
1867                 g_free(mac);
1868                 return;
1869         }
1870
1871         log_print(NET_POPUP, "Successfully added notification");
1872
1873         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
1874                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
1875         if (noti_list != NULL) {
1876                 notification_free_list(noti_list);
1877                 g_free(mac);
1878                 return;
1879         }
1880
1881         noti = notification_create(NOTIFICATION_TYPE_NOTI);
1882         if (noti == NULL) {
1883                 log_print(NET_POPUP, "fail to create notification");
1884                 g_free(mac);
1885                 return;
1886         }
1887
1888         noti_err = notification_set_time(noti, time(NULL));
1889         if (noti_err != NOTIFICATION_ERROR_NONE) {
1890                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
1891                 goto error;
1892         }
1893
1894         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
1895                         NETCONFIG_NOTIFICATION_WIFI_ICON_LITE);
1896         if (noti_err != NOTIFICATION_ERROR_NONE) {
1897                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
1898                 goto error;
1899         }
1900
1901         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range_ongoing.png");
1902         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
1903         if (noti_err != NOTIFICATION_ERROR_NONE) {
1904                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
1905                 goto error;
1906         }
1907
1908         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
1909         if (noti_err != NOTIFICATION_ERROR_NONE) {
1910                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
1911                 goto error;
1912         }
1913
1914         noti_err = notification_set_text_domain(noti, PACKAGE,
1915                         LOCALEDIR);
1916         if (noti_err != NOTIFICATION_ERROR_NONE) {
1917                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
1918                 goto error;
1919         }
1920
1921         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1922                         NETCONFIG_NOTIFICATION_IP_CONFLICT_TITLE,
1923                         "IDS_IP_CONFLICT",
1924                         NOTIFICATION_VARIABLE_TYPE_NONE);
1925         if (noti_err != NOTIFICATION_ERROR_NONE) {
1926                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
1927                 goto error;
1928         }
1929
1930         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1931                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1932                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1933                         NOTIFICATION_VARIABLE_TYPE_STRING, mac,
1934                         NOTIFICATION_VARIABLE_TYPE_NONE);
1935         if (noti_err != NOTIFICATION_ERROR_NONE) {
1936                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
1937                 goto error;
1938         }
1939
1940         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
1941         noti_err = notification_set_display_applist(noti, noti_flags);
1942         if (noti_err != NOTIFICATION_ERROR_NONE) {
1943                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
1944                 goto error;
1945         }
1946
1947         ret = app_control_create(&service_handle);
1948         log_print(NET_POPUP, "service create ret[%d]", ret);
1949         if (ret != APP_CONTROL_ERROR_NONE)
1950                 goto error;
1951
1952         ret = app_control_set_app_id(service_handle, WIFI_EFL_UG);
1953         log_print(NET_POPUP, "Service set app id ret = %d", ret);
1954         if (ret != APP_CONTROL_ERROR_NONE)
1955                 goto error;
1956
1957         ret = app_control_add_extra_data(service_handle, "caller", "notification");
1958         log_print(NET_POPUP, "Service data addition ret = %d", ret);
1959         if (ret != APP_CONTROL_ERROR_NONE)
1960                 goto error;
1961
1962         noti_err = notification_set_launch_option(noti,
1963                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1964         if (noti_err != NOTIFICATION_ERROR_NONE) {
1965                 log_print(NET_POPUP, "fail to notification_set_launch_option");
1966                 goto error;
1967         }
1968
1969         noti_err = notification_post(noti);
1970         if (noti_err != NOTIFICATION_ERROR_NONE) {
1971                 log_print(NET_POPUP, "fail to notification_post");
1972                 goto error;
1973         }
1974
1975         log_print(NET_POPUP, "Successfully added notification");
1976
1977 error:
1978         g_free(mac);
1979         if (noti != NULL)
1980                 notification_free(noti);
1981
1982         if (service_handle != NULL)
1983                 app_control_destroy(service_handle);
1984 }
1985
1986 static void __net_popup_add_portal_noti(app_control_h request)
1987 {
1988         log_print(NET_POPUP, "__net_popup_add_portal_noti()\n");
1989
1990         int ret = 0;
1991         int noti_flags = 0;
1992         char *ap_name = NULL;
1993         char icon_path[ICON_PATH_LEN];
1994         notification_h noti = NULL;
1995         app_control_h service_handle = NULL;
1996         notification_list_h noti_list = NULL;
1997         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1998
1999         ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
2000
2001         if (ap_name == NULL || ret != APP_CONTROL_ERROR_NONE) {
2002                 log_print(NET_POPUP, "Failed to retrieve connected AP name!!");
2003                 g_free(ap_name);
2004                 return;
2005         }
2006
2007         log_print(NET_POPUP, "Successfully added notification");
2008
2009         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
2010                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
2011         if (noti_list != NULL) {
2012                 notification_free_list(noti_list);
2013                 g_free(ap_name);
2014                 return;
2015         }
2016
2017         noti = notification_create(NOTIFICATION_TYPE_NOTI);
2018         if (noti == NULL) {
2019                 log_print(NET_POPUP, "fail to create notification");
2020                 g_free(ap_name);
2021                 return;
2022         }
2023
2024         noti_err = notification_set_time(noti, time(NULL));
2025         if (noti_err != NOTIFICATION_ERROR_NONE) {
2026                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
2027                 goto error;
2028         }
2029
2030         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2031                         NETCONFIG_NOTIFICATION_WIFI_ICON);
2032         if (noti_err != NOTIFICATION_ERROR_NONE) {
2033                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
2034                 goto error;
2035         }
2036
2037         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
2038         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
2039         if (noti_err != NOTIFICATION_ERROR_NONE) {
2040                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
2041                 goto error;
2042         }
2043         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
2044         if (noti_err != NOTIFICATION_ERROR_NONE) {
2045                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
2046                 goto error;
2047         }
2048
2049         noti_err = notification_set_text_domain(noti, PACKAGE,
2050                         LOCALEDIR);
2051         if (noti_err != NOTIFICATION_ERROR_NONE) {
2052                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
2053                 goto error;
2054         }
2055
2056         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2057                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE,
2058                         "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB",
2059                         NOTIFICATION_VARIABLE_TYPE_NONE);
2060         if (noti_err != NOTIFICATION_ERROR_NONE) {
2061                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
2062                 goto error;
2063         }
2064
2065         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2066                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
2067                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
2068                         NOTIFICATION_VARIABLE_TYPE_STRING, ap_name,
2069                         NOTIFICATION_VARIABLE_TYPE_NONE);
2070         if (noti_err != NOTIFICATION_ERROR_NONE) {
2071                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
2072                 goto error;
2073         }
2074
2075         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
2076         noti_err = notification_set_display_applist(noti, noti_flags);
2077         if (noti_err != NOTIFICATION_ERROR_NONE) {
2078                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
2079                 goto error;
2080         }
2081
2082         ret = app_control_create(&service_handle);
2083         log_print(NET_POPUP, "service create ret[%d]", ret);
2084         if (ret != APP_CONTROL_ERROR_NONE)
2085                 goto error;
2086
2087         ret = app_control_set_operation(service_handle, APP_CONTROL_OPERATION_VIEW);
2088         if (ret != APP_CONTROL_ERROR_NONE)
2089                 goto error;
2090
2091         log_print(NET_POPUP, "service set operation is successful");
2092
2093         ret = app_control_set_uri(service_handle, "http://www.google.com");
2094
2095         if (ret != APP_CONTROL_ERROR_NONE)
2096                 goto error;
2097
2098         noti_err = notification_set_launch_option(noti,
2099                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
2100         if (noti_err != NOTIFICATION_ERROR_NONE) {
2101                 log_print(NET_POPUP, "fail to notification_set_launch_option");
2102                 goto error;
2103         }
2104
2105         noti_err = notification_post(noti);
2106         if (noti_err != NOTIFICATION_ERROR_NONE) {
2107                 log_print(NET_POPUP, "fail to notification_post");
2108                 goto error;
2109         }
2110
2111         log_print(NET_POPUP, "Successfully added notification");
2112
2113 error:
2114         g_free(ap_name);
2115         if (noti != NULL)
2116                 notification_free(noti);
2117
2118         if (service_handle != NULL)
2119                 app_control_destroy(service_handle);
2120 }
2121
2122 static void __net_popup_del_ip_conflict_noti(void)
2123 {
2124         log_print(NET_POPUP, "__net_popup_del_ip_conflict_noti()\n");
2125
2126         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
2127
2128         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
2129         if (noti_err != NOTIFICATION_ERROR_NONE) {
2130                 log_print(NET_POPUP, "fail to notification_delete_all");
2131                 return;
2132         }
2133
2134         log_print(NET_POPUP, "Successfully deleted notification");
2135 }
2136
2137 static void __net_popup_del_portal_noti(void)
2138 {
2139         log_print(NET_POPUP, "__net_popup_del_portal_noti()\n");
2140
2141         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
2142
2143         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
2144         if (noti_err != NOTIFICATION_ERROR_NONE) {
2145                 log_print(NET_POPUP, "fail to notification_delete_all");
2146                 return;
2147         }
2148
2149         log_print(NET_POPUP, "Successfully deleted notification");
2150 }
2151
2152 EXPORT_API int main(int argc, char *argv[])
2153 {
2154         log_print(NET_POPUP, "main()\n");
2155
2156         ui_app_lifecycle_callback_s app_callback = {
2157                 .create = __net_popup_create,
2158                 .terminate = __net_popup_terminate,
2159                 .pause = __net_popup_pause,
2160                 .resume = __net_popup_resume,
2161                 .app_control = __net_popup_service_cb,
2162         };
2163
2164         return ui_app_main(argc, argv, &app_callback, NULL);
2165 }
2166