From 11eac8e12b30643881951b640da0db9cbe78d3c7 Mon Sep 17 00:00:00 2001 From: Patrick Rohr Date: Wed, 11 Oct 2023 17:32:32 -0700 Subject: [PATCH] Include both eth%d and usb%d ethernet interfaces on U+ Ethernet interface naming is not consistent on Linux. While some USB ethernet dongles show up as eth0, others might show up as usb0. This CL changes config_ethernet_iface_regex to "*" which stands for "use Android version specific default". The default will include both usb\d+ and eth%d named interfaces on Android U+. Android T will continue to only include eth%d interfaces (note that the "+" is a new addition which is highly unlikely to have any actual effect, but is more technically correct). Bug: 304335605 Test: TH Change-Id: I823be8ee390cb2b6dd41b537c72ed76f5aa9e0ea --- .../android/server/ethernet/EthernetTracker.java | 14 +++++++++++++- .../res/values/config.xml | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java index 48e86d8e7e..01b8de7e1c 100644 --- a/service-t/src/com/android/server/ethernet/EthernetTracker.java +++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java @@ -48,6 +48,7 @@ import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.IndentingPrintWriter; +import com.android.modules.utils.build.SdkLevel; import com.android.net.module.util.NetdUtils; import com.android.net.module.util.PermissionUtils; import com.android.net.module.util.SharedLog; @@ -237,7 +238,18 @@ public class EthernetTracker { mDeps = deps; // Interface match regex. - mIfaceMatch = mDeps.getInterfaceRegexFromResource(mContext); + String ifaceMatchRegex = mDeps.getInterfaceRegexFromResource(mContext); + // "*" is a magic string to indicate "pick the default". + if (ifaceMatchRegex.equals("*")) { + if (SdkLevel.isAtLeastU()) { + // On U+, include both usb%d and eth%d interfaces. + ifaceMatchRegex = "(usb|eth)\\d+"; + } else { + // On T, include only eth%d interfaces. + ifaceMatchRegex = "eth\\d+"; + } + } + mIfaceMatch = ifaceMatchRegex; // Read default Ethernet interface configuration from resources final String[] interfaceConfigs = mDeps.getInterfaceConfigFromResource(context); diff --git a/service/ServiceConnectivityResources/res/values/config.xml b/service/ServiceConnectivityResources/res/values/config.xml index f30abc6b0b..045d707f34 100644 --- a/service/ServiceConnectivityResources/res/values/config.xml +++ b/service/ServiceConnectivityResources/res/values/config.xml @@ -194,8 +194,11 @@ --> - - eth\\d + + *