am 97afc8f5: am 7315af87: Need enough time (1 sec) to read amounts of packet from /proc/stat_uid/[uid]/tcp_snd.

Merge commit '97afc8f560be0b0e2e78e1d966365263ab643a72' into gingerbread-plus-aosp

* commit '97afc8f560be0b0e2e78e1d966365263ab643a72':
  Need enough time (1 sec) to read amounts of packet from /proc/stat_uid/[uid]/tcp_snd.
diff --git a/tests/appsecurity-tests/Android.mk b/tests/appsecurity-tests/Android.mk
index a0f7f41..4ec9922 100644
--- a/tests/appsecurity-tests/Android.mk
+++ b/tests/appsecurity-tests/Android.mk
@@ -23,7 +23,7 @@
 
 LOCAL_MODULE := CtsAppSecurityTests
 
-LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib junit
+LOCAL_JAVA_LIBRARIES := hosttestlib ddmlib-prebuilt junit
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 
diff --git a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
index 2833fa4..8607b73 100644
--- a/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
+++ b/tests/appsecurity-tests/src/com/android/cts/appsecurity/AppSecurityTests.java
@@ -18,10 +18,15 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Map;
 
 import junit.framework.Test;
 
+import com.android.ddmlib.AdbCommandRejectedException;
+import com.android.ddmlib.InstallException;
 import com.android.ddmlib.Log;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.testrunner.ITestRunListener;
 import com.android.ddmlib.testrunner.RemoteAndroidTestRunner;
 import com.android.ddmlib.testrunner.TestIdentifier;
@@ -78,7 +83,7 @@
      * Test that an app that declares the same shared uid as an existing app, cannot be installed
      * if it is signed with a different certificate.
      */
