WifiManagerTest: allow for multiple modes

Now that WifiService can/will support dual simultaneous mode operation, make
sure the tests allow for it as well.

Bug: 31346104
Bug: 115567184
Test: atest android.net.wifi.cts
Change-Id: Id3aaacb3651568c18850a0fdf3832c0f52218cf2
Merged-In: Id3aaacb3651568c18850a0fdf3832c0f52218cf2
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
index b2d912e..44b49c0 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -825,10 +825,9 @@
 
         TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot();
 
-        // at this point, wifi should be off
-        assertFalse(mWifiManager.isWifiEnabled());
-
         stopLocalOnlyHotspot(callback, wifiEnabled);
+
+        // wifi should either stay on, or come back on
         assertEquals(wifiEnabled, mWifiManager.isWifiEnabled());
     }
 
@@ -840,23 +839,31 @@
      * tethering is started.
      * Note: Location mode must be enabled for this test.
      */
-    public void testSetWifiEnabledByAppDoesNotStopHotspot() {
-        // first check that softap mode is supported by the device
+
+    public void testSetWifiEnabledByAppDoesNotStopHotspot() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        // check that softap mode is supported by the device
         if (!mWifiManager.isPortableHotspotSupported()) {
             return;
         }
 
         boolean wifiEnabled = mWifiManager.isWifiEnabled();
 
+        if (wifiEnabled) {
+            // disable wifi so we have something to turn on (some devices may be able to run
+            // simultaneous modes)
+            setWifiEnabled(false);
+        }
+
         TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot();
-        // at this point, wifi should be off
-        assertFalse(mWifiManager.isWifiEnabled());
 
         // now we should fail to turn on wifi
         assertFalse(mWifiManager.setWifiEnabled(true));
 
         stopLocalOnlyHotspot(callback, wifiEnabled);
-        assertEquals(wifiEnabled, mWifiManager.isWifiEnabled());
     }
 
     /**
@@ -876,9 +883,6 @@
 
         TestLocalOnlyHotspotCallback callback = startLocalOnlyHotspot();
 
-        // at this point, wifi should be off
-        assertFalse(mWifiManager.isWifiEnabled());
-
         // now make a second request - this should fail.
         TestLocalOnlyHotspotCallback callback2 = new TestLocalOnlyHotspotCallback(mLOHSLock);
         try {
@@ -887,9 +891,12 @@
             Log.d(TAG, "Caught the IllegalStateException we expected: called startLOHS twice");
             caughtException = true;
         }
+        if (!caughtException) {
+            // second start did not fail, should clean up the hotspot.
+            stopLocalOnlyHotspot(callback2, wifiEnabled);
+        }
         assertTrue(caughtException);
 
         stopLocalOnlyHotspot(callback, wifiEnabled);
-        assertEquals(wifiEnabled, mWifiManager.isWifiEnabled());
     }
 }