Added fix to deactivate WIFI when switching from wireless to wired 74/128674/2
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Thu, 11 May 2017 04:51:05 +0000 (10:21 +0530)
committerAbhishek Sansanwal <abhishek.s94@samsung.com>
Thu, 11 May 2017 07:29:53 +0000 (12:59 +0530)
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: I691c7b049f481ed7b3908b39491771de43827b3c

include/common/datamgr.h
src/common/datamgr.c
src/data/system/data_wireless.c
src/data/system/settings_voice_control.c
src/layout/layout_network.c
src/view/network/view_wireless.c
src/view/network/view_wireless_list.c
src/view/network/view_wireless_scanning.c

index 445011c..ff422fa 100644 (file)
 
 struct datamgr;
 
+enum wirelessmgr_update_type {
+       WIRELESS_ACTIVATE = 0,
+       WIRELESS_DEACTIVATE
+};
+
 enum event_type {
        EVENT_DATA_INIT_DONE_WIRELESS,
        EVENT_DATA_INIT_FAIL_WIRELESS,
        EVENT_DATA_INVALID_PWD_WIRELESS,
+       EVENT_DATA_DEACTIVATE_FAIL,
        EVENT_DATA_UPDATE_DONE,
        EVENT_DATA_CHANGED,
        EVENT_DATA_SELECT_DONE,
@@ -39,7 +45,7 @@ struct data_class {
        void *(*create)(void (*event_cb)(enum event_type type, void *data),
                        void *cb_data);
        bool (*destroy)(void *dclass_data);
-       bool (*update)(void *dclass_data);
+       bool (*update)(void *dclass_data, int wireless_update_type);
        bool (*select)(void *dclass_data, Elm_Object_Item *it, void *data);
        Eina_List *(*get_data)(void *dclass_data);
 };
@@ -74,10 +80,11 @@ bool datamgr_destroy(struct datamgr *dmgr);
 * @brief Call it whenever it is necessary to update view associated with model data.
 *
 * @param[in] dmgr Data manager pointer.
+* @param[in] wireless_update_type The type id to update.
 *
 * @return true on success.
 */
-bool datamgr_update(struct datamgr *dmgr);
+bool datamgr_update(struct datamgr *dmgr, int wireless_update_type);
 
 /**
 * @brief Call it when associated UI item was selected.
index 3359576..ad859cc 100644 (file)
@@ -58,7 +58,7 @@ bool datamgr_destroy(struct datamgr *dmgr)
        return true;
 }
 
-bool datamgr_update(struct datamgr *dmgr)
+bool datamgr_update(struct datamgr *dmgr, int wireless_update_type)
 {
        if (!dmgr) {
                _ERR("Invalid argument.");
@@ -66,7 +66,7 @@ bool datamgr_update(struct datamgr *dmgr)
        }
 
        if (dmgr->dclass->update)
-               return dmgr->dclass->update(dmgr->dclass_data);
+               return dmgr->dclass->update(dmgr->dclass_data, wireless_update_type);
 
        return true;
 }
index 6f79ee6..5715eff 100644 (file)
@@ -191,6 +191,7 @@ static void _wifi_manager_connection_state_changed_cb(wifi_manager_connection_st
        struct _priv *priv;
        char *essid;
        int r;
+       bool wifi_state = false;
 
        if (!data) {
                _ERR("Invalid argument.");
@@ -205,6 +206,12 @@ static void _wifi_manager_connection_state_changed_cb(wifi_manager_connection_st
                return;
        }
 
+       r = wifi_manager_is_activated(priv->wifi, &wifi_state);
+       if (r == WIFI_MANAGER_ERROR_NONE && wifi_state == false) {
+               _ERR("wifi is not activated, ignore callback.");
+               return;
+       }
+
        r = wifi_manager_ap_get_connection_state(ap, &connection_state);
        if (r != WIFI_MANAGER_ERROR_NONE) {
                _ERR("wifi_manager_ap_get_connection_state failed.");
@@ -336,6 +343,26 @@ static void _wifi_manager_scan_finished_cb(wifi_manager_error_e err, void *data)
                priv->event_cb(EVENT_DATA_UPDATE_DONE, priv->cb_data);
 }
 
+static void _wifi_manager_deactivated_cb(wifi_manager_error_e err, void *data)
+{
+       struct _priv *priv;
+
+       if (!data) {
+               _ERR("Invalid argument.");
+               return;
+       }
+
+       priv = data;
+
+       if (err != WIFI_MANAGER_ERROR_NONE) {
+               _ERR("wifi deactivation failed.");
+               if (priv->event_cb)
+                       priv->event_cb(EVENT_DATA_DEACTIVATE_FAIL, priv->cb_data);
+               return;
+       }
+
+}
+
 static void _wifi_manager_activated_cb(wifi_manager_error_e err, void *data)
 {
        struct _priv *priv;
@@ -362,7 +389,7 @@ static void _wifi_manager_activated_cb(wifi_manager_error_e err, void *data)
        }
 }
 
-static bool _update(void *dclass_data)
+static bool _update(void *dclass_data, int wireless_update_type)
 {
        bool activated;
        int r;
@@ -375,26 +402,40 @@ static bool _update(void *dclass_data)
 
        priv = dclass_data;
 
-       r = wifi_manager_is_activated(priv->wifi, &activated);
-       if (r != WIFI_MANAGER_ERROR_NONE) {
-               _ERR("wifi_manager_is_activated failed.");
-               return false;
-       }
-
-       if (activated) {
-               r = wifi_manager_scan(priv->wifi, _wifi_manager_scan_finished_cb, dclass_data);
+       switch (wireless_update_type) {
+       case WIRELESS_ACTIVATE:
+               r = wifi_manager_is_activated(priv->wifi, &activated);
                if (r != WIFI_MANAGER_ERROR_NONE) {
-                       _ERR("wifi_manager_scan failed. err[%x]", r);
+                       _ERR("wifi_manager_is_activated failed.");
                        return false;
                }
-       } else {
-               r = wifi_manager_activate(priv->wifi, _wifi_manager_activated_cb, dclass_data);
-               if (r != WIFI_MANAGER_ERROR_NONE) {
-                       _ERR("wifi_manager_activated failed.");
-                       return false;
+
+               if (activated) {
+                       r = wifi_manager_scan(priv->wifi, _wifi_manager_scan_finished_cb, dclass_data);
+                       if (r != WIFI_MANAGER_ERROR_NONE) {
+                               _ERR("wifi_manager_scan failed. err[%x]", r);
+                               return false;
+                       }
+               } else {
+                       r = wifi_manager_activate(priv->wifi, _wifi_manager_activated_cb, dclass_data);
+                       if (r != WIFI_MANAGER_ERROR_NONE) {
+                               _ERR("wifi_manager_activated failed.");
+                               return false;
+                       }
                }
+               break;
+       case WIRELESS_DEACTIVATE:
+                       r = wifi_manager_deactivate(priv->wifi, _wifi_manager_deactivated_cb, dclass_data);
+                       if (r != WIFI_MANAGER_ERROR_NONE) {
+                               _ERR("wifi_manager_deactivated failed.");
+                               return false;
+                       }
+               break;
+       default :
+                       _ERR("Unexpected case");
+                       return false;
+               break;
        }
-
        return true;
 }
 
index 2ffe46b..094da1a 100755 (executable)
@@ -23,7 +23,7 @@
 static void *_create(void (*event_cb)(enum event_type type, void *data),
                        void *cb_data);
 static bool _destroy(void *data);
-static bool _update(void *data);
+static bool _update(void *data, int update_type);
 static bool _select(void *dclass_data, Elm_Object_Item *it, void *data);
 static Eina_List *_get_data(void *dclass_data);
 
@@ -186,7 +186,7 @@ static bool _destroy(void *data)
        return (VC_ERROR_NONE == ret);
 }
 
-static bool _update(void *data)
+static bool _update(void *data, int update_type)
 {
        int ret = VC_ERROR_NONE;
        private_data *priv = data;
index 4089ca7..f567a08 100644 (file)
@@ -753,6 +753,7 @@ static void _retry_wired_network(struct _priv *priv)
 
        data = priv->wired;
 
+       datamgr_update(priv->wirelessmgr, WIRELESS_DEACTIVATE);
        /* Set progress state */
        //elm_object_signal_emit(priv->wired_layout, SIG_WIRED_PROGRESS, SRC_ELM);
        //elm_object_part_text_set(priv->wired_layout, "part.wired.text",
@@ -800,7 +801,7 @@ void _retry_wireless_network(struct _priv *priv)
 
        /* Update wireless network state */
        elm_object_signal_emit(priv->ly, SIG_LOADING_START, SRC_ELM);
-       if (!datamgr_update(priv->wirelessmgr)) {
+       if (!datamgr_update(priv->wirelessmgr, WIRELESS_ACTIVATE)) {
                _ERR("Unavailable status for updating list.");
 
                elm_object_signal_emit(priv->ly, SIG_NO_WIRELESS, SRC_ELM);
@@ -1174,6 +1175,8 @@ static void _data_event_cb(enum event_type type, void *data)
 //                     PART_WIRELESS_LIST);
                break;
 
+       case EVENT_DATA_DEACTIVATE_FAIL:
+               break;
        case EVENT_DATA_UPDATE_DONE:
                priv->wireless_update_requested = false;
 
index 188dd8e..19df131 100644 (file)
@@ -29,6 +29,8 @@
 #include "view/network/view_wireless.h"
 #define STR_WIRELESS "Wireless"
 
+Evas_Object *wifi_popup;
+
 enum input_type {
        EO_NO = 0,
        EO_YES
@@ -78,7 +80,7 @@ static input_handler handler = {
                 _ERR("Invalid parameter.");
                 return;
         }
-       evas_object_del(priv->base);
+       evas_object_del(wifi_popup);
 }*/
 
 static Evas_Object *_create(Evas_Object *win, void *data)
@@ -94,23 +96,23 @@ static Evas_Object *_create(Evas_Object *win, void *data)
 
        priv = data;
 
-       priv->base = utils_add_popup(win, STYLE_POPUP, STR_WIRELESS, NULL);
-       if (!priv->base) {
+       wifi_popup = utils_add_popup(win, STYLE_POPUP, STR_WIRELESS, NULL);
+       if (!wifi_popup) {
                _ERR("Add popup failed");
                return NULL;
        }
 
-       ly = utils_add_layout(priv->base, GRP_CONTENT_NETWORK_POPUP, EINA_FALSE);
+       ly = utils_add_layout(wifi_popup, GRP_CONTENT_NETWORK_POPUP, EINA_FALSE);
        if (!ly) {
                _ERR("Add layout failed.");
-               evas_object_del(priv->base);
+               evas_object_del(wifi_popup);
                return NULL;
        }
        //elm_object_part_text_set(ly, PART_POPUP_TITLE, "NO network ?");
 /*
        if (!_fill_popup_btns(priv, ly, LANG_TYPE_MAX, PART_POPUP_BUTTON_X,
                        language_option, EO_BTN_LANG_ENG)) {
-               evas_object_del(priv->base);
+               evas_object_del(wifi_popup);
                return NULL;
        }
 */
@@ -124,36 +126,36 @@ static Evas_Object *_create(Evas_Object *win, void *data)
         btn1 = utils_add_button(ly, "part.popup.bottom.no", STYLE_DISABLE_BTN, "No");
         if (!btn1) {
                 _ERR("Add button failed.");
-                evas_object_del(priv->base);
+                evas_object_del(wifi_popup);
                 return NULL;
         }
-       //evas_object_smart_callback_add(btn1, "clicked", _clicked_cb, priv->base);
+       //evas_object_smart_callback_add(btn1, "clicked", _clicked_cb, wifi_popup);
        inputmgr_add_callback(btn1, EO_NO, &handler, priv);
 
         btn2 = utils_add_button(ly, "part.popup.bottom.yes", STYLE_DISABLE_BTN, "Yes");
         if (!btn2) {
                 _ERR("Add button failed.");
-                evas_object_del(priv->base);
+                evas_object_del(wifi_popup);
                 return NULL;
         }
-       //evas_object_smart_callback_add(btn2, "clicked", NULL/*_retry_cb*/, priv->base);
+       //evas_object_smart_callback_add(btn2, "clicked", NULL/*_retry_cb*/, wifi_popup);
 
         //evas_object_show(_content_network_popup);
        inputmgr_add_callback(btn2, EO_YES, &handler, priv);
 
-       elm_object_focus_allow_set(priv->base, EINA_TRUE);
+       elm_object_focus_allow_set(wifi_popup, EINA_TRUE);
        elm_object_focus_set(btn2, EINA_TRUE);
 
-       elm_object_content_set(priv->base, ly);
+       elm_object_content_set(wifi_popup, ly);
 
 
        if (!viewmgr_set_view_data(VIEW_WIRELESS, priv)) {
                _ERR("Set view data failed.");
-               evas_object_del(priv->base);
+               evas_object_del(wifi_popup);
                return NULL;
        }
 
-       return priv->base;
+       return wifi_popup;
 }
 
 static void _show(void *data)
@@ -165,7 +167,7 @@ static void _show(void *data)
                return;
        }
 
-       evas_object_show(priv->base);
+       evas_object_show(wifi_popup);
 
 
 }
@@ -179,7 +181,7 @@ static void _hide(void *data)
                return;
        }
 
