4 * Copyright 2012 Samsung Electronics Co., Ltd
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
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.
20 #include <wifi-manager.h>
22 #include <vconf-keys.h>
23 #include <appcore-efl.h>
24 #include <ui-gadget-module.h>
26 #include <efl_extension.h>
29 #include "view-main.h"
30 #include "i18nmanager.h"
31 #include "view-alerts.h"
32 #include "common_utils.h"
33 #include "wlan_manager.h"
34 #include "wifi-syspopup.h"
35 #include "appcoreWrapper.h"
36 #include "wifi-syspopup-engine-callback.h"
46 #define FONT_SIZE_SMALL_GENLIST_H 96
47 #define FONT_SIZE_NORMAL_GENLIST_H 96
48 #define FONT_SIZE_LARGE_GENLIST_H 163
49 #define FONT_SIZE_HUGE_GENLIST_H 182
50 #define FONT_SIZE_GIANT_GENLIST_H 216
51 #define FONT_SIZE_SMALL_GRP_TITLE_GENLIST_H 51
52 #define FONT_SIZE_NORMAL_GRP_TITLE_GENLIST_H 51
53 #define FONT_SIZE_LARGE_GRP_TITLE_GENLIST_H 95
54 #define FONT_SIZE_HUGE_GRP_TITLE_GENLIST_H 108
55 #define FONT_SIZE_GIANT_GRP_TITLE_GENLIST_H 132
57 wifi_object* devpkr_app_state = NULL;
59 Ecore_Event_Handler* event_handler = NULL;
61 static void __idle_lock_state_change_cb(keynode_t *node, void *user_data);
63 static gboolean __del_found_ap_noti(void *data)
65 common_utils_send_message_to_net_popup(NULL, NULL, "del_found_ap_noti",
71 gboolean wifi_devpkr_get_scan_status(void)
73 Evas_Object *btn_scan = NULL;
74 Eina_Bool status = EINA_FALSE;
77 btn_scan = elm_object_part_content_get(devpkr_app_state->popup,
79 status = elm_object_disabled_get(btn_scan);
81 if (status == EINA_TRUE)
87 void wifi_devpkr_enable_scan_btn(void)
89 Evas_Object *btn_scan = NULL;
91 btn_scan = elm_object_part_content_get(devpkr_app_state->popup,
93 elm_object_disabled_set(btn_scan, EINA_FALSE);
96 void wifi_devpkr_disable_scan_btn(void)
98 Evas_Object *btn_scan = NULL;
100 btn_scan = elm_object_part_content_get(devpkr_app_state->popup,
102 elm_object_disabled_set(btn_scan, EINA_TRUE);
105 static void _scan_cb(void *data, Evas_Object *obj, void *event_info)
107 __COMMON_FUNC_ENTER__;
111 wifi_devpkr_disable_scan_btn();
112 view_main_update_group_title(FALSE);
114 scan_result = wlan_manager_scan();
115 if (scan_result != WLAN_MANAGER_ERR_NONE) {
116 wifi_devpkr_enable_scan_btn();
117 ERROR_LOG(SP_NAME_ERR, "Scan failed");
120 __COMMON_FUNC_EXIT__;
123 static int __wifi_devpkr_calculate_height(int rotate_angle,
130 font_size_index font_index;
131 double scale = elm_config_scale_get();
133 if (profile_count == 0)
134 height = (int)(DEVICE_PICKER_EMPTY_POPUP_H * scale);
136 vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &x);
139 switch (font_index) {
140 case SIZE_INDEX_SMALL:
141 item_h = (int)(FONT_SIZE_SMALL_GENLIST_H * scale);
142 grp_title_h = (int)(FONT_SIZE_SMALL_GRP_TITLE_GENLIST_H * scale);
144 case SIZE_INDEX_NORMAL:
145 item_h = (int)(FONT_SIZE_NORMAL_GENLIST_H * scale);
146 grp_title_h = (int)(FONT_SIZE_NORMAL_GRP_TITLE_GENLIST_H * scale);
148 case SIZE_INDEX_LARGE:
149 item_h = (int)(FONT_SIZE_LARGE_GENLIST_H * scale);
150 grp_title_h = (int)(FONT_SIZE_LARGE_GRP_TITLE_GENLIST_H * scale);
152 case SIZE_INDEX_HUGE:
153 item_h = (int)(FONT_SIZE_HUGE_GENLIST_H * scale);
154 grp_title_h = (int)(FONT_SIZE_HUGE_GRP_TITLE_GENLIST_H * scale);
156 case SIZE_INDEX_GIANT:
157 item_h = (int)(FONT_SIZE_GIANT_GENLIST_H * scale);
158 grp_title_h = (int)(FONT_SIZE_GIANT_GRP_TITLE_GENLIST_H * scale);
161 item_h = (int)(FONT_SIZE_NORMAL_GENLIST_H * scale);
162 grp_title_h = (int)(FONT_SIZE_NORMAL_GRP_TITLE_GENLIST_H * scale);
166 height = profile_count * item_h;
167 height += grp_title_h;
168 } else if (wifi_devpkr_get_scan_status() == TRUE) {
169 height += grp_title_h;
172 if (0 == rotate_angle || 180 == rotate_angle) {
173 if (height > DEVICE_PICKER_POPUP_H)
174 height = DEVICE_PICKER_POPUP_H * scale;
176 if (height > DEVICE_PICKER_POPUP_LN_H)
177 height = DEVICE_PICKER_POPUP_LN_H * scale;
183 static void wifi_devpkr_rotate_cb(void *data, Evas_Object *obj, void *event)
186 Evas_Object *box = NULL;
187 int profile_count = 0;
193 rotate_angle = elm_win_rotation_get(obj);
194 box = elm_object_content_get(devpkr_app_state->popup);
196 profile_count = view_main_get_profile_count();
197 INFO_LOG(SP_NAME_NORMAL, "Profiles count: %d", profile_count);
199 height = __wifi_devpkr_calculate_height(rotate_angle, profile_count);
201 evas_object_size_hint_min_set(box, -1, height);
203 if (0 == rotate_angle || 180 == rotate_angle)
204 common_utils_contents_rotation_adjust(UG_EVENT_ROTATE_PORTRAIT);
206 common_utils_contents_rotation_adjust(UG_EVENT_ROTATE_LANDSCAPE);
208 INFO_LOG(SP_NAME_NORMAL, "rotate_angle: %d", rotate_angle);
211 /* Tizen 2.4's setting supports auto rotate mode */
213 static void wifi_devpkr_set_rotation(Evas_Object *win)
215 if (!elm_win_wm_rotation_supported_get(win))
218 elm_win_wm_rotation_preferred_rotation_set(win, 0);
222 static void _exit_cb(void *data, Evas_Object *obj, void *event_info)
224 __COMMON_FUNC_ENTER__;
226 wifi_devpkr_destroy();
228 __COMMON_FUNC_EXIT__;
231 static void __idle_lock_state_change_cb(keynode_t *node, void *user_data)
233 __COMMON_FUNC_ENTER__;
237 if (vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state) != 0)
238 ERROR_LOG(UG_NAME_NORMAL, "Failed to get vconf");
240 if (VCONFKEY_IDLE_LOCK == lock_state)
241 wifi_devpkr_destroy();
243 __COMMON_FUNC_EXIT__;
246 void wifi_devpkr_redraw(void)
248 __COMMON_FUNC_ENTER__;
250 wifi_devpkr_rotate_cb(NULL, devpkr_app_state->win_main, NULL);
252 __COMMON_FUNC_EXIT__;
255 int wifi_devpkr_destroy(void)
257 if (VCONFKEY_WIFI_QS_WIFI_CONNECTED == devpkr_app_state->connection_result) {
258 INFO_LOG(SP_NAME_NORMAL, "Wi-Fi connected");
259 } else if (VCONFKEY_WIFI_QS_3G == devpkr_app_state->connection_result) {
260 INFO_LOG(SP_NAME_NORMAL, "Cellular connected");
262 WARN_LOG(SP_NAME_NORMAL, "Result: [%d]",
263 devpkr_app_state->connection_result);
265 devpkr_app_state->connection_result = VCONFKEY_WIFI_QS_3G;
268 view_main_clear_disconnect_popup(NULL);
270 if (event_handler != NULL)
271 ecore_event_handler_del(event_handler);
273 common_util_set_system_registry("memory/wifi/wifi_qs_exit",
274 devpkr_app_state->connection_result);
276 vconf_ignore_key_changed(VCONFKEY_IDLE_LOCK_STATE, __idle_lock_state_change_cb);
278 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_EXPONENTIAL);
285 static void __keydown_cb(void *data, Evas_Object *obj, void *event_info)
287 __COMMON_FUNC_ENTER__;
289 wifi_devpkr_destroy();
291 __COMMON_FUNC_EXIT__;
294 static Eina_Bool __key_press_cb(void *data, int type, void *event)
296 __COMMON_FUNC_ENTER__;
297 Evas_Event_Key_Down *ev = event;
299 return ECORE_CALLBACK_RENEW;
301 if (strcmp(ev->keyname, "XF86Home") == 0)
302 wifi_devpkr_destroy();
304 __COMMON_FUNC_EXIT__;
305 return ECORE_CALLBACK_RENEW;
309 static int wifi_devpkr_create(void)
311 __COMMON_FUNC_ENTER__;
313 Evas_Object *btn_scan = NULL;
314 Evas_Object *btn_cancel = NULL;
316 if (NULL == devpkr_app_state->popup) {
317 devpkr_app_state->popup = elm_popup_add(devpkr_app_state->layout_main);
318 elm_object_content_set(devpkr_app_state->layout_main, devpkr_app_state->popup);
319 assertm_if(NULL == devpkr_app_state->popup, "syspopup is NULL!!");
322 eext_object_event_callback_add(devpkr_app_state->popup, EEXT_CALLBACK_BACK,
325 event_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, __key_press_cb, NULL);
327 elm_object_style_set(devpkr_app_state->popup, "default");
328 elm_object_part_text_set(devpkr_app_state->popup, "title,text", sc(PACKAGE, I18N_TYPE_Wi_Fi));
329 evas_object_size_hint_weight_set(devpkr_app_state->popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
331 btn_cancel = elm_button_add(devpkr_app_state->popup);
332 elm_object_style_set(btn_cancel, "popup");
333 elm_object_text_set(btn_cancel, sc(PACKAGE, I18N_TYPE_Cancel));
334 elm_object_part_content_set(devpkr_app_state->popup, "button1", btn_cancel);
335 evas_object_smart_callback_add(btn_cancel, "clicked", _exit_cb, NULL);
337 btn_scan = elm_button_add(devpkr_app_state->popup);
338 elm_object_style_set(btn_scan, "popup");
339 elm_object_text_set(btn_scan, sc(PACKAGE, I18N_TYPE_Scan));
340 elm_object_part_content_set(devpkr_app_state->popup, "button2", btn_scan);
341 evas_object_smart_callback_add(btn_scan, "clicked", _scan_cb, NULL);
343 view_main_create_main_list();
345 /* Tizen 2.4's setting supports auto rotate mode */
347 wifi_devpkr_set_rotation(devpkr_app_state->win_main);
349 wifi_devpkr_redraw();
351 elm_win_indicator_mode_set(devpkr_app_state->win_main, ELM_WIN_INDICATOR_SHOW);
352 elm_win_indicator_opacity_set(devpkr_app_state->win_main, ELM_WIN_INDICATOR_TRANSPARENT);
354 vconf_notify_key_changed(VCONFKEY_IDLE_LOCK_STATE, __idle_lock_state_change_cb, NULL);
356 __COMMON_FUNC_EXIT__;
360 static void _bg_scan_status_callback(GDBusConnection *conn,
361 const gchar *name, const gchar *path, const gchar *interface,
362 const gchar *sig, GVariant *param, gpointer user_data)
364 __COMMON_FUNC_ENTER__;
366 GVariantIter *iter = NULL;
367 GVariant *var = NULL;
369 gboolean value = FALSE;
371 if (NULL == devpkr_app_state) {
372 INFO_LOG(SP_NAME_ERR, "devpkr_app_state is NULL!! Is it test mode?");
374 __COMMON_FUNC_EXIT__;
378 g_variant_get(param, "(a{sv})", &iter);
379 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
380 if (g_strcmp0(key, "Scanning") == 0) {
381 value = g_variant_get_boolean(var);
383 wifi_devpkr_disable_scan_btn();
384 view_main_update_group_title(TRUE);
386 wifi_devpkr_enable_scan_btn();
388 g_variant_unref(var);
394 g_variant_iter_free(iter);
396 __COMMON_FUNC_EXIT__;
399 static int wifi_devpkr_init()
401 __COMMON_FUNC_ENTER__;
404 bool activated = FALSE;
406 wlan_manager_create();
407 wlan_manager_set_message_callback(wlan_engine_callback);
408 wlan_manager_set_refresh_callback(wlan_engine_refresh_callback);
410 wlan_ret = wlan_manager_start();
412 case WLAN_MANAGER_ERR_ALREADY_REGISTERED:
413 ERROR_LOG(SP_NAME_ERR, "Already registered.");
415 case WLAN_MANAGER_ERR_NONE:
416 wlan_ret = wlan_manager_is_activated(&activated);
417 if (WIFI_MANAGER_ERROR_NONE == wlan_ret) {
418 INFO_LOG(SP_NAME_NORMAL, "Wi-Fi activated: %d", activated);
422 INFO_LOG(SP_NAME_NORMAL, "wlan_manager start complete");
426 ERROR_LOG(SP_NAME_ERR, "Failed to start wlan_manager (%d)", wlan_ret);
430 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_PERIODIC);
432 __COMMON_FUNC_EXIT__;
437 /* TODO: Check if bundle paramter check is required later:
438 * "[Wi-Fi_syspopup wifi_syspopup_supports:support]"
440 static int devpkr_support_set(const char* support)
442 __COMMON_FUNC_ENTER__;
444 if (NULL == support) {
445 __COMMON_FUNC_EXIT__;
449 if (g_strcmp0("WIFI_SYSPOPUP_SUPPORT_QUICKPANEL", support) == 0) {
450 devpkr_app_state->wifi_devpkr_support =
451 WIFI_DEVPKR_SUPPORT_QUICKPANEL;
453 __COMMON_FUNC_EXIT__;
457 __COMMON_FUNC_EXIT__;
462 static gboolean _power_on_check(void)
464 int connection_state;
466 connection_state = wlan_manager_state_get();
467 switch (connection_state) {
468 case WLAN_MANAGER_OFF:
469 INFO_LOG(SP_NAME_NORMAL, "current state is wifi-off");
471 int wlan_ret = wlan_manager_power_on();
472 if (wlan_ret == WLAN_MANAGER_ERR_NONE) {
473 view_alerts_powering_on_show();
475 __COMMON_FUNC_EXIT__;
477 #if defined TIZEN_TETHERING_ENABLE
478 } else if (wlan_ret == WLAN_MANAGER_ERR_WIFI_TETHERING_OCCUPIED) {
479 __COMMON_FUNC_EXIT__;
481 } else if (wlan_ret == WLAN_MANAGER_ERR_WIFI_AP_TETHERING_OCCUPIED) {
482 __COMMON_FUNC_EXIT__;
486 __COMMON_FUNC_EXIT__;
491 case WLAN_MANAGER_UNCONNECTED:
492 case WLAN_MANAGER_CONNECTING:
493 __COMMON_FUNC_EXIT__;
496 case WLAN_MANAGER_CONNECTED:
497 ERROR_LOG(SP_NAME_NORMAL, "current state is wifi-connected");
499 __COMMON_FUNC_EXIT__;
502 case WLAN_MANAGER_ERROR:
503 ERROR_LOG(SP_NAME_NORMAL, "current state is wifi error");
505 __COMMON_FUNC_EXIT__;
509 ERROR_LOG(SP_NAME_NORMAL, "current state is wifi etc");
511 __COMMON_FUNC_EXIT__;
515 __COMMON_FUNC_EXIT__;
519 static gboolean load_initial_ap_list(void)
521 __COMMON_FUNC_ENTER__;
523 wlan_manager_scanned_profile_refresh();
525 __COMMON_FUNC_EXIT__;
529 static void app_control(app_control_h request, void *data)
531 __COMMON_FUNC_ENTER__;
533 Evas_Object *win_main = NULL;
537 assertm_if(NULL == data, "data param is NULL!!");
539 devpkr_app_state = data;
541 INFO_LOG(SP_NAME_NORMAL, "Creating device-picker popup");
543 if (NULL != devpkr_app_state->win_main) {
544 INFO_LOG(SP_NAME_ERR, "Don't create device picker again");
548 win_main = appcore_create_win(PACKAGE, ELM_WIN_NOTIFICATION);
550 assertm_if(NULL == win_main, "win_main is NULL!!");
551 evas = evas_object_evas_get(win_main);
552 assertm_if(NULL == evas, "evas is NULL!!");
554 devpkr_app_state->win_main = win_main;
555 devpkr_app_state->evas = evas;
557 elm_win_alpha_set(devpkr_app_state->win_main, EINA_TRUE); /* invisible window */
559 efl_util_set_notification_window_level(win_main, EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT);
561 elm_win_borderless_set(devpkr_app_state->win_main, EINA_TRUE); /* No borders */
562 elm_win_conformant_set(devpkr_app_state->win_main, TRUE); /* Popup autoscroll */
564 Evas_Object *conformant = elm_conformant_add(devpkr_app_state->win_main);
565 elm_win_conformant_set(devpkr_app_state->win_main, EINA_TRUE);
566 elm_win_resize_object_add(devpkr_app_state->win_main, conformant);
567 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
568 evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
569 devpkr_app_state->conformant = conformant;
571 Evas_Object *layout = elm_layout_add(conformant);
572 elm_object_content_set(conformant, layout);
573 devpkr_app_state->layout_main = layout;
575 /* TODO: Check if the parameter check '-t' is required later */
577 devpkr_app_state->devpkr_type = WIFI_DEVPKR_WITH_AP_LIST;
579 int wlan_ret = wifi_devpkr_init();
580 if (WLAN_MANAGER_ERR_NONE != wlan_ret || _power_on_check() == FALSE) {
581 INFO_LOG(SP_NAME_ERR, "failed to wifi_devpkr_init()");
585 devpkr_app_state->popup = elm_popup_add(devpkr_app_state->win_main);
587 evas_object_show(devpkr_app_state->win_main);
588 evas_object_show(devpkr_app_state->conformant);
590 /* TODO: Check if below bundle parameter check is required later:
591 * "[Wi-Fi_syspopup wifi_syspopup_supports:support]" */
593 wifi_devpkr_create();
595 load_initial_ap_list();
598 if (request != NULL) {
599 app_control_get_extra_data(request, "caller", &caller);
600 INFO_LOG(SP_NAME_NORMAL, "caller - [%s]", caller);
602 if (caller != NULL) {
603 /* Remove the "WiFi networks found" from
604 * the notification tray.*/
605 if (strcmp(caller, "notification") == 0) {
606 common_util_managed_idle_add(
607 __del_found_ap_noti, NULL);
613 __COMMON_FUNC_EXIT__;
617 wifi_devpkr_destroy();
618 __COMMON_FUNC_EXIT__;
623 static bool app_create(void *data)
625 __COMMON_FUNC_ENTER__;
627 bindtextdomain(PACKAGE, LOCALEDIR);
629 __COMMON_FUNC_EXIT__;
633 static void app_terminate(void *data)
635 __COMMON_FUNC_ENTER__;
637 if (devpkr_app_state->passpopup) {
638 passwd_popup_free(devpkr_app_state->passpopup);
639 devpkr_app_state->passpopup = NULL;
642 if (devpkr_app_state->win_main) {
643 evas_object_del(devpkr_app_state->win_main);
644 devpkr_app_state->win_main = NULL;
647 if (devpkr_app_state->popup) {
648 evas_object_del(devpkr_app_state->popup);
649 devpkr_app_state->popup = NULL;
652 if (devpkr_app_state->alertpopup) {
653 evas_object_del(devpkr_app_state->alertpopup);
654 devpkr_app_state->alertpopup = NULL;
657 if (devpkr_app_state->eap_popup) {
658 eap_connect_data_free(devpkr_app_state->eap_popup);
659 devpkr_app_state->eap_popup = NULL;
662 common_util_managed_idle_cleanup();
663 common_util_managed_ecore_scan_update_timer_del();
664 wlan_manager_destroy();
666 __COMMON_FUNC_EXIT__;
670 static void app_pause(void *data)
672 __COMMON_FUNC_ENTER__;
674 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_EXPONENTIAL);
676 __COMMON_FUNC_EXIT__;
680 static void app_resume(void *data)
682 __COMMON_FUNC_ENTER__;
684 connman_request_scan_mode_set(WIFI_BGSCAN_MODE_PERIODIC);
686 __COMMON_FUNC_EXIT__;
690 EXPORT_API int main(int argc, char *argv[])
692 __COMMON_FUNC_ENTER__;
694 INFO_LOG(SP_NAME_NORMAL, "argc [%d]", argc);
697 memset(&ad, 0x0, sizeof(wifi_object));
699 ad.connection_result = VCONFKEY_WIFI_QS_3G;
704 ad.alertpopup = NULL;
706 ui_app_lifecycle_callback_s app_callback = {
707 .create = app_create,
708 .terminate = app_terminate,
710 .resume = app_resume,
711 .app_control = app_control,
714 return ui_app_main(argc, argv, &app_callback, &ad);