Merge "Create a TetherInterfaceStateMachine when told the interface name."
am: 51ee00785c

Change-Id: If79a096375e6b9665d5ba4aa0bcd9dbec6a8adab
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java
index 0f9d881..3327bec 100644
--- a/services/core/java/com/android/server/connectivity/Tethering.java
+++ b/services/core/java/com/android/server/connectivity/Tethering.java
@@ -877,6 +877,7 @@
         }
 
         if (!TextUtils.isEmpty(ifname)) {
+            maybeTrackNewInterfaceLocked(ifname, ConnectivityManager.TETHERING_WIFI);
             changeInterfaceState(ifname, ipServingMode);
         } else {
             tetherMatchingInterfaces(ipServingMode, ConnectivityManager.TETHERING_WIFI);
@@ -1800,7 +1801,10 @@
             mLog.log(iface + " is not a tetherable iface, ignoring");
             return;
         }
+        maybeTrackNewInterfaceLocked(iface, interfaceType);
+    }
 
+    private void maybeTrackNewInterfaceLocked(final String iface, int interfaceType) {
         // If we have already started a TISM for this interface, skip.
         if (mTetherStates.containsKey(iface)) {
             mLog.log("active iface (" + iface + ") reported as added, ignoring");
diff --git a/tests/net/java/com/android/server/connectivity/TetheringTest.java b/tests/net/java/com/android/server/connectivity/TetheringTest.java
index be0924a..5b4e901 100644
--- a/tests/net/java/com/android/server/connectivity/TetheringTest.java
+++ b/tests/net/java/com/android/server/connectivity/TetheringTest.java
@@ -264,13 +264,16 @@
         mIntents.remove(bcast);
     }
 
-    public void workingLocalOnlyHotspot(boolean enrichedApBroadcast) throws Exception {
+    public void workingLocalOnlyHotspot(
+            boolean withInterfaceStateChanged, boolean enrichedApBroadcast) throws Exception {
         when(mConnectivityManager.isTetheringSupported()).thenReturn(true);
 
         // Emulate externally-visible WifiManager effects, causing the
         // per-interface state machine to start up, and telling us that
         // hotspot mode is to be started.
-        mTethering.interfaceStatusChanged(mTestIfname, true);
+        if (withInterfaceStateChanged) {
+            mTethering.interfaceStatusChanged(mTestIfname, true);
+        }
         if (enrichedApBroadcast) {
             sendWifiApStateChanged(WIFI_AP_STATE_ENABLED, mTestIfname, IFACE_IP_MODE_LOCAL_ONLY);
         } else {
@@ -320,12 +323,17 @@
 
     @Test
     public void workingLocalOnlyHotspotLegacyApBroadcast() throws Exception {
-        workingLocalOnlyHotspot(false);
+        workingLocalOnlyHotspot(true, false);
     }
 
     @Test
     public void workingLocalOnlyHotspotEnrichedApBroadcast() throws Exception {
-        workingLocalOnlyHotspot(true);
+        workingLocalOnlyHotspot(true, true);
+    }
+
+    @Test
+    public void workingLocalOnlyHotspotEnrichedApBroadcastWithoutInterfaceUp() throws Exception {
+        workingLocalOnlyHotspot(false, true);
     }
 
     public void workingWifiTethering(boolean enrichedApBroadcast) throws Exception {