am d15dd73c: am df318f65: am 5f033a61: am 198f049a: am 505ce805: Merge "Change SSLCertificateSocketFactoryTest to use googlemail.com" into jb-dev

* commit 'd15dd73c1d2e887d53d530c5188539d9a9759a8b':
  Change SSLCertificateSocketFactoryTest to use googlemail.com
diff --git a/CtsBuild.mk b/CtsBuild.mk
index 6e57086..d396006 100644
--- a/CtsBuild.mk
+++ b/CtsBuild.mk
@@ -36,10 +36,6 @@
 	$(foreach lib,$(1),$(HOST_OUT_JAVA_LIBRARIES)/$(lib).jar)
 endef
 
-define cts-get-ui-lib-paths
-	$(foreach lib,$(1),$(CTS_TESTCASES_OUT)/$(lib).jar)
-endef
-
 define cts-get-native-paths
 	$(foreach exe,$(1),$(call intermediates-dir-for,EXECUTABLES,$(exe))/$(exe))
 endef
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 2b61134..5511ebd 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -38,7 +38,6 @@
 	CtsTestStubs \
 	SignatureTest \
 	TestDeviceSetup \
-        CtsUiAutomatorApp \
 	$(cts_security_apps_list)
 
 cts_external_packages := \
@@ -116,23 +115,17 @@
 	NativeMediaTest_SL \
 	NativeMediaTest_XA
 
-cts_ui_tests := \
-        CtsUiAutomatorTests
-
 # All the files that will end up under the repository/testcases
 # directory of the final CTS distribution.
 CTS_TEST_CASES := $(call cts-get-lib-paths,$(cts_host_libraries)) \
 		$(call cts-get-package-paths,$(cts_test_packages)) \
-		$(call cts-get-native-paths,$(cts_native_exes)) \
-		$(call cts-get-ui-lib-paths,$(cts_ui_tests))
+		$(call cts-get-native-paths,$(cts_native_exes))
 
 # All the XMLs that will end up under the repository/testcases
 # and that need to be created before making the final CTS distribution.
 CTS_TEST_XMLS := $(call cts-get-test-xmls,$(cts_host_libraries)) \
 		$(call cts-get-test-xmls,$(cts_test_packages)) \
-		$(call cts-get-test-xmls,$(cts_native_exes)) \
-		$(call cts-get-test-xmls,$(cts_ui_tests))
-
+		$(call cts-get-test-xmls,$(cts_native_exes))
 
 # The following files will be placed in the tools directory of the CTS distribution
 CTS_TOOLS_LIST :=
diff --git a/apps/CtsVerifier/jni/cameraanalyzer/com_android_cts_verifier_camera_analyzer_CameraTests.cpp b/apps/CtsVerifier/jni/cameraanalyzer/com_android_cts_verifier_camera_analyzer_CameraTests.cpp
index 83f5c17..ed91233 100644
--- a/apps/CtsVerifier/jni/cameraanalyzer/com_android_cts_verifier_camera_analyzer_CameraTests.cpp
+++ b/apps/CtsVerifier/jni/cameraanalyzer/com_android_cts_verifier_camera_analyzer_CameraTests.cpp
@@ -51,7 +51,7 @@
             inputBitmap,
             reinterpret_cast<void**>(&inputBuffer));
 
-    if (result != ANDROID_BITMAP_RESUT_SUCCESS) {
+    if (result != ANDROID_BITMAP_RESULT_SUCCESS) {
         ALOGE("Unable to lock input bitmap");
     }
 
@@ -106,7 +106,7 @@
     long lp = (long)input_testing_image;
 
     result = AndroidBitmap_unlockPixels(env, inputBitmap);
-    if (result != ANDROID_BITMAP_RESUT_SUCCESS) {
+    if (result != ANDROID_BITMAP_RESULT_SUCCESS) {
         ALOGE("Unable to unlock input bitmap");
     }
 
@@ -200,14 +200,14 @@
                 outputBitmap,
                 reinterpret_cast<void**>(&outputBuffer) );
 
-        if (result != ANDROID_BITMAP_RESUT_SUCCESS) {
+        if (result != ANDROID_BITMAP_RESULT_SUCCESS) {
             ALOGE("Unable to lock output bitmap");
         }
 
         memcpy(outputBuffer, outputImage, outputWidth * outputHeight * 4);
 
         result = AndroidBitmap_unlockPixels(env, outputBitmap);
-        if (result != ANDROID_BITMAP_RESUT_SUCCESS) {
+        if (result != ANDROID_BITMAP_RESULT_SUCCESS) {
             ALOGE("Unable to unlock output bitmap");
         }
 
diff --git a/build/config.mk b/build/config.mk
index a121dc5..c9fa709 100644
--- a/build/config.mk
+++ b/build/config.mk
@@ -15,4 +15,3 @@
 BUILD_CTS_EXECUTABLE := cts/build/test_executable.mk
 BUILD_CTS_PACKAGE := cts/build/test_package.mk
 BUILD_CTS_HOST_JAVA_LIBRARY := cts/build/test_host_java_library.mk
-BUILD_CTS_UI_JAVA_LIBRARY := cts/build/test_uiautomator.mk
diff --git a/build/test_uiautomator.mk b/build/test_uiautomator.mk
deleted file mode 100644
index 255f70b..0000000
--- a/build/test_uiautomator.mk
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright (C) 2012 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.
-
-#
-# Builds a uiautomator library and defines a rule to generate the associated test
-# package XML needed by CTS.
-#
-
-include $(BUILD_JAVA_LIBRARY)
-
-cts_library_xml := $(CTS_TESTCASES_OUT)/$(LOCAL_MODULE).xml 
-cts_library_jar := $(CTS_TESTCASES_OUT)/$(LOCAL_MODULE).jar
-
-$(cts_library_jar): PRIVATE_MODULE := $(LOCAL_MODULE)
-$(cts_library_jar): $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE))/javalib.jar | $(ACP)
-	$(hide) mkdir -p $(CTS_TESTCASES_OUT)
-	$(hide) $(ACP) -fp $(call intermediates-dir-for,JAVA_LIBRARIES,$(PRIVATE_MODULE))/javalib.jar $@
-
-$(cts_library_xml): PRIVATE_PATH := $(LOCAL_PATH)/src
-$(cts_library_xml): PRIVATE_TEST_APP_PACKAGE := $(LOCAL_CTS_TEST_APP_PACKAGE)
-$(cts_library_xml): PRIVATE_TEST_PACKAGE := $(LOCAL_CTS_TEST_PACKAGE)
-$(cts_library_xml): PRIVATE_TEST_APK := $(LOCAL_CTS_TEST_APK)
-$(cts_library_xml): PRIVATE_LIBRARY := $(LOCAL_MODULE)
-$(cts_library_xml): PRIVATE_JAR_PATH := $(LOCAL_MODULE).jar
-$(cts_library_xml): $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE))/javalib.jar $(CTS_EXPECTATIONS) $(CTS_JAVA_TEST_SCANNER_DOCLET) $(CTS_JAVA_TEST_SCANNER) $(CTS_XML_GENERATOR)
-	$(hide) echo Generating test description for uiautomator library $(PRIVATE_LIBRARY)
-	$(hide) mkdir -p $(CTS_TESTCASES_OUT)
-	$(hide) $(CTS_JAVA_TEST_SCANNER) -s $(PRIVATE_PATH) \
-						-d $(CTS_JAVA_TEST_SCANNER_DOCLET) | \
-			$(CTS_XML_GENERATOR) -t uiAutomator \
-						-i $(PRIVATE_TEST_APK) \
-						-j $(PRIVATE_JAR_PATH) \
-						-a $(PRIVATE_TEST_PACKAGE) \
-						-n $(PRIVATE_LIBRARY) \
-						-p $(PRIVATE_TEST_PACKAGE) \
-						-r $(PRIVATE_TEST_APP_PACKAGE) \
-						-e $(CTS_EXPECTATIONS) \
-						-o $@
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
index 89c2f7c..5161697 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/AlmostFullTest.java
@@ -17,18 +17,11 @@
 package com.android.pts.filesystemperf;
 
 import android.cts.util.TimeoutReq;
