App control sets app id when add found ap noti
[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.0 (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 <appsvc.h>
31 #include <vconf.h>
32 #include <vconf-keys.h>
33 #include <gio/gio.h>
34 #include <dbus/dbus.h>
35 #include <efl_extension.h>
36 #include <tzplatform_config.h>
37
38 #include "net-popup.h"
39 #include "net-popup-strings.h"
40
41 #define NET_WIFIQS_APPID        "net.wifi-qs"
42
43 #define LOCALEDIR                       "/usr/share/locale"
44 #define NETPOPUP_EDJ                    tzplatform_mkpath(TZ_SYS_RO_UG, "/res/edje/net-popup/netpopup-custom.edj")
45 #define QP_PRELOAD_NOTI_ICON_PATH       tzplatform_mkpath(TZ_SYS_RO_APP, "/org.tizen.quickpanel/shared/res/noti_icons/Wi-Fi")
46
47 #define NETCONFIG_NOTIFICATION_WIFI_ICON \
48                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range.png")
49 #define NETCONFIG_NOTIFICATION_WIFI_ICON_LITE \
50                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range_ongoing.png")
51 #define NETCONFIG_NOTIFICATION_WIFI_CAPTIVE_ICON \
52                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/B03_notify_Wi-fi_range.png")
53 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON \
54                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/Q02_Notification_wifi_in_range.png")
55 #define NETCONFIG_NOTIFICATION_WIFI_IN_RANGE_ICON_LITE \
56                                         tzplatform_mkpath(TZ_SYS_RO_ICONS, "/noti_wifi_in_range.png")
57 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE \
58                 dgettext(PACKAGE, "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE")
59 #define NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT \
60                 dgettext(PACKAGE, "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT")
61 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE \
62                         dgettext(PACKAGE, "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB")
63 #define NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT "\"%s\""
64
65 #define USER_RESP_LEN 30
66 #define ICON_PATH_LEN 128
67 #define RESP_REMAIN_CONNECTED "RESP_REMAIN_CONNECTED"
68 #define RESP_WIFI_TETHERING_OFF "RESP_TETHERING_TYPE_WIFI_OFF"
69 #define RESP_WIFI_AP_TETHERING_OFF "RESP_TETHERING_TYPE_WIFI_AP_OFF"
70 #define RESP_TETHERING_ON "RESP_TETHERING_ON"
71 #define CAPTIVE_PORTAL_LOGIN "Login required to access Internet"
72 #define CAPTIVE_PORTAL_LOGIN_ERROR "Login not completed. Disconnected active Wifi"
73
74 static Ecore_Event_Handler *ecore_event_evas_handler;
75 static Ecore_Event_Handler *ecore_event_evas_quick_panel_handler;
76
77 #define BUF_SIZE 1024
78 long sizes[] = {1073741824, 1048576, 1024, 0};
79 char *units[] = {"GB", "MB", "KB", "B"};
80
81 static app_control_h g_req_handle = NULL;
82 static char * resp_popup_mode = NULL;
83
84 static GDBusConnection *conn = NULL;
85 static GDBusProxy *proxy = NULL;
86
87 static int __net_popup_show_notification(app_control_h request, void *data);
88 static int __toast_popup_show(app_control_h request, void *data);
89 static int __net_popup_show_popup(app_control_h request, void *data);
90 static void __net_popup_add_found_ap_noti(void);
91 static void __net_popup_del_found_ap_noti(void);
92 static void __net_popup_add_portal_noti(app_control_h request);
93 static void __net_popup_del_portal_noti(void);
94 static void __net_popup_show_popup_with_user_resp(app_control_h request, void *data);
95 static int _net_popup_send_user_resp(char *resp, Eina_Bool state);
96
97
98 GDBusProxy *__net_popup_init_dbus(void)
99 {
100         log_print(NET_POPUP, "__net_popup_init_dbus()\n");
101
102         GError *err = NULL;
103
104         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
105         if (err != NULL) {
106                 g_error_free(err);
107                 return NULL;
108         }
109
110         proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
111                         "net.netpopup",
112                         "/Netpopup",
113                         "net.netpopup",
114                         NULL, &err);
115
116         if (proxy == NULL) {
117                 g_object_unref(conn);
118                 conn = NULL;
119         }
120
121         return proxy;
122 }
123
124 void __net_popup_deinit_dbus(void)
125 {
126         log_print(NET_POPUP, "__net_popup_deinit_dbus()\n");
127
128         if (proxy) {
129                 g_object_unref(proxy);
130                 proxy = NULL;
131         }
132
133         if (conn) {
134                 g_object_unref(conn);
135                 conn = NULL;
136         }
137
138         return;
139 }
140
141 int __net_popup_send_dbus_msg(const char *resp)
142 {
143         log_print(NET_POPUP, "__net_popup_send_dbus_msg()\n");
144
145         if (conn == NULL || resp == NULL) {
146                 return -1;
147         }
148
149         GDBusConnection *gconn = NULL;
150         GVariant *msg = NULL;
151         char *module = "wifi";
152         GError *err = NULL;
153
154         gconn = g_bus_get_sync(DBUS_BUS_SYSTEM, NULL, &err);
155         if (err != NULL) {
156                 g_error_free(err);
157                 err = NULL;
158                 return -1;
159         }
160
161         msg = g_variant_new("(ss)", module, resp);
162         g_dbus_connection_emit_signal(gconn, NULL, "/Org/Tizen/Quickpanel",
163                         "org.tizen.quickpanel", "ACTIVITY", msg, &err);
164         if (err) {
165                 g_error_free(err);
166                 return -1;
167         }
168
169         g_variant_unref(msg);
170
171         if (gconn)
172                 g_object_unref(gconn);
173
174
175         return 0;
176 }
177
178 static bool __net_popup_create(void *data)
179 {
180         log_print(NET_POPUP, "__net_popup_create()\n");
181
182         bindtextdomain(PACKAGE, LOCALEDIR);
183
184         return true;
185 }
186
187 static void __net_popup_terminate(void *data)
188 {
189         log_print(NET_POPUP, "__net_popup_terminate()\n");
190
191         if (ecore_event_evas_handler) {
192                 ecore_event_handler_del(ecore_event_evas_handler);
193                 ecore_event_evas_handler = NULL;
194         }
195         if (ecore_event_evas_quick_panel_handler) {
196                 ecore_event_handler_del(ecore_event_evas_quick_panel_handler);
197                 ecore_event_evas_quick_panel_handler = NULL;
198         }
199
200         return;
201 }
202
203 static void __net_popup_pause(void *data)
204 {
205         log_print(NET_POPUP, "__net_popup_pause()\n");
206 }
207
208 static void __net_popup_resume(void *data)
209 {
210         return;
211 }
212
213 static Eina_Bool __key_release_event_cb(void *data, int type,
214                 void *event)
215 {
216         log_print(NET_POPUP, "__key_release_event_cb()\n");
217
218         Evas_Event_Key_Down *ev = (Evas_Event_Key_Down *) event;
219
220         if (!ev) {
221                 return ECORE_CALLBACK_RENEW;
222         }
223
224         if (!ev->keyname) {
225                 return ECORE_CALLBACK_RENEW;
226         }
227
228         log_print(NET_POPUP, "key_release : %s", ev->keyname);
229         if (g_strcmp0(ev->keyname, "XF86Phone") == 0 ||
230                         g_strcmp0(ev->keyname, "XF86Stop") == 0) {
231                 elm_exit();
232         }
233
234         return ECORE_CALLBACK_DONE;
235 }
236
237 #if 0
238 static Eina_Bool _ecore_event_client_message_cb(void *data, int type,
239                                                  void *event)
240 {
241         Ecore_X_Event_Client_Message *ev = event;
242
243         if (ev->message_type == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_STATE) {
244                 if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF) {
245                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_OFF");
246                 } else if (ev->data.l[0] == ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON) {
247                         log_print(NET_POPUP, "ECORE_X_ATOM_E_ILLUME_QUICKPANEL_ON");
248                 }
249         }
250         return ECORE_CALLBACK_RENEW;
251 }
252 #endif
253
254 static void __net_popup_service_cb(app_control_h request, void *data)
255 {
256         log_print(NET_POPUP, "__net_popup_service_cb()\n");
257
258         int ret = 0;
259         char *type = NULL;
260
261         if (ecore_event_evas_handler == NULL) {
262                 ecore_event_evas_handler = ecore_event_handler_add(ECORE_EVENT_KEY_UP,
263                                 __key_release_event_cb, NULL);
264         }
265
266 #if 0
267         if (ecore_event_evas_quick_panel_handler == NULL) {
268                 ecore_event_evas_quick_panel_handler = ecore_event_handler_add(
269                                 ECORE_X_EVENT_CLIENT_MESSAGE, _ecore_event_client_message_cb, NULL);
270         }
271 #endif
272
273         ret = app_control_get_extra_data(request, "_SYSPOPUP_TYPE_", &type);
274
275         if (APP_CONTROL_ERROR_NONE != ret) {
276                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_TYPE_ ret = %d", ret);
277                 g_free(type);
278                 elm_exit();
279                 return;
280         }
281
282         log_print(NET_POPUP, "type = %s\n", type);
283
284         if (g_str_equal(type, "notification")) {
285                 __net_popup_show_notification(request, data);
286                 elm_exit();
287         } else if (g_str_equal(type, "toast_popup")) {
288                 __toast_popup_show(request, data);
289         } else if (g_str_equal(type, "popup")) {
290                 __net_popup_show_popup(request, data);
291         } else if (g_str_equal(type, "add_found_ap_noti")) {
292                 __net_popup_add_found_ap_noti();
293                 elm_exit();
294         } else if (g_str_equal(type, "del_found_ap_noti")) {
295                 __net_popup_del_found_ap_noti();
296                 elm_exit();
297         } else if (g_str_equal(type, "add_portal_noti")) {
298                 __net_popup_add_portal_noti(request);
299                 elm_exit();
300         } else if (g_str_equal(type, "del_portal_noti")) {
301                 __net_popup_del_portal_noti();
302                 elm_exit();
303         } else if (g_str_equal(type, "popup_user_resp")) {
304                 app_control_clone(&g_req_handle, request);
305                 __net_popup_show_popup_with_user_resp(request, data);
306         } else {
307                 __net_popup_show_notification(request, data);
308                 elm_exit();
309         }
310         g_free(type);
311
312         return;
313 }
314
315 static void __net_popup_set_orientation(Evas_Object *win)
316 {
317         log_print(NET_POPUP, "__net_popup_set_orientation()\n");
318
319         int rots[4] = { 0, 90, 180, 270 };
320
321         if (!elm_win_wm_rotation_supported_get(win)) {
322                 return;
323         }
324
325         elm_win_wm_rotation_available_rotations_set(win, rots, 4);
326 }
327
328 static Evas_Object* __net_popup_create_win(void)
329 {
330         log_print(NET_POPUP, "__net_popup_create_win()\n");
331
332         Evas_Object *win = NULL;
333         Evas *e = NULL;
334         Ecore_Evas *ee = NULL;
335 #if 0
336         int w, h;
337 #endif
338
339         win = elm_win_add(NULL, PACKAGE, ELM_WIN_NOTIFICATION);
340
341         e = evas_object_evas_get(win);
342         ee = ecore_evas_ecore_evas_get(e);
343         ecore_evas_name_class_set(ee,"APP_POPUP","APP_POPUP");
344
345         elm_win_alpha_set(win, EINA_TRUE);
346         elm_win_borderless_set(win, EINA_TRUE);
347 #if 0
348         ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
349         evas_object_resize(win, w, h);
350         utilx_set_system_notification_level (ecore_x_display_get(),
351                                 elm_win_xwindow_get(win),
352                                 UTILX_NOTIFICATION_LEVEL_LOW);
353 #endif
354
355         __net_popup_set_orientation(win);
356
357         return win;
358 }
359
360 static void _ok_button_clicked_cb(void *data, Evas_Object *obj, void *event_info)
361 {
362         log_print(NET_POPUP, "_ok_button_clicked_cb()\n");
363
364         if (data)
365                 evas_object_del(data);
366         elm_exit();
367 }
368
369 static void _timeout_cb(void *data, Evas_Object *obj, void *event_info)
370 {
371         log_print(NET_POPUP, "_timeout_cb()\n");
372
373         evas_object_del(obj);
374
375         elm_exit();
376 }
377
378 static int __toast_popup_show(app_control_h request, void *data)
379 {
380         log_print(NET_POPUP, "__toast_popup_show()\n");
381
382         char buf[ALERT_STR_LEN_MAX] = "";
383         int ret = 0;
384         char *mode = NULL;
385         Evas_Object *twin = NULL;
386         Evas_Object *tpop = NULL;
387         char *ap_name = NULL;
388         char *restricted_type = NULL;
389
390         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
391         if (ret != APP_CONTROL_ERROR_NONE) {
392                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
393                 g_free(mode);
394                 elm_exit();
395                 return 0;
396         }
397
398         log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
399
400         twin = __net_popup_create_win();
401         tpop = elm_popup_add(twin);
402         elm_object_style_set(tpop, "toast");
403         evas_object_size_hint_weight_set(tpop, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
404
405         elm_popup_timeout_set(tpop, 2.0);
406
407         evas_object_smart_callback_add(tpop, "timeout", _timeout_cb, twin);
408         if (strcmp(mode, "wrong password") == 0) {
409                 log_print(NET_POPUP, "alert wrong password\n");
410
411                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_ERR_WRONG_PASSWORD);
412         } else if (strcmp(mode, "no ap found") == 0) {
413                 log_print(NET_POPUP, "alert no ap found\n");
414
415                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_NO_AP_FOUND);
416         } else if (strcmp(mode, "unable to connect") == 0) {
417                 log_print(NET_POPUP, "alert no ap found\n");
418
419                 g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_ERR_CONNECT);
420         } else if (strcmp(mode, "wifi connected") == 0) {
421                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
422
423                 if (APP_CONTROL_ERROR_NONE != ret) {
424                         log_print(NET_POPUP, "Failed to get _AP_NAME_ ret = %d", ret);
425                         g_free(mode);
426                         return 0;
427                 }
428
429                 if (ap_name != NULL)
430                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
431                 else
432                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
433                 log_print(NET_POPUP, "alert wifi connected\n");
434                 g_free(ap_name);
435         } else if (strcmp(mode, "security restriction") == 0) {
436                 ret = app_control_get_extra_data(request, "_RESTRICTED_TYPE_", &restricted_type);
437                 if (APP_CONTROL_ERROR_NONE != ret) {
438                         log_print(NET_POPUP, "Failed to get _RESTRICTED_TYPE_ ret = %d", ret);
439                         g_free(mode);
440                         return 0;
441                 }
442
443                 if (strcmp(restricted_type, "wifi") == 0)
444                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_RESTRICTED_USE_WIFI);
445                 else if (strcmp(restricted_type, "wifi tethering") == 0)
446                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_WIFI_TETHERING);
447                 else if (strcmp(restricted_type, "bt tethering") == 0)
448                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_BT_TETHERING);
449                 else if (strcmp(restricted_type, "usb tethering") == 0)
450                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_SECURITY_RESTRICTION, ALERT_STR_USB_TETHERING);
451
452                 log_print(NET_POPUP, "alert security restriction\n");
453                 g_free(restricted_type);
454         } else
455                 log_print(NET_POPUP, "%s\n", mode);
456
457         elm_object_text_set(tpop, buf);
458         evas_object_show(tpop);
459         evas_object_show(twin);
460         g_free(mode);
461
462         return 0;
463 }
464
465 static int __net_popup_show_notification(app_control_h request, void *data)
466 {
467         log_print(NET_POPUP, "__net_popup_show_notification()\n");
468
469         int ret = 0;
470         char *mode = NULL;
471         char buf[ALERT_STR_LEN_MAX] = "";
472         char *ap_name = NULL;
473
474         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
475
476         if (APP_CONTROL_ERROR_NONE != ret) {
477                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_");
478                 return 0;
479         }
480
481         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
482
483         if (strcmp(mode, "connected") == 0) {
484                 notification_status_message_post(ALERT_STR_MOBILE_NETWORKS_CHARGE);
485                 log_print(NET_POPUP, "alert 3g\n");
486         } else if (strcmp(mode, "fail to connect") == 0) {
487                 notification_status_message_post(ALERT_STR_ERR_UNAVAILABLE);
488                 log_print(NET_POPUP, "alert err\n");
489         } else if (strcmp(mode, "unable to connect") == 0) {
490                 notification_status_message_post(ALERT_STR_ERR_CONNECT);
491                 log_print(NET_POPUP, "alert unable to connect\n");
492         } else if (strcmp(mode, "wrong password") == 0) {
493                 notification_status_message_post(ALERT_STR_ERR_WRONG_PASSWORD);
494                 log_print(NET_POPUP, "alert wrong password\n");
495         } else if (strcmp(mode, "not support") == 0) {
496                 notification_status_message_post(ALERT_STR_ERR_NOT_SUPPORT);
497                 log_print(NET_POPUP, "alert not support\n");
498         } else if (strcmp(mode, "wifi restricted") == 0) {
499                 notification_status_message_post(ALERT_STR_RESTRICTED_USE_WIFI);
500                 log_print(NET_POPUP, "alert wifi restricted\n");
501         } else if (strcmp(mode, "no ap found") == 0) {
502                 notification_status_message_post(ALERT_STR_NO_AP_FOUND);
503                 log_print(NET_POPUP, "alert no ap found\n");
504         } else if (strcmp(mode, "Lengthy Password") == 0) {
505                 notification_status_message_post(ALERT_STR_LENGHTY_PASSWORD);
506                 log_print(NET_POPUP, "Password entered crosses 64 bytes\n");
507         } else if (strcmp(mode, "Portal Login") == 0) {
508                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN);
509                 log_print(NET_POPUP, "Please login to access Internet\n");
510         } else if (strcmp(mode, "Portal Login Error") == 0) {
511                 notification_status_message_post(CAPTIVE_PORTAL_LOGIN_ERROR);
512                 log_print(NET_POPUP, "Login not completed. Disconnected Wifi\n");
513         } else if (strcmp(mode, "wifi connected") == 0) {
514                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
515
516                 if (APP_CONTROL_ERROR_NONE != ret) {
517                         log_print(NET_POPUP, "Failed to get _AP_NAME_ ret = %d", ret);
518                         g_free(mode);
519                         return 0;
520                 }
521
522                 if (ap_name != NULL)
523                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
524                 else
525                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
526
527                 notification_status_message_post(buf);
528
529                 log_print(NET_POPUP, "alert wifi connected\n");
530                 g_free(ap_name);
531         } else {
532                 notification_status_message_post(mode);
533                 log_print(NET_POPUP, "%s\n", mode);
534         }
535         g_free(mode);
536
537         return 0;
538 }
539
540 static int _net_popup_send_user_resp(char *resp, Eina_Bool state)
541 {
542         log_print(NET_POPUP, "_net_popup_send_user_resp()\n");
543
544         int ret = 0;
545         app_control_h reply = NULL;
546         char checkbox_str[USER_RESP_LEN] = { '\0', };
547
548         log_print(NET_POPUP, "Send the user response to the caller");
549         ret = app_control_create(&reply);
550         if (APP_CONTROL_ERROR_NONE != ret) {
551                 log_print(NET_POPUP, "Failed to create service ret = %d", ret);
552                 app_control_destroy(g_req_handle);
553                 g_req_handle = NULL;
554
555                 return false;
556         }
557
558         if (TRUE == state)
559                 g_strlcpy(checkbox_str, "TRUE", USER_RESP_LEN);
560         else
561                 g_strlcpy(checkbox_str, "FALSE", USER_RESP_LEN);
562
563         log_print(NET_POPUP, "Checkbox_str[%s]", checkbox_str);
564
565         ret = app_control_add_extra_data(reply, "_SYSPOPUP_RESP_", resp);
566         if (APP_CONTROL_ERROR_NONE == ret) {
567                 ret = app_control_add_extra_data(reply, "_SYSPOPUP_CHECKBOX_RESP_",
568                                 checkbox_str);
569                 if (APP_CONTROL_ERROR_NONE == ret) {
570                         ret = app_control_reply_to_launch_request(reply, g_req_handle,
571                                         APP_CONTROL_RESULT_SUCCEEDED);
572                         if (APP_CONTROL_ERROR_NONE == ret) {
573                                 log_print(NET_POPUP, "Service reply success");
574                                 ret = TRUE;
575                         } else {
576                                 log_print(NET_POPUP, "Service reply failed ret = %d", ret);
577                         }
578                 } else {
579                         log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
580                 }
581         } else {
582                 log_print(NET_POPUP, "Service data addition failed ret = %d", ret);
583         }
584
585         app_control_destroy(reply);
586         app_control_destroy(g_req_handle);
587         g_req_handle = NULL;
588
589         return ret;
590 }
591
592 void _tethering_wifi_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
593 {
594         log_print(NET_POPUP, "_tethering_wifi_btn_yes_cb()\n");
595
596         bool result = FALSE;
597         Evas_Object *popup = (Evas_Object *)data;
598
599         __net_popup_init_dbus();
600         __net_popup_send_dbus_msg("progress_off");
601         __net_popup_deinit_dbus();
602
603         result = _net_popup_send_user_resp(RESP_WIFI_TETHERING_OFF, FALSE);
604         if (true != result)
605                 log_print(NET_POPUP, "Failed to send user response ");
606
607         if (popup)
608                 evas_object_del(popup);
609
610         elm_exit();
611 }
612
613 void _tethering_wifi_ap_btn_yes_cb(void *data, Evas_Object *obj, void *event_info)
614 {
615         log_print(NET_POPUP, "_tethering_wifi_ap_btn_yes_cb()\n");
616
617         bool result = FALSE;
618         Evas_Object *popup = (Evas_Object *)data;
619
620         __net_popup_init_dbus();
621         __net_popup_send_dbus_msg("progress_off");
622         __net_popup_deinit_dbus();
623
624         result = _net_popup_send_user_resp(RESP_WIFI_AP_TETHERING_OFF, FALSE);
625         if (true != result)
626                 log_print(NET_POPUP, "Failed to send user response ");
627
628         if (popup)
629                 evas_object_del(popup);
630
631         elm_exit();
632 }
633
634 void _btn_no_cb(void *data, Evas_Object *obj, void *event_info)
635 {
636         log_print(NET_POPUP, "_btn_no_cb()\n");
637
638         bool result = FALSE;
639         Evas_Object *popup = (Evas_Object *)data;
640
641         result = _net_popup_send_user_resp(RESP_TETHERING_ON, FALSE);
642         if (true != result)
643                 log_print(NET_POPUP, "Failed to send user response ");
644
645         if (popup)
646                 evas_object_del(popup);
647
648         elm_exit();
649 }
650
651 static void __net_popup_show_popup_with_user_resp(app_control_h request,
652                 void *data)
653 {
654         log_print(NET_POPUP, "__net_popup_show_popup_with_user_resp()\n");
655
656         Evas_Object *win;
657         Evas_Object *popup;
658         Evas_Object *layout;
659         Evas_Object *label;
660         Evas_Object *btn1;
661         Evas_Object *btn2;
662         int ret = 0;
663
664         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &resp_popup_mode);
665         if (APP_CONTROL_ERROR_NONE != ret)
666                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
667
668         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", resp_popup_mode);
669
670         win = __net_popup_create_win();
671         evas_object_show(win);
672
673         popup = elm_popup_add(win);
674         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
675                         EVAS_HINT_EXPAND);
676
677         if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0 ||
678                         g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0) {
679                 log_print(NET_POPUP, "Drawing Wi-Fi Tethering OFF popup");
680
681                 __net_popup_init_dbus();
682                 elm_object_part_text_set(popup, "title,text", ALERT_STR_WIFI);
683
684                 layout = elm_layout_add(popup);
685                 elm_layout_file_set(layout, NETPOPUP_EDJ, "popup");
686                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
687                                 EVAS_HINT_EXPAND);
688
689                 __net_popup_send_dbus_msg("progress_on");
690                 label = elm_label_add(popup);
691                 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
692                 elm_object_text_set(label, ALERT_STR_WIFI_MOBILE_AP_ON);
693                 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND,
694                                 EVAS_HINT_EXPAND);
695                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
696                 evas_object_show(label);
697
698                 elm_object_part_content_set(layout, "elm.swallow.content", label);
699                 evas_object_show(layout);
700                 elm_object_style_set(label, "popup/default");
701                 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _btn_no_cb, popup);
702                 elm_object_content_set(popup, label);
703
704                 btn1 = elm_button_add(popup);
705                 elm_object_style_set(btn1, "popup");
706                 elm_object_text_set(btn1, ALERT_STR_CANCEL);
707                 elm_object_part_content_set(popup, "button1", btn1);
708                 evas_object_smart_callback_add(btn1, "clicked",
709                                         _btn_no_cb, popup);
710
711                 btn2 = elm_button_add(popup);
712                 elm_object_style_set(btn2, "popup");
713                 elm_object_text_set(btn2, ALERT_STR_OK);
714                 elm_object_part_content_set(popup, "button2", btn2);
715
716                 if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI") == 0)
717                         evas_object_smart_callback_add(btn2, "clicked",
718                                 _tethering_wifi_btn_yes_cb, popup);
719                 else if (g_strcmp0(resp_popup_mode, "TETHERING_TYPE_WIFI_AP") == 0)
720                         evas_object_smart_callback_add(btn2, "clicked",
721                                 _tethering_wifi_ap_btn_yes_cb, popup);
722
723                 evas_object_show(popup);
724                 evas_object_show(win);
725                 __net_popup_deinit_dbus();
726         }
727 }
728
729 static int __net_popup_show_popup(app_control_h request, void *data)
730 {
731         log_print(NET_POPUP, "__net_popup_show_popup()\n");
732
733         Evas_Object *win;
734         Evas_Object *popup;
735         Evas_Object *button;
736         int ret = 0;
737         char *mode = NULL;
738
739         ret = app_control_get_extra_data(request, "_SYSPOPUP_CONTENT_", &mode);
740         if (APP_CONTROL_ERROR_NONE != ret) {
741                 log_print(NET_POPUP, "Failed to get _SYSPOPUP_CONTENT_ ret = %d", ret);
742                 g_free(mode);
743                 elm_exit();
744                 return 0;
745         }
746
747         secure_log_print(NET_POPUP, "_SYSPOPUP_CONTENT_ = %s\n", mode);
748
749         win = __net_popup_create_win();
750
751         popup = elm_popup_add(win);
752         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
753         if (strcmp(mode, "connected") == 0) {
754                 elm_object_text_set(popup, ALERT_STR_MOBILE_NETWORKS_CHARGE);
755                 log_print(NET_POPUP, "alert 3g\n");
756         } else if (strcmp(mode, "fail to connect") == 0) {
757                 elm_object_text_set(popup, ALERT_STR_ERR_UNAVAILABLE);
758                 log_print(NET_POPUP, "alert err\n");
759         } else if (strcmp(mode, "unable to connect") == 0) {
760                 elm_object_text_set(popup, ALERT_STR_ERR_CONNECT);
761                 log_print(NET_POPUP, "alert unable to connect\n");
762         } else if (strcmp(mode, "wrong password") == 0) {
763                 elm_object_text_set(popup, ALERT_STR_ERR_WRONG_PASSWORD);
764                 log_print(NET_POPUP, "alert wrong password\n");
765         } else if (strcmp(mode, "not support") == 0) {
766                 elm_object_text_set(popup, ALERT_STR_ERR_NOT_SUPPORT);
767                 log_print(NET_POPUP, "alert not support\n");
768         } else if (strcmp(mode, "wifi restricted") == 0) {
769                 elm_object_text_set(popup, ALERT_STR_RESTRICTED_USE_WIFI);
770                 log_print(NET_POPUP, "alert wifi restricted\n");
771         } else if (strcmp(mode, "no ap found") == 0) {
772                 elm_object_text_set(popup, ALERT_STR_NO_AP_FOUND);
773                 log_print(NET_POPUP, "alert no ap found\n");
774         } else if (strcmp(mode, "wifi connected") == 0) {
775                 char buf[ALERT_STR_LEN_MAX] = "";
776                 char *ap_name = NULL;
777
778                 ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
779
780                 if (ap_name != NULL)
781                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, ap_name);
782                 else
783                         g_snprintf(buf, ALERT_STR_LEN_MAX, ALERT_STR_WIFI_CONNECTED, "");
784
785                 elm_object_text_set(popup, buf);
786
787                 log_print(NET_POPUP, "alert wifi connected\n");
788                 g_free(ap_name);
789         } else {
790                 elm_object_text_set(popup, mode);
791                 log_print(NET_POPUP, "%s\n", mode);
792         }
793
794         button = elm_button_add(popup);
795         elm_object_style_set(button, "popup");
796         elm_object_text_set(button, ALERT_STR_OK);
797         elm_object_part_content_set(popup, "button1", button);
798         evas_object_smart_callback_add(button, "clicked", _ok_button_clicked_cb, popup);
799         evas_object_show(popup);
800         evas_object_show(win);
801         g_free(mode);
802
803         return 0;
804 }
805
806 static void __net_popup_add_found_ap_noti(void)
807 {
808         log_print(NET_POPUP, "__net_popup_add_found_ap_noti()\n");
809
810         int ret = 0, noti_flags = 0;
811         char icon_path[ICON_PATH_LEN];
812         notification_h noti = NULL;
813         notification_list_h noti_list = NULL;
814         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
815         app_control_h service_handle = NULL;
816
817         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
818                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
819         if (noti_list != NULL) {
820                 notification_free_list(noti_list);
821                 return;
822         }
823
824         noti = notification_create(NOTIFICATION_TYPE_ONGOING);
825         if (noti == NULL) {
826                 log_print(NET_POPUP, "Failed to create notification");
827                 return;
828         }
829
830         noti_err = notification_set_time(noti, time(NULL));
831         if(noti_err != NOTIFICATION_ERROR_NONE) {
832                 log_print(NET_POPUP, "Failed to notification_set_time : %d", noti_err);
833                 goto error;
834         }
835
836         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
837         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
838         if(noti_err != NOTIFICATION_ERROR_NONE) {
839                 log_print(NET_POPUP, "Failed to notification_set_image : %d", noti_err);
840                 goto error;
841         }
842
843         noti_err = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
844         if (noti_err != NOTIFICATION_ERROR_NONE) {
845                 log_print(NET_POPUP, "Failed to notification_set_layout : %d", noti_err);
846                 goto error;
847         }
848
849         noti_err = notification_set_text_domain(noti, PACKAGE,
850                         LOCALEDIR);
851         if(noti_err != NOTIFICATION_ERROR_NONE) {
852                 log_print(NET_POPUP, "Failed to notification_set_text_domain : %d", noti_err);
853                 goto error;
854         }
855
856         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
857                         NETCONFIG_NOTIFICATION_WIFI_FOUND_TITLE,
858                         "IDS_COM_BODY_WI_FI_NETWORKS_AVAILABLE",
859                         NOTIFICATION_VARIABLE_TYPE_NONE);
860         if (noti_err != NOTIFICATION_ERROR_NONE) {
861                 log_print(NET_POPUP, "Failed to notification_set_title : %d", noti_err);
862                 goto error;
863         }
864
865         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
866                         NETCONFIG_NOTIFICATION_WIFI_FOUND_CONTENT,
867                         "IDS_WIFI_SBODY_TAP_HERE_TO_CONNECT",
868                         NOTIFICATION_VARIABLE_TYPE_NONE);
869         if (noti_err != NOTIFICATION_ERROR_NONE) {
870                 log_print(NET_POPUP, "Failed to notification_set_content: %d", noti_err);
871                 goto error;
872         }
873
874         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
875         noti_err = notification_set_display_applist(noti, noti_flags);
876         if(noti_err != NOTIFICATION_ERROR_NONE) {
877                 log_print(NET_POPUP, "Failed to notification_set_display_applist: %d", noti_err);
878                 goto error;
879         }
880
881         ret = app_control_create(&service_handle);
882         log_print(NET_POPUP, "Service create ret[%d]", ret);
883         if(ret != APP_CONTROL_ERROR_NONE)
884                 goto error;
885
886         ret = app_control_set_app_id(service_handle, NET_WIFIQS_APPID);
887         log_print(NET_POPUP, "Service set app id ret = %d", ret);
888         if(ret != APP_CONTROL_ERROR_NONE)
889                 goto error;
890
891         ret = app_control_add_extra_data(service_handle, "caller", "notification");
892         log_print(NET_POPUP, "Service data addition ret = %d", ret);
893         if(ret != APP_CONTROL_ERROR_NONE)
894                 goto error;
895
896         noti_err = notification_set_launch_option(noti,
897                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
898         if (noti_err != NOTIFICATION_ERROR_NONE) {
899                 log_print(NET_POPUP, "Failed to notification_set_launch_option");
900                 goto error;
901         }
902
903         noti_err = notification_post(noti);
904         if (noti_err != NOTIFICATION_ERROR_NONE) {
905                 log_print(NET_POPUP, "Failed to insert notification[error# is %d]", noti_err);
906                 goto error;
907         }
908
909         log_print(NET_POPUP, "Successfully added notification");
910
911 error:
912
913         if (noti != NULL)
914                 notification_free(noti);
915 }
916
917 static void __net_popup_del_found_ap_noti(void)
918 {
919         log_print(NET_POPUP, "__net_popup_del_found_ap_noti()\n");
920
921         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
922
923         noti_err = notification_delete_all(NOTIFICATION_TYPE_ONGOING);
924         if (noti_err != NOTIFICATION_ERROR_NONE) {
925                 log_print(NET_POPUP, "fail to notification_delete_by_priv_id");
926                 return;
927         }
928
929         log_print(NET_POPUP, "Successfully deleted notification");
930 }
931
932 static void __net_popup_add_portal_noti(app_control_h request)
933 {
934         log_print(NET_POPUP, "__net_popup_add_portal_noti()\n");
935
936         int ret = 0;
937         int noti_flags = 0;
938         char *ap_name = NULL;
939         char icon_path[ICON_PATH_LEN];
940         notification_h noti = NULL;
941         app_control_h service_handle = NULL;
942         notification_list_h noti_list = NULL;
943         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
944
945         ret = app_control_get_extra_data(request, "_AP_NAME_", &ap_name);
946
947         if (ap_name == NULL || ret != APP_CONTROL_ERROR_NONE) {
948                 log_print(NET_POPUP, "Failed to retrieve connected AP name!!");
949                 g_free(ap_name);
950                 return;
951         }
952
953         log_print(NET_POPUP, "Successfully added notification");
954
955         notification_get_detail_list("net.netpopup", NOTIFICATION_GROUP_ID_NONE,
956                         NOTIFICATION_PRIV_ID_NONE, -1, &noti_list);
957         if (noti_list != NULL) {
958                 notification_free_list(noti_list);
959                 g_free(ap_name);
960                 return;
961         }
962
963         noti = notification_create(NOTIFICATION_TYPE_NOTI);
964         if (noti == NULL) {
965                 log_print(NET_POPUP, "fail to create notification");
966                 g_free(ap_name);
967                 return;
968         }
969
970         noti_err = notification_set_time(noti, time(NULL));
971         if(noti_err != NOTIFICATION_ERROR_NONE) {
972                 log_print(NET_POPUP, "fail to notification_set_time : %d", noti_err);
973                 goto error;
974         }
975
976         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON,
977                         NETCONFIG_NOTIFICATION_WIFI_ICON);
978         if(noti_err != NOTIFICATION_ERROR_NONE) {
979                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
980                 goto error;
981         }
982
983         g_snprintf(icon_path, sizeof(icon_path), "%s%s", QP_PRELOAD_NOTI_ICON_PATH, "/noti_wifi_in_range.png");
984         noti_err = notification_set_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
985         if(noti_err != NOTIFICATION_ERROR_NONE) {
986                 log_print(NET_POPUP, "fail to notification_set_image : %d", noti_err);
987                 goto error;
988         }
989         noti_err = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_MULTIPLE);
990         if (noti_err != NOTIFICATION_ERROR_NONE) {
991                 log_print(NET_POPUP, "fail to notification_set_layout : %d", noti_err);
992                 goto error;
993         }
994
995         noti_err = notification_set_text_domain(noti, PACKAGE,
996                         LOCALEDIR);
997         if(noti_err != NOTIFICATION_ERROR_NONE) {
998                 log_print(NET_POPUP, "fail to notification_set_text_domain : %d", noti_err);
999                 goto error;
1000         }
1001
1002         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
1003                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_TITLE,
1004                         "IDS_WIFI_HEADER_SIGN_IN_TO_WI_FI_NETWORK_ABB",
1005                         NOTIFICATION_VARIABLE_TYPE_NONE);
1006         if (noti_err != NOTIFICATION_ERROR_NONE) {
1007                 log_print(NET_POPUP, "fail to notification_set_title : %d", noti_err);
1008                 goto error;
1009         }
1010
1011         noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
1012                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1013                         NETCONFIG_NOTIFICATION_WIFI_PORTAL_CONTENT,
1014                         NOTIFICATION_VARIABLE_TYPE_STRING, ap_name,
1015                         NOTIFICATION_VARIABLE_TYPE_NONE);
1016         if (noti_err != NOTIFICATION_ERROR_NONE) {
1017                 log_print(NET_POPUP, "fail to notification_set_content : %d", noti_err);
1018                 goto error;
1019         }
1020
1021         noti_flags = NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY | NOTIFICATION_DISPLAY_APP_INDICATOR;
1022         noti_err = notification_set_display_applist(noti, noti_flags);
1023         if(noti_err != NOTIFICATION_ERROR_NONE) {
1024                 log_print(NET_POPUP, "fail to notification_set_display_applist : %d", noti_err);
1025                 goto error;
1026         }
1027
1028         ret = app_control_create(&service_handle);
1029         log_print(NET_POPUP, "service create ret[%d]", ret);
1030         if(ret != APP_CONTROL_ERROR_NONE)
1031                 goto error;
1032
1033         ret = app_control_set_operation(service_handle, APP_CONTROL_OPERATION_VIEW);
1034         if(ret != APP_CONTROL_ERROR_NONE)
1035                 goto error;
1036
1037         log_print(NET_POPUP, "service set operation is successful");
1038
1039         ret = app_control_set_uri(service_handle, "http://www.google.com");
1040
1041         if(ret != APP_CONTROL_ERROR_NONE)
1042                 goto error;
1043
1044         noti_err = notification_set_launch_option(noti,
1045                         NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, service_handle);
1046         if (noti_err != NOTIFICATION_ERROR_NONE) {
1047                 log_print(NET_POPUP, "fail to notification_set_launch_option");
1048                 goto error;
1049         }
1050
1051         noti_err = notification_post(noti);
1052         if (noti_err != NOTIFICATION_ERROR_NONE) {
1053                 log_print(NET_POPUP, "fail to notification_post");
1054                 goto error;
1055         }
1056
1057         log_print(NET_POPUP, "Successfully added notification");
1058
1059 error:
1060         g_free(ap_name);
1061         if (noti != NULL)
1062                 notification_free(noti);
1063
1064         if (service_handle != NULL)
1065                 app_control_destroy(service_handle);
1066 }
1067
1068 static void __net_popup_del_portal_noti(void)
1069 {
1070         log_print(NET_POPUP, "__net_popup_del_portal_noti()\n");
1071
1072         notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
1073
1074         noti_err = notification_delete_all(NOTIFICATION_TYPE_NOTI);
1075         if (noti_err != NOTIFICATION_ERROR_NONE) {
1076                 log_print(NET_POPUP, "fail to notification_delete_all");
1077                 return;
1078         }
1079
1080         log_print(NET_POPUP, "Successfully deleted notification");
1081 }
1082
1083 EXPORT_API int main(int argc, char *argv[])
1084 {
1085         log_print(NET_POPUP, "main()\n");
1086
1087         ui_app_lifecycle_callback_s app_callback = {
1088                 .create = __net_popup_create,
1089                 .terminate = __net_popup_terminate,
1090                 .pause = __net_popup_pause,
1091                 .resume = __net_popup_resume,
1092                 .app_control = __net_popup_service_cb,
1093         };
1094
1095         return ui_app_main(argc, argv, &app_callback, NULL);
1096 }
1097