facebookarchive / network-connection-class

Listen to current network traffic in the app and categorize the quality of the network.
Other
3.19k stars 515 forks source link

Clear previous bytes on stop sampling #7

Closed nipuns closed 9 years ago

nipuns commented 9 years ago

Issue: parseDataUsageForUidAndTag() method always calculates diff from last read value of bytes transferred (stored in sPreviousBytes). Consider the following scenario:

  1. We call start sampling, initiate network call, end network call, call end sampling. 'sPreviousBytes' now has the value of rx_bytes from /proc/net/xt_qtaguid/stats file.
  2. We make some other network calls in the app which are NOT sampled. rx_bytes in /proc/net/xt_qtaguid/stats gets updated.
  3. We call start sampling & initiate another network call.

Now in the first call to addSample method , the diff calculated between the current value of rx_bytes and sPreviousBytes is the amount of data transferred in between the 2 sessions. The time duration for this sample is very small as mLastTimeReading is reset in startSampling method. This results in a incorrect data point being logged.

Fix: Reset the previous bytes value when a sampling session ends.

SeyelentEco commented 9 years ago

Thanks!