From a9a3b4ce04cac0db58837007fea3a788c1c54dcb Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Tue, 28 Dec 2021 09:16:09 +0000 Subject: [PATCH] Split out the ethernet API surface and use framework-connectivity-t Ethernet framework and service source code is going to be moved to Connectivity mainline module, this CL contains below corresponding changes to adapt the migration in f/b side: 1. Split out ethernet module-lib APIs to Connectivity module. Add the ethernet resource filegroup to tiramisu-updatable-sources filegroup as well, build them together. Also update the module-lib and system api txt to reflect the APIs change. Remove the hidden APIs which are moved to Connectivity module. This removal fixes the api inconsistent issue with Tethering/apex/hidden/. 2. Remove EthernetService from SystemServer which will be registered from ConnectivityServiceInitializer. 3. Replace the BackgroundThread class(imported from f/b/core/java) with the one in the modules-utils-backgroundthread lib, which is visible to Connectivity module. Bug: 210586283 Test: m Test: atest FrameworksNetTests EthernetServiceTests Change-Id: I1956848d3248cc56e9841d221e5e4c160bed65a4 --- framework-t/Sources.bp | 6 +++--- ...nectivityFrameworkInitializerTiramisu.java | 14 ++++++++++++-- .../src/android/net/EthernetManager.java | 2 +- service-t/Sources.bp | 8 ++++---- .../android/server/net/IpConfigStoreTest.java | 19 +++++++++---------- 5 files changed, 29 insertions(+), 20 deletions(-) rename {services/tests/servicestests/src => tests/unit/java}/com/android/server/net/IpConfigStoreTest.java (92%) diff --git a/framework-t/Sources.bp b/framework-t/Sources.bp index 66527802a0..217a1f67c3 100644 --- a/framework-t/Sources.bp +++ b/framework-t/Sources.bp @@ -154,17 +154,17 @@ filegroup { ], } +// TODO: remove this empty filegroup. filegroup { name: "framework-connectivity-tiramisu-sources", - srcs: [ - ":framework-connectivity-ethernet-sources", - ], + srcs: [], visibility: ["//frameworks/base"], } filegroup { name: "framework-connectivity-tiramisu-updatable-sources", srcs: [ + ":framework-connectivity-ethernet-sources", ":framework-connectivity-ipsec-sources", ":framework-connectivity-netstats-sources", ":framework-connectivity-nsd-sources", diff --git a/framework-t/src/android/net/ConnectivityFrameworkInitializerTiramisu.java b/framework-t/src/android/net/ConnectivityFrameworkInitializerTiramisu.java index 9bffbfb27a..61b34d0bcf 100644 --- a/framework-t/src/android/net/ConnectivityFrameworkInitializerTiramisu.java +++ b/framework-t/src/android/net/ConnectivityFrameworkInitializerTiramisu.java @@ -34,8 +34,9 @@ public final class ConnectivityFrameworkInitializerTiramisu { private ConnectivityFrameworkInitializerTiramisu() {} /** - * Called by {@link SystemServiceRegistry}'s static initializer and registers nsd services to - * {@link Context}, so that {@link Context#getSystemService} can return them. + * Called by {@link SystemServiceRegistry}'s static initializer and registers NetworkStats, nsd, + * ipsec and ethernet services to {@link Context}, so that {@link Context#getSystemService} can + * return them. * * @throws IllegalStateException if this is called anywhere besides * {@link SystemServiceRegistry}. @@ -68,5 +69,14 @@ public final class ConnectivityFrameworkInitializerTiramisu { return new NetworkStatsManager(context, service); } ); + + SystemServiceRegistry.registerContextAwareService( + Context.ETHERNET_SERVICE, + EthernetManager.class, + (context, serviceBinder) -> { + IEthernetManager service = IEthernetManager.Stub.asInterface(serviceBinder); + return new EthernetManager(context, service); + } + ); } } diff --git a/framework-t/src/android/net/EthernetManager.java b/framework-t/src/android/net/EthernetManager.java index eba51c1148..793f28d5aa 100644 --- a/framework-t/src/android/net/EthernetManager.java +++ b/framework-t/src/android/net/EthernetManager.java @@ -33,7 +33,7 @@ import android.os.Build; import android.os.RemoteException; import com.android.internal.annotations.GuardedBy; -import com.android.internal.os.BackgroundThread; +import com.android.modules.utils.BackgroundThread; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/service-t/Sources.bp b/service-t/Sources.bp index 5100e7c5b9..4b799c599b 100644 --- a/service-t/Sources.bp +++ b/service-t/Sources.bp @@ -102,17 +102,16 @@ filegroup { ], path: "src", visibility: [ - "//frameworks/opt/net/ethernet", + "//frameworks/opt/net/ethernet/tests", ], } // Connectivity-T common libraries. +// TODO: remove this empty filegroup. filegroup { name: "services.connectivity-tiramisu-sources", - srcs: [ - ":services.connectivity-ethernet-sources", - ], + srcs: [], path: "src", visibility: ["//frameworks/base/services/core"], } @@ -120,6 +119,7 @@ filegroup { filegroup { name: "services.connectivity-tiramisu-updatable-sources", srcs: [ + ":services.connectivity-ethernet-sources", ":services.connectivity-ipsec-sources", ":services.connectivity-netstats-sources", ":services.connectivity-nsd-sources", diff --git a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java b/tests/unit/java/com/android/server/net/IpConfigStoreTest.java similarity index 92% rename from services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java rename to tests/unit/java/com/android/server/net/IpConfigStoreTest.java index 2f771260ac..ad0be5862c 100644 --- a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java +++ b/tests/unit/java/com/android/server/net/IpConfigStoreTest.java @@ -48,10 +48,16 @@ import java.util.Arrays; */ @RunWith(AndroidJUnit4.class) public class IpConfigStoreTest { + private static final int KEY_CONFIG = 17; + private static final String IFACE_1 = "eth0"; + private static final String IFACE_2 = "eth1"; + private static final String IP_ADDR_1 = "192.168.1.10/24"; + private static final String IP_ADDR_2 = "192.168.1.20/24"; + private static final String DNS_IP_ADDR_1 = "1.2.3.4"; + private static final String DNS_IP_ADDR_2 = "5.6.7.8"; @Test public void backwardCompatibility2to3() throws IOException { - final int KEY_CONFIG = 17; ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(byteStream); @@ -73,13 +79,6 @@ public class IpConfigStoreTest { @Test public void staticIpMultiNetworks() throws Exception { - final String IFACE_1 = "eth0"; - final String IFACE_2 = "eth1"; - final String IP_ADDR_1 = "192.168.1.10/24"; - final String IP_ADDR_2 = "192.168.1.20/24"; - final String DNS_IP_ADDR_1 = "1.2.3.4"; - final String DNS_IP_ADDR_2 = "5.6.7.8"; - final ArrayList dnsServers = new ArrayList<>(); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1)); dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2)); @@ -144,11 +143,11 @@ public class IpConfigStoreTest { /** Synchronously writes into given byte steam */ private static class MockedDelayedDiskWrite extends DelayedDiskWrite { - final ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + final ByteArrayOutputStream mByteStream = new ByteArrayOutputStream(); @Override public void write(String filePath, Writer w) { - DataOutputStream outputStream = new DataOutputStream(byteStream); + DataOutputStream outputStream = new DataOutputStream(mByteStream); try { w.onWriteCalled(outputStream);