am 928ec5e0: Merge "Modify connectivity manager test suite so that it can be run on Wi-Fi only device." into honeycomb

* commit '928ec5e021162fe371da8bdac7f5bb2c854b1aa1':
  Modify connectivity manager test suite so that it can be run on Wi-Fi only device.
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java
index 5b76e39..3f78ce0 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java
@@ -19,6 +19,7 @@
 import android.os.Bundle;
 import android.test.InstrumentationTestRunner;
 import android.test.InstrumentationTestSuite;
+
 import com.android.connectivitymanagertest.stress.WifiApStress;
 import com.android.connectivitymanagertest.stress.WifiStressTest;
 
@@ -44,8 +45,18 @@
     @Override
     public TestSuite getAllTests() {
         TestSuite suite = new InstrumentationTestSuite(this);
-        suite.addTestSuite(WifiApStress.class);
-        suite.addTestSuite(WifiStressTest.class);
+        if (!UtilHelper.isWifiOnly()) {
+            suite.addTestSuite(WifiApStress.class);
+            suite.addTestSuite(WifiStressTest.class);
+        } else {
+            // create a new test suite
+            suite.setName("WifiOnlyStressTests");
+            String[] methodNames = {"testWifiScanning"};
+            Class<WifiStressTest> testClass = WifiStressTest.class;
+            for (String method: methodNames) {
+                suite.addTest(TestSuite.createTest(testClass, method));
+            }
+        }
         return suite;
     }
 
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
index 3d4dc3d..20aae47 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestRunner.java
@@ -19,7 +19,7 @@
 import android.os.Bundle;
 import android.test.InstrumentationTestRunner;
 import android.test.InstrumentationTestSuite;
-import android.util.Log;
+
 import com.android.connectivitymanagertest.functional.ConnectivityManagerMobileTest;
 import com.android.connectivitymanagertest.functional.WifiConnectionTest;
 
@@ -35,10 +35,24 @@
  */
 
 public class ConnectivityManagerTestRunner extends InstrumentationTestRunner {
+    public String TEST_SSID = null;
+
     @Override
     public TestSuite getAllTests() {
         TestSuite suite = new InstrumentationTestSuite(this);
-        suite.addTestSuite(ConnectivityManagerMobileTest.class);
+        if (!UtilHelper.isWifiOnly()) {
+            suite.addTestSuite(ConnectivityManagerMobileTest.class);
+        } else {
+            // create a new test suite
+            suite.setName("ConnectivityManagerWifiOnlyFunctionalTests");
+            String[] methodNames = {"testConnectToWifi", "testConnectToWifWithKnownAP",
+                    "testDisconnectWifi", "testDataConnectionOverAMWithWifi",
+                    "testDataConnectionWithWifiToAMToWifi", "testWifiStateChange"};
+            Class<ConnectivityManagerMobileTest> testClass = ConnectivityManagerMobileTest.class;
+            for (String method: methodNames) {
+                suite.addTest(TestSuite.createTest(testClass, method));
+            }
+        }
         suite.addTestSuite(WifiConnectionTest.class);
         return suite;
     }
@@ -56,6 +70,4 @@
             TEST_SSID = testSSID;
         }
     }
-
-    public String TEST_SSID = null;
 }
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/UtilHelper.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/UtilHelper.java
new file mode 100644
index 0000000..1b966bf
--- /dev/null
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/UtilHelper.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.connectivitymanagertest;
+
+import android.os.SystemProperties;
+
+public class UtilHelper {
+    public static boolean isWifiOnly() {
+        return "wifi-only".equals(SystemProperties.get("ro.carrier"));
+    }
+
+
+}
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
index b87021a..d9b770a 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
@@ -17,6 +17,7 @@
 package com.android.connectivitymanagertest.functional;
 
 import com.android.connectivitymanagertest.ConnectivityManagerTestActivity;
+import com.android.connectivitymanagertest.UtilHelper;
 
 import android.content.Intent;
 import android.content.Context;
@@ -48,7 +49,7 @@
     private WakeLock wl;
 
     public ConnectivityManagerMobileTest() {
-        super(PKG_NAME, ConnectivityManagerTestActivity.class);
+        super(ConnectivityManagerTestActivity.class);
     }
 
     @Override
@@ -68,13 +69,15 @@
             Log.v(LOG_TAG, "airplane is not disabled, disable it.");
             cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
         }
-        if (!cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT)) {
-            // Note: When the test fails in setUp(), tearDown is not called. In that case,
-            // the activity is destroyed which blocks the next test at "getActivity()".
-            // tearDown() is called here to avoid that situation.
-            tearDown();
-            fail("Device is not connected to Mobile, setUp failed");
+        if (!UtilHelper.isWifiOnly()) {
+            if (!cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
+                    ConnectivityManagerTestActivity.LONG_TIMEOUT)) {
+                // Note: When the test fails in setUp(), tearDown is not called. In that case,
+                // the activity is destroyed which blocks the next test at "getActivity()".
+                // tearDown() is called here to avoid that situation.
+                tearDown();
+                fail("Device is not connected to Mobile, setUp failed");
+            }
         }
     }
 
@@ -128,8 +131,8 @@
         // As Wifi stays in DISCONNETED, Mobile statys in CONNECTED,
         // the connectivity manager will not broadcast any network connectivity event for Wifi
         NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE, networkInfo.getState(),
