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

Connection class doesn't change even when offline #24

Closed sreejithr closed 8 years ago

sreejithr commented 8 years ago

The connection class doesn't change from what it used to be, when the phone goes offline. I traced the issue to this in line 91 in ConnectionClassManager.java:

    //Ignore garbage values.
    if (timeInMs == 0 || (bytes) * 1.0 / (timeInMs) * BYTES_TO_BITS < BANDWIDTH_LOWER_BOUND) {
      return;
    }

Here, when bytes is 0 (because there's no byte diff), it just fails to add this bandwidth. Is this by design?

P.S: My app is running code from release 1.0.1 (commit).

sreejithr commented 8 years ago

Ok. This is what I understand. The phone could be idle (not uploading/downloading anything) and still be connected to the internet. So, a zero byte diff doesn't imply phone is offline. So adding such values to the moving average will pollute the average. Am I correct?

SeyelentEco commented 8 years ago

Yes, the zero byte check is for situations where you are idle or for situations where we're getting so few bytes, it doesn't make sense to analyze them directly and we should wait until more data comes to make any calculation.

Regarding offline, we handle the offline connection check separately in our apps since the decisions you need to make when the user is offline are different than if they have a connection and it's just slow.