Snap for 8441503 from 04ec66f365138532279684ffc5886758efa7c486 to mainline-cellbroadcast-release Change-Id: I0fbe0c1175242f2f81b9ce14ab5bf2cfaf4a6968
diff --git a/apishim/31/com/android/networkstack/apishim/api31/NetworkAgentConfigShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/NetworkAgentConfigShimImpl.java index ac97c60..a2fb136 100644 --- a/apishim/31/com/android/networkstack/apishim/api31/NetworkAgentConfigShimImpl.java +++ b/apishim/31/com/android/networkstack/apishim/api31/NetworkAgentConfigShimImpl.java
@@ -17,7 +17,9 @@ package com.android.networkstack.apishim.api31; import android.net.NetworkAgentConfig; +import android.net.networkstack.aidl.NetworkMonitorParameters; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.android.modules.utils.build.SdkLevel; @@ -44,13 +46,16 @@ */ public static NetworkAgentConfigShim newInstance(@Nullable final NetworkAgentConfig config) { if (!SdkLevel.isAtLeastS()) { - return new NetworkAgentConfigShimImpl(null); + return new com.android.networkstack.apishim.api29.NetworkAgentConfigShimImpl(); } return new NetworkAgentConfigShimImpl( (config != null) ? config : new NetworkAgentConfig.Builder().build()); } - public NetworkAgentConfig getConfig() { - return mNetworkAgentConfig; + /** + * Set the NetworkAgentConfig into the given {@link NetworkMonitorParameters} + */ + public void writeToNetworkMonitorParams(@NonNull NetworkMonitorParameters params) { + params.networkAgentConfig = mNetworkAgentConfig; } }
diff --git a/apishim/common/com/android/networkstack/apishim/common/NetworkAgentConfigShim.java b/apishim/common/com/android/networkstack/apishim/common/NetworkAgentConfigShim.java index da60300..55e218d 100644 --- a/apishim/common/com/android/networkstack/apishim/common/NetworkAgentConfigShim.java +++ b/apishim/common/com/android/networkstack/apishim/common/NetworkAgentConfigShim.java
@@ -16,7 +16,9 @@ package com.android.networkstack.apishim.common; -import android.net.NetworkAgentConfig; +import android.net.networkstack.aidl.NetworkMonitorParameters; + +import androidx.annotation.NonNull; /** * A shim for NetworkAgentConfig @@ -28,9 +30,10 @@ boolean isVpnValidationRequired(); /** - * Return the config. + * Set the NetworkAgentConfig into the given {@link NetworkMonitorParameters} */ - default NetworkAgentConfig getConfig() throws UnsupportedApiLevelException { + default void writeToNetworkMonitorParams(@NonNull NetworkMonitorParameters params) + throws UnsupportedApiLevelException { throw new UnsupportedApiLevelException("Only supported from API 31"); } }
diff --git a/common/networkstackclient/src/android/net/ip/IpClientUtil.java b/common/networkstackclient/src/android/net/ip/IpClientUtil.java index d488578..7636abd 100644 --- a/common/networkstackclient/src/android/net/ip/IpClientUtil.java +++ b/common/networkstackclient/src/android/net/ip/IpClientUtil.java
@@ -120,19 +120,27 @@ mCb.onNewDhcpResults(dhcpResults); } + // LinkProperties always have parcelSensitiveFields=false after parceling + // and unparceling, so the IIpClientCallback caller's side will always receive + // LinkProperties that do not have the flag set, except on Go devices where + // IpClient is running in the system_server, it's possible that no parceling + // happens and the object is sent as true, which results in wifi throws the + // UnsupportedOperationException when calling LinkProperties.clear() and then + // reboot. To keep the consistent behavior, deliver LinkProperties with + // mParcelSensitiveFields=false to wifi upon callback is triggered. @Override public void onProvisioningSuccess(LinkProperties newLp) { - mCb.onProvisioningSuccess(newLp); + mCb.onProvisioningSuccess(new LinkProperties(newLp)); } @Override public void onProvisioningFailure(LinkProperties newLp) { - mCb.onProvisioningFailure(newLp); + mCb.onProvisioningFailure(new LinkProperties(newLp)); } // Invoked on LinkProperties changes. @Override public void onLinkPropertiesChange(LinkProperties newLp) { - mCb.onLinkPropertiesChange(newLp); + mCb.onLinkPropertiesChange(new LinkProperties(newLp)); } // Called when the internal IpReachabilityMonitor (if enabled) has
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java b/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java index da4fb5e..f423862 100644 --- a/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java +++ b/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java
@@ -59,6 +59,7 @@ import static com.android.net.module.util.NetworkStackConstants.PIO_FLAG_AUTONOMOUS; import static com.android.net.module.util.NetworkStackConstants.PIO_FLAG_ON_LINK; import static com.android.testutils.MiscAsserts.assertThrows; +import static com.android.testutils.ParcelUtils.parcelingRoundTrip; import static com.android.testutils.TestPermissionUtil.runAsShell; import static junit.framework.Assert.fail; @@ -2320,7 +2321,7 @@ assertIpMemoryStoreNetworkAttributes(TEST_LEASE_DURATION_S, currentTime, TEST_DEFAULT_MTU); } - private void runDhcpClientCaptivePortalApiTest(boolean featureEnabled, + private LinkProperties runDhcpClientCaptivePortalApiTest(boolean featureEnabled, boolean serverSendsOption) throws Exception { startIpClientProvisioning(false /* isDhcpLeaseCacheEnabled */, false /* shouldReplyRapidCommitAck */, false /* isPreConnectionEnabled */, @@ -2347,10 +2348,12 @@ // Ensure that the URL was set as expected in the callbacks. // Can't verify the URL up to Q as there is no such attribute in LinkProperties. - if (!ShimUtils.isAtLeastR()) return; + if (!ShimUtils.isAtLeastR()) return null; verify(mCb, atLeastOnce()).onLinkPropertiesChange(captor.capture()); - assertTrue(captor.getAllValues().stream().anyMatch( - lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl()))); + final LinkProperties expectedLp = captor.getAllValues().stream().findFirst().get(); + assertNotNull(expectedLp); + assertEquals(expectedUrl, expectedLp.getCaptivePortalApiUrl()); + return expectedLp; } @Test @@ -2368,6 +2371,30 @@ } @Test + public void testDhcpClientCaptivePortalApiEnabled_ParcelSensitiveFields() throws Exception { + // Only run the test on platforms / builds where the API is enabled + assumeTrue(CaptivePortalDataShimImpl.isSupported()); + LinkProperties lp = runDhcpClientCaptivePortalApiTest(true /* featureEnabled */, + true /* serverSendsOption */); + + // Integration test process runs in the same process with network stack module, there + // won't be any IPC call happened on IpClientCallbacks, manually run parcelingRoundTrip + // to parcel and unparcel the LinkProperties to simulate what happens during the binder + // call. In this case lp should contain the senstive data but mParcelSensitiveFields is + // false after round trip. + if (useNetworkStackSignature()) { + lp = parcelingRoundTrip(lp); + } + final Uri expectedUrl = Uri.parse(TEST_CAPTIVE_PORTAL_URL); + assertEquals(expectedUrl, lp.getCaptivePortalApiUrl()); + + // Parcel and unparcel the captured LinkProperties, mParcelSensitiveFields is false, + // CaptivePortalApiUrl should be null after parceling round trip. + final LinkProperties unparceled = parcelingRoundTrip(lp); + assertNull(unparceled.getCaptivePortalApiUrl()); + } + + @Test public void testDhcpClientCaptivePortalApiDisabled() throws Exception { // Only run the test on platforms / builds where the API is disabled assumeFalse(CaptivePortalDataShimImpl.isSupported());
diff --git a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java index ddc1aba..a963537 100644 --- a/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java +++ b/tests/unit/src/com/android/server/connectivity/NetworkMonitorTest.java
@@ -115,7 +115,6 @@ import android.net.InetAddresses; import android.net.LinkProperties; import android.net.Network; -import android.net.NetworkAgentConfig; import android.net.NetworkCapabilities; import android.net.NetworkTestResultParcelable; import android.net.Uri; @@ -3074,7 +3073,7 @@ @NonNull final LinkProperties prop, @NonNull final NetworkCapabilities caps) throws Exception { final NetworkMonitorParameters params = new NetworkMonitorParameters(); - params.networkAgentConfig = (NetworkAgentConfig) config.getConfig(); + config.writeToNetworkMonitorParams(params); params.linkProperties = prop; params.networkCapabilities = caps; return params;