-    public void testSharedUidDifferentCerts() throws IOException {
+    public void testSharedUidDifferentCerts() throws InstallException {
         Log.i(LOG_TAG, "installing apks with shared uid, but different certs");
         try {
             // cleanup test apps that might be installed from previous partial test run
@@ -104,7 +109,7 @@
      * Test that an app update cannot be installed over an existing app if it has a different
      * certificate.
      */
-    public void testAppUpgradeDifferentCerts() throws IOException {
+    public void testAppUpgradeDifferentCerts() throws InstallException {
         Log.i(LOG_TAG, "installing app upgrade with different certs");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -127,7 +132,8 @@
     /**
      * Test that an app cannot access another app's private data.
      */
-    public void testAppFailAccessPrivateData() throws IOException {
+    public void testAppFailAccessPrivateData() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to access another app's private data");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -155,7 +161,8 @@
     /**
      * Test that an app cannot instrument another app that is signed with different certificate.
      */
-    public void testInstrumentationDiffCert() throws IOException {
+    public void testInstrumentationDiffCert() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to instrument another app");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -186,7 +193,8 @@
      * Test that an app cannot use a signature-enforced permission if it is signed with a different
      * certificate than the app that declared the permission.
      */
-    public void testPermissionDiffCert() throws IOException {
+    public void testPermissionDiffCert() throws InstallException, TimeoutException,
+            AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         Log.i(LOG_TAG, "installing app that attempts to use permission of another app");
         try {
             // cleanup test app that might be installed from previous partial test run
@@ -225,9 +233,15 @@
      *
      * @param pkgName Android application package for tests
      * @return <code>true</code> if all tests passed.
-     * @throws IOException if connection to device was lost
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output any test result for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    private boolean runDeviceTests(String pkgName) throws IOException {
+    private boolean runDeviceTests(String pkgName)
+            throws TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, IOException {
         CollectingTestRunListener listener = doRunTests(pkgName);
         return listener.didAllTestsPass();
     }
@@ -236,9 +250,15 @@
      * Helper method to run tests and return the listener that collected the results.
      * @param pkgName Android application package for tests
      * @return the {@link CollectingTestRunListener}
-     * @throws IOException if connection to device was lost
+     * @throws TimeoutException in case of a timeout on the connection.
+     * @throws AdbCommandRejectedException if adb rejects the command
+     * @throws ShellCommandUnresponsiveException if the device did not output any test result for
+     * a period longer than the max time to output.
+     * @throws IOException if connection to device was lost.
      */
-    private CollectingTestRunListener doRunTests(String pkgName) throws IOException {
+    private CollectingTestRunListener doRunTests(String pkgName)
+            throws TimeoutException, AdbCommandRejectedException,
+            ShellCommandUnresponsiveException, IOException {
         RemoteAndroidTestRunner testRunner = new RemoteAndroidTestRunner(pkgName, getDevice());
         CollectingTestRunListener listener = new CollectingTestRunListener();
         testRunner.run(listener);
@@ -250,7 +270,7 @@
         private boolean mAllTestsPassed = true;
         private String mTestRunErrorMessage = null;
 
-        public void testEnded(TestIdentifier test) {
+        public void testEnded(TestIdentifier test, Map<String, String> metrics) { 
             // ignore
         }
 
@@ -261,7 +281,7 @@
             mAllTestsPassed = false;
         }
 
-        public void testRunEnded(long elapsedTime) {
+        public void testRunEnded(long elapsedTime, Map<String, String> resultBundle) {
             // ignore
         }
 
diff --git a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
index c67002c..c47b65b 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
@@ -50,6 +50,7 @@
         "age",             // 2
         "address"          // 3
     };
+    private static final String TABLE_NAME = "test";
 
     @Override
     protected void setUp() throws Exception {
@@ -61,7 +62,7 @@
         }
         mDatabase = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null);
         assertNotNull(mDatabase);
-        mDatabase.execSQL("CREATE TABLE test (_id INTEGER PRIMARY KEY, " +
+        mDatabase.execSQL("CREATE TABLE " + TABLE_NAME + " (_id INTEGER PRIMARY KEY, " +
                 "name TEXT, age INTEGER, address TEXT);");
     }
 
@@ -132,11 +133,12 @@
         String address = "LA";
 
         // at the beginning, there are no records in the database.
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
         assertEquals(0, cursor.getCount());
 
-        String sql = "INSERT INTO test (name, age, address) VALUES (?, ?, ?);";
+        String sql = "INSERT INTO " + TABLE_NAME + " (name, age, address) VALUES (?, ?, ?);";
         SQLiteStatement statement = mDatabase.compileStatement(sql);
         DatabaseUtils.bindObjectToProgram(statement, 1, name);
         DatabaseUtils.bindObjectToProgram(statement, 2, age);
@@ -144,7 +146,7 @@
         statement.execute();
         statement.close();
 
-        cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null, null, null);
         assertNotNull(cursor);
         assertEquals(1, cursor.getCount());
         cursor.moveToFirst();
@@ -161,8 +163,8 @@
     )
     public void testCreateDbFromSqlStatements() {
         String dbName = "ExampleName";
-        String sqls = "CREATE TABLE test (_id INTEGER PRIMARY KEY, name TEXT);\n"
-                + "INSERT INTO test (name) VALUES ('Mike');\n";
+        String sqls = "CREATE TABLE " + TABLE_NAME + " (_id INTEGER PRIMARY KEY, name TEXT);\n"
+                + "INSERT INTO " + TABLE_NAME + " (name) VALUES ('Mike');\n";
         DatabaseUtils.createDbFromSqlStatements(getContext(), dbName, 1, sqls);
 
         SQLiteDatabase db = getContext().openOrCreateDatabase(dbName, 0, null);
@@ -170,7 +172,7 @@
             "_id",             // 0
             "name"             // 1
         };
-        Cursor cursor = db.query("test", PROJECTION, null, null, null, null, null);
+        Cursor cursor = db.query(TABLE_NAME, PROJECTION, null, null, null, null, null);
         assertNotNull(cursor);
         assertEquals(1, cursor.getCount());
         cursor.moveToFirst();
@@ -185,8 +187,10 @@
                 android.content.ContentValues.class, java.lang.String.class}
     )
     public void testCursorDoubleToContentValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -210,8 +214,10 @@
     )
     @ToBeFixed(bug = "1586458", explanation = "It's probably a typo.")
     public void testCursorDoubleToCursorValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -241,8 +247,9 @@
         )
     })
     public void testCursorIntToContentValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -283,8 +290,9 @@
         )
     })
     public void testcursorLongToContentValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -316,8 +324,10 @@
         args = {android.database.Cursor.class, android.content.ContentValues.class}
     )
     public void testCursorRowToContentValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -343,8 +353,10 @@
         )
     })
     public void testCursorStringToContentValues() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
 
         ContentValues contentValues = new ContentValues();
