Loading src/com/android/server/connectivity/NetworkMonitor.java +5 −0 Original line number Diff line number Diff line Loading @@ -793,6 +793,11 @@ public class NetworkMonitor extends StateMachine { return HANDLED; case CMD_FORCE_REEVALUATION: case CMD_CAPTIVE_PORTAL_RECHECK: if (getCurrentState() == mDefaultState) { // Before receiving CMD_NETWORK_CONNECTED (when still in mDefaultState), // requests to reevaluate are not valid: drop them. return HANDLED; } String msg = "Forcing reevaluation for UID " + message.arg1; final DnsStallDetector dsd = getDnsStallDetector(); if (dsd != null) { Loading tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.after; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeastOnce; Loading Loading @@ -1229,6 +1230,32 @@ public class NetworkMonitorTest { verify(mCapportApiConnection, times(1)).getResponseCode(); } @Test public void testIsCaptivePortal_NoRevalidationBeforeNetworkConnected() throws Exception { assumeTrue(CaptivePortalDataShimImpl.isSupported()); final NetworkMonitor nm = makeCellMeteredNetworkMonitor(); final LinkProperties lp = makeCapportLPs(); // LinkProperties changed, but NM should not revalidate before notifyNetworkConnected nm.notifyLinkPropertiesChanged(lp); verify(mHttpConnection, after(100).never()).getResponseCode(); verify(mHttpsConnection, never()).getResponseCode(); verify(mCapportApiConnection, never()).getResponseCode(); setValidProbes(); setApiContent(mCapportApiConnection, "{'captive': true, " + "'user-portal-url': '" + TEST_LOGIN_URL + "'}"); // After notifyNetworkConnected, validation uses the capport API contents nm.notifyNetworkConnected(lp, CELL_METERED_CAPABILITIES); verifyNetworkTested(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL); verify(mHttpConnection, never()).getResponseCode(); verify(mCapportApiConnection).getResponseCode(); } @Test public void testIsCaptivePortal_CapportApiNotPortalNotValidated() throws Exception { assumeTrue(CaptivePortalDataShimImpl.isSupported()); Loading Loading
src/com/android/server/connectivity/NetworkMonitor.java +5 −0 Original line number Diff line number Diff line Loading @@ -793,6 +793,11 @@ public class NetworkMonitor extends StateMachine { return HANDLED; case CMD_FORCE_REEVALUATION: case CMD_CAPTIVE_PORTAL_RECHECK: if (getCurrentState() == mDefaultState) { // Before receiving CMD_NETWORK_CONNECTED (when still in mDefaultState), // requests to reevaluate are not valid: drop them. return HANDLED; } String msg = "Forcing reevaluation for UID " + message.arg1; final DnsStallDetector dsd = getDnsStallDetector(); if (dsd != null) { Loading
tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ import static org.junit.Assume.assumeTrue; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.after; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeastOnce; Loading Loading @@ -1229,6 +1230,32 @@ public class NetworkMonitorTest { verify(mCapportApiConnection, times(1)).getResponseCode(); } @Test public void testIsCaptivePortal_NoRevalidationBeforeNetworkConnected() throws Exception { assumeTrue(CaptivePortalDataShimImpl.isSupported()); final NetworkMonitor nm = makeCellMeteredNetworkMonitor(); final LinkProperties lp = makeCapportLPs(); // LinkProperties changed, but NM should not revalidate before notifyNetworkConnected nm.notifyLinkPropertiesChanged(lp); verify(mHttpConnection, after(100).never()).getResponseCode(); verify(mHttpsConnection, never()).getResponseCode(); verify(mCapportApiConnection, never()).getResponseCode(); setValidProbes(); setApiContent(mCapportApiConnection, "{'captive': true, " + "'user-portal-url': '" + TEST_LOGIN_URL + "'}"); // After notifyNetworkConnected, validation uses the capport API contents nm.notifyNetworkConnected(lp, CELL_METERED_CAPABILITIES); verifyNetworkTested(VALIDATION_RESULT_PORTAL, 0 /* probesSucceeded */, TEST_LOGIN_URL); verify(mHttpConnection, never()).getResponseCode(); verify(mCapportApiConnection).getResponseCode(); } @Test public void testIsCaptivePortal_CapportApiNotPortalNotValidated() throws Exception { assumeTrue(CaptivePortalDataShimImpl.isSupported()); Loading