Modify to update statistics for multi-interfaces 90/244190/5
authorhyunuk.tak <hyunuk.tak@samsung.com>
Wed, 16 Sep 2020 01:15:50 +0000 (10:15 +0900)
committerhyunuk.tak <hyunuk.tak@samsung.com>
Wed, 16 Sep 2020 23:58:52 +0000 (08:58 +0900)
Change-Id: Ia6e2c83549b3e68d99857e8cbcec5e9b242458a9
Signed-off-by: hyunuk.tak <hyunuk.tak@samsung.com>
include/network-statistics.h
include/wifi-state.h
src/network-statistics.c
src/wifi-firmware.c
src/wifi-indicator.c
src/wifi-state.c

index d958676..8bcffef 100755 (executable)
@@ -28,8 +28,10 @@ extern "C" {
 
 #include "wifi-state.h"
 
-gboolean       netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx);
-void           netconfig_wifi_statistics_update_powered_off(void);
+gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx, gboolean update);
+void netconfig_wifi_get_bytes_default_iface(guint64 *tx, guint64 *rx);
+void netconfig_wifi_set_bytes_pkt_vconf(guint64 tx_diff, guint64 rx_diff);
+void netconfig_wifi_reset_last_bytes(void);
 
 void statistics_object_create_and_init(void);
 void statistics_object_deinit(void);
index 9a2da28..f8e63d9 100755 (executable)
@@ -59,6 +59,10 @@ typedef struct {
        gboolean connected;
        wifi_tech_state_e tech_state;
        wifi_service_state_e service_state;
+       guint64 rx;
+       guint64 tx;
+       guint64 rx_diff;
+       guint64 tx_diff;
 } wifi_device_data_s;
 
 char *_convert_wifi_technology_state_to_string(wifi_tech_state_e wifi_tech_state_type);
index 8c303bb..11065cb 100755 (executable)
 
 static Network_statistics *netconfigstatistics = NULL;
 
-static gboolean __find_wifi_interface_name(const char *interface_name)
+static wifi_device_data_s *__find_wifi_interface_name(const char *interface_name)
 {
        GSList *list = wifi_state_get_device_list();
 
        for ( ; list; list = list->next) {
                wifi_device_data_s *device_data = list->data;
                if (g_strcmp0(device_data->interface_name, interface_name) == 0)
-                       return TRUE;
+                       return device_data;
        }
 
-       return FALSE;
+       return NULL;
 }
 
-gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx)
+gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx, gboolean update)
 {
        gboolean ret = FALSE;
        FILE *fp;
        gchar buf[1024];
        gchar *p_ifname = NULL, *p_entry = NULL;
+       guint64 curr_tx = 0;
+       guint64 curr_rx = 0;
+       wifi_device_data_s *device_data = NULL;
 
        *tx = 0;
        *rx = 0;
@@ -74,17 +77,18 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx)
                p_ifname = buf;
                while (*p_ifname == ' ') p_ifname++;
                p_entry = strchr(p_ifname, ':');
-               if (p_entry != NULL) {
+               if (p_entry != NULL)
                        *p_entry++ = '\0';
 
-               if (__find_wifi_interface_name(p_ifname) == FALSE)
+               device_data = __find_wifi_interface_name(p_ifname);
+               if (device_data == NULL)
                        continue;
 
                /* read interface statistics */
                sscanf(p_entry,
                                "%llu %llu %lu %lu %lu %lu %lu %lu "
                                "%llu %llu %lu %lu %lu %lu %lu %lu",
-                               (long long unsigned int *)rx, /* rx bytes */
+                               (long long unsigned int *)&curr_rx, /* rx bytes */
                                &llval,         /* rx packet */
                                &lval,          /* rx errors */
                                &lval,          /* rx dropped */
@@ -93,7 +97,7 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx)
                                &lval,          /* rx compressed */
                                &lval,          /* rx multicast */
 
-                               (long long unsigned int *)tx, /* tx bytes */
+                               (long long unsigned int *)&curr_tx, /* tx bytes */
                                &llval,         /* tx packet */
                                &lval,          /* tx errors */
                                &lval,          /* tx dropped */
@@ -102,31 +106,97 @@ gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx)
                                &lval,          /* tx carrier errors */
                                &lval           /* tx compressed */
                                );
