Fix transport override

The EthernetConfigParser was adding the transportType on top of the
TRANSPORT_ETHERNET of DEFAULT_CAPABILITIES, causing multiple transport
types to be added.

This was causing an IllegalStateException when trying to set the
NetworkSpecifier within the EthernetNetworkFactory.

This only applies for when isAtLeastB && capabilitiesString.equals("*")
is true (as the parsed capability is equal to DEFAULT_CAPABILITIES).

Flag: TEST_ONLY
Bug: 405172885
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ethernet.EthernetTrackerTest
(cherry picked from https://android-review.googlesource.com/q/commit:65a26519c00bfb9b45bec30153cb2306577d2fc1)
Merged-In: I6678a52ddc87b8ad66c602c68335f3e2073d7231
Change-Id: I6678a52ddc87b8ad66c602c68335f3e2073d7231
diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java
index 7a192ce..c09a94d 100644
--- a/service-t/src/com/android/server/ethernet/EthernetTracker.java
+++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java
@@ -992,7 +992,11 @@
             if (isAtLeastB && capabilitiesString.equals("*")) {
                 // On Android B+, a "*" string defaults to the same set of default
                 // capabilities assigned to unconfigured interfaces.
-                return new NetworkCapabilities(DEFAULT_CAPABILITIES);
+                // Note that the transport type is populated later with the result of
+                // parseTransportType().
+                return new NetworkCapabilities.Builder(DEFAULT_CAPABILITIES)
+                        .removeTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
+                        .build();
             }
 
             for (String strNetworkCapability : capabilitiesString.split(",")) {
diff --git a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
index 1a313fe..97ca8ad 100644
--- a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
+++ b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
@@ -18,6 +18,7 @@
 
 import static android.net.TestNetworkManager.TEST_TAP_PREFIX;
 
+import static com.android.server.ethernet.EthernetTracker.DEFAULT_CAPABILITIES;
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.junit.Assert.assertEquals;
@@ -200,7 +201,7 @@
 
         // On Android B+, "*" defaults to using DEFAULT_CAPABILITIES.
         p = new EthernetConfigParser("eth0;*;;;;;;", true /*isAtLeastB*/);
-        assertThat(p.mCaps).isEqualTo(EthernetTracker.DEFAULT_CAPABILITIES);
+        assertThat(p.mCaps).isEqualTo(DEFAULT_CAPABILITIES);
 
         // But not so before B.
         p = new EthernetConfigParser("eth0;*", false /*isAtLeastB*/);
@@ -220,10 +221,24 @@
         // TRANSPORT_VPN (4) is not allowed.
         p = new EthernetConfigParser("eth0;;;4", false /*isAtLeastB*/);
         assertThat(p.mCaps.hasSingleTransport(NetworkCapabilities.TRANSPORT_ETHERNET)).isTrue();
+        p = new EthernetConfigParser("eth0;*;;4", true /*isAtLeastB*/);
+        assertThat(p.mCaps.hasSingleTransport(NetworkCapabilities.TRANSPORT_ETHERNET)).isTrue();
 
         // invalid capability and transport type
         p = new EthernetConfigParser("eth0;-1,a,1000,,;;-1", false /*isAtLeastB*/);
         assertThat(p.mCaps).isEqualTo(baseNc);
+
+        p = new EthernetConfigParser("eth0;*;;0", false /*isAtLeastB*/);
+        assertThat(p.mCaps.hasSingleTransport(NetworkCapabilities.TRANSPORT_CELLULAR)).isTrue();
+        p = new EthernetConfigParser("eth0;*;;0", true /*isAtLeastB*/);
+        assertThat(p.mCaps.hasSingleTransport(NetworkCapabilities.TRANSPORT_CELLULAR)).isTrue();
+
+        NetworkCapabilities nc = new NetworkCapabilities.Builder(DEFAULT_CAPABILITIES)
+                .removeTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
+                .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
+                .build();
+        p = new EthernetConfigParser("eth0;*;;0", true /*isAtLeastB*/);
+        assertThat(p.mCaps).isEqualTo(nc);
     }
 
     @Test