[Fix] NULL_AFTER_DEREF
[platform/core/connectivity/net-config.git] / src / wifi-state.c
index 3819afc..40d0a95 100755 (executable)
 
 #include <vconf.h>
 #include <vconf-keys.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <eventsystem.h>
-#include <syspopup_caller.h>
 
 #include "log.h"
 #include "util.h"
@@ -45,25 +41,60 @@ static wifi_tech_state_e g_tech_state = NETCONFIG_WIFI_TECH_UNKNOWN;
 
 static GSList *notifier_list = NULL;
 
+static guint network_connected_popup_timer_id = 0;
+static gboolean block_network_connected_popup = FALSE;
+
+static const char *_convert_wifi_service_state_to_string(wifi_service_state_e wifi_service_state_type)
+{
+       switch (wifi_service_state_type) {
+       case NETCONFIG_WIFI_UNKNOWN:
+               return "unknown";
+       case NETCONFIG_WIFI_IDLE:
+               return "idle";
+       case NETCONFIG_WIFI_ASSOCIATION:
+               return "association";
+       case NETCONFIG_WIFI_CONFIGURATION:
+               return "configuration";
+       case NETCONFIG_WIFI_CONNECTED:
+               return "connected";
+       case NETCONFIG_WIFI_FAILURE:
+               return "failure";
+       default:
+               ERR("Invalid wifi_service_state_e parameter");
+               break;
+       }
 
-static void __netconfig_pop_wifi_connected_poppup(const char *ssid)
-{
-       bundle *b = NULL;
-
-       if (ssid == NULL)
-               return;
-
-       b = bundle_create();
-
-       bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup");
-       bundle_add(b, "_SYSPOPUP_TYPE_", "toast_popup");
-       bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected");
-       bundle_add(b, "_AP_NAME_", ssid);
+       return "Invalid parameter";
+}
+
+static const char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type)
+{
+       switch (wifi_tech_state_type) {
+       case NETCONFIG_WIFI_TECH_UNKNOWN:
+               return "unknown";
+       case NETCONFIG_WIFI_TECH_OFF:
+               return "off";
+       case NETCONFIG_WIFI_TECH_WPS_ONLY:
+               return "wps only";
+       case NETCONFIG_WIFI_TECH_POWERED:
+               return "powered";
+       case NETCONFIG_WIFI_TECH_CONNECTED:
+               return "connected";
+       case NETCONFIG_WIFI_TECH_TETHERED:
+               return "tethered";
+       default:
+               ERR("Invalid wifi_tech_state_e parameter");
+               break;
+       }
 
-       DBG("Launch Wi-Fi connected alert network popup");
-       syspopup_launch("net-popup", b);
+       return "Invalid parameter";
+}
 
-       bundle_free(b);
+static gboolean _block_network_connection_popup(gpointer data)
+{
+       block_network_connected_popup = FALSE;
+       netconfig_stop_timer(&network_connected_popup_timer_id);
+       return FALSE;
 }
 
 static void __set_wifi_connected_essid(void)
@@ -87,7 +118,15 @@ static void __set_wifi_connected_essid(void)
        }
 
        netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name);
-       __netconfig_pop_wifi_connected_poppup(essid_name);
+
+       /* Block Network Connected popup for 3sec
+        * to avoid multiple popup's due to ready signals */
+       if (block_network_connected_popup == FALSE) {
+               block_network_connected_popup = TRUE;
+               netconfig_start_timer(3000, _block_network_connection_popup,
+                               NULL, &network_connected_popup_timer_id);
+               __netconfig_pop_wifi_connected_poppup(essid_name);
+       }
 }
 
 static void __unset_wifi_connected_essid(void)
@@ -443,7 +482,7 @@ void wifi_state_update_power_state(gboolean powered)
                        netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
 
-                       netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
+                       netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
 
                        netconfig_wifi_bgscan_stop();
                        netconfig_wifi_bgscan_start(TRUE);
@@ -467,7 +506,7 @@ void wifi_state_update_power_state(gboolean powered)
                netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF);
                netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF);
 
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_OFF);
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_OFF);
 
                netconfig_wifi_set_bgscan_pause(FALSE);
                netconfig_wifi_bgscan_stop();
@@ -534,7 +573,8 @@ void wifi_state_set_service_state(wifi_service_state_e new_state)
                return;
 
        g_service_state = new_state;
-       DBG("Wi-Fi state %d ==> %d", old_state, new_state);
+       DBG("Wi-Fi service state, old state[%s] ==> new state[%s]",
+               _convert_wifi_service_state_to_string(old_state), _convert_wifi_service_state_to_string(new_state));
 
        /* During DHCP, temporarily disable Wi-Fi power saving */
        if ((old_state < NETCONFIG_WIFI_ASSOCIATION || old_state == NETCONFIG_WIFI_FAILURE) && new_state == NETCONFIG_WIFI_CONFIGURATION) {
@@ -553,7 +593,7 @@ void wifi_state_set_service_state(wifi_service_state_e new_state)
                netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED);
                netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED);
 
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_CONNECTED);
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_CONNECTED);
 
                __set_wifi_connected_essid();
 
@@ -566,7 +606,7 @@ void wifi_state_set_service_state(wifi_service_state_e new_state)
                netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED);
                netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED);
 
-               netconfig_set_system_event(SYS_EVENT_WIFI_STATE, EVT_KEY_WIFI_STATE, EVT_VAL_WIFI_ON);
+               netconfig_set_system_event(SYS_EVT_WIFI_STATE, EKEY_WIFI_STATE, EVAL_WIFI_ON);
 
                netconfig_wifi_indicator_stop();
 
@@ -585,12 +625,8 @@ void wifi_state_set_service_state(wifi_service_state_e new_state)
 
        _wifi_state_changed(new_state);
 
-       if (new_state == NETCONFIG_WIFI_CONNECTED) {
+       if (new_state == NETCONFIG_WIFI_CONNECTED)
                _wifi_state_connected_activation();
-#if defined TIZEN_WEARABLE
-               wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
-#endif
-       }
 }
 
 wifi_service_state_e wifi_state_get_service_state(void)
@@ -607,7 +643,8 @@ void wifi_state_set_tech_state(wifi_tech_state_e new_state)
 
        g_tech_state = new_state;
 
-       DBG("Wi-Fi technology state %d ==> %d", old_state, new_state);
+       DBG("Wi-Fi technology state, old state[%s] ==> new state[%s]",
+               _convert_wifi_technology_state_to_string(old_state), _convert_wifi_technology_state_to_string(new_state));
 }
 
 wifi_tech_state_e wifi_state_get_technology_state(void)
@@ -677,9 +714,6 @@ wifi_tech_state_e wifi_state_get_technology_state(void)
 void wifi_state_set_connected_essid(void)
 {
        __set_wifi_connected_essid();
-#if defined TIZEN_WEARABLE
-       wc_launch_syspopup(WC_POPUP_TYPE_WIFI_CONNECTED);
-#endif
 }
 
 void wifi_state_get_connected_essid(gchar **essid)