summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2022-01-24 03:54:55 +0000
committerXiao Ma <xiaom@google.com>2022-03-10 20:23:46 +0900
commitbe24c99542454e671612bb109063826a95c9e200 (patch)
treed544e577f63311755cd29ab8f0dad30ffb053fe1
parent10937d6c2d9f8931940073911585fb2e4bd83950 (diff)
downloadethernet-be24c99542454e671612bb109063826a95c9e200.tar.gz
Build ethernet service into service-connectivity-tiramisu-pre-jarjar.
Along with ethernet service is going to be moved into Connectivity module, this CL contains the corresponding changes as below: 1. deprecate the etherent-service lib and create a new filegroup: When the ethernet mainline code migration completes, ethernet-service lib won't be kept any more, instead the ethernet service should be started from ConnectivityServiceInitializer. So deprecate the current ethernet-service lib and cleanup the usages on other places later. Create a new filegroup which includes all ethernet service code, that will be built into service-connectivity-tiramisu-pre-jarjar. 2. Move the implementation of starting ethernet service: ConnectivityServiceInitializer should take responsibility to start ethernet service and EthernetTracker on boot phase. Move this code to ConnectivityServiceInitializer and remove the current onStart and onBootPhase implemenation. 3. Move below ethernet service related config resources: - config_ethernet_tcp_buffers - config_ethernet_interfaces - config_ethernet_iface_regex Move the definition of these resource from frameworks/base/core to p/m/Connectivity/service/ServiceConnectivityResources, and import the ServiceConnectivityResources lib to adapt the ethernet update. 4. Update the EthernetServiceTests dependencies and refactor the code which uses ConnectivityResources instead of internal Resource to make the tests pass. Bug: 210586283 Test: m Test: atest FrameworksNetTests atest EthernetServiceTests Change-Id: I0bbecfb64f720213ee2b02417bc8357ccf4725b6
-rw-r--r--Android.bp18
-rw-r--r--java/com/android/server/ethernet/EthernetNetworkFactory.java29
-rw-r--r--java/com/android/server/ethernet/EthernetService.java38
-rw-r--r--java/com/android/server/ethernet/EthernetTracker.java64
-rw-r--r--tests/Android.bp13
-rw-r--r--tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java5
-rw-r--r--tests/java/com/android/server/ethernet/EthernetTrackerTest.java13
7 files changed, 123 insertions, 57 deletions
diff --git a/Android.bp b/Android.bp
index c3393bc..c429a6f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -19,18 +19,14 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
-java_library {
- name: "ethernet-service",
- installable: true,
-
- aidl: {
- local_include_dirs: ["java"],
- },
+filegroup {
+ name: "ethernet-service-updatable-sources",
srcs: [
"java/**/*.java",
- "java/**/I*.aidl",
- "java/**/*.logtags",
],
-
- libs: ["services"],
+ path: "java",
+ visibility: [
+ "//frameworks/opt/net/ethernet/tests",
+ "//packages/modules/Connectivity/service-t",
+ ],
}
diff --git a/java/com/android/server/ethernet/EthernetNetworkFactory.java b/java/com/android/server/ethernet/EthernetNetworkFactory.java
index 875fc10..ce0d77c 100644
--- a/java/com/android/server/ethernet/EthernetNetworkFactory.java
+++ b/java/com/android/server/ethernet/EthernetNetworkFactory.java
@@ -19,7 +19,9 @@ package com.android.server.ethernet;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
+import android.content.res.Resources;
import android.net.ConnectivityManager;
+import android.net.ConnectivityResources;
import android.net.EthernetManager;
import android.net.EthernetNetworkSpecifier;
import android.net.IEthernetNetworkManagementListener;
@@ -49,6 +51,7 @@ import android.util.AndroidRuntimeException;
import android.util.Log;
import android.util.SparseArray;
+import com.android.connectivity.resources.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
import com.android.net.module.util.InterfaceParams;
@@ -69,6 +72,8 @@ public class EthernetNetworkFactory extends NetworkFactory {
private final static int NETWORK_SCORE = 70;
private static final String NETWORK_TYPE = "Ethernet";
+ private static final String LEGACY_TCP_BUFFER_SIZES =
+ "524288,1048576,3145728,524288,1048576,2097152";
private final ConcurrentHashMap<String, NetworkInterfaceState> mTrackingInterfaces =
new ConcurrentHashMap<>();
@@ -94,6 +99,27 @@ public class EthernetNetworkFactory extends NetworkFactory {
public InterfaceParams getNetworkInterfaceByName(String name) {
return InterfaceParams.getByName(name);
}
+
+ // TODO: remove legacy resource fallback after migrating its overlays.
+ private String getPlatformTcpBufferSizes(Context context) {
+ final Resources r = context.getResources();
+ final int resId = r.getIdentifier("config_ethernet_tcp_buffers", "string",
+ context.getPackageName());
+ return r.getString(resId);
+ }
+
+ public String getTcpBufferSizesFromResource(Context context) {
+ final String tcpBufferSizes;
+ final String platformTcpBufferSizes = getPlatformTcpBufferSizes(context);
+ if (!LEGACY_TCP_BUFFER_SIZES.equals(platformTcpBufferSizes)) {
+ // Platform resource is not the historical default: use the overlay.
+ tcpBufferSizes = platformTcpBufferSizes;
+ } else {
+ final ConnectivityResources resources = new ConnectivityResources(context);
+ tcpBufferSizes = resources.get().getString(R.string.config_ethernet_tcp_buffers);
+ }
+ return tcpBufferSizes;
+ }
}
public static class ConfigurationException extends AndroidRuntimeException {
@@ -518,8 +544,7 @@ public class EthernetNetworkFactory extends NetworkFactory {
mIpClientCallback.awaitIpClientStart();
if (sTcpBufferSizes == null) {
- sTcpBufferSizes = mContext.getResources().getString(
- com.android.internal.R.string.config_ethernet_tcp_buffers);
+ sTcpBufferSizes = mDeps.getTcpBufferSizesFromResource(mContext);
}
provisionIpClient(mIpClient, mIpConfig, sTcpBufferSizes);
}
diff --git a/java/com/android/server/ethernet/EthernetService.java b/java/com/android/server/ethernet/EthernetService.java
index e6fee9e..d405fd5 100644
--- a/java/com/android/server/ethernet/EthernetService.java
+++ b/java/com/android/server/ethernet/EthernetService.java
@@ -21,45 +21,27 @@ import android.net.INetd;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
-import android.util.Log;
-import com.android.server.SystemService;
import java.util.Objects;
-public final class EthernetService extends SystemService {
-
+// TODO: consider renaming EthernetServiceImpl to EthernetService and deleting this file.
+public final class EthernetService {
private static final String TAG = "EthernetService";
private static final String THREAD_NAME = "EthernetServiceThread";
- private final EthernetServiceImpl mImpl;
-
- public EthernetService(Context context) {
- super(context);
- final HandlerThread handlerThread = new HandlerThread(THREAD_NAME);
- handlerThread.start();
- final Handler handler = handlerThread.getThreadHandler();
- final EthernetNetworkFactory factory = new EthernetNetworkFactory(handler, context);
- mImpl = new EthernetServiceImpl(
- context, handler,
- new EthernetTracker(context, handler, factory, getNetd(context)));
- }
- private INetd getNetd(Context context) {
+ private static INetd getNetd(Context context) {
final INetd netd =
INetd.Stub.asInterface((IBinder) context.getSystemService(Context.NETD_SERVICE));
Objects.requireNonNull(netd, "could not get netd instance");
return netd;
}
- @Override
- public void onStart() {
- Log.i(TAG, "Registering service " + Context.ETHERNET_SERVICE);
- publishBinderService(Context.ETHERNET_SERVICE, mImpl);
- }
-
- @Override
- public void onBootPhase(int phase) {
- if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
- mImpl.start();
- }
+ public static EthernetServiceImpl create(Context context) {
+ final HandlerThread handlerThread = new HandlerThread(THREAD_NAME);
+ handlerThread.start();
+ final Handler handler = new Handler(handlerThread.getLooper());
+ final EthernetNetworkFactory factory = new EthernetNetworkFactory(handler, context);
+ return new EthernetServiceImpl(context, handler,
+ new EthernetTracker(context, handler, factory, getNetd(context)));
}
}
diff --git a/java/com/android/server/ethernet/EthernetTracker.java b/java/com/android/server/ethernet/EthernetTracker.java
index ea241e1..1b696a4 100644
--- a/java/com/android/server/ethernet/EthernetTracker.java
+++ b/java/com/android/server/ethernet/EthernetTracker.java
@@ -23,6 +23,8 @@ import static com.android.internal.annotations.VisibleForTesting.Visibility.PACK
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
+import android.content.res.Resources;
+import android.net.ConnectivityResources;
import android.net.EthernetManager;
import android.net.IEthernetServiceListener;
import android.net.IEthernetNetworkManagementListener;
@@ -80,6 +82,7 @@ public class EthernetTracker {
private static final boolean DBG = EthernetNetworkFactory.DBG;
private static final String TEST_IFACE_REGEXP = TEST_TAP_PREFIX + "\\d+";
+ private static final String LEGACY_IFACE_REGEXP = "eth\\d";
/**
* Interface names we track. This is a product-dependent regular expression, plus,
@@ -102,6 +105,7 @@ public class EthernetTracker {
private final Handler mHandler;
private final EthernetNetworkFactory mFactory;
private final EthernetConfigStore mConfigStore;
+ private final Dependencies mDeps;
private final RemoteCallbackList<IEthernetServiceListener> mListeners =
new RemoteCallbackList<>();
@@ -123,19 +127,72 @@ public class EthernetTracker {
}
}
+ public static class Dependencies {
+ // TODO: remove legacy resource fallback after migrating its overlays.
+ private String getPlatformRegexResource(Context context) {
+ final Resources r = context.getResources();
+ final int resId =
+ r.getIdentifier("config_ethernet_iface_regex", "string", context.getPackageName());
+ return r.getString(resId);
+ }
+
+ // TODO: remove legacy resource fallback after migrating its overlays.
+ private String[] getPlatformInterfaceConfigs(Context context) {
+ final Resources r = context.getResources();
+ final int resId = r.getIdentifier("config_ethernet_interfaces", "array",
+ context.getPackageName());
+ return r.getStringArray(resId);
+ }
+
+ public String getInterfaceRegexFromResource(Context context) {
+ final String platformRegex = getPlatformRegexResource(context);
+ final String match;
+ if (!LEGACY_IFACE_REGEXP.equals(platformRegex)) {
+ // Platform resource is not the historical default: use the overlay
+ match = platformRegex;
+ } else {
+ final ConnectivityResources resources = new ConnectivityResources(context);
+ match = resources.get().getString(
+ com.android.connectivity.resources.R.string.config_ethernet_iface_regex);
+ }
+ return match;
+ }
+
+ public String[] getInterfaceConfigFromResource(Context context) {
+ final String[] platformInterfaceConfigs = getPlatformInterfaceConfigs(context);
+ final String[] interfaceConfigs;
+ if (platformInterfaceConfigs.length != 0) {
+ // Platform resource is not the historical default: use the overlay
+ interfaceConfigs = platformInterfaceConfigs;
+ } else {
+ final ConnectivityResources resources = new ConnectivityResources(context);
+ interfaceConfigs = resources.get().getStringArray(
+ com.android.connectivity.resources.R.array.config_ethernet_interfaces);
+ }
+ return interfaceConfigs;
+ }
+ }
+
EthernetTracker(@NonNull final Context context, @NonNull final Handler handler,
@NonNull final EthernetNetworkFactory factory, @NonNull final INetd netd) {
+ this(context, handler, factory, netd, new Dependencies());
+ }
+
+ @VisibleForTesting
+ EthernetTracker(@NonNull final Context context, @NonNull final Handler handler,
+ @NonNull final EthernetNetworkFactory factory, @NonNull final INetd netd,
+ @NonNull final Dependencies deps) {
mContext = context;
mHandler = handler;
mFactory = factory;
mNetd = netd;
+ mDeps = deps;
// Interface match regex.
updateIfaceMatchRegexp();
// Read default Ethernet interface configuration from resources
- final String[] interfaceConfigs = context.getResources().getStringArray(
- com.android.internal.R.array.config_ethernet_interfaces);
+ final String[] interfaceConfigs = mDeps.getInterfaceConfigFromResource(context);
for (String strConfig : interfaceConfigs) {
parseEthernetConfig(strConfig);
}
@@ -735,8 +792,7 @@ public class EthernetTracker {
}
private void updateIfaceMatchRegexp() {
- final String match = mContext.getResources().getString(
- com.android.internal.R.string.config_ethernet_iface_regex);
+ final String match = mDeps.getInterfaceRegexFromResource(mContext);
mIfaceMatch = mIncludeTestInterfaces
? "(" + match + "|" + TEST_IFACE_REGEXP + ")"
: match;
diff --git a/tests/Android.bp b/tests/Android.bp
index 28b13c5..6cfebdc 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -17,10 +17,17 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
+// TODO: merge the tests into service-connectivity tests after
+// ethernet service migration completes. So far just import the
+// ethernet service source to fix the dependencies.
android_test {
name: "EthernetServiceTests",
- srcs: ["java/**/*.java"],
+ srcs: [
+ ":ethernet-service-updatable-sources",
+ ":services.connectivity-ethernet-sources",
+ "java/**/*.java",
+ ],
certificate: "platform",
platform_apis: true,
@@ -29,11 +36,13 @@ android_test {
"android.test.runner",
"android.test.base",
"android.test.mock",
+ "framework-connectivity.impl",
+ "framework-connectivity-t.impl",
+ "ServiceConnectivityResources",
],
static_libs: [
"androidx.test.rules",
- "ethernet-service",
"frameworks-base-testutils",
"mockito-target-minus-junit4",
"net-tests-utils",
diff --git a/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java b/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
index 61425bf..501324a 100644
--- a/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
+++ b/tests/java/com/android/server/ethernet/EthernetNetworkFactoryTest.java
@@ -63,7 +63,7 @@ import android.util.Pair;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.internal.R;
+import com.android.connectivity.resources.R;
import com.android.net.module.util.InterfaceParams;
import com.android.testutils.DevSdkIgnoreRule;
@@ -174,8 +174,7 @@ public class EthernetNetworkFactoryTest {
}
private void setupContext() {
- when(mContext.getResources()).thenReturn(mResources);
- when(mResources.getString(R.string.config_ethernet_tcp_buffers)).thenReturn("");
+ when(mDeps.getTcpBufferSizesFromResource(eq(mContext))).thenReturn("");
}
@After
diff --git a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
index d86cc0f..ef70d94 100644
--- a/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
+++ b/tests/java/com/android/server/ethernet/EthernetTrackerTest.java
@@ -27,7 +27,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -48,7 +47,7 @@ import android.os.RemoteException;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
-import com.android.internal.R;
+import com.android.connectivity.resources.R;
import com.android.testutils.HandlerUtils;
import org.junit.After;
@@ -73,7 +72,7 @@ public class EthernetTrackerTest {
@Mock private Context mContext;
@Mock private EthernetNetworkFactory mFactory;
@Mock private INetd mNetd;
- @Mock Resources mResources;
+ @Mock private EthernetTracker.Dependencies mDeps;
@Before
public void setUp() throws RemoteException {
@@ -83,7 +82,8 @@ public class EthernetTrackerTest {
when(mNetd.interfaceGetList()).thenReturn(new String[0]);
mHandlerThread = new HandlerThread(THREAD_NAME);
mHandlerThread.start();
- tracker = new EthernetTracker(mContext, mHandlerThread.getThreadHandler(), mFactory, mNetd);
+ tracker = new EthernetTracker(mContext, mHandlerThread.getThreadHandler(), mFactory, mNetd,
+ mDeps);
}
@After
@@ -92,9 +92,8 @@ public class EthernetTrackerTest {
}
private void initMockResources() {
- doReturn("").when(mResources).getString(R.string.config_ethernet_iface_regex);
- doReturn(new String[0]).when(mResources).getStringArray(R.array.config_ethernet_interfaces);
- doReturn(mResources).when(mContext).getResources();
+ when(mDeps.getInterfaceRegexFromResource(eq(mContext))).thenReturn("");
+ when(mDeps.getInterfaceConfigFromResource(eq(mContext))).thenReturn(new String[0]);
}
private void waitForIdle() {