-import com.android.pts.util.MeasureRun;
-import com.android.pts.util.MeasureTime;
-import com.android.pts.util.PtsAndroidTestCase;
-import com.android.pts.util.ReportLog;
-import com.android.pts.util.Stat;
-import com.android.pts.util.SystemUtil;
-
 import android.util.Log;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import com.android.pts.util.PtsAndroidTestCase;
+import com.android.pts.util.SystemUtil;
+
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -57,7 +50,8 @@
         super.setUp();
         if (mDiskFilled.compareAndSet(false, true)) {
             Log.i(TAG, "Filling disk");
-            // initial fill done in two stage as disk can be filled by other components
+            // initial fill done in two stage as disk can be filled by other
+            // components
             long freeDisk = SystemUtil.getFreeDiskSize(getContext());
             long diskToFill = freeDisk - FREE_SPACE_FINAL;
             Log.i(TAG, "free disk " + freeDisk + ", to fill " + diskToFill);
@@ -106,8 +100,8 @@
                 BUFFER_SIZE, NUMBER_REPETITION);
     }
 
-    //TODO: file size too small and caching will give wrong better result.
-    //      needs to flush cache by reading big files per each read.
+    // TODO: file size too small and caching will give wrong better result.
+    // needs to flush cache by reading big files per each read.
     @TimeoutReq(minutes = 60)
     public void testRandomRead() throws Exception {
         final int BUFFER_SIZE = 4 * 1024;
diff --git a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
index 537d900..e52af08 100644
--- a/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
+++ b/suite/pts/deviceTests/filesystemperf/src/com/android/pts/filesystemperf/RandomRWTest.java
@@ -17,16 +17,8 @@
 package com.android.pts.filesystemperf;
 
 import android.cts.util.TimeoutReq;
-import com.android.pts.util.MeasureRun;
-import com.android.pts.util.PtsAndroidTestCase;
-import com.android.pts.util.ReportLog;
-import com.android.pts.util.Stat;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.util.Random;
+import com.android.pts.util.PtsAndroidTestCase;
 
 
 public class RandomRWTest extends PtsAndroidTestCase {
diff --git a/tests/core/ctscore.mk b/tests/core/ctscore.mk
index 27ff881..1e4e017 100644
--- a/tests/core/ctscore.mk
+++ b/tests/core/ctscore.mk
@@ -22,4 +22,7 @@
 LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
 # Don't delete META-INF from the core-tests jar
 LOCAL_DONT_DELETE_JAR_META_INF := true
+
+LOCAL_JNI_SHARED_LIBRARIES := libjavacoretests
+
 include $(BUILD_PACKAGE)
diff --git a/tests/jni/android_os_cts_CpuFeatures.cpp b/tests/jni/android_os_cts_CpuFeatures.cpp
index 95a0d2f..053b44e 100644
--- a/tests/jni/android_os_cts_CpuFeatures.cpp
+++ b/tests/jni/android_os_cts_CpuFeatures.cpp
@@ -30,11 +30,27 @@
     return (cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) == ANDROID_CPU_ARM_FEATURE_ARMv7;
 }
 
+jboolean android_os_cts_CpuFeatures_isMipsCpu(JNIEnv* env, jobject thiz)
+{
+    AndroidCpuFamily cpuFamily = android_getCpuFamily();
+    return cpuFamily == ANDROID_CPU_FAMILY_MIPS;
+}
+
+jboolean android_os_cts_CpuFeatures_isX86Cpu(JNIEnv* env, jobject thiz)
+{
+    AndroidCpuFamily cpuFamily = android_getCpuFamily();
+    return cpuFamily == ANDROID_CPU_FAMILY_X86;
+}
+
 static JNINativeMethod gMethods[] = {
     {  "isArmCpu", "()Z",
             (void *) android_os_cts_CpuFeatures_isArmCpu  },
     {  "isArm7Compatible", "()Z",
             (void *) android_os_cts_CpuFeatures_isArm7Compatible  },
+    {  "isMipsCpu", "()Z",
+            (void *) android_os_cts_CpuFeatures_isMipsCpu  },
+    {  "isX86Cpu", "()Z",
+            (void *) android_os_cts_CpuFeatures_isX86Cpu  },
 };
 
 int register_android_os_cts_CpuFeatures(JNIEnv* env)
diff --git a/tests/src/android/os/cts/CpuFeatures.java b/tests/src/android/os/cts/CpuFeatures.java
index f87db6a..5009474 100644
--- a/tests/src/android/os/cts/CpuFeatures.java
+++ b/tests/src/android/os/cts/CpuFeatures.java
@@ -22,6 +22,10 @@
 
     public static final String ARMEABI = "armeabi";
 
+    public static final String MIPSABI = "mips";
+
+    public static final  String X86ABI = "x86";
+
     static {
         System.loadLibrary("cts_jni");
     }
@@ -29,4 +33,8 @@
     public static native boolean isArmCpu();
 
     public static native boolean isArm7Compatible();
+
+    public static native boolean isMipsCpu();
+
+    public static native boolean isX86Cpu();
 }
diff --git a/tests/tests/os/src/android/os/cts/BuildTest.java b/tests/tests/os/src/android/os/cts/BuildTest.java
index 210299a..fae7d1f 100644
--- a/tests/tests/os/src/android/os/cts/BuildTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildTest.java
@@ -40,14 +40,37 @@
 
     private void assertArmCpuAbiConstants() throws IOException {
         if (CpuFeatures.isArm7Compatible()) {
-            String message = "CPU is ARM v7 compatible, so "
+            String cpuAbi = getProperty(RO_PRODUCT_CPU_ABI);
+            String cpuAbi2 = getProperty(RO_PRODUCT_CPU_ABI2);
+            //if CPU_ABI is armv7, CPU_ABI2 is either of {armeabi, NULL}
+            if (cpuAbi.equals(CpuFeatures.ARMEABI_V7)) {
+                String message = "CPU is ARM v7 compatible, so "
                     + RO_PRODUCT_CPU_ABI  + " must be set to " + CpuFeatures.ARMEABI_V7 + " and "
-                    + RO_PRODUCT_CPU_ABI2 + " must be set to " + CpuFeatures.ARMEABI;
-            assertProperty(message, RO_PRODUCT_CPU_ABI, CpuFeatures.ARMEABI_V7);
-            assertProperty(message, RO_PRODUCT_CPU_ABI2, CpuFeatures.ARMEABI);
-            assertEquals(message, CpuFeatures.ARMEABI_V7, Build.CPU_ABI);
-            assertEquals(message, CpuFeatures.ARMEABI, Build.CPU_ABI2);
-        } else {
+                    + RO_PRODUCT_CPU_ABI2 + " must be set to " + CpuFeatures.ARMEABI + " or NULL";
+                assertEquals(message, CpuFeatures.ARMEABI_V7, Build.CPU_ABI);
+                if (cpuAbi2.equals(CpuFeatures.ARMEABI)){
+                    assertEquals(message, cpuAbi2, Build.CPU_ABI2);
+                } else {
+                    assertNoPropertySet(message, RO_PRODUCT_CPU_ABI2);
+                    assertEquals(message, Build.UNKNOWN, Build.CPU_ABI2);
+                }
+            }
+            //if CPU_ABI is x86, then CPU_ABI2 is either of {armeabi, armv7, NULL}
+            else if (cpuAbi.equals(CpuFeatures.X86ABI)) {
+                String message = "CPU is x86 but ARM v7 compatible, so "
+                    + RO_PRODUCT_CPU_ABI  + " must be set to " + CpuFeatures.X86ABI + " and "
+                    + RO_PRODUCT_CPU_ABI2 + " must be set to " + CpuFeatures.ARMEABI + " or "
+                    + CpuFeatures.ARMEABI_V7 + " or NULL";
+                assertEquals(message, CpuFeatures.X86ABI, Build.CPU_ABI);
+                if (cpuAbi2.equals(CpuFeatures.ARMEABI_V7) || cpuAbi2.equals(CpuFeatures.ARMEABI))
+                    assertEquals(message, cpuAbi2, Build.CPU_ABI2);
+                else {
+                    assertNoPropertySet(message, RO_PRODUCT_CPU_ABI2);
+                    assertEquals(message, Build.UNKNOWN, Build.CPU_ABI2);
+                }
+            }
+        }
+        else {
             String message = "CPU is not ARM v7 compatible. "
                     + RO_PRODUCT_CPU_ABI  + " must be set to " + CpuFeatures.ARMEABI + " and "
                     + RO_PRODUCT_CPU_ABI2 + " must not be set.";
@@ -57,7 +80,24 @@
             assertEquals(message, Build.UNKNOWN, Build.CPU_ABI2);
         }
     }