@@ -390,7 +402,8 @@
         mDatabase.execSQL("CREATE TABLE test_copy (_id INTEGER PRIMARY KEY, " +
                 "name TEXT, age INTEGER, address TEXT);");
 
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
         Cursor cursor = mDatabase.query("test_copy", TEST_PROJECTION, null, null, null, null, null);
         assertEquals(0, cursor.getCount());
 
@@ -399,7 +412,7 @@
         int indexAge = insertHelper.getColumnIndex("age");
         int indexAddress = insertHelper.getColumnIndex("address");
 
-        cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION, null, null, null, null, null);
         cursor.moveToNext();
         insertHelper.prepareForInsert();
         DatabaseUtils.cursorStringToInsertHelper(cursor, "name", insertHelper, indexName);
@@ -438,8 +451,10 @@
         )
     })
     public void testDumpCurrentRow() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
         cursor.moveToNext();
         String expected = "0 {\n   _id=1\n   name=Mike\n   age=20\n   address=LA\n}\n";
@@ -483,9 +498,12 @@
         )
     })
     public void testDumpCursor() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Jack', '30', 'London');");
-        Cursor cursor = mDatabase.query("test", TEST_PROJECTION, null, null, null, null, null);
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Jack', '30', 'London');");
+        Cursor cursor = mDatabase.query(TABLE_NAME, TEST_PROJECTION,
+                null, null, null, null, null);
         assertNotNull(cursor);
         int pos = cursor.getPosition();
         String expected = ">>>>> Dumping cursor " + cursor + "\n" +
@@ -564,13 +582,15 @@
         )
     })
     public void testLongForQuery() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
 
-        String query = "SELECT age FROM test";
+        String query = "SELECT age FROM " + TABLE_NAME;
         assertEquals(20, DatabaseUtils.longForQuery(mDatabase, query, null));
 
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Jack', '35', 'London');");
-        query = "SELECT age FROM test WHERE name = ?";
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Jack', '35', 'London');");
+        query = "SELECT age FROM " + TABLE_NAME + " WHERE name = ?";
         String[] args = new String[] { "Jack" };
         assertEquals(35, DatabaseUtils.longForQuery(mDatabase, query, args));
         args = new String[] { "No such name" };
@@ -581,11 +601,11 @@
             // expected
         }
 
-        query = "SELECT count(*) FROM test;";
+        query = "SELECT count(*) FROM " + TABLE_NAME + ";";
         SQLiteStatement statement = mDatabase.compileStatement(query);
         assertEquals(2, DatabaseUtils.longForQuery(statement, null));
 
-        query = "SELECT age FROM test WHERE address = ?;";
+        query = "SELECT age FROM " + TABLE_NAME + " WHERE address = ?;";
         statement = mDatabase.compileStatement(query);
         args = new String[] { "London" };
         assertEquals(35, DatabaseUtils.longForQuery(statement, args));