-       evas_object_hide(priv->base);
+       evas_object_hide(wifi_popup);
 }
 
 static void _destroy(void *data)
@@ -191,7 +193,7 @@ static void _destroy(void *data)
                return;
        }
 
-       evas_object_del(priv->base);
+       evas_object_del(wifi_popup);
 
 }
 
@@ -235,10 +237,11 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
        case EO_NO:
                viewmgr_pop_view();
                viewmgr_pop_view();
+               viewmgr_remove_view(VIEW_WIRELESS);
                break;
        case EO_YES:
                viewmgr_pop_view();
-               datamgr_update(priv->wirelessmgr);
+               datamgr_update(priv->wirelessmgr, WIRELESS_ACTIVATE);
                break;
        default:
                _ERR("Unhandled object type.");
index e559b6c..d899342 100644 (file)
@@ -286,7 +286,7 @@ static Evas_Object *_create(Evas_Object *win, void *data)
 
        if (!listmgr_update_grid(priv->listmgr, LIST_WIRELESS))
                _ERR("Listmgr update list failed.");
-       datamgr_update(priv->wirelessmgr);
+       datamgr_update(priv->wirelessmgr, WIRELESS_ACTIVATE);
        list = datamgr_get_data(priv->wirelessmgr);
        if (!list) {
                //_draw_no_contents_message(priv);
@@ -424,7 +424,7 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
                break;
        case EO_YES:
                viewmgr_pop_view();
-               datamgr_update(priv->wirelessmgr);
+               datamgr_update(priv->wirelessmgr, WIRELESS_ACTIVATE);
                break;
        default:
                _ERR("Unhandled object type.");
index 8bd9cd7..27348a5 100644 (file)
@@ -324,7 +324,7 @@ static void _clicked_cb(int id, void *data, Evas_Object *obj)
                break;
        case EO_YES:
                viewmgr_pop_view();
-               datamgr_update(priv->wirelessmgr);
+               datamgr_update(priv->wirelessmgr, WIRELESS_ACTIVATE);
                break;
        default:
                _ERR("Unhandled object type.");