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