diff options
author | lucaslin <lucaslin@google.com> | 2019-03-20 18:21:59 +0800 |
---|---|---|
committer | lucaslin <lucaslin@google.com> | 2019-03-20 18:21:59 +0800 |
commit | d01ea625de7daf3e43f9a3f721f7ad85884bdc2d (patch) | |
tree | 57394ff4c358b1e23a77db9f95978f835891ead4 | |
parent | b05739670a5036519ac37cc9eacc0c6fc3a91956 (diff) |
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
3 files changed, 27 insertions, 10 deletions
diff --git a/src/com/android/server/NetworkStackService.java b/src/com/android/server/NetworkStackService.java index 72955bb..a8bd0a1 100644 --- a/src/com/android/server/NetworkStackService.java +++ b/src/com/android/server/NetworkStackService.java @@ -253,9 +253,9 @@ public class NetworkStackService extends Service { } @Override - public void notifyAcceptPartialConnectivity() { + public void setAcceptPartialConnectivity() { checkNetworkStackCallingPermission(); - mNm.notifyAcceptPartialConnectivity(); + mNm.setAcceptPartialConnectivity(); } @Override diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java index fc56da7..31fa5c5 100644 --- a/src/com/android/server/connectivity/NetworkMonitor.java +++ b/src/com/android/server/connectivity/NetworkMonitor.java @@ -319,7 +319,8 @@ public class NetworkMonitor extends StateMachine { private final DnsStallDetector mDnsStallDetector; private long mLastProbeTime; // 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, SharedLog validationLog) { @@ -386,10 +387,11 @@ public class NetworkMonitor extends StateMachine { } /** - * ConnectivityService notifies NetworkMonitor that the user accepts partial connectivity and - * NetworkMonitor should ignore the https probe. + * ConnectivityService notifies NetworkMonitor that the user already accepted partial + * 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); } @@ -651,9 +653,11 @@ public class NetworkMonitor extends StateMachine { case EVENT_DNS_NOTIFICATION: mDnsStallDetector.accumulateConsecutiveDnsTimeoutCount(message.arg1); 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: - mUseHttps = false; - transitionTo(mEvaluatingPrivateDnsState); + mAcceptPartialConnectivity = true; break; default: break; @@ -849,6 +853,14 @@ public class NetworkMonitor extends StateMachine { // ignore any re-evaluation requests. After, restart the // evaluation process via EvaluatingState#enter. 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: return NOT_HANDLED; } @@ -1081,7 +1093,12 @@ public class NetworkMonitor extends StateMachine { logNetworkEvent(NetworkEvent.NETWORK_PARTIAL_CONNECTIVITY); notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY, probeResult.redirectUrl); - transitionTo(mWaitingForNextProbeState); + if (mAcceptPartialConnectivity) { + mUseHttps = false; + transitionTo(mEvaluatingPrivateDnsState); + } else { + transitionTo(mWaitingForNextProbeState); + } } else { logNetworkEvent(NetworkEvent.NETWORK_VALIDATION_FAILED); notifyNetworkTested(NETWORK_TEST_RESULT_INVALID, probeResult.redirectUrl); diff --git a/tests/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/src/com/android/server/connectivity/NetworkMonitorTest.java index d93aef2..d732c4e 100644 --- a/tests/src/com/android/server/connectivity/NetworkMonitorTest.java +++ b/tests/src/com/android/server/connectivity/NetworkMonitorTest.java @@ -583,7 +583,7 @@ public class NetworkMonitorTest { verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)) .notifyNetworkTested(NETWORK_TEST_RESULT_PARTIAL_CONNECTIVITY, null); - nm.notifyAcceptPartialConnectivity(); + nm.setAcceptPartialConnectivity(); verify(mCallbacks, timeout(HANDLER_TIMEOUT_MS).times(1)) .notifyNetworkTested(NETWORK_TEST_RESULT_VALID, null); } |