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

Commit d01ea625 authored by lucaslin's avatar lucaslin
Browse files

Improve partial connectivity

Improve the design and fix some nits.

Bug: 113450764
Test: 1. Build pass
      2. atest FrameworksNetTests
      3. atest NetworkStackTests
      4. Change captive_portal_https_url to https://invalid.com
      to simulate partial connectivity.
Change-Id: Ia56645841d00d2ed8406cfeacb86a4a27fd58650
parent b0573967
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -253,9 +253,9 @@ public class NetworkStackService extends Service {
        }
        }


        @Override
        @Override
        public void notifyAcceptPartialConnectivity() {
        public void setAcceptPartialConnectivity() {
            checkNetworkStackCallingPermission();
            checkNetworkStackCallingPermission();
            mNm.notifyAcceptPartialConnectivity();
            mNm.setAcceptPartialConnectivity();
        }
        }


        @Override
        @Override
+24 −7
Original line number Original line Diff line number Diff line
@@ -319,7 +319,8 @@ public class NetworkMonitor extends StateMachine {
    private final DnsStallDetector mDnsStallDetector;
    private final DnsStallDetector mDnsStallDetector;
    private long mLastProbeTime;
    private long mLastProbeTime;
    // Set to true if data stall is suspected and reset to false after metrics are sent to statsd.
    // Set to true if data stall is suspected and reset to false after metrics are sent to statsd.
    private boolean mCollectDataStallMetrics = false;
    private boolean mCollectDataStallMetrics;
    private boolean mAcceptPartialConnectivity;


    public NetworkMonitor(Context context, INetworkMonitorCallbacks cb, Network network,
    public NetworkMonitor(Context context, INetworkMonitorCallbacks cb, Network network,
            SharedLog validationLog) {
            SharedLog validationLog) {
@@ -386,10 +387,11 @@ public class NetworkMonitor extends StateMachine {
    }
    }


    /**
    /**
     * ConnectivityService notifies NetworkMonitor that the user accepts partial connectivity and
     * ConnectivityService notifies NetworkMonitor that the user already accepted partial
     * NetworkMonitor should ignore the https probe.
     * connectivity previously, so NetworkMonitor can validate the network even if it has partial
     * connectivity.
     */
     */
    public void notifyAcceptPartialConnectivity() {
    public void setAcceptPartialConnectivity() {
        sendMessage(EVENT_ACCEPT_PARTIAL_CONNECTIVITY);
        sendMessage(EVENT_ACCEPT_PARTIAL_CONNECTIVITY);
    }
    }


@@ -651,9 +653,11 @@ public class NetworkMonitor extends StateMachine {
                case EVENT_DNS_NOTIFICATION:
                case EVENT_DNS_NOTIFICATION:
                    mDnsStallDetector.accumulateConsecutiveDnsTimeoutCount(message.arg1);
                    mDnsStallDetector.accumulateConsecutiveDnsTimeoutCount(message.arg1);
                    break;
                    break;
                // Set mAcceptPartialConnectivity to true and if network start evaluating or
                // re-evaluating and get the result of partial connectivity, ProbingState will
                // disable HTTPS probe and transition to EvaluatingPrivateDnsState.
                case EVENT_ACCEPT_PARTIAL_CONNECTIVITY:
                case EVENT_ACCEPT_PARTIAL_CONNECTIVITY:
                    mUseHttps = false;
                    mAcceptPartialConnectivity = true;
                    transitionTo(mEvaluatingPrivateDnsState);
                    break;
                    break;
                default:
                default:
                    break;
                    break;
@@ -849,6 +853,14 @@ public class NetworkMonitor extends StateMachine {
                    // ignore any re-evaluation requests. After, restart the
                    // ignore any re-evaluation requests. After, restart the
                    // evaluation process via EvaluatingState#enter.
                    // evaluation process via EvaluatingState#enter.
                    return (mEvaluateAttempts < IGNORE_REEVALUATE_ATTEMPTS) ? HANDLED : NOT_HANDLED;
                    return (mEvaluateAttempts < IGNORE_REEVALUATE_ATTEMPTS) ? HANDLED : NOT_HANDLED;
                // Disable HTTPS probe and transition to EvaluatingPrivateDnsState because:
                // 1. Network is connected and finish the network validation.
                // 2. NetworkMonitor detects network is partial connectivity and user accepts it.
                case EVENT_ACCEPT_PARTIAL_CONNECTIVITY:
                    mAcceptPartialConnectivity = true;
                    mUseHttps = false;
                    transitionTo(mEvaluatingPrivateDnsState);
                    return HANDLED;
                default:
                default:
                    return NOT_HANDLED;
                    return NOT_HANDLED;
            }
            }
@@ -1081,7 +1093,12 @@ public class NetworkMonitor extends StateMachine {
                        logNetworkEvent(NetworkEvent.NETWORK_PARTIAL_CONNECTIVITY);
                        logNetworkEvent(NetworkEvent.NETWORK_PARTIAL_CONNECTIVITY);
                        notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY,
                        notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY,
                                probeResult.redirectUrl);
                                probeResult.redirectUrl);
                        if (mAcceptPartialConnectivity) {
                            mUseHttps = false;
                            transitionTo(mEvaluatingPrivateDnsState);
                        } else {
                            transitionTo(mWaitingForNextProbeState);
                            transitionTo(mWaitingForNextProbeState);
                        }
                    } else {
                    } else {
                        logNetworkEvent(NetworkEvent.NETWORK_VALIDATION_FAILED);
                        logNetworkEvent(NetworkEvent.NETWORK_VALIDATION_FAILED);
                        notifyNetworkTested(NETWORK_TEST_RESULT_INVALID, probeResult.redirectUrl);
                        notifyNetworkTested(NETWORK_TEST_RESULT_INVALID, probeResult.redirectUrl);
+1 −1
Original line number Original line Diff line number Diff line
@@ -583,7 +583,7 @@ public class NetworkMonitorTest {
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
                .notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY, null);
                .notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY, null);


        nm.notifyAcceptPartialConnectivity();
        nm.setAcceptPartialConnectivity();
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
        verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1))
                .notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null);
                .notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null);
    }
    }