-
+    /**
+     * @param property name passed to getprop
+     */
+    private String getProperty(String property)
+            throws IOException {
+        Process process = new ProcessBuilder("getprop", property).start();
+        Scanner scanner = null;
+        String line = "";
+        try {
+            scanner = new Scanner(process.getInputStream());
+            line = scanner.nextLine();
+        } finally {
+            if (scanner != null) {
+                scanner.close();
+            }
+        }
+        return line;
+    }
     /**
      * @param message shown when the test fails
      * @param property name passed to getprop
diff --git a/tests/tests/os/src/android/os/cts/NoExecutePermissionTest.java b/tests/tests/os/src/android/os/cts/NoExecutePermissionTest.java
index 6256267..43afb53 100644
--- a/tests/tests/os/src/android/os/cts/NoExecutePermissionTest.java
+++ b/tests/tests/os/src/android/os/cts/NoExecutePermissionTest.java
@@ -75,6 +75,10 @@
             // http://code.google.com/p/android/issues/detail?id=17328
             return false;
         }
+        if (CpuFeatures.isMipsCpu()) {
+            // MIPS processors do not have NX support.
+            return false;
+        }
 
         // TODO: handle other processors.  For now, assume those processors
         // have NX support.
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 0a2d56c..933875a 100644
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -196,6 +196,39 @@
         assertFileOwnedByGroup(f, "nfc");
     }
 
+    @MediumTest
+    public void testDevQtaguidSane() throws Exception {
+        File f = new File("/dev/xt_qtaguid");
+        assertTrue(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+
+        assertFileOwnedBy(f, "root");
+        assertFileOwnedByGroup(f, "root");
+    }
+
+    @MediumTest
+    public void testProcQtaguidCtrlSane() throws Exception {
+        File f = new File("/proc/net/xt_qtaguid/ctrl");
+        assertTrue(f.canRead());
+        assertTrue(f.canWrite());
+        assertFalse(f.canExecute());
+
+        assertFileOwnedBy(f, "root");
+        assertFileOwnedByGroup(f, "net_bw_acct");
+    }
+
+    @MediumTest
+    public void testProcQtaguidStatsSane() throws Exception {
+        File f = new File("/proc/net/xt_qtaguid/stats");
+        assertTrue(f.canRead());
+        assertFalse(f.canWrite());
+        assertFalse(f.canExecute());
+
+        assertFileOwnedBy(f, "root");
+        assertFileOwnedByGroup(f, "net_bw_stats");
+    }
+
     /**
      * Assert that a file is owned by a specific owner. This is a noop if the
      * file does not exist.
@@ -538,7 +571,12 @@
     private static final Set<String> SYS_EXCEPTIONS = new HashSet<String>(
             Arrays.asList(
                 "/sys/kernel/debug/tracing/trace_marker",
-                "/sys/fs/selinux"
+                "/sys/fs/selinux/member",
+                "/sys/fs/selinux/user",
+                "/sys/fs/selinux/relabel",
+                "/sys/fs/selinux/create",
+                "/sys/fs/selinux/access",
+                "/sys/fs/selinux/context"
             ));
 
     private static Set <File> getIgnorablesFromPaths(Set <String> paths) {
diff --git a/tests/tests/security/src/android/security/cts/BannedFilesTest.java b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
index b4deed5..ada9aaf 100644
--- a/tests/tests/security/src/android/security/cts/BannedFilesTest.java
+++ b/tests/tests/security/src/android/security/cts/BannedFilesTest.java
@@ -22,6 +22,18 @@
 
 public class BannedFilesTest extends TestCase {
 
+    /**
+     * Detect devices vulnerable to the cmdclient privilege escalation bug.
+     *
+     * References:
+     *
+     * http://vulnfactory.org/blog/2012/02/18/xoom-fe-stupid-bugs-and-more-plagiarism/
+     * http://forum.xda-developers.com/showthread.php?t=1213014
+     */
+    public void testNoCmdClient() {
+        assertNotSetugid("/system/bin/cmdclient");
+    }
+
     public void testNoSyncAgent() {
         assertNotSetugid("/system/bin/sync_agent");
     }
diff --git a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
index 31ac271..9d739d3 100644
--- a/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateFormatTest.java
@@ -24,6 +24,7 @@
 import android.text.format.DateFormat;
 
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
@@ -34,10 +35,11 @@
 
     private Context mContext;
     private ContentResolver mContentResolver;
-    // Date: 12-18-2008 5:30AM
+
+    // Date: 2008-12-18 05:30
     private static final int YEAR_FROM_1900 = 108;
     private static final int YEAR = 2008;
-    private static final int MONTH = 11;
+    private static final int MONTH = Calendar.DECEMBER; // java.util.Calendar months are 0-based.
     private static final int DAY = 18;
     private static final int HOUR = 5;
     private static final int MINUTE = 30;
@@ -70,13 +72,51 @@
     }
 
 
