Loading src/com/android/server/connectivity/NetworkMonitor.java +1 −4 Original line number Diff line number Diff line Loading @@ -2984,10 +2984,7 @@ public class NetworkMonitor extends StateMachine { httpsProbe.join(); reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTPS, httpsProbe.result()); final boolean isHttpSuccessful = (httpProbe.result().isSuccessful() || (fallbackProbeResult != null && fallbackProbeResult.isSuccessful())); if (httpsProbe.result().isFailed() && isHttpSuccessful) { if (httpsProbe.result().isFailed() && httpProbe.result().isSuccessful()) { return CaptivePortalProbeResult.PARTIAL; } return httpsProbe.result(); Loading tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java +35 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileReader; import java.io.IOException; Loading Loading @@ -2654,4 +2655,38 @@ public abstract class IpClientIntegrationTestCommon { // due to the null V6ONLY_WAIT. assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU); } private static int getNumOpenFds() { return new File("/proc/" + Os.getpid() + "/fd").listFiles().length; } private void shutdownAndRecreateIpClient() throws Exception { mIpc.shutdown(); awaitIpClientShutdown(); mIpc = makeIpClient(); } @Test public void testNoFdLeaks() throws Exception { // Shut down and restart IpClient once to ensure that any fds that are opened the first // time it runs do not cause the test to fail. doDualStackProvisioning(); shutdownAndRecreateIpClient(); // Unfortunately we cannot use a large number of iterations as it would make the test run // too slowly. On crosshatch-eng each iteration takes ~250ms. final int iterations = 10; final int before = getNumOpenFds(); for (int i = 0; i < iterations; i++) { doDualStackProvisioning(); shutdownAndRecreateIpClient(); // The last time this loop runs, mIpc will be shut down in tearDown. } final int after = getNumOpenFds(); // Check that the number of open fds is the same as before. // If this exact match becomes flaky, we could add some tolerance here (e.g., allow 2-3 // extra fds), since it's likely that any leak would at least leak one FD per loop. assertEquals("Fd leak after " + iterations + " iterations: ", before, after); } } tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +21 −9 Original line number Diff line number Diff line Loading @@ -1109,6 +1109,14 @@ public class NetworkMonitorTest { runPortalNetworkTest(); } @Test public void testIsCaptivePortal_HttpSucceedFallbackProbeIsPortal() throws Exception { setSslException(mHttpsConnection); setStatus(mHttpConnection, 204); setPortal302(mFallbackConnection); runPortalNetworkTest(); } @Test public void testIsCaptivePortal_FallbackProbeIsNotPortal() throws Exception { setSslException(mHttpsConnection); Loading Loading @@ -1435,13 +1443,13 @@ public class NetworkMonitorTest { } @Test public void testIsCaptivePortal_FallbackSpecIsPartial() throws Exception { public void testIsCaptivePortal_FallbackSpecIsFail() throws Exception { setupFallbackSpec(); set302(mOtherFallbackConnection, "https://www.google.com/test?q=3"); // HTTPS failed, fallback spec went through -> partial connectivity runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); verify(mOtherFallbackConnection, times(1)).getResponseCode(); verify(mFallbackConnection, never()).getResponseCode(); } Loading Loading @@ -2208,13 +2216,16 @@ public class NetworkMonitorTest { setStatus(mFallbackConnection, 500); runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP); } resetCallbacks(); @Test public void testIsCaptivePortal_OnlyFallbackSucceed() throws Exception { setStatus(mHttpsConnection, 500); setStatus(mHttpConnection, 500); setStatus(mFallbackConnection, 204); runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); } private void assertIpAddressArrayEquals(String[] expected, InetAddress[] actual) { Loading Loading @@ -2274,8 +2285,9 @@ public class NetworkMonitorTest { setStatus(mFallbackConnection, 204); nm.forceReevaluation(Process.myUid()); // Expect to send HTTP, HTTPs, FALLBACK and evaluation results. verifyNetworkTested(NETWORK_VALIDATION_RESULT_PARTIAL, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); } @Test Loading Loading
src/com/android/server/connectivity/NetworkMonitor.java +1 −4 Original line number Diff line number Diff line Loading @@ -2984,10 +2984,7 @@ public class NetworkMonitor extends StateMachine { httpsProbe.join(); reportHttpProbeResult(NETWORK_VALIDATION_PROBE_HTTPS, httpsProbe.result()); final boolean isHttpSuccessful = (httpProbe.result().isSuccessful() || (fallbackProbeResult != null && fallbackProbeResult.isSuccessful())); if (httpsProbe.result().isFailed() && isHttpSuccessful) { if (httpsProbe.result().isFailed() && httpProbe.result().isSuccessful()) { return CaptivePortalProbeResult.PARTIAL; } return httpsProbe.result(); Loading
tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java +35 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import java.io.BufferedReader; import java.io.File; import java.io.FileDescriptor; import java.io.FileReader; import java.io.IOException; Loading Loading @@ -2654,4 +2655,38 @@ public abstract class IpClientIntegrationTestCommon { // due to the null V6ONLY_WAIT. assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU); } private static int getNumOpenFds() { return new File("/proc/" + Os.getpid() + "/fd").listFiles().length; } private void shutdownAndRecreateIpClient() throws Exception { mIpc.shutdown(); awaitIpClientShutdown(); mIpc = makeIpClient(); } @Test public void testNoFdLeaks() throws Exception { // Shut down and restart IpClient once to ensure that any fds that are opened the first // time it runs do not cause the test to fail. doDualStackProvisioning(); shutdownAndRecreateIpClient(); // Unfortunately we cannot use a large number of iterations as it would make the test run // too slowly. On crosshatch-eng each iteration takes ~250ms. final int iterations = 10; final int before = getNumOpenFds(); for (int i = 0; i < iterations; i++) { doDualStackProvisioning(); shutdownAndRecreateIpClient(); // The last time this loop runs, mIpc will be shut down in tearDown. } final int after = getNumOpenFds(); // Check that the number of open fds is the same as before. // If this exact match becomes flaky, we could add some tolerance here (e.g., allow 2-3 // extra fds), since it's likely that any leak would at least leak one FD per loop. assertEquals("Fd leak after " + iterations + " iterations: ", before, after); } }
tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +21 −9 Original line number Diff line number Diff line Loading @@ -1109,6 +1109,14 @@ public class NetworkMonitorTest { runPortalNetworkTest(); } @Test public void testIsCaptivePortal_HttpSucceedFallbackProbeIsPortal() throws Exception { setSslException(mHttpsConnection); setStatus(mHttpConnection, 204); setPortal302(mFallbackConnection); runPortalNetworkTest(); } @Test public void testIsCaptivePortal_FallbackProbeIsNotPortal() throws Exception { setSslException(mHttpsConnection); Loading Loading @@ -1435,13 +1443,13 @@ public class NetworkMonitorTest { } @Test public void testIsCaptivePortal_FallbackSpecIsPartial() throws Exception { public void testIsCaptivePortal_FallbackSpecIsFail() throws Exception { setupFallbackSpec(); set302(mOtherFallbackConnection, "https://www.google.com/test?q=3"); // HTTPS failed, fallback spec went through -> partial connectivity runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); verify(mOtherFallbackConnection, times(1)).getResponseCode(); verify(mFallbackConnection, never()).getResponseCode(); } Loading Loading @@ -2208,13 +2216,16 @@ public class NetworkMonitorTest { setStatus(mFallbackConnection, 500); runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_HTTP); } resetCallbacks(); @Test public void testIsCaptivePortal_OnlyFallbackSucceed() throws Exception { setStatus(mHttpsConnection, 500); setStatus(mHttpConnection, 500); setStatus(mFallbackConnection, 204); runPartialConnectivityNetworkTest( NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); } private void assertIpAddressArrayEquals(String[] expected, InetAddress[] actual) { Loading Loading @@ -2274,8 +2285,9 @@ public class NetworkMonitorTest { setStatus(mFallbackConnection, 204); nm.forceReevaluation(Process.myUid()); // Expect to send HTTP, HTTPs, FALLBACK and evaluation results. verifyNetworkTested(NETWORK_VALIDATION_RESULT_PARTIAL, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK); runNetworkTest(VALIDATION_RESULT_INVALID, NETWORK_VALIDATION_PROBE_DNS | NETWORK_VALIDATION_PROBE_FALLBACK, null /* redirectUrl */); } @Test Loading