Fix memory leak on app_control handle
[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         if (service_handle)
1330                 app_control_destroy(service_handle);
1331 }
1332
1333 static void __data_usage_btn_on_cb(void *data, Evas_Object *obj, void *event_info)
1334 {
1335         log_print(NET_POPUP, "__data_usage_btn_on_cb()");
1336         Evas_Object *popup = (Evas_Object *)data;
1337
1338         __net_popup_init_dbus();
1339         __net_popup_send_data_usage_msg(data_usage_app_id, data_usage_iftype);
1340         __net_popup_deinit_dbus();
1341
1342         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1343                 NOTIFICATION_LY_ONGOING_EVENT,
1344                 STC_NOTIFICATION_RESTRICTION_ON_TITLE,
1345                 "IDS_SM_TMBODY_MOBILE_DATA_LIMIT_EXCEEDED_ABB",
1346                 NULL, NULL, NULL);
1347
1348         if (popup)
1349                 evas_object_del(popup);
1350         if (obj)
1351                 evas_object_del(obj);
1352
1353         g_free(data_usage_app_id);
1354         g_free(data_usage_iftype);
1355
1356         elm_exit();
1357 }
1358
1359 static void __data_usage_btn_ok_cb(void *data, Evas_Object *obj, void *event_info)
1360 {
1361         log_print(NET_POPUP, "__data_usage_btn_ok_cb()");
1362         Evas_Object *popup = (Evas_Object *)data;
1363
1364         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1365                 NOTIFICATION_LY_ONGOING_EVENT,
1366                 STC_NOTIFICATION_RESTRICTION_OK_TITLE,
1367                 "IDS_SM_HEADER_MOBILE_DATA_TURNED_OFF_ABB2",
1368                 STC_NOTIFICATION_RESTRICTION_OK_CONTENT,
1369                 "IDS_SM_SBODY_TAP_HERE_TO_TURN_IT_ON_AGAIN_ABB",
1370                 DATA_USAGE_APPID);
1371
1372         if (popup)
1373                 evas_object_del(popup);
1374         if (obj)
1375                 evas_object_del(obj);
1376
1377         g_free(data_usage_app_id);
1378         g_free(data_usage_iftype);
1379
1380         elm_exit();
1381 }
1382
1383 static void __net_popup_show_popup_with_user_resp(app_control_h request,
1384                 void *data)
1385 {
1386         log_print(NET_POPUP, "__net_popup_show_popup_with_user_resp()\n");
1387
1388         Evas_Object *win;
1389         Evas_Object *popup;
1390         Evas_Object *layout;
1391         Evas_Object *label;
1392         Evas_Object *btn1;
1393         Evas_Object *btn2;
1394         int ret = 0;
1395
1396         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &resp_popup_mode);
1397         if (APP_CONTROL_ERROR_NONE != ret)
1398                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
1399
1400         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", resp_popup_mode);
1401
1402         win = __net_popup_create_win();
1403         evas_object_show(win);
1404
1405         popup = elm_popup_add(win);
1406         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
1407                         EVAS_HINT_EXPAND);
1408
1409         if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0 ||
1410                         g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0) {
1411                 log_print(NET_POPUP, "Drawing Wi-Fi Tethering OFF popup");
1412
1413                 __net_popup_init_dbus();
1414                 elm_object_part_text_set(popup, "title,text", ALERT_STR_WIFI);
1415
1416                 layout = elm_layout_add(popup);
1417                 elm_layout_file_set(layout, NETPOPUP_EDJ, "popup");
1418                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
1419                                 EVAS_HINT_EXPAND);
1420
1421                 __net_popup_send_dbus_msg("progress_on");
1422                 label = elm_label_add(popup);
1423                 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
1424                 elm_object_text_set(label, ALERT_STR_WIFI_MOBILE_AP_ON);
1425                 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
1426                                 EVAS_HINT_EXPAND);
1427                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1428                 evas_object_show(label);
1429
1430                 elm_object_part_content_set(layout, "elm.swallow.content", label);
1431                 evas_object_show(layout);
1432                 elm_object_style_set(label, "popup/default");
1433                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _btn_no_cb, popup);
1434                 elm_object_content_set(popup, label);
1435
1436                 btn1 = elm_button_add(popup);
1437                 elm_object_style_set(btn1, "popup");
1438                 elm_object_text_set(btn1, ALERT_STR_CANCEL);
1439                 elm_object_part_content_set(popup, "button1", btn1);
1440                 evas_object_smart_callback_add(btn1, "clicked",
1441                                         _btn_no_cb, popup);
1442
1443                 btn2 = elm_button_add(popup);
1444                 elm_object_style_set(btn2, "popup");
1445                 elm_object_text_set(btn2, ALERT_STR_OK);
1446                 elm_object_part_content_set(popup, "button2", btn2);
1447
1448                 if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0)
1449                         evas_object_smart_callback_add(btn2, "clicked",
1450                                 _tethering_wifi_btn_yes_cb, popup);
1451                 else if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0)
1452                         evas_object_smart_callback_add(btn2, "clicked",
1453                                 _tethering_wifi_ap_btn_yes_cb, popup);
1454
1455                 evas_object_show(popup);
1456                 evas_object_show(win);
1457                 __net_popup_deinit_dbus();
1458         }
1459 }
1460
1461 static void __net_popup_show_vpn_popup(app_control_h request, void *data)
1462 {
1463         Evas_Object *win;
1464         Evas_Object *popup;
1465         Evas_Object *button1;
1466         Evas_Object *button2;
1467         char *type = NULL;
1468         char *title = NULL;
1469         char *content = NULL;
1470         char *ok_btn = NULL;
1471         void *ok_cb = NULL;
1472
1473         log_print(NET_POPUP, "__net_popup_show_vpn_popup");
1474
1475         int ret = app_control_get_extra_data(request, APP_CONTROL_DATA_TYPE, &type);
1476         if (APP_CONTROL_ERROR_NONE != ret) {
1477                 log_print(NET_POPUP, "Failed to get APP_CONTROL_DATA_TYPE ret = %d", ret);
1478                 elm_exit();
1479                 return;
1480         }
1481
1482         ret = app_control_get_extra_data(request, APP_CONTROL_DATA_NAME, &iface_name);
1483         if (APP_CONTROL_ERROR_NONE != ret) {
1484                 log_print(NET_POPUP, "Failed to get APP_CONTROL_DATA_NAME ret = %d", ret);
1485                 elm_exit();
1486                 return;
1487         }
1488         log_print(NET_POPUP, "type(%s) name(%s)", type, iface_name);
1489
1490         if (strcmp(type, "up") == 0) {
1491                 title = ALERT_STR_VPN_CONNECT_TITLE;
1492                 content = ALERT_STR_VPN_CONNECT_CONTENT;
1493                 ok_btn = ALERT_STR_VPN_CONNECT_BUTTON;
1494                 ok_cb = _vpn_btn_connect_cb;
1495         } else if (strcmp(type, "down") == 0) {
1496                 title = ALERT_STR_VPN_DISCONNECT_TITLE;
1497                 content = ALERT_STR_VPN_DISCONNECT_CONTENT;
1498                 ok_btn = ALERT_STR_VPN_DISCONNECT_BUTTON;
1499                 ok_cb = _vpn_btn_disconnect_cb;
1500         } else {
1501                 log_print(NET_POPUP, "Invalid appcontrol value");
1502                 elm_exit();
1503                 return;
1504         }
1505
1506         log_print(NET_POPUP, "title(%s) content(%s) ok(%s)", title, content, ok_btn);
1507
1508         win = __net_popup_create_win();
1509
1510         popup = elm_popup_add(win);
1511         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1512
1513         elm_object_text_set(popup, content);
1514         elm_object_part_text_set(popup, "title,text", title);
1515
1516         /* Cancel button */
1517         button1 = elm_button_add(popup);
1518         elm_object_style_set(button1, "bottom");
1519         elm_object_text_set(button1, ALERT_STR_CANCEL);
1520         elm_object_part_content_set(popup, "button1", button1);
1521         evas_object_smart_callback_add(button1, "clicked", _vpn_btn_no_cb, popup);
1522
1523         /* OK button */
1524         button2 = elm_button_add(popup);
1525         elm_object_style_set(button2, "bottom");
1526         elm_object_text_set(button2, ok_btn);
1527         elm_object_part_content_set(popup, "button2", button2);
1528         evas_object_smart_callback_add(button2, "clicked", ok_cb, popup);
1529
1530         evas_object_show(popup);
1531         evas_object_show(win);
1532
1533         return;
1534 }
1535
1536 static void __net_popup_show_warning_noti(app_control_h request, void *data)
1537 {
1538         log_print(NET_POPUP, "__net_popup_show_warning_noti()\n");
1539
1540         int ret = app_control_get_extra_data(request, "_APP_ID_", &data_usage_app_id);
1541         if (APP_CONTROL_ERROR_NONE != ret) {
1542                 log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
1543                 elm_exit();
1544                 return;
1545         }
1546
1547         if (strcmp(data_usage_app_id, STC_TOTAL_DATACALL) &&
1548                 strcmp(data_usage_app_id, STC_TOTAL_WIFI) &&
1549                 strcmp(data_usage_app_id, STC_TOTAL_BLUETOOTH)) {
1550                 log_print(NET_POPUP, "It's not total data usage [%s]", data_usage_app_id);
1551                 g_free(data_usage_app_id);
1552                 elm_exit();
1553                 return;
1554         }
1555
1556         __data_usage_notification(NOTIFICATION_TYPE_ONGOING,
1557                 NOTIFICATION_LY_ONGOING_EVENT,
1558                 STC_NOTIFICATION_WARNING_TITLE,
1559                 "IDS_COM_BODY_DATA_USAGE_WARNING",
1560                 STC_NOTIFICATION_WARNING_CONTENT,
1561                 "IDS_SM_SBODY_TAP_HERE_TO_VIEW_YOUR_DATA_USAGE_ABB",
1562                 DATA_USAGE_APPID);
1563 }
1564
1565 static void __net_popup_show_restriction_noti(app_control_h request, void *data)
1566 {
1567         Evas_Object *win;
1568         Evas_Object *popup;
1569         Evas_Object *button1;
1570         Evas_Object *button2;
1571         char *title = NULL;
1572         char *content = NULL;
1573         char *limit = NULL;
1574         char *on_btn = NULL;
1575         char *ok_btn = NULL;
1576         char buf[ALERT_STR_LEN_MAX] = "";
1577
1578         log_print(NET_POPUP, "__net_popup_show_data_usage_popup");
1579
1580         int ret = app_control_get_extra_data(request, "_APP_ID_", &data_usage_app_id);
1581         if (APP_CONTROL_ERROR_NONE != ret) {
1582                 log_print(NET_POPUP, "Failed to get _APP_ID_ ret = %d", ret);
1583                 elm_exit();
1584                 return;
1585         }
1586
1587         if (strcmp(data_usage_app_id, STC_TOTAL_DATACALL) &&
1588                 strcmp(data_usage_app_id, STC_TOTAL_WIFI) &&
1589                 strcmp(data_usage_app_id, STC_TOTAL_BLUETOOTH)) {
1590                 log_print(NET_POPUP, "It's not total data usage [%s]", data_usage_app_id);
1591                 g_free(data_usage_app_id);
1592                 elm_exit();
1593                 return;
1594         }
1595
1596         ret = app_control_get_extra_data(request, "_IF_TYPE_", &data_usage_iftype);
1597         if (APP_CONTROL_ERROR_NONE != ret) {
1598                 log_print(NET_POPUP, "Failed to get _IF_TYPE_ ret = %d", ret);
1599                 g_free(data_usage_app_id);
1600                 elm_exit();
1601                 return;
1602         }
1603
1604         ret = app_control_get_extra_data(request, "_RESTRICTION_LIMIT_", &limit);
1605         if (APP_CONTROL_ERROR_NONE != ret) {
1606                 log_print(NET_POPUP, "Failed to get _RESTRICTION_LIMIT_ ret = %d", ret);
1607                 g_free(data_usage_app_id);
1608                 g_free(data_usage_iftype);
1609                 elm_exit();
1610                 return;
1611         }
1612
1613         title = ALERT_STR_DATA_USAGE_TITLE;
1614         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_DATA_USAGE_CONTENT, limit);
1615         content = buf;
1616         on_btn = ALERT_STR_DATA_USAGE_TURN_ON_BUTTON;
1617         ok_btn = ALERT_STR_OK;
1618
1619         log_print(NET_POPUP, "title(%s) content(%s) app_id(%s) iftype(%s) limit(%s)",
1620                 title, content, data_usage_app_id, data_usage_iftype, limit);
1621
1622         win = __net_popup_create_win();
1623
1624         popup = elm_popup_add(win);
1625         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1626
1627         elm_object_text_set(popup, content);
1628         elm_object_part_text_set(popup, "title,text", title);
1629
1630         /* ON button */
1631         button1 = elm_button_add(popup);
1632         elm_object_style_set(button1, "bottom");
1633         elm_object_text_set(button1, on_btn);
1634         elm_object_part_content_set(popup, "button1", button1);
1635         evas_object_smart_callback_add(button1, "clicked", __data_usage_btn_on_cb, popup);
1636
1637         /* OK button */
1638         button2 = elm_button_add(popup);
1639         elm_object_style_set(button2, "bottom");
1640         elm_object_text_set(button2, ok_btn);
1641         elm_object_part_content_set(popup, "button2", button2);
1642         evas_object_smart_callback_add(button2, "clicked", __data_usage_btn_ok_cb, popup);
1643
1644         evas_object_show(popup);
1645         evas_object_show(win);
1646
1647         return;
1648 }
1649
1650 static int __net_popup_show_popup(app_control_h request, void *data)
1651 {
1652         log_print(NET_POPUP, "__net_popup_show_popup()\n");
1653
1654         Evas_Object *win;
1655         Evas_Object *popup;
1656         Evas_Object *button;
1657         int ret = 0;
1658         char *mode = NULL;
1659
1660         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
1661         if (APP_CONTROL_ERROR_NONE != ret) {
1662                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
1663                 g_free(mode);
1664                 elm_exit();
1665                 return 0;
1666         }
1667
1668         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
1669
1670         win = __net_popup_create_win();
1671
1672         popup = elm_popup_add(win);
1673         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1674         if (strcmp(mode, "connected") == 0) {
1675                 elm_object_text_set(popup, ALERT_STR_MOBILE_NETWORKS_CHARGE);
1676                 log_print(NET_POPUP, "alert 3g\n");
1677         } else if (strcmp(mode, "fail to connect") == 0) {
1678                 elm_object_text_set(popup, ALERT_STR_ERR_UNAVAILABLE);
1679                 log_print(NET_POPUP, "alert err\n");
1680         } else if (strcmp(mode, "unable to connect") == 0) {
1681                 elm_object_text_set(popup, ALERT_STR_ERR_CONNECT);
1682                 log_print(NET_POPUP, "alert unable to connect\n");
1683         } else if (strcmp(mode, "wrong password") == 0) {
1684                 elm_object_text_set(popup, ALERT_STR_ERR_WRONG_PASSWORD);
1685                 log_print(NET_POPUP, "alert wrong password\n");
1686         } else if (strcmp(mode, "not support") == 0) {
1687                 elm_object_text_set(popup, ALERT_STR_ERR_NOT_SUPPORT);
1688                 log_print(NET_POPUP, "alert not support\n");
1689         } else if (strcmp(mode, "wifi restricted") == 0) {
1690                 elm_object_text_set(popup, ALERT_STR_RESTRICTED_USE_WIFI);
1691                 log_print(NET_POPUP, "alert wifi restricted\n");
1692         } else if (strcmp(mode, "no ap found") == 0) {
1693                 elm_object_text_set(popup, ALERT_STR_NO_AP_FOUND);
1694                 log_print(NET_POPUP, "alert no ap found\n");
1695         } else if (strcmp(mode, "wifi connected") == 0) {
1696                 char buf[ALERT_STR_LEN_MAX] = "";
1697                 char *ap_name = NULL;
1698
1699                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
1700
1701                 if (ap_name != NULL)
1702                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
1703                 else
1704                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
1705
1706                 elm_object_text_set(popup, buf);
1707
1708                 log_print(NET_POPUP, "alert wifi connected\n");
1709                 g_free(ap_name);
1710         } else {
1711                 elm_object_text_set(popup, mode);
1712                 log_print(NET_POPUP, "%s\n", mode);
1713         }
1714
1715         button = elm_button_add(popup);
1716         elm_object_style_set(button, "popup");
1717         elm_object_text_set(button, ALERT_STR_OK);
1718         elm_object_part_content_set(popup, "button1", button);
1719         evas_object_smart_callback_add(button, "clicked", _ok_button_clicked_cb, popup);
1720         evas_object_show(popup);
1721         evas_object_show(win);
1722         g_free(mode);
1723
1724         return 0;
1725 }
1726
1727 static void __net_popup_add_found_ap_noti(void)
1728 {
1729         log_print(NET_POPUP, "__net_popup_add_found_ap_noti()\n");
1730
1731         int ret = 0, noti_flags = 0;
1732         char icon_path[ICON_PATH_LEN];
1733         notification_h noti = NULL;
1734         notification_list_h noti_list = NULL;
1735         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1736         app_control_h service_handle = NULL;
1737
1738         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
1739                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
1740         if (noti_list != NULL) {
1741                 notification_free_list(noti_list);
1742                 return;
1743         }
1744
1745         noti = notification_create(NOTIFICATION_TYPE_ONGOING);
1746         if (noti == NULL) {
1747                 log_print(NET_POPUP, "Failed to create notification");
1748                 return;
1749         }
1750
1751         noti_err = notification_set_time(noti, time(NULL));
1752         if (noti_err != NOTIFICATION_ERROR_NONE) {
1753                 log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
1754                 goto error;
1755         }
1756
1757         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
1758         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
1759         if (noti_err != NOTIFICATION_ERROR_NONE) {
1760                 log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
1761                 goto error;
1762         }
1763
1764         noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
1765         if (noti_err != NOTIFICATION_ERROR_NONE) {
1766                 log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
1767                 goto error;
1768         }
1769
1770         noti_err = notification_set_text_domain(noti, PACKAGE,
1771                         LOCALEDIR);
1772         if (noti_err != NOTIFICATION_ERROR_NONE) {
1773                 log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
1774                 goto error;
1775         }
1776
1777         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1778                         NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE,
1779                         "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE",
1780                         NOTIFICATION_VARIABLE_TYPE_NONE);
1781         if (noti_err != NOTIFICATION_ERROR_NONE) {
1782                 log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
1783                 goto error;
1784         }
1785
1786         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1787                         NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT,
1788                         "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT",
1789                         NOTIFICATION_VARIABLE_TYPE_NONE);
1790         if (noti_err != NOTIFICATION_ERROR_NONE) {
1791                 log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
1792                 goto error;
1793         }
1794
1795         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
1796         noti_err = notification_set_display_applist(noti, noti_flags);
1797         if (noti_err != NOTIFICATION_ERROR_NONE) {
1798                 log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
1799                 goto error;
1800         }
1801
1802         ret = app_control_create(&service_handle);
1803         log_print(NET_POPUP, "Service create ret[%d]", ret);
1804         if (ret != APP_CONTROL_ERROR_NONE)
1805                 goto error;
1806
1807         ret = app_control_set_app_id(service_handle, NET_WIFIQS_APPID);
1808         log_print(NET_POPUP, "Service set app id ret = %d", ret);
1809         if (ret != APP_CONTROL_ERROR_NONE)
1810                 goto error;
1811
1812         ret = app_control_add_extra_data(service_handle, "caller", "notification");
1813         log_print(NET_POPUP, "Service data addition ret = %d", ret);
1814         if (ret != APP_CONTROL_ERROR_NONE)
1815                 goto error;
1816
1817         noti_err = notification_set_launch_option(noti,
1818                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1819         if (noti_err != NOTIFICATION_ERROR_NONE) {
1820                 log_print(NET_POPUP, "Failed to notification_set_launch_option");
1821                 goto error;
1822         }
1823
1824         noti_err = notification_post(noti);
1825         if (noti_err != NOTIFICATION_ERROR_NONE) {
1826                 log_print(NET_POPUP, "Failed to insert notification[error# is %d]", noti_err);
1827                 goto error;
1828         }
1829
1830         log_print(NET_POPUP, "Successfully added notification");
1831
1832 error:
1833
1834         if (noti != NULL)
1835                 notification_free(noti);
1836 }
1837
1838 static void __net_popup_del_found_ap_noti(void)
1839 {
1840         log_print(NET_POPUP, "__net_popup_del_found_ap_noti()\n");
1841
1842         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1843
1844         noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
1845         if (noti_err != NOTIFICATION_ERROR_NONE) {
1846                 log_print(NET_POPUP, "fail to notification_delete_by_priv_id");
1847                 return;
1848         }
1849
1850         log_print(NET_POPUP, "Successfully deleted notification");
1851 }
1852
1853 static void __net_popup_add_ip_conflict_noti(app_control_h request)
1854 {
1855         log_print(NET_POPUP, "__net_popup_add_portal_noti()\n");
1856
1857         int ret = 0;
1858         int noti_flags = 0;
1859         char *mac = NULL;
1860         char icon_path[ICON_PATH_LEN];
1861         notification_h noti = NULL;
1862         app_control_h service_handle = NULL;
1863         notification_list_h noti_list = NULL;
1864         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1865
1866         ret = app_control_get_extra_data(request, "_MAC_ADDRESS_", &mac);
1867
1868         if (mac == NULL || ret != APP_CONTROL_ERROR_NONE) {
1869                 log_print(NET_POPUP, "Failed to retrieve mac address!!");
1870                 g_free(mac);
1871                 return;
1872         }
1873
1874         log_print(NET_POPUP, "Successfully added notification");
1875
1876         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
1877                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
1878         if (noti_list != NULL) {
1879                 notification_free_list(noti_list);
1880                 g_free(mac);
1881                 return;
1882         }
1883
1884         noti = notification_create(NOTIFICATION_TYPE_NOTI);
1885         if (noti == NULL) {
1886                 log_print(NET_POPUP, "fail to create notification");
1887                 g_free(mac);
1888                 return;
1889         }
1890
1891         noti_err = notification_set_time(noti, time(NULL));
1892         if (noti_err != NOTIFICATION_ERROR_NONE) {
1893                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
1894                 goto error;
1895         }
1896
1897         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
1898                         NETCONFIG_NOTIFICATION_WIFI_ICON_LITE);
1899         if (noti_err != NOTIFICATION_ERROR_NONE) {
1900                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
1901                 goto error;
1902         }
1903
1904         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range_ongoing.png");
1905         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
1906         if (noti_err != NOTIFICATION_ERROR_NONE) {
1907                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
1908                 goto error;
1909         }
1910
1911         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
1912         if (noti_err != NOTIFICATION_ERROR_NONE) {
1913                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
1914                 goto error;
1915         }
1916
1917         noti_err = notification_set_text_domain(noti, PACKAGE,
1918                         LOCALEDIR);
1919         if (noti_err != NOTIFICATION_ERROR_NONE) {
1920                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
1921                 goto error;
1922         }
1923
1924         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1925                         NETCONFIG_NOTIFICATION_IP_CONFLICT_TITLE,
1926                         "IDS_IP_CONFLICT",
1927                         NOTIFICATION_VARIABLE_TYPE_NONE);
1928         if (noti_err != NOTIFICATION_ERROR_NONE) {
1929                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
1930                 goto error;
1931         }
1932
1933         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1934                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1935                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1936                         NOTIFICATION_VARIABLE_TYPE_STRING, mac,
1937                         NOTIFICATION_VARIABLE_TYPE_NONE);
1938         if (noti_err != NOTIFICATION_ERROR_NONE) {
1939                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
1940                 goto error;
1941         }
1942
1943         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
1944         noti_err = notification_set_display_applist(noti, noti_flags);
1945         if (noti_err != NOTIFICATION_ERROR_NONE) {
1946                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
1947                 goto error;
1948         }
1949
1950         ret = app_control_create(&service_handle);
1951         log_print(NET_POPUP, "service create ret[%d]", ret);
1952         if (ret != APP_CONTROL_ERROR_NONE)
1953                 goto error;
1954
1955         ret = app_control_set_app_id(service_handle, WIFI_EFL_UG);
1956         log_print(NET_POPUP, "Service set app id ret = %d", ret);
1957         if (ret != APP_CONTROL_ERROR_NONE)
1958                 goto error;
1959
1960         ret = app_control_add_extra_data(service_handle, "caller", "notification");
1961         log_print(NET_POPUP, "Service data addition ret = %d", ret);
1962         if (ret != APP_CONTROL_ERROR_NONE)
1963                 goto error;
1964
1965         noti_err = notification_set_launch_option(noti,
1966                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1967         if (noti_err != NOTIFICATION_ERROR_NONE) {
1968                 log_print(NET_POPUP, "fail to notification_set_launch_option");
1969                 goto error;
1970         }
1971
1972         noti_err = notification_post(noti);
1973         if (noti_err != NOTIFICATION_ERROR_NONE) {
1974                 log_print(NET_POPUP, "fail to notification_post");
1975                 goto error;
1976         }
1977
1978         log_print(NET_POPUP, "Successfully added notification");
1979
1980 error:
1981         g_free(mac);
1982         if (noti != NULL)
1983                 notification_free(noti);
1984
1985         if (service_handle != NULL)
1986                 app_control_destroy(service_handle);
1987 }
1988
1989 static void __net_popup_add_portal_noti(app_control_h request)
1990 {
1991         log_print(NET_POPUP, "__net_popup_add_portal_noti()\n");
1992
1993         int ret = 0;
1994         int noti_flags = 0;
1995         char *ap_name = NULL;
1996         char icon_path[ICON_PATH_LEN];
1997         notification_h noti = NULL;
1998         app_control_h service_handle = NULL;
1999         notification_list_h noti_list = NULL;
2000         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
2001
2002         ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
2003
2004         if (ap_name == NULL || ret != APP_CONTROL_ERROR_NONE) {
2005                 log_print(NET_POPUP, "Failed to retrieve connected AP name!!");
2006                 g_free(ap_name);
2007                 return;
2008         }
2009
2010         log_print(NET_POPUP, "Successfully added notification");
2011
2012         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
2013                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
2014         if (noti_list != NULL) {
2015                 notification_free_list(noti_list);
2016                 g_free(ap_name);
2017                 return;
2018         }
2019
2020         noti = notification_create(NOTIFICATION_TYPE_NOTI);
2021         if (noti == NULL) {
2022                 log_print(NET_POPUP, "fail to create notification");
2023                 g_free(ap_name);
2024                 return;
2025         }
2026
2027         noti_err = notification_set_time(noti, time(NULL));
2028         if (noti_err != NOTIFICATION_ERROR_NONE) {
2029                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
2030                 goto error;
2031         }
2032
2033         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
2034                         NETCONFIG_NOTIFICATION_WIFI_ICON);
2035         if (noti_err != NOTIFICATION_ERROR_NONE) {
2036                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
2037                 goto error;
2038         }
2039
2040         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
2041         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
2042         if (noti_err != NOTIFICATION_ERROR_NONE) {
2043                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
2044                 goto error;
2045         }
2046         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
2047         if (noti_err != NOTIFICATION_ERROR_NONE) {
2048                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
2049                 goto error;
2050         }
2051
2052         noti_err = notification_set_text_domain(noti, PACKAGE,
2053                         LOCALEDIR);
2054         if (noti_err != NOTIFICATION_ERROR_NONE) {
2055                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
2056                 goto error;
2057         }
2058
2059         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
2060                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE,
2061                         "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB",
2062                         NOTIFICATION_VARIABLE_TYPE_NONE);
2063         if (noti_err != NOTIFICATION_ERROR_NONE) {
2064                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
2065                 goto error;
2066         }
2067
2068         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
2069                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
2070                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
2071                         NOTIFICATION_VARIABLE_TYPE_STRING, ap_name,
2072                         NOTIFICATION_VARIABLE_TYPE_NONE);
2073         if (noti_err != NOTIFICATION_ERROR_NONE) {
2074                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
2075                 goto error;
2076         }
2077
2078         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
2079         noti_err = notification_set_display_applist(noti, noti_flags);
2080         if (noti_err != NOTIFICATION_ERROR_NONE) {
2081                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
2082                 goto error;
2083         }
2084
2085         ret = app_control_create(&service_handle);
2086         log_print(NET_POPUP, "service create ret[%d]", ret);
2087         if (ret != APP_CONTROL_ERROR_NONE)
2088                 goto error;
2089
2090         ret = app_control_set_operation(service_handle, APP_CONTROL_OPERATION_VIEW);
2091         if (ret != APP_CONTROL_ERROR_NONE)
2092                 goto error;
2093
2094         log_print(NET_POPUP, "service set operation is successful");
2095
2096         ret = app_control_set_uri(service_handle, "http://www.google.com");
2097
2098         if (ret != APP_CONTROL_ERROR_NONE)
2099                 goto error;
2100
2101         noti_err = notification_set_launch_option(noti,
2102                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
2103         if (noti_err != NOTIFICATION_ERROR_NONE) {
2104                 log_print(NET_POPUP, "fail to notification_set_launch_option");
2105                 goto error;
2106         }
2107
2108         noti_err = notification_post(noti);
2109         if (noti_err != NOTIFICATION_ERROR_NONE) {
2110                 log_print(NET_POPUP, "fail to notification_post");
2111                 goto error;
2112         }
2113
2114         log_print(NET_POPUP, "Successfully added notification");
2115
2116 error:
2117         g_free(ap_name);
2118         if (noti != NULL)
2119                 notification_free(noti);
2120
2121         if (service_handle != NULL)
2122                 app_control_destroy(service_handle);
2123 }
2124
2125 static void __net_popup_del_ip_conflict_noti(void)
2126 {
2127         log_print(NET_POPUP, "__net_popup_del_ip_conflict_noti()\n");
2128
2129         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
2130
2131         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
2132         if (noti_err != NOTIFICATION_ERROR_NONE) {
2133                 log_print(NET_POPUP, "fail to notification_delete_all");
2134                 return;
2135         }
2136
2137         log_print(NET_POPUP, "Successfully deleted notification");
2138 }
2139
2140 static void __net_popup_del_portal_noti(void)
2141 {
2142         log_print(NET_POPUP, "__net_popup_del_portal_noti()\n");
2143
2144         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
2145
2146         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
2147         if (noti_err != NOTIFICATION_ERROR_NONE) {
2148                 log_print(NET_POPUP, "fail to notification_delete_all");
2149                 return;
2150         }
2151
2152         log_print(NET_POPUP, "Successfully deleted notification");
2153 }
2154
2155 EXPORT_API int main(int argc, char *argv[])
2156 {
2157         log_print(NET_POPUP, "main()\n");
2158
2159         ui_app_lifecycle_callback_s app_callback = {
2160                 .create = __net_popup_create,
2161                 .terminate = __net_popup_terminate,
2162                 .pause = __net_popup_pause,
2163                 .resume = __net_popup_resume,
2164                 .app_control = __net_popup_service_cb,
2165         };
2166
2167         return ui_app_main(argc, argv, &app_callback, NULL);
2168 }
2169