4 * Copyright 2012 Samsung Electronics Co., Ltd
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
10 * http://www.tizenopensource.org/license
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.
21 #define UG_MODULE_API __attribute__ ((visibility("default")))
24 #include <vconf-keys.h>
25 //#include <setting-cfg.h>
27 #include "view_detail.h"
28 #include "i18nmanager.h"
29 #include "wlan_manager.h"
30 #include "winset_popup.h"
31 #include "common_utils.h"
32 #include "viewer_manager.h"
33 #include "view_ime_hidden.h"
34 #include "view_advanced.h"
35 #include "wifi-engine-callback.h"
37 #define STR_ATOM_PANEL_SCROLLABLE_STATE "_E_MOVE_PANEL_SCROLLABLE_STATE"
39 static int wifi_exit_end = FALSE;
40 static bool is_scan_reqd = false;
41 wifi_appdata *ug_app_state = NULL;
43 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops);
44 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops);
45 UG_MODULE_API int setting_plugin_reset(bundle *data, void *priv);
46 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void *priv, char **domainname);
48 static gboolean __wifi_efl_ug_del_found_ap_noti(void *data)
50 common_utils_send_message_to_net_popup(NULL, NULL,
51 "del_found_ap_noti", NULL);
56 static void _bg_scan_status_callback(GDBusConnection *conn,
57 const gchar *name, const gchar *path, const gchar *interface,
58 const gchar *sig, GVariant *param, gpointer user_data)
60 __COMMON_FUNC_ENTER__;
62 GVariantIter *iter = NULL;
65 gboolean value = FALSE;
67 int header_mode = viewer_manager_header_mode_get();
68 viewer_manager_create_scan_btn();
69 if (header_mode == HEADER_MODE_DEACTIVATING ||
70 header_mode == HEADER_MODE_OFF) {
75 g_variant_get(param, "(a{sv})", &iter);
76 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
77 if (g_strcmp0(key, "Scanning") == 0) {
78 value = g_variant_get_boolean(var);
80 if (header_mode != HEADER_MODE_CONNECTING) {
81 viewer_manager_show(VIEWER_WINSET_SEARCHING_GRP_TITLE);
82 viewer_manager_header_mode_set(HEADER_MODE_SEARCHING);
92 g_variant_iter_free(iter);
97 static void _set_rotation(Evas_Object *win)
99 int rots[4] = { 0, 90, 180, 270 };
101 if (!elm_win_wm_rotation_supported_get(win)) {
105 elm_win_wm_rotation_available_rotations_set(win, (const int *)(&rots), 4);
108 static void *on_create(ui_gadget_h ug, enum ug_mode mode,
109 app_control_h app_control, void *priv)
111 __COMMON_FUNC_ENTER__;
113 const char *uri = NULL;
117 INFO_LOG(UG_NAME_ERR, "UG and PRIV should not be NULL");
119 __COMMON_FUNC_EXIT__;
123 ug_app_state = g_new0(wifi_appdata, 1);
124 retvm_if(NULL == ug_app_state, NULL);
127 ugd = (struct ug_data*)priv;
130 if (NULL != app_control) {
131 INFO_LOG(UG_NAME_NORMAL, "message load from caller");
134 app_control_get_extra_data(app_control, UG_CALLER, &caller);
136 if (app_control_get_uri(app_control, (char **)&uri) < 0)
137 ERROR_LOG(UG_NAME_NORMAL, "Failed to get app_control URI");
142 if (caller != NULL) {
143 SECURE_INFO_LOG(UG_NAME_NORMAL, "caller: %s", caller);
145 if (g_strcmp0(caller, "pwlock") == 0) {
146 ugd->elm_conform = ug_get_conformant();
147 ug_app_state->ug_type = UG_VIEW_SETUP_WIZARD;
149 ug_app_state->rbutton_setup_wizard_next = g_strdup(sc(PACKAGE,
151 ug_app_state->rbutton_setup_wizard_skip = g_strdup(sc(PACKAGE,
153 ug_app_state->lbutton_setup_wizard_prev = g_strdup(sc(PACKAGE,
155 } else if (g_strcmp0(caller, "notification") == 0){
156 /* Remove the "WiFi networks found" from the notification tray.*/
157 common_util_managed_idle_add(__wifi_efl_ug_del_found_ap_noti, NULL);
158 ug_app_state->ug_type = UG_VIEW_DEFAULT;
159 } else if (g_strcmp0(caller, "lbhome") == 0){
160 ug_app_state->ug_type = UG_VIEW_DEFAULT;
161 ug_app_state->app_control = app_control;
162 ug_app_state->is_lbhome = EINA_TRUE;
164 ug_app_state->ug_type = UG_VIEW_DEFAULT;
169 INFO_LOG(UG_NAME_NORMAL, "caller is not defined");
170 ug_app_state->ug_type = UG_VIEW_DEFAULT;
175 INFO_LOG(UG_NAME_NORMAL, "caller is not defined");
176 ug_app_state->ug_type = UG_VIEW_DEFAULT;
179 Evas_Object *parent_layout = ug_get_parent_layout(ug);
180 if (parent_layout == NULL) {
181 ERROR_LOG(UG_NAME_NORMAL, "Failed to get parent layout");
183 __COMMON_FUNC_EXIT__;
187 ugd->win_main = ug_get_window();
188 ug_app_state->gadget= ugd;
189 ug_app_state->ug = ug;
190 ug_app_state->conformant = ug_get_conformant();
192 _set_rotation(ugd->win_main);
194 common_util_set_system_registry(VCONFKEY_WIFI_UG_RUN_STATE,
195 VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND);
197 Evas_Object *layout_main = viewer_manager_create(parent_layout, ugd->win_main);
198 if (layout_main == NULL) {
199 INFO_LOG(UG_NAME_ERR, "Failed to create viewer_manager");
201 __COMMON_FUNC_EXIT__;
205 if (app_control != NULL) {
207 app_control_get_extra_data(app_control, "z_order", &zorder);
208 INFO_LOG(UG_NAME_NORMAL, "zorder [%s]", zorder);
209 if (zorder != NULL && 0 == g_strcmp0(zorder, "highest")) {
210 efl_util_set_notification_window_level(ugd->win_main, EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT);
216 #if defined TIZEN_TETHERING_ENABLE
217 ug_app_state->popup_manager = winset_popup_manager_create(layout_main, PACKAGE);
220 ugd->base = layout_main;
221 ug_app_state->layout_main = layout_main;
222 ug_app_state->bAlive = EINA_TRUE;
224 wlan_manager_create();
225 wlan_manager_set_message_callback(wlan_engine_callback);
226 wlan_manager_set_refresh_callback(wlan_engine_refresh_callback);
227 common_util_subscribe_scanning_signal(_bg_scan_status_callback);
229 switch (wlan_manager_start()) {
230 case WLAN_MANAGER_ERR_NONE:
233 case WLAN_MANAGER_ERR_ALREADY_REGISTERED:
237 ERROR_LOG(UG_NAME_NORMAL, "Cannot start wlan_manager");
239 __COMMON_FUNC_EXIT__;
243 state = wlan_manager_state_get();
245 case WLAN_MANAGER_OFF:
246 if (ug_app_state->ug_type == UG_VIEW_SETUP_WIZARD) {
247 viewer_manager_header_mode_set(HEADER_MODE_ACTIVATING);
250 viewer_manager_hide(VIEWER_WINSET_SUB_CONTENTS);
251 viewer_manager_header_mode_set(HEADER_MODE_OFF);
255 case WLAN_MANAGER_CONNECTING:
256 case WLAN_MANAGER_UNCONNECTED:
257 case WLAN_MANAGER_CONNECTED:
258 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
259 viewer_manager_show(VIEWER_WINSET_SUB_CONTENTS);
260 viewer_manager_header_mode_set(HEADER_MODE_SEARCHING);
263 case WLAN_MANAGER_ERROR:
268 evas_object_show(layout_main);
270 __COMMON_FUNC_EXIT__;
274 static gboolean load_initial_ap_list(gpointer data)
276 __COMMON_FUNC_ENTER__;
278 /* Because of transition effect performance,
279 * Wi-Fi lists might be better to be updated at maximum delayed
281 wlan_manager_scanned_profile_refresh();
283 __COMMON_FUNC_EXIT__;
287 static void on_start(ui_gadget_h ug, app_control_h app_control, void *priv)
289 __COMMON_FUNC_ENTER__;
291 common_util_managed_idle_add(load_initial_ap_list, NULL);
293 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_PERIODIC);
295 __COMMON_FUNC_EXIT__;
298 static void on_pause(ui_gadget_h ug, app_control_h app_control, void *priv)
300 __COMMON_FUNC_ENTER__;
302 INFO_LOG(UG_NAME_NORMAL, "Wi-Fi UG paused");
304 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_EXPONENTIAL);
306 common_util_set_system_registry(VCONFKEY_WIFI_UG_RUN_STATE,
307 VCONFKEY_WIFI_UG_RUN_STATE_ON_BACKGROUND);
309 __COMMON_FUNC_EXIT__;
312 static void on_resume(ui_gadget_h ug, app_control_h app_control, void *priv)
314 __COMMON_FUNC_ENTER__;
316 INFO_LOG(UG_NAME_NORMAL, "Wi-Fi UG resumed");
318 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_PERIODIC);
320 common_util_set_system_registry(VCONFKEY_WIFI_UG_RUN_STATE,
321 VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND);
323 view_manager_view_type_t top_viewID = viewer_manager_view_type_get();
324 if (top_viewID == VIEW_MANAGER_VIEW_TYPE_MAIN) {
325 viewer_manager_request_scan();
326 is_scan_reqd = false;
331 __COMMON_FUNC_EXIT__;
334 static void on_destroy(ui_gadget_h ug, app_control_h app_control, void *priv)
336 __COMMON_FUNC_ENTER__;
339 struct ug_data* ugd = priv;
341 common_util_set_system_registry(VCONFKEY_WIFI_UG_RUN_STATE,
342 VCONFKEY_WIFI_UG_RUN_STATE_OFF);
345 __COMMON_FUNC_EXIT__;
349 /*Added to handle incase of force closure*/
350 passwd_popup_free(ug_app_state->passpopup);
351 ug_app_state->passpopup = NULL;
353 if (ug_app_state->timeout) {
354 g_source_remove(ug_app_state->timeout);
355 ug_app_state->timeout = 0;
358 #if defined TIZEN_TETHERING_ENABLE
359 winset_popup_manager_destroy(ug_app_state->popup_manager);
360 ug_app_state->popup_manager = NULL;
361 DEBUG_LOG(UG_NAME_NORMAL, "* popup manager destroy complete");
364 if (wifi_exit_end == FALSE) {
365 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_EXPONENTIAL);
367 common_util_managed_idle_cleanup();
368 common_util_managed_ecore_scan_update_timer_del();
370 ret = wlan_manager_destroy();
371 if (ret != WLAN_MANAGER_ERR_NONE) {
372 ERROR_LOG(UG_NAME_NORMAL, "Failed to destroy wlan manager: %d",ret);
374 INFO_LOG(UG_NAME_NORMAL, "* wlan manager destroy complete");
378 viewer_manager_destroy();
379 INFO_LOG(UG_NAME_NORMAL, "* viewer manager destroy complete");
381 if (ug_app_state->rbutton_setup_wizard_next != NULL) {
382 g_free(ug_app_state->rbutton_setup_wizard_next);
383 ug_app_state->rbutton_setup_wizard_next = NULL;
386 if (ug_app_state->rbutton_setup_wizard_skip != NULL) {
387 g_free(ug_app_state->rbutton_setup_wizard_skip);
388 ug_app_state->rbutton_setup_wizard_skip = NULL;
391 if (ug_app_state->lbutton_setup_wizard_prev != NULL) {
392 g_free(ug_app_state->lbutton_setup_wizard_prev);
393 ug_app_state->lbutton_setup_wizard_prev = NULL;
396 if (ug_app_state != NULL) {
397 g_free(ug_app_state);
401 if (ugd->base != NULL) {
402 evas_object_del(ugd->base);
406 __COMMON_FUNC_EXIT__;
409 static void on_message(ui_gadget_h ug, app_control_h msg, app_control_h app_control, void *priv)
413 static void _language_changed(void)
416 __COMMON_FUNC_ENTER__;
418 if (NULL != ug_app_state->rbutton_setup_wizard_next) {
419 g_free(ug_app_state->rbutton_setup_wizard_next);
420 ug_app_state->rbutton_setup_wizard_next = NULL;
423 if (NULL != ug_app_state->rbutton_setup_wizard_skip) {
424 g_free(ug_app_state->rbutton_setup_wizard_skip);
425 ug_app_state->rbutton_setup_wizard_skip = NULL;
428 if (NULL != ug_app_state->lbutton_setup_wizard_prev) {
429 g_free(ug_app_state->lbutton_setup_wizard_prev);
430 ug_app_state->lbutton_setup_wizard_prev = NULL;
433 ug_app_state->rbutton_setup_wizard_next = g_strdup(sc(PACKAGE, I18N_TYPE_Next));
434 ug_app_state->rbutton_setup_wizard_skip = g_strdup(sc(PACKAGE, I18N_TYPE_Skip));
435 ug_app_state->lbutton_setup_wizard_prev = g_strdup(sc(PACKAGE, I18N_TYPE_Prev));
437 viewer_manager_setup_wizard_button_controller();
439 language_changed_refresh();
441 __COMMON_FUNC_EXIT__;
444 static void on_event(ui_gadget_h ug, enum ug_event event, app_control_h app_control, void *priv)
446 __COMMON_FUNC_ENTER__;
449 case UG_EVENT_LOW_MEMORY:
451 case UG_EVENT_LOW_BATTERY:
453 case UG_EVENT_LANG_CHANGE:
454 INFO_LOG(UG_NAME_NORMAL, "LANGUAGE");
455 if (UG_VIEW_SETUP_WIZARD == ug_app_state->ug_type)
458 case UG_EVENT_ROTATE_PORTRAIT:
459 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
460 INFO_LOG(UG_NAME_NORMAL, "PORTRAIT");
461 viewer_manager_rotate_top_setupwizard_layout();
463 case UG_EVENT_ROTATE_LANDSCAPE:
464 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
465 INFO_LOG(UG_NAME_NORMAL, "LANSCAPE");
466 viewer_manager_rotate_top_setupwizard_layout();
472 __COMMON_FUNC_EXIT__;
475 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, app_control_h app_control, void *priv)
477 __COMMON_FUNC_ENTER__;
480 __COMMON_FUNC_EXIT__;
485 case UG_KEY_EVENT_END:
486 INFO_LOG(UG_NAME_NORMAL, "UG_KEY_EVENT_END");
488 #if defined TIZEN_TETHERING_ENABLE
489 /* popup key event determine */
490 winset_popup_hide_popup(ug_app_state->popup_manager);
492 view_manager_view_type_t top_view_id = viewer_manager_view_type_get();
493 if (top_view_id == VIEW_MANAGER_VIEW_TYPE_MAIN) {
494 INFO_LOG(UG_NAME_NORMAL, "same");
496 INFO_LOG(UG_NAME_NORMAL, "differ");
497 elm_naviframe_item_pop(viewer_manager_get_naviframe());
499 __COMMON_FUNC_EXIT__;
506 INFO_LOG(UG_NAME_NORMAL, "UG_KEY_EVENT [%d]", event);
510 __COMMON_FUNC_EXIT__;
513 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
515 __COMMON_FUNC_ENTER__;
517 wifi_exit_end = FALSE;
519 retvm_if(NULL == ops, 0);
522 ugd = calloc(1, sizeof(struct ug_data));
524 assertm_if(NULL == ugd, "Err!! calloc fail");
526 ops->create = on_create;
527 ops->start = on_start;
528 ops->pause = on_pause;
529 ops->resume = on_resume;
530 ops->destroy = on_destroy;
531 ops->message = on_message;
532 ops->event = on_event;
533 ops->key_event = on_key_event;
535 ops->opt = UG_OPT_INDICATOR_ENABLE;
537 __COMMON_FUNC_EXIT__;
541 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
543 __COMMON_FUNC_ENTER__;
545 retm_if(NULL == ops);
555 __COMMON_FUNC_EXIT__;
558 static bool setting_plugin_wifi_found_ap_cb(wifi_ap_h ap, void* user_data)
560 bool favorite = false;
562 wifi_ap_is_favorite(ap, &favorite);
564 if (true == favorite) {
565 wlan_manager_forget(ap);
571 UG_MODULE_API int setting_plugin_reset(bundle *data, void *priv)
573 __COMMON_FUNC_ENTER__;
575 int return_value = 0;
577 return_value = wlan_manager_start();
578 if (return_value != WLAN_MANAGER_ERR_NONE) {
579 ERROR_LOG(UG_NAME_NORMAL, "Failed to register : %d",return_value);
584 wifi_foreach_found_aps(setting_plugin_wifi_found_ap_cb, NULL);
585 return_value = wlan_manager_power_off();
586 if (return_value != WLAN_MANAGER_ERR_NONE) {
587 ERROR_LOG(UG_NAME_NORMAL, "Failed to power_off: %d",return_value);
592 common_util_set_system_registry(VCONFKEY_WIFI_ENABLE_QS,
593 VCONFKEY_WIFI_QS_ENABLE);
596 wlan_manager_destroy();
598 __COMMON_FUNC_EXIT__;
604 __COMMON_FUNC_ENTER__;
606 if (wifi_exit_end == TRUE) {
607 __COMMON_FUNC_EXIT__;
610 wifi_exit_end = TRUE;
612 int ret = WLAN_MANAGER_ERR_NONE;
614 ugd = ug_app_state->gadget;
615 ug_app_state->bAlive = EINA_FALSE;
617 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_EXPONENTIAL);
619 common_util_managed_idle_cleanup();
620 common_util_managed_ecore_scan_update_timer_del();
622 ret = wlan_manager_destroy();
623 if (ret != WLAN_MANAGER_ERR_NONE) {
624 ERROR_LOG(UG_NAME_NORMAL, "Failed to destroy wlan manager: %d",ret);
626 DEBUG_LOG(UG_NAME_NORMAL, "* wlan manager destroy complete");
629 DEBUG_LOG(UG_NAME_NORMAL, "* ug_destroying...");
630 ug_destroy_me(ugd->ug);
632 __COMMON_FUNC_EXIT__;
636 bool wifi_is_scan_required(void)
641 UG_MODULE_API int setting_plugin_search_init(app_control_h app_control, void *priv, char **domainname)
644 *domainname = strdup(PACKAGE);
645 Eina_List **pplist = (Eina_List **)priv;
647 node = setting_plugin_search_item_add("IDS_ST_BODY_NETWORK_NOTIFICATION",
648 "viewtype:advancedsetting", NULL, 5, NULL);
649 *pplist = eina_list_append(*pplist, node);
650 node = setting_plugin_search_item_add("IDS_WIFI_TMBODY_SMART_NETWORK_SWITCH",
651 "viewtype:mainview", NULL, 5, NULL);
652 *pplist = eina_list_append(*pplist, node);
653 node = setting_plugin_search_item_add("IDS_WIFI_HEADER_PASSPOINT",
654 "viewtype:advancedsetting", NULL, 5, NULL);
655 *pplist = eina_list_append(*pplist, node);
656 node = setting_plugin_search_item_add("IDS_ST_BODY_KEEP_WI_FI_ON_DURING_SLEEP",
657 "viewtype:advancedsetting", NULL, 5, NULL);
658 *pplist = eina_list_append(*pplist, node);
659 node = setting_plugin_search_item_add("IDS_ST_MBODY_ALWAYS_ALLOW_SCANNING",
660 "viewtype:advancedsetting", NULL, 5, NULL);
661 *pplist = eina_list_append(*pplist, node);
662 node = setting_plugin_search_item_add("IDS_WIFI_BODY_ADVANCED_SETTINGS",
663 "viewtype:advancedsetting", NULL, 5, NULL);
664 *pplist = eina_list_append(*pplist, node);