-    public void testDateFormat() {
+    public void test_is24HourFormat() {
         Settings.System.putString(mContentResolver, Settings.System.TIME_12_24, "24");
         assertTrue(DateFormat.is24HourFormat(mContext));
         Settings.System.putString(mContentResolver, Settings.System.TIME_12_24, "12");
         assertFalse(DateFormat.is24HourFormat(mContext));
     }
 
+    public void test_format_M() {
+        Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
+        assertEquals("D", DateFormat.format("MMMMM", c));
+        assertEquals("December", DateFormat.format("MMMM", c));
+        assertEquals("Dec", DateFormat.format("MMM", c));
+        assertEquals("12", DateFormat.format("MM", c));
+        assertEquals("12", DateFormat.format("M", c));
+    }
+
+    public void test_format_L() {
+        // TODO: we can't test other locales with this API so we can't test 'L' properly!
+        Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
+        assertEquals("D", DateFormat.format("LLLLL", c));
+        assertEquals("December", DateFormat.format("LLLL", c));
+        assertEquals("Dec", DateFormat.format("LLL", c));
+        assertEquals("12", DateFormat.format("LL", c));
+        assertEquals("12", DateFormat.format("L", c));
+    }
+
+    public void test_format_E() {
+        Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
+        assertEquals("T", DateFormat.format("EEEEE", c));
+        assertEquals("Thursday", DateFormat.format("EEEE", c));
+        assertEquals("Thu", DateFormat.format("EEE", c));
+        assertEquals("Thu", DateFormat.format("EE", c));
+        assertEquals("Thu", DateFormat.format("E", c));
+    }
+
+    public void test_format_c() {
+        // TODO: we can't test other locales with this API, so we can't test 'c' properly!
+        Calendar c = new GregorianCalendar(2008, Calendar.DECEMBER, 18);
+        assertEquals("T", DateFormat.format("ccccc", c));
+        assertEquals("Thursday", DateFormat.format("cccc", c));
+        assertEquals("Thu", DateFormat.format("ccc", c));
+        assertEquals("Thu", DateFormat.format("cc", c));
+        assertEquals("Thu", DateFormat.format("c", c));
+    }
+
     @SuppressWarnings("deprecation")
     public void testFormatMethods() throws ParseException {
         if (!mDefaultLocale.equals(Locale.US)) {
@@ -129,22 +169,68 @@
 
         calendar.setTimeInMillis(((long) Integer.MIN_VALUE + Integer.MIN_VALUE) * 1000L);
         assertEquals("Sun Nov 24 17:31:44 GMT+00:00 1833",
-                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+                DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar));
 
         calendar.setTimeInMillis(Integer.MIN_VALUE * 1000L);
         assertEquals("Fri Dec 13 20:45:52 GMT+00:00 1901",
-                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+                DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar));
 
         calendar.setTimeInMillis(0L);
         assertEquals("Thu Jan 01 00:00:00 GMT+00:00 1970",
-                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+                DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar));
 
         calendar.setTimeInMillis(Integer.MAX_VALUE * 1000L);
         assertEquals("Tue Jan 19 03:14:07 GMT+00:00 2038",
-                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+                DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar));
 
         calendar.setTimeInMillis((2L + Integer.MAX_VALUE + Integer.MAX_VALUE) * 1000L);
         assertEquals("Sun Feb 07 06:28:16 GMT+00:00 2106",
-                DateFormat.format("EEE MMM dd kk:mm:ss zzz yyyy", calendar));
+                DateFormat.format("EEE MMM dd HH:mm:ss zzz yyyy", calendar));
+    }
+
+    private static void checkFormat(String expected, String pattern, int hour) {
+        TimeZone utc = TimeZone.getTimeZone("UTC");
+
+        Calendar c = new GregorianCalendar(utc);
+        c.set(2013, Calendar.JANUARY, 1, hour, 00);
+
+        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+        sdf.setTimeZone(utc);
+
+        if (pattern.equals("k") && (hour == 0 || hour == 24)) {
+          // http://b/8359981: 'k' has always been broken on Android, and we keep it broken
+          // for compatibility. Maybe one day we'll be able to fix this...
+          assertEquals("0", DateFormat.format(pattern, c));
+        } else {
+          assertEquals(expected, DateFormat.format(pattern, c));
+        }
+        assertEquals(expected, sdf.format(c.getTime()));
+    }
+
+    public void test_bug_8359981() {
+        checkFormat("24", "k", 00);
+        checkFormat( "0", "K", 00);
+        checkFormat("12", "h", 00);
+        checkFormat( "0", "H", 00);
+
+        checkFormat( "1", "k", 01);
+        checkFormat( "1", "K", 01);
+        checkFormat( "1", "h", 01);
+        checkFormat( "1", "H", 01);
+
+        checkFormat("12", "k", 12);
+        checkFormat( "0", "K", 12);
+        checkFormat("12", "h", 12);
+        checkFormat("12", "H", 12);
+
+        checkFormat("13", "k", 13);
+        checkFormat( "1", "K", 13);
+        checkFormat( "1", "h", 13);
+        checkFormat("13", "H", 13);
+
+        checkFormat("24", "k", 24);
+        checkFormat( "0", "K", 24);
+        checkFormat("12", "h", 24);
+        checkFormat( "0", "H", 24);
     }
 }
diff --git a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
index 420af25..52f0d3f 100644
--- a/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
+++ b/tests/tests/text/src/android/text/format/cts/DateUtilsTest.java
@@ -28,10 +28,6 @@
 
 public class DateUtilsTest extends AndroidTestCase {
 
-    private static final long MIN_DURATION = 1000;
-    private static final long MINUTE_DURATION = 42 * 60 * 1000;
-    private static final long HOUR_DURATION = 2 * 60 * 60 * 1000;
-    private static final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
     private long mBaseTime;
     private Context mContext;
 
@@ -87,36 +83,83 @@
         assertEquals("PM", DateUtils.getAMPMString(Calendar.PM));
     }
 
-
-    public void testGetSpanString() {
+    public void test_getRelativeTimeSpanString() {
         if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
             return;
         }
+
+        final long ONE_SECOND_IN_MS = 1000;
         assertEquals("0 minutes ago",
-                DateUtils.getRelativeTimeSpanString(mBaseTime - MIN_DURATION).toString());
+                     DateUtils.getRelativeTimeSpanString(mBaseTime - ONE_SECOND_IN_MS));
         assertEquals("in 0 minutes",
-                DateUtils.getRelativeTimeSpanString(mBaseTime + MIN_DURATION).toString());
+                     DateUtils.getRelativeTimeSpanString(mBaseTime + ONE_SECOND_IN_MS));
 
-        assertEquals("42 minutes ago", DateUtils.getRelativeTimeSpanString(
-                mBaseTime - MINUTE_DURATION, mBaseTime, DateUtils.MINUTE_IN_MILLIS).toString());
-        assertEquals("in 42 minutes", DateUtils.getRelativeTimeSpanString(
-                mBaseTime + MINUTE_DURATION, mBaseTime, DateUtils.MINUTE_IN_MILLIS).toString());
+        final long ONE_MINUTE_IN_MS = 60 * ONE_SECOND_IN_MS;
+        assertEquals("1 minute ago",
+                     DateUtils.getRelativeTimeSpanString(0, ONE_MINUTE_IN_MS, DateUtils.MINUTE_IN_MILLIS));
+        assertEquals("in 1 minute",
+                     DateUtils.getRelativeTimeSpanString(ONE_MINUTE_IN_MS, 0, DateUtils.MINUTE_IN_MILLIS));
 