@@ -600,19 +620,47 @@
         statement.close();
     }
 
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        method = "queryNumEntries",
-        args = {android.database.sqlite.SQLiteDatabase.class, java.lang.String.class}
-    )
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "queryNumEntries",
+            args = {android.database.sqlite.SQLiteDatabase.class, java.lang.String.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "queryNumEntries",
+            args = {android.database.sqlite.SQLiteDatabase.class, java.lang.String.class,
+                    java.lang.String.class}
+        ),
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "queryNumEntries",
+            args = {android.database.sqlite.SQLiteDatabase.class, java.lang.String.class,
+                    java.lang.String.class, java.lang.String[].class}
+        )
+    })
     public void testQueryNumEntries() {
-        assertEquals(0, DatabaseUtils.queryNumEntries(mDatabase, "test"));
+        assertEquals(0, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME));
 
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        assertEquals(1, DatabaseUtils.queryNumEntries(mDatabase, "test"));
+        mDatabase.execSQL(
+                "INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
+        assertEquals(1, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME));
 
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
-        assertEquals(2, DatabaseUtils.queryNumEntries(mDatabase, "test"));
+        mDatabase.execSQL(
+                "INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Susan', '20', 'AR');");
+        assertEquals(2, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME));
+
+        mDatabase.execSQL(
+                "INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Christian', '25', 'AT');");
+        assertEquals(3, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME));
+
+        assertEquals(2, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME, "AGE = 20"));
+
+        assertEquals(1, DatabaseUtils.queryNumEntries(mDatabase, TABLE_NAME, "AGE = ?",
+                new String[] { "25" }));
 
         try {
             DatabaseUtils.queryNumEntries(mDatabase, "NoSuchTable");
@@ -695,13 +743,15 @@
         )
     })
     public void testStringForQuery() {
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Mike', '20', 'LA');");
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Mike', '20', 'LA');");
 
-        String query = "SELECT name FROM test";
+        String query = "SELECT name FROM " + TABLE_NAME;
         assertEquals("Mike", DatabaseUtils.stringForQuery(mDatabase, query, null));
 
-        mDatabase.execSQL("INSERT INTO test (name, age, address) VALUES ('Jack', '35', 'London');");
-        query = "SELECT name FROM test WHERE address = ?";
+        mDatabase.execSQL("INSERT INTO " + TABLE_NAME + " (name, age, address)" +
+                " VALUES ('Jack', '35', 'London');");
+        query = "SELECT name FROM " + TABLE_NAME + " WHERE address = ?";
         String[] args = new String[] { "London" };
         assertEquals("Jack", DatabaseUtils.stringForQuery(mDatabase, query, args));
         args = new String[] { "No such address" };
@@ -712,7 +762,7 @@
             // expected
         }
 
-        query = "SELECT name FROM test WHERE age = ?;";
+        query = "SELECT name FROM " + TABLE_NAME + " WHERE age = ?;";
         SQLiteStatement statement = mDatabase.compileStatement(query);
         args = new String[] { "20" };
         assertEquals("Mike", DatabaseUtils.stringForQuery(statement, args));
@@ -726,4 +776,4 @@
         }
         statement.close();
     }
-}
+}
\ No newline at end of file
diff --git a/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java b/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
index a268cba..4541e9d 100644
--- a/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ArrayAdapterTest.java
@@ -526,6 +526,94 @@
         assertEquals(2, mockDataSetObserver.getCalledOnChangedCount());
     }
 
