Merge "Update CapportData in CapportApiProbeResult to be nullable" into rvc-dev
diff --git a/src/android/net/captiveportal/CapportApiProbeResult.java b/src/android/net/captiveportal/CapportApiProbeResult.java
index f693bed..e35b791 100644
--- a/src/android/net/captiveportal/CapportApiProbeResult.java
+++ b/src/android/net/captiveportal/CapportApiProbeResult.java
@@ -25,11 +25,12 @@
* @hide
*/
public class CapportApiProbeResult extends CaptivePortalProbeResult {
- @NonNull
+ // CaptivePortalData may be null if the capport API does not send any valid reply.
+ @Nullable
private final CaptivePortalDataShim mCapportData;
public CapportApiProbeResult(@NonNull CaptivePortalProbeResult result,
- @NonNull CaptivePortalDataShim capportData) {
+ @Nullable CaptivePortalDataShim capportData) {
this(result.mHttpResponseCode, result.redirectUrl, result.detectUrl, capportData,
result.probeType);
}
diff --git a/src/com/android/server/connectivity/NetworkMonitor.java b/src/com/android/server/connectivity/NetworkMonitor.java
index 8493816..b6b1fff 100755
--- a/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/src/com/android/server/connectivity/NetworkMonitor.java
@@ -2628,7 +2628,7 @@
validationLog("Missing user-portal-url from capport response");
return new CapportApiProbeResult(
sendDnsAndHttpProbes(mProxy, mUrl, ValidationProbeEvent.PROBE_HTTP),
- capportData);
+ null /* capportData */);
}
final String loginUrlString = capportData.getUserPortalUrl().toString();
// Starting from R (where CaptivePortalData was introduced), the captive portal app
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
index 00fe17c..a3ef532 100644
--- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
+++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -1152,7 +1152,29 @@
}
@Test
- public void testIsCaptivePortal_CapportApiIsPortal() throws Exception {
+ public void testIsCaptivePortal_CapportApiIsPortalWithNullPortalUrl() throws Exception {
+ assumeTrue(CaptivePortalDataShimImpl.isSupported());
+ setSslException(mHttpsConnection);
+ final long bytesRemaining = 10_000L;
+ final long secondsRemaining = 500L;
+ // Set content without partal url.
+ setApiContent(mCapportApiConnection, "{'captive': true,"
+ + "'venue-info-url': '" + TEST_VENUE_INFO_URL + "',"
+ + "'bytes-remaining': " + bytesRemaining + ","
+ + "'seconds-remaining': " + secondsRemaining + "}");
+ setPortal302(mHttpConnection);
+
+ runNetworkTest(makeCapportLPs(), CELL_METERED_CAPABILITIES, VALIDATION_RESULT_PORTAL,
+ 0 /* probesSucceeded*/, TEST_LOGIN_URL);
+
+ verify(mCapportApiConnection).getResponseCode();
+
+ verify(mHttpConnection, times(1)).getResponseCode();
+ verify(mCallbacks, never()).notifyCaptivePortalDataChanged(any());
+ }
+
+ @Test
+ public void testIsCaptivePortal_CapportApiIsPortalWithValidPortalUrl() throws Exception {
assumeTrue(CaptivePortalDataShimImpl.isSupported());
setSslException(mHttpsConnection);
final long bytesRemaining = 10_000L;