-                NetworkState.DO_NOTHING, State.CONNECTED);
+        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+                networkInfo.getState(), NetworkState.DO_NOTHING, State.CONNECTED);
         networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
                 NetworkState.DO_NOTHING, State.DISCONNECTED);
@@ -162,10 +165,13 @@
     @LargeTest
     public void testConnectToWifi() {
         assertNotNull("SSID is null", TEST_ACCESS_POINT);
-        //Prepare for connectivity verification
-        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE, networkInfo.getState(),
-                NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
+        NetworkInfo networkInfo;
+        if (!UtilHelper.isWifiOnly()) {
+            //Prepare for connectivity verification
+            networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+            cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+                    networkInfo.getState(), NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
+        }
         networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
                 NetworkState.TO_CONNECTION, State.CONNECTED);
@@ -179,8 +185,10 @@
         Log.v(LOG_TAG, "wifi state is enabled");
         assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
                 ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        }
 
         // validate states
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
@@ -189,11 +197,13 @@
                     cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
             assertTrue(false);
         }
-        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
-            Log.v(LOG_TAG, "Mobile state transition validation failed.");
-            Log.v(LOG_TAG, "reason: " +
-                    cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
-            assertTrue(false);
+        if (!UtilHelper.isWifiOnly()) {
+            if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+                Log.v(LOG_TAG, "Mobile state transition validation failed.");
+                Log.v(LOG_TAG, "reason: " +
+                        cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+                assertTrue(false);
+            }
         }
     }
 
@@ -225,16 +235,21 @@
         // Wait for the Wifi state to be DISABLED
         assertTrue(cmActivity.waitForWifiState(WifiManager.WIFI_STATE_DISABLED,
                 ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI,
+                State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        }
 
-        //Prepare for connectivity state verification
-        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
-                                              networkInfo.getState(), NetworkState.DO_NOTHING,
-                                              State.DISCONNECTED);
+        NetworkInfo networkInfo;
+        if (!UtilHelper.isWifiOnly()) {
+            //Prepare for connectivity state verification
+            networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+            cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+                                                  networkInfo.getState(), NetworkState.DO_NOTHING,
+                                                  State.DISCONNECTED);
+        }
         networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
                 NetworkState.TO_CONNECTION, State.CONNECTED);
@@ -246,8 +261,10 @@
         // Wait for Wifi to be connected and mobile to be disconnected
         assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
                 ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        }
 
         // validate wifi states
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
@@ -277,11 +294,14 @@
             Log.v(LOG_TAG, "exception: " + e.toString());
         }
 
-        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
-                                              networkInfo.getState(),
-                                              NetworkState.TO_CONNECTION,
-                                              State.CONNECTED);
+        NetworkInfo networkInfo;
+        if (!UtilHelper.isWifiOnly()) {
+            networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+            cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+                                                  networkInfo.getState(),
+                                                  NetworkState.TO_CONNECTION,
+                                                  State.CONNECTED);
+        }
         networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
                 NetworkState.TO_DISCONNECTION, State.DISCONNECTED);
@@ -291,8 +311,10 @@
 
         assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.DISCONNECTED,
                 ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.CONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.CONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        }
 
         // validate states
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
@@ -301,11 +323,13 @@
                     cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
             assertTrue(false);
         }
-        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
-            Log.v(LOG_TAG, "Mobile state transition validation failed.");
-            Log.v(LOG_TAG, "reason: " +
-                    cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
-            assertTrue(false);
+        if (!UtilHelper.isWifiOnly()) {
+            if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+                Log.v(LOG_TAG, "Mobile state transition validation failed.");
+                Log.v(LOG_TAG, "reason: " +
+                        cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+                assertTrue(false);
+            }
         }
     }
 
@@ -377,14 +401,16 @@
         // Eanble airplane mode
         cmActivity.setAirplaneMode(getInstrumentation().getContext(), true);
 
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED,
-                ConnectivityManagerTestActivity.LONG_TIMEOUT));
-
-        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
-                                              networkInfo.getState(),
-                                              NetworkState.DO_NOTHING,
-                                              State.DISCONNECTED);
+        NetworkInfo networkInfo;
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+            networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+            cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
+                                                  networkInfo.getState(),
+                                                  NetworkState.DO_NOTHING,
+                                                  State.DISCONNECTED);
+        }
         networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI, networkInfo.getState(),
                                               NetworkState.TO_CONNECTION, State.CONNECTED);
@@ -402,11 +428,13 @@
                     cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
             assertTrue("State validation failed", false);
         }
-        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
-            Log.v(LOG_TAG, "state validation for Mobile failed");
-            Log.v(LOG_TAG, "reason: " +
-                    cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
-            assertTrue("state validation failed", false);
+        if (!UtilHelper.isWifiOnly()) {
+            if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
+                Log.v(LOG_TAG, "state validation for Mobile failed");
+                Log.v(LOG_TAG, "reason: " +
+                        cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
+                assertTrue("state validation failed", false);
+            }
         }
         cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
     }
@@ -452,8 +480,10 @@
 
         assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
                             ConnectivityManagerTestActivity.LONG_TIMEOUT));
-        assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED,
-                            ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        if (!UtilHelper.isWifiOnly()) {
+            assertTrue(cmActivity.waitForNetworkState(ConnectivityManager.TYPE_MOBILE,
+                    State.DISCONNECTED, ConnectivityManagerTestActivity.LONG_TIMEOUT));
+        }
 
         // validate the state transition
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {