Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d740dc38 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Reduce redundant network probing and prevent probing loop

NetworkMonitor did not limit the probe usage on a non-metered
network for data stall detection verification. As NM polls TCP
information with certain timer(10s for now), NM may get legacy
information if the data stall suspicion comes from other
signals, e.g. DNS. It may cause false alarm probing on the
network. The first tcp polling event will be 10s later. It may
cause a loop due to dns result received w/o latest tcp info.
Hence, start first polling while entering validated state.

Bug: 145275899
Bug: 147673885
Test: atest NetworkStackTests NetworkStackNextTests
Test: Manually test with such network and observe the probe
      behavior

Change-Id: Icb56ebe9d8304880d4f9f4fa8153b6e3727000fb
parent f52fa0ea
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ public class TcpSocketTracker {
            }
        }
        final SocketInfo info = new SocketInfo(tcpInfo, family, mark, time);
        log("pollSocketsInfo, " + info);
        log("parseSockInfo, " + info);
        return info;
    }

+17 −6
Original line number Diff line number Diff line
@@ -752,9 +752,20 @@ public class NetworkMonitor extends StateMachine {
            }
            mEvaluationState.reportEvaluationResult(result, null /* redirectUrl */);
            mValidations++;
            initSocketTrackingIfRequired();
            // start periodical polling.
            sendTcpPollingEvent();
        }

        private void initSocketTrackingIfRequired() {
            if (!isValidationRequired()) return;

            final TcpSocketTracker tst = getTcpSocketTracker();
            if (tst != null) {
                tst.pollSocketsInfo();
            }
        }

        @Override
        public boolean processMessage(Message message) {
            switch (message.what) {
@@ -2229,7 +2240,7 @@ public class NetworkMonitor extends StateMachine {
    @VisibleForTesting
    protected boolean isDataStall() {
        Boolean result = null;
        final StringJoiner msg = VDBG_STALL ? new StringJoiner(", ") : null;
        final StringJoiner msg = (DBG || VDBG_STALL) ? new StringJoiner(", ") : null;
        // Reevaluation will generate traffic. Thus, set a minimal reevaluation timer to limit the
        // possible traffic cost in metered network.
        if (!mNetworkCapabilities.hasCapability(NET_CAPABILITY_NOT_METERED)
@@ -2247,9 +2258,9 @@ public class NetworkMonitor extends StateMachine {
            } else if (tst.isDataStallSuspected()) {
                result = true;
            }
            if (VDBG_STALL) {
            if (DBG || VDBG_STALL) {
                msg.add("tcp packets received=" + tst.getLatestReceivedCount())
                     .add("tcp fail rate=" + tst.getLatestPacketFailPercentage());
                    .add("latest tcp fail rate=" + tst.getLatestPacketFailPercentage());
            }
        }

@@ -2262,13 +2273,13 @@ public class NetworkMonitor extends StateMachine {
                result = true;
                logNetworkEvent(NetworkEvent.NETWORK_CONSECUTIVE_DNS_TIMEOUT_FOUND);
            }
            if (VDBG_STALL) {
            if (DBG || VDBG_STALL) {
                msg.add("consecutive dns timeout count="
                        + mDnsStallDetector.getConsecutiveTimeoutCount());
            }
        }

        if (VDBG_STALL) {
        // log only data stall suspected.
        if ((DBG && Boolean.TRUE.equals(result)) || VDBG_STALL) {
            log("isDataStall: result=" + result + ", " + msg);
        }