-               } else {
-                       ERR("No matched Iface name in proc file");
+
+               if (update == TRUE) {
+                       device_data->tx_diff = curr_tx - device_data->tx;
+                       device_data->rx_diff = curr_rx - device_data->rx;
+                       device_data->tx = curr_tx;
+                       device_data->rx = curr_rx;
                }
+
+               *tx += device_data->tx_diff;
+               *rx += device_data->rx_diff;
+
                ret = TRUE;
-               break;
        }
 
 endline:
+       DBG("tx[%llu] rx[%llu]", *tx, *rx);
+
        fclose(fp);
        return ret;
 }
 
+void netconfig_wifi_get_bytes_default_iface(guint64 *tx, guint64 *rx)
+{
+       wifi_device_data_s *device_data = NULL;
+
+       *tx = 0;
+       *rx = 0;
+
+       device_data = __find_wifi_interface_name(netconfig_get_default_ifname());
+       if (device_data == NULL)
+               return;
+
+       *tx = device_data->tx_diff;
+       *rx = device_data->rx_diff;
+}
+
+void netconfig_wifi_set_bytes_pkt_vconf(guint64 tx_diff, guint64 rx_diff)
+{
+       int val = 0;
+       guint64 last_tx = 0, last_rx = 0;
+       guint64 total_tx = 0, total_rx = 0;
+
+       /* LAST */
+       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
+       last_tx = (guint64)val + tx_diff;
+
+       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
+       last_rx = (guint64)val + rx_diff;
+
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx);
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx);
+
+       /* TOTAL */
+       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
+       total_tx = (guint64)val + tx_diff;
+
+       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
+       total_rx = (guint64)val + rx_diff;
+
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx);
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx);
+}
+
+void netconfig_wifi_reset_last_bytes(void)
+{
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
+}
+
 static gboolean handle_get_wifi_total_tx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
+       int wifi_state = 0;
        guint64 tx = 0, rx = 0;
        guint64 tx_bytes = 0;
        guint64 total_bytes = 0;
        int val = 0;
 
+       netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
        netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
        tx_bytes = (guint64)val;
 
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
+       if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+               total_bytes = tx_bytes;
+               network_statistics_complete_get_wifi_total_tx_bytes(object, context, total_bytes);
+               return TRUE;
+       }
+
+       if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
                total_bytes = tx + tx_bytes;
        else
                total_bytes = tx_bytes;
@@ -139,15 +209,24 @@ static gboolean handle_get_wifi_total_rx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
+       int wifi_state = 0;
        guint64 tx = 0, rx = 0;
        guint64 rx_bytes = 0;
        guint64 total_bytes = 0;
        int val = 0;
 
+       netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
        netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
        rx_bytes = (guint64)val;
 
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
+       if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+               total_bytes = rx_bytes;
+               network_statistics_complete_get_wifi_total_rx_bytes(object, context, total_bytes);
+               return TRUE;
+       }
+
+       if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
                total_bytes = rx + rx_bytes;
        else
                total_bytes = rx_bytes;
@@ -160,22 +239,25 @@ static gboolean handle_get_wifi_last_tx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
+       int wifi_state = 0;
        guint64 tx = 0, rx = 0;
        guint64 tx_bytes = 0;
        guint64 last_bytes = 0;
        int val = 0;
 
+       netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
        netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
        tx_bytes = (guint64)val;
 
-       if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
+       if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
                last_bytes = tx_bytes;
                network_statistics_complete_get_wifi_last_tx_bytes(object, context, last_bytes);
                return TRUE;
        }
 
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               last_bytes = tx < tx_bytes ? 0 : tx - tx_bytes;
+       if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+               last_bytes = tx + tx_bytes;
        else
                last_bytes = tx_bytes;
 
