Merge "Test that rs_script_call_t works properly." into jb-mr1-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 6fcb9ca..e588d05 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -70,7 +70,7 @@
         </activity>
 
         <activity android:name=".ReportViewerActivity"
-                android:configChanges="keyboardHidden|orientation"
+                android:configChanges="keyboardHidden|orientation|screenSize"
                 android:label="@string/report_viewer" />
 
         <provider android:name=".TestResultsProvider" 
@@ -78,7 +78,7 @@
 
         <activity android:name=".admin.PolicySerializationTestActivity"
                 android:label="@string/da_policy_serialization_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -88,7 +88,7 @@
 
         <activity android:name=".admin.ScreenLockTestActivity"
                 android:label="@string/da_screen_lock_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -114,7 +114,7 @@
 
         <activity android:name=".bluetooth.BluetoothTestActivity"
                 android:label="@string/bluetooth_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -125,7 +125,7 @@
 
         <activity android:name=".bluetooth.BluetoothToggleActivity"
                 android:label="@string/bt_toggle_bluetooth"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -136,7 +136,7 @@
 
         <activity android:name=".bluetooth.SecureServerActivity"
                 android:label="@string/bt_secure_server"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -147,7 +147,7 @@
 
         <activity android:name=".bluetooth.InsecureServerActivity"
                 android:label="@string/bt_insecure_server"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -158,7 +158,7 @@
 
         <activity android:name=".bluetooth.SecureClientActivity"
                 android:label="@string/bt_secure_client"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -169,7 +169,7 @@
 
         <activity android:name=".bluetooth.InsecureClientActivity"
                 android:label="@string/bt_insecure_client"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -180,7 +180,7 @@
 
         <activity android:name=".bluetooth.ConnectionAccessServerActivity"
                 android:label="@string/bt_connection_access_server"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
             </intent-filter>
@@ -190,7 +190,7 @@
 
         <activity android:name=".bluetooth.ConnectionAccessClientActivity"
                 android:label="@string/bt_connection_access_client"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
             </intent-filter>
@@ -200,11 +200,11 @@
 
         <activity android:name=".bluetooth.DevicePickerActivity"
                 android:label="@string/bt_device_picker"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".suid.SuidFilesActivity"
                 android:label="@string/suid_files"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -214,7 +214,7 @@
 
         <activity android:name=".streamquality.StreamingVideoActivity"
                 android:label="@string/streaming_video"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -224,7 +224,7 @@
 
         <activity android:name=".streamquality.PlayVideoActivity"
                 android:label="@string/streaming_video"
-                android:configChanges="keyboardHidden|orientation"
+                android:configChanges="keyboardHidden|orientation|screenSize"
                 android:screenOrientation="nosensor" />
 
         <activity android:name=".features.FeatureSummaryActivity" android:label="@string/feature_summary">
@@ -237,7 +237,7 @@
 
         <activity android:name=".location.GpsTestActivity"
                 android:label="@string/location_gps_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -248,7 +248,7 @@
 
         <activity android:name=".nfc.NfcTestActivity"
                 android:label="@string/nfc_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -259,15 +259,15 @@
 
         <activity android:name=".nfc.NdefPushSenderActivity"
                 android:label="@string/nfc_ndef_push_sender"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".nfc.NdefPushReceiverActivity"
                 android:label="@string/nfc_ndef_push_receiver"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".nfc.TagVerifierActivity"
                 android:label="@string/nfc_tag_verifier"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".sensors.AccelerometerTestActivity" android:label="@string/snsr_accel_test"
                 android:screenOrientation="nosensor">
@@ -332,7 +332,7 @@
 
         <activity android:name=".usb.UsbAccessoryTestActivity"
                 android:label="@string/usb_accessory_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -343,7 +343,7 @@
 
         <activity android:name=".p2p.P2pTestListActivity"
                 android:label="@string/p2p_test"
-                android:configChanges="keyboardHidden|orientation">
+                android:configChanges="keyboardHidden|orientation|screenSize">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
@@ -354,39 +354,39 @@
 
         <activity android:name=".p2p.GoNegRequesterTestListActivity"
                 android:label="@string/p2p_go_neg_requester"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.GoNegRequesterTestActivity"
                 android:label="@string/p2p_go_neg_requester"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.GoNegResponderTestActivity"
                 android:label="@string/p2p_go_neg_responder"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.P2pClientTestListActivity"
                 android:label="@string/p2p_join_go"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.P2pClientTestActivity"
                 android:label="@string/p2p_join_go"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.GoTestActivity"
                 android:label="@string/p2p_accept_client"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.ServiceRequesterTestListActivity"
                 android:label="@string/p2p_service_discovery_requester"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.ServiceRequesterTestActivity"
                 android:label="@string/p2p_service_discovery_requester"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity android:name=".p2p.ServiceResponderTestActivity"
                 android:label="@string/p2p_service_discovery_responder"
