From fcc56fc1588a9f5f884cd8b3eaa63bcea610f8b5 Mon Sep 17 00:00:00 2001 From: James Mattis Date: Thu, 17 Feb 2022 13:08:20 -0800 Subject: Using a builder for eth requests Updating ethernet classes to use a builder when creating an EthernetNetworkUpdateRequest and also changing to use IpConfiguration instead of StaticIpConfiguration for the UpdateConfiguration API. Bug: 220017952 Bug: 210487893 Bug: 210485380 Test: atest EthernetServiceTests Change-Id: I2647115bf867dfaa3f3dadf00e3c875aa7e8d88f --- .../android/server/ethernet/EthernetServiceImpl.java | 2 +- java/com/android/server/ethernet/EthernetTracker.java | 18 +++++++----------- .../server/ethernet/EthernetServiceImplTest.java | 9 +++++---- .../android/server/ethernet/EthernetTrackerTest.java | 11 +++++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/java/com/android/server/ethernet/EthernetServiceImpl.java b/java/com/android/server/ethernet/EthernetServiceImpl.java index c1c6d3a..fed500f 100644 --- a/java/com/android/server/ethernet/EthernetServiceImpl.java +++ b/java/com/android/server/ethernet/EthernetServiceImpl.java @@ -239,7 +239,7 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { // TODO: validate that iface is listed in overlay config_ethernet_interfaces mTracker.updateConfiguration( - iface, request.getIpConfig(), request.getNetworkCapabilities(), listener); + iface, request.getIpConfiguration(), request.getNetworkCapabilities(), listener); } @Override diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java index 2571fe6..794b5d1 100644 --- a/java/com/android/server/ethernet/EthernetTracker.java +++ b/java/com/android/server/ethernet/EthernetTracker.java @@ -229,18 +229,18 @@ public class EthernetTracker { @VisibleForTesting(visibility = PACKAGE) protected void updateConfiguration(@NonNull final String iface, - @NonNull final StaticIpConfiguration staticIpConfig, + @NonNull final IpConfiguration ipConfig, @NonNull final NetworkCapabilities capabilities, @Nullable final IEthernetNetworkManagementListener listener) { if (DBG) { Log.i(TAG, "updateConfiguration, iface: " + iface + ", capabilities: " + capabilities - + ", staticIpConfig: " + staticIpConfig); + + ", ipConfig: " + ipConfig); } - final IpConfiguration ipConfig = createIpConfiguration(staticIpConfig); - writeIpConfiguration(iface, ipConfig); + final IpConfiguration localIpConfig = new IpConfiguration(ipConfig); + writeIpConfiguration(iface, localIpConfig); mNetworkCapabilities.put(iface, capabilities); mHandler.post(() -> { - mFactory.updateInterface(iface, ipConfig, capabilities, listener); + mFactory.updateInterface(iface, localIpConfig, capabilities, listener); broadcastInterfaceStateChange(iface); }); } @@ -715,13 +715,9 @@ public class EthernetTracker { return createIpConfiguration(staticIpConfigBuilder.build()); } - static IpConfiguration createIpConfiguration( + private static IpConfiguration createIpConfiguration( @NonNull final StaticIpConfiguration staticIpConfig) { - final IpConfiguration ret = new IpConfiguration(); - ret.setIpAssignment(IpAssignment.STATIC); - ret.setProxySettings(ProxySettings.NONE); - ret.setStaticIpConfiguration(staticIpConfig); - return ret; + return new IpConfiguration.Builder().setStaticIpConfiguration(staticIpConfig).build(); } private IpConfiguration getOrCreateIpConfiguration(String iface) { diff --git a/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java index 0ac28c4..2829753 100644 --- a/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java +++ b/tests/java/com/android/server/ethernet/EthernetServiceImplTest.java @@ -32,7 +32,6 @@ import android.net.IEthernetNetworkManagementListener; import android.net.EthernetNetworkUpdateRequest; import android.net.IpConfiguration; import android.net.NetworkCapabilities; -import android.net.StaticIpConfiguration; import android.os.Handler; import androidx.test.filters.SmallTest; @@ -49,8 +48,10 @@ import org.mockito.MockitoAnnotations; public class EthernetServiceImplTest { private static final String TEST_IFACE = "test123"; private static final EthernetNetworkUpdateRequest UPDATE_REQUEST = - new EthernetNetworkUpdateRequest( - new StaticIpConfiguration(), new NetworkCapabilities.Builder().build()); + new EthernetNetworkUpdateRequest.Builder() + .setIpConfiguration(new IpConfiguration()) + .setNetworkCapabilities(new NetworkCapabilities.Builder().build()) + .build(); private static final IEthernetNetworkManagementListener NULL_LISTENER = null; private EthernetServiceImpl mEthernetServiceImpl; @Mock private Context mContext; @@ -214,7 +215,7 @@ public class EthernetServiceImplTest { mEthernetServiceImpl.updateConfiguration(TEST_IFACE, UPDATE_REQUEST, NULL_LISTENER); verify(mEthernetTracker).updateConfiguration( eq(TEST_IFACE), - eq(UPDATE_REQUEST.getIpConfig()), + eq(UPDATE_REQUEST.getIpConfiguration()), eq(UPDATE_REQUEST.getNetworkCapabilities()), eq(NULL_LISTENER)); } diff --git a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java index 14f34d0..e1a1a8e 100644 --- a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java +++ b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java @@ -324,15 +324,18 @@ public class EthernetTrackerTest { @Test public void testUpdateConfiguration() { final NetworkCapabilities capabilities = new NetworkCapabilities.Builder().build(); - final StaticIpConfiguration staticIpConfig = new StaticIpConfiguration(); + final LinkAddress linkAddr = new LinkAddress("192.0.2.2/25"); + final StaticIpConfiguration staticIpConfig = + new StaticIpConfiguration.Builder().setIpAddress(linkAddr).build(); + final IpConfiguration ipConfig = + new IpConfiguration.Builder().setStaticIpConfiguration(staticIpConfig).build(); final IEthernetNetworkManagementListener listener = null; - tracker.updateConfiguration(TEST_IFACE, staticIpConfig, capabilities, listener); + tracker.updateConfiguration(TEST_IFACE, ipConfig, capabilities, listener); waitForIdle(); verify(mFactory).updateInterface( - eq(TEST_IFACE), eq(EthernetTracker.createIpConfiguration(staticIpConfig)), - eq(capabilities), eq(listener)); + eq(TEST_IFACE), eq(ipConfig), eq(capabilities), eq(listener)); } @Test -- cgit v1.2.3