@@ -187,22 +269,25 @@ static gboolean handle_get_wifi_last_rx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
+       int wifi_state = 0;
        guint64 tx = 0, rx = 0;
        guint64 rx_bytes = 0;
        guint64 last_bytes = 0;
        int val = 0;
 
+       netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
        netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
        rx_bytes = (guint64)val;
 
-       if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
+       if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
                last_bytes = rx_bytes;
                network_statistics_complete_get_wifi_last_rx_bytes(object, context, last_bytes);
                return TRUE;
        }
 
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               last_bytes = rx < rx_bytes ? 0 : rx - rx_bytes;
+       if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+               last_bytes = rx + rx_bytes;
        else
                last_bytes = rx_bytes;
 
@@ -250,15 +335,8 @@ static gboolean handle_reset_wifi_total_tx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
-       guint64 tx = 0, rx = 0;
-
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, -(int)tx);
-       else
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0);
-
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0);
        network_statistics_complete_reset_wifi_total_tx_bytes(object, context);
-
        return TRUE;
 }
 
@@ -266,13 +344,7 @@ static gboolean handle_reset_wifi_total_rx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
-       guint64 tx = 0, rx = 0;
-
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, -(int)rx);
-       else
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0);
-
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0);
        network_statistics_complete_reset_wifi_total_rx_bytes(object, context);
        return TRUE;
 }
@@ -281,21 +353,8 @@ static gboolean handle_reset_wifi_last_tx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
-       guint64 tx = 0, rx = 0;
-
-       if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
-               network_statistics_complete_reset_wifi_last_tx_bytes(object, context);
-               return TRUE;
-       }
-
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)tx);
-       else
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
-
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
        network_statistics_complete_reset_wifi_last_tx_bytes(object, context);
-
        return TRUE;
 }
 
@@ -303,96 +362,18 @@ static gboolean handle_reset_wifi_last_rx_bytes(
                Network_statistics *object,
                GDBusMethodInvocation *context)
 {
-       guint64 tx = 0, rx = 0;
-
-       if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
-               network_statistics_complete_reset_wifi_last_rx_bytes(object, context);
-               return TRUE;
-       }
-
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)rx);
-       else
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
-
+       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
        network_statistics_complete_reset_wifi_last_rx_bytes(object, context);
-
        return TRUE;
 }
 
-void netconfig_wifi_statistics_update_powered_off(void)
+static void wifi_statistics_update_state(void)
 {
-       guint64 cur_tx = 0, cur_rx = 0;
-       guint64 prev_tx = 0, prev_rx = 0;
-       guint64 total_tx = 0, total_rx = 0;
-       int val = 0;
-
-       if (netconfig_wifi_get_bytes_statistics(&cur_tx, &cur_rx) != TRUE)
-               return;
+       guint64 tx, rx;
 
-       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
-       prev_tx = (guint64)val;
-
-       netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
-       prev_rx = (guint64)val;
-
-       total_tx = prev_tx + cur_tx;
-       total_rx = prev_rx + cur_rx;
-
-       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx);
-       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx);
-}
-
-static void wifi_statistics_update_state(wifi_state_notifier_s *notifier,
-               char *service, wifi_service_state_e state, void *user_data)
-{
-       guint64 tx = 0, rx = 0;
-       guint64 last_tx = 0, last_rx = 0;
-       int val = 0;
-       static wifi_service_state_e prev_state = NETCONFIG_WIFI_UNKNOWN;
-
-       if (prev_state == NETCONFIG_WIFI_UNKNOWN) {
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
-               netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
-
-               prev_state = NETCONFIG_WIFI_IDLE;
-               return;
-       }
-
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) != TRUE)
-               return;
-
-       if (state == NETCONFIG_WIFI_CONNECTED) {
-               last_tx = tx;
-               last_rx = rx;
-       } else {
-               if (prev_state != NETCONFIG_WIFI_CONNECTED)
-                       return;
-
-               netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
-               last_tx = (guint64)val;
-
-               netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
-               last_rx = (guint64)val;
-
-               last_tx = tx < last_tx ? 0 : tx - last_tx;
-               last_rx = rx < last_rx ? 0 : rx - last_rx;
-       }
-
-       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx);
-       netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx);
-
-       prev_state = state;
+       netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE);
 }
 