+    /**
+     * insert multiple items via add, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "add",
+            args = {Object.class}
+        )
+    })
+    public void testAdd() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.add("testing");
+        mArrayAdapter.add("android");
+        assertEquals(mArrayAdapter.getCount(), 2);
+        assertEquals(mArrayAdapter.getItem(0), "testing");
+        assertEquals(mArrayAdapter.getItem(1), "android");
+    }
+
+    /**
+     * insert multiple items via addAll, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "addAll",
+            args = {java.util.Collection.class}
+        )
+    })
+    public void testAddAllCollection() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        List<String> list = new ArrayList<String>();
+        list.add("");
+        list.add("hello");
+        list.add("android");
+        list.add("!");
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.addAll(list);
+        assertEquals(mArrayAdapter.getCount(), list.size());
+
+        assertEquals(mArrayAdapter.getItem(0), list.get(0));
+        assertEquals(mArrayAdapter.getItem(1), list.get(1));
+        assertEquals(mArrayAdapter.getItem(2), list.get(2));
+        assertEquals(mArrayAdapter.getItem(3), list.get(3));
+    }
+
+    /**
+     * insert multiple items via addAll, notify data changed
+     * check count and content
+     */
+    @TestTargets({
+        @TestTargetNew(
+            level = TestLevel.COMPLETE,
+            method = "addAll",
+            args = {Object[].class}
+        )
+    })
+    public void testAddAllParams() {
+        mArrayAdapter.setNotifyOnChange(true);
+        final MockDataSetObserver mockDataSetObserver = new MockDataSetObserver();
+        mArrayAdapter.registerDataSetObserver(mockDataSetObserver);
+
+        mArrayAdapter.clear();
+        assertEquals(mArrayAdapter.getCount(), 0);
+
+        mArrayAdapter.addAll("this", "is", "a", "unit", "test");
+        assertEquals(mArrayAdapter.getCount(), 5);
+        assertEquals(mArrayAdapter.getItem(0), "this");
+        assertEquals(mArrayAdapter.getItem(1), "is");
+        assertEquals(mArrayAdapter.getItem(2), "a");
+        assertEquals(mArrayAdapter.getItem(3), "unit");
+        assertEquals(mArrayAdapter.getItem(4), "test");
+    }
+
     private static class MockDataSetObserver extends DataSetObserver {
 
         private int mCalledOnChangedCount;
diff --git a/tools/host/src/Android.mk b/tools/host/src/Android.mk
index df43dc8..47a9cb8 100644
--- a/tools/host/src/Android.mk
+++ b/tools/host/src/Android.mk
@@ -21,7 +21,7 @@
 
 LOCAL_JAR_MANIFEST := ../etc/manifest.txt
 LOCAL_JAVA_LIBRARIES := \
-    ddmlib junit hosttestlib
+    ddmlib-prebuilt junit hosttestlib
 
 LOCAL_MODULE := cts
 
diff --git a/tools/host/src/com/android/cts/DeviceManager.java b/tools/host/src/com/android/cts/DeviceManager.java
index 528036e..80e05d5 100644
--- a/tools/host/src/com/android/cts/DeviceManager.java
+++ b/tools/host/src/com/android/cts/DeviceManager.java
@@ -16,8 +16,10 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.AndroidDebugBridge;
 import com.android.ddmlib.IDevice;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener;
 
 import java.io.IOException;
@@ -230,6 +232,10 @@
                 mSemaphore.release();
             } catch (IOException e) {
                 // FIXME: handle failed connection to device.
+            } catch (TimeoutException e) {
+                // FIXME: handle failed connection to device.
+            } catch (AdbCommandRejectedException e) {
+                // FIXME: handle failed connection to device.
             }
         }
     }
diff --git a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
index 2b70b86..6b91ab4 100644
--- a/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
+++ b/tools/host/src/com/android/cts/ReferenceAppTestPackage.java
@@ -16,8 +16,10 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.MultiLineReceiver;
 import com.android.ddmlib.RawImage;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.log.LogReceiver.ILogListener;
 import com.android.ddmlib.log.LogReceiver.LogEntry;
 
@@ -199,6 +201,10 @@
                     }
                 } catch (IOException e) {
                     Log.e("Error taking snapshot! " + cmdArgs, e);
+                } catch (TimeoutException e) {
+                    Log.e("Error taking snapshot! " + cmdArgs, e);
+                } catch (AdbCommandRejectedException e) {
+                    Log.e("Error taking snapshot! " + cmdArgs, e);
                 }
             }
         });
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 65ff969..5fd00b4 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -16,6 +16,7 @@
 
 package com.android.cts;
 
+import com.android.ddmlib.AdbCommandRejectedException;
 import com.android.ddmlib.Client;
 import com.android.ddmlib.ClientData;
 import com.android.ddmlib.IDevice;