-        assertEquals("2 hours ago", DateUtils.getRelativeTimeSpanString(mBaseTime - HOUR_DURATION,
-                mBaseTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_NUMERIC_DATE).toString());
-        assertEquals("in 2 hours", DateUtils.getRelativeTimeSpanString(mBaseTime + HOUR_DURATION,
-                mBaseTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_NUMERIC_DATE).toString());
-        assertEquals("in 42 mins", DateUtils.getRelativeTimeSpanString(mBaseTime + MINUTE_DURATION,
+        assertEquals("42 minutes ago",
+                     DateUtils.getRelativeTimeSpanString(mBaseTime - (42 * ONE_MINUTE_IN_MS),
+                                                         mBaseTime, DateUtils.MINUTE_IN_MILLIS));
+        assertEquals("in 42 minutes",
+                     DateUtils.getRelativeTimeSpanString(mBaseTime + (42 * ONE_MINUTE_IN_MS),
+                                                         mBaseTime, DateUtils.MINUTE_IN_MILLIS));
+
+        final long ONE_HOUR_IN_MS = 60 * 60 * 1000;
+        final long TWO_HOURS_IN_MS = 2 * ONE_HOUR_IN_MS;
+        assertEquals("2 hours ago", DateUtils.getRelativeTimeSpanString(mBaseTime - TWO_HOURS_IN_MS,
+                mBaseTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_NUMERIC_DATE));
+        assertEquals("in 2 hours", DateUtils.getRelativeTimeSpanString(mBaseTime + TWO_HOURS_IN_MS,
+                mBaseTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_NUMERIC_DATE));
+
+        assertEquals("in 42 mins", DateUtils.getRelativeTimeSpanString(mBaseTime + (42 * ONE_MINUTE_IN_MS),
                 mBaseTime, DateUtils.MINUTE_IN_MILLIS,
-                DateUtils.FORMAT_ABBREV_RELATIVE).toString());
+                DateUtils.FORMAT_ABBREV_RELATIVE));
 
+        final long ONE_DAY_IN_MS = 24 * ONE_HOUR_IN_MS;
+        assertEquals("Tomorrow",
+                     DateUtils.getRelativeTimeSpanString(ONE_DAY_IN_MS, 0, DateUtils.DAY_IN_MILLIS, 0));
+        assertEquals("in 2 days",
+                     DateUtils.getRelativeTimeSpanString(2 * ONE_DAY_IN_MS, 0, DateUtils.DAY_IN_MILLIS, 0));
+        assertEquals("Yesterday",
+                     DateUtils.getRelativeTimeSpanString(0, ONE_DAY_IN_MS, DateUtils.DAY_IN_MILLIS, 0));
+        assertEquals("2 days ago",
+                     DateUtils.getRelativeTimeSpanString(0, 2 * ONE_DAY_IN_MS, DateUtils.DAY_IN_MILLIS, 0));
+
+        final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
+        assertNotNull(DateUtils.getRelativeTimeSpanString(mContext, mBaseTime - DAY_DURATION, true));
+        assertNotNull(DateUtils.getRelativeTimeSpanString(mContext, mBaseTime - DAY_DURATION));
+    }
+
+    public void test_getRelativeDateTimeString() {
+        final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
         assertNotNull(DateUtils.getRelativeDateTimeString(mContext,
-                mBaseTime - DAY_DURATION, DateUtils.MINUTE_IN_MILLIS, DateUtils.DAY_IN_MILLIS,
-                DateUtils.FORMAT_NUMERIC_DATE).toString());
-        assertNotNull(DateUtils.getRelativeTimeSpanString(mContext,
-                mBaseTime - DAY_DURATION, true).toString());
-        assertNotNull(DateUtils.getRelativeTimeSpanString(mContext,
-                mBaseTime - DAY_DURATION).toString());
+                                                          mBaseTime - DAY_DURATION,
+                                                          DateUtils.MINUTE_IN_MILLIS,
+                                                          DateUtils.DAY_IN_MILLIS,
+                                                          DateUtils.FORMAT_NUMERIC_DATE));
+    }
+
+    public void test_formatElapsedTime() {
+        if (!LocaleUtils.isCurrentLocale(mContext, Locale.US)) {
+            return;
+        }
+
+        long MINUTES = 60;
+        long HOURS = 60 * MINUTES;
+        test_formatElapsedTime("02:01", 2 * MINUTES + 1);
+        test_formatElapsedTime("3:02:01", 3 * HOURS + 2 * MINUTES + 1);
+        // http://code.google.com/p/android/issues/detail?id=41401
+        test_formatElapsedTime("123:02:01", 123 * HOURS + 2 * MINUTES + 1);
+    }
+
+    private void test_formatElapsedTime(String expected, long elapsedTime) {
+        assertEquals(expected, DateUtils.formatElapsedTime(elapsedTime));
+        StringBuilder sb = new StringBuilder();
+        assertEquals(expected, DateUtils.formatElapsedTime(sb, elapsedTime));
+        assertEquals(expected, sb.toString());
     }
 
     @SuppressWarnings("deprecation")
@@ -125,13 +168,6 @@
             return;
         }
 
-        long elapsedTime = 2 * 60 * 60;
-        String expected = "2:00:00";
-        assertEquals(expected, DateUtils.formatElapsedTime(elapsedTime));
-        StringBuilder sb = new StringBuilder();
-        assertEquals(expected, DateUtils.formatElapsedTime(sb, elapsedTime));
-        assertEquals(expected, sb.toString());
-
         Date date = new Date(109, 0, 19, 3, 30, 15);
         long fixedTime = date.getTime();
 
@@ -139,28 +175,30 @@
         Date dateWithCurrentYear = new Date(currentYear - 1900, 0, 19, 3, 30, 15);
         long timeWithCurrentYear = dateWithCurrentYear.getTime();
 
+        final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000;
         assertEquals("Saturday, January 24, 2009", DateUtils.formatSameDayTime(
                 fixedTime + DAY_DURATION, fixedTime, java.text.DateFormat.FULL,
-                java.text.DateFormat.FULL).toString());
+                java.text.DateFormat.FULL));
         assertEquals("Jan 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.DEFAULT, java.text.DateFormat.FULL).toString());
+                fixedTime, java.text.DateFormat.DEFAULT, java.text.DateFormat.FULL));
         assertEquals("January 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.LONG, java.text.DateFormat.FULL).toString());
+                fixedTime, java.text.DateFormat.LONG, java.text.DateFormat.FULL));
         assertEquals("Jan 24, 2009", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.MEDIUM, java.text.DateFormat.FULL).toString());
+                fixedTime, java.text.DateFormat.MEDIUM, java.text.DateFormat.FULL));
         assertEquals("1/24/09", DateUtils.formatSameDayTime(fixedTime + DAY_DURATION,
-                fixedTime, java.text.DateFormat.SHORT, java.text.DateFormat.FULL).toString());
+                fixedTime, java.text.DateFormat.SHORT, java.text.DateFormat.FULL));
 
+        final long HOUR_DURATION = 2 * 60 * 60 * 1000;
         assertEquals("5:30:15 AM GMT", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.FULL).toString());
+                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.FULL));
         assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.DEFAULT).toString());
+                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.DEFAULT));
         assertEquals("5:30:15 AM GMT", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.LONG).toString());
+                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.LONG));
         assertEquals("5:30:15 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.MEDIUM).toString());
+                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.MEDIUM));
         assertEquals("5:30 AM", DateUtils.formatSameDayTime(fixedTime + HOUR_DURATION,
-                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.SHORT).toString());
+                fixedTime, java.text.DateFormat.FULL, java.text.DateFormat.SHORT));
 
         long noonDuration = (8 * 60 + 30) * 60 * 1000 - 15 * 1000;
         long midnightDuration = (3 * 60 + 30) * 60 * 1000 + 15 * 1000;