-static wifi_state_notifier_s state_notifier = {
-               .notifier = NULL,
-               .service = NULL,
-               .wifi_state_changed = wifi_statistics_update_state,
-               .user_data = NULL,
-};
-
 void statistics_object_create_and_init(void)
 {
        DBG("Creating statistics object");
@@ -439,8 +420,7 @@ void statistics_object_create_and_init(void)
                ERR("Export with path failed");
        }
 
-       wifi_statistics_update_state(&state_notifier, NULL, NETCONFIG_WIFI_IDLE, NULL);
-       wifi_state_notifier_register(&state_notifier);
+       wifi_statistics_update_state();
 
        return;
 }
index 284973c..154f4a3 100755 (executable)
@@ -64,9 +64,6 @@ static int __netconfig_sta_firmware_stop(const char *interface_name)
        char *const args[] = { "/usr/bin/wlan.sh", "stop", (char *)interface_name, NULL };
        char *const envs[] = { NULL };
 
-       /* Update statistics before driver remove */
-       netconfig_wifi_statistics_update_powered_off();
-
        rv = netconfig_interface_down(interface_name);
        if (rv != TRUE)
                return -EIO;
index 5b0810a..6070118 100755 (executable)
@@ -293,66 +293,61 @@ static void __netconfig_wifi_data_activity_booster(int level)
 static void __netconfig_wifi_get_statistics(void)
 {
        static int last_transfer_state = 0;
-       static guint64 netconfig_wifi_tx_bytes = 0;
-       static guint64 netconfig_wifi_rx_bytes = 0;
        static int booster_tic = 0;
        static int old_level = 0;
        int booster_level = 0;
-       guint64 tx, rx, tx_diff, rx_diff;
+       guint64 tx, rx;
        int transfer_state;
 
-       if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) {
-               tx_diff = tx - netconfig_wifi_tx_bytes;
-               rx_diff = rx - netconfig_wifi_rx_bytes;
-
-               if (tx_diff > 0) {
-                       if (rx_diff > 0)
-                               transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX;
-                       else
-                               transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX;
-               } else {
-                       if (rx_diff > 0)
-                               transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX;
-                       else
-                               transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE;
-               }
+       if (netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE))
+               netconfig_wifi_set_bytes_pkt_vconf(tx, rx);
+
+       netconfig_wifi_get_bytes_default_iface(&tx, &rx);
+
+       if (tx > 0) {
+               if (rx > 0)
+                       transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX;
+               else
+                       transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX;
+       } else {
+               if (rx > 0)
+                       transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX;
+               else
+                       transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE;
+       }
 
-               if (transfer_state != last_transfer_state) {
-                       netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state);
-                       last_transfer_state = transfer_state;
-               }
+       if (transfer_state != last_transfer_state) {
+               netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state);
+               last_transfer_state = transfer_state;
+       }
 
-               /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */
-               if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 ||
-                       rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1)
-                       booster_level = 1;
-               else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 ||
-                               rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2)
-                       booster_level = 2;
-               else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 ||
-                               rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3)
-                       booster_level = 3;
-
-               if (old_level == booster_level) {
-                       if (--booster_tic <= 0) {
-                               __netconfig_wifi_data_activity_booster(booster_level);
-
-                               booster_tic = 2;
-                       }
-               } else {
+       /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */
+       if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 ||
+               rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1)
+               booster_level = 1;
+       else if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 ||
+                       rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2)
+               booster_level = 2;
+       else if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 ||
+                       rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3)
+               booster_level = 3;
+
+       if (old_level == booster_level) {
+               if (--booster_tic <= 0) {
                        __netconfig_wifi_data_activity_booster(booster_level);
 
-                       if (booster_level > 0)
-                               booster_tic = 2;
-                       else
-                               booster_tic = 0;
+                       booster_tic = 2;
                }
+       } else {
+               __netconfig_wifi_data_activity_booster(booster_level);
 
-               old_level = booster_level;
-
-               netconfig_wifi_tx_bytes = tx;
-               netconfig_wifi_rx_bytes = rx;
+               if (booster_level > 0)
+                       booster_tic = 2;
+               else
+                       booster_tic = 0;
        }