-                android:configChanges="keyboardHidden|orientation" />
+                android:configChanges="keyboardHidden|orientation|screenSize" />
 
         <activity-alias android:name=".CtsVerifierActivity" android:label="@string/app_name"
                 android:targetActivity=".TestListActivity">
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/location/LocationVerifier.java b/apps/CtsVerifier/src/com/android/cts/verifier/location/LocationVerifier.java
index 56a3b44..be0ef01 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/location/LocationVerifier.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/location/LocationVerifier.java
@@ -45,12 +45,14 @@
     private int mNumActiveUpdates = 0;
     private int mNumPassiveUpdates = 0;
     private boolean mRunning = false;
+    private boolean mActiveLocationArrive = false;
 
     private class ActiveListener implements LocationListener {
         @Override
         public void onLocationChanged(Location location) {
             if (!mRunning) return;
 
+            mActiveLocationArrive = true;
             mNumActiveUpdates++;
             scheduleTimeout();
 
@@ -103,6 +105,15 @@
             if (!mRunning) return;
             if (!location.getProvider().equals(mProvider)) return;
 
+            // When a test round start, passive listener shouldn't recevice location before active listener.
+            // If this situation occurs, we treat this location as overdue location.
+            // (The overdue location comes from previous test round, it occurs occasionally)
+            // We have to skip it to prevent wrong calculation of time interval.
+            if (!mActiveLocationArrive) {
+                mCb.log("ignoring passive " + mProvider + " update");
+                return;
+            }
+
             mNumPassiveUpdates++;
             long timestamp = location.getTime();
             long delta = timestamp - mLastPassiveTimestamp;
diff --git a/tests/tests/bluetooth/src/android/bluetooth/cts/BasicAdapterTest.java b/tests/tests/bluetooth/src/android/bluetooth/cts/BasicAdapterTest.java
index e64da89..8616a6d 100644
--- a/tests/tests/bluetooth/src/android/bluetooth/cts/BasicAdapterTest.java
+++ b/tests/tests/bluetooth/src/android/bluetooth/cts/BasicAdapterTest.java
@@ -31,9 +31,10 @@
  * BluetoothAdapter}.
  */
 public class BasicAdapterTest extends AndroidTestCase {
-    private static final int DISABLE_TIMEOUT = 5000;  // ms timeout for BT disable
+    private static final int DISABLE_TIMEOUT = 8000;  // ms timeout for BT disable
     private static final int ENABLE_TIMEOUT = 10000;  // ms timeout for BT enable
     private static final int POLL_TIME = 400;         // ms to poll BT state
+    private static final int CHECK_WAIT_TIME = 1000;  // ms to wait before enable/disable
 
     private boolean mHasBluetooth;
 
@@ -222,6 +223,7 @@
      * Behavior of getState() and isEnabled() are validated along the way.
      */
     private void disable(BluetoothAdapter adapter) {
+        sleep(CHECK_WAIT_TIME);
         if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
             assertFalse(adapter.isEnabled());
             return;
@@ -230,15 +232,19 @@
         assertEquals(BluetoothAdapter.STATE_ON, adapter.getState());
         assertTrue(adapter.isEnabled());
         adapter.disable();
+        boolean turnOff = false;
         for (int i=0; i<DISABLE_TIMEOUT/POLL_TIME; i++) {
             sleep(POLL_TIME);
-            switch (adapter.getState()) {
+            int state = adapter.getState();
+            switch (state) {
             case BluetoothAdapter.STATE_OFF:
                 assertFalse(adapter.isEnabled());
                 return;
             default:
-                assertEquals(BluetoothAdapter.STATE_TURNING_OFF, adapter.getState());
-                assertFalse(adapter.isEnabled());
+                if (state != BluetoothAdapter.STATE_ON || turnOff) {
+                    assertEquals(BluetoothAdapter.STATE_TURNING_OFF, state);
+                    turnOff = true;
+                }
                 break;
             }
         }
@@ -250,6 +256,7 @@
      * Behavior of getState() and isEnabled() are validated along the way.
      */
     private void enable(BluetoothAdapter adapter) {
+        sleep(CHECK_WAIT_TIME);
         if (adapter.getState() == BluetoothAdapter.STATE_ON) {
             assertTrue(adapter.isEnabled());
             return;
@@ -258,15 +265,19 @@
         assertEquals(BluetoothAdapter.STATE_OFF, adapter.getState());
         assertFalse(adapter.isEnabled());
         adapter.enable();
+        boolean turnOn = false;
         for (int i=0; i<ENABLE_TIMEOUT/POLL_TIME; i++) {
             sleep(POLL_TIME);
-            switch (adapter.getState()) {
+            int state = adapter.getState();
+            switch (state) {
             case BluetoothAdapter.STATE_ON:
                 assertTrue(adapter.isEnabled());
                 return;
             default:
-                assertEquals(BluetoothAdapter.STATE_TURNING_ON, adapter.getState());
-                assertFalse(adapter.isEnabled());
+                if (state != BluetoothAdapter.STATE_OFF || turnOn) {
+                    assertEquals(BluetoothAdapter.STATE_TURNING_ON, state);
+                    turnOn = true;
+                }
                 break;
             }
         }
diff --git a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
index a64477d..7408301 100644
--- a/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -399,30 +399,39 @@
         }
         assertTrue(mWifiManager.isWifiEnabled());
 
-        // Wait for a WiFi connection
-        connectWifi();
+        int i = 0;
+        for (; i < 15; i++) {
+            // Wait for a WiFi connection
+            connectWifi();
 
-        // Read TX packet counter
-        int txcount1 = getTxPacketCount();
+            // Read TX packet counter
+            int txcount1 = getTxPacketCount();
 
-        // Do some network operations
-        HttpURLConnection connection = null;
-        try {
-            URL url = new URL("http://www.google.com/");
-            connection = (HttpURLConnection) url.openConnection();
-            connection.setInstanceFollowRedirects(false);
-            connection.setConnectTimeout(TIMEOUT_MSEC);
-            connection.setReadTimeout(TIMEOUT_MSEC);
-            connection.setUseCaches(false);
-            connection.getInputStream();
-        } catch (Exception e) {
-            // ignore
-        } finally {
-            if (connection != null) connection.disconnect();
+            // Do some network operations
+            HttpURLConnection connection = null;
+            try {
+                URL url = new URL("http://www.google.com/");
+                connection = (HttpURLConnection) url.openConnection();
+                connection.setInstanceFollowRedirects(false);
+                connection.setConnectTimeout(TIMEOUT_MSEC);
+                connection.setReadTimeout(TIMEOUT_MSEC);
+                connection.setUseCaches(false);
+                connection.getInputStream();
+            } catch (Exception e) {
+                // ignore
+            } finally {
+                if (connection != null) connection.disconnect();
+            }
+
+            // Read TX packet counter again and make sure it increases
+            int txcount2 = getTxPacketCount();
+
+            if (txcount2 > txcount1) {
+                break;
+            } else {
+                Thread.sleep(DURATION);
+            }
         }
-
-        // Read TX packet counter again and make sure it increases
-        int txcount2 = getTxPacketCount();
-        assertTrue(txcount2 > txcount1);
+        assertTrue(i < 15);
     }
 }
diff --git a/tests/tests/textureview/src/android/textureview/cts/TextureViewSnapshotTest.java b/tests/tests/textureview/src/android/textureview/cts/TextureViewSnapshotTest.java
index 6195e5c..c056786 100644
--- a/tests/tests/textureview/src/android/textureview/cts/TextureViewSnapshotTest.java
+++ b/tests/tests/textureview/src/android/textureview/cts/TextureViewSnapshotTest.java
@@ -25,7 +25,7 @@
     }
 
     public void testTextureViewGrabSnapshot() {
-        TextureViewSnapshotTestActivity.mMaxWaitDelayMs = 750;
+        TextureViewSnapshotTestActivity.mMaxWaitDelayMs = 1500;
         if (!getActivity().waitForCompletion())
             fail("Did not complete complete test.");
     }
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java b/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
index 8e59cc5..f014135 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/command/CtsConsole.java
@@ -174,7 +174,7 @@
         helpBuilder.append("Dump:\n");
         helpBuilder.append("  d/dump l/logs: dump the tradefed logs for all running invocations\n");
         helpBuilder.append("Options:\n");
-        helpBuilder.append("  --reboot-per-package : reboot device after running each package.\n");
+        helpBuilder.append("  --disable-reboot : Do not reboot device after running some amount of tests.\n");
         return helpBuilder.toString();
     }
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
index 7699ef1..55d947e 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/CtsTest.java
@@ -137,16 +137,16 @@
         "run tests including known failures")
     private boolean mIncludeKnownFailures;
 
-    @Option(name = "reboot-per-package", description =
-            "Reboot after each package run")
-    private boolean mRebootPerPackage = false;
+    @Option(name = "disable-reboot", description =
+            "Do not reboot device after running some amount of tests. Default behavior is to reboot.")
+    private boolean mDisableReboot = false;
 
     @Option(name = "reboot-wait-time", description =
-            "Additional wait time in ms after boot complete. Meaningful only with reboot-per-package option")
+            "Additional wait time in ms after boot complete.")
     private int mRebootWaitTimeMSec = 2 * 60 * 1000;
 
     @Option(name = "reboot-interval", description =
-            "Interval between each reboot in min. Meaningful only with reboot-per-package option")
+            "Interval between each reboot in min.")
     private int mRebootIntervalMin = 30;
 
 
@@ -350,7 +350,7 @@
             // always collect the device info, even for resumed runs, since test will likely be
             // running on a different device
             collectDeviceInfo(getDevice(), mCtsBuild, listener);
-            if (mRemainingTestPkgs.size() > 1) {
+            if (mRemainingTestPkgs.size() > 1 && !mDisableReboot) {
                 Log.i(LOG_TAG, "Initial reboot for multiple packages");
                 rebootDevice();
             }
@@ -405,7 +405,7 @@
                 "CtsViewTestCases",
                 "CtsWidgetTestCases" );
         long intervalInMSec = mRebootIntervalMin * 60 * 1000;
-        if (mRebootPerPackage) {
+        if (!mDisableReboot) {
             long currentTime = System.currentTimeMillis();
             if (((currentTime - mPrevRebootTime) > intervalInMSec) ||
                     rebootAfterList.contains(testFinished.getPackageDef().getName()) ||