@@ -217,16 +255,24 @@
     }
 
     public void testIsToday() {
+        final long ONE_DAY_IN_MS = 24 * 60 * 60 * 1000;
         assertTrue(DateUtils.isToday(mBaseTime));
-        assertFalse(DateUtils.isToday(mBaseTime - DAY_DURATION));
+        assertFalse(DateUtils.isToday(mBaseTime - ONE_DAY_IN_MS));
     }
 
     /**
-     * DateUtils is broken beyond Integer.MAX_VALUE seconds of 1970.
+     * DateUtils used to use Time rather than Calendar, which is broken
+     * because Time uses a 32-bit time_t rather than Calendar's 64-bit Java long.
      * http://code.google.com/p/android/issues/detail?id=13050
      */
     public void test2038() {
         assertEquals("00:00, Thursday, January 1, 1970", formatFull(0L));
+        assertEquals("17:31, Sunday, November 24, 1833",
+                     formatFull(((long) Integer.MIN_VALUE + Integer.MIN_VALUE) * 1000L));
+        assertEquals("20:45, Friday, December 13, 1901", formatFull(Integer.MIN_VALUE * 1000L));
+        assertEquals("03:14, Tuesday, January 19, 2038", formatFull(Integer.MAX_VALUE * 1000L));
+        assertEquals("06:28, Sunday, February 7, 2106",
+                     formatFull((2L + Integer.MAX_VALUE + Integer.MAX_VALUE) * 1000L));
     }
 
     private String formatFull(long millis) {
@@ -238,4 +284,17 @@
         DateUtils.formatDateRange(null, formatter, millis, millis, flags, "UTC");
         return formatter.toString();
     }
+
+    public void test_bug_7548161() {
+        long now = System.currentTimeMillis();
+        long today = now;
+        long tomorrow = now + DateUtils.DAY_IN_MILLIS;
+        long yesterday = now - DateUtils.DAY_IN_MILLIS;
+        assertEquals("Tomorrow", DateUtils.getRelativeTimeSpanString(tomorrow, now,
+                                                                     DateUtils.DAY_IN_MILLIS, 0));
+        assertEquals("Yesterday", DateUtils.getRelativeTimeSpanString(yesterday, now,
+                                                                      DateUtils.DAY_IN_MILLIS, 0));
+        assertEquals("Today", DateUtils.getRelativeTimeSpanString(today, now,
+                                                                  DateUtils.DAY_IN_MILLIS, 0));
+    }
 }
diff --git a/tests/tests/webkit/src/android/webkit/cts/MimeTypeMapTest.java b/tests/tests/webkit/src/android/webkit/cts/MimeTypeMapTest.java
index 7213184..6c0ff78 100644
--- a/tests/tests/webkit/src/android/webkit/cts/MimeTypeMapTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/MimeTypeMapTest.java
@@ -75,6 +75,7 @@
     }
 
     public void testGetExtensionFromMimeType() {
+        assertEquals("mp3", mMimeTypeMap.getExtensionFromMimeType("audio/mpeg"));
         assertEquals("png", mMimeTypeMap.getExtensionFromMimeType("image/png"));
         assertEquals("zip", mMimeTypeMap.getExtensionFromMimeType("application/zip"));
 
diff --git a/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java b/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
index e583dce..5426ae9 100644
--- a/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
+++ b/tests/tests/widget/src/android/widget/cts/HeaderViewListAdapterTest.java
@@ -81,6 +81,21 @@
         HeaderViewFullAdapter fullAdapter = new HeaderViewFullAdapter();
         headerViewListAdapter = new HeaderViewListAdapter(null, null, fullAdapter);
         assertFalse(headerViewListAdapter.isEmpty());
+
+        ListView lv = new ListView(getContext());
+        ArrayList<ListView.FixedViewInfo> header = new ArrayList<ListView.FixedViewInfo>(4);
+        header.add(lv.new FixedViewInfo());
+        headerViewListAdapter = new HeaderViewListAdapter(header, null, null);
+        assertEquals(1, headerViewListAdapter.getHeadersCount());
+        assertFalse(headerViewListAdapter.isEmpty());
+
+        lv = new ListView(getContext());
+        ArrayList<ListView.FixedViewInfo> footer = new ArrayList<ListView.FixedViewInfo>(4);
+        footer.add(lv.new FixedViewInfo());
+        headerViewListAdapter = new HeaderViewListAdapter(null, footer, null);
+        assertEquals(1, headerViewListAdapter.getFootersCount());
+        assertFalse(headerViewListAdapter.isEmpty());
+
     }
 
     public void testRemoveHeader() {
diff --git a/tests/tests/widget/src/android/widget/cts/ToastTest.java b/tests/tests/widget/src/android/widget/cts/ToastTest.java
index 9586731..9c7846b 100644
--- a/tests/tests/widget/src/android/widget/cts/ToastTest.java
+++ b/tests/tests/widget/src/android/widget/cts/ToastTest.java
@@ -28,6 +28,7 @@
 import android.test.UiThreadTest;
 import android.view.Gravity;
 import android.view.View;
+import android.view.ViewTreeObserver;
 import android.view.WindowManager;
 import android.widget.ImageView;
 import android.widget.Toast;
@@ -39,6 +40,8 @@
     private Toast mToast;
     private Activity mActivity;
     private Instrumentation mInstrumentation;
+    private boolean mLayoutDone;
+    private ViewTreeObserver.OnGlobalLayoutListener mLayoutListener;
 
     public ToastTest() {
         super("com.android.cts.stub", StubActivity.class);
@@ -51,6 +54,12 @@
         mActivity = getActivity();
         mInstrumentation = getInstrumentation();
         mToast = new Toast(mActivity);
+        mLayoutDone = false;
+        mLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
+            public void onGlobalLayout() {
+                mLayoutDone = true;
+            }
+        };
     }
 
     public void testConstructor() {
@@ -89,6 +98,21 @@
         assertNull(view.getParent());
     }
 