+
+       old_level = booster_level;
 }
 
 static gboolean __netconfig_wifi_update_statistics(gpointer data)
@@ -409,18 +404,31 @@ void netconfig_wifi_indicator_start(const char *interface_name,
        wifi_emit_rssi_changed((Wifi *)get_wifi_object(),
                interface_name, VCONFKEY_WIFI_STRENGTH_MAX);
 
-       netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL,
-               __netconfig_wifi_update_statistics, g_strdup(interface_name),
-               &netconfig_wifi_statistics_timer);
+       if (netconfig_wifi_statistics_timer == 0) {
+               netconfig_wifi_reset_last_bytes();
+               netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL,
+                       __netconfig_wifi_update_statistics, g_strdup(interface_name),
+                       &netconfig_wifi_statistics_timer);
+       }
 
        netconfig_battery_update_wifi_rssi(VCONFKEY_WIFI_STRENGTH_MAX);
 }
 
 void netconfig_wifi_indicator_stop(const char *interface_name)
 {
+       int wifi_state = 0;
+       guint64 tx, rx;
+
        INFO("Stop Wi-Fi indicator");
 
-       netconfig_stop_timer(&netconfig_wifi_statistics_timer);
+       netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
+       if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+               if (netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE))
+                       netconfig_wifi_set_bytes_pkt_vconf(tx, rx);
+
+               netconfig_stop_timer(&netconfig_wifi_statistics_timer);
+       }
 
        __destroy_rssi_data(interface_name);
 }
index 74d0830..d8e3b99 100755 (executable)
@@ -610,10 +610,27 @@ gboolean wifi_state_is_bss_found(void)
        return new_bss_found;
 }
 
+void __copy_device_statistics(wifi_device_data_s *dst_data, GSList *device_list)
+{
+       GSList *list;
+
+       for (list = device_list; list; list = list->next) {
+               wifi_device_data_s *org_data = list->data;
+               if (g_strcmp0(org_data->interface_name, dst_data->interface_name) == 0) {
+                       dst_data->tx = org_data->tx;
+                       dst_data->rx = org_data->rx;
+                       dst_data->tx_diff = org_data->tx_diff;
+                       dst_data->tx_diff = org_data->tx_diff;
+                       return;
+               }
+       }
+}
+
 gboolean wifi_state_update_device_list(void)
 {
        GVariant *message = NULL, *variant;
        GVariantIter *iter, *next;
+       GSList *device_list = NULL;
        const char *path;
        gchar *key;
        gboolean updated = FALSE;
@@ -626,7 +643,7 @@ gboolean wifi_state_update_device_list(void)
                return updated;
        }
 
-       g_slist_free_full(g_device_list, __device_free_data);
+       device_list = g_device_list;
        g_device_list = NULL;
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
@@ -658,6 +675,8 @@ gboolean wifi_state_update_device_list(void)
 
                                                        updated = TRUE;
 
+                                                       __copy_device_statistics(device_data, device_list);
+
                                                } else if (g_strcmp0(dev_key, "MAC.Address") == 0) {
                                                        if (device_data) {
                                                                sdata = g_variant_get_string(dev_var, NULL);
@@ -696,6 +715,8 @@ gboolean wifi_state_update_device_list(void)
 
        g_variant_iter_free(iter);
 
+       g_slist_free_full(device_list, __device_free_data);
+
        return updated;
 }