diff options
author | Patrick Rohr <prohr@google.com> | 2022-03-17 07:43:02 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-03-17 07:43:02 +0000 |
commit | f1117377ba11cc36ad93263c289b77855b1beb9d (patch) | |
tree | ef9eae2ed00f36f2d4641fd5cf2e26494dd5d7fc | |
parent | 7ba8f9b8a62a00939f0bc7582e5fed2ebad6bad1 (diff) | |
parent | 8900f662e5d454aa36127931ffb84d96a77d4ed1 (diff) | |
download | ethernet-f1117377ba11cc36ad93263c289b77855b1beb9d.tar.gz |
Add support for Nullable IpConfiguration am: 7e81787e0b am: 8900f662e5
Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/net/ethernet/+/2024300
Change-Id: If9f0241c2d725ea2ecaf405cfe81e02f1a0e4e46
4 files changed, 52 insertions, 7 deletions
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java index ce0d77c..ef3abba 100644 --- a/java/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java @@ -233,7 +233,8 @@ public class EthernetNetworkFactory extends NetworkFactory { * Update a network's configuration and restart it if necessary. * * @param ifaceName the interface name of the network to be updated. - * @param ipConfig the desired {@link IpConfiguration} for the given network. + * @param ipConfig the desired {@link IpConfiguration} for the given network or null. If + * {@code null} is passed, the existing IpConfiguration is not updated. * @param capabilities the desired {@link NetworkCapabilities} for the given network. If * {@code null} is passed, then the network's current * {@link NetworkCapabilities} will be used in support of existing APIs as @@ -243,7 +244,7 @@ public class EthernetNetworkFactory extends NetworkFactory { */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) protected void updateInterface(@NonNull final String ifaceName, - @NonNull final IpConfiguration ipConfig, + @Nullable final IpConfiguration ipConfig, @Nullable final NetworkCapabilities capabilities, @Nullable final IEthernetNetworkManagementListener listener) { if (!hasInterface(ifaceName)) { @@ -499,7 +500,7 @@ public class EthernetNetworkFactory extends NetworkFactory { mLegacyType = getLegacyType(mCapabilities); } - void updateInterface(@NonNull final IpConfiguration ipConfig, + void updateInterface(@Nullable final IpConfiguration ipConfig, @Nullable final NetworkCapabilities capabilities, @Nullable final IEthernetNetworkManagementListener listener) { if (DBG) { @@ -510,7 +511,9 @@ public class EthernetNetworkFactory extends NetworkFactory { ); } - mIpConfig = ipConfig; + if (null != ipConfig){ + mIpConfig = ipConfig; + } if (null != capabilities) { setCapabilities(capabilities); } diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java index 1b696a4..074c81b 100644 --- a/java/com/android/server/ethernet/EthernetTracker.java +++ b/java/com/android/server/ethernet/EthernetTracker.java @@ -289,15 +289,20 @@ public class EthernetTracker { @VisibleForTesting(visibility = PACKAGE) protected void updateConfiguration(@NonNull final String iface, - @NonNull final IpConfiguration ipConfig, + @Nullable final IpConfiguration ipConfig, @Nullable final NetworkCapabilities capabilities, @Nullable final IEthernetNetworkManagementListener listener) { if (DBG) { Log.i(TAG, "updateConfiguration, iface: " + iface + ", capabilities: " + capabilities + ", ipConfig: " + ipConfig); } - final IpConfiguration localIpConfig = new IpConfiguration(ipConfig); - writeIpConfiguration(iface, localIpConfig); + + final IpConfiguration localIpConfig = ipConfig == null + ? null : new IpConfiguration(ipConfig); + if (ipConfig != null) { + writeIpConfiguration(iface, localIpConfig); + } + if (null != capabilities) { mNetworkCapabilities.put(iface, capabilities); } diff --git a/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java index 501324a..726833f 100644 --- a/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java +++ b/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java @@ -776,4 +776,28 @@ public class EthernetNetworkFactoryTest { verifyNoStopOrStart(); assertFailedListener(listener, "can't be updated as it is not available"); } + + @Test + public void testUpdateInterfaceWithNullIpConfiguration() throws Exception { + initEthernetNetworkFactory(); + createAndVerifyProvisionedInterface(TEST_IFACE); + + final IpConfiguration initialIpConfig = createStaticIpConfig(); + mNetFactory.updateInterface(TEST_IFACE, initialIpConfig, null /*capabilities*/, + null /*listener*/); + triggerOnProvisioningSuccess(); + verifyRestart(initialIpConfig); + + // TODO: have verifyXyz functions clear invocations. + clearInvocations(mDeps); + clearInvocations(mIpClient); + clearInvocations(mNetworkAgent); + + + // verify that sending a null ipConfig does not update the current ipConfig. + mNetFactory.updateInterface(TEST_IFACE, null /*ipConfig*/, null /*capabilities*/, + null /*listener*/); + triggerOnProvisioningSuccess(); + verifyRestart(initialIpConfig); + } } diff --git a/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java index 175a97d..2131f7f 100644 --- a/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java +++ b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java @@ -60,6 +60,10 @@ public class EthernetServiceImplTest { new EthernetNetworkUpdateRequest.Builder() .setIpConfiguration(new IpConfiguration()) .build(); + private static final EthernetNetworkUpdateRequest UPDATE_REQUEST_WITHOUT_IP_CONFIG = + new EthernetNetworkUpdateRequest.Builder() + .setNetworkCapabilities(new NetworkCapabilities.Builder().build()) + .build(); private static final IEthernetNetworkManagementListener NULL_LISTENER = null; private EthernetServiceImpl mEthernetServiceImpl; @Mock private Context mContext; @@ -276,6 +280,15 @@ public class EthernetServiceImplTest { } @Test + public void testUpdateConfigurationAcceptsRequestWithNullIpConfiguration() { + mEthernetServiceImpl.updateConfiguration(TEST_IFACE, UPDATE_REQUEST_WITHOUT_IP_CONFIG, + NULL_LISTENER); + verify(mEthernetTracker).updateConfiguration(eq(TEST_IFACE), + eq(UPDATE_REQUEST_WITHOUT_IP_CONFIG.getIpConfiguration()), + eq(UPDATE_REQUEST_WITHOUT_IP_CONFIG.getNetworkCapabilities()), isNull()); + } + + @Test public void testUpdateConfigurationRejectsInvalidTestRequest() { enableTestInterface(); assertThrows(IllegalArgumentException.class, () -> { |