Use "*" to indicate default capabilities in config

Instead of using an empty string, make the use of default capabilities
explicit by requiring "*" to be specified.

This behavior is more consistent and allows OEMs to explicitly configure
an interface without any capabilities (apart from those which are
hard-coded). (Technically, they could do so by specifying one of the
hardcoded capabilities in the config).

Test: TH
Change-Id: I1d25e5c4b302b0dbde5e1bb91fc1ed5a7b08be9d
diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java
index e41f1d6..7a192ce 100644
--- a/service-t/src/com/android/server/ethernet/EthernetTracker.java
+++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java
@@ -985,11 +985,12 @@
             builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED);
             builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
 
-            if (TextUtils.isEmpty(capabilitiesString)) {
-                if (!isAtLeastB) {
-                    return builder.build();
-                }
-                // On Android B+, a null or empty string defaults to the same set of default
+            if (capabilitiesString == null) {
+                return builder.build();
+            }
+
+            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);
             }
diff --git a/service/ServiceConnectivityResources/res/values/config.xml b/service/ServiceConnectivityResources/res/values/config.xml
index 1b0f29d..514563b 100644
--- a/service/ServiceConnectivityResources/res/values/config.xml
+++ b/service/ServiceConnectivityResources/res/values/config.xml
@@ -193,6 +193,8 @@
                    The NOT_ROAMING, NOT_CONGESTED and NOT_SUSPENDED capabilities are always
                    added automatically because this configuration provides no way to update
                    them dynamically.
+                   On Android B+, a "*" string configures the same default capabilities as is
+                   used for interfaces without any explicit configuration.
                [IP config] Optional. If empty or not specified - DHCP will be used, otherwise
                    use the following format to specify static IP configuration:
                        ip=<ip-address/mask> gateway=<ip-address> dns=<comma-sep-ip-addresses>
diff --git a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
index dc469a1..c1291b0 100644
--- a/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
+++ b/tests/unit/java/com/android/server/ethernet/EthernetTrackerTest.java
@@ -192,13 +192,20 @@
                 .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED)
                 .build();
 
+        // Empty capabilities always default to the baseNc above.
         EthernetConfigParser parser = new EthernetConfigParser("eth0;", false /*isAtLeastB*/);
         assertThat(parser.mCaps).isEqualTo(baseNc);
+        parser = new EthernetConfigParser("eth0;", true /*isAtLeastB*/);
+        assertThat(parser.mCaps).isEqualTo(baseNc);
 
-        // On Android B+, empty capabilities default to using DEFAULT_CAPABILITIES.
-        parser = new EthernetConfigParser("eth0;;;;;;;", true /*isAtLeastB*/);
+        // On Android B+, "*" defaults to using DEFAULT_CAPABILITIES.
+        parser = new EthernetConfigParser("eth0;*;;;;;;", true /*isAtLeastB*/);
         assertThat(parser.mCaps).isEqualTo(EthernetTracker.DEFAULT_CAPABILITIES);
 
+        // But not so before B.
+        parser = new EthernetConfigParser("eth0;*", false /*isAtLeastB*/);
+        assertThat(parser.mCaps).isEqualTo(baseNc);
+
         parser = new EthernetConfigParser("eth0;12,13,14,15;", false /*isAtLeastB*/);
         assertThat(parser.mCaps.getCapabilities()).asList().containsAtLeast(12, 13, 14, 15);