@@ -23,13 +24,16 @@
 import com.android.ddmlib.MultiLineReceiver;
 import com.android.ddmlib.NullOutputReceiver;
 import com.android.ddmlib.RawImage;
+import com.android.ddmlib.ShellCommandUnresponsiveException;
+import com.android.ddmlib.SyncException;
 import com.android.ddmlib.SyncService;
 import com.android.ddmlib.SyncService.ISyncProgressMonitor;
-import com.android.ddmlib.SyncService.SyncResult;
+import com.android.ddmlib.TimeoutException;
 import com.android.ddmlib.log.LogReceiver;
 import com.android.ddmlib.log.LogReceiver.ILogListener;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -101,6 +105,8 @@
             try {
                 mDevice.runLogService("main", logReceiver);
             } catch (IOException e) {
+            } catch (TimeoutException e) {
+            } catch (AdbCommandRejectedException e) {
             }
         }
 
@@ -136,6 +142,10 @@
             mSyncService = mDevice.getSyncService();
         } catch (IOException e) {
             // FIXME: handle failed connection.
+        } catch (TimeoutException e) {
+            // FIXME: handle failed connection.
+        } catch (AdbCommandRejectedException e) {
+            // FIXME: handle failed connection.
         }
         mBatchModeResultParser = null;
         mUninstallObserver = new PackageActionObserver(ACTION_UNINSTALL);
@@ -922,10 +932,16 @@
      * @param remotePath The remote path.
      */
     public void pushFile(String localPath, String remotePath) {
-        SyncResult result = mSyncService.pushFile(localPath, remotePath,
-                new PushMonitor());
-        if (result.getCode() != SyncService.RESULT_OK) {
-            Log.e("Uploading file failed: " + result.getMessage(), null);
+        try {
+            mSyncService.pushFile(localPath, remotePath, new PushMonitor());
+        } catch (TimeoutException e) {
+            Log.e("Uploading file failed: timeout", null);
+        } catch (SyncException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
+        } catch (FileNotFoundException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
+        } catch (IOException e) {
+            Log.e("Uploading file failed: " + e.getMessage(), null);
         }
     }
 
@@ -1670,6 +1686,12 @@
                     mDevice.executeShellCommand(cmd, receiver);
                 } catch (IOException e) {
                     Log.e("", e);
+                } catch (TimeoutException e) {
+                    Log.e("", e);
+                } catch (AdbCommandRejectedException e) {
+                    Log.e("", e);
+                } catch (ShellCommandUnresponsiveException e) {
+                    Log.e("", e);
                 }
             }
         }.start();
@@ -1887,8 +1909,11 @@
      *
      * @return the screenshot
      * @throws IOException
+     * @throws AdbCommandRejectedException
+     * @throws TimeoutException
      */
-    public RawImage getScreenshot() throws IOException {
+    public RawImage getScreenshot() throws IOException, TimeoutException,
+            AdbCommandRejectedException {
         return mDevice.getScreenshot();
     }
 }
diff --git a/tools/utils/startcts b/tools/utils/startcts
index 59ca6aa..a4c97f8 100755
--- a/tools/utils/startcts
+++ b/tools/utils/startcts
@@ -49,7 +49,7 @@
 checkDir ${CTS_ROOT} "Error: Cannot locate CTS in \"${CTS_DIR}\". Please check your configuration in $0"
 checkDir ${SDK_ROOT} "Error: Cannot locate SDK installation in \"${SDK_ROOT}\". Please check your configuration in $0"
 
-DDM_LIB=${SDK_ROOT}/tools/lib/ddmlib.jar
+DDM_LIB=${CTS_ROOT}/tools/ddmlib-prebuilt.jar
 CTS_LIB=${CTS_ROOT}/tools/cts.jar
 JUNIT_LIB=${CTS_ROOT}/tools/junit.jar
 HOSTTEST_LIB=${CTS_ROOT}/tools/hosttestlib.jar