+    private void registerLayoutListener(final View view) {
+        mLayoutDone = false;
+        view.getViewTreeObserver().addOnGlobalLayoutListener(mLayoutListener);
+    }
+
+    private void assertLayoutDone(final View view) {
+        new PollingCheck(TIME_OUT) {
+            @Override
+            protected boolean check() {
+                return mLayoutDone;
+            }
+        }.run();
+        view.getViewTreeObserver().removeOnGlobalLayoutListener(mLayoutListener);
+    }
+
     public void testShow() {
         mActivity.runOnUiThread(new Runnable() {
             public void run() {
@@ -173,7 +197,6 @@
         assertSame(imageView, mToast.getView());
         assertShowAndHide(imageView);
     }
-
     public void testAccessDuration() {
         long start = SystemClock.uptimeMillis();
         mActivity.runOnUiThread(new Runnable() {
@@ -222,6 +245,7 @@
             public void run() {
                 mToast.setMargin(horizontal1, vertical1);
                 mToast.show();
+                registerLayoutListener(mToast.getView());
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -232,6 +256,7 @@
         WindowManager.LayoutParams params1 = (WindowManager.LayoutParams) view.getLayoutParams();
         assertEquals(horizontal1, params1.horizontalMargin);
         assertEquals(vertical1, params1.verticalMargin);
+        assertLayoutDone(view);
         int[] xy1 = new int[2];
         view.getLocationOnScreen(xy1);
         assertShowAndHide(view);
@@ -242,6 +267,7 @@
             public void run() {
                 mToast.setMargin(horizontal2, vertical2);
                 mToast.show();
+                registerLayoutListener(mToast.getView());
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -253,6 +279,7 @@
         assertEquals(horizontal2, params2.horizontalMargin);
         assertEquals(vertical2, params2.verticalMargin);
 
+        assertLayoutDone(view);
         int[] xy2 = new int[2];
         view.getLocationOnScreen(xy2);
         assertShowAndHide(view);
@@ -267,6 +294,7 @@
                 mToast = Toast.makeText(mActivity, TEST_TOAST_TEXT, Toast.LENGTH_SHORT);
                 mToast.setGravity(Gravity.CENTER, 0, 0);
                 mToast.show();
+                registerLayoutListener(mToast.getView());
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -275,6 +303,7 @@
         assertEquals(Gravity.CENTER, mToast.getGravity());
         assertEquals(0, mToast.getXOffset());
         assertEquals(0, mToast.getYOffset());
+        assertLayoutDone(view);
         int[] centerXY = new int[2];
         view.getLocationOnScreen(centerXY);
         assertShowAndHide(view);
@@ -283,6 +312,7 @@
             public void run() {
                 mToast.setGravity(Gravity.BOTTOM, 0, 0);
                 mToast.show();
+                registerLayoutListener(mToast.getView());
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -291,6 +321,7 @@
         assertEquals(Gravity.BOTTOM, mToast.getGravity());
         assertEquals(0, mToast.getXOffset());
         assertEquals(0, mToast.getYOffset());
+        assertLayoutDone(view);
         int[] bottomXY = new int[2];
         view.getLocationOnScreen(bottomXY);
         assertShowAndHide(view);
@@ -306,6 +337,7 @@
             public void run() {
                 mToast.setGravity(Gravity.BOTTOM, xOffset, yOffset);
                 mToast.show();
+                registerLayoutListener(mToast.getView());
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -314,6 +346,7 @@
         assertEquals(Gravity.BOTTOM, mToast.getGravity());
         assertEquals(xOffset, mToast.getXOffset());
         assertEquals(yOffset, mToast.getYOffset());
+        assertLayoutDone(view);
         int[] bottomOffsetXY = new int[2];
         view.getLocationOnScreen(bottomOffsetXY);
         assertShowAndHide(view);
diff --git a/tests/uiautomator/test-apps/Android.mk b/tests/uiautomator/test-apps/Android.mk
deleted file mode 100644
index e790e1e..0000000
--- a/tests/uiautomator/test-apps/Android.mk
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (C) 2012 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.
-
-include $(call all-subdir-makefiles)
diff --git a/tools/cts-java-scanner/src/com/android/cts/javascanner/DocletRunner.java b/tools/cts-java-scanner/src/com/android/cts/javascanner/DocletRunner.java
index 25a4ec1..ba87156 100644
--- a/tools/cts-java-scanner/src/com/android/cts/javascanner/DocletRunner.java
+++ b/tools/cts-java-scanner/src/com/android/cts/javascanner/DocletRunner.java
@@ -72,7 +72,6 @@
         // PTS adds PtsAndroidTestCase
         sourcePath.add("./cts/suite/pts/deviceTests/ptsutil/src");
         sourcePath.add("./cts/libs/util/src");
-        sourcePath.add("./frameworks/testing/uiautomator/library/src");
         sourcePath.add(sourceDir.toString());
         return join(sourcePath, ":");
     }
diff --git a/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/CtsXmlGenerator.java b/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/CtsXmlGenerator.java
index c5b253a..ce4fdd7 100644
--- a/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/CtsXmlGenerator.java
+++ b/tools/cts-xml-generator/src/com/android/cts/xmlgenerator/CtsXmlGenerator.java
@@ -49,8 +49,6 @@
         String instrumentation = null;
         String testType = null;
         String jarPath = null;
-        String appNameSpace = null;
-        String targetNameSpace = null;
 
         for (int i = 0; i < args.length; i++) {
             if ("-p".equals(args[i])) {
@@ -70,17 +68,15 @@
                         "Missing value for expectation store")));
             } else if ("-o".equals(args[i])) {
                 outputPath = getArg(args, ++i, "Missing value for output file");
-            } else if ("-a".equals(args[i])) {
-                appNameSpace =  getArg(args, ++i, "Missing value for app name space");
-            } else if ("-r".equals(args[i])) {
-                targetNameSpace =  getArg(args, ++i, "Missing value for target name space");
             } else {
                 System.err.println("Unsupported flag: " + args[i]);
                 usage(args);
             }
         }
 
+        String appNameSpace = null;
         String runner = null;
+        String targetNameSpace = null;
 
         if (manifestFile != null) {
             Document manifest = DocumentBuilderFactory.newInstance().newDocumentBuilder()
diff --git a/tools/tradefed-host/.classpath b/tools/tradefed-host/.classpath
index 09dd0ce..275ecf9 100644
--- a/tools/tradefed-host/.classpath
+++ b/tools/tradefed-host/.classpath
@@ -3,10 +3,10 @@
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="res"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/ddmlib"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/tradefederation"/>
 	<classpathentry exported="true" kind="var" path="CTS_SRC_ROOT/out/host/common/obj/JAVA_LIBRARIES/ctsdeviceinfolib_intermediates/javalib.jar"/>
 	<classpathentry exported="true" kind="var" path="CTS_SRC_ROOT/out/host/common/obj/JAVA_LIBRARIES/hosttestlib_intermediates/javalib.jar"/>
-	<classpathentry kind="var" path="CTS_SRC_ROOT/prebuilt/common/ddmlib/ddmlib-prebuilt.jar" sourcepath="/SDK_SRC_ROOT"/>
-	<classpathentry kind="var" path="CTS_SRC_ROOT/prebuilt/common/tradefed/tradefed-prebuilt.jar" sourcepath="/TRADEFED_ROOT/tools/tradefederation/src"/>
-	<classpathentry kind="var" path="CTS_SRC_ROOT/out/host/common/obj/JAVA_LIBRARIES/junit_intermediates/javalib.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/tools/tradefed-host/.gitignore b/tools/tradefed-host/.gitignore
deleted file mode 100644
index ba077a4..0000000
--- a/tools/tradefed-host/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/targetprep/SettingsToggler.java b/tools/tradefed-host/src/com/android/cts/tradefed/targetprep/SettingsToggler.java
index 597d866..69d4c8a 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/targetprep/SettingsToggler.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/targetprep/SettingsToggler.java
@@ -51,7 +51,7 @@
                 "content update"
                 + " --uri content://settings/secure"
                 + " --bind value:s:" + value
-                + " --where \"name=\\'" + name + "\\'\"");
+                + " --where \"name='" + name + "'\"");
     }
 
     public static void updateSecureInt(ITestDevice device, String name, int value)
@@ -60,7 +60,7 @@
                 "content update"
                 + " --uri content://settings/secure"
                 + " --bind value:i:" + value
-                + " --where \"name=\\'" + name + "\\'\"");
+                + " --where \"name='" + name + "'\"");
     }
 
     private static void deleteSecure(ITestDevice device, String name)
@@ -68,6 +68,6 @@
         device.executeShellCommand(
                 "content delete"
                 + " --uri content://settings/secure"
-                + " --where \"name=\\'" + name + "\\'\"");
+                + " --where \"name='" + name + "'\"");
     }
 }
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 db11bce..19ee3b7 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
@@ -400,7 +400,8 @@
         // reboot it before running it.
         // Also reboot after package which is know to leave pop-up behind
         final List<String> rebootAfterList = Arrays.asList(
-                "CtsMediaTestCases");
+                "CtsMediaTestCases",
+                "CtsAccessibilityTestCases");
         final List<String> rebootBeforeList = Arrays.asList(
                 "CtsAnimationTestCases",
                 "CtsGraphicsTestCases",
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
index 78a72ba..ffbb930 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageDef.java
@@ -16,7 +16,6 @@
 
 package com.android.cts.tradefed.testtype;
 
-import com.android.ddmlib.Log.LogLevel;
 import com.android.ddmlib.testrunner.TestIdentifier;
 import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.IRemoteTest;
@@ -49,7 +48,6 @@
         "com.android.cts.tradefed.testtype.AccessibilityTestRunner";
     public static final String ACCESSIBILITYSERVICE_TEST =
         "com.android.cts.tradefed.testtype.AccessibilityServiceTestRunner";
-    public static final String UIAUTOMATOR_TEST = "uiAutomator";
 
     private static final String SIGNATURE_TEST_METHOD = "testSignature";
     private static final String SIGNATURE_TEST_CLASS = "android.tests.sigtest.SimpleSignatureTest";
@@ -227,9 +225,6 @@
         } else if (ACCESSIBILITYSERVICE_TEST.equals(mTestType)) {
             AccessibilityServiceTestRunner test = new AccessibilityServiceTestRunner();
             return setInstrumentationTest(test, testCaseDir);
-        } else if (UIAUTOMATOR_TEST.equals(mTestType)) {
-            UiAutomatorJarTest uiautomatorTest = new UiAutomatorJarTest();
-            return setUiAutomatorTest(uiautomatorTest);
         } else if (mIsSignatureTest) {
             // TODO: hardcode the runner/class/method for now, since current package xml points to
             // specialized instrumentation. Eventually this special case for signatureTest can be
@@ -290,28 +285,6 @@
     }
 
     /**
-     * Populates given {@link UiAutomatorJarTest} with data from the package xml.
-     *
-     * @param uiautomatorTest
-     * @return the populated {@link UiAutomatorJarTest} or <code>null</code>
-     */
-    private IRemoteTest setUiAutomatorTest(UiAutomatorJarTest uiautomatorTest) {
-        uiautomatorTest.setInstallArtifacts(getJarPath());
-        if (mClassName != null) {
-            if (mMethodName != null) {
-                CLog.logAndDisplay(LogLevel.WARN, "ui automator tests don't currently support" +
-                        "running  individual methods");
-            }
-            uiautomatorTest.addClassName(mClassName);
-        } else {
-            uiautomatorTest.addClassNames(mTestClasses);
-        }
-        uiautomatorTest.setRunName(getUri());
-        uiautomatorTest.setCaptureLogs(false);
-        return uiautomatorTest;
-    }
-
-    /**
      * Filter the tests to run based on list of excluded tests, class and method name.
      *
      * @return the filtered collection of tests
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/UiAutomatorJarTest.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/UiAutomatorJarTest.java
deleted file mode 100644
index 83cc6d6..0000000
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/UiAutomatorJarTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2011 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.cts.tradefed.testtype;
-
-import com.android.cts.tradefed.build.CtsBuildHelper;
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.log.LogUtil.CLog;
-import com.android.tradefed.result.ITestInvocationListener;
-import com.android.tradefed.testtype.IBuildReceiver;
-import com.android.tradefed.testtype.UiAutomatorTest;
-
-import java.io.FileNotFoundException;
-import java.util.Arrays;
-
-import junit.framework.Assert;
-
-/**
- * A {@link UiAutomatorTest} that will install a uiautomator jar before test
- * execution, and uninstall on execution completion.
- */
-public class UiAutomatorJarTest extends UiAutomatorTest implements IBuildReceiver {
-
-    // TODO: expose this in parent
-    private static final String SHELL_EXE_BASE = "/data/local/tmp/";
-
-    /** the file names of the CTS jar to install */
-    private String mTestJarFileName;
-
-    private CtsBuildHelper mCtsBuild = null;
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void setBuild(IBuildInfo build) {
-        mCtsBuild  = CtsBuildHelper.createBuildHelper(build);
-    }
-
-    /**
-     * Setter for CTS build files needed to perform the test. 
-     *
-     * @param testJarName the file name of the jar containing the uiautomator tests
-     */
-    public void setInstallArtifacts(String testJarName) {
-        mTestJarFileName = testJarName;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void run(final ITestInvocationListener listener)
-            throws DeviceNotAvailableException {
-        Assert.assertNotNull("missing device", getDevice());
-        Assert.assertNotNull("missing build", mCtsBuild);
-        Assert.assertNotNull("missing jar to install", mTestJarFileName);
-
-        installJar();
-
-        super.run(listener);
-
-        uninstallJar();
-    }
-
-    private void installJar() throws DeviceNotAvailableException {
-        CLog.d("Installing %s on %s", mTestJarFileName, getDevice().getSerialNumber());
-        String fullJarPath = String.format("%s%s", SHELL_EXE_BASE, mTestJarFileName);
-        try {
-            boolean result = getDevice().pushFile(mCtsBuild.getTestApp(mTestJarFileName),
-                    fullJarPath);
-            Assert.assertTrue(String.format("Failed to push file to %s", fullJarPath), result);
-            setTestJarPaths(Arrays.asList(fullJarPath));
-        }  catch (FileNotFoundException e) {
-            Assert.fail(String.format("Could not find file %s", mTestJarFileName));
-        }
-    }
-
-    private void uninstallJar() throws DeviceNotAvailableException {
-        CLog.d("Uninstalling %s on %s", mTestJarFileName, getDevice().getSerialNumber());
-        String fullJarPath = String.format("%s%s", SHELL_EXE_BASE, mTestJarFileName);
-        getDevice().executeShellCommand(String.format("rm %s", fullJarPath));
-    }
-}
diff --git a/tools/vm-tests-tf/src/dot/junit/opcodes/invoke_interface/Test_invoke_interface.java b/tools/vm-tests-tf/src/dot/junit/opcodes/invoke_interface/Test_invoke_interface.java
index 377cc58..ae06cda 100644
--- a/tools/vm-tests-tf/src/dot/junit/opcodes/invoke_interface/Test_invoke_interface.java
+++ b/tools/vm-tests-tf/src/dot/junit/opcodes/invoke_interface/Test_invoke_interface.java
@@ -90,6 +90,29 @@
     }
 
     /**
+     * @title dvmInterpFindInterfaceMethod failures were putting NULL Method*s
+     * in the interface cache, leading to a null pointer deference the second
+     * time you made the same bad call, with no exception thrown.
+     * See http://code.google.com/p/android/issues/detail?id=29358 for details.
+     */
+    public void testE4_2() {
+        //@uses dot.junit.opcodes.invoke_interface.d.T_invoke_interface_11
+        //@uses dot.junit.opcodes.invoke_interface.ITest
+        //@uses dot.junit.opcodes.invoke_interface.ITestImpl
+        T_invoke_interface_11 t = new T_invoke_interface_11();
+        try {
+            t.run();
+            fail("expected IncompatibleClassChangeError");
+        } catch (IncompatibleClassChangeError expected) {
+        }
+        try {
+            t.run();
+            fail("expected IncompatibleClassChangeError");
+        } catch (IncompatibleClassChangeError expected) {
+        }
+    }
+
+    /**
      * @title Native method can't be linked
      */
     public void testE5() {
diff --git a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
index bd688fe..20429f0 100644
--- a/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
+++ b/tools/vm-tests-tf/src/util/build/BuildDalvikSuite.java
@@ -576,14 +576,6 @@
         }
 
         // find the @title/@constraint in javadoc comment for this method
-        Scanner scanner2;
-        try {
-            // using platform's default charset
-            scanner2 = new Scanner(f);
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException("error while reading to file: " + e.getClass().getName() +
-                    ", msg:" + e.getMessage());
-        }
         // using platform's default charset
         String all = new String(FileUtils.readFile(f));
         // System.out.println("grepping javadoc found for method " + method +
@@ -630,9 +622,6 @@
         if (scanner != null) {
             scanner.close();
         }
-        if (scanner2 != null) {
-            scanner2.close();
-        }
         return md;
     }