am 5d5cfe83: am f5259a20: Merge "Fix VirtualDisplayTest by putting image checking task to an non-UI thread"

* commit '5d5cfe837ba8e986298078815dd30f397b7ce14f':
  Fix VirtualDisplayTest by putting image checking task to an non-UI thread
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index 3b30e0d..ce12fff 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -88,7 +88,6 @@
     CtsGraphicsTestCases \
     CtsGraphics2TestCases \
     CtsHardwareTestCases \
-    CtsHoloTestCases \
     CtsJniTestCases \
     CtsKeystoreTestCases \
     CtsLocationTestCases \
@@ -130,7 +129,6 @@
 cts_host_libraries := \
     CtsAdbTests \
     CtsAppSecurityTests \
-    CtsHoloHostTestCases \
     CtsHostJank \
     CtsHostUi \
     CtsMonkeyTestCases \
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 8f50535..8b8c8b6 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -17,8 +17,8 @@
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
-      android:versionCode="1"
-      android:versionName="4.4_r1.95">
+      android:versionCode="3"
+      android:versionName="4.4_r3">
 
     <!-- Using 10+ for more complete NFC support... -->
     <uses-sdk android:minSdkVersion="12"></uses-sdk>
@@ -27,6 +27,7 @@
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     <uses-permission android:name="android.permission.BLUETOOTH" />
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
+    <uses-permission android:name="android.permission.BODY_SENSORS"/>
     <uses-permission android:name="android.permission.CAMERA" />
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
@@ -577,6 +578,18 @@
                        android:value="android.hardware.sensor.gyroscope"/>
         </activity>
 
+        <activity android:name=".sensors.HeartRateMonitorTestActivity"
+                  android:label="@string/snsr_heartrate_test"
+                  android:screenOrientation="nosensor">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.cts.intent.category.MANUAL_TEST" />
+            </intent-filter>
+            <meta-data android:name="test_category" android:value="@string/test_category_sensors" />
+            <meta-data android:name="test_required_features"
+                       android:value="android.hardware.sensor.heartrate" />
+        </activity>
+
         <!-- Disable the test until calibration routine is verified -->
         <!--activity android:name=".sensors.MagneticFieldMeasurementTestActivity"
                   android:label="@string/snsr_mag_m_test"
diff --git a/apps/CtsVerifier/res/layout/ca_boot_notify.xml b/apps/CtsVerifier/res/layout/ca_boot_notify.xml
index 29fa549..e9309d4 100644
--- a/apps/CtsVerifier/res/layout/ca_boot_notify.xml
+++ b/apps/CtsVerifier/res/layout/ca_boot_notify.xml
@@ -19,47 +19,51 @@
   android:orientation="vertical" android:layout_width="fill_parent"
   android:layout_height="fill_parent">
 
+  <ScrollView
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_alignParentTop="true" >
 
-  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:orientation="vertical"
-    android:layout_width="fill_parent"
-    android:layout_height="wrap_content">
+    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+      android:orientation="vertical"
+      android:layout_width="fill_parent"
+      android:layout_height="wrap_content">
 
-    <TextView
-        android:id="@+id/check_cert_desc"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_check_cert_installed"/>
+      <TextView
+          android:id="@+id/check_cert_desc"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_check_cert_installed"/>
 
-    <Button android:id="@+id/check_creds"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_check_creds" />
+      <Button android:id="@+id/check_creds"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_check_creds" />
 
-     <TextView
-        android:id="@+id/need_to_install_cert"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_if_not_installed"/>
+      <TextView
+          android:id="@+id/need_to_install_cert"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_if_not_installed"/>
 
-    <Button android:id="@+id/install"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_install_cert" />
+      <Button android:id="@+id/install"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_install_cert" />
 
-     <TextView
-        android:id="@+id/reboot"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_reboot_desc"/>
+      <TextView
+          android:id="@+id/reboot"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_reboot_desc"/>
 
-    <TextView
-        android:id="@+id/after_reboot"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:text="@string/caboot_after_boot"/>
-  </LinearLayout>
+      <TextView
+          android:id="@+id/after_reboot"
+          android:layout_width="wrap_content"
+          android:layout_height="wrap_content"
+          android:text="@string/caboot_after_boot"/>
 
-  <include layout="@layout/pass_fail_buttons" />
-
+      <include layout="@layout/pass_fail_buttons" />
+    </LinearLayout>
+  </ScrollView>
 </LinearLayout>
diff --git a/apps/CtsVerifier/res/layout/intent_driven_test.xml b/apps/CtsVerifier/res/layout/intent_driven_test.xml
index 225ad01..00c1cf6 100644
--- a/apps/CtsVerifier/res/layout/intent_driven_test.xml
+++ b/apps/CtsVerifier/res/layout/intent_driven_test.xml
@@ -1,27 +1,30 @@
 <?xml version="1.0" encoding="utf-8"?>
 
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
-          android:layout_width="match_parent"
-          android:layout_height="match_parent"
-          android:orientation="vertical" >
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
 
-  <LinearLayout
+  <ScrollView
       android:layout_width="match_parent"
-      android:layout_height="wrap_content" >
+      android:layout_height="0dp"
+      android:layout_weight="1">
     <TextView android:id="@+id/info"
-              android:layout_width="match_parent"
-              android:layout_height="wrap_content"
-              android:textSize="18sp"
-              android:padding="5dp"
-              android:text="@string/dc_start_alarm_test_info" />
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="18sp"
+        android:padding="5dp"
+        android:text="@string/dc_start_alarm_test_info"/>
+  </ScrollView>
 
-    <LinearLayout android:id="@+id/buttons"
-                  android:orientation="horizontal"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:layout_alignParentTop="true"/>
+  <LinearLayout android:id="@+id/buttons"
+      android:orientation="horizontal"
+      android:layout_width="wrap_content"
+      android:layout_height="wrap_content"/>
 
-    <include layout="@layout/pass_fail_buttons"/>
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+      <include layout="@layout/pass_fail_buttons"/>
   </LinearLayout>
-
-</ScrollView>
+</LinearLayout>
diff --git a/apps/CtsVerifier/res/layout/snsr_hrm.xml b/apps/CtsVerifier/res/layout/snsr_hrm.xml
new file mode 100644
index 0000000..506ba9f
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/snsr_hrm.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2014 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
+  -->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent">
+
+    <include android:id="@+id/pass_fail_buttons"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_alignParentBottom="true"
+            layout="@layout/pass_fail_buttons" />
+
+    <TextView android:id="@+id/sensor_value"
+              android:background="@drawable/gray_bubble"
+              android:drawablePadding="10dip"
+              android:layout_above="@+id/sensor_accuracy_value"
+              android:layout_centerInParent="true"
+              android:layout_width="wrap_content"
+              android:layout_height="wrap_content"
+              android:layout_marginBottom="10dip"
+              android:paddingLeft="10dip"
+              android:paddingRight="10dip"
+              android:paddingTop="5dip"
+              android:paddingBottom="5dip"
+              android:textSize="28dip"
+        />
+
+    <TextView android:id="@+id/sensor_accuracy_value"
+              android:background="@drawable/gray_bubble"
+              android:drawablePadding="10dip"
+              android:layout_above="@+id/pass_fail_buttons"
+              android:layout_centerInParent="true"
+              android:layout_width="wrap_content"
+              android:layout_height="wrap_content"
+              android:layout_marginBottom="10dip"
+              android:paddingLeft="10dip"
+              android:paddingRight="10dip"
+              android:paddingTop="5dip"
+              android:paddingBottom="5dip"
+              android:textSize="28dip"
+        />
+
+</RelativeLayout>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 00ff965..d93649e 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -410,6 +410,12 @@
     <string name="snsr_gyro_test_degrees_message">These values looks like degrees per second. These should be radians per second!</string>
     <string name="snsr_gyro_m_test">Gyroscope Measurement Test</string>
 
+    <!-- Heart Rate -->
+    <string name="snsr_heartrate_test">Heart Rate Test</string>
+    <string name="snsr_heartrate_test_info">This test verifies that the heart rate monitor is working properly.\n\nWait for at least 1 minute before verifying.\n\nVerify that the resting heart rate is between 0 and 100.</string>
+    <string name="snsr_heartrate_test_no_heartrate_title">No heart rate monitor?</string>
+    <string name="snsr_heartrate_test_no_heartrate_message">It doesn\'t seem like you have a heart rate monitor, so you don\'t need to run this test.</string>
+
     <!-- Magnetic Field -->
     <string name="snsr_mag_m_test">Magnetic Field Measurement Tests</string>
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
index e7bf70d..ef80b5d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
@@ -23,8 +23,11 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnCancelListener;
+import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.os.Bundle;
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -86,6 +89,25 @@
     }
 
     public static class Activity extends android.app.Activity implements PassFailActivity {
+        private WakeLock mWakeLock;
+
+        @Override
+        protected void onResume() {
+            super.onResume();
+            if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+                mWakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
+                        .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "PassFailButtons");
+                mWakeLock.acquire();
+            }
+        }
+
+        @Override
+        protected void onPause() {
+            super.onPause();
+            if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+                mWakeLock.release();
+            }
+        }
 
         @Override
         public void setPassFailButtonClickListeners() {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
index 22f1813..b010f79 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/camera/video/CameraVideoActivity.java
@@ -445,6 +445,7 @@
                 CamcorderProfile.QUALITY_LOW,
                 CamcorderProfile.QUALITY_HIGH,
                 CamcorderProfile.QUALITY_QCIF,
+                CamcorderProfile.QUALITY_QVGA,
                 CamcorderProfile.QUALITY_CIF,
                 CamcorderProfile.QUALITY_480P,
                 CamcorderProfile.QUALITY_720P,
@@ -455,6 +456,7 @@
                 "LOW",
                 "HIGH",
                 "QCIF",
+                "QVGA",
                 "CIF",
                 "480P",
                 "720P",
@@ -488,45 +490,25 @@
         }
     }
 
-    private Size findRecordSize() {
+    private Size findRecordSize(int cameraId) {
         int[] possibleQuality = {
+                CamcorderProfile.QUALITY_LOW,
+                CamcorderProfile.QUALITY_HIGH,
                 CamcorderProfile.QUALITY_QCIF,
+                CamcorderProfile.QUALITY_QVGA,
                 CamcorderProfile.QUALITY_CIF,
                 CamcorderProfile.QUALITY_480P,
                 CamcorderProfile.QUALITY_720P,
                 CamcorderProfile.QUALITY_1080P
         };
 
-        Size[] sizes = new Size[] {
-                mCamera.new Size(176, 144),
-                mCamera.new Size(352, 288),
-                mCamera.new Size(720, 480),
-                mCamera.new Size(1280, 720),
-                mCamera.new Size(1920, 1080)
-        };
-
-        Size minSize = mCamera.new Size(Integer.MAX_VALUE, Integer.MAX_VALUE);
-        Size maxSize = mCamera.new Size(0, 0);
-
-        for (int i = 0; i < possibleQuality.length; i++) {
-            if (mVideoSizeIds.contains(possibleQuality[i])) {
-                if (sizes[i].height < minSize.height) {
-                    minSize = sizes[i];
-                }
-                if (sizes[i].height > maxSize.height) {
-                    maxSize = sizes[i];
-                }
-            }
-        }
-
         ArrayList<ResolutionQuality> qualityList = new ArrayList<ResolutionQuality>();
-        qualityList.add(new ResolutionQuality(CamcorderProfile.QUALITY_LOW, minSize.width,
-                minSize.height));
-        qualityList.add(new ResolutionQuality(CamcorderProfile.QUALITY_HIGH, maxSize.width,
-                maxSize.height));
         for (int i = 0; i < possibleQuality.length; i++) {
-            qualityList.add(new ResolutionQuality(possibleQuality[i], sizes[i].width,
-                    sizes[i].height));
+            if (CamcorderProfile.hasProfile(cameraId, possibleQuality[i])) {
+                CamcorderProfile profile = CamcorderProfile.get(cameraId, possibleQuality[i]);
+                qualityList.add(new ResolutionQuality(possibleQuality[i],
+                        profile.videoFrameWidth, profile.videoFrameHeight));
+            }
         }
 
         Size recordSize = null;
@@ -547,7 +529,7 @@
 
     // Match preview size with current recording size mCurrentVideoSizeId
     private Size matchPreviewRecordSize() {
-        Size recordSize = findRecordSize();
+        Size recordSize = findRecordSize(mCurrentCameraId);
 
         Size matchedSize = null;
         // First try to find exact match in size
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
index 6b87261..581121e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/features/FeatureSummaryActivity.java
@@ -188,6 +188,10 @@
             new Feature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR, false),
     };
 
+    public static final Feature[] ALL_KITKAT_WATCH_FEATURES = {
+            new Feature(PackageManager.FEATURE_SENSOR_HEART_RATE, false),
+    };
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -218,6 +222,9 @@
 
         // add features from latest to last so that the latest requirements are put in the set first
         int apiVersion = Build.VERSION.SDK_INT;
+        if (apiVersion >= Build.VERSION_CODES.KITKAT_WATCH) {
+            Collections.addAll(features, ALL_KITKAT_WATCH_FEATURES);
+        }
         if (apiVersion >= Build.VERSION_CODES.KITKAT) {
             Collections.addAll(features, ALL_KITKAT_FEATURES);
         }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java
new file mode 100644
index 0000000..3a48e3c
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/HeartRateMonitorTestActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2014 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.verifier.sensors;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.hardware.Sensor;
+import android.hardware.SensorEvent;
+import android.hardware.SensorEventListener;
+import android.hardware.SensorManager;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.cts.verifier.PassFailButtons;
+import com.android.cts.verifier.R;
+
+/**
+ * CTS Verifier case for verifying correct integration of heart rate monitor.
+ * If a user is wearing a device with an HRM, the value is between <> and <>
+ */
+public class HeartRateMonitorTestActivity extends PassFailButtons.Activity {
+    private SensorManager mSensorManager;
+    private Sensor mSensor;
+    private SensorListener mSensorListener;
+    private AlertDialog mNoHeartRateWarningDialog;
+    private TextView mSensorText;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.snsr_hrm);
+        setInfoResources(R.string.snsr_heartrate_test, R.string.snsr_heartrate_test_info, 0);
+        setPassFailButtonClickListeners();
+
+        mSensorText = (TextView) findViewById(R.id.sensor_value);
+
+        mSensorManager = (SensorManager) getApplicationContext().getSystemService(
+                Context.SENSOR_SERVICE);
+        mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
+        mSensorListener = new SensorListener();
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        if (!mSensorManager.registerListener(mSensorListener, mSensor,
+                SensorManager.SENSOR_DELAY_UI)) {
+            showNoHeartRateWarningDialog();
+            PassFailButtons.setTestResultAndFinish(this, getTestId(), getTestDetails(), true);
+        }
+    }
+
+    @Override
+    protected void onPause() {
+        super.onPause();
+        mSensorManager.unregisterListener(mSensorListener, mSensor);
+    }
+
+    private void showNoHeartRateWarningDialog() {
+        if (mNoHeartRateWarningDialog == null) {
+            mNoHeartRateWarningDialog = new AlertDialog.Builder(this)
+                    .setIcon(android.R.drawable.ic_dialog_alert)
+                    .setTitle(R.string.snsr_heartrate_test_no_heartrate_title)
+                    .setMessage(R.string.snsr_heartrate_test_no_heartrate_message)
+                    .setPositiveButton(android.R.string.ok, null)
+                    .create();
+        }
+        if (!mNoHeartRateWarningDialog.isShowing()) {
+            mNoHeartRateWarningDialog.show();
+        }
+    }
+
+    private class SensorListener implements SensorEventListener {
+        private static final double MIN_HEART_RATE = 40;
+        private static final double MAX_HEART_RATE = 200;
+        @Override
+        public void onSensorChanged(SensorEvent sensorEvent) {
+            float value = sensorEvent.values[0];
+            if (value > MAX_HEART_RATE || value < MIN_HEART_RATE) {
+                updateWidgets(value, sensorEvent.accuracy, R.drawable.fs_error);
+            } else {
+                updateWidgets(value, sensorEvent.accuracy, R.drawable.fs_good);
+            }
+        }
+
+        void updateWidgets(float value, float accuracy, int icon) {
+            TextView sensorText = (TextView) findViewById(R.id.sensor_value);
+            TextView sensorAccuracyText = (TextView) findViewById(R.id.sensor_accuracy_value);
+
+            sensorText.setText(String.format("%+.2f", value));
+            sensorText.setCompoundDrawablesWithIntrinsicBounds(0, 0, icon, 0);
+            sensorAccuracyText.setText(String.format("%+.2f", accuracy));
+        }
+
+        @Override
+        public void onAccuracyChanged(Sensor sensor, int i) {
+        }
+    }
+}
diff --git a/common/Android.mk b/common/Android.mk
new file mode 100644
index 0000000..a8b6af7
--- /dev/null
+++ b/common/Android.mk
@@ -0,0 +1,15 @@
+# Copyright (C) 2014 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/common/device-side/Android.mk b/common/device-side/Android.mk
new file mode 100644
index 0000000..a8b6af7
--- /dev/null
+++ b/common/device-side/Android.mk
@@ -0,0 +1,15 @@
+# Copyright (C) 2014 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/common/device-side/device-setup/Android.mk b/common/device-side/device-setup/Android.mk
new file mode 100644
index 0000000..bc7c504
--- /dev/null
+++ b/common/device-side/device-setup/Android.mk
@@ -0,0 +1,43 @@
+# Copyright (C) 2014 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-setup_v2
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-setup-tests_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java b/common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java
new file mode 100644
index 0000000..7b19b00
--- /dev/null
+++ b/common/device-side/device-setup/src/com/android/compatibility/common/devicesetup/DeviceInfoConstants.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.devicesetup;
+
+/**
+ * Constants for device info attributes to be sent as instrumentation keys.
+ */
+public interface DeviceInfoConstants {
+
+    public static final String BUILD_ABI = "buildAbi";
+    public static final String BUILD_ABI2 = "buildAbi2";
+    public static final String BUILD_BOARD = "buildBoard";
+    public static final String BUILD_BRAND = "buildBrand";
+    public static final String BUILD_DEVICE = "buildDevice";
+    public static final String BUILD_FINGERPRINT = "buildFingerprint";
+    public static final String BUILD_ID = "buildId";
+    public static final String BUILD_MANUFACTURER = "buildManufacturer";
+    public static final String BUILD_MODEL = "buildModel";
+    public static final String BUILD_TAGS = "buildTags";
+    public static final String BUILD_TYPE = "buildType";
+    public static final String BUILD_VERSION = "buildVersion";
+
+    public static final String FEATURES = "features";
+
+    public static final String GRAPHICS_RENDERER = "graphicsRenderer";
+    public static final String GRAPHICS_VENDOR = "graphicsVendor";
+
+    public static final String IMEI = "imei";
+    public static final String IMSI = "imsi";
+
+    public static final String KEYPAD = "keypad";
+
+    public static final String LOCALES = "locales";
+
+    public static final String MULTI_USER = "multiUser";
+
+    public static final String NAVIGATION = "navigation";
+    public static final String NETWORK = "network";
+
+    public static final String OPEN_GL_ES_VERSION = "openGlEsVersion";
+    public static final String OPEN_GL_EXTENSIONS = "openGlExtensions";
+    public static final String OPEN_GL_COMPRESSED_TEXTURE_FORMATS =
+            "openGlCompressedTextureFormats";
+
+    public static final String PARTITIONS = "partitions";
+    public static final String PHONE_NUMBER = "phoneNumber";
+    public static final String PROCESSES = "processes";
+    public static final String PRODUCT_NAME = "productName";
+
+    public static final String RESOLUTION = "resolution";
+
+    public static final String SCREEN_DENSITY = "screenDensity";
+    public static final String SCREEN_DENSITY_BUCKET = "screenDensityBucket";
+    public static final String SCREEN_DENSITY_X = "screenDensityX";
+    public static final String SCREEN_DENSITY_Y = "screenDensityY";
+    public static final String SCREEN_SIZE = "screenSize";
+    public static final String SERIAL_NUMBER = "deviceId";
+    public static final String STORAGE_DEVICES = "storageDevices";
+    public static final String SYS_LIBRARIES = "systemLibraries";
+
+    public static final String TOUCH = "touch";
+
+    public static final String VERSION_RELEASE = "versionRelease";
+    public static final String VERSION_SDK_INT = "versionSdkInt";
+}
diff --git a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl b/common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
similarity index 67%
copy from tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
copy to common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
index af264c9..ee55a66 100644
--- a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
+++ b/common/device-side/device-setup/tests/src/com/android/compatibility/common/devicesetup/DeviceSetupTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,8 +14,12 @@
  * limitations under the License.
  */
 
-package android.security.cts.activity;
+package com.android.compatibility.common.devicesetup;
 
-interface ISecureRandomService {
-    int getRandomBytesAndPid(inout byte[] randomBytes);
+import junit.framework.TestCase;
+
+public class DeviceSetupTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/common/device-side/util/Android.mk b/common/device-side/util/Android.mk
new file mode 100644
index 0000000..c8104bf
--- /dev/null
+++ b/common/device-side/util/Android.mk
@@ -0,0 +1,45 @@
+# Copyright (C) 2014 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_STATIC_JAVA_LIBRARIES := compatibility-common-util-devicesidelib_v2
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-util_v2
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-device-util-tests_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java b/common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java
new file mode 100644
index 0000000..273cdf5
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/DeviceReportLog.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import android.app.Instrumentation;
+import android.os.Bundle;
+import android.util.Log;
+
+import com.android.compatibility.common.util.ReportLog;
+
+/**
+ * Handles adding results to the report for device side tests.
+ *
+ * NOTE: tests MUST call {@link #submit(Instrumentation)} if and only if the test passes in order to
+ * send the results to the runner.
+ */
+public class DeviceReportLog extends ReportLog {
+    private static final String TAG = DeviceReportLog.class.getSimpleName();
+    private static final String RESULT = "RESULT";
+    private static final int INST_STATUS_IN_PROGRESS = 2;
+
+    public void submit(Instrumentation instrumentation) {
+        Log.i(TAG, "submit");
+        Bundle output = new Bundle();
+        output.putSerializable(RESULT, this);
+        instrumentation.sendStatus(INST_STATUS_IN_PROGRESS, output);
+    }
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java b/common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java
new file mode 100644
index 0000000..521dc40
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/EvaluateJsResultPollingCheck.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import android.webkit.ValueCallback;
+
+public class EvaluateJsResultPollingCheck  extends PollingCheck
+        implements ValueCallback<String> {
+    private String mActualResult;
+    private String mExpectedResult;
+
+    public EvaluateJsResultPollingCheck(String expected) {
+        mExpectedResult = expected;
+    }
+
+    @Override
+    public synchronized boolean check() {
+        return mExpectedResult.equals(mActualResult);
+    }
+
+    @Override
+    public synchronized void onReceiveValue(String result) {
+        mActualResult = result;
+    }
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java b/common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java
new file mode 100644
index 0000000..02be372
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/FileCopyHelper.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import android.content.Context;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+/**
+ * FileCopyHelper is used to copy files from resources to the application directory and responsible
+ * for deleting the files.
+ *
+ * @see MediaStore_VideoTest
+ * @see MediaStore_Images_MediaTest
+ * @see MediaStore_Images_ThumbnailsTest
+ */
+public class FileCopyHelper {
+    /** The context. */
+    private Context mContext;
+
+    /** The files added. */
+    private ArrayList<String> mFilesList;
+
+    /**
+     * Instantiates a new file copy helper.
+     *
+     * @param context the context
+     */
+    public FileCopyHelper(Context context) {
+        mContext = context;
+        mFilesList = new ArrayList<String>();
+    }
+
+    /**
+     * Copy the file from the resources with a filename.
+     *
+     * @param resId the res id
+     * @param fileName the file name
+     *
+     * @return the absolute path of the destination file
+     * @throws IOException
+     */
+    public String copy(int resId, String fileName) throws IOException {
+        InputStream source = mContext.getResources().openRawResource(resId);
+        OutputStream target = mContext.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
+        copyFile(source, target);
+        mFilesList.add(fileName);
+        return mContext.getFileStreamPath(fileName).getAbsolutePath();
+    }
+
+    public void copyToExternalStorage(int resId, File path) throws IOException {
+        InputStream source = mContext.getResources().openRawResource(resId);
+        OutputStream target = new FileOutputStream(path);
+        copyFile(source, target);
+    }
+
+    private void copyFile(InputStream source, OutputStream target) throws IOException {
+        try {
+            byte[] buffer = new byte[1024];
+            for (int len = source.read(buffer); len > 0; len = source.read(buffer)) {
+                target.write(buffer, 0, len);
+            }
+        } finally {
+            if (source != null) {
+                source.close();
+            }
+            if (target != null) {
+                target.close();
+            }
+        }
+    }
+
+    /**
+     * Delete all the files copied by the helper.
+     */
+    public void clear(){
+        for (String path : mFilesList) {
+            mContext.deleteFile(path);
+        }
+    }
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java b/common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java
new file mode 100644
index 0000000..a976a92
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/PollingCheck.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import java.util.concurrent.Callable;
+
+import junit.framework.Assert;
+
+public abstract class PollingCheck {
+
+    private static final long TIME_SLICE = 50;
+    private long mTimeoutMs = 3000;
+
+    public PollingCheck() {
+    }
+
+    public PollingCheck(long timeoutMs) {
+        mTimeoutMs = timeoutMs;
+    }
+
+    protected abstract boolean check();
+
+    public void run() {
+        if (check()) {
+            return;
+        }
+
+        long timeoutMs = mTimeoutMs;
+        while (timeoutMs > 0) {
+            try {
+                Thread.sleep(TIME_SLICE);
+            } catch (InterruptedException e) {
+                Assert.fail("unexpected InterruptedException");
+            }
+
+            if (check()) {
+                return;
+            }
+
+            timeoutMs -= TIME_SLICE;
+        }
+
+        Assert.fail("unexpected timeout");
+    }
+
+    public static void check(CharSequence message, long timeoutMs, Callable<Boolean> condition)
+            throws Exception {
+        while (timeoutMs > 0) {
+            if (condition.call()) {
+                return;
+            }
+
+            Thread.sleep(TIME_SLICE);
+            timeoutMs -= TIME_SLICE;
+        }
+
+        Assert.fail(message.toString());
+    }
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/Result.java b/common/device-side/util/src/com/android/compatibility/common/util/Result.java
new file mode 100644
index 0000000..0d8a29a
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/Result.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+/**
+ * Represents the result of a test.
+ */
+public interface Result {
+    public static final int RESULT_OK = 1;
+    public static final int RESULT_FAIL = 2;
+    /**
+     * Sets the test result of this object.
+     *
+     * @param resultCode The test result, either {@code RESULT_OK} or {@code RESULT_FAIL}.
+     */
+    void setResult(int resultCode);
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java b/common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java
new file mode 100644
index 0000000..2ec9bef
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/SystemUtil.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import android.app.ActivityManager;
+import android.app.ActivityManager.MemoryInfo;
+import android.content.Context;
+import android.os.StatFs;
+
+public class SystemUtil {
+    public static long getFreeDiskSize(Context context) {
+        final StatFs statFs = new StatFs(context.getFilesDir().getAbsolutePath());
+        return (long)statFs.getAvailableBlocks() * statFs.getBlockSize();
+    }
+
+    public static long getFreeMemory(Context context) {
+        final MemoryInfo info = new MemoryInfo();
+        ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(info);
+        return info.availMem;
+    }
+
+    public static long getTotalMemory(Context context) {
+        final MemoryInfo info = new MemoryInfo();
+        ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(info);
+        return info.totalMem;
+    }
+}
diff --git a/common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java b/common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java
new file mode 100644
index 0000000..4862323
--- /dev/null
+++ b/common/device-side/util/src/com/android/compatibility/common/util/WatchDog.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import android.util.Log;
+
+import junit.framework.Assert;
+
+/**
+ * Used to fail a test if a function takes more than a certain amount of time.
+ */
+public class WatchDog implements Runnable {
+    private static final String TAG = WatchDog.class.getSimpleName();
+    private Thread mThread;
+    private Semaphore mSemaphore;
+    private volatile boolean mStopRequested;
+    private final long mTimeoutInMilliSecs;
+    private TimeoutCallback mCallback = null;
+
+    public WatchDog(long timeoutInMilliSecs) {
+        mTimeoutInMilliSecs = timeoutInMilliSecs;
+    }
+
+    public WatchDog(long timeoutInMilliSecs, TimeoutCallback callback) {
+        this(timeoutInMilliSecs);
+        mCallback = callback;
+    }
+
+    /** start watch-dog */
+    public void start() {
+        Log.i(TAG, "start");
+        mStopRequested = false;
+        mSemaphore = new Semaphore(0);
+        mThread = new Thread(this);
+        mThread.start();
+    }
+
+    /** stop watch-dog */
+    public void stop() {
+        Log.i(TAG, "stop");
+        if (mThread == null) {
+            return; // already finished
+        }
+        mStopRequested = true;
+        mSemaphore.release();
+        try {
+            mThread.join();
+        } catch (InterruptedException e) {
+            // ignore
+        }
+        mThread = null;
+        mSemaphore = null;
+    }
+
+    /** resets watch-dog, thus prevent it from panic */
+    public void reset() {
+        if (!mStopRequested) { // stop requested, but rendering still on-going
+            mSemaphore.release();
+        }
+    }
+
+    @Override
+    public void run() {
+        while (!mStopRequested) {
+            try {
+                boolean success = mSemaphore.tryAcquire(mTimeoutInMilliSecs, TimeUnit.MILLISECONDS);
+                if (mCallback == null) {
+                    Assert.assertTrue("Watchdog timed-out", success);
+                } else if (!success) {
+                    mCallback.onTimeout();
+                }
+            } catch (InterruptedException e) {
+                // this thread will not be interrupted,
+                // but if it happens, just check the exit condition.
+            }
+        }
+    }
+
+    /**
+     * Called by the Watchdog when it has timed out.
+     */
+    public interface TimeoutCallback {
+
+        public void onTimeout();
+    }
+}
diff --git a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl b/common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
similarity index 74%
rename from tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
rename to common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
index af264c9..a7e81d7 100644
--- a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
+++ b/common/device-side/util/tests/src/com/android/compatibility/common/util/DeviceUtilTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
-package android.security.cts.activity;
+package com.android.compatibility.common.util;
 
-interface ISecureRandomService {
-    int getRandomBytesAndPid(inout byte[] randomBytes);
+import junit.framework.TestCase;
+
+public class DeviceUtilTest extends TestCase {
+
 }
diff --git a/common/host-side/Android.mk b/common/host-side/Android.mk
new file mode 100644
index 0000000..a8b6af7
--- /dev/null
+++ b/common/host-side/Android.mk
@@ -0,0 +1,15 @@
+# Copyright (C) 2014 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/common/host-side/java-scanner/Android.mk b/common/host-side/java-scanner/Android.mk
new file mode 100644
index 0000000..7c101ff
--- /dev/null
+++ b/common/host-side/java-scanner/Android.mk
@@ -0,0 +1,47 @@
+# Copyright (C) 2014 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-common-util-hostsidelib_v2
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_MODULE := compatibility-java-scanner_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-java-scanner_v2 junit
+
+LOCAL_MODULE := compatibility-java-scanner-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/java-scanner/MANIFEST.mf b/common/host-side/java-scanner/MANIFEST.mf
new file mode 100644
index 0000000..975b1ef
--- /dev/null
+++ b/common/host-side/java-scanner/MANIFEST.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.scanner.JavaScanner
+Class-Path: compatibility-common-util-hostsidelib_v2.jar
diff --git a/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java
new file mode 100644
index 0000000..f3f8a49
--- /dev/null
+++ b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScanner.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.scanner;
+
+import com.android.compatibility.common.util.KeyValueArgsParser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Scans a source directory for java tests and outputs a list of test classes and methods.
+ */
+public class JavaScanner {
+
+    static final String[] SOURCE_PATHS = {
+        "./frameworks/base/core/java",
+        "./frameworks/base/test-runner/src",
+        "./external/junit/src",
+        "./development/tools/hosttestlib/src",
+        "./libcore/dalvik/src/main/java",
+        "./common/device-side/util/src",
+        "./common/host-side/tradefed/src",
+        "./common/util/src"
+    };
+    static final String[] CLASS_PATHS = {
+        "./prebuilts/misc/common/tradefed/tradefed-prebuilt.java",
+        "./prebuilts/misc/common/ub-uiautomator/ub-uiautomator.java"
+    };
+    private final File mSourceDir;
+    private final File mDocletDir;
+
+    /**
+     * @param sourceDir The directory holding the source to scan.
+     * @param docletDir The directory holding the doclet (or its jar).
+     */
+    JavaScanner(File sourceDir, File docletDir) {
+        this.mSourceDir = sourceDir;
+        this.mDocletDir = docletDir;
+    }
+
+    int scan() throws Exception {
+        final ArrayList<String> args = new ArrayList<String>();
+        args.add("javadoc");
+        args.add("-doclet");
+        args.add("com.android.compatibility.common.scanner.JavaScannerDoclet");
+        args.add("-sourcepath");
+        args.add(getSourcePath(mSourceDir));
+        args.add("-classpath");
+        args.add(getClassPath());
+        args.add("-docletpath");
+        args.add(mDocletDir.toString());
+        args.addAll(getSourceFiles(mSourceDir));
+
+        // Dont want p to get blocked due to a full pipe.
+        final Process p = new ProcessBuilder(args).redirectErrorStream(true).start();
+        final BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+        try {
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                if (line.startsWith("suite:") ||
+                    line.startsWith("case:") ||
+                    line.startsWith("test:")) {
+                    System.out.println(line);
+                }
+            }
+        } finally {
+          if (in != null) {
+              in.close();
+          }
+        }
+
+        return p.waitFor();
+    }
+
+    private static String getSourcePath(File sourceDir) {
+        final ArrayList<String> sourcePath = new ArrayList<String>(Arrays.asList(SOURCE_PATHS));
+        sourcePath.add(sourceDir.toString());
+        return join(sourcePath, ":");
+    }
+
+    private static String getClassPath() {
+        return join(Arrays.asList(CLASS_PATHS), ":");
+    }
+
+    private static ArrayList<String> getSourceFiles(File sourceDir) {
+        final ArrayList<String> sourceFiles = new ArrayList<String>();
+        final File[] files = sourceDir.listFiles(new FileFilter() {
+            public boolean accept(File pathname) {
+                return pathname.isDirectory() || pathname.toString().endsWith(".java");
+            }
+        });
+        for (File f : files) {
+            if (f.isDirectory()) {
+                sourceFiles.addAll(getSourceFiles(f));
+            } else {
+                sourceFiles.add(f.toString());
+            }
+        }
+        return sourceFiles;
+    }
+
+    private static String join(List<String> list, String delimiter) {
+        final StringBuilder builder = new StringBuilder();
+        for (String s : list) {
+            builder.append(s);
+            builder.append(delimiter);
+        }
+        // Adding the delimiter each time and then removing the last one at the end is more
+        // efficient than doing a check in each iteration of the loop.
+        return builder.substring(0, builder.length() - delimiter.length());
+    }
+
+    public static void main(String[] args) throws Exception {
+        final HashMap<String, String> argsMap = KeyValueArgsParser.parse(args);
+        final String sourcePath = argsMap.get("-s");
+        final String docletPath = argsMap.get("-d");
+        if (sourcePath == null || docletPath == null) {
+            usage(args);
+        }
+        System.exit(new JavaScanner(new File(sourcePath), new File(docletPath)).scan());
+    }
+
+    private static void usage(String[] args) {
+        System.err.println("Arguments: " + Arrays.toString(args));
+        System.err.println("Usage: javascanner -s SOURCE_DIR -d DOCLET_PATH");
+        System.exit(1);
+    }
+}
diff --git a/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java
new file mode 100644
index 0000000..94eccd0
--- /dev/null
+++ b/common/host-side/java-scanner/src/com/android/compatibility/common/scanner/JavaScannerDoclet.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.scanner;
+
+import com.sun.javadoc.ClassDoc;
+import com.sun.javadoc.Doclet;
+import com.sun.javadoc.MethodDoc;
+import com.sun.javadoc.RootDoc;
+
+import java.io.PrintWriter;
+
+/**
+ * Doclet that scans java files looking for tests.
+ *
+ * Sample Ouput;
+ * suite:com.android.sample.cts
+ * case:SampleDeviceTest
+ * test:testSharedPreferences
+ */
+public class JavaScannerDoclet extends Doclet {
+
+    private static final String JUNIT_TEST_CASE_CLASS_NAME = "junit.framework.testcase";
+
+    public static boolean start(RootDoc root) {
+        ClassDoc[] classes = root.classes();
+        if (classes == null) {
+            return false;
+        }
+
+        PrintWriter writer = new PrintWriter(System.out);
+
+        for (ClassDoc clazz : classes) {
+            if (clazz.isAbstract() || !isValidJUnitTestCase(clazz)) {
+                continue;
+            }
+            writer.append("suite:").println(clazz.containingPackage().name());
+            writer.append("case:").println(clazz.name());
+            for (; clazz != null; clazz = clazz.superclass()) {
+                for (MethodDoc method : clazz.methods()) {
+                    if (method.name().startsWith("test")) {
+                        writer.append("test:").println(method.name());
+                    }
+                }
+            }
+        }
+
+        writer.close();
+        return true;
+    }
+
+    private static boolean isValidJUnitTestCase(ClassDoc clazz) {
+        while ((clazz = clazz.superclass()) != null) {
+            if (JUNIT_TEST_CASE_CLASS_NAME.equals(clazz.qualifiedName().toLowerCase())) {
+                return true;
+            }
+        }
+        return false;
+    }
+}
diff --git a/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java b/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java
new file mode 100644
index 0000000..4159f0e
--- /dev/null
+++ b/common/host-side/java-scanner/tests/src/com/android/compatibility/common/scanner/JavaScannerTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.scanner;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+public class JavaScannerTest extends TestCase {
+
+    private static final String JAR = "out/host/linux-x86/framework/compatibility-java-scanner_v2.jar";
+    private static final String VALID_RESULT =
+        "suite:com.android.test" +
+        "case:ValidTest" +
+        "test:testA";
+
+    private static final String VALID_FILENAME = "ValidTest";
+    private static final String VALID =
+        "package com.android.test;" +
+        "import junit.framework.TestCase;" +
+        "public class ValidTest extends TestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    // TestCases must have TestCase in their hierarchy
+    private static final String INVALID_A_FILENAME = "NotTestCase";
+    private static final String INVALID_A =
+        "package com.android.test;" +
+        "public class NotTestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    // TestCases cant be abstract classes
+    private static final String INVALID_B_FILENAME = "AbstractClass";
+    private static final String INVALID_B =
+        "package com.android.test;" +
+        "import junit.framework.TestCase;" +
+        "public abstract class AbstractClass extends TestCase {" +
+        "  public void testA() throws Exception {" +
+        "    helper();" +
+        "  }" +
+        "  public void helper() {" +
+        "    fail();" +
+        "  }" +
+        "}";
+
+    public void testValidFile() throws Exception {
+        String result = runScanner(VALID_FILENAME, VALID);
+        assertEquals(VALID_RESULT, result);
+    }
+
+    public void testInvalidFileA() throws Exception {
+        assertEquals("", runScanner(INVALID_A_FILENAME, INVALID_A));
+    }
+
+    public void testInvalidFileB() throws Exception {
+        assertEquals("", runScanner(INVALID_B_FILENAME, INVALID_B));
+    }
+
+    private static String runScanner(String filename, String content) throws Exception {
+        final File parent0 = new File(System.getProperty("java.io.tmpdir"));
+        final File parent1 = new File(parent0, "tmp" + System.currentTimeMillis());
+        final File parent2 = new File(parent1, "com");
+        final File parent3 = new File(parent2, "android");
+        final File parent4 = new File(parent3, "test");
+        File f = null;
+        try {
+            parent4.mkdirs();
+            f = new File(parent4, filename + ".java");
+            final PrintWriter out = new PrintWriter(f);
+            out.print(content);
+            out.flush();
+            out.close();
+            ArrayList<String> args = new ArrayList<String>();
+            args.add("java");
+            args.add("-jar");
+            args.add(JAR);
+            args.add("-s");
+            args.add(parent1.toString());
+            args.add("-d");
+            args.add(JAR);
+
+            final Process p = new ProcessBuilder(args).start();
+            final StringBuilder output = new StringBuilder();
+            final BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String line = null;
+            while ((line = in.readLine()) != null) {
+                output.append(line);
+            }
+            int ret = p.waitFor();
+            if (ret == 0) {
+                return output.toString();
+            }
+        } finally {
+            if (f != null) {
+                f.delete();
+            }
+            parent4.delete();
+            parent3.delete();
+            parent2.delete();
+            parent1.delete();
+        }
+        return null;
+    }
+}
diff --git a/common/host-side/native-scanner/Android.mk b/common/host-side/native-scanner/Android.mk
new file mode 100644
index 0000000..184cdc0
--- /dev/null
+++ b/common/host-side/native-scanner/Android.mk
@@ -0,0 +1,47 @@
+# Copyright (C) 2014 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_JAVA_LIBRARIES := compatibility-common-util-hostsidelib_v2
+
+LOCAL_MODULE := compatibility-native-scanner_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+################################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-native-scanner_v2 junit
+
+LOCAL_MODULE := compatibility-native-scanner-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/native-scanner/MANIFEST.mf b/common/host-side/native-scanner/MANIFEST.mf
new file mode 100644
index 0000000..c5641ca
--- /dev/null
+++ b/common/host-side/native-scanner/MANIFEST.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.scanner.NativeScanner
+Class-Path: compatibility-common-util-hostsidelib_v2.jar
diff --git a/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java b/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java
new file mode 100644
index 0000000..7b9e447
--- /dev/null
+++ b/common/host-side/native-scanner/src/com/android/compatibility/common/scanner/NativeScanner.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.scanner;
+
+import com.android.compatibility.common.util.KeyValueArgsParser;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+/**
+ * Passes the gtest output and outputs a list of test classes and methods.
+ */
+public final class NativeScanner {
+
+    private static final String TEST_SUITE_ARG = "t";
+    private static final String USAGE = "Usage: compatibility-native-scanner -t TEST_SUITE"
+        + "  This code reads from stdin the list of tests."
+        + "  The format expected:"
+        + "    TEST_CASE_NAME."
+        + "      TEST_NAME";
+
+    /**
+     * @return An {@link ArrayList} of suites, classes and method names.
+     */
+    static ArrayList<String> getTestNames(BufferedReader reader, String testSuite)
+            throws IOException {
+        ArrayList<String> testNames = new ArrayList<String>();
+        testNames.add("suite:" + testSuite);
+
+        String testCaseName = null;
+        String line;
+        while ((line = reader.readLine()) != null) {
+            if (line.length() == 0) {
+                continue;
+            }
+            if (line.charAt(0) == ' ') {
+                if (testCaseName == null) {
+                    throw new RuntimeException("TEST_CASE_NAME not defined before first test.");
+                }
+                testNames.add("test:" + line.trim());
+            } else {
+                testCaseName = line.trim();
+                if (testCaseName.endsWith(".")) {
+                    testCaseName = testCaseName.substring(0, testCaseName.length()-1);
+                }
+                testNames.add("case:" + testCaseName);
+            }
+        }
+        return testNames;
+    }
+
+    /** Lookup test suite argument and scan {@code System.in} for test cases */
+    public static void main(String[] args) throws IOException {
+        HashMap<String, String> argMap = KeyValueArgsParser.parse(args);
+        if (!argMap.containsKey(TEST_SUITE_ARG)) {
+            System.err.println(USAGE);
+            System.exit(1);
+        }
+
+        String testSuite = argMap.get(TEST_SUITE_ARG);
+
+        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+        for (String name : getTestNames(reader, testSuite)) {
+            System.out.println(name);
+        }
+    }
+}
diff --git a/common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java b/common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java
new file mode 100644
index 0000000..c5d3157
--- /dev/null
+++ b/common/host-side/native-scanner/tests/src/com/android/compatibility/common/scanner/NativeScannerTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.scanner;
+
+import com.android.compatibility.common.scanner.NativeScanner;
+
+import junit.framework.TestCase;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+import java.util.Iterator;
+
+public class NativeScannerTest extends TestCase {
+
+    public void testSingleTestNamesCase() throws Exception {
+        StringReader singleTestString = new StringReader("FakeTestCase.\n  FakeTestName\n");
+        BufferedReader reader = new BufferedReader(singleTestString);
+
+        List<String> names = NativeScanner.getTestNames(reader, "TestSuite");
+        Iterator<String> it = names.iterator();
+        assertEquals("suite:TestSuite", it.next());
+        assertEquals("case:FakeTestCase", it.next());
+        assertEquals("test:FakeTestName", it.next());
+        assertFalse(it.hasNext());
+    }
+
+    public void testMultipleTestNamesCase() throws Exception {
+        StringReader singleTestString = new StringReader(
+          "Case1.\n  Test1\n  Test2\nCase2.\n  Test3\n Test4\n");
+        BufferedReader reader = new BufferedReader(singleTestString);
+
+        List<String> names = NativeScanner.getTestNames(reader, "TestSuite");
+
+        Iterator<String> it = names.iterator();
+        assertEquals("suite:TestSuite", it.next());
+        assertEquals("case:Case1", it.next());
+        assertEquals("test:Test1", it.next());
+        assertEquals("test:Test2", it.next());
+        assertEquals("case:Case2", it.next());
+        assertEquals("test:Test3", it.next());
+        assertEquals("test:Test4", it.next());
+        assertFalse(it.hasNext());
+    }
+
+    public void testMissingTestCaseNameCase() throws IOException {
+        StringReader singleTestString = new StringReader("  Test1\n");
+        BufferedReader reader = new BufferedReader(singleTestString);
+
+        try {
+            NativeScanner.getTestNames(reader, "TestSuite");
+            fail("Expected RuntimeException");
+        } catch (RuntimeException expected) {}
+    }
+}
diff --git a/common/host-side/scripts/compatibility-tests_v2 b/common/host-side/scripts/compatibility-tests_v2
new file mode 100755
index 0000000..797909e
--- /dev/null
+++ b/common/host-side/scripts/compatibility-tests_v2
@@ -0,0 +1,61 @@
+#!/bin/bash
+#
+# Copyright (C) 2014 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.
+
+checkFile() {
+    if [ ! -f "$1" ]; then
+        echo "Unable to locate $1"
+        exit
+    fi;
+}
+
+HOST_JAR_DIR=${ANDROID_HOST_OUT}/framework
+HOST_JARS="ddmlib-prebuilt tradefed-prebuilt hosttestlib\
+    compatibility-tradefed_v2 compatibility-tradefed-tests_v2\
+    compatibility-java-scanner_v2 compatibility-java-scanner-tests_v2\
+    compatibility-native-scanner_v2 compatibility-native-scanner-tests_v2\
+    compatibility-xml-plan-generator_v2 compatibility-xml-plan-generator-tests_v2\
+    compatibility-device-util-tests_v2 compatibility-device-setup-tests_v2\
+    compatibility-common-util-hostsidelib_v2 compatibility-common-util-tests_v2"
+
+for JAR in ${HOST_JARS}; do
+    checkFile ${HOST_JAR_DIR}/${JAR}.jar
+    JAR_PATH=${JAR_PATH}:${HOST_JAR_DIR}/${JAR}.jar
+done
+
+DEVICE_LIBS_DIR=${ANDROID_PRODUCT_OUT}/obj/JAVA_LIBRARIES
+DEVICE_LIBS="compatibility-common-util-devicesidelib_v2 compatibility-device-util_v2\
+    compatibility-device-setup_v2"
+
+for LIB in ${DEVICE_LIBS}; do
+    checkFile ${DEVICE_LIBS_DIR}/${LIB}_intermediates/javalib.jar
+    JAR_PATH=${JAR_PATH}:${DEVICE_LIBS_DIR}/${LIB}_intermediates/javalib.jar
+done
+
+# TODO(stuartscott): Currently the test classes are explicitly set here, but
+# once our wrappers for tradefed are in place we can make it scan and generate
+# the list of test at runtime.
+TEST_CLASSES="com.android.compatibility.common.devicesetup.DeviceSetupTest\
+    com.android.compatibility.common.scanner.JavaScannerTest\
+    com.android.compatibility.common.scanner.NativeScannerTest\
+    com.android.compatibility.common.tradefed.TradefedTest\
+    com.android.compatibility.common.util.DeviceUtilTest\
+    com.android.compatibility.common.util.CommonUtilTest\
+    com.android.compatibility.common.xmlgenerator.XmlPlanGeneratorTest"
+
+for CLASS in ${TEST_CLASSES}; do
+    java $RDBG_FLAG -cp ${JAR_PATH} com.android.compatibility.common.tradefed.command.CompatibilityConsole run\
+            singleCommand host -n --class ${CLASS} "$@"
+done
diff --git a/common/host-side/scripts/compatibility-tradefed_v2 b/common/host-side/scripts/compatibility-tradefed_v2
new file mode 100755
index 0000000..f64e273
--- /dev/null
+++ b/common/host-side/scripts/compatibility-tradefed_v2
@@ -0,0 +1,16 @@
+#!/bin/bash
+#
+# Copyright (C) 2014 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.
+echo "TODO(stuartscott): Add the wrapper to launch the executable. This will be done in the next CL"
diff --git a/common/host-side/tradefed/Android.mk b/common/host-side/tradefed/Android.mk
new file mode 100644
index 0000000..2cb559a
--- /dev/null
+++ b/common/host-side/tradefed/Android.mk
@@ -0,0 +1,51 @@
+# Copyright (C) 2014 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 the compatibility tradefed host library
+###############################################################################
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+#LOCAL_JAVA_RESOURCE_DIRS := res
+
+LOCAL_MODULE := compatibility-tradefed_v2
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt hosttestlib compatibility-common-util-hostsidelib_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+###############################################################################
+# Build the compatibility tradefed tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_MODULE := compatibility-tradefed-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_JAVA_LIBRARIES := ddmlib-prebuilt tradefed-prebuilt compatibility-tradefed_v2 junit
+
+LOCAL_STATIC_JAVA_LIBRARIES := easymock
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java
new file mode 100644
index 0000000..dfd1c71
--- /dev/null
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/command/CompatibilityConsole.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.tradefed.command;
+
+import com.android.tradefed.command.Console;
+import com.android.tradefed.config.ConfigurationException;
+
+/**
+ * An extension of Tradefed's console which adds features specific to compatibility testing.
+ */
+public class CompatibilityConsole extends Console {
+
+    public static void main(String[] args) throws InterruptedException, ConfigurationException {
+        CompatibilityConsole console = new CompatibilityConsole();
+        Console.startConsole(console, args);
+    }
+}
diff --git a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
similarity index 68%
copy from tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
copy to common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
index af264c9..ab19369 100644
--- a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/TradefedTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,8 +14,12 @@
  * limitations under the License.
  */
 
-package android.security.cts.activity;
+package com.android.compatibility.common.tradefed;
 
-interface ISecureRandomService {
-    int getRandomBytesAndPid(inout byte[] randomBytes);
+import junit.framework.TestCase;
+
+public class TradefedTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/common/host-side/xml-plan-generator/Android.mk b/common/host-side/xml-plan-generator/Android.mk
new file mode 100644
index 0000000..53718e5
--- /dev/null
+++ b/common/host-side/xml-plan-generator/Android.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2014 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-common-util-hostsidelib_v2
+
+LOCAL_STATIC_JAVA_LIBRARIES := vogarexpectlib
+
+LOCAL_JAR_MANIFEST := MANIFEST.mf
+
+LOCAL_CLASSPATH := $(HOST_JDK_TOOLS_JAR)
+
+LOCAL_MODULE := compatibility-xml-plan-generator_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := compatibility-tradefed_v2 compatibility-xml-plan-generator_v2 junit
+
+LOCAL_MODULE := compatibility-xml-plan-generator-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/host-side/xml-plan-generator/MANIFEST.mf b/common/host-side/xml-plan-generator/MANIFEST.mf
new file mode 100644
index 0000000..95aee0d
--- /dev/null
+++ b/common/host-side/xml-plan-generator/MANIFEST.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.android.compatibility.common.xmlgenerator.XmlPlanGenerator
+Class-Path: compatibility-common-util-hostsidelib_v2.jar
diff --git a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/Test.java
similarity index 66%
copy from tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
copy to common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/Test.java
index af264c9..d3e1d88 100644
--- a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/Test.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,8 +14,17 @@
  * limitations under the License.
  */
 
-package android.security.cts.activity;
+package com.android.compatibility.common.xmlgenerator;
 
-interface ISecureRandomService {
-    int getRandomBytesAndPid(inout byte[] randomBytes);
+public class Test {
+
+    private final String mName;
+
+    public Test(String name) {
+        mName = name;
+    }
+
+    public String getName() {
+        return mName;
+    }
 }
diff --git a/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestCase.java b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestCase.java
new file mode 100644
index 0000000..65b4aa3
--- /dev/null
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestCase.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.xmlgenerator;
+
+import java.util.ArrayList;
+
+public class TestCase {
+
+    private final String mName;
+    private final ArrayList<Test> mTests = new ArrayList<Test>();
+
+    public TestCase(String name) {
+        mName = name;
+    }
+
+    public void addTest(Test test) {
+        mTests.add(test);
+    }
+
+    public String getName() {
+        return mName;
+    }
+
+    public ArrayList<Test> getTests() {
+        return mTests;
+    }
+}
diff --git a/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestListParser.java b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestListParser.java
new file mode 100644
index 0000000..6880440
--- /dev/null
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestListParser.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.xmlgenerator;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Scanner;
+
+/**
+ * Parser of test lists in the form;
+ *
+ * suite:android.sample
+ * case:SampleTest
+ * test:testA
+ * test:testB
+ * suite:android.sample.ui
+ * case:SampleUiTest
+ * test:testA
+ * test:testB
+ */
+public class TestListParser {
+
+    private TestListParser() {}
+
+    public static HashMap<String, TestSuite> parse(InputStream input) {
+        final HashMap<String, TestSuite> suites = new HashMap<String, TestSuite>();
+        TestSuite currentSuite = null;
+        TestCase currentCase = null;
+        Scanner in = null;
+        try {
+            in = new Scanner(input);
+            while (in.hasNextLine()) {
+                final String line = in.nextLine();
+                final String[] parts = line.split(":");
+                if (parts.length != 2) {
+                    throw new RuntimeException("Invalid Format: " + line);
+                }
+                final String key = parts[0];
+                final String value = parts[1];
+                if (currentSuite == null) {
+                    if (!"suite".equals(key)) {
+                        throw new RuntimeException("TestSuite Expected");
+                    }
+                    final String[] names = value.split("\\.");
+                    for (int i = 0; i < names.length; i++) {
+                        final String name = names[i];
+                        if (currentSuite != null) {
+                            if (currentSuite.hasTestSuite(name)) {
+                                currentSuite = currentSuite.getTestSuite(name);
+                            } else {
+                                final TestSuite newSuite = new TestSuite(name);
+                                currentSuite.addTestSuite(newSuite);
+                                currentSuite = newSuite;
+                            }
+                        } else if (suites.containsKey(name)) {
+                            currentSuite = suites.get(name);
+                        } else {
+                            currentSuite = new TestSuite(name);
+                            suites.put(name, currentSuite);
+                        }
+                    }
+                } else if (currentCase == null) {
+                    if (!"case".equals(key)) {
+                        throw new RuntimeException("TestCase Expected");
+                    }
+                    currentCase = new TestCase(value);
+                    currentSuite.addTestCase(currentCase);
+                } else {
+                    if (!"test".equals(key)) {
+                        throw new RuntimeException("Test Expected");
+                    }
+                    currentCase.addTest(new Test(value));
+                }
+            }
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+        return suites;
+    }
+}
diff --git a/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestSuite.java b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestSuite.java
new file mode 100644
index 0000000..db4fd07
--- /dev/null
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/TestSuite.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.xmlgenerator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+public class TestSuite {
+
+    private final String mName;
+    private final HashMap<String, TestSuite> mTestSuites = new HashMap<String, TestSuite>();
+    private final ArrayList<TestCase> mTestCases = new ArrayList<TestCase>();
+
+    public TestSuite(String name) {
+        mName = name;
+    }
+
+    public boolean hasTestSuite(String name) {
+        return mTestSuites.containsKey(name);
+    }
+
+    public TestSuite getTestSuite(String name) {
+        return mTestSuites.get(name);
+    }
+
+    public void addTestSuite(TestSuite testSuite) {
+        mTestSuites.put(testSuite.getName(), testSuite);
+    }
+
+    public void addTestCase(TestCase testCase) {
+        mTestCases.add(testCase);
+    }
+
+    public String getName() {
+        return mName;
+    }
+
+    public HashMap<String, TestSuite> getTestSuites() {
+        return mTestSuites;
+    }
+
+    public ArrayList<TestCase> getTestCases() {
+        return mTestCases;
+    }
+}
diff --git a/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java
new file mode 100644
index 0000000..d0a3a37
--- /dev/null
+++ b/common/host-side/xml-plan-generator/src/com/android/compatibility/common/xmlgenerator/XmlPlanGenerator.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.xmlgenerator;
+
+import com.android.compatibility.common.util.KeyValueArgsParser;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import vogar.Expectation;
+import vogar.ExpectationStore;
+import vogar.ModeId;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+/**
+ * Passes the scanner output and outputs an xml description of the tests.
+ */
+public class XmlPlanGenerator {
+
+    private final ExpectationStore mExpectations;
+    private final String mAppNameSpace;
+    private final String mAppPackageName;
+    private final String mName;
+    private final String mRunner;
+    private final String mTargetBinaryName;
+    private final String mTargetNameSpace;
+    private final String mJarPath;
+    private final String mTestType;
+    private final String mOutput;
+
+    private XmlPlanGenerator(ExpectationStore expectations, String appNameSpace,
+            String appPackageName, String name, String runner, String targetBinaryName,
+            String targetNameSpace, String jarPath, String testType, String output) {
+        mExpectations = expectations;
+        mAppNameSpace = appNameSpace;
+        mAppPackageName = appPackageName;
+        mName = name;
+        mRunner = runner;
+        mTargetBinaryName = targetBinaryName;
+        mTargetNameSpace = targetNameSpace;
+        mJarPath = jarPath;
+        mTestType = testType;
+        mOutput = output;
+    }
+
+    private void writePackageXml() throws IOException {
+        OutputStream out = System.out;
+        if (mOutput != null) {
+            out = new FileOutputStream(mOutput);
+        }
+        PrintWriter writer = null;
+        try {
+            writer = new PrintWriter(out);
+            writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+            writeTestPackage(writer);
+        } finally {
+            if (writer != null) {
+                writer.close();
+            }
+        }
+    }
+
+    private void writeTestPackage(PrintWriter writer) {
+        writer.append("<TestPackage");
+        if (mAppNameSpace != null) {
+            writer.append(" appNameSpace=\"").append(mAppNameSpace).append("\"");
+        }
+
+        writer.append(" appPackageName=\"").append(mAppPackageName).append("\"");
+        writer.append(" name=\"").append(mName).append("\"");
+
+        if (mRunner != null) {
+            writer.append(" runner=\"").append(mRunner).append("\"");
+        }
+
+        if (mAppNameSpace != null && mTargetNameSpace != null
+                && !mAppNameSpace.equals(mTargetNameSpace)) {
+            writer.append(" targetBinaryName=\"").append(mTargetBinaryName).append("\"");
+            writer.append(" targetNameSpace=\"").append(mTargetNameSpace).append("\"");
+        }
+
+        if (mTestType != null && !mTestType.isEmpty()) {
+            writer.append(" testType=\"").append(mTestType).append("\"");
+        }
+
+        if (mJarPath != null) {
+            writer.append(" jarPath=\"").append(mJarPath).append("\"");
+        }
+
+        writer.println(" version=\"1.0\">");
+
+        final HashMap<String, TestSuite> suites = TestListParser.parse(System.in);
+        if (suites.isEmpty()) {
+            throw new RuntimeException("No TestSuites Found");
+        }
+        writeTestSuites(writer, suites, "");
+        writer.println("</TestPackage>");
+    }
+
+    private void writeTestSuites(PrintWriter writer, HashMap<String, TestSuite> suites, String name) {
+        for (String suiteName : suites.keySet()) {
+            final TestSuite suite = suites.get(suiteName);
+            writer.append("<TestSuite name=\"").append(suiteName).println("\">");
+            final String fullname = name + suiteName + ".";
+            writeTestSuites(writer, suite.getTestSuites(), fullname);
+            writeTestCases(writer, suite.getTestCases(), fullname);
+            writer.println("</TestSuite>");
+        }
+    }
+
+    private void writeTestCases(PrintWriter writer, ArrayList<TestCase> cases, String name) {
+        for (TestCase testCase : cases) {
+            final String caseName = testCase.getName();
+            writer.append("<TestCase name=\"").append(caseName).println("\">");
+            final String fullname = name + caseName;
+            writeTests(writer, testCase.getTests(), fullname);
+            writer.println("</TestCase>");
+        }
+    }
+
+    private void writeTests(PrintWriter writer, ArrayList<Test> tests, String name) {
+        if (tests.isEmpty()) {
+            throw new RuntimeException("No Tests Found");
+        }
+        for (Test test : tests) {
+            final String testName = test.getName();
+            writer.append("<Test name=\"").append(testName).append("\"");
+            final String fullname = name + "#" + testName;
+            if (isKnownFailure(mExpectations, fullname)) {
+                writer.append(" expectation=\"failure\"");
+            }
+            writer.println(" />");
+        }
+    }
+
+    public static boolean isKnownFailure(ExpectationStore store, String fullname) {
+        return store != null && store.get(fullname) != Expectation.SUCCESS;
+    }
+
+    public static void main(String[] args) throws Exception {
+        final HashMap<String, String> argsMap = KeyValueArgsParser.parse(args);
+        final String packageName = argsMap.get("-p");
+        final String name = argsMap.get("-n");
+        final String testType = argsMap.get("-t");
+        final String jarPath = argsMap.get("-j");
+        final String instrumentation = argsMap.get("-i");
+        final String manifest = argsMap.get("-m");
+        final String expectations = argsMap.get("-e");
+        final String output = argsMap.get("-o");
+        String appNameSpace = argsMap.get("-a");
+        String targetNameSpace = argsMap.get("-r");
+        if (packageName == null || name == null) {
+            usage(args);
+        }
+        String runner = null;
+        if (manifest != null) {
+            Document m = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(manifest);
+            Element elem = m.getDocumentElement();
+            appNameSpace = elem.getAttribute("package");
+            runner = getElementAttribute(elem, "instrumentation", "android:name");
+            targetNameSpace = getElementAttribute(elem, "instrumentation", "android:targetPackage");
+        }
+
+        final HashSet<File> expectationFiles = new HashSet<File>();
+        if (expectations != null) {
+            expectationFiles.add(new File(expectations));
+        }
+        final ExpectationStore store = ExpectationStore.parse(expectationFiles, ModeId.DEVICE);
+        XmlPlanGenerator generator = new XmlPlanGenerator(store, appNameSpace, packageName, name,
+            runner, instrumentation, targetNameSpace, jarPath, testType, output);
+        generator.writePackageXml();
+    }
+
+    private static String getElementAttribute(Element parent, String elem, String name) {
+        NodeList nodeList = parent.getElementsByTagName(elem);
+        if (nodeList.getLength() > 0) {
+             Element element = (Element) nodeList.item(0);
+             return element.getAttribute(name);
+        }
+        return null;
+    }
+
+    private static void usage(String[] args) {
+        System.err.println("Arguments: " + Arrays.toString(args));
+        System.err.println("Usage: compatibility-xml-plan-generator -p PACKAGE_NAME -n NAME" +
+            "[-t TEST_TYPE] [-j JAR_PATH] [-i INSTRUMENTATION] [-m MANIFEST] [-e EXPECTATIONS]" +
+            "[-o OUTPUT]");
+        System.exit(1);
+    }
+}
diff --git a/common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java b/common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java
new file mode 100644
index 0000000..082af17
--- /dev/null
+++ b/common/host-side/xml-plan-generator/tests/src/com/android/compatibility/common/xmlgenerator/XmlPlanGeneratorTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.xmlgenerator;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Scanner;
+
+public class XmlPlanGeneratorTest extends TestCase {
+
+    private static final String JAR = "out/host/linux-x86/framework/compatibility-xml-plan-generator_v2.jar";
+    private static final String PACKAGE_NAME = "com.android.test";
+    private static final String NAME = "ValidTest";
+    private static final String VALID_RESULT =
+        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+        "<TestPackage appPackageName=\"com.android.test\" name=\"ValidTest\" version=\"1.0\">" +
+        "<TestSuite name=\"com\">" +
+        "<TestSuite name=\"android\">" +
+        "<TestSuite name=\"test\">" +
+        "<TestCase name=\"ValidTest\">" +
+        "<Test name=\"testA\" />" +
+        "</TestCase>" +
+        "</TestSuite>" +
+        "</TestSuite>" +
+        "</TestSuite>" +
+        "</TestPackage>";
+
+    private static final String VALID =
+        "suite:com.android.test\n" +
+        "case:ValidTest\n" +
+        "test:testA\n";
+
+    private static final String INVALID_A = "";
+
+    private static final String INVALID_B =
+        "suite:com.android.test\n" +
+        "case:InvalidTest\n";
+
+    private static final String INVALID_C =
+        "uh oh";
+
+    private static final String INVALID_D =
+        "test:testA\n" +
+        "case:InvalidTest\n" +
+        "suite:com.android.test\n";
+
+    private static final String INVALID_E =
+        "suite:com.android.test\n" +
+        "test:testA\n" +
+        "case:InvalidTest\n";
+
+    public void testValid() throws Exception {
+        assertEquals(VALID_RESULT, runGenerator(VALID));
+    }
+
+    public void testInvalidA() throws Exception {
+        assertNull(runGenerator(INVALID_A));
+    }
+
+    public void testInvalidB() throws Exception {
+        assertNull(runGenerator(INVALID_B));
+    }
+
+    public void testTestListParserInvalidFormat() throws Exception {
+        runTestListParser(INVALID_C);
+    }
+
+    public void testTestListParserSuiteExpected() throws Exception {
+        runTestListParser(INVALID_D);
+    }
+
+    public void testTestListParserCaseExpected() throws Exception {
+        runTestListParser(INVALID_E);
+    }
+
+    private static String runGenerator(String input) throws Exception {
+        ArrayList<String> args = new ArrayList<String>();
+        args.add("java");
+        args.add("-jar");
+        args.add(JAR);
+        args.add("-p");
+        args.add(PACKAGE_NAME);
+        args.add("-n");
+        args.add(NAME);
+
+        final Process p = new ProcessBuilder(args).start();
+        final PrintWriter out = new PrintWriter(p.getOutputStream());
+        out.print(input);
+        out.flush();
+        out.close();
+        final StringBuilder output = new StringBuilder();
+        final Scanner in = new Scanner(p.getInputStream());
+        while (in.hasNextLine()) {
+            output.append(in.nextLine());
+        }
+        int ret = p.waitFor();
+        if (ret == 0) {
+            return output.toString();
+        }
+        return null;
+    }
+
+    private static void runTestListParser(String input) throws Exception {
+        try {
+            final ByteArrayInputStream in = new ByteArrayInputStream(input.getBytes());
+            final HashMap<String, TestSuite> suites = TestListParser.parse(in);
+            fail();
+        } catch (RuntimeException e) {}
+    }
+}
diff --git a/common/util/Android.mk b/common/util/Android.mk
new file mode 100644
index 0000000..b7842559
--- /dev/null
+++ b/common/util/Android.mk
@@ -0,0 +1,61 @@
+# Copyright (C) 2014 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.
+
+###############################################################################
+# Build the common utility library for use device-side
+###############################################################################
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-common-util-devicesidelib_v2
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_STATIC_JAVA_LIBRARY)
+
+###############################################################################
+# Build the common utility library for use host-side
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE := compatibility-common-util-hostsidelib_v2
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
+###############################################################################
+# Build the tests
+###############################################################################
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, tests/src)
+
+LOCAL_JAVA_LIBRARIES := junit
+
+LOCAL_MODULE := compatibility-common-util-tests_v2
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/common/util/src/com/android/compatibility/common/util/KeyValueArgsParser.java b/common/util/src/com/android/compatibility/common/util/KeyValueArgsParser.java
new file mode 100644
index 0000000..92a2b18
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/KeyValueArgsParser.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import java.util.HashMap;
+
+/**
+ * Parses an array of arguments into a HashMap.
+ *
+ * This class assumed the arguments are in the form "-<key> <value> ..."
+ */
+public class KeyValueArgsParser {
+
+    private KeyValueArgsParser() {}
+
+    public static HashMap<String, String> parse(String[] args) {
+        final HashMap<String, String> map = new HashMap<String, String>();
+        String key = null;
+        for (String s : args) {
+            if (key == null) {
+                if (!s.startsWith("-")) {
+                    throw new RuntimeException("Invalid Key: " + s);
+                }
+                key = s;
+            } else {
+                map.put(key, s);
+                key = null;
+            }
+        }
+        if (key != null) {
+            throw new RuntimeException("Left over key");
+        }
+        return map;
+    }
+}
diff --git a/common/util/src/com/android/compatibility/common/util/MeasureRun.java b/common/util/src/com/android/compatibility/common/util/MeasureRun.java
new file mode 100644
index 0000000..d58b8d4
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/MeasureRun.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+/**
+ * Interface for measuring time for each run.
+ */
+public abstract class MeasureRun {
+    /**
+     *  Called before each run. not included in time measurement.
+     */
+    public void prepare(int i) throws Exception {
+        // default empty implementation
+    };
+
+    abstract public void run(int i) throws Exception;
+}
diff --git a/common/util/src/com/android/compatibility/common/util/MeasureTime.java b/common/util/src/com/android/compatibility/common/util/MeasureTime.java
new file mode 100644
index 0000000..102b96a
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/MeasureTime.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+/**
+ * Provides a mechanism to measure the time taken to run a piece of code.
+ *
+ * The code will be run multiple times and the time taken by each run will returned.
+ */
+public class MeasureTime {
+    /**
+     * measure time taken for each run for given count
+     * @param count
+     * @param run
+     * @return array of time taken in each run in msec.
+     * @throws Exception
+     */
+    public static double[] measure(int count, MeasureRun run) throws Exception {
+        double[] result = new double[count];
+
+        for (int i = 0; i < count; i++) {
+            run.prepare(i);
+            long start = System.currentTimeMillis();
+            run.run(i);
+            long end =  System.currentTimeMillis();
+            result[i] = end - start;
+        }
+        return result;
+    }
+}
diff --git a/common/util/src/com/android/compatibility/common/util/ReportLog.java b/common/util/src/com/android/compatibility/common/util/ReportLog.java
new file mode 100644
index 0000000..9e733e4
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/ReportLog.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Utility class to add results to the report.
+ */
+public abstract class ReportLog implements Serializable {
+
+    private Result mSummary;
+    private final List<Result> mDetails = new ArrayList<Result>();
+
+    private class Result implements Serializable {
+        private static final int BASE_DEPTH = 2;// 0:constructor, 1:addValues/setSummary, 2:caller
+        private String mLocation;
+        private String mMessage;
+        private double[] mValues;
+        private ResultType mType;
+        private ResultUnit mUnit;
+
+        /**
+         * Creates a result object to be included in the report. Each object has a message
+         * describing its values and enums to interpret them. In addition, each result also includes
+         * class, method and line number information about the test which added this result which is
+         * collected by looking at the stack trace.
+         *
+         * @param message A string describing the values
+         * @param values An array of the values
+         * @param type Represents how to interpret the values (eg. A lower score is better)
+         * @param unit Represents the unit in which the values are (eg. Milliseconds)
+         * @param depth A number used to increase the depth the stack is queried. This should only
+         * be given in the case that the report is populated by a helper function, in which case it
+         * would be 1, or else 0.
+         */
+        private Result(String message, double[] values, ResultType type,
+                ResultUnit unit, int depth) {
+            final StackTraceElement[] trace = Thread.currentThread().getStackTrace();
+            final StackTraceElement e = trace[Math.min(BASE_DEPTH + depth, trace.length - 1)];
+            mLocation = String.format("%s#%s:%d",
+                    e.getClassName(), e.getMethodName(), e.getLineNumber());
+            mMessage = message;
+            mValues = values;
+            mType = type;
+            mUnit = unit;
+        }
+
+    }
+
+    /**
+     * Adds an array of values to the report.
+     */
+    public void addValues(String message, double[] values, ResultType type, ResultUnit unit) {
+        mDetails.add(new Result(message, values, type, unit, 0));
+    }
+
+    /**
+     * Adds an array of values to the report.
+     */
+    public void addValues(String message, double[] values, ResultType type,
+            ResultUnit unit, int depth) {
+        mDetails.add(new Result(message, values, type, unit, depth));
+    }
+
+    /**
+     * Adds a value to the report.
+     */
+    public void addValue(String message, double value, ResultType type, ResultUnit unit) {
+        mDetails.add(new Result(message, new double[] {value}, type, unit, 0));
+    }
+
+    /**
+     * Adds a value to the report.
+     */
+    public void addValue(String message, double value, ResultType type,
+            ResultUnit unit, int depth) {
+        mDetails.add(new Result(message, new double[] {value}, type, unit, depth));
+    }
+
+    /**
+     * Sets the summary of the report.
+     */
+    public void setSummary(String message, double value, ResultType type, ResultUnit unit) {
+        mSummary = new Result(message, new double[] {value}, type, unit, 0);
+    }
+
+    /**
+     * Sets the summary of the report.
+     */
+    public void setSummary(String message, double value, ResultType type,
+            ResultUnit unit, int depth) {
+        mSummary = new Result(message, new double[] {value}, type, unit, depth);
+    }
+}
diff --git a/common/util/src/com/android/compatibility/common/util/ResultType.java b/common/util/src/com/android/compatibility/common/util/ResultType.java
new file mode 100644
index 0000000..779c6d0
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/ResultType.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+/**
+ * Enum for distinguishing results.
+ */
+public enum ResultType {
+    /** Lower score is better. */
+    LOWER_BETTER,
+    /** Higher score is better. */
+    HIGHER_BETTER,
+    /** This value is not directly correlated with score. */
+    NEUTRAL,
+    /** Presence of this type requires some attention although it may not be an error. */
+    WARNING;
+
+    /**
+     * Return string used in the XML report
+     */
+    public String getXmlString() {
+        return name().toLowerCase();
+    }
+}
diff --git a/common/util/src/com/android/compatibility/common/util/ResultUnit.java b/common/util/src/com/android/compatibility/common/util/ResultUnit.java
new file mode 100644
index 0000000..f38ddae
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/ResultUnit.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+/**
+ * Enum for representing the unit of results.
+ */
+public enum ResultUnit {
+    /** for value with no unit */
+    NONE,
+    /** milli-seconds */
+    MS,
+    /** frames per second */
+    FPS,
+    /** operations per second */
+    OPS,
+    /** kilo-bytes-per-second, not bits-per-second */
+    KBPS,
+    /** mega-bytes-per-second */
+    MBPS,
+    /** amount of data, bytes */
+    BYTE,
+    /** tell how many times it did happen. */
+    COUNT,
+    /** unit for benchmarking with generic score. */
+    SCORE;
+
+    /**
+     * Return string used in the XML report
+     */
+    public String getXmlString() {
+        return name().toLowerCase();
+    }
+}
+
diff --git a/common/util/src/com/android/compatibility/common/util/Stat.java b/common/util/src/com/android/compatibility/common/util/Stat.java
new file mode 100644
index 0000000..8bf9bf7
--- /dev/null
+++ b/common/util/src/com/android/compatibility/common/util/Stat.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2014 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.compatibility.common.util;
+
+import java.util.Arrays;
+
+/**
+ * Utilities for doing statistics
+ */
+public class Stat {
+
+    /**
+     * Collection of statistical propertirs like average, max, min, and stddev
+     */
+    public static class StatResult {
+        public double mAverage;
+        public double mMin;
+        public double mMax;
+        public double mStddev;
+        public int mDataCount;
+        public StatResult(double average, double min, double max, double stddev, int dataCount) {
+            mAverage = average;
+            mMin = min;
+            mMax = max;
+            mStddev = stddev;
+            mDataCount = dataCount;
+        }
+    }
+
+    /**
+     * Calculate statistics properties likes average, min, max, and stddev for the given array
+     */
+    public static StatResult getStat(double[] data) {
+        double average = data[0];
+        double min = data[0];
+        double max = data[0];
+        double eX2 = data[0] * data[0]; // will become E[X^2]
+        for (int i = 1; i < data.length; i++) {
+            average += data[i];
+            eX2 += data[i] * data[i];
+            if (data[i] > max) {
+                max = data[i];
+            }
+            if (data[i] < min) {
+                min = data[i];
+            }
+        }
+        average /= data.length;
+        eX2 /= data.length;
+        // stddev = sqrt(E[X^2] - (E[X])^2)
+        double stddev = Math.sqrt(eX2 - average * average);
+        return new StatResult(average, min, max, stddev, data.length);
+    }
+
+    /**
+     * Calculate statistics properties likes average, min, max, and stddev for the given array
+     * while rejecting outlier +/- median * rejectionThreshold.
+     * rejectionThreshold should be bigger than 0.0 and be lowerthan 1.0
+     */
+    public static StatResult getStatWithOutlierRejection(double[] data, double rejectionThreshold) {
+        double[] dataCopied = Arrays.copyOf(data, data.length);
+        Arrays.sort(dataCopied);
+        int medianIndex = dataCopied.length / 2;
+        double median;
+        if (dataCopied.length % 2 == 1) {
+            median = dataCopied[medianIndex];
+        } else {
+            median = (dataCopied[medianIndex - 1] + dataCopied[medianIndex]) / 2.0;
+        }
+        double thresholdMin = median * (1.0 - rejectionThreshold);
+        double thresholdMax = median * (1.0 + rejectionThreshold);
+
+        double average = 0.0;
+        double min = median;
+        double max = median;
+        double eX2 = 0.0; // will become E[X^2]
+        int validDataCounter = 0;
+        for (int i = 0; i < data.length; i++) {
+            if ((data[i] > thresholdMin) && (data[i] < thresholdMax)) {
+                validDataCounter++;
+                average += data[i];
+                eX2 += data[i] * data[i];
+                if (data[i] > max) {
+                    max = data[i];
+                }
+                if (data[i] < min) {
+                    min = data[i];
+                }
+            }
+            // TODO report rejected data
+        }
+        double stddev;
+        if (validDataCounter > 0) {
+            average /= validDataCounter;
+            eX2 /= validDataCounter;
+            // stddev = sqrt(E[X^2] - (E[X])^2)
+            stddev = Math.sqrt(eX2 - average * average);
+        } else { // both median is showing too much diff
+            average = median;
+            stddev = 0; // don't care
+        }
+
+        return new StatResult(average, min, max, stddev, validDataCounter);
+    }
+
+    /**
+     * return the average value of the passed array
+     */
+    public static double getAverage(double[] data) {
+        double sum = data[0];
+        for (int i = 1; i < data.length; i++) {
+            sum += data[i];
+        }
+        return sum / data.length;
+    }
+
+    /**
+     * return the minimum value of the passed array
+     */
+    public static double getMin(double[] data) {
+        double min = data[0];
+        for (int i = 1; i < data.length; i++) {
+            if (data[i] < min) {
+                min = data[i];
+            }
+        }
+        return min;
+    }
+
+    /**
+     * return the maximum value of the passed array
+     */
+    public static double getMax(double[] data) {
+        double max = data[0];
+        for (int i = 1; i < data.length; i++) {
+            if (data[i] > max) {
+                max = data[i];
+            }
+        }
+        return max;
+    }
+
+    /**
+     * Calculate rate per sec for given change happened during given timeInMSec.
+     * timeInSec with 0 value will be changed to small value to prevent divide by zero.
+     * @param change total change of quality for the given duration timeInMSec.
+     * @param timeInMSec
+     * @return
+     */
+    public static double calcRatePerSec(double change, double timeInMSec) {
+        if (timeInMSec == 0) {
+            return change * 1000.0 / 0.001; // do not allow zero
+        } else {
+            return change * 1000.0 / timeInMSec;
+        }
+    }
+
+    /**
+     * array version of calcRatePerSecArray
+     */
+    public static double[] calcRatePerSecArray(double change, double[] timeInMSec) {
+        double[] result = new double[timeInMSec.length];
+        change *= 1000.0;
+        for (int i = 0; i < timeInMSec.length; i++) {
+            if (timeInMSec[i] == 0) {
+                result[i] = change / 0.001;
+            } else {
+                result[i] = change / timeInMSec[i];
+            }
+        }
+        return result;
+    }
+
+}
diff --git a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl b/common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
similarity index 68%
copy from tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
copy to common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
index af264c9..a376373 100644
--- a/tests/tests/security/src/android/security/cts/activity/ISecureRandomService.aidl
+++ b/common/util/tests/src/com/android/compatibility/common/util/CommonUtilTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2013 The Android Open Source Project
+ * Copyright (C) 2014 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.
@@ -14,8 +14,12 @@
  * limitations under the License.
  */
 
-package android.security.cts.activity;
+package com.android.compatibility.common.util;
 
-interface ISecureRandomService {
-    int getRandomBytesAndPid(inout byte[] randomBytes);
+import junit.framework.TestCase;
+
+public class CommonUtilTest extends TestCase {
+
+    // TODO(stuartscott): Add tests when there is something to test.
+
 }
diff --git a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
index 8257602..b540048 100644
--- a/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
+++ b/hostsidetests/aadb/src/com/android/cts/aadb/TestDeviceFuncTest.java
@@ -338,8 +338,8 @@
         try {
             FileUtil.writeToFile(source.createInputStream(), tmpPngFile);
             CLog.i("Created file at %s", tmpPngFile.getAbsolutePath());
-            assertTrue("Saved png file is less than 16K - is it invalid?",
-                    tmpPngFile.length() > 16*1024);
+            assertTrue("Saved png file is less than 10K - is it invalid?",
+                    tmpPngFile.length() > 10*1024);
             // TODO: add more stringent checks
         } finally {
             FileUtil.deleteFile(tmpPngFile);
diff --git a/hostsidetests/holo/src/android/holo/cts/HoloHostTest.java b/hostsidetests/holo/src/android/holo/cts/HoloHostTest.java
index 5de3030..25d1312 100644
--- a/hostsidetests/holo/src/android/holo/cts/HoloHostTest.java
+++ b/hostsidetests/holo/src/android/holo/cts/HoloHostTest.java
@@ -186,6 +186,8 @@
             ref.delete();
         }
         mExecutionService.shutdown();
+        // Remove the APK.
+        mDevice.uninstallPackage(PACKAGE);
         super.tearDown();
     }
 
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index b65ded0..5348861 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -117,6 +117,9 @@
     <!-- Used for Transmit IR Test -->
     <uses-permission android:name="android.permission.TRANSMIT_IR" />
 
+    <!-- Used for SystemFeatures Test -->
+    <uses-permission android:name="android.permission.BODY_SENSORS"/>
+
     <!-- Used for PackageManager test, don't delete this permission-tree -->
     <permission-tree android:name="com.android.cts.stub.permission.TEST_DYNAMIC"
                     android:label="Test Tree"/>
diff --git a/tests/plans/CTS-stable.xml b/tests/plans/CTS-stable.xml
index b9e7321..62198f0 100644
--- a/tests/plans/CTS-stable.xml
+++ b/tests/plans/CTS-stable.xml
@@ -27,12 +27,10 @@
   <Entry uri="android.dreams"/>
   <Entry uri="android.drm"/>
   <Entry uri="android.effect"/>
-  <Entry uri="android.example"/>
   <Entry uri="android.gesture"/>
   <Entry uri="android.graphics"/>
   <Entry uri="android.graphics2"/>
   <Entry uri="android.hardware" exclude="android.hardware.cts.SensorIntegrationTests#testAccelerometerDoesNotStopGyroscope;android.hardware.cts.SensorIntegrationTests#testsAccelerometerDoesnNotStopMagnetometer;android.hardware.cts.SensorIntegrationTests#testAndroidTestCaseSetupProperly;android.hardware.cts.SensorIntegrationTests#testBatchAndFlush;android.hardware.cts.SensorIntegrationTests#testGyroscopeDoesNotStopAccelerometer;android.hardware.cts.SensorIntegrationTests#testGyroscopeDoesNotStopMagnetometer;android.hardware.cts.SensorIntegrationTests#testMagnetometerDoesNotStopAccelerometer;android.hardware.cts.SensorIntegrationTests#testMagnetometerDoesNotStopGyroscope;android.hardware.cts.SensorMagneticFieldTest#testBatchingStoppingOtherClients;android.hardware.cts.SensorMagneticFieldTest#testBatchingStoppingOtherClientsBatching;android.hardware.cts.SensorMagneticFieldTest#testFrequencyAccuracy;android.hardware.cts.SensorMagneticFieldTest#testOneClientSeveralThreads;android.hardware.cts.SensorMagneticFieldTest#testOneClientSeveralThreadsBatching;android.hardware.cts.SensorMagneticFieldTest#testStandardDeviationWhileStatic;android.hardware.cts.SensorMagneticFieldTest#testStoppingOtherClients;android.hardware.cts.SensorMagneticFieldTest#testStoppingOtherClientsBatching;android.hardware.cts.SensorAccelerometerTest#testBatchingStoppingOtherClients;android.hardware.cts.SensorAccelerometerTest#testBatchingStoppingOtherClientsBatching;android.hardware.cts.SensorAccelerometerTest#testFrequencyAccuracy;android.hardware.cts.SensorAccelerometerTest#testOneClientSeveralThreads;android.hardware.cts.SensorAccelerometerTest#testOneClientSeveralThreadsBatching;android.hardware.cts.SensorGyroscopeTest#testBatchingStoppingOtherClients;android.hardware.cts.SensorGyroscopeTest#testBatchingStoppingOtherClientsBatching;android.hardware.cts.SensorGyroscopeTest#testFrequencyAccuracy;android.hardware.cts.SensorGyroscopeTest#testOneClientSeveralThreads;android.hardware.cts.SensorGyroscopeTest#testOneClientSeveralThreadsBatching;android.hardware.cts.SensorGyroscopeTest#testStandardDeviationWhilStatic;android.hardware.cts.SensorGyroscopeTest#testStoppingOtherClients;android.hardware.cts.SensorGyroscopeTest#testStoppingOtherClientsBatching;android.hardware.cts.SensorAccelerometerTest#testStandardDeviationWhileStatic;android.hardware.cts.SensorAccelerometerTest#testStoppingOtherClients;android.hardware.cts.SensorAccelerometerTest#testStoppingOtherClientsBatching;android.hardware.camera2.cts.CameraDeviceTest#testCameraDeviceRepeatingRequest;android.hardware.camera2.cts.ImageReaderTest#testImageReaderFromCameraJpeg;android.hardware.cts.CameraGLTest#testCameraToSurfaceTextureMetadata;android.hardware.cts.CameraTest#testImmediateZoom;android.hardware.cts.CameraTest#testPreviewCallback;android.hardware.cts.CameraTest#testSmoothZoom;android.hardware.cts.CameraTest#testVideoSnapshot;android.hardware.cts.CameraGLTest#testSetPreviewTextureBothCallbacks;android.hardware.cts.CameraGLTest#testSetPreviewTexturePreviewCallback" />
-  <Entry uri="android.holo"/>
   <Entry uri="android.jni"/>
   <Entry uri="android.keystore"/>
   <Entry uri="android.location"/>
@@ -59,7 +57,6 @@
   <Entry uri="android.speech"/>
   <Entry uri="android.telephony"/>
   <Entry uri="android.tests.appsecurity"/>
-  <Entry uri="android.tests.location"/>    
   <Entry uri="android.tests.sigtest"/>
   <Entry uri="android.text"/>
   <Entry uri="android.textureview"/>
@@ -70,12 +67,10 @@
   <Entry uri="android.view"/>
   <Entry uri="android.webkit" exclude="android.webkit.cts.WebViewClientTest#testDoUpdateVisitedHistory;android.webkit.cts.WebViewClientTest#testLoadPage;android.webkit.cts.WebViewClientTest#testOnFormResubmission;android.webkit.cts.WebViewClientTest#testOnReceivedError;android.webkit.cts.WebViewClientTest#testOnReceivedHttpAuthRequest;android.webkit.cts.WebViewClientTest#testOnScaleChanged;android.webkit.cts.WebViewClientTest#testOnUnhandledKeyEvent;android.webkit.cts.WebViewTest#testSetInitialScale" />
   <Entry uri="android.widget" exclude="android.widget.cts.GridViewTest#testSetNumColumns" />
-  <Entry uri="com.android.cts.bootup"/>
   <Entry uri="com.android.cts.browserbench"/>
   <Entry uri="com.android.cts.dram"/>
   <Entry uri="com.android.cts.filesystemperf"/>
-  <Entry uri="com.android.cts.jank.opengl"/>
-  <Entry uri="com.android.cts.jank.ui"/>
+  <Entry uri="com.android.cts.jank"/>
   <Entry uri="com.android.cts.opengl"/>
   <Entry uri="com.android.cts.simplecpu"/>
   <Entry uri="com.android.cts.ui"/>
diff --git a/tests/src/android/opengl/cts/EglConfigStubActivity.java b/tests/src/android/opengl/cts/EglConfigStubActivity.java
index ab1a6d0..749679a 100644
--- a/tests/src/android/opengl/cts/EglConfigStubActivity.java
+++ b/tests/src/android/opengl/cts/EglConfigStubActivity.java
@@ -20,6 +20,7 @@
 import android.content.Intent;
 import android.opengl.GLSurfaceView;
 import android.os.Bundle;
+import android.view.WindowManager;
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -44,6 +45,11 @@
         int contextClientVersion = getContextClientVersion();
         setTitle("EGL Config Id: " + configId + " Client Version: " + contextClientVersion);
 
+        // Dismiss keyguard and keep screen on while this test is on.
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
+                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
+                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
         mFinishedDrawing = new CountDownLatch(1);
         mView = new EglConfigGLSurfaceView(this, configId, contextClientVersion, new Runnable() {
             @Override
diff --git a/tests/src/android/text/EmojiStubActivity.java b/tests/src/android/text/EmojiStubActivity.java
index 1587c94..8d09250 100644
--- a/tests/src/android/text/EmojiStubActivity.java
+++ b/tests/src/android/text/EmojiStubActivity.java
@@ -21,15 +21,20 @@
 import android.app.Activity;
 import android.os.Bundle;
 import android.webkit.WebView;
+import android.webkit.cts.NullWebViewUtils;
 
 public class EmojiStubActivity extends Activity {
     private WebView mWebView;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.webview_layout);
-        mWebView = (WebView) findViewById(R.id.web_page);
+        try {
+            super.onCreate(savedInstanceState);
+            setContentView(R.layout.webview_layout);
+            mWebView = (WebView) findViewById(R.id.web_page);
+        } catch (Exception e) {
+            NullWebViewUtils.determineIfWebViewAvailable(this, e);
+        }
     }
 
     public WebView getWebView() {
@@ -38,7 +43,9 @@
 
     @Override
     public void onDestroy() {
-        mWebView.destroy();
+        if (mWebView != null) {
+            mWebView.destroy();
+        }
         super.onDestroy();
     }
 }
diff --git a/tests/src/android/webkit/cts/CookieSyncManagerStubActivity.java b/tests/src/android/webkit/cts/CookieSyncManagerStubActivity.java
index 3421ac6..a5ac6ec 100644
--- a/tests/src/android/webkit/cts/CookieSyncManagerStubActivity.java
+++ b/tests/src/android/webkit/cts/CookieSyncManagerStubActivity.java
@@ -27,22 +27,35 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        CookieSyncManager.createInstance(this);
 
-        mWebView = new WebView(this);
-        setContentView(mWebView);
+        try {
+            CookieSyncManager.createInstance(this);
+
+            mWebView = new WebView(this);
+            setContentView(mWebView);
+        } catch (Exception e) {
+            NullWebViewUtils.determineIfWebViewAvailable(this, e);
+        }
     }
 
     @Override
     protected void onResume() {
         super.onResume();
-        CookieSyncManager.getInstance().startSync();
+        try {
+            CookieSyncManager.getInstance().startSync();
+        } catch (Exception e) {
+            // May throw on a device with no webview, OK to ignore at this point.
+        }
     }
 
     @Override
     protected void onStop() {
         super.onStop();
-        CookieSyncManager.getInstance().stopSync();
+        try {
+            CookieSyncManager.getInstance().stopSync();
+        } catch (Exception e) {
+            // May throw on a device with no webview, OK to ignore at this point.
+        }
     }
 
     public WebView getWebView(){
diff --git a/tests/src/android/webkit/cts/NullWebViewUtils.java b/tests/src/android/webkit/cts/NullWebViewUtils.java
new file mode 100644
index 0000000..c52219f
--- /dev/null
+++ b/tests/src/android/webkit/cts/NullWebViewUtils.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.webkit.cts;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+/**
+ * Utilities to enable the android.webkit.* CTS tests (and others that rely on a functioning
+ * android.webkit.WebView implementation) to determine whether a functioning WebView is present
+ * on the device or not.
+ *
+ * Test cases that require android.webkit.* classes should wrap their first usage of WebView in a
+ * try catch block, and pass any exception that is thrown to
+ * NullWebViewUtils.determineIfWebViewAvailable. The return value of
+ * NullWebViewUtils.isWebViewAvailable will then determine if the test should expect to be able to
+ * use a WebView.
+ */
+public class NullWebViewUtils {
+
+    private static boolean sWebViewUnavailable;
+
+    /**
+     * @param context Current Activity context, used to query the PackageManager.
+     * @param t       An exception thrown by trying to invoke android.webkit.* APIs.
+     */
+    public static void determineIfWebViewAvailable(Context context, Throwable t) {
+        sWebViewUnavailable = !hasWebViewFeature(context) && checkCauseWasUnsupportedOperation(t);
+    }
+
+    /**
+     * After calling determineIfWebViewAvailable, this returns whether a WebView is available on the
+     * device and wheter the test can rely on it.
+     * @return True iff. PackageManager determined that there is no WebView on the device and the
+     *         exception thrown from android.webkit.* was UnsupportedOperationException.
+     */
+    public static boolean isWebViewAvailable() {
+        return !sWebViewUnavailable;
+    }
+
+    private static boolean hasWebViewFeature(Context context) {
+        // Query the system property that determins if there is a functional WebView on the device.
+        PackageManager pm = context.getPackageManager();
+        return pm.hasSystemFeature(PackageManager.FEATURE_WEBVIEW);
+    }
+
+    private static boolean checkCauseWasUnsupportedOperation(Throwable t) {
+        if (t == null) return false;
+        while (t.getCause() != null) {
+            t = t.getCause();
+        }
+        return t instanceof UnsupportedOperationException;
+    }
+
+    /**
+     * Some CTS tests (by design) first use android.webkit.* from a background thread. This helper
+     * allows the test to catch the UnsupportedOperationException from that background thread, and
+     * then query the result from the test main thread.
+     */
+    public static class NullWebViewFromThreadExceptionHandler
+            implements Thread.UncaughtExceptionHandler {
+        private Throwable mPendingException;
+
+        @Override
+        public void uncaughtException(Thread t, Throwable e) {
+            mPendingException = e;
+        }
+
+        public boolean isWebViewAvailable(Context context) {
+            return hasWebViewFeature(context) ||
+                    !checkCauseWasUnsupportedOperation(mPendingException);
+        }
+    }
+}
\ No newline at end of file
diff --git a/tests/src/android/webkit/cts/WebViewOnUiThread.java b/tests/src/android/webkit/cts/WebViewOnUiThread.java
index 3616655..f638ba8 100644
--- a/tests/src/android/webkit/cts/WebViewOnUiThread.java
+++ b/tests/src/android/webkit/cts/WebViewOnUiThread.java
@@ -241,6 +241,15 @@
         });
     }
 
+    public boolean canZoomIn() {
+        return getValue(new ValueGetter<Boolean>() {
+            @Override
+            public Boolean capture() {
+                return mWebView.canZoomIn();
+            }
+        });
+    }
+
     public boolean zoomIn() {
         return getValue(new ValueGetter<Boolean>() {
             @Override
diff --git a/tests/src/android/webkit/cts/WebViewStubActivity.java b/tests/src/android/webkit/cts/WebViewStubActivity.java
index 6a51bbe..62adc39 100644
--- a/tests/src/android/webkit/cts/WebViewStubActivity.java
+++ b/tests/src/android/webkit/cts/WebViewStubActivity.java
@@ -29,9 +29,13 @@
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.webview_layout);
-        mWebView = (WebView) findViewById(R.id.web_page);
+        try {
+            super.onCreate(savedInstanceState);
+            setContentView(R.layout.webview_layout);
+            mWebView = (WebView) findViewById(R.id.web_page);
+        } catch (Exception e) {
+            NullWebViewUtils.determineIfWebViewAvailable(this, e);
+        }
     }
 
     public WebView getWebView() {
@@ -40,11 +44,13 @@
 
     @Override
     public void onDestroy() {
-        ViewParent parent =  mWebView.getParent();
-        if (parent instanceof ViewGroup) {
-            ((ViewGroup) parent).removeView(mWebView);
+        if (mWebView != null) {
+            ViewParent parent =  mWebView.getParent();
+            if (parent instanceof ViewGroup) {
+                ((ViewGroup) parent).removeView(mWebView);
+            }
+            mWebView.destroy();
         }
-        mWebView.destroy();
         super.onDestroy();
     }
 }
diff --git a/tests/src/android/widget/cts/RemoteViewsStubActivity.java b/tests/src/android/widget/cts/RemoteViewsStubActivity.java
index f1c0a72..f16ae13 100644
--- a/tests/src/android/widget/cts/RemoteViewsStubActivity.java
+++ b/tests/src/android/widget/cts/RemoteViewsStubActivity.java
@@ -20,6 +20,7 @@
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.webkit.cts.NullWebViewUtils;
 import android.widget.RemoteViews;
 
 /**
@@ -28,7 +29,11 @@
 public class RemoteViewsStubActivity extends Activity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.remoteviews_host);
+        try {
+            super.onCreate(savedInstanceState);
+            setContentView(R.layout.remoteviews_host);
+        } catch (Exception e) {
+            NullWebViewUtils.determineIfWebViewAvailable(this, e);
+        }
     }
 }
diff --git a/tests/tests/accessibilityservice/AndroidManifest.xml b/tests/tests/accessibilityservice/AndroidManifest.xml
index ac75553..ed94f9c 100644
--- a/tests/tests/accessibilityservice/AndroidManifest.xml
+++ b/tests/tests/accessibilityservice/AndroidManifest.xml
@@ -22,8 +22,6 @@
   <uses-sdk android:minSdkVersion="18"
           android:targetSdkVersion="18" />
 
-  <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
-
   <application android:theme="@android:style/Theme.Holo.NoActionBar" >
 
       <uses-library android:name="android.test.runner"/>
@@ -41,7 +39,7 @@
               android:name="android.accessibilityservice.cts.AccessibilityFocusAndInputFocusSyncActivity"/>
 
       <activity android:label="@string/accessibility_text_traversal_test_activity"
-              android:name="android.accessibilityservice.cts.AccessibilityTextTraversalActivity"/> 
+              android:name="android.accessibilityservice.cts.AccessibilityTextTraversalActivity"/>
 
   </application>
 
diff --git a/tests/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml b/tests/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
index f86f00f..9906227 100644
--- a/tests/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
+++ b/tests/tests/accessibilityservice/res/layout/accessibility_text_traversal_test.xml
@@ -26,29 +26,32 @@
        android:id="@+id/view"
        android:layout_width="50dip"
        android:layout_height="50dip"
+       android:visibility="gone"
        />
 
    <TextView
        android:id="@+id/text"
-       android:layout_width="200dip"
-       android:layout_height="200dip"
+       android:layout_width="80dip"
+       android:layout_height="80dip"
        android:includeFontPadding="false"
-       android:textSize="14dip"
+       android:textSize="10dip"
        android:textStyle="normal"
        android:fontFamily="sans-serif"
+       android:visibility="gone"
        />
 
    <EditText
        android:id="@+id/edit"
-       android:layout_width="200dip"
-       android:layout_height="200dip"
+       android:layout_width="80dip"
+       android:layout_height="80dip"
        android:maxLines="1000"
        android:scrollbars="vertical"
        android:focusable="false"
        android:includeFontPadding="false"
-       android:textSize="18dip"
+       android:textSize="10dip"
        android:textStyle="normal"
        android:fontFamily="sans-serif"
+       android:visibility="gone"
        />
 
 </LinearLayout>
diff --git a/tests/tests/accessibilityservice/res/layout/accessibility_view_tree_reporting_test.xml b/tests/tests/accessibilityservice/res/layout/accessibility_view_tree_reporting_test.xml
index fe420bc..0dbd62a 100644
--- a/tests/tests/accessibilityservice/res/layout/accessibility_view_tree_reporting_test.xml
+++ b/tests/tests/accessibilityservice/res/layout/accessibility_view_tree_reporting_test.xml
@@ -29,19 +29,22 @@
               android:id="@+id/firstTextView"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
-              android:text="@string/firstTextView" />
+              android:text="@string/firstTextView"
+              android:textSize="10dip" />
 
           <EditText
               android:id="@+id/firstEditText"
-              android:layout_width="200dip"
+              android:layout_width="20dip"
               android:layout_height="wrap_content"
-              android:contentDescription="@string/firstEditText" />
+              android:contentDescription="@string/firstEditText"
+              android:textSize="10dip" />
 
           <Button
               android:id="@+id/firstButton"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
-              android:text="@string/firstButton" />
+              android:text="@string/firstButton"
+              android:textSize="10dip" />
 
       </LinearLayout>
 
@@ -68,19 +71,22 @@
               android:id="@+id/secondTextView"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
-              android:text="@string/secondTextView" />
+              android:text="@string/secondTextView"
+              android:textSize="10dip" />
 
           <EditText
               android:id="@+id/secondEditText"
-              android:layout_width="200dip"
+              android:layout_width="20dip"
               android:layout_height="wrap_content"
-              android:contentDescription="@string/secondEditText" />
+              android:contentDescription="@string/secondEditText"
+              android:textSize="10dip" />
 
           <Button
               android:id="@+id/secondButton"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
-              android:text="@string/secondButton" />
+              android:text="@string/secondButton"
+              android:textSize="10dip" />
 
       </LinearLayout>
 
diff --git a/tests/tests/accessibilityservice/res/layout/end_to_end_test.xml b/tests/tests/accessibilityservice/res/layout/end_to_end_test.xml
index 351ea24..79f87dc 100644
--- a/tests/tests/accessibilityservice/res/layout/end_to_end_test.xml
+++ b/tests/tests/accessibilityservice/res/layout/end_to_end_test.xml
@@ -18,7 +18,8 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
-              android:gravity="center" android:orientation="vertical">
+              android:gravity="center"
+              android:orientation="vertical">
 
     <ListView android:id="@+id/listview"
               android:layout_width="fill_parent"
diff --git a/tests/tests/accessibilityservice/res/layout/query_window_test.xml b/tests/tests/accessibilityservice/res/layout/query_window_test.xml
index 37c0ef0..001b024 100644
--- a/tests/tests/accessibilityservice/res/layout/query_window_test.xml
+++ b/tests/tests/accessibilityservice/res/layout/query_window_test.xml
@@ -17,6 +17,7 @@
 */
 -->
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/added_content"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
@@ -29,21 +30,24 @@
         >
         <Button
             android:id="@+id/button1"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button1"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button2"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button2"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button3"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button3"
+            android:textSize="10dip"
         />
     </LinearLayout>
 
@@ -54,21 +58,24 @@
         >
         <Button
             android:id="@+id/button4"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button4"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button5"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button5"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button6"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button6"
+            android:textSize="10dip"
             android:contentDescription="@string/contentDescription"
         />
     </LinearLayout>
@@ -80,21 +87,24 @@
         >
         <Button
             android:id="@+id/button7"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button7"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button8"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button8"
+            android:textSize="10dip"
         />
         <Button
             android:id="@+id/button9"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
+            android:layout_width="20dip"
+            android:layout_height="20dip"
             android:text="@string/button9"
+            android:textSize="10dip"
         />
     </LinearLayout>
 
diff --git a/tests/tests/accessibilityservice/res/values/strings.xml b/tests/tests/accessibilityservice/res/values/strings.xml
index 97ddb7c..f60df17 100644
--- a/tests/tests/accessibilityservice/res/values/strings.xml
+++ b/tests/tests/accessibilityservice/res/values/strings.xml
@@ -52,34 +52,34 @@
     <string name="accessibility_query_window_test_activity">Query window test</string>
 
     <!-- String Button1 text -->
-    <string name="button1">Button1</string>
+    <string name="button1">B1</string>
 
     <!-- String Button2 text -->
-    <string name="button2">Button2</string>
+    <string name="button2">B2</string>
 
     <!-- String Button3 text -->
-    <string name="button3">Button3</string>
+    <string name="button3">B3</string>
 
     <!-- String Button4 text -->
-    <string name="button4">Button4</string>
+    <string name="button4">B4</string>
 
     <!-- String Button5 text -->
-    <string name="button5">Button5</string>
+    <string name="button5">B5</string>
 
     <!-- String Button6 text -->
-    <string name="button6">Button6</string>
+    <string name="button6">B6</string>
 
     <!-- String with content description for Button6 -->
     <string name="contentDescription">contentDescription</string>
 
     <!-- String Button7 text -->
-    <string name="button7">Button7</string>
+    <string name="button7">B7</string>
 
     <!-- String Button8 text -->
-    <string name="button8">Button8</string>
+    <string name="button8">B8</string>
 
     <!-- String Button9 text -->
-    <string name="button9">Button9</string>
+    <string name="button9">B9</string>
 
     <!-- AccessibilityFocusTest -->
 
@@ -87,37 +87,37 @@
     <string name="accessibility_view_tree_reporting_test_activity">Accessibility view three reporting test</string>
 
     <!-- String root LinearLayout text -->
-    <string name="rootLinearLayout">rootLinearLayout</string>
+    <string name="rootLinearLayout">rLL</string>
 
     <!-- String first FrameLayout text -->
-    <string name="firstFrameLayout">firstFrameLayout</string>
+    <string name="firstFrameLayout">fFL</string>
 
     <!-- String first LinearLayout text -->
-    <string name="firstLinearLayout">firstLinearLayout</string>
+    <string name="firstLinearLayout">fLL</string>
 
     <!-- String first TextView text -->
-    <string name="firstTextView">firstTextView</string>
+    <string name="firstTextView">fTV</string>
 
     <!-- String first EditText text -->
-    <string name="firstEditText">firstEditText</string>
+    <string name="firstEditText">fET</string>
 
     <!-- String first Button text -->
-    <string name="firstButton">firstButton</string>
+    <string name="firstButton">fB</string>
 
     <!-- String second FrameLayout text -->
-    <string name="secondFrameLayout">secondFrameLayout</string>
+    <string name="secondFrameLayout">sFL</string>
 
     <!-- String second LinearLayout text -->
-    <string name="secondLinearLayout">secondLinearLayout</string>
+    <string name="secondLinearLayout">sLL</string>
 
     <!-- String second TextView text -->
-    <string name="secondTextView">secondTextView</string>
+    <string name="secondTextView">sTV</string>
 
     <!-- String second EditText text -->
-    <string name="secondEditText">secondEditText</string>
+    <string name="secondEditText">sET</string>
 
     <!-- String second Button text -->
-    <string name="secondButton">secondButton</string>
+    <string name="secondButton">sB</string>
 
     <!-- String title of the accessibility focus and input focus sync test activity -->
     <string name="accessibility_focus_and_input_focus_sync_test_activity">Accessibility focus and input focus sync test</string>
@@ -126,14 +126,11 @@
     <string name="accessibility_text_traversal_test_activity">Accessibility text traversal test</string>
 
     <string name="android_wiki_short">
-        Android is a Linux-based operating system for mobile devices</string>
+        Android is a Linux-based operating</string>
 
     <string name="android_wiki">
         Android is a Linux-based operating system for mobile devices such as smartphones and tablet
-        computers. It is developed by the Open Handset Alliance, led by Google, and other companies.
-        Google purchased the initial developer of the software, Android Inc., in 2005. The
-        unveiling of the Android distribution in 2007 was announced with the founding of the Open
-        Handset Alliance, a consortium of 86 hardware, software, and telecommunication </string>
+        computers. It is developed by the Open Handset Alliance, more</string>
 
     <string name="a_b">A B</string>
 
@@ -142,12 +139,7 @@
     <string name="foo_bar_baz">Foo bar baz.</string>
 
     <string name="android_wiki_paragraphs">
-        \n\nAndroid is a Linux-based operating system for mobile devices such as smartphones and tablet
-        computers.\n\n It is developed by the Open Handset Alliance, led by Google, and other companies.
-        Google purchased the initial developer of the software, Android Inc., in 2005.\n The
-        unveiling of the Android distribution in 2007 was announced with the founding of the Open
-        Handset Alliance, a consortium of 86 hardware, software, and telecommunication companies
-        devoted to advancing open standards for mobile devices. Google releases the
-        Android code as open-source, under the Apache License.\n\n</string>
+        \n\nAndroid is a\n\n It is developed\n The
+        unveiling\n\n</string>
 
 </resources>
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
index c7e4f4c..c121071 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityActivityTestCase.java
@@ -22,12 +22,13 @@
 import android.test.ActivityInstrumentationTestCase2;
 import android.view.accessibility.AccessibilityEvent;
 
+import java.util.concurrent.TimeoutException;
+
 /**
  * Base text case for testing accessibility APIs by instrumenting an Activity.
  */
 public abstract class AccessibilityActivityTestCase<T extends Activity>
         extends ActivityInstrumentationTestCase2<T> {
-
     /**
      * Timeout required for pending Binder calls or event processing to
      * complete.
@@ -37,7 +38,7 @@
     /**
      * The timeout since the last accessibility event to consider the device idle.
      */
-    public static final long TIMEOUT_ACCESSIBILITY_STATE_IDLE = 200;
+    public static final long TIMEOUT_ACCESSIBILITY_STATE_IDLE = 500;
 
     /**
      * @param activityClass
@@ -55,11 +56,20 @@
         info.flags &= ~AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
         getInstrumentation().getUiAutomation().setServiceInfo(info);
 
+        startActivityAndWaitForFirstEvent();
+
+        waitForIdle();
+    }
+
+    /**
+     * Waits for the UI do be idle.
+     *
+     * @throws TimeoutException if idle cannot be detected.
+     */
+    public void waitForIdle() throws TimeoutException {
         getInstrumentation().getUiAutomation().waitForIdle(
                 TIMEOUT_ACCESSIBILITY_STATE_IDLE,
                 TIMEOUT_ASYNC_PROCESSING);
-
-        startActivityAndWaitForFirstEvent();
     }
 
     /**
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndActivity.java
index 12bcd96..157a3dc 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndActivity.java
@@ -18,7 +18,6 @@
 
 import com.android.cts.accessibilityservice.R;
 
-import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
 import android.view.ViewGroup;
@@ -28,11 +27,11 @@
 import android.widget.TextView;
 
 /**
- * This class is an {@link Activity} used to perform end-to-end
+ * This class is an {@link android.app.Activity} used to perform end-to-end
  * testing of the accessibility feature by interaction with the
  * UI widgets.
  */
-public class AccessibilityEndToEndActivity extends Activity {
+public class AccessibilityEndToEndActivity extends AccessibilityTestActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
index 7e05e32..f0f0dd7 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityEndToEndTest.java
@@ -368,7 +368,6 @@
             && first.getCurrentItemIndex() == second.getCurrentItemIndex()
             && first.isEnabled() == second.isEnabled()
             && first.getFromIndex() == second.getFromIndex()
-            && first.isFullScreen() == second.isFullScreen()
             && first.getItemCount() == second.getItemCount()
             && first.isPassword() == second.isPassword()
             && first.getRemovedCount() == second.getRemovedCount()
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityFocusAndInputFocusSyncActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityFocusAndInputFocusSyncActivity.java
index cdd2e42..46f04aa 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityFocusAndInputFocusSyncActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityFocusAndInputFocusSyncActivity.java
@@ -14,7 +14,6 @@
 
 package android.accessibilityservice.cts;
 
-import android.app.Activity;
 import android.os.Bundle;
 
 import com.android.cts.accessibilityservice.R;
@@ -26,7 +25,7 @@
  * this activity is for verifying the the sync between accessibility
  * and input focus.
  */
-public class AccessibilityFocusAndInputFocusSyncActivity extends Activity {
+public class AccessibilityFocusAndInputFocusSyncActivity extends AccessibilityTestActivity {
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTestActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTestActivity.java
new file mode 100644
index 0000000..4d9b97d
--- /dev/null
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTestActivity.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2014 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 android.accessibilityservice.cts;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.WindowManager;
+
+public abstract class AccessibilityTestActivity extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+    }
+}
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalActivity.java
index 7c9b45a..4a4a4ba 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalActivity.java
@@ -14,7 +14,6 @@
 
 package android.accessibilityservice.cts;
 
-import android.app.Activity;
 import android.os.Bundle;
 
 import com.android.cts.accessibilityservice.R;
@@ -23,7 +22,7 @@
  * Activity for testing the accessibility APIs for traversing the
  * text content of a View at several granularities.
  */
-public class AccessibilityTextTraversalActivity extends Activity {
+public class AccessibilityTextTraversalActivity extends AccessibilityTestActivity {
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
index cbaf5d2..bdc0cd5 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
@@ -15,6 +15,7 @@
 package android.accessibilityservice.cts;
 
 import android.app.UiAutomation;
+import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.test.suitebuilder.annotation.MediumTest;
 import android.text.Selection;
@@ -46,6 +47,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                view.setVisibility(View.VISIBLE);
                 view.setContentDescription(getString(R.string.a_b));
             }
         });
@@ -260,6 +262,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                view.setVisibility(View.VISIBLE);
                 view.setContentDescription(getString(R.string.foo_bar_baz));
             }
         });
@@ -474,6 +477,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                textView.setVisibility(View.VISIBLE);
                 textView.setText(getString(R.string.a_b));
             }
         });
@@ -722,6 +726,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.a_b));
                 Selection.removeSelection(editText.getText());
             }
@@ -1220,6 +1225,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                textView.setVisibility(View.VISIBLE);
                 textView.setText(getString(R.string.foo_bar_baz));
             }
         });
@@ -1463,12 +1469,12 @@
     @MediumTest
     public void testActionNextAndPreviousAtGranularityWordOverEditTextWithContentDescription()
             throws Exception {
-
         final EditText editText = (EditText) getActivity().findViewById(R.id.edit);
 
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.foo_bar_baz));
                 editText.setContentDescription(getString(R.string.android_wiki));
             }
@@ -1723,6 +1729,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.foo_bar_baz));
                 Selection.removeSelection(editText.getText());
             }
@@ -2217,6 +2224,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                textView.setVisibility(View.VISIBLE);
                 textView.setText(getString(R.string.android_wiki_short));
             }
         });
@@ -2258,7 +2266,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 25
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2268,8 +2276,8 @@
         assertNotNull(firstExpected);
 
         // Verify the selection position.
-        assertEquals(25, Selection.getSelectionStart(textView.getText()));
-        assertEquals(25, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(13, Selection.getSelectionStart(textView.getText()));
+        assertEquals(13, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -2292,8 +2300,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 25
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                  AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2303,8 +2311,8 @@
         assertNotNull(secondExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(textView.getText()));
-        assertEquals(53, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(25, Selection.getSelectionStart(textView.getText()));
+        assertEquals(25, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -2327,8 +2335,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 53
-                        && event.getToIndex() == 60
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2338,16 +2346,16 @@
         assertNotNull(thirdExpected);
 
         // Verify the selection position.
-        assertEquals(60, Selection.getSelectionStart(textView.getText()));
-        assertEquals(60, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(34, Selection.getSelectionStart(textView.getText()));
+        assertEquals(34, Selection.getSelectionEnd(textView.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
                 AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(60, Selection.getSelectionStart(textView.getText()));
-        assertEquals(60, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(34, Selection.getSelectionStart(textView.getText()));
+        assertEquals(34, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent fourthExpected = getInstrumentation().getUiAutomation()
@@ -2370,8 +2378,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 53
-                        && event.getToIndex() == 60
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2381,8 +2389,8 @@
         assertNotNull(fourthExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(textView.getText()));
-        assertEquals(53, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(25, Selection.getSelectionStart(textView.getText()));
+        assertEquals(25, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -2405,8 +2413,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 25
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2416,8 +2424,8 @@
         assertNotNull(fifthExpected);
 
         // Verify the selection position.
-        assertEquals(25, Selection.getSelectionStart(textView.getText()));
-        assertEquals(25, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(13, Selection.getSelectionStart(textView.getText()));
+        assertEquals(13, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -2441,7 +2449,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 25
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2470,6 +2478,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.android_wiki_short));
                 Selection.removeSelection(editText.getText());
             }
@@ -2513,7 +2522,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 19
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2524,7 +2533,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(19, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(13, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -2547,8 +2556,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 19
-                        && event.getToIndex() == 35
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2559,7 +2568,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(35, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(25, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -2582,8 +2591,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 35
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                  AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2594,7 +2603,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent fourthExpected = getInstrumentation().getUiAutomation()
@@ -2617,8 +2626,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 35
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2629,7 +2638,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(35, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(25, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -2652,8 +2661,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 19
-                        && event.getToIndex() == 35
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2664,7 +2673,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(19, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(13, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -2688,7 +2697,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 19
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2720,14 +2729,14 @@
 
         // Put selection at the end of the text.
         Bundle setSelectionArgs = new Bundle();
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 53);
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 53);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 34);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 34);
         assertTrue(text.performAction(
                 AccessibilityNodeInfo.ACTION_SET_SELECTION, setSelectionArgs));
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(34, Selection.getSelectionEnd(editText.getText()));
 
         // Unocus the view so we can hide the keyboard.
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -2759,8 +2768,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 35
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2770,8 +2779,8 @@
         assertNotNull(seventhExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(35, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(25, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent eightExpected = getInstrumentation().getUiAutomation()
@@ -2794,8 +2803,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 19
-                        && event.getToIndex() == 35
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2805,8 +2814,8 @@
         assertNotNull(eightExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(19, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(13, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous line and wait for an event.
         AccessibilityEvent ninethExpected = getInstrumentation().getUiAutomation()
@@ -2830,7 +2839,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 19
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2840,7 +2849,7 @@
         assertNotNull(ninethExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
         assertEquals(0, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no previous.
@@ -2848,7 +2857,7 @@
                 AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
         assertEquals(0, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next line and wait for an event.
@@ -2873,7 +2882,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 19
+                        && event.getToIndex() == 13
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2883,8 +2892,8 @@
         assertNotNull(tenthExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(19, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(13, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent eleventhExpected = getInstrumentation().getUiAutomation()
@@ -2907,8 +2916,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 19
-                        && event.getToIndex() == 35
+                        && event.getFromIndex() == 13
+                        && event.getToIndex() == 25
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2918,8 +2927,8 @@
         assertNotNull(eleventhExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(35, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(25, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next line and wait for an event.
         AccessibilityEvent twelvethExpected = getInstrumentation().getUiAutomation()
@@ -2942,8 +2951,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_short))
-                        && event.getFromIndex() == 35
-                        && event.getToIndex() == 53
+                        && event.getFromIndex() == 25
+                        && event.getToIndex() == 34
                         && event.getMovementGranularity() ==
                                  AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE);
             }
@@ -2953,8 +2962,8 @@
         assertNotNull(twelvethExpected);
 
         // Verify the selection position.
-        assertEquals(53, Selection.getSelectionStart(editText.getText()));
-        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(34, Selection.getSelectionStart(editText.getText()));
+        assertEquals(34, Selection.getSelectionEnd(editText.getText()));
     }
 
     @MediumTest
@@ -2964,6 +2973,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.android_wiki));
                 Selection.removeSelection(editText.getText());
             }
@@ -3006,7 +3016,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3016,8 +3026,8 @@
         assertNotNull(firstExpected);
 
         // Verify the selection position.
-        assertEquals(139, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(53, Selection.getSelectionStart(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -3040,8 +3050,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3051,8 +3061,8 @@
         assertNotNull(secondExpected);
 
         // Verify the selection position.
-        assertEquals(285, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(103, Selection.getSelectionStart(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -3075,8 +3085,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3086,16 +3096,16 @@
         assertNotNull(thirdExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(436, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
                 AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(436, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent fourthExpected = getInstrumentation().getUiAutomation()
@@ -3118,8 +3128,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3129,8 +3139,8 @@
         assertNotNull(fourthExpected);
 
         // Verify the selection position.
-        assertEquals(285, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(103, Selection.getSelectionStart(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -3153,8 +3163,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3164,8 +3174,8 @@
         assertNotNull(fifthExpected);
 
         // Verify the selection position.
-        assertEquals(139, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(53, Selection.getSelectionStart(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -3189,7 +3199,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3218,6 +3228,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.android_wiki));
                 Selection.removeSelection(editText.getText());
             }
@@ -3261,7 +3272,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3272,7 +3283,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -3295,8 +3306,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3307,7 +3318,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -3330,8 +3341,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3342,7 +3353,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(436, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
@@ -3369,8 +3380,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3381,7 +3392,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -3404,8 +3415,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3416,7 +3427,7 @@
 
         // Verify the selection position.
         assertEquals(0, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -3440,7 +3451,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3472,14 +3483,14 @@
 
         // Put selection at the end of the text.
         Bundle setSelectionArgs = new Bundle();
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 436);
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 436);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 153);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 153);
         assertTrue(text.performAction(
                 AccessibilityNodeInfo.ACTION_SET_SELECTION, setSelectionArgs));
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(436, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionEnd(editText.getText()));
 
         // Unfocus the view so we can hide the soft-keyboard.
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -3511,8 +3522,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3522,8 +3533,8 @@
         assertNotNull(seventhExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent eightExpected = getInstrumentation().getUiAutomation()
@@ -3546,8 +3557,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3557,8 +3568,8 @@
         assertNotNull(eightExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous page and wait for an event.
         AccessibilityEvent ninethExpected = getInstrumentation().getUiAutomation()
@@ -3582,7 +3593,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3592,7 +3603,7 @@
         assertNotNull(ninethExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
         assertEquals(0, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no previous.
@@ -3600,7 +3611,7 @@
                 AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
         assertEquals(0, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
@@ -3625,7 +3636,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
                         && event.getFromIndex() == 0
-                        && event.getToIndex() == 139
+                        && event.getToIndex() == 53
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3635,8 +3646,8 @@
         assertNotNull(tenthExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(139, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(53, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent eleventhExpected = getInstrumentation().getUiAutomation()
@@ -3659,8 +3670,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 139
-                        && event.getToIndex() == 285
+                        && event.getFromIndex() == 53
+                        && event.getToIndex() == 103
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3670,8 +3681,8 @@
         assertNotNull(eleventhExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(285, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(103, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next page and wait for an event.
         AccessibilityEvent twelvethExpected = getInstrumentation().getUiAutomation()
@@ -3694,8 +3705,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki))
-                        && event.getFromIndex() == 285
-                        && event.getToIndex() == 436
+                        && event.getFromIndex() == 103
+                        && event.getToIndex() == 153
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
             }
@@ -3705,8 +3716,8 @@
         assertNotNull(twelvethExpected);
 
         // Verify the selection position.
-        assertEquals(436, Selection.getSelectionStart(editText.getText()));
-        assertEquals(436, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(153, Selection.getSelectionStart(editText.getText()));
+        assertEquals(153, Selection.getSelectionEnd(editText.getText()));
     }
 
     @MediumTest
@@ -3716,13 +3727,14 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                textView.setVisibility(View.VISIBLE);
                 textView.setText(getString(R.string.android_wiki_paragraphs));
             }
         });
 
         final AccessibilityNodeInfo text = getInstrumentation().getUiAutomation()
                .getRootInActiveWindow().findAccessibilityNodeInfosByText(getString(
-                       R.string.android_wiki_short)).get(0);
+                       R.string.android_wiki_paragraphs)).get(0);
 
         final int granularities = text.getMovementGranularities();
         assertEquals(granularities, AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
@@ -3757,7 +3769,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                  AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3767,8 +3779,8 @@
         assertNotNull(firstExpected);
 
         // Verify the selection position.
-        assertEquals(104, Selection.getSelectionStart(textView.getText()));
-        assertEquals(104, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(14, Selection.getSelectionStart(textView.getText()));
+        assertEquals(14, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -3791,8 +3803,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3802,8 +3814,8 @@
         assertNotNull(secondExpected);
 
         // Verify the selection position.
-        assertEquals(267, Selection.getSelectionStart(textView.getText()));
-        assertEquals(267, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(32, Selection.getSelectionStart(textView.getText()));
+        assertEquals(32, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -3826,8 +3838,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3837,16 +3849,16 @@
         assertNotNull(thirdExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(textView.getText()));
-        assertEquals(582, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(47, Selection.getSelectionStart(textView.getText()));
+        assertEquals(47, Selection.getSelectionEnd(textView.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
                 AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(textView.getText()));
-        assertEquals(582, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(47, Selection.getSelectionStart(textView.getText()));
+        assertEquals(47, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent fourthExpected = getInstrumentation().getUiAutomation()
@@ -3869,8 +3881,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                  AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3880,8 +3892,8 @@
         assertNotNull(fourthExpected);
 
         // Verify the selection position.
-        assertEquals(268, Selection.getSelectionStart(textView.getText()));
-        assertEquals(268, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(33, Selection.getSelectionStart(textView.getText()));
+        assertEquals(33, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -3904,8 +3916,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3915,8 +3927,8 @@
         assertNotNull(fifthExpected);
 
         // Verify the selection position.
-        assertEquals(106, Selection.getSelectionStart(textView.getText()));
-        assertEquals(106, Selection.getSelectionEnd(textView.getText()));
+        assertEquals(16, Selection.getSelectionStart(textView.getText()));
+        assertEquals(16, Selection.getSelectionEnd(textView.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -3940,7 +3952,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -3969,6 +3981,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setText(getString(R.string.android_wiki_paragraphs));
                 Selection.removeSelection(editText.getText());
             }
@@ -3976,7 +3989,7 @@
 
         final AccessibilityNodeInfo text = getInstrumentation().getUiAutomation()
                .getRootInActiveWindow().findAccessibilityNodeInfosByText(getString(
-                       R.string.android_wiki_short)).get(0);
+                       R.string.android_wiki_paragraphs)).get(0);
 
         final int granularities = text.getMovementGranularities();
         assertEquals(granularities, AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
@@ -4012,7 +4025,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4023,7 +4036,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(104, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(14, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent secondExpected = getInstrumentation().getUiAutomation()
@@ -4046,8 +4059,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4058,7 +4071,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(267, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(32, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent thirdExpected = getInstrumentation().getUiAutomation()
@@ -4081,8 +4094,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4093,7 +4106,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(582, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
@@ -4101,7 +4114,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(582, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent fourthExpected = getInstrumentation().getUiAutomation()
@@ -4124,8 +4137,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4136,7 +4149,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(268, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(33, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent fifthExpected = getInstrumentation().getUiAutomation()
@@ -4159,8 +4172,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4171,7 +4184,7 @@
 
         // Verify the selection position.
         assertEquals(2, Selection.getSelectionStart(editText.getText()));
-        assertEquals(106, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(16, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent sixthExpected = getInstrumentation().getUiAutomation()
@@ -4195,7 +4208,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4227,14 +4240,14 @@
 
         // Put selection at the end of the text.
         Bundle setSelectionArgs = new Bundle();
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 582);
-        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 582);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, 47);
+        setSelectionArgs.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, 47);
         assertTrue(text.performAction(
                 AccessibilityNodeInfo.ACTION_SET_SELECTION, setSelectionArgs));
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(582, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(47, Selection.getSelectionEnd(editText.getText()));
 
         // Unfocus the view so we can get rid of the soft-keyboard.
         getInstrumentation().runOnMainSync(new Runnable() {
@@ -4266,8 +4279,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4277,8 +4290,8 @@
         assertNotNull(seventhExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(268, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(33, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent eightExpected = getInstrumentation().getUiAutomation()
@@ -4301,8 +4314,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4312,8 +4325,8 @@
         assertNotNull(eightExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(106, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(16, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the previous paragraph and wait for an event.
         AccessibilityEvent ninethExpected = getInstrumentation().getUiAutomation()
@@ -4337,7 +4350,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4347,7 +4360,7 @@
         assertNotNull(ninethExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
         assertEquals(2, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no previous.
@@ -4355,7 +4368,7 @@
                 AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
         assertEquals(2, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next paragraph and wait for an event.
@@ -4380,7 +4393,7 @@
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
                         && event.getFromIndex() == 2
-                        && event.getToIndex() == 104
+                        && event.getToIndex() == 14
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4390,8 +4403,8 @@
         assertNotNull(tenthExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(104, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(14, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent eleventhExpected = getInstrumentation().getUiAutomation()
@@ -4414,8 +4427,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 106
-                        && event.getToIndex() == 267
+                        && event.getFromIndex() == 16
+                        && event.getToIndex() == 32
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4425,8 +4438,8 @@
         assertNotNull(eleventhExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(267, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(32, Selection.getSelectionEnd(editText.getText()));
 
         // Move to the next paragraph and wait for an event.
         AccessibilityEvent twlevethExpected = getInstrumentation().getUiAutomation()
@@ -4449,8 +4462,8 @@
                         && event.getText().size() > 0
                         && event.getText().get(0).toString().equals(getString(
                                 R.string.android_wiki_paragraphs))
-                        && event.getFromIndex() == 268
-                        && event.getToIndex() == 582
+                        && event.getFromIndex() == 33
+                        && event.getToIndex() == 47
                         && event.getMovementGranularity() ==
                                 AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH);
             }
@@ -4460,26 +4473,32 @@
         assertNotNull(twlevethExpected);
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(582, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(47, Selection.getSelectionEnd(editText.getText()));
 
         // Make sure there is no next.
         assertFalse(text.performAction(
                 AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY, arguments));
 
         // Verify the selection position.
-        assertEquals(582, Selection.getSelectionStart(editText.getText()));
-        assertEquals(582, Selection.getSelectionEnd(editText.getText()));
+        assertEquals(47, Selection.getSelectionStart(editText.getText()));
+        assertEquals(47, Selection.getSelectionEnd(editText.getText()));
     }
 
     @MediumTest
     public void testTextEditingActions() throws Exception {
+        if (!getActivity().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_INPUT_METHODS)) {
+            return;
+        }
+
         final EditText editText = (EditText) getActivity().findViewById(R.id.edit);
         final String textContent = getString(R.string.foo_bar_baz);
 
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                editText.setVisibility(View.VISIBLE);
                 editText.setFocusable(true);
                 editText.requestFocus();
                 editText.setText(getString(R.string.foo_bar_baz));
@@ -4500,7 +4519,7 @@
                 AccessibilityNodeInfo.ACTION_SET_SELECTION, arguments));
 
         // Copy the selected text.
-        text.performAction( AccessibilityNodeInfo.ACTION_COPY);
+        text.performAction(AccessibilityNodeInfo.ACTION_COPY);
 
         // Set selection at the end.
         final int textLength = editText.getText().length();
@@ -4536,6 +4555,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                view.setVisibility(View.VISIBLE);
                 view.setContentDescription(getString(R.string.foo_bar_baz));
             }
         });
@@ -4564,6 +4584,7 @@
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
             public void run() {
+                view.setVisibility(View.VISIBLE);
                 view.setContentDescription(getString(R.string.foo_bar_baz));
             }
         });
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityViewTreeReportingActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityViewTreeReportingActivity.java
index 5aaa067..6aa4f44 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityViewTreeReportingActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityViewTreeReportingActivity.java
@@ -14,7 +14,6 @@
 
 package android.accessibilityservice.cts;
 
-import android.app.Activity;
 import android.os.Bundle;
 
 import com.android.cts.accessibilityservice.R;
@@ -26,7 +25,7 @@
  * this activity is for verifying the hierarchical movement of the
  * accessibility focus.
  */
-public class AccessibilityViewTreeReportingActivity extends Activity {
+public class AccessibilityViewTreeReportingActivity extends AccessibilityTestActivity {
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivity.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivity.java
index 6f72a75..b0cedf6 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivity.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryActivity.java
@@ -14,7 +14,6 @@
 
 package android.accessibilityservice.cts;
 
-import android.app.Activity;
 import android.os.Bundle;
 import android.view.View;
 
@@ -26,7 +25,7 @@
  * requesting an action to be performed on a given view from an
  * AccessiiblityService.
  */
-public class AccessibilityWindowQueryActivity extends Activity {
+public class AccessibilityWindowQueryActivity extends AccessibilityTestActivity {
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
diff --git a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
index 0ea9a7f..492b99b 100644
--- a/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
+++ b/tests/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
@@ -27,7 +27,6 @@
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.app.UiAutomation;
 import android.graphics.Rect;
-import android.os.SystemClock;
 import android.test.suitebuilder.annotation.MediumTest;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
@@ -55,7 +54,7 @@
     public void testFindByText() throws Exception {
         // find a view by text
         List<AccessibilityNodeInfo> buttons = getInstrumentation().getUiAutomation()
-                .getRootInActiveWindow().findAccessibilityNodeInfosByText("butto");
+                .getRootInActiveWindow().findAccessibilityNodeInfosByText("b");
         assertEquals(9, buttons.size());
     }
 
@@ -77,22 +76,22 @@
 
             // make list of expected nodes
             List<String> classNameAndTextList = new ArrayList<String>();
-            classNameAndTextList.add("android.widget.FrameLayout");
-            classNameAndTextList.add("android.widget.LinearLayout");
-            classNameAndTextList.add("android.widget.FrameLayout");
             classNameAndTextList.add("android.widget.LinearLayout");
             classNameAndTextList.add("android.widget.LinearLayout");
             classNameAndTextList.add("android.widget.LinearLayout");
             classNameAndTextList.add("android.widget.LinearLayout");
-            classNameAndTextList.add("android.widget.ButtonButton1");
-            classNameAndTextList.add("android.widget.ButtonButton2");
-            classNameAndTextList.add("android.widget.ButtonButton3");
-            classNameAndTextList.add("android.widget.ButtonButton4");
-            classNameAndTextList.add("android.widget.ButtonButton5");
-            classNameAndTextList.add("android.widget.ButtonButton6");
-            classNameAndTextList.add("android.widget.ButtonButton7");
-            classNameAndTextList.add("android.widget.ButtonButton8");
-            classNameAndTextList.add("android.widget.ButtonButton9");
+            classNameAndTextList.add("android.widget.ButtonB1");
+            classNameAndTextList.add("android.widget.ButtonB2");
+            classNameAndTextList.add("android.widget.ButtonB3");
+            classNameAndTextList.add("android.widget.ButtonB4");
+            classNameAndTextList.add("android.widget.ButtonB5");
+            classNameAndTextList.add("android.widget.ButtonB6");
+            classNameAndTextList.add("android.widget.ButtonB7");
+            classNameAndTextList.add("android.widget.ButtonB8");
+            classNameAndTextList.add("android.widget.ButtonB9");
+
+            String contentViewIdResName = "com.android.cts.accessibilityservice:id/added_content";
+            boolean verifyContent = false;
 
             Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
             fringe.add(getInstrumentation().getUiAutomation().getRootInActiveWindow());
@@ -101,13 +100,20 @@
             while (!fringe.isEmpty()) {
                 AccessibilityNodeInfo current = fringe.poll();
 
-                CharSequence text = current.getText();
-                String receivedClassNameAndText = current.getClassName().toString()
-                    + ((text != null) ? text.toString() : "");
-                String expectedClassNameAndText = classNameAndTextList.remove(0);
+                if (!verifyContent
+                        && contentViewIdResName.equals(current.getViewIdResourceName())) {
+                    verifyContent = true;
+                }
 
-                assertEquals("Did not get the expected node info",
-                        expectedClassNameAndText, receivedClassNameAndText);
+                if (verifyContent) {
+                    CharSequence text = current.getText();
+                    String receivedClassNameAndText = current.getClassName().toString()
+                            + ((text != null) ? text.toString() : "");
+                    String expectedClassNameAndText = classNameAndTextList.remove(0);
+
+                    assertEquals("Did not get the expected node info",
+                            expectedClassNameAndText, receivedClassNameAndText);
+                }
 
                 final int childCount = current.getChildCount();
                 for (int i = 0; i < childCount; i++) {
@@ -327,7 +333,7 @@
                 AccessibilityService.GLOBAL_ACTION_BACK));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
     }
 
     @MediumTest
@@ -336,7 +342,7 @@
                 AccessibilityService.GLOBAL_ACTION_HOME));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
     }
 
     @MediumTest
@@ -346,14 +352,14 @@
                 AccessibilityService.GLOBAL_ACTION_RECENTS));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
 
         // Clean up.
         getInstrumentation().getUiAutomation().performGlobalAction(
                 AccessibilityService.GLOBAL_ACTION_BACK);
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
     }
 
     @MediumTest
@@ -363,14 +369,14 @@
                 AccessibilityService.GLOBAL_ACTION_NOTIFICATIONS));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
 
         // Clean up.
         assertTrue(getInstrumentation().getUiAutomation().performGlobalAction(
                 AccessibilityService.GLOBAL_ACTION_BACK));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
     }
 
     @MediumTest
@@ -380,14 +386,14 @@
                 AccessibilityService.GLOBAL_ACTION_QUICK_SETTINGS));
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
 
         // Clean up.
         getInstrumentation().getUiAutomation().performGlobalAction(
                 AccessibilityService.GLOBAL_ACTION_BACK);
 
         // Sleep a bit so the UI is settles.
-        SystemClock.sleep(3000);
+        waitForIdle();
     }
 
     @MediumTest
diff --git a/tests/tests/app/src/android/app/cts/ActionBarActivity.java b/tests/tests/app/src/android/app/cts/ActionBarActivity.java
index 11cee03..dc65cb2 100644
--- a/tests/tests/app/src/android/app/cts/ActionBarActivity.java
+++ b/tests/tests/app/src/android/app/cts/ActionBarActivity.java
@@ -25,6 +25,8 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         ActionBar bar = getActionBar();
-        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+        if (bar != null) {
+            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
+        }
     }
 }
diff --git a/tests/tests/app/src/android/app/cts/ActionBarTest.java b/tests/tests/app/src/android/app/cts/ActionBarTest.java
index 796cd74..75e7807 100644
--- a/tests/tests/app/src/android/app/cts/ActionBarTest.java
+++ b/tests/tests/app/src/android/app/cts/ActionBarTest.java
@@ -40,6 +40,9 @@
 
     @UiThreadTest
     public void testAddTab() {
+        if (mBar == null) {
+            return;
+        }
         assertEquals(0, mBar.getTabCount());
 
         Tab t1 = createTab("Tab 1");
diff --git a/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java b/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java
index 5c80fd1..c4318d8 100644
--- a/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java
+++ b/tests/tests/app/src/android/app/cts/SystemFeaturesTest.java
@@ -114,6 +114,9 @@
             assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
             assertNotAvailable(PackageManager.FEATURE_CAMERA_FRONT);
             assertNotAvailable(PackageManager.FEATURE_CAMERA_ANY);
+            assertFalse("Devices supporting external cameras must have a representative camera " +
+                    "connected for testing",
+                    mPackageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL));
         } else {
             assertAvailable(PackageManager.FEATURE_CAMERA_ANY);
             checkFrontCamera();
@@ -234,6 +237,8 @@
                 Sensor.TYPE_STEP_COUNTER);
         assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_STEP_DETECTOR,
                 Sensor.TYPE_STEP_DETECTOR);
+        assertFeatureForSensor(featuresLeft, PackageManager.FEATURE_SENSOR_HEART_RATE,
+                Sensor.TYPE_HEART_RATE);
 
         assertTrue("Assertions need to be added to this test for " + featuresLeft,
                 featuresLeft.isEmpty());
diff --git a/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java b/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
index fdf3cac..65f89f3 100644
--- a/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/WallpaperManagerTest.java
@@ -33,26 +33,37 @@
         mWallpaperManager = WallpaperManager.getInstance(mContext);
     }
 
+    /**
+     * Suggesting desired dimensions is only a hint to the system that can be ignored.
+     *
+     * Test if the desired minimum width or height the WallpaperManager returns
+     * is greater than 0. If so, then we check whether that the size is at least the
+     * as big as the screen.
+     */
     public void testSuggestDesiredDimensions() {
-        Point min = getScreenSize();
-        int w = min.x * 3;
-        int h = min.y * 2;
+        final Point min = getScreenSize();
+        final int w = min.x * 3;
+        final int h = min.y * 2;
 
-        mWallpaperManager.suggestDesiredDimensions(min.x / 2, min.y / 2);
-        assertEquals(min.x, mWallpaperManager.getDesiredMinimumWidth());
-        assertEquals(min.y, mWallpaperManager.getDesiredMinimumHeight());
+        assertDesiredMinimum(new Point(min.x / 2, min.y / 2), min);
 
-        mWallpaperManager.suggestDesiredDimensions(w, h);
-        assertEquals(w, mWallpaperManager.getDesiredMinimumWidth());
-        assertEquals(h, mWallpaperManager.getDesiredMinimumHeight());
+        assertDesiredMinimum(new Point(w, h),
+                             new Point(w, h));
 
-        mWallpaperManager.suggestDesiredDimensions(min.x / 2, h);
-        assertEquals(min.x, mWallpaperManager.getDesiredMinimumWidth());
-        assertEquals(h, mWallpaperManager.getDesiredMinimumHeight());
+        assertDesiredMinimum(new Point(min.x / 2, h),
+                             new Point(min.x, h));
 
-        mWallpaperManager.suggestDesiredDimensions(w, min.y / 2);
-        assertEquals(w, mWallpaperManager.getDesiredMinimumWidth());
-        assertEquals(min.y, mWallpaperManager.getDesiredMinimumHeight());
+        assertDesiredMinimum(new Point(w, min.y / 2),
+                             new Point(w, min.y));
+    }
+
+    private void assertDesiredMinimum(Point suggestedSize, Point expectedSize) {
+        mWallpaperManager.suggestDesiredDimensions(suggestedSize.x, suggestedSize.y);
+        Point actualSize = new Point(mWallpaperManager.getDesiredMinimumWidth(),
+                mWallpaperManager.getDesiredMinimumHeight());
+        if (actualSize.x > 0 || actualSize.y > 0) {
+            assertEquals(expectedSize, actualSize);
+        }
     }
 
     private Point getScreenSize() {
diff --git a/tests/tests/bionic/bionic-unit-tests-cts_list.txt b/tests/tests/bionic/bionic-unit-tests-cts_list.txt
deleted file mode 100644
index 55daff5..0000000
--- a/tests/tests/bionic/bionic-unit-tests-cts_list.txt
+++ /dev/null
@@ -1,576 +0,0 @@
-Fortify1_Gcc_DeathTest.
-  strcpy_fortified
-  strcpy2_fortified
-  strcpy3_fortified
-  strcpy4_fortified
-  strlen_fortified
-  strchr_fortified
-  strrchr_fortified
-  strlcpy_fortified
-  strlcat_fortified
-  sprintf_fortified
-  sprintf2_fortified
-  vsprintf_fortified
-  vsprintf2_fortified
-  vsnprintf_fortified
-  vsnprintf2_fortified
-  strncat_fortified
-  strncat2_fortified
-  strcat_fortified
-  memmove_fortified
-  memcpy_fortified
-  strncpy_fortified
-  snprintf_fortified
-  bzero_fortified
-  umask_fortified
-Fortify2_Gcc_DeathTest.
-  strncpy_fortified2
-  sprintf_fortified2
-  sprintf2_fortified2
-  vsprintf_fortified2
-  vsprintf2_fortified2
-  vsnprintf_fortified2
-  vsnprintf2_fortified2
-  strcpy_fortified2
-  strcpy2_fortified2
-  strcpy3_fortified2
-  strchr_fortified2
-  strrchr_fortified2
-  strlcpy_fortified2
-  strlcat_fortified2
-  strncat_fortified2
-  strncat2_fortified2
-  strncat3_fortified2
-  strcat_fortified2
-  strcat2_fortified2
-  snprintf_fortified2
-  bzero_fortified2
-  strcpy_fortified
-  strcpy2_fortified
-  strcpy3_fortified
-  strcpy4_fortified
-  strlen_fortified
-  strchr_fortified
-  strrchr_fortified
-  strlcpy_fortified
-  strlcat_fortified
-  sprintf_fortified
-  sprintf2_fortified
-  vsprintf_fortified
-  vsprintf2_fortified
-  vsnprintf_fortified
-  vsnprintf2_fortified
-  strncat_fortified
-  strncat2_fortified
-  strcat_fortified
-  memmove_fortified
-  memcpy_fortified
-  strncpy_fortified
-  snprintf_fortified
-  bzero_fortified
-  umask_fortified
-Fortify1_Clang_DeathTest.
-  strcpy_fortified
-  strcpy2_fortified
-  strcpy3_fortified
-  strcpy4_fortified
-  strlen_fortified
-  strchr_fortified
-  strrchr_fortified
-  strlcpy_fortified
-  strlcat_fortified
-  sprintf_fortified
-  sprintf2_fortified
-  vsprintf_fortified
-  vsprintf2_fortified
-  vsnprintf_fortified
-  vsnprintf2_fortified
-  strncat_fortified
-  strncat2_fortified
-  strcat_fortified
-  memmove_fortified
-  memcpy_fortified
-  strncpy_fortified
-  snprintf_fortified
-  bzero_fortified
-  umask_fortified
-Fortify2_Clang_DeathTest.
-  strncat3_fortified2
-  strcat2_fortified2
-  snprintf_fortified2
-  bzero_fortified2
-  strcpy_fortified
-  strcpy2_fortified
-  strcpy3_fortified
-  strcpy4_fortified
-  strlen_fortified
-  strchr_fortified
-  strrchr_fortified
-  strlcpy_fortified
-  strlcat_fortified
-  sprintf_fortified
-  sprintf2_fortified
-  vsprintf_fortified
-  vsprintf2_fortified
-  vsnprintf_fortified
-  vsnprintf2_fortified
-  strncat_fortified
-  strncat2_fortified
-  strcat_fortified
-  memmove_fortified
-  memcpy_fortified
-  strncpy_fortified
-  snprintf_fortified
-  bzero_fortified
-  umask_fortified
-pthread_DeathTest.
-  pthread_bug_37410
-stack_protector_DeathTest.
-  modify_stack_protector
-properties_DeathTest.
-  read_only
-Fortify1_Gcc.
-  strncat
-  strncat2
-  strncat3
-  strncat4
-  strncat5
-  strncat6
-  strcat
-  strcat2
-  strcat_chk_max_int_size
-  strcpy_chk_max_int_size
-  memcpy_chk_max_int_size
-Fortify2_Gcc.
-  strncat
-  strncat2
-  strncat3
-  strncat4
-  strncat5
-  strncat6
-  strcat
-  strcat2
-  strcat_chk_max_int_size
-  strcpy_chk_max_int_size
-  memcpy_chk_max_int_size
-Fortify1_Clang.
-  strncat
-  strncat2
-  strncat3
-  strncat4
-  strncat5
-  strncat6
-  strcat
-  strcat2
-  strcat_chk_max_int_size
-  strcpy_chk_max_int_size
-  memcpy_chk_max_int_size
-Fortify2_Clang.
-  strncat
-  strncat2
-  strncat3
-  strncat4
-  strncat5
-  strncat6
-  strcat
-  strcat2
-  strcat_chk_max_int_size
-  strcpy_chk_max_int_size
-  memcpy_chk_max_int_size
-dirent.
-  scandir
-  fdopendir_invalid
-  fdopendir
-  opendir_invalid
-  opendir
-  closedir_invalid
-  closedir
-  readdir
-  readdir_r
-  rewinddir
-eventfd.
-  smoke
-fenv.
-  fesetround_fegetround_FE_TONEAREST
-  fesetround_fegetround_FE_TOWARDZERO
-  fesetround_fegetround_FE_UPWARD
-  fesetround_fegetround_FE_DOWNWARD
-  feclearexcept_fetestexcept
-  FE_DFL_ENV_macro
-getauxval.
-  expected_values
-  unexpected_values
-getcwd.
-  auto_full
-  auto_reasonable
-  auto_too_small
-  auto_too_large
-  manual_too_small
-  manual_zero
-  manual_path_max
-inttypes.
-  misc
-libc_logging.
-  smoke
-  d_INT_MAX
-  d_INT_MIN
-  ld_LONG_MAX
-  ld_LONG_MIN
-  lld_LLONG_MAX
-  lld_LLONG_MIN
-libgen.
-  basename
-  dirname
-  basename_r
-  dirname_r
-malloc.
-  malloc_std
-  calloc_std
-  memalign_multiple
-  memalign_realloc
-  malloc_realloc_larger
-  malloc_realloc_smaller
-  malloc_multiple_realloc
-  calloc_realloc_larger
-  calloc_realloc_smaller
-  calloc_multiple_realloc
-math.
-  fpclassify
-  isinf
-  isnan
-  isnormal
-  __fpclassifyd
-  __fpclassifyf
-  __fpclassifyl
-  finitef
-  __isfinite
-  __isfinitef
-  __isfinitel
-  finite
-  __isinff
-  __isinfl
-  __isnanf
-  __isnanl
-  isnanf
-  __isnormal
-  __isnormalf
-  __isnormall
-  __signbit
-  __signbitf
-  __signbitl
-  acos
-  acosf
-  acosl
-  asin
-  asinf
-  asinl
-  atan
-  atanf
-  atanl
-  atan2
-  atan2f
-  atan2l
-  cos
-  cosf
-  cosl
-  sin
-  sinf
-  sinl
-  tan
-  tanf
-  tanl
-  acosh
-  acoshf
-  acoshl
-  asinh
-  asinhf
-  asinhl
-  atanh
-  atanhf
-  atanhl
-  cosh
-  coshf
-  coshl
-  sinh
-  sinhf
-  sinhl
-  tanh
-  tanhf
-  tanhl
-  log
-  logf
-  logl
-  log2
-  log2f
-  log2l
-  log10
-  log10f
-  log10l
-  cbrt
-  cbrtf
-  cbrtl
-  sqrt
-  sqrtf
-  sqrtl
-  exp
-  expf
-  expl
-  exp2
-  exp2f
-  exp2l
-  expm1
-  expm1f
-  expm1l
-  pow
-  powf
-  powl
-  ceil
-  ceilf
-  ceill
-  floor
-  floorf
-  floorl
-  fabs
-  fabsf
-  fabsl
-  ldexp
-  ldexpf
-  ldexpl
-  fmod
-  fmodf
-  fmodl
-  remainder
-  remainderf
-  remainderl
-  drem
-  dremf
-  fmax
-  fmaxf
-  fmaxl
-  fmin
-  fminf
-  fminl
-  fma
-  fmaf
-  fmal
-  hypot
-  hypotf
-  hypotl
-  erf
-  erff
-  erfl
-  erfc
-  erfcf
-  erfcl
-  lrint
-  rint
-  nearbyint
-  lround
-  llround
-  ilogb
-  ilogbf
-  ilogbl
-  logb
-  logbf
-  logbl
-  log1p
-  log1pf
-  log1pl
-  fdim
-  fdimf
-  fdiml
-  round
-  roundf
-  roundl
-  trunc
-  truncf
-  truncl
-  nextafter
-  nextafterf
-  nextafterl
-  copysign
-  copysignf
-  copysignl
-  significand
-  significandf
-  significandl
-  scalb
-  scalbf
-  scalbln
-  scalblnf
-  scalblnl
-  scalbn
-  scalbnf
-  scalbnl
-  gamma
-  gammaf
-  gamma_r
-  gammaf_r
-  lgamma
-  lgammaf
-  lgammal
-  lgamma_r
-  lgammaf_r
-  tgamma
-  tgammaf
-  tgammal
-  j0
-  j0f
-  j1
-  j1f
-  jn
-  jnf
-  y0
-  y0f
-  y1
-  y1f
-  yn
-  ynf
-  frexp
-  frexpf
-  frexpl
-  modf
-  modff
-  modfl
-  remquo
-  remquof
-  remquol
-  frexpf_public_bug_6697
-netdb.
-  getaddrinfo_NULL_hints
-  getnameinfo_salen
-pthread.
-  pthread_key_create
-  pthread_key_create_lots
-  pthread_create
-  pthread_create_EAGAIN
-  pthread_no_join_after_detach
-  pthread_no_op_detach_after_join
-  pthread_join_self
-  pthread_sigmask
-  __pthread_clone
-  pthread_setname_np__too_long
-  pthread_setname_np__self
-  pthread_setname_np__other
-  pthread_setname_np__no_such_thread
-  pthread_kill__0
-  pthread_kill__invalid_signal
-  pthread_kill__in_signal_handler
-  pthread_detach__no_such_thread
-  pthread_getcpuclockid__clock_gettime
-  pthread_getcpuclockid__no_such_thread
-  pthread_getschedparam__no_such_thread
-  pthread_setschedparam__no_such_thread
-  pthread_join__no_such_thread
-  pthread_kill__no_such_thread
-  pthread_join__multijoin
-  pthread_attr_setguardsize
-  pthread_attr_setstacksize
-regex.
-  smoke
-signal.
-  sigismember_invalid
-  sigaddset_invalid
-  sigdelset_invalid
-  sigemptyset_invalid
-  sigfillset_invalid
-  raise_invalid
-  raise_in_signal_handler
-  sigwait
-stack_protector.
-  global_guard
-statvfs.
-  statvfs
-  fstatvfs
-stdio.
-  tmpfile_fileno_fprintf_rewind_fgets
-  getdelim
-  getdelim_invalid
-  getline
-  getline_invalid
-  printf_ssize_t
-  popen
-  getc
-  putc
-stdlib.
-  drand48
-  lrand48_random_rand
-  mrand48
-  posix_memalign
-  realpath__NULL_filename
-  realpath__empty_filename
-  realpath__ENOENT
-  realpath
-  qsort
-string.
-  strerror
-  strerror_concurrent
-  strerror_r
-  strsignal
-  strsignal_concurrent
-  strcat
-  strcpy2
-  strcpy3
-  strcpy4
-  strcat2
-  strcat3
-  strncat2
-  strncat3
-  strncat4
-  strncat5
-  strchr_with_0
-  strchr
-  strcmp
-  strcpy
-  strlcat
-  strlcpy
-  strncat
-  strncmp
-  strncpy
-  strrchr
-  memchr
-  memrchr
-  memcmp
-  __memcmp16
-  wmemcmp
-  memcpy
-  memset
-  memmove
-  bcopy
-  bzero
-strings.
-  ffs
-getpwnam.
-  system_id_root
-  system_id_system
-  app_id_radio
-  app_id_nobody
-  app_id_all_a0
-  app_id_u1_a40000
-  app_id_u0_a0
-  app_id_u0_a1234
-  app_id_u0_a9999
-  app_id_u1_root
-  app_id_u1_radio
-  app_id_u1_a0
-  app_id_u1_i0
-sys_stat.
-  futimens
-  futimens_EBADF
-properties.
-  add
-  update
-  fill
-  foreach
-  find_nth
-  fill_hierarchical
-  errors
-  serial
-  wait
-time.
-  mktime_tz
-  gmtime
-  mktime_10310929
-unistd.
-  sysconf_SC_MONOTONIC_CLOCK
-  sbrk
diff --git a/tests/tests/content/src/android/content/pm/cts/ResolveInfo_DisplayNameComparatorTest.java b/tests/tests/content/src/android/content/pm/cts/ResolveInfo_DisplayNameComparatorTest.java
deleted file mode 100644
index be3d99c..0000000
--- a/tests/tests/content/src/android/content/pm/cts/ResolveInfo_DisplayNameComparatorTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 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 android.content.pm.cts;
-
-
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.ResolveInfo.DisplayNameComparator;
-import android.test.AndroidTestCase;
-
-public class ResolveInfo_DisplayNameComparatorTest extends AndroidTestCase {
-    private static final String MAIN_ACTION_NAME = "android.intent.action.MAIN";
-    private static final String SERVICE_NAME = "android.content.pm.cts.activity.PMTEST_SERVICE";
-
-    public void testDisplayNameComparator() {
-        PackageManager pm = getContext().getPackageManager();
-        DisplayNameComparator dnc = new DisplayNameComparator(pm);
-
-        Intent intent = new Intent(MAIN_ACTION_NAME);
-        ResolveInfo activityInfo = pm.resolveActivity(intent, 0);
-
-        intent = new Intent(SERVICE_NAME);
-        ResolveInfo serviceInfo = pm.resolveService(intent, PackageManager.GET_RESOLVED_FILTER);
-
-        assertTrue(dnc.compare(activityInfo, serviceInfo) < 0);
-        assertTrue(dnc.compare(activityInfo, activityInfo) == 0);
-        assertTrue(dnc.compare(serviceInfo, activityInfo) > 0);
-    }
-}
diff --git a/tests/tests/display/src/android/display/cts/VirtualDisplayTest.java b/tests/tests/display/src/android/display/cts/VirtualDisplayTest.java
index 11bc15c..f2f859a 100644
--- a/tests/tests/display/src/android/display/cts/VirtualDisplayTest.java
+++ b/tests/tests/display/src/android/display/cts/VirtualDisplayTest.java
@@ -124,6 +124,7 @@
         Display display = virtualDisplay.getDisplay();
         try {
             assertDisplayRegistered(display, Display.FLAG_PRIVATE);
+            assertEquals(mSurface, virtualDisplay.getSurface());
 
             // Show a private presentation on the display.
             assertDisplayCanShowPresentation("private presentation window",
@@ -148,6 +149,7 @@
         Display display = virtualDisplay.getDisplay();
         try {
             assertDisplayRegistered(display, Display.FLAG_PRIVATE | Display.FLAG_PRESENTATION);
+            assertEquals(mSurface, virtualDisplay.getSurface());
 
             // Show a private presentation on the display.
             assertDisplayCanShowPresentation("private presentation window",
@@ -159,6 +161,38 @@
         assertDisplayUnregistered(display);
     }
 
+    /**
+     * Ensures that an application can create a private virtual display and show
+     * its own windows on it where the surface is attached or detached dynamically.
+     */
+    public void testPrivateVirtualDisplayWithDynamicSurface() throws Exception {
+        VirtualDisplay virtualDisplay = mDisplayManager.createVirtualDisplay(NAME,
+                WIDTH, HEIGHT, DENSITY, null, 0);
+        assertNotNull("virtual display must not be null", virtualDisplay);
+
+        Display display = virtualDisplay.getDisplay();
+        try {
+            assertDisplayRegistered(display, Display.FLAG_PRIVATE);
+            assertNull(virtualDisplay.getSurface());
+
+            // Attach the surface.
+            virtualDisplay.setSurface(mSurface);
+            assertEquals(mSurface, virtualDisplay.getSurface());
+
+            // Show a private presentation on the display.
+            assertDisplayCanShowPresentation("private presentation window",
+                    display, BLUEISH,
+                    WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION, 0);
+
+            // Detach the surface.
+            virtualDisplay.setSurface(null);
+            assertNull(virtualDisplay.getSurface());
+        } finally {
+            virtualDisplay.release();
+        }
+        assertDisplayUnregistered(display);
+    }
+
     private void assertDisplayRegistered(Display display, int flags) {
         assertNotNull("display object must not be null", display);
         assertTrue("display must be valid", display.isValid());
diff --git a/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java b/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
index 572c3f4..fafce61 100644
--- a/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/AspectRatioTest.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.DisplayMetrics;
 import android.view.Display;
@@ -49,6 +50,12 @@
         if (aspectRatio >= 1.333 && aspectRatio <= 1.86) {
             return;
         }
+        if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+            // Watch allows for a different set of aspect ratios.
+            if (aspectRatio >= 1.0 && aspectRatio <= 1.86) {
+                return;
+            }
+        }
         fail("Aspect ratio was not between 1.333 and 1.86: " + aspectRatio);
     }
 
diff --git a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
index 4ecabc5..e2f75c6 100644
--- a/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
+++ b/tests/tests/dpi/src/android/dpi/cts/ConfigurationTest.java
@@ -17,6 +17,7 @@
 package android.dpi.cts;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.test.AndroidTestCase;
 import android.util.DisplayMetrics;
 import android.view.Display;
@@ -40,8 +41,13 @@
         double xInches = (double) metrics.widthPixels / metrics.xdpi;
         double yInches = (double) metrics.heightPixels / metrics.ydpi;
         double diagonalInches = Math.sqrt(Math.pow(xInches, 2) + Math.pow(yInches, 2));
-        assertTrue("Screen diagonal must be at least 2.5 inches: " + diagonalInches,
-                diagonalInches >= 2.5d);
+        double minSize = 2.5d;
+        if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+            // Watches have a different minimum diagonal.
+            minSize = 1.0d;
+        }
+        assertTrue("Screen diagonal must be at least " + minSize + " inches: " + diagonalInches,
+                diagonalInches >= minSize);
 
         double density = 160.0d * metrics.density;
         assertTrue("Screen density must be at least 100 dpi: " + density, density >= 100.0d);
diff --git a/tests/tests/drm/src/android/drm/cts/DRMTest.java b/tests/tests/drm/src/android/drm/cts/DRMTest.java
index bb77668..bd4291d 100644
--- a/tests/tests/drm/src/android/drm/cts/DRMTest.java
+++ b/tests/tests/drm/src/android/drm/cts/DRMTest.java
@@ -18,6 +18,7 @@
 
 
 import android.content.ContentValues;
+import android.content.pm.PackageManager;
 import android.test.AndroidTestCase;
 import android.util.Log;
 import java.io.IOException;
@@ -48,22 +49,30 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mDrmManagerClient = new DrmManagerClient(getContext());
-        String[] plugins = mDrmManagerClient.getAvailableDrmEngines();
 
-        mConfigs.clear();
-        for(String plugInName : plugins) {
-            Config config = ConfigFactory.getConfig(plugInName);
-            if (null != config) {
-                mConfigs.add(config);
+        if (deviceSupportsDRM()) {
+            mDrmManagerClient = new DrmManagerClient(getContext());
+            String[] plugins = mDrmManagerClient.getAvailableDrmEngines();
+
+            mConfigs.clear();
+            for(String plugInName : plugins) {
+                Config config = ConfigFactory.getConfig(plugInName);
+                if (null != config) {
+                    mConfigs.add(config);
+                }
             }
         }
     }
 
+    private boolean deviceSupportsDRM() {
+       /* Watches don't support DRM */
+        return !getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+    }
+
     private void register(Config config) throws Exception {
         DrmInfo drmInfo = executeAcquireDrmInfo(DrmInfoRequest.TYPE_REGISTRATION_INFO,
-                                            config.getInfoOfRegistration(),
-                                            config.getMimeType());
+                config.getInfoOfRegistration(),
+                config.getMimeType());
         executeProcessDrmInfo(drmInfo, config);
     }
 
@@ -82,86 +91,106 @@
     }
 
     public void testIsDrmDirectoryExist() {
-        assertTrue("/data/drm/ does not exist", new File("/data/drm/").exists());
+        if (deviceSupportsDRM()) {
+            assertTrue("/data/drm/ does not exist", new File("/data/drm/").exists());
+        }
     }
 
     public void testRegisterAndDeregister() throws Exception {
-        for (Config config : mConfigs) {
-            register(config);
-            deregister(config);
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                register(config);
+                deregister(config);
+            }
         }
     }
 
     public void testAcquireRights() throws Exception {
-        for (Config config : mConfigs) {
-            register(config);
-            acquireRights(config);
-            deregister(config);
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                register(config);
+                acquireRights(config);
+                deregister(config);
+            }
         }
     }
 
     public void testGetConstraints() throws Exception {
-        for (Config config : mConfigs) {
-            register(config);
-            acquireRights(config);
-            ContentValues constraints = mDrmManagerClient.getConstraints(
-                                            config.getContentPath(),
-                                            DrmStore.Action.DEFAULT);
-            assertNotNull("Failed on plugin: " + config.getPluginName(), constraints);
-            deregister(config);
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                register(config);
+                acquireRights(config);
+                ContentValues constraints = mDrmManagerClient.getConstraints(
+                                                                             config.getContentPath(),
+                                                                             DrmStore.Action.DEFAULT);
+                assertNotNull("Failed on plugin: " + config.getPluginName(), constraints);
+                deregister(config);
+            }
         }
     }
 
     public void testCanHandle() throws Exception {
-        for (Config config : mConfigs) {
-            assertTrue("Failed on plugin: " + config.getPluginName(),
-                    mDrmManagerClient.canHandle(config.getContentPath(), config.getMimeType()));
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                assertTrue("Failed on plugin: " + config.getPluginName(),
+                        mDrmManagerClient.canHandle(config.getContentPath(), config.getMimeType()));
+            }
         }
     }
 
     public void testGetOriginalMimeType() throws Exception {
-        for (Config config : mConfigs) {
-            assertNotNull("Failed on plugin: " + config.getPluginName(),
-                    mDrmManagerClient.getOriginalMimeType(config.getContentPath()));
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                assertNotNull("Failed on plugin: " + config.getPluginName(),
+                        mDrmManagerClient.getOriginalMimeType(config.getContentPath()));
+            }
         }
     }
 
     public void testCheckRightsStatus() throws Exception {
-        for (Config config : mConfigs) {
-            register(config);
-            acquireRights(config);
-            int rightsStatus = mDrmManagerClient.checkRightsStatus(
-                                                config.getContentPath(),
-                                                DrmStore.Action.PLAY);
-            assertEquals("Failed on plugin: " + config.getPluginName(),
-                    DrmStore.RightsStatus.RIGHTS_VALID, rightsStatus);
-            deregister(config);
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                register(config);
+                acquireRights(config);
+                int rightsStatus = mDrmManagerClient.checkRightsStatus(
+                                                                       config.getContentPath(),
+                                                                       DrmStore.Action.PLAY);
+                assertEquals("Failed on plugin: " + config.getPluginName(),
+                        DrmStore.RightsStatus.RIGHTS_VALID, rightsStatus);
+                deregister(config);
+            }
         }
     }
 
     public void testRemoveRights() throws Exception {
-        for (Config config : mConfigs) {
-            assertEquals("Failed on plugin: " + config.getPluginName(),
-                    DrmManagerClient.ERROR_NONE,
-                    mDrmManagerClient.removeRights(config.getContentPath()));
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                assertEquals("Failed on plugin: " + config.getPluginName(),
+                        DrmManagerClient.ERROR_NONE,
+                        mDrmManagerClient.removeRights(config.getContentPath()));
+            }
         }
     }
 
     public void testRemoveAllRights() throws Exception {
-        for (Config config : mConfigs) {
-            assertEquals("Failed on plugin: " + config.getPluginName(),
-                    mDrmManagerClient.removeAllRights(), DrmManagerClient.ERROR_NONE);
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                assertEquals("Failed on plugin: " + config.getPluginName(),
+                        mDrmManagerClient.removeAllRights(), DrmManagerClient.ERROR_NONE);
+            }
         }
     }
 
     public void testConvertData() throws Exception {
-        for (Config config : mConfigs) {
-            byte[] inputData = new byte[]{'T','E','S','T'};
+        if (deviceSupportsDRM()) {
+            for (Config config : mConfigs) {
+                byte[] inputData = new byte[]{'T','E','S','T'};
 
-            int convertId = mDrmManagerClient.openConvertSession(config.getMimeType());
-            DrmConvertedStatus drmConvertStatus
-                                = mDrmManagerClient.convertData(convertId, inputData);
-            mDrmManagerClient.closeConvertSession(convertId);
+                int convertId = mDrmManagerClient.openConvertSession(config.getMimeType());
+                DrmConvertedStatus drmConvertStatus
+                    = mDrmManagerClient.convertData(convertId, inputData);
+                mDrmManagerClient.closeConvertSession(convertId);
+            }
         }
     }
 
diff --git a/tests/tests/drm/src/android/drm/cts/DrmInfoRequestTest.java b/tests/tests/drm/src/android/drm/cts/DrmInfoRequestTest.java
index cedc2d5..02894d4 100644
--- a/tests/tests/drm/src/android/drm/cts/DrmInfoRequestTest.java
+++ b/tests/tests/drm/src/android/drm/cts/DrmInfoRequestTest.java
@@ -31,8 +31,6 @@
 
     public static void testInvalidInfoTypes() throws Exception {
         checkInvalidInfoType(DrmInfoRequest.TYPE_REGISTRATION_INFO - 1);
-        checkInvalidInfoType(
-                DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO + 1);
     }
 
     public static void testValidInfoTypes() throws Exception {
diff --git a/tests/tests/drm/src/android/drm/cts/DrmInfoStatusTest.java b/tests/tests/drm/src/android/drm/cts/DrmInfoStatusTest.java
index 103bd6e..cecd558 100644
--- a/tests/tests/drm/src/android/drm/cts/DrmInfoStatusTest.java
+++ b/tests/tests/drm/src/android/drm/cts/DrmInfoStatusTest.java
@@ -30,7 +30,6 @@
             DrmInfoRequest.TYPE_REGISTRATION_INFO;
 
     public static void testInvalidStatusCodes() throws Exception {
-        checkInvalidStatusCode(DrmInfoStatus.STATUS_ERROR + 1);
         checkInvalidStatusCode(DrmInfoStatus.STATUS_OK - 1);
     }
 
diff --git a/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java b/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
index 656df5b..7a498a6 100644
--- a/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
+++ b/tests/tests/drm/src/android/drm/cts/DrmInfoTest.java
@@ -33,8 +33,6 @@
 
     public static void testInvalidInfoTypes() throws Exception {
         checkInvalidInfoType(DrmInfoRequest.TYPE_REGISTRATION_INFO - 1);
-        checkInvalidInfoType(
-                DrmInfoRequest.TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO + 1);
     }
 
     public static void testValidInfoTypes() throws Exception {
diff --git a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
index f942f93..91d827c 100644
--- a/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/BitmapFactoryTest.java
@@ -40,7 +40,6 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.RandomAccessFile;
 
 public class BitmapFactoryTest extends InstrumentationTestCase {
     private Resources mRes;
@@ -241,50 +240,6 @@
         assertEquals(START_WIDTH, b.getWidth());
     }
 
-    public void testDecodeFileDescriptor3() throws IOException {
-        // Arbitrary offsets to use. If the offset of the FD matches the offset of the image,
-        // decoding should succeed, but if they do not match, decoding should fail.
-        long ACTUAL_OFFSETS[] = new long[] { 0, 17 };
-        for (int RES_ID : RES_IDS) {
-            for (int j = 0; j < ACTUAL_OFFSETS.length; ++j) {
-                // FIXME: The purgeable test should attempt to purge the memory
-                // to force a re-decode.
-                for (boolean TEST_PURGEABLE : new boolean[] { false, true }) {
-                    BitmapFactory.Options opts = new BitmapFactory.Options();
-                    opts.inPurgeable = TEST_PURGEABLE;
-                    opts.inInputShareable = TEST_PURGEABLE;
-
-                    long actualOffset = ACTUAL_OFFSETS[j];
-                    String path = obtainPath(RES_ID, actualOffset);
-                    RandomAccessFile file = new RandomAccessFile(path, "r");
-                    FileDescriptor fd = file.getFD();
-                    assertTrue(fd.valid());
-
-                    // Set the offset to ACTUAL_OFFSET
-                    file.seek(actualOffset);
-                    assertEquals(file.getFilePointer(), actualOffset);
-
-                    // Now decode. This should be successful and leave the offset
-                    // unchanged.
-                    Bitmap b = BitmapFactory.decodeFileDescriptor(fd, null, opts);
-                    assertNotNull(b);
-                    assertEquals(file.getFilePointer(), actualOffset);
-
-                    // Now use the other offset. It should fail to decode, and
-                    // the offset should remain unchanged.
-                    long otherOffset = ACTUAL_OFFSETS[(j + 1) % ACTUAL_OFFSETS.length];
-                    assertFalse(otherOffset == actualOffset);
-                    file.seek(otherOffset);
-                    assertEquals(file.getFilePointer(), otherOffset);
-
-                    b = BitmapFactory.decodeFileDescriptor(fd, null, opts);
-                    assertNull(b);
-                    assertEquals(file.getFilePointer(), otherOffset);
-                }
-            }
-        }
-    }
-
     public void testDecodeFile1() throws IOException {
         Bitmap b = BitmapFactory.decodeFile(obtainPath(), mOpt1);
         assertNotNull(b);
@@ -471,32 +426,17 @@
     }
 
     private String obtainPath() throws IOException {
-        return obtainPath(R.drawable.start, 0);
-    }
-
-    /*
-     * Create a new file and return a path to it.
-     * @param resId Original file. It will be copied into the new file.
-     * @param offset Number of zeroes to write to the new file before the
-     *               copied file. This allows testing decodeFileDescriptor
-     *               with an offset. Must be less than or equal to 1024
-     */
-    private String obtainPath(int resId, long offset) throws IOException {
         File dir = getInstrumentation().getTargetContext().getFilesDir();
         dir.mkdirs();
-        // The suffix does not necessarily represent theactual file type.
         File file = new File(dir, "test.jpg");
         if (!file.createNewFile()) {
             if (!file.exists()) {
                 fail("Failed to create new File!");
             }
         }
-        InputStream is = obtainInputStream(resId);
+        InputStream is = obtainInputStream();
         FileOutputStream fOutput = new FileOutputStream(file);
         byte[] dataBuffer = new byte[1024];
-        // Write a bunch of zeroes before the image.
-        assertTrue(offset <= 1024);
-        fOutput.write(dataBuffer, 0, (int) offset);
         int readLength = 0;
         while ((readLength = is.read(dataBuffer)) != -1) {
             fOutput.write(dataBuffer, 0, readLength);
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
index aac71cf..c84510d 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/BitmapDrawableTest.java
@@ -252,6 +252,7 @@
         bitmapDrawable.setGravity(Gravity.BOTTOM);
         assertEquals(PixelFormat.TRANSLUCENT, bitmapDrawable.getOpacity());
 
+        source = mContext.getResources().openRawResource(R.raw.testimage);
         bitmapDrawable = new BitmapDrawable(source);
         assertEquals(Gravity.FILL, bitmapDrawable.getGravity());
         assertEquals(PixelFormat.OPAQUE, bitmapDrawable.getOpacity());
diff --git a/tests/tests/hardware/src/android/hardware/consumerir/cts/ConsumerIrTest.java b/tests/tests/hardware/src/android/hardware/consumerir/cts/ConsumerIrTest.java
index 395a69b..e06adac 100644
--- a/tests/tests/hardware/src/android/hardware/consumerir/cts/ConsumerIrTest.java
+++ b/tests/tests/hardware/src/android/hardware/consumerir/cts/ConsumerIrTest.java
@@ -77,12 +77,12 @@
 
         ConsumerIrManager.CarrierFrequencyRange[] freqs = mCIR.getCarrierFrequencies();
         // Transmit two seconds for min and max for each frequency range
-        int[] pattern = {1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999};
-        long totalXmitTime = 0; // get the length of the pattern
+        int[] pattern = {11111, 22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999};
+        long totalXmitTimeNanos = 0; // get the length of the pattern
         for (int slice : pattern) {
-            totalXmitTime += slice;
+            totalXmitTimeNanos += slice * 1000; // add the time in nanoseconds
         }
-        double margin = 0.1; // max fraction xmit is allowed to be off timing
+        double margin = 0.5; // max fraction xmit is allowed to be off timing
 
         for (ConsumerIrManager.CarrierFrequencyRange range : freqs) {
             // test min freq
@@ -90,18 +90,18 @@
             mCIR.transmit(range.getMinFrequency(), pattern);
             long newTime = SystemClock.elapsedRealtimeNanos();
             String msg = String.format("Pattern length pattern:%d, actual:%d",
-                    totalXmitTime, newTime - currentTime);
-            assertTrue(msg, newTime - currentTime >= totalXmitTime * (1.0 - margin));
-            assertTrue(msg, newTime - currentTime <= totalXmitTime * (1.0 + margin));
+                    totalXmitTimeNanos, newTime - currentTime);
+            assertTrue(msg, newTime - currentTime >= totalXmitTimeNanos * (1.0 - margin));
+            assertTrue(msg, newTime - currentTime <= totalXmitTimeNanos * (1.0 + margin));
 
             // test max freq
             currentTime = SystemClock.elapsedRealtimeNanos();
             mCIR.transmit(range.getMaxFrequency(), pattern);
             newTime = SystemClock.elapsedRealtimeNanos();
             msg = String.format("Pattern length pattern:%d, actual:%d",
-                    totalXmitTime, newTime - currentTime);
-            assertTrue(msg, newTime - currentTime >= totalXmitTime * (1.0 - margin));
-            assertTrue(msg, newTime - currentTime <= totalXmitTime * (1.0 + margin));
+                    totalXmitTimeNanos, newTime - currentTime);
+            assertTrue(msg, newTime - currentTime >= totalXmitTimeNanos * (1.0 - margin));
+            assertTrue(msg, newTime - currentTime <= totalXmitTimeNanos * (1.0 + margin));
         }
     }
 
diff --git a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
index b198541..c6e28f7 100644
--- a/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/CameraTest.java
@@ -16,6 +16,7 @@
 
 package android.hardware.cts;
 
+import android.content.pm.PackageManager;
 import android.graphics.BitmapFactory;
 import android.graphics.ImageFormat;
 import android.graphics.Rect;
@@ -2938,4 +2939,23 @@
         terminateMessageLooper();
     }
 
+    public void testCameraExternalConnected() {
+        if (getActivity().getPackageManager().
+                hasSystemFeature(PackageManager.FEATURE_CAMERA_EXTERNAL) ) {
+            int nCameras = Camera.getNumberOfCameras();
+            assertTrue("Devices with external camera support must have a camera connected for " +
+                    "testing",
+                    nCameras > 0);
+            for (int id = 0; id < nCameras; id++) {
+                try {
+                    Camera c = Camera.open(id);
+                    c.release();
+                } catch (Throwable e) {
+                    throw new AssertionError("Devices with external camera support must " +
+                            "have all listed cameras be connected and openable for testing", e);
+                }
+            }
+        }
+    }
+
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
index 24dd368..907759f 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
@@ -99,6 +99,17 @@
             assertNull(sensor);
         }
 
+        sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
+        boolean hasHeartRate = getContext().getPackageManager().hasSystemFeature(
+                PackageManager.FEATURE_SENSOR_HEART_RATE);
+        // heartrate sensor is optional
+        if (hasHeartRate) {
+            assertEquals(Sensor.TYPE_HEART_RATE, sensor.getType());
+            assertSensorValues(sensor);
+        } else {
+            assertNull(sensor);
+        }
+
         sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
         boolean hasCompass = getContext().getPackageManager().hasSystemFeature(
                 PackageManager.FEATURE_SENSOR_COMPASS);
diff --git a/tests/tests/media/res/raw/bug13652927.ogg b/tests/tests/media/res/raw/bug13652927.ogg
new file mode 100644
index 0000000..065d9e5
--- /dev/null
+++ b/tests/tests/media/res/raw/bug13652927.ogg
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
index 0230edc..13852ae 100644
--- a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
+++ b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
@@ -44,6 +44,7 @@
 public class AdaptivePlaybackTest extends MediaPlayerTestBase {
     private static final String TAG = "AdaptivePlaybackTest";
     private boolean sanity = false;
+    private static final int MIN_FRAMES_BEFORE_DRC = 2;
 
     public Iterable<Codec> H264(CodecFactory factory) {
         return factory.createCodecList(
@@ -466,6 +467,10 @@
             tests.add(
                 new Step("testing DRC with no reconfigure - init", this, c) {
                     public void run() throws Throwable {
+                        // FIXME wait 2 seconds to allow system to free up previous codecs
+                        try {
+                            Thread.sleep(2000);
+                        } catch (InterruptedException e) {}
                         mDecoder = new Decoder(c.name);
                         mDecoder.configureAndStart(stepFormat(), stepSurface());
                         mAdjustTimeUs = 0;
@@ -473,7 +478,7 @@
                         mQueuedFrames = 0;
                     }});
 
-            for (int i = NUM_FRAMES, ix = 0; i > 1; i--, ix++) {
+            for (int i = NUM_FRAMES, ix = 0; i >= MIN_FRAMES_BEFORE_DRC; i--, ix++) {
                 final int mediaIx = ix % c.mediaList.length;
                 final int segmentSize = i;
                 tests.add(
@@ -481,9 +486,9 @@
                             this, c, mediaIx) {
                         public void run() throws Throwable {
                             mQueuedFrames += segmentSize;
-                            boolean lastSequence = segmentSize == 2;
+                            boolean lastSequence = segmentSize == MIN_FRAMES_BEFORE_DRC;
                             if (sanity) {
-                                lastSequence = (segmentSize >> 1) <= 2;
+                                lastSequence = (segmentSize >> 1) <= MIN_FRAMES_BEFORE_DRC;
                             }
                             int frames = mDecoder.queueInputBufferRange(
                                     stepMedia(),
@@ -589,7 +594,7 @@
             };
         }
         public void addTests(TestList tests, Codec c) {
-            for (int drcFrame = 6; drcFrame > 1; drcFrame--) {
+            for (int drcFrame = 6; drcFrame >= MIN_FRAMES_BEFORE_DRC; drcFrame--) {
                 for (int eosFrame = 6; eosFrame >= 1; eosFrame--) {
                     tests.add(testStep(c, drcFrame, eosFrame));
                 }
@@ -1270,11 +1275,13 @@
 
             /* test if the explicitly named codec is present on the system */
             if (explicitCodecName != null) {
-                MediaCodec codec = MediaCodec.createByCodecName(explicitCodecName);
-                if (codec != null) {
-                    codec.release();
-                    add(new Codec(explicitCodecName, null, mediaList));
-                }
+                try {
+                    MediaCodec codec = MediaCodec.createByCodecName(explicitCodecName);
+                    if (codec != null) {
+                        codec.release();
+                        add(new Codec(explicitCodecName, null, mediaList));
+                    }
+                } catch (Exception e) {}
             }
         } catch (Throwable t) {
             Log.wtf("Constructor failed", t);
diff --git a/tests/tests/media/src/android/media/cts/AudioTrackTest.java b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
index 9b1879a..090cde8 100644
--- a/tests/tests/media/src/android/media/cts/AudioTrackTest.java
+++ b/tests/tests/media/src/android/media/cts/AudioTrackTest.java
@@ -18,6 +18,7 @@
 
 import android.media.AudioFormat;
 import android.media.AudioManager;
+import android.media.AudioTimestamp;
 import android.media.AudioTrack;
 import android.test.AndroidTestCase;
 import android.util.Log;
@@ -1364,6 +1365,76 @@
         track.release();
     }
 
+    public void testGetTimestamp() throws Exception {
+        // constants for test
+        final String TEST_NAME = "testGetTimestamp";
+        final int TEST_SR = 22050;
+        final int TEST_CONF = AudioFormat.CHANNEL_CONFIGURATION_MONO;
+        final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
+        final int TEST_MODE = AudioTrack.MODE_STREAM;
+        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
+        final int TEST_LOOP_CNT = 10;
+
+        final int MILLIS_PER_SEC = 1000;
+        final int NANOS_PER_MILLI = 1000000;
+
+        // -------- initialization --------------
+        final int BYTES_PER_FRAME = 2;
+        final int FRAMES_PER_100_MILLIS =
+                AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
+        final int FRAMES_PER_SEC = FRAMES_PER_100_MILLIS * 10;
+        byte[] data = new byte[FRAMES_PER_100_MILLIS * BYTES_PER_FRAME];
+        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT,
+                 FRAMES_PER_SEC * BYTES_PER_FRAME, TEST_MODE);
+        // -------- test --------------
+        assertTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
+
+        long framesWritten = 0, framesSeen = 0, framesPresented = 0;
+        long lastFramesPresented = 0, lastFrameTime = 0, lastOutputFrequency = FRAMES_PER_SEC;
+        AudioTimestamp timestamp = new AudioTimestamp();
+
+        for (int i = 0; i < TEST_LOOP_CNT; i++) {
+            for (int j = 0; j < FRAMES_PER_SEC; j += FRAMES_PER_100_MILLIS) {
+                track.write(data, 0, data.length);
+                framesWritten += FRAMES_PER_100_MILLIS;
+            }
+
+            track.play();
+            Thread.sleep(MILLIS_PER_SEC);
+            track.pause();
+
+            framesSeen = track.getPlaybackHeadPosition();
+            assertTrue(TEST_NAME, framesWritten >= framesSeen);
+
+            assertTrue(TEST_NAME, track.getTimestamp(timestamp));
+            framesPresented = timestamp.framePosition;
+            assertTrue(TEST_NAME, framesSeen >= framesPresented);
+
+            // check output frequency
+            long outFrequency = framesPresented - lastFramesPresented;
+            long freqDiff = Math.abs(FRAMES_PER_SEC - outFrequency);
+            assertTrue(TEST_NAME, freqDiff < FRAMES_PER_100_MILLIS);
+
+            // check output frequency jitter
+            freqDiff = Math.abs(outFrequency - lastOutputFrequency);
+            assertTrue(TEST_NAME, freqDiff < FRAMES_PER_100_MILLIS);
+
+            lastFramesPresented = framesPresented;
+            lastOutputFrequency = outFrequency;
+
+            long frameTime = timestamp.nanoTime;
+            assertTrue(TEST_NAME, frameTime >= lastFrameTime);
+            lastFrameTime = frameTime;
+
+            long curTime = System.nanoTime();
+            assertTrue(TEST_NAME, curTime >= frameTime);
+            assertTrue(TEST_NAME, curTime - frameTime < 100 * NANOS_PER_MILLI);
+        }
+        track.stop();
+        // -------- tear down --------------
+        track.release();
+    }
+
 /* Do not run in JB-MR1. will be re-opened in the next platform release.
     public void testResourceLeakage() throws Exception {
         final int BUFFER_SIZE = 600 * 1024;
diff --git a/tests/tests/media/src/android/media/cts/EncodeVirtualDisplayWithCompositionTest.java b/tests/tests/media/src/android/media/cts/EncodeVirtualDisplayWithCompositionTest.java
index dc767c9..d7ba82d 100644
--- a/tests/tests/media/src/android/media/cts/EncodeVirtualDisplayWithCompositionTest.java
+++ b/tests/tests/media/src/android/media/cts/EncodeVirtualDisplayWithCompositionTest.java
@@ -866,8 +866,7 @@
                         } break;
                     }
                 } catch (GlException e) {
-                    // should stop rendering
-                    mLooper.quit();
+                    //ignore as this can happen during tearing down
                 }
             }
         }
diff --git a/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java b/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
index 81296e4..40b4949 100644
--- a/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
+++ b/tests/tests/media/src/android/media/cts/ExtractDecodeEditEncodeMuxTest.java
@@ -95,6 +95,8 @@
     private boolean mCopyVideo;
     /** Whether to copy the audio from the test video. */
     private boolean mCopyAudio;
+    /** Whether to verify the audio format. */
+    private boolean mVerifyAudioFormat;
     /** Width of the output frames. */
     private int mWidth = -1;
     /** Height of the output frames. */
@@ -131,6 +133,7 @@
         setSize(1280, 720);
         setSource(R.raw.video_480x360_mp4_h264_500kbps_30fps_aac_stereo_128kbps_44100hz);
         setCopyAudio();
+        setVerifyAudioFormat();
         TestWrapper.runTest(this);
     }
 
@@ -139,6 +142,7 @@
         setSource(R.raw.video_480x360_mp4_h264_500kbps_30fps_aac_stereo_128kbps_44100hz);
         setCopyAudio();
         setCopyVideo();
+        setVerifyAudioFormat();
         TestWrapper.runTest(this);
     }
 
@@ -190,6 +194,13 @@
     }
 
     /**
+     * Sets the test to verify the output audio format.
+     */
+    private void setVerifyAudioFormat() {
+        mVerifyAudioFormat = true;
+    }
+
+    /**
      * Sets the desired frame size.
      */
     private void setSize(int width, int height) {
@@ -449,6 +460,43 @@
         if (exception != null) {
             throw exception;
         }
+
+        MediaExtractor mediaExtractor = null;
+        try {
+            mediaExtractor = new MediaExtractor();
+            mediaExtractor.setDataSource(mOutputFile);
+
+            assertEquals("incorrect number of tracks", (mCopyAudio ? 1 : 0) + (mCopyVideo ? 1 : 0),
+                    mediaExtractor.getTrackCount());
+            if (mVerifyAudioFormat) {
+                boolean foundAudio = false;
+                for (int i = 0; i < mediaExtractor.getTrackCount(); i++) {
+                    MediaFormat trackFormat = mediaExtractor.getTrackFormat(i);
+                    if (isAudioFormat(trackFormat)) {
+                        foundAudio = true;
+                        int expectedSampleRate = OUTPUT_AUDIO_SAMPLE_RATE_HZ;
+
+                        // SBR mode halves the sample rate in the format.
+                        if (OUTPUT_AUDIO_AAC_PROFILE ==
+                                MediaCodecInfo.CodecProfileLevel.AACObjectHE) {
+                            expectedSampleRate /= 2;
+                        }
+                        assertEquals("sample rates should match", expectedSampleRate,
+                                trackFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE));
+                    }
+                }
+
+                assertTrue("output should have an audio track", foundAudio || !mCopyAudio);
+            }
+        } catch (IOException e) {
+            throw new IllegalStateException("exception verifying output file", e);
+        } finally {
+            if (mediaExtractor != null) {
+                mediaExtractor.release();
+            }
+        }
+
+        // TODO: Check the generated output file's video format and sample data.
     }
 
     /**
@@ -1061,8 +1109,6 @@
         if (mCopyAudio) {
             assertEquals("no frame should be pending", -1, pendingAudioDecoderOutputBufferIndex);
         }
-
-        // TODO: Check the generated output file.
     }
 
     private static boolean isVideoFormat(MediaFormat format) {
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index 0267497..c670b8c 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -22,6 +22,7 @@
 import android.content.res.AssetFileDescriptor;
 import android.media.AudioManager;
 import android.media.MediaPlayer;
+import android.media.MediaPlayer.OnErrorListener;
 import android.media.MediaRecorder;
 import android.media.MediaMetadataRetriever;
 import android.media.TimedText;
@@ -30,7 +31,9 @@
 import android.media.cts.MediaPlayerTestBase.Monitor;
 import android.net.Uri;
 import android.os.Environment;
+import android.os.IBinder;
 import android.os.PowerManager;
+import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.util.Log;
 
@@ -76,6 +79,35 @@
             mOutFile.delete();
         }
     }
+
+    // Bug 13652927
+    public void testVorbisCrash() throws Exception {
+        MediaPlayer mp = mMediaPlayer;
+        MediaPlayer mp2 = mMediaPlayer2;
+        AssetFileDescriptor afd2 = mResources.openRawResourceFd(R.raw.testmp3_2);
+        mp2.setDataSource(afd2.getFileDescriptor(), afd2.getStartOffset(), afd2.getLength());
+        afd2.close();
+        mp2.prepare();
+        mp2.setLooping(true);
+        mp2.start();
+
+        for (int i = 0; i < 20; i++) {
+            try {
+                AssetFileDescriptor afd = mResources.openRawResourceFd(R.raw.bug13652927);
+                mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
+                afd.close();
+                mp.prepare();
+                fail("shouldn't be here");
+            } catch (Exception e) {
+                // expected to fail
+                Log.i("@@@", "failed: " + e);
+            }
+            Thread.sleep(500);
+            assertTrue("media server died", mp2.isPlaying());
+            mp.reset();
+        }
+    }
+
     public void testPlayNullSource() throws Exception {
         try {
             mMediaPlayer.setDataSource((String) null);
diff --git a/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java b/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
index 2c1b401..8bac442 100644
--- a/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/StreamingMediaPlayerTest.java
@@ -116,7 +116,7 @@
                 + "0.0.0.0/ipbits/0/expire/19000000000/sparams/ip,ipbits,expire"
                 + ",id,itag,source,playlist_type/signature/773AB8ACC68A96E5AA48"
                 + "1996AD6A1BBCB70DCB87.95733B544ACC5F01A1223A837D2CF04DF85A336"
-                + "0/key/ik0", 60 * 1000);
+                + "0/key/ik0/file/m3u8", 60 * 1000);
     }
 
     // Streaming audio from local HTTP server
diff --git a/tests/tests/nativemedia/sl/NativeMediaTest_SL_list.txt b/tests/tests/nativemedia/sl/NativeMediaTest_SL_list.txt
deleted file mode 100644
index c5d17a3..0000000
--- a/tests/tests/nativemedia/sl/NativeMediaTest_SL_list.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-SLObjectCreationTest.
-  testEngineCreation
-  testOutputMixCreation
-  testAudioPlayerFromUriCreation
-  testAudioPlayerFromFdCreation
-  testAudioPlayerFromPcmBqCreation
-  testAudioPlayerFromTsAbqCreation
-  testAudioPlayerFromUriToPcmBqCreation
-  testAudioPlayerFromFdToPcmBqCreation
-  testAudioPlayerFromAdtsAbqToPcmBqCreation
-  testAudioRecorderCreation
diff --git a/tests/tests/nativemedia/xa/NativeMediaTest_XA_list.txt b/tests/tests/nativemedia/xa/NativeMediaTest_XA_list.txt
deleted file mode 100644
index af8bfad..0000000
--- a/tests/tests/nativemedia/xa/NativeMediaTest_XA_list.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-XAObjectCreationTest.
-  testEngineCreation
-  testOutputMixCreation
diff --git a/tests/tests/os/src/android/os/cts/BuildVersionTest.java b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
index 1e7503c..ad4ec37 100644
--- a/tests/tests/os/src/android/os/cts/BuildVersionTest.java
+++ b/tests/tests/os/src/android/os/cts/BuildVersionTest.java
@@ -29,7 +29,7 @@
 
     private static final String LOG_TAG = "BuildVersionTest";
     private static final Set<String> EXPECTED_RELEASES =
-            new HashSet<String>(Arrays.asList("4.4", "4.4.1", "4.4.2"));
+        new HashSet<String>(Arrays.asList("4.4", "4.4.1", "4.4.2", "4.4.3"));
     private static final int EXPECTED_SDK = 19;
 
     @SuppressWarnings("deprecation")
diff --git a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
index 354fbaf..85af555 100755
--- a/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/FileSystemPermissionTest.java
@@ -446,6 +446,7 @@
                     "/data/logs",
                     "/data/logs/core",
                     "/data/lost+found",
+                    "/data/mdl",
                     "/data/misc",
                     "/data/misc/bluetooth",
                     "/data/misc/dhcp",
@@ -733,7 +734,8 @@
                 new File("/dev/alarm"),      // b/9035217
                 new File("/dev/ashmem"),
                 new File("/dev/binder"),
-                new File("/dev/quadd"),      // b/11336334
+                new File("/dev/card0"),       // b/13159510
+                new File("/dev/dri/card0"),   // b/13159510
                 new File("/dev/felica"),     // b/11142586
                 new File("/dev/felica_ant"), // b/11142586
                 new File("/dev/felica_cen"), // b/11142586
@@ -754,10 +756,10 @@
                 new File("/dev/log/radio"),  // b/9035217
                 new File("/dev/log/system"), // b/9035217
                 new File("/dev/mali0"),       // b/9106968
+                new File("/dev/mali"),        // b/11142586
                 new File("/dev/mm_interlock"), // b/12955573
                 new File("/dev/mm_isp"),      // b/12955573
                 new File("/dev/mm_v3d"),      // b/12955573
-                new File("/dev/mali"),        // b/11142586
                 new File("/dev/msm_rotator"), // b/9035217
                 new File("/dev/null"),
                 new File("/dev/nvhost-as-gpu"),
diff --git a/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java b/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java
index 2e09a49..9441319 100644
--- a/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/NoReadLogsPermissionTest.java
@@ -52,14 +52,14 @@
             int lineCt = 0;
             String line;
             while ((line = reader.readLine()) != null) {
-                if (!line.startsWith("--------- beginning of /dev/log")) {
+                if (!line.startsWith("--------- beginning of ")) {
                     lineCt++;
                 }
             }
 
             // no permission get an empty log buffer.
             // Logcat returns only one line:
-            // "--------- beginning of /dev/log/main"
+            // "--------- beginning of <log device>"
 
             assertEquals("Unexpected logcat entries. Are you running the "
                        + "the latest logger.c from the Android kernel?",
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
index e68286f..3f28a34 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_MediaTest.java
@@ -78,6 +78,13 @@
 
         mHelper = new FileCopyHelper(mContext);
         mRowsAdded = new ArrayList<Uri>();
+
+        String campath = Environment.getExternalStorageDirectory() + File.separator +
+                Environment.DIRECTORY_DCIM + File.separator + "Camera";
+        File camfile = new File(campath);
+        if (!camfile.exists()) {
+            assertTrue("failed to create " + campath, camfile.mkdir());
+        }
     }
 
     public void testInsertImageWithImagePath() throws Exception {
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
index e8a13a9..03adad7 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_Images_ThumbnailsTest.java
@@ -68,6 +68,13 @@
 
         mHelper = new FileCopyHelper(mContext);
         mRowsAdded = new ArrayList<Uri>();
+
+        String campath = Environment.getExternalStorageDirectory() + File.separator +
+                Environment.DIRECTORY_DCIM + File.separator + "Camera";
+        File camfile = new File(campath);
+        if (!camfile.exists()) {
+            assertTrue("failed to create " + campath, camfile.mkdir());
+        }
     }
 
     public void testQueryInternalThumbnails() throws Exception {
diff --git a/tests/tests/security/Android.mk b/tests/tests/security/Android.mk
index cd1d8d0..f1a6bfb 100644
--- a/tests/tests/security/Android.mk
+++ b/tests/tests/security/Android.mk
@@ -20,12 +20,11 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner
 
-LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner guava ctstestserver
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner guava
 
 LOCAL_JNI_SHARED_LIBRARIES := libctssecurity_jni
 
-LOCAL_SRC_FILES := $(call all-java-files-under, src) \
-    src/android/security/cts/activity/ISecureRandomService.aidl
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
 LOCAL_PACKAGE_NAME := CtsSecurityTestCases
 
diff --git a/tests/tests/security/AndroidManifest.xml b/tests/tests/security/AndroidManifest.xml
index 0b9baf2..101c01c 100644
--- a/tests/tests/security/AndroidManifest.xml
+++ b/tests/tests/security/AndroidManifest.xml
@@ -18,7 +18,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.cts.security">
 
-    <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
     <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
     <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
@@ -30,13 +29,11 @@
                  android:process=":death_test_service"
                  android:isolatedProcess="true"
                  android:exported="true"/>
-        <service android:name="android.security.cts.activity.SecureRandomService"
-                 android:process=":secureRandom"/>
     </application>
 
     <instrumentation android:name="android.test.InstrumentationCtsTestRunner"
-                     android:targetPackage="com.android.cts.security"
-                     android:label="CTS tests of com.android.cts.security"/>
+                     android:targetPackage="com.android.cts.stub"
+                     android:label="CTS tests of com.android.cts.stub"/>
 
 </manifest>
 
diff --git a/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
index 203382f..6bbc426 100644
--- a/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
+++ b/tests/tests/security/jni/android_security_cts_NativeCodeTest.cpp
@@ -15,13 +15,21 @@
  */
 
 #include <jni.h>
+#include <netlink.h>
+#include <sock_diag.h>
+#include <stdio.h>
+#include <sys/socket.h>
 #include <sys/types.h>
-#include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/prctl.h>
 #include <sys/ptrace.h>
 #include <sys/wait.h>
 #include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+
+#define PASSED 0
+#define UNKNOWN_ERROR -1
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -213,12 +221,80 @@
     return result;
 }
 
+/*
+ * Will hang if vulnerable, return 0 if successful, -1 on unforseen
+ * error.
+ */
+static jint android_security_cts_NativeCodeTest_doSockDiagTest(JNIEnv* env, jobject thiz)
+{
+    int fd, nlmsg_size, err, len;
+    char buf[1024];
+    struct sockaddr_nl nladdr;
+    struct nlmsghdr *nlh;
+    struct msghdr msg;
+    struct iovec iov;
+    struct sock_diag_req* sock_diag_data;
+
+    fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
+    if (fd == -1) {
+        switch (errno) {
+            /* NETLINK_SOCK_DIAG not accessible, vector dne */
+            case EACCES:
+            case EAFNOSUPPORT:
+            case EPERM:
+            case EPROTONOSUPPORT:
+                return PASSED;
+            default:
+                return UNKNOWN_ERROR;
+        }
+    }
+    /* prepare and send netlink packet */
+    memset(&nladdr, 0, sizeof(nladdr));
+    nladdr.nl_family = AF_NETLINK;
+    nlmsg_size = NLMSG_ALIGN(NLMSG_HDRLEN + sizeof(sock_diag_data));
+    nlh = (nlmsghdr *)malloc(nlmsg_size);
+    nlh->nlmsg_len = nlmsg_size;
+    nlh->nlmsg_pid = 0;      //send packet to kernel
+    nlh->nlmsg_type = SOCK_DIAG_BY_FAMILY;
+    nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
+    iov = { (void *) nlh, nlmsg_size };
+    msg = { (void *) &nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 };
+    sock_diag_data = (sock_diag_req *) NLMSG_DATA(nlh);
+    sock_diag_data->sdiag_family = AF_MAX+1;
+    if ((err = sendmsg(fd, &msg, 0)) == -1) {
+        /* SELinux blocked it */
+        if (errno == 22) {
+            return PASSED;
+        } else {
+            return UNKNOWN_ERROR;
+        }
+    }
+    free(nlh);
+
+    memset(&nladdr, 0, sizeof(nladdr));
+    iov = { buf, sizeof(buf) };
+    msg = { (void *) &nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0 };
+    if ((len = recvmsg(fd, &msg, 0)) == -1) {
+        return UNKNOWN_ERROR;
+    }
+    for (nlh = (struct nlmsghdr *) buf; NLMSG_OK(nlh, len); nlh = NLMSG_NEXT (nlh, len)){
+        if (nlh->nlmsg_type == NLMSG_ERROR) {
+            /* -22 = -EINVAL from kernel */
+            if (*(int *)NLMSG_DATA(nlh) == -22) {
+                return PASSED;
+            }
+        }
+    }
+    return UNKNOWN_ERROR;
+}
 
 static JNINativeMethod gMethods[] = {
     {  "doPerfEventTest", "()Z",
             (void *) android_security_cts_NativeCodeTest_doPerfEventTest },
     {  "doPerfEventTest2", "()Z",
             (void *) android_security_cts_NativeCodeTest_doPerfEventTest2 },
+    {  "doSockDiagTest", "()I",
+            (void *) android_security_cts_NativeCodeTest_doSockDiagTest },
     {  "doVrootTest", "()Z",
             (void *) android_security_cts_NativeCodeTest_doVrootTest },
     {  "doCVE20141710Test", "()Z",
diff --git a/tests/tests/security/jni/netlink.h b/tests/tests/security/jni/netlink.h
new file mode 100644
index 0000000..b5567b0
--- /dev/null
+++ b/tests/tests/security/jni/netlink.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI__LINUX_NETLINK_H
+#define _UAPI__LINUX_NETLINK_H
+#include <linux/kernel.h>
+#include <linux/socket.h>
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#include <linux/types.h>
+#define NETLINK_ROUTE 0
+#define NETLINK_UNUSED 1
+#define NETLINK_USERSOCK 2
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_FIREWALL 3
+#define NETLINK_SOCK_DIAG 4
+#define NETLINK_NFLOG 5
+#define NETLINK_XFRM 6
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_SELINUX 7
+#define NETLINK_ISCSI 8
+#define NETLINK_AUDIT 9
+#define NETLINK_FIB_LOOKUP 10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_CONNECTOR 11
+#define NETLINK_NETFILTER 12
+#define NETLINK_IP6_FW 13
+#define NETLINK_DNRTMSG 14
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_KOBJECT_UEVENT 15
+#define NETLINK_GENERIC 16
+#define NETLINK_SCSITRANSPORT 18
+#define NETLINK_ECRYPTFS 19
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_RDMA 20
+#define NETLINK_CRYPTO 21
+#define NETLINK_INET_DIAG NETLINK_SOCK_DIAG
+#define MAX_LINKS 32
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct sockaddr_nl {
+ __kernel_sa_family_t nl_family;
+ unsigned short nl_pad;
+ __u32 nl_pid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 nl_groups;
+};
+struct nlmsghdr {
+ __u32 nlmsg_len;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 nlmsg_type;
+ __u16 nlmsg_flags;
+ __u32 nlmsg_seq;
+ __u32 nlmsg_pid;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+};
+#define NLM_F_REQUEST 1
+#define NLM_F_MULTI 2
+#define NLM_F_ACK 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLM_F_ECHO 8
+#define NLM_F_DUMP_INTR 16
+#define NLM_F_ROOT 0x100
+#define NLM_F_MATCH 0x200
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLM_F_ATOMIC 0x400
+#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
+#define NLM_F_REPLACE 0x100
+#define NLM_F_EXCL 0x200
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLM_F_CREATE 0x400
+#define NLM_F_APPEND 0x800
+#define NLMSG_ALIGNTO 4U
+#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
+#define NLMSG_LENGTH(len) ((len) + NLMSG_HDRLEN)
+#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
+#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len),   (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
+#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) &&   (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) &&   (nlh)->nlmsg_len <= (len))
+#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
+#define NLMSG_NOOP 0x1
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLMSG_ERROR 0x2
+#define NLMSG_DONE 0x3
+#define NLMSG_OVERRUN 0x4
+#define NLMSG_MIN_TYPE 0x10
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nlmsgerr {
+ int error;
+ struct nlmsghdr msg;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_ADD_MEMBERSHIP 1
+#define NETLINK_DROP_MEMBERSHIP 2
+#define NETLINK_PKTINFO 3
+#define NETLINK_BROADCAST_ERROR 4
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NETLINK_NO_ENOBUFS 5
+#define NETLINK_RX_RING 6
+#define NETLINK_TX_RING 7
+struct nl_pktinfo {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 group;
+};
+struct nl_mmap_req {
+ unsigned int nm_block_size;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ unsigned int nm_block_nr;
+ unsigned int nm_frame_size;
+ unsigned int nm_frame_nr;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct nl_mmap_hdr {
+ unsigned int nm_status;
+ unsigned int nm_len;
+ __u32 nm_group;
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u32 nm_pid;
+ __u32 nm_uid;
+ __u32 nm_gid;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum nl_mmap_status {
+ NL_MMAP_STATUS_UNUSED,
+ NL_MMAP_STATUS_RESERVED,
+ NL_MMAP_STATUS_VALID,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NL_MMAP_STATUS_COPY,
+ NL_MMAP_STATUS_SKIP,
+};
+#define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NL_MMAP_MSG_ALIGN(sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)
+#define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr))
+#define NET_MAJOR 36
+enum {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ NETLINK_UNCONNECTED = 0,
+ NETLINK_CONNECTED,
+};
+struct nlattr {
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ __u16 nla_len;
+ __u16 nla_type;
+};
+#define NLA_F_NESTED (1 << 15)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLA_F_NET_BYTEORDER (1 << 14)
+#define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
+#define NLA_ALIGNTO 4
+#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+#define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
+#endif
diff --git a/tests/tests/security/jni/sock_diag.h b/tests/tests/security/jni/sock_diag.h
new file mode 100644
index 0000000..0dc2902
--- /dev/null
+++ b/tests/tests/security/jni/sock_diag.h
@@ -0,0 +1,43 @@
+/****************************************************************************
+ ****************************************************************************
+ ***
+ ***   This header was automatically generated from a Linux kernel header
+ ***   of the same name, to make information necessary for userspace to
+ ***   call into the kernel available to libc.  It contains only constants,
+ ***   structures, and macros generated from the original header, and thus,
+ ***   contains no copyrightable information.
+ ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
+ ****************************************************************************
+ ****************************************************************************/
+#ifndef _UAPI__SOCK_DIAG_H__
+#define _UAPI__SOCK_DIAG_H__
+#include <linux/types.h>
+#define SOCK_DIAG_BY_FAMILY 20
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+struct sock_diag_req {
+ __u8 sdiag_family;
+ __u8 sdiag_protocol;
+};
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+enum {
+ SK_MEMINFO_RMEM_ALLOC,
+ SK_MEMINFO_RCVBUF,
+ SK_MEMINFO_WMEM_ALLOC,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SK_MEMINFO_SNDBUF,
+ SK_MEMINFO_FWD_ALLOC,
+ SK_MEMINFO_WMEM_QUEUED,
+ SK_MEMINFO_OPTMEM,
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
+ SK_MEMINFO_BACKLOG,
+ SK_MEMINFO_VARS,
+};
+#endif
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
diff --git a/tests/tests/security/src/android/security/cts/NativeCodeTest.java b/tests/tests/security/src/android/security/cts/NativeCodeTest.java
index a9fd821..6634310 100644
--- a/tests/tests/security/src/android/security/cts/NativeCodeTest.java
+++ b/tests/tests/security/src/android/security/cts/NativeCodeTest.java
@@ -39,6 +39,12 @@
         assertTrue(doPerfEventTest2());
     }
 
+    public void testSockDiag() throws Exception {
+        int result = doSockDiagTest();
+        assertFalse("Encountered unexpected error: " + result + ".", (result == -1));
+        assertEquals(0, result);
+    }
+
     /**
      * Returns true iff this device is vulnerable to CVE-2013-2094.
      * A patch for CVE-2013-2094 can be found at
@@ -84,4 +90,10 @@
      * false if the device is vulnerable.
      */
     private static native boolean doCVE20141710Test();
+
+    /**
+     * Hangs if device is vulnerable to CVE-2013-1763, returns -1 if
+     * unexpected error occurs, 0 otherwise.
+     */
+    private static native int doSockDiagTest();
 }
diff --git a/tests/tests/security/src/android/security/cts/ServicePermissionsTest.java b/tests/tests/security/src/android/security/cts/ServicePermissionsTest.java
index 8c02d6b..00cbfd8 100644
--- a/tests/tests/security/src/android/security/cts/ServicePermissionsTest.java
+++ b/tests/tests/security/src/android/security/cts/ServicePermissionsTest.java
@@ -17,6 +17,7 @@
 package android.security.cts;
 
 import android.os.IBinder;
+import android.os.TransactionTooLargeException;
 import android.test.AndroidTestCase;
 import android.util.Log;
 
@@ -99,13 +100,17 @@
             try {
                 serviceBinder.dump(out.getFD(), new String[0]);
             } catch (SecurityException e) {
-                if (e.getMessage().contains("android.permission.DUMP")) {
+                String msg = e.getMessage();
+                if ((msg == null) || msg.contains("android.permission.DUMP")) {
                     // Service correctly checked for DUMP permission, yay
                 } else {
                     // Service is throwing about something else; they're
                     // probably not checking for DUMP.
                     throw e;
                 }
+            } catch (TransactionTooLargeException e) {
+                // SELinux likely prevented the dump - assume safe
+                continue;
             } finally {
                 out.close();
             }
diff --git a/tests/tests/security/src/android/security/cts/activity/SecureRandomService.java b/tests/tests/security/src/android/security/cts/activity/SecureRandomService.java
deleted file mode 100644
index 2d425b3..0000000
--- a/tests/tests/security/src/android/security/cts/activity/SecureRandomService.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2013 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 android.security.cts.activity;
-
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Message;
-import android.security.cts.activity.ISecureRandomService;
-
-import android.app.Service;
-import android.content.Intent;
-
-import java.security.SecureRandom;
-
-public class SecureRandomService extends Service {
-    /**
-     * This helps the process shut down a little faster and get us a new
-     * PID earlier than calling stopService.
-     */
-    private Handler mShutdownHandler = new Handler() {
-        @Override
-        public void handleMessage(Message msg) {
-            stopSelf();
-        }
-    };
-
-    private final ISecureRandomService.Stub mBinder = new ISecureRandomService.Stub() {
-
-        /**
-         * Returns output from SecureRandom and the current process PID. Note
-         * that this should only be called once. To ensure that it's only called
-         * once, this will throw an error if it's called twice in a row.
-         */
-        public int getRandomBytesAndPid(byte[] randomBytes) {
-            mShutdownHandler.sendEmptyMessage(-1);
-
-            SecureRandom sr = new SecureRandom();
-            sr.nextBytes(randomBytes);
-            return android.os.Process.myPid();
-        }
-    };
-
-    @Override
-    public IBinder onBind(Intent intent) {
-        return mBinder;
-    }
-}
diff --git a/tests/tests/text/src/android/text/cts/EmojiTest.java b/tests/tests/text/src/android/text/cts/EmojiTest.java
index f5f191f..4bcc0e1 100644
--- a/tests/tests/text/src/android/text/cts/EmojiTest.java
+++ b/tests/tests/text/src/android/text/cts/EmojiTest.java
@@ -25,6 +25,7 @@
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.View;
+import android.webkit.cts.NullWebViewUtils;
 import android.webkit.cts.WebViewOnUiThread;
 import android.widget.TextView;
 import android.widget.EditText;
@@ -58,7 +59,6 @@
      */
     public void testEmojiGlyph() {
         CaptureCanvas ccanvas = new CaptureCanvas(getInstrumentation().getContext());
-        CaptureWebView cwebview = new CaptureWebView(getInstrumentation().getContext());
 
         Bitmap mBitmapA, mBitmapB;  // Emoji displayed Bitmaps to compare
 
@@ -92,11 +92,15 @@
 
             assertFalse(mBitmapA.sameAs(mBitmapB));
 
-            mBitmapA = cwebview.capture(Character.toChars(comparedCodePoints[i][0]));
-            mBitmapB = cwebview.capture(Character.toChars(comparedCodePoints[i][1]));
-
-            assertFalse(mBitmapA.sameAs(mBitmapB));
-
+            // Trigger activity bringup so we can determine if a WebView is available on this
+            // device.
+            EmojiStubActivity activity = getActivity();
+            if (NullWebViewUtils.isWebViewAvailable()) {
+                CaptureWebView cwebview = new CaptureWebView(getInstrumentation().getContext());
+                mBitmapA = cwebview.capture(Character.toChars(comparedCodePoints[i][0]));
+                mBitmapB = cwebview.capture(Character.toChars(comparedCodePoints[i][1]));
+                assertFalse(mBitmapA.sameAs(mBitmapB));
+            }
         }
     }
 
diff --git a/tests/tests/text/src/android/text/cts/MyanmarTest.java b/tests/tests/text/src/android/text/cts/MyanmarTest.java
new file mode 100644
index 0000000..60fe608
--- /dev/null
+++ b/tests/tests/text/src/android/text/cts/MyanmarTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2014 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 android.text.cts;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.test.ActivityInstrumentationTestCase2;
+import android.widget.TextView;
+
+public class MyanmarTest extends ActivityInstrumentationTestCase2<Activity> {
+
+    public MyanmarTest() {
+        super("com.android.cts.stub", Activity.class);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Tests Unicode composition semantics.
+     */
+    public void testCompositionSemantics() {
+        String textA = "\u1019\u102d\u102f";
+        String textB = "\u1019\u102f\u102d"; // wrong order for Unicode
+
+        CaptureTextView cviewA = new CaptureTextView(getInstrumentation().getContext());
+        Bitmap bitmapA = cviewA.capture(textA);
+        CaptureTextView cviewB = new CaptureTextView(getInstrumentation().getContext());
+        Bitmap bitmapB = cviewB.capture(textB);
+        if (bitmapA.sameAs(bitmapB)) {
+            // if textA and textB render identically, test against replacement characters
+            String textC = "\ufffd\ufffd\ufffd"; // replacement characters are acceptable
+            CaptureTextView cviewC = new CaptureTextView(getInstrumentation().getContext());
+            Bitmap bitmapC = cviewC.capture(textC);
+            if (!bitmapA.sameAs(bitmapC)) {
+                // ...or against blank/empty glyphs
+                Bitmap bitmapD = Bitmap.createBitmap(bitmapC.getWidth(), bitmapC.getHeight(),
+                        bitmapC.getConfig());
+                assertTrue(bitmapA.sameAs(bitmapD));
+            }
+        }
+    }
+
+    private class CaptureTextView extends TextView {
+
+        CaptureTextView(Context context) {
+            super(context);
+        }
+
+        Bitmap capture(String text) {
+            setText(text);
+
+            invalidate();
+
+            setDrawingCacheEnabled(true);
+            measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
+                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
+            layout(0, 0, 200,200);
+
+            Bitmap bitmap = Bitmap.createBitmap(getDrawingCache());
+            setDrawingCacheEnabled(false);
+            return bitmap;
+        }
+
+    }
+}
diff --git a/tests/tests/text/src/android/text/method/cts/TouchTest.java b/tests/tests/text/src/android/text/method/cts/TouchTest.java
index 3071fd6..58e889a 100644
--- a/tests/tests/text/src/android/text/method/cts/TouchTest.java
+++ b/tests/tests/text/src/android/text/method/cts/TouchTest.java
@@ -34,6 +34,10 @@
     private static final String LONG_TEXT = "Scrolls the specified widget to the specified " +
             "coordinates, except constrains the X scrolling position to the horizontal regions " +
             "of the text that will be visible after scrolling to the specified Y position." +
+            "This is the description of the test." +
+            "Scrolls the specified widget to the specified " +
+            "coordinates, except constrains the X scrolling position to the horizontal regions " +
+            "of the text that will be visible after scrolling to the specified Y position." +
             "This is the description of the test.";
 
     private boolean mReturnFromTouchEvent;
diff --git a/tests/tests/theme/src/android/theme/cts/DeviceDefaultTest.java b/tests/tests/theme/src/android/theme/cts/DeviceDefaultTest.java
index 086dce1..77de0b4 100644
--- a/tests/tests/theme/src/android/theme/cts/DeviceDefaultTest.java
+++ b/tests/tests/theme/src/android/theme/cts/DeviceDefaultTest.java
@@ -19,6 +19,7 @@
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.test.ActivityInstrumentationTestCase2;
 
@@ -85,7 +86,7 @@
     }
 
     public void testGetActionBar_DeviceDefault_Light_DialogWhenLarge() {
-        assertActionBarWhenLarge(android.R.style.Theme_Holo_Light_DialogWhenLarge);
+        assertActionBarWhenLarge(android.R.style.Theme_DeviceDefault_Light_DialogWhenLarge);
     }
 
     public void testGetActionBar_DeviceDefault_Light_DialogWhenLarge_NoActionBar() {
@@ -122,6 +123,10 @@
 
     private void assertGetActionBar(int themeId, boolean actionBar) {
         Activity activity = startActivity(themeId);
+        if (activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+            assertNull(activity.getActionBar());
+            return;
+        }
         if (actionBar) {
             assertNotNull(activity.getActionBar());
         } else {
diff --git a/tests/tests/util/src/android/util/cts/DisplayMetricsTest.java b/tests/tests/util/src/android/util/cts/DisplayMetricsTest.java
index d7c1895..fd8fa53 100644
--- a/tests/tests/util/src/android/util/cts/DisplayMetricsTest.java
+++ b/tests/tests/util/src/android/util/cts/DisplayMetricsTest.java
@@ -36,9 +36,9 @@
         outMetrics.setToDefaults();
         assertEquals(0, outMetrics.widthPixels);
         assertEquals(0, outMetrics.heightPixels);
-        // according to Android enmulator doc UI -scale confine density should between 0.1 to 3
-        assertTrue((0.1 <= outMetrics.density) && (outMetrics.density <= 3));
-        assertTrue((0.1 <= outMetrics.scaledDensity) && (outMetrics.scaledDensity <= 3));
+        // according to Android emulator doc UI -scale confine density should between 0.1 to 4
+        assertTrue((0.1 <= outMetrics.density) && (outMetrics.density <= 4));
+        assertTrue((0.1 <= outMetrics.scaledDensity) && (outMetrics.scaledDensity <= 4));
         assertTrue(0 < outMetrics.xdpi);
         assertTrue(0 < outMetrics.ydpi);
 
@@ -48,9 +48,9 @@
         metrics.setTo(outMetrics);
         assertEquals(display.getHeight(), metrics.heightPixels);
         assertEquals(display.getWidth(), metrics.widthPixels);
-        // according to Android enmulator doc UI -scale confine density should between 0.1 to 3
-        assertTrue((0.1 <= metrics.density) && (metrics.density <= 3));
-        assertTrue((0.1 <= metrics.scaledDensity) && (metrics.scaledDensity <= 3));
+        // according to Android emulator doc UI -scale confine density should between 0.1 to 4
+        assertTrue((0.1 <= metrics.density) && (metrics.density <= 4));
+        assertTrue((0.1 <= metrics.scaledDensity) && (metrics.scaledDensity <= 4));
         assertTrue(0 < metrics.xdpi);
         assertTrue(0 < metrics.ydpi);
     }
diff --git a/tests/tests/util/src/android/util/cts/TypedValueTest.java b/tests/tests/util/src/android/util/cts/TypedValueTest.java
index 5cd7463..2ab91d9 100644
--- a/tests/tests/util/src/android/util/cts/TypedValueTest.java
+++ b/tests/tests/util/src/android/util/cts/TypedValueTest.java
@@ -205,16 +205,4 @@
 
         assertEquals(TypedValue.complexToDimension(10, dm), tv.getDimension(dm));
     }
-
-    public void testComplexToDimensionNoisy() {
-        DisplayMetrics dm = new DisplayMetrics();
-        dm.density = 1.1f;
-        dm.heightPixels = 100;
-        dm.scaledDensity = 2.1f;
-        dm.xdpi = 200f;
-        dm.ydpi = 300f;
-
-        assertEquals(TypedValue.complexToDimension(1, dm),
-                                 TypedValue.complexToDimensionNoisy(1, dm));
-    }
 }
diff --git a/tests/tests/view/src/android/view/cts/WindowTest.java b/tests/tests/view/src/android/view/cts/WindowTest.java
index 7e147ab..afe5f0d 100644
--- a/tests/tests/view/src/android/view/cts/WindowTest.java
+++ b/tests/tests/view/src/android/view/cts/WindowTest.java
@@ -1088,5 +1088,8 @@
 
         public void onActionModeFinished(ActionMode mode) {
         }
+
+        public void onWindowDismissed() {
+        }
     }
 }
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
index a0b4fa6..ead235e 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieManagerTest.java
@@ -42,13 +42,19 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
 
-        mCookieManager = CookieManager.getInstance();
-        assertNotNull(mCookieManager);
+            mCookieManager = CookieManager.getInstance();
+            assertNotNull(mCookieManager);
+        }
     }
 
     public void testGetInstance() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mOnUiThread.cleanUp();
         CookieManager c1 = CookieManager.getInstance();
         CookieManager c2 = CookieManager.getInstance();
@@ -57,9 +63,15 @@
     }
 
     public void testClone() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
     }
 
     public void testAcceptCookie() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mCookieManager.removeAllCookie();
         mCookieManager.setAcceptCookie(false);
         assertFalse(mCookieManager.acceptCookie());
@@ -113,6 +125,9 @@
     }
 
     public void testCookieManager() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // enable cookie
         mCookieManager.setAcceptCookie(true);
         assertTrue(mCookieManager.acceptCookie());
@@ -146,6 +161,9 @@
 
     @SuppressWarnings("deprecation")
     public void testRemoveCookies() throws InterruptedException {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // enable cookie
         mCookieManager.setAcceptCookie(true);
         assertTrue(mCookieManager.acceptCookie());
@@ -212,6 +230,9 @@
     }
 
     public void testb3167208() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String uri = "http://host.android.com/path/";
         // note the space after the domain=
         String problemCookie = "foo=bar; domain= .android.com; path=/";
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
index 67a77e7..e2112b7 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieSyncManagerTest.java
@@ -33,6 +33,9 @@
     }
 
     public void testCookieSyncManager() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         CookieSyncManager csm1 = CookieSyncManager.createInstance(getActivity());
         assertNotNull(csm1);
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
index 0c0396a..704ae24 100644
--- a/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/CookieTest.java
@@ -16,22 +16,30 @@
 
 package android.webkit.cts;
 
-import android.test.AndroidTestCase;
+import android.test.ActivityInstrumentationTestCase2;
 import android.webkit.CookieManager;
 import android.webkit.CookieSyncManager;
 
 /**
  * Original framework tests for CookieManager
  */
-public class CookieTest extends AndroidTestCase {
+public class CookieTest extends ActivityInstrumentationTestCase2<CookieSyncManagerStubActivity> {
 
     private CookieManager mCookieManager;
     private static final long WAIT_TIME = 50;
 
+    public CookieTest() {
+        super("com.android.cts.stub", CookieSyncManagerStubActivity.class);
+    }
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        CookieSyncManager.createInstance(getContext());
+
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         mCookieManager = CookieManager.getInstance();
         mCookieManager.removeAllCookie();
         // cookies are removed asynchronously, wait a bit for cookies to be removed
@@ -48,6 +56,9 @@
     }
 
     public void testDomain() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String url = "http://www.foo.com";
 
         // basic
@@ -86,6 +97,9 @@
     }
 
     public void testSubDomain() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String url_abcd = "http://a.b.c.d.com";
         String url_bcd = "http://b.c.d.com";
         String url_cd = "http://c.d.com";
@@ -127,6 +141,9 @@
     }
 
     public void testInvalidDomain() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String url = "http://foo.bar.com";
 
         mCookieManager.setCookie(url, "a=1; domain=.yo.foo.bar.com");
@@ -163,6 +180,9 @@
     }
 
     public void testPath() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String url = "http://www.foo.com";
 
         mCookieManager.setCookie(url, "a=b; path=/wee");
@@ -192,6 +212,9 @@
     }
 
     public void testEmptyValue() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         String url = "http://www.foobar.com";
 
         mCookieManager.setCookie(url, "bar=");
diff --git a/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java b/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
index 016d7c2..8ab9eb6 100644
--- a/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/GeolocationTest.java
@@ -135,49 +135,58 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        // Set up a WebView with JavaScript and Geolocation enabled
-        final String GEO_DIR = "geo_test";
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
-        mOnUiThread.getSettings().setJavaScriptEnabled(true);
-        mOnUiThread.getSettings().setGeolocationEnabled(true);
-        mOnUiThread.getSettings().setGeolocationDatabasePath(
-                getActivity().getApplicationContext().getDir(GEO_DIR, 0).getPath());
+        WebView webview = getActivity().getWebView();
 
-        // Add a JsInterface to report back to the test when a location is received
-        mJavascriptStatusReceiver = new JavascriptStatusReceiver();
-        mOnUiThread.addJavascriptInterface(mJavascriptStatusReceiver, JS_INTERFACE_NAME);
+        if (webview != null) {
+            // Set up a WebView with JavaScript and Geolocation enabled
+            final String GEO_DIR = "geo_test";
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+            mOnUiThread.getSettings().setJavaScriptEnabled(true);
+            mOnUiThread.getSettings().setGeolocationEnabled(true);
+            mOnUiThread.getSettings().setGeolocationDatabasePath(
+                    getActivity().getApplicationContext().getDir(GEO_DIR, 0).getPath());
 
-        // Always intercept all loads with the same geolocation test page
-        mOnUiThread.setWebViewClient(new InterceptClient(mOnUiThread));
-        // Clear all permissions before each test
-        GeolocationPermissions.getInstance().clearAll();
-        // Cache this mostly because the lookup is two lines of code
-        mLocationManager = (LocationManager)getActivity().getApplicationContext()
-                .getSystemService(Context.LOCATION_SERVICE);
-        // Add a test provider before each test to inject a location
-        mProviders = mLocationManager.getAllProviders();
-        for (String provider : mProviders) {
-            // Can't mock passive provider.
-            if (provider.equals(LocationManager.PASSIVE_PROVIDER)) {
-                mProviders.remove(provider);
-                break;
+            // Add a JsInterface to report back to the test when a location is received
+            mJavascriptStatusReceiver = new JavascriptStatusReceiver();
+            mOnUiThread.addJavascriptInterface(mJavascriptStatusReceiver, JS_INTERFACE_NAME);
+
+            // Always intercept all loads with the same geolocation test page
+            mOnUiThread.setWebViewClient(new InterceptClient(mOnUiThread));
+            // Clear all permissions before each test
+            GeolocationPermissions.getInstance().clearAll();
+            // Cache this mostly because the lookup is two lines of code
+            mLocationManager = (LocationManager)getActivity().getApplicationContext()
+                    .getSystemService(Context.LOCATION_SERVICE);
+            // Add a test provider before each test to inject a location
+            mProviders = mLocationManager.getAllProviders();
+            for (String provider : mProviders) {
+                // Can't mock passive provider.
+                if (provider.equals(LocationManager.PASSIVE_PROVIDER)) {
+                    mProviders.remove(provider);
+                    break;
+                }
             }
+            addTestProviders();
         }
-        addTestProviders();
     }
 
     @Override
     protected void tearDown() throws Exception {
         stopUpdateLocationThread();
-        // Remove the test provider after each test
-        for (String provider : mProviders) {
-            try {
-                // Work around b/11446702 by clearing the test provider before removing it
-                mLocationManager.clearTestProviderEnabled(provider);
-                mLocationManager.removeTestProvider(provider);
-            } catch (IllegalArgumentException e) {} // Not much to do about this
+        if (mProviders != null) {
+            // Remove the test provider after each test
+            for (String provider : mProviders) {
+                try {
+                    // Work around b/11446702 by clearing the test provider before removing it
+                    mLocationManager.clearTestProviderEnabled(provider);
+                    mLocationManager.removeTestProvider(provider);
+                } catch (IllegalArgumentException e) {} // Not much to do about this
+            }
         }
-        mOnUiThread.cleanUp();
+
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         // This will null all member and static variables
         super.tearDown();
     }
@@ -278,6 +287,9 @@
 
     // Test loading a page and accepting the domain for one load
     public void testSimpleGeolocationRequestAcceptOnce() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final TestSimpleGeolocationRequestWebChromeClient chromeClientAcceptOnce =
                 new TestSimpleGeolocationRequestWebChromeClient(mOnUiThread, true, false);
         mOnUiThread.setWebChromeClient(chromeClientAcceptOnce);
@@ -368,6 +380,9 @@
 
     // Test loading a page and retaining the domain forever
     public void testSimpleGeolocationRequestAcceptAlways() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final TestSimpleGeolocationRequestWebChromeClient chromeClientAcceptAlways =
                 new TestSimpleGeolocationRequestWebChromeClient(mOnUiThread, true, true);
         mOnUiThread.setWebChromeClient(chromeClientAcceptAlways);
@@ -424,6 +439,9 @@
 
     // Test the GeolocationPermissions API
     public void testGeolocationPermissions() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         Set<String> acceptedOrigins = new TreeSet<String>();
         BooleanCheck falseCheck = new BooleanCheck(false);
         GeolocationPermissions.getInstance().getAllowed(URL_2, falseCheck);
@@ -483,6 +501,9 @@
 
     // Test loading pages and checks rejecting once and recjecting the domain forever
     public void testSimpleGeolocationRequestReject() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final TestSimpleGeolocationRequestWebChromeClient chromeClientRejectOnce =
                 new TestSimpleGeolocationRequestWebChromeClient(mOnUiThread, false, false);
         mOnUiThread.setWebChromeClient(chromeClientRejectOnce);
diff --git a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
index 52e9278..b078c7a 100644
--- a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
@@ -43,12 +43,18 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+        }
     }
 
     @Override
     protected void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
+
         if (mWebServer != null) {
             mWebServer.shutdown();
         }
@@ -138,6 +144,9 @@
     }
 
     public void testProceed() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebServer = new CtsTestServer(getActivity());
         String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
 
@@ -147,6 +156,9 @@
     }
 
     public void testCancel() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebServer = new CtsTestServer(getActivity());
         String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
 
@@ -159,6 +171,9 @@
     }
 
     public void testUseHttpAuthUsernamePassword() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebServer = new CtsTestServer(getActivity());
         String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java b/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
index 34dc697..71893f4 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebBackForwardListTest.java
@@ -20,6 +20,7 @@
 import android.test.ActivityInstrumentationTestCase2;
 import android.webkit.WebBackForwardList;
 import android.webkit.WebHistoryItem;
+import android.webkit.WebView;
 
 
 public class WebBackForwardListTest extends ActivityInstrumentationTestCase2<WebViewStubActivity> {
@@ -35,16 +36,24 @@
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+        }
     }
 
     @Override
     public void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         super.tearDown();
     }
 
     public void testGetCurrentItem() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         WebBackForwardList list = mOnUiThread.copyBackForwardList();
 
         assertNull(list.getCurrentItem());
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 5c9c958..3142298 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -44,13 +44,18 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+        }
         mWebServer = new CtsTestServer(getActivity());
     }
 
     @Override
     protected void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         if (mWebServer != null) {
             mWebServer.shutdown();
         }
@@ -62,6 +67,9 @@
     }
 
     public void testOnProgressChanged() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -78,6 +86,9 @@
     }
 
     public void testOnReceivedTitle() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -96,6 +107,9 @@
     }
 
     public void testOnReceivedIcon() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -159,20 +173,32 @@
         }
     }
     public void testWindows() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         runWindowTest(true);
     }
 
     public void testBlockWindowsSync() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mBlockWindowCreationSync = true;
         runWindowTest(false);
     }
 
     public void testBlockWindowsAsync() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mBlockWindowCreationAsync = true;
         runWindowTest(false);
     }
 
     public void testOnJsBeforeUnload() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -196,6 +222,9 @@
     }
 
     public void testOnJsAlert() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -218,6 +247,9 @@
     }
 
     public void testOnJsConfirm() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
@@ -240,6 +272,9 @@
     }
 
     public void testOnJsPrompt() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebChromeClient webChromeClient = new MockWebChromeClient();
         mOnUiThread.setWebChromeClient(webChromeClient);
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
index 468430f..7d276e9 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebHistoryItemTest.java
@@ -54,12 +54,17 @@
     protected void setUp() throws Exception {
         super.setUp();
         mWebServer = new CtsTestServer(getActivity());
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+        }
     }
 
     @Override
     protected void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         mWebServer.shutdown();
         super.tearDown();
         if (mIconDb != null) {
@@ -69,6 +74,9 @@
     }
 
     public void testWebHistoryItem() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final WaitForIconClient waitForIconClient = new WaitForIconClient(mOnUiThread);
         mOnUiThread.setWebChromeClient(waitForIconClient);
         runTestOnUiThread(new Runnable() {
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index 291136f..c2104fe 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -65,8 +65,11 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mOnUiThread = new WebViewOnUiThread(this, getActivity().getWebView());
-        mSettings = mOnUiThread.getSettings();
+        WebView webview = getActivity().getWebView();
+        if (webview != null) {
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+            mSettings = mOnUiThread.getSettings();
+        }
         mContext = getInstrumentation().getTargetContext();
     }
 
@@ -75,7 +78,9 @@
         if (mWebServer != null) {
             mWebServer.shutdown();
         }
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         super.tearDown();
     }
 
@@ -90,6 +95,9 @@
      * Safari/<major>.<minor>
      */
     public void testUserAgentString_default() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final String actualUserAgentString = mSettings.getUserAgentString();
         Log.i(LOG_TAG, String.format("Checking user agent string %s", actualUserAgentString));
         final String patternString =
@@ -131,6 +139,9 @@
     }
 
     public void testAccessUserAgentString() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         startWebServer();
         String url = mWebServer.getUserAgentUrl();
 
@@ -159,6 +170,9 @@
     }
 
     public void testAccessAllowFileAccess() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // This test is not compatible with 4.0.3
         if ("4.0.3".equals(Build.VERSION.RELEASE)) {
             return;
@@ -184,6 +198,9 @@
     }
 
     public void testAccessCacheMode() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         runTestOnUiThread(new Runnable() {
             @Override
             public void run() {
@@ -256,6 +273,9 @@
     }
 
     public void testAccessCursiveFontFamily() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getCursiveFontFamily());
 
         String newCusiveFamily = "Apple Chancery";
@@ -264,6 +284,9 @@
     }
 
     public void testAccessFantasyFontFamily() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getFantasyFontFamily());
 
         String newFantasyFamily = "Papyrus";
@@ -272,6 +295,9 @@
     }
 
     public void testAccessFixedFontFamily() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getFixedFontFamily());
 
         String newFixedFamily = "Courier";
@@ -280,6 +306,9 @@
     }
 
     public void testAccessSansSerifFontFamily() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getSansSerifFontFamily());
 
         String newFixedFamily = "Verdana";
@@ -288,6 +317,9 @@
     }
 
     public void testAccessSerifFontFamily() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getSerifFontFamily());
 
         String newSerifFamily = "Times";
@@ -296,6 +328,9 @@
     }
 
     public void testAccessStandardFontFamily() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getStandardFontFamily());
 
         String newStandardFamily = "Times";
@@ -304,6 +339,9 @@
     }
 
     public void testAccessDefaultFontSize() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         int defaultSize = mSettings.getDefaultFontSize();
         assertTrue(defaultSize > 0);
 
@@ -322,6 +360,9 @@
     }
 
     public void testAccessDefaultFixedFontSize() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         int defaultSize = mSettings.getDefaultFixedFontSize();
         assertTrue(defaultSize > 0);
 
@@ -340,6 +381,9 @@
     }
 
     public void testAccessDefaultTextEncodingName() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getDefaultTextEncodingName());
 
         String newEncodingName = "iso-8859-1";
@@ -348,6 +392,9 @@
     }
 
     public void testAccessJavaScriptCanOpenWindowsAutomatically() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mSettings.setJavaScriptEnabled(true);
 
         mSettings.setJavaScriptCanOpenWindowsAutomatically(false);
@@ -372,6 +419,9 @@
     }
 
     public void testAccessJavaScriptEnabled() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mSettings.setJavaScriptEnabled(true);
         assertTrue(mSettings.getJavaScriptEnabled());
         loadAssetUrl(TestHtmlConstants.JAVASCRIPT_URL);
@@ -395,6 +445,9 @@
     }
 
     public void testAccessLayoutAlgorithm() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertEquals(WebSettings.LayoutAlgorithm.NARROW_COLUMNS, mSettings.getLayoutAlgorithm());
 
         mSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
@@ -405,6 +458,9 @@
     }
 
     public void testAccessMinimumFontSize() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertEquals(8, mSettings.getMinimumFontSize());
 
         mSettings.setMinimumFontSize(100);
@@ -418,6 +474,9 @@
     }
 
     public void testAccessMinimumLogicalFontSize() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertEquals(8, mSettings.getMinimumLogicalFontSize());
 
         mSettings.setMinimumLogicalFontSize(100);
@@ -431,6 +490,9 @@
     }
 
     public void testAccessPluginsEnabled() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getPluginsEnabled());
 
         mSettings.setPluginsEnabled(true);
@@ -438,6 +500,9 @@
     }
 
     public void testAccessPluginsPath() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(mSettings.getPluginsPath());
 
         String pluginPath = "pluginPath";
@@ -447,6 +512,9 @@
     }
 
     public void testAccessSaveFormData() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertTrue(mSettings.getSaveFormData());
 
         mSettings.setSaveFormData(false);
@@ -454,6 +522,9 @@
     }
 
     public void testAccessTextSize() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertEquals(TextSize.NORMAL, mSettings.getTextSize());
 
         mSettings.setTextSize(TextSize.LARGER);
@@ -470,6 +541,9 @@
     }
 
     public void testAccessUseDoubleTree() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getUseDoubleTree());
 
         mSettings.setUseDoubleTree(true);
@@ -478,6 +552,9 @@
     }
 
     public void testAccessUseWideViewPort() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getUseWideViewPort());
 
         mSettings.setUseWideViewPort(true);
@@ -485,12 +562,18 @@
     }
 
     public void testSetNeedInitialFocus() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mSettings.setNeedInitialFocus(false);
 
         mSettings.setNeedInitialFocus(true);
     }
 
     public void testSetRenderPriority() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
 
         mSettings.setRenderPriority(WebSettings.RenderPriority.LOW);
@@ -499,6 +582,9 @@
     }
 
     public void testAccessSupportMultipleWindows() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.supportMultipleWindows());
 
         mSettings.setSupportMultipleWindows(true);
@@ -506,6 +592,9 @@
     }
 
     public void testAccessSupportZoom() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertTrue(mSettings.supportZoom());
 
         runTestOnUiThread(new Runnable() {
@@ -518,6 +607,9 @@
     }
 
     public void testAccessBuiltInZoomControls() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getBuiltInZoomControls());
 
         runTestOnUiThread(new Runnable() {
@@ -530,6 +622,9 @@
     }
 
     public void testAppCacheDisabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Test that when AppCache is disabled, we don't get any AppCache
         // callbacks.
         startWebServer();
@@ -549,6 +644,9 @@
     }
 
     public void testAppCacheEnabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Note that the AppCache path can only be set once. This limits the
         // amount of testing we can do, and means that we must test all aspects
         // of setting the AppCache path in a single test to guarantee ordering.
@@ -594,6 +692,9 @@
     // using a URL. Finally, it looks like enabling database requires creating a
     // webChromeClient and listening to Quota callbacks, which is not documented.
     public void testDatabaseDisabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Verify that websql database does not work when disabled.
         startWebServer();
 
@@ -612,6 +713,9 @@
     }
 
     public void testLoadsImagesAutomatically() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertTrue(mSettings.getLoadsImagesAutomatically());
 
         startWebServer();
@@ -644,6 +748,9 @@
     }
 
     public void testBlockNetworkImage() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getBlockNetworkImage());
 
         startWebServer();
@@ -673,6 +780,9 @@
     }
 
     public void testBlockNetworkLoads() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertFalse(mSettings.getBlockNetworkLoads());
 
         startWebServer();
@@ -709,6 +819,9 @@
 
     // Verify that an image in local file system can be loaded by an asset
     public void testLocalImageLoads() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         mSettings.setJavaScriptEnabled(true);
         // Check that local images are loaded without issues regardless of domain checkings
@@ -723,6 +836,9 @@
     // Verify that javascript cross-domain request permissions matches file domain settings
     // for iframes
     public void testIframesWhenAccessFromFileURLsEnabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         mSettings.setJavaScriptEnabled(true);
         // disable universal access from files
@@ -739,6 +855,9 @@
     // Verify that javascript cross-domain request permissions matches file domain settings
     // for iframes
     public void testIframesWhenAccessFromFileURLsDisabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         mSettings.setJavaScriptEnabled(true);
         // disable universal access from files
@@ -757,11 +876,17 @@
 
     // Verify that enabling file access from file URLs enable XmlHttpRequest (XHR) across files
     public void testXHRWhenAccessFromFileURLsEnabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         verifyFileXHR(true);
     }
 
     // Verify that disabling file access from file URLs disable XmlHttpRequest (XHR) accross files
     public void testXHRWhenAccessFromFileURLsDisabled() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         final ChromeClient webChromeClient = new ChromeClient(mOnUiThread);
         mOnUiThread.setWebChromeClient(webChromeClient);
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
index f78c126..7872dbe 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewClientTest.java
@@ -47,18 +47,24 @@
     protected void setUp() throws Exception {
         super.setUp();
         final WebViewStubActivity activity = getActivity();
-        new PollingCheck(TEST_TIMEOUT) {
-            @Override
-                protected boolean check() {
-                return activity.hasWindowFocus();
-            }
-        }.run();
-        mOnUiThread = new WebViewOnUiThread(this, activity.getWebView());
+        WebView webview = activity.getWebView();
+        if (webview != null) {
+            new PollingCheck(TEST_TIMEOUT) {
+                @Override
+                    protected boolean check() {
+                    return activity.hasWindowFocus();
+                }
+            }.run();
+
+            mOnUiThread = new WebViewOnUiThread(this, webview);
+        }
     }
 
     @Override
     protected void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         if (mWebServer != null) {
             mWebServer.shutdown();
         }
@@ -67,12 +73,18 @@
 
     // Verify that the shouldoverrideurlloading is false by default
     public void testShouldOverrideUrlLoadingDefault() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final WebViewClient webViewClient = new WebViewClient();
         assertFalse(webViewClient.shouldOverrideUrlLoading(mOnUiThread.getWebView(), null));
     }
 
     // Verify shouldoverrideurlloading called on top level navigation
     public void testShouldOverrideUrlLoading() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         mOnUiThread.getSettings().setJavaScriptEnabled(true);
@@ -86,6 +98,9 @@
 
     // Verify shouldoverrideurlloading called on webview called via onCreateWindow
     public void testShouldOverrideUrlLoadingOnCreateWindow() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebServer = new CtsTestServer(getActivity());
         // WebViewClient for main window
         final MockWebViewClient mainWebViewClient = new MockWebViewClient();
@@ -132,6 +147,9 @@
     }
 
     public void testLoadPage() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         mWebServer = new CtsTestServer(getActivity());
@@ -165,6 +183,9 @@
     }
 
     public void testOnReceivedError() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
 
@@ -176,6 +197,9 @@
     }
 
     public void testOnFormResubmission() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         final WebSettings settings = mOnUiThread.getSettings();
@@ -201,6 +225,9 @@
     }
 
     public void testDoUpdateVisitedHistory() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         mWebServer = new CtsTestServer(getActivity());
@@ -219,6 +246,9 @@
     }
 
     public void testOnReceivedHttpAuthRequest() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         mWebServer = new CtsTestServer(getActivity());
@@ -230,6 +260,9 @@
     }
 
     public void testShouldOverrideKeyEvent() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
 
@@ -237,6 +270,9 @@
     }
 
     public void testOnUnhandledKeyEvent() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         requireLoadedPage();
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
@@ -256,6 +292,9 @@
     }
 
     public void testOnScaleChanged() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final MockWebViewClient webViewClient = new MockWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         mWebServer = new CtsTestServer(getActivity());
@@ -264,7 +303,14 @@
         String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         mOnUiThread.loadUrlAndWaitForCompletion(url1);
 
-        mOnUiThread.zoomIn();
+        new PollingCheck(TEST_TIMEOUT) {
+            @Override
+            protected boolean check() {
+                return mOnUiThread.canZoomIn();
+            }
+        }.run();
+
+        assertTrue(mOnUiThread.zoomIn());
         new PollingCheck(TEST_TIMEOUT) {
             @Override
             protected boolean check() {
@@ -274,6 +320,9 @@
     }
 
     private void requireLoadedPage() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mOnUiThread.loadUrlAndWaitForCompletion("about:blank");
     }
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
index a7ee974..56f8f61 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewStartupTest.java
@@ -63,9 +63,17 @@
                 Log.i(TAG, "done setting cookie before creating webview");
             }
         });
+        NullWebViewUtils.NullWebViewFromThreadExceptionHandler h =
+                new NullWebViewUtils.NullWebViewFromThreadExceptionHandler();
+
+        background.setUncaughtExceptionHandler(h);
         background.start();
         background.join();
 
+        if (!h.isWebViewAvailable(mActivity)) {
+            return;
+        }
+
         // Now create WebView and test that setting the cookie beforehand really worked.
         mActivity.createAndAttachWebView();
         WebViewOnUiThread onUiThread = new WebViewOnUiThread(this, mActivity.getWebView());
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index 9815aef..d339a62 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -124,23 +124,28 @@
     protected void setUp() throws Exception {
         super.setUp();
         final WebViewStubActivity activity = getActivity();
-        new PollingCheck() {
-            @Override
-                protected boolean check() {
-                return activity.hasWindowFocus();
-            }
-        }.run();
         mWebView = activity.getWebView();
-        File f = activity.getFileStreamPath("snapshot");
-        if (f.exists()) {
-            f.delete();
+        if (mWebView != null) {
+            new PollingCheck() {
+                @Override
+                    protected boolean check() {
+                        return activity.hasWindowFocus();
+                }
+            }.run();
+            File f = activity.getFileStreamPath("snapshot");
+            if (f.exists()) {
+                f.delete();
+            }
+
+            mOnUiThread = new WebViewOnUiThread(this, mWebView);
         }
-        mOnUiThread = new WebViewOnUiThread(this, mWebView);
     }
 
     @Override
     protected void tearDown() throws Exception {
-        mOnUiThread.cleanUp();
+        if (mOnUiThread != null) {
+            mOnUiThread.cleanUp();
+        }
         if (mWebServer != null) {
             mWebServer.shutdown();
         }
@@ -171,6 +176,10 @@
 
     @UiThreadTest
     public void testConstructor() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         new WebView(getActivity());
         new WebView(getActivity(), null);
         new WebView(getActivity(), null, 0);
@@ -178,12 +187,19 @@
 
     @UiThreadTest
     public void testCreatingWebViewCreatesCookieSyncManager() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         new WebView(getActivity());
         assertNotNull(CookieSyncManager.getInstance());
     }
 
     @UiThreadTest
     public void testFindAddress() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         /*
          * Info about USPS
          * http://en.wikipedia.org/wiki/Postal_address#United_States
@@ -199,19 +215,25 @@
     @SuppressWarnings("deprecation")
     @UiThreadTest
     public void testGetZoomControls() {
-         WebSettings settings = mWebView.getSettings();
-         assertTrue(settings.supportZoom());
-         View zoomControls = mWebView.getZoomControls();
-         assertNotNull(zoomControls);
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+        WebSettings settings = mWebView.getSettings();
+        assertTrue(settings.supportZoom());
+        View zoomControls = mWebView.getZoomControls();
+        assertNotNull(zoomControls);
 
-         // disable zoom support
-         settings.setSupportZoom(false);
-         assertFalse(settings.supportZoom());
-         assertNull(mWebView.getZoomControls());
+        // disable zoom support
+        settings.setSupportZoom(false);
+        assertFalse(settings.supportZoom());
+        assertNull(mWebView.getZoomControls());
     }
 
     @UiThreadTest
     public void testInvokeZoomPicker() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         WebSettings settings = mWebView.getSettings();
         assertTrue(settings.supportZoom());
         startWebServer(false);
@@ -221,6 +243,10 @@
     }
 
     public void testZoom() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         // Pinch zoom is not supported in wrap_content layouts.
         mOnUiThread.setLayoutHeightToMatchParent();
 
@@ -230,6 +256,7 @@
         mWebServer = new CtsTestServer(getActivity());
         mOnUiThread.loadUrlAndWaitForCompletion(
                 mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL));
+        pollingCheckForCanZoomIn();
 
         WebSettings settings = mOnUiThread.getSettings();
         settings.setSupportZoom(false);
@@ -306,6 +333,10 @@
 
     @UiThreadTest
     public void testSetScrollBarStyle() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
         assertFalse(mWebView.overlayHorizontalScrollbar());
         assertFalse(mWebView.overlayVerticalScrollbar());
@@ -325,6 +356,10 @@
 
     @UiThreadTest
     public void testScrollBarOverlay() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         mWebView.setHorizontalScrollbarOverlay(true);
         mWebView.setVerticalScrollbarOverlay(false);
         assertTrue(mWebView.overlayHorizontalScrollbar());
@@ -338,6 +373,10 @@
 
     @UiThreadTest
     public void testLoadUrl() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         assertNull(mWebView.getUrl());
         assertNull(mWebView.getOriginalUrl());
         assertEquals(INITIAL_PROGRESS, mWebView.getProgress());
@@ -361,6 +400,10 @@
 
     @UiThreadTest
     public void testLoadUrlDoesNotStripParamsWhenLoadingContentUrls() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         Uri.Builder uriBuilder = new Uri.Builder().scheme(
                 ContentResolver.SCHEME_CONTENT).authority(MockContentProvider.AUTHORITY);
         uriBuilder.appendPath("foo.html").appendQueryParameter("param","bar");
@@ -373,6 +416,10 @@
 
     @UiThreadTest
     public void testAppInjectedXRequestedWithHeaderIsNotOverwritten() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         startWebServer(false);
         String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         HashMap<String, String> map = new HashMap<String, String>();
@@ -392,6 +439,10 @@
 
     @UiThreadTest
     public void testAppCanInjectHeadersViaImmutableMap() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         startWebServer(false);
         String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         HashMap<String, String> map = new HashMap<String, String>();
@@ -412,6 +463,10 @@
     @SuppressWarnings("deprecation")
     @UiThreadTest
     public void testGetVisibleTitleHeight() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         startWebServer(false);
         String url = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         mOnUiThread.loadUrlAndWaitForCompletion(url);
@@ -420,6 +475,10 @@
 
     @UiThreadTest
     public void testGetOriginalUrl() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         startWebServer(false);
         final String finalUrl = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         final String redirectUrl =
@@ -440,6 +499,10 @@
     }
 
     public void testStopLoading() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         assertEquals(INITIAL_PROGRESS, mOnUiThread.getProgress());
 
         startWebServer(false);
@@ -475,6 +538,10 @@
 
     @UiThreadTest
     public void testGoBackAndForward() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         assertGoBackOrForwardBySteps(false, -1);
         assertGoBackOrForwardBySteps(false, 1);
 
@@ -521,6 +588,10 @@
 
     @UiThreadTest
     public void testAddJavascriptInterface() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         WebSettings settings = mWebView.getSettings();
         settings.setJavaScriptEnabled(true);
         settings.setJavaScriptCanOpenWindowsAutomatically(true);
@@ -567,6 +638,10 @@
 
     @UiThreadTest
     public void testAddJavascriptInterfaceNullObject() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         WebSettings settings = mWebView.getSettings();
         settings.setJavaScriptEnabled(true);
         String setTitleToPropertyTypeHtml = "<html><head></head>" +
@@ -599,6 +674,10 @@
 
     @UiThreadTest
     public void testRemoveJavascriptInterface() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         WebSettings settings = mWebView.getSettings();
         settings.setJavaScriptEnabled(true);
         String setTitleToPropertyTypeHtml = "<html><head></head>" +
@@ -618,6 +697,10 @@
     }
 
     public void testUseRemovedJavascriptInterface() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
         class RemovedObject {
             @Override
             @JavascriptInterface
@@ -665,6 +748,34 @@
         assertEquals("removedObject", resultObject.getResult());
     }
 
+    public void testJavascriptInterfaceCustomPropertiesClearedOnReload() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
+
+        mOnUiThread.getSettings().setJavaScriptEnabled(true);
+
+        class DummyJavaScriptInterface {
+        }
+        final DummyJavaScriptInterface obj = new DummyJavaScriptInterface();
+        mOnUiThread.addJavascriptInterface(obj, "dummy");
+        mOnUiThread.loadUrlAndWaitForCompletion("about:blank");
+
+        EvaluateJsResultPollingCheck jsResult;
+        jsResult = new EvaluateJsResultPollingCheck("42");
+        mOnUiThread.evaluateJavascript("dummy.custom_property = 42", jsResult);
+        jsResult.run();
+        jsResult = new EvaluateJsResultPollingCheck("true");
+        mOnUiThread.evaluateJavascript("'custom_property' in dummy", jsResult);
+        jsResult.run();
+
+        mOnUiThread.reload();
+
+        jsResult = new EvaluateJsResultPollingCheck("false");
+        mOnUiThread.evaluateJavascript("'custom_property' in dummy", jsResult);
+        jsResult.run();
+    }
+
     private final class TestPictureListener implements PictureListener {
         public int callCount;
 
@@ -702,6 +813,9 @@
     }
 
     public void testCapturePicture() throws Exception, Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final TestPictureListener listener = new TestPictureListener();
 
         startWebServer(false);
@@ -726,6 +840,9 @@
     }
 
     public void testSetPictureListener() throws Exception, Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MyPictureListener implements PictureListener {
             public int callCount;
             public WebView webView;
@@ -769,6 +886,9 @@
 
     @UiThreadTest
     public void testAccessHttpAuthUsernamePassword() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         try {
             WebViewDatabase.getInstance(getActivity()).clearHttpAuthUsernamePassword();
 
@@ -830,6 +950,9 @@
     }
 
     public void testLoadData() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final String HTML_CONTENT =
                 "<html><head><title>Hello,World!</title></head><body></body>" +
                 "</html>";
@@ -858,6 +981,9 @@
 
     @UiThreadTest
     public void testLoadDataWithBaseUrl() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNull(mWebView.getUrl());
         String imgUrl = TestHtmlConstants.SMALL_IMG_URL; // relative
         // Snippet of HTML that will prevent favicon requests to the test server.
@@ -946,6 +1072,9 @@
     }
 
     public void testFindAll()  throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Make the page scrollable, so we can detect the scrolling to make sure the
         // content fully loaded.
         mOnUiThread.setInitialScale(100);
@@ -970,6 +1099,9 @@
     }
 
     public void testFindNext() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Reset the scaling so that finding the next "all" text will require scrolling.
         mOnUiThread.setInitialScale(100);
 
@@ -1026,6 +1158,9 @@
     }
 
     public void testDocumentHasImages() throws Exception, Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class DocumentHasImageCheckHandler extends Handler {
             private boolean mReceived;
             private int mMsgArg1;
@@ -1075,6 +1210,9 @@
     }
 
     public void testPageScroll() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         DisplayMetrics metrics = mOnUiThread.getDisplayMetrics();
         int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
         String p = "<p style=\"height:" + dimension + "px;\">" +
@@ -1119,6 +1257,9 @@
     }
 
     public void testGetContentHeight() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mOnUiThread.loadDataAndWaitForCompletion(
                 "<html><body></body></html>", "text/html", null);
         new PollingCheck() {
@@ -1157,12 +1298,18 @@
 
     @UiThreadTest
     public void testPlatformNotifications() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         WebView.enablePlatformNotifications();
         WebView.disablePlatformNotifications();
     }
 
     @UiThreadTest
     public void testAccessPluginList() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         assertNotNull(WebView.getPluginList());
 
         // can not find a way to install plugins
@@ -1171,12 +1318,18 @@
 
     @UiThreadTest
     public void testDestroy() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Create a new WebView, since we cannot call destroy() on a view in the hierarchy
         WebView localWebView = new WebView(getActivity());
         localWebView.destroy();
     }
 
     public void testFlingScroll() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         DisplayMetrics metrics = mOnUiThread.getDisplayMetrics();
         final int dimension = 10 * Math.max(metrics.widthPixels, metrics.heightPixels);
         String p = "<p style=\"height:" + dimension + "px;" +
@@ -1206,6 +1359,9 @@
     }
 
     public void testRequestFocusNodeHref() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         startWebServer(false);
         String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1);
         String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2);
@@ -1273,6 +1429,9 @@
     }
 
     public void testRequestImageRef() throws Exception, Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class ImageLoaded {
             public boolean mImageLoaded;
 
@@ -1353,10 +1512,16 @@
 
     @UiThreadTest
     public void testDebugDump() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebView.debugDump();
     }
 
     public void testGetHitTestResult() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final String anchor = "<p><a href=\"" + TestHtmlConstants.EXT_WEB_URL1
                 + "\">normal anchor</a></p>";
         final String blankAnchor = "<p><a href=\"\">blank anchor</a></p>";
@@ -1418,6 +1583,9 @@
     }
 
     public void testSetInitialScale() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final String p = "<p style=\"height:1000px;width:1000px\">Test setInitialScale.</p>";
         final float defaultScale =
             getInstrumentation().getTargetContext().getResources().getDisplayMetrics().density;
@@ -1469,6 +1637,9 @@
 
     @UiThreadTest
     public void testGetFavicon() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         startWebServer(false);
         String url = mWebServer.getAssetUrl(TestHtmlConstants.TEST_FAVICON_URL);
         mOnUiThread.loadUrlAndWaitForCompletion(url);
@@ -1479,6 +1650,9 @@
 
     @UiThreadTest
     public void testClearHistory() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         startWebServer(false);
         String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1);
         String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2);
@@ -1501,6 +1675,9 @@
 
     @UiThreadTest
     public void testSaveAndRestoreState() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // nothing to save
         assertNull(mWebView.saveState(new Bundle()));
 
@@ -1564,6 +1741,9 @@
     }
 
     public void testSetWebViewClient() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final ScaleChangedWebViewClient webViewClient = new ScaleChangedWebViewClient();
         mOnUiThread.setWebViewClient(webViewClient);
         startWebServer(false);
@@ -1571,13 +1751,17 @@
         assertFalse(webViewClient.onScaleChangedCalled());
         String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
         mOnUiThread.loadUrlAndWaitForCompletion(url1);
+        pollingCheckForCanZoomIn();
 
-        mOnUiThread.zoomIn();
+        assertTrue(mOnUiThread.zoomIn());
         webViewClient.waitForScaleChanged();
     }
 
     @UiThreadTest
     public void testInsecureSiteClearsCertificate() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebViewClient extends WaitForLoadedClient {
             public MockWebViewClient() {
                 super(mOnUiThread);
@@ -1606,6 +1790,9 @@
 
     @UiThreadTest
     public void testSecureSiteSetsCertificate() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebViewClient extends WaitForLoadedClient {
             public MockWebViewClient() {
                 super(mOnUiThread);
@@ -1634,6 +1821,9 @@
 
     @UiThreadTest
     public void testClearSslPreferences() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Load the first page. We expect a call to
         // WebViewClient.onReceivedSslError().
         final SslErrorWebViewClient webViewClient = new SslErrorWebViewClient();
@@ -1661,6 +1851,9 @@
     }
 
     public void testOnReceivedSslError() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebViewClient extends WaitForLoadedClient {
             private String mErrorUrl;
             private WebView mWebView;
@@ -1694,6 +1887,9 @@
     }
 
     public void testOnReceivedSslErrorProceed() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebViewClient extends WaitForLoadedClient {
             public MockWebViewClient() {
                 super(mOnUiThread);
@@ -1712,6 +1908,9 @@
     }
 
     public void testOnReceivedSslErrorCancel() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebViewClient extends WaitForLoadedClient {
             public MockWebViewClient() {
                 super(mOnUiThread);
@@ -1731,6 +1930,9 @@
     }
 
     public void testSslErrorProceedResponseReusedForSameHost() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Load the first page. We expect a call to
         // WebViewClient.onReceivedSslError().
         final SslErrorWebViewClient webViewClient = new SslErrorWebViewClient();
@@ -1751,6 +1953,9 @@
     }
 
     public void testSslErrorProceedResponseNotReusedForDifferentHost() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         // Load the first page. We expect a call to
         // WebViewClient.onReceivedSslError().
         final SslErrorWebViewClient webViewClient = new SslErrorWebViewClient();
@@ -1774,6 +1979,9 @@
     }
 
     public void testRequestChildRectangleOnScreen() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         DisplayMetrics metrics = mOnUiThread.getDisplayMetrics();
         final int dimension = 2 * Math.max(metrics.widthPixels, metrics.heightPixels);
         String p = "<p style=\"height:" + dimension + "px;width:" + dimension + "px\">&nbsp;</p>";
@@ -1797,6 +2005,9 @@
     }
 
     public void testSetDownloadListener() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MyDownloadListener implements DownloadListener {
             public String url;
             public String mimeType;
@@ -1828,9 +2039,13 @@
         // the WebView will load the new URL.
         mOnUiThread.setDownloadListener(listener);
         mOnUiThread.getSettings().setJavaScriptEnabled(true);
+
+        // See b/13675265 for discussion on why the setTimeout is necessary.
+        // Works around a Blink bug.
         mOnUiThread.loadDataAndWaitForCompletion(
-                "<html><body onload=\"window.location = \'" + url + "\'\"></body></html>",
-                "text/html", null);
+                "<html><body onload=\"setTimeout(" +
+                "function() { window.location = \'" + url + "\'; }, 100);\">" +
+                "</body></html>", "text/html", null);
         // Wait for layout to complete before setting focus.
         getInstrumentation().waitForIdleSync();
 
@@ -1849,6 +2064,9 @@
 
     @UiThreadTest
     public void testSetLayoutParams() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(600, 800);
         mWebView.setLayoutParams(params);
         assertSame(params, mWebView.getLayoutParams());
@@ -1856,10 +2074,16 @@
 
     @UiThreadTest
     public void testSetMapTrackballToArrowKeys() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mWebView.setMapTrackballToArrowKeys(true);
     }
 
     public void testSetNetworkAvailable() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         WebSettings settings = mOnUiThread.getSettings();
         settings.setJavaScriptEnabled(true);
         startWebServer(false);
@@ -1890,6 +2114,9 @@
     }
 
     public void testSetWebChromeClient() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         final class MockWebChromeClient extends WaitForProgressClient {
             private boolean mOnProgressChanged = false;
 
@@ -1927,6 +2154,9 @@
     }
 
     public void testPauseResumeTimers() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         class Monitor {
             private boolean mIsUpdated;
 
@@ -1982,6 +2212,9 @@
 
     // verify query parameters can be passed correctly to android asset files
     public void testAndroidAssetQueryParam() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         WebSettings settings = mOnUiThread.getSettings();
         settings.setJavaScriptEnabled(true);
@@ -1993,6 +2226,9 @@
 
     // verify anchors work correctly for android asset files
     public void testAndroidAssetAnchor() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
 
         WebSettings settings = mOnUiThread.getSettings();
         settings.setJavaScriptEnabled(true);
@@ -2003,6 +2239,9 @@
     }
 
     public void testEvaluateJavascript() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mOnUiThread.getSettings().setJavaScriptEnabled(true);
         mOnUiThread.loadUrlAndWaitForCompletion("about:blank");
 
@@ -2026,6 +2265,9 @@
 
     // Verify Print feature can create a PDF file with a correct preamble.
     public void testPrinting() throws Throwable {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         mOnUiThread.loadDataAndWaitForCompletion("<html><head></head>" +
                 "<body>foo</body></html>",
                 "text/html", null);
@@ -2301,6 +2543,15 @@
         }
     }
 
+    private void pollingCheckForCanZoomIn() {
+        new PollingCheck(TEST_TIMEOUT) {
+            @Override
+            protected boolean check() {
+                return mOnUiThread.canZoomIn();
+            }
+        }.run();
+    }
+
     final class ScaleChangedWebViewClient extends WaitForLoadedClient {
         private boolean mOnScaleChangedCalled = false;
         public ScaleChangedWebViewClient() {
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java b/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
index dd784be..cb72ef0 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebView_WebViewTransportTest.java
@@ -31,6 +31,9 @@
 
     @UiThreadTest
     public void testAccessWebView() {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         WebView webView = getActivity().getWebView();
         WebViewTransport transport = webView.new WebViewTransport();
 
diff --git a/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java b/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
index 758afd7..b3c0915 100644
--- a/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
+++ b/tests/tests/widget/src/android/widget/cts/RemoteViewsActivityTest.java
@@ -23,6 +23,7 @@
 import android.view.InflateException;
 import android.view.View;
 import android.view.ViewGroup;
+import android.webkit.cts.NullWebViewUtils;
 import android.widget.RemoteViews;
 
 import com.android.cts.stub.R;
@@ -96,6 +97,9 @@
 
     @MediumTest
     public void testWebView() throws Exception {
+        if (!NullWebViewUtils.isWebViewAvailable()) {
+            return;
+        }
         RemoteViews orig = new RemoteViews(PACKAGE_NAME, R.layout.remote_view_test_bad_2);
         Parcel p = Parcel.obtain();
         orig.writeToParcel(p, 0);
diff --git a/tests/tests/widget/src/android/widget/cts/TextViewTest.java b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
index 9e03f84..36ace30 100644
--- a/tests/tests/widget/src/android/widget/cts/TextViewTest.java
+++ b/tests/tests/widget/src/android/widget/cts/TextViewTest.java
@@ -2833,6 +2833,17 @@
     }
 
     @UiThreadTest
+    public void testSetTextLong() {
+        final int MAX_COUNT = 1 << 21;
+        char[] longText = new char[MAX_COUNT];
+        for (int n = 0; n < MAX_COUNT; n++) {
+            longText[n] = 'm';
+        }
+        mTextView = findTextView(R.id.textview_text);
+        mTextView.setText(new String(longText));
+    }
+
+    @UiThreadTest
     public void testSetExtractedText() {
         mTextView = findTextView(R.id.textview_text);
         assertEquals(mActivity.getResources().getString(R.string.text_view_hello),
diff --git a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
index 4df8e62..ed82b08 100644
--- a/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
+++ b/tools/device-setup/TestDeviceSetup/src/android/tests/getinfo/DeviceInfoActivity.java
@@ -106,6 +106,11 @@
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
+        // Dismiss keyguard and keep screen on while this test is on.
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
+                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
+                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
         super.onCreate(savedInstanceState);
         Window w = getWindow();
         w.setFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
diff --git a/tools/tradefed-host/res/report/cts_result.xsl b/tools/tradefed-host/res/report/cts_result.xsl
index 2d8bb50..fe49308 100644
--- a/tools/tradefed-host/res/report/cts_result.xsl
+++ b/tools/tradefed-host/res/report/cts_result.xsl
@@ -538,15 +538,7 @@
                                                             <xsl:value-of select="@result"/>
                                                         </div>
                                                     </TD>
-                                                    <TD class="failuredetails">
-                                                        <div class="details">
-                                                            <ul>
-                                                              <xsl:for-each select="Details/ValueArray/Value">
-                                                                <li><xsl:value-of select="."/></li>
-                                                              </xsl:for-each>
-                                                            </ul>
-                                                        </div>
-                                                    </TD>
+                                                    <TD class="failuredetails"/>
                                                 </xsl:if>
 
                                                 <xsl:if test="@result='fail'">
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java b/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
index 103ba6e..ccdb0eb 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/build/CtsBuildProvider.java
@@ -31,7 +31,7 @@
     @Option(name="cts-install-path", description="the path to the cts installation to use")
     private String mCtsRootDirPath = System.getProperty("CTS_ROOT");
 
-    public static final String CTS_BUILD_VERSION = "4.4_r1.95";
+    public static final String CTS_BUILD_VERSION = "4.4_r3";
 
     /**
      * {@inheritDoc}
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index 6643934..70310ca 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -58,7 +58,7 @@
     private static final String LOG_TAG = "CtsXmlResultReporter";
 
     static final String TEST_RESULT_FILE_NAME = "testResult.xml";
-    private static final String CTS_RESULT_FILE_VERSION = "4.4";
+    static final String CTS_RESULT_FILE_VERSION = "4.4";
     private static final String[] CTS_RESULT_RESOURCES = {"cts_result.xsl", "cts_result.css",
         "logo.gif", "newrule-green.png"};
 
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 c6977e5..48f4773 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
@@ -43,14 +43,13 @@
 import com.android.tradefed.util.RunUtil;
 import com.android.tradefed.util.xml.AbstractXmlParser.ParseException;
 
+import junit.framework.Test;
+
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
-import java.lang.InterruptedException;
-import java.lang.System;
-import java.lang.Thread;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -63,8 +62,6 @@
 import java.util.Queue;
 import java.util.Set;
 
-import junit.framework.Test;
-
 /**
  * A {@link Test} for running CTS tests.
  * <p/>
@@ -600,8 +597,13 @@
             for (String uri : plan.getTestUris()) {
                 if (!mExcludedPackageNames.contains(uri)) {
                     ITestPackageDef testPackage = testRepo.getTestPackage(uri);
-                    testPackage.setExcludedTestFilter(plan.getExcludedTestFilter(uri));
-                    testPkgDefs.add(testPackage);
+                    if (testPackage != null) {
+                        testPackage.setExcludedTestFilter(plan.getExcludedTestFilter(uri));
+                        testPkgDefs.add(testPackage);
+                    } else {
+                        CLog.e("Could not find test package uri %s referenced in plan %s", uri,
+                                mPlanName);
+                    }
                 }
             }
         } else if (mPackageNames.size() > 0){
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestFilter.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestFilter.java
index 053b265..f1a0485 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestFilter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestFilter.java
@@ -33,6 +33,10 @@
 
     private final Set<String> mExcludedClasses;
     private final Set<TestIdentifier> mExcludedTests;
+
+    private final Set<String> mIncludedClasses;
+    private final Set<TestIdentifier> mIncludedTests;
+
     private String mIncludedClass = null;
     private String mIncludedMethod = null;
 
@@ -42,6 +46,9 @@
     public TestFilter() {
         mExcludedClasses = new HashSet<String>();
         mExcludedTests = new HashSet<TestIdentifier>();
+
+        mIncludedClasses = new HashSet<String>();
+        mIncludedTests = new HashSet<TestIdentifier>();
     }
 
     /**
@@ -79,6 +86,36 @@
     }
 
     /**
+     * Adds a test class to the filter.
+     * <p/>
+     * All tests in this class should be allowed.
+     */
+    public void addIncludedClass(String className) {
+        mIncludedClasses.add(className);
+    }
+
+    /**
+     * Adds a test class to the filter. All tests in this class should be excluded.
+     */
+    public void addIncludedTest(TestIdentifier test) {
+        mIncludedTests.add(test);
+    }
+
+    /**
+     * @return the mIncludedClasses
+     */
+    public Set<String> getIncludedClasses() {
+        return mIncludedClasses;
+    }
+
+    /**
+     * @return the mIncludedTests
+     */
+    public Set<TestIdentifier> getIncludedTests() {
+        return mIncludedTests;
+    }
+
+    /**
      * Sets the class name and optionally method that should pass this filter. If non-null, all
      * other tests will be excluded.
      *
@@ -96,7 +133,7 @@
      * @param tests the list of tests to filter
      * @return a new sorted list of tests that passed the filter
      */
-    public Collection<TestIdentifier> filter(Collection<TestIdentifier > tests) {
+    public Collection<TestIdentifier> filter(Collection<TestIdentifier> tests) {
         List<TestIdentifier> filteredTests = new ArrayList<TestIdentifier>(tests.size());
         for (TestIdentifier test : tests) {
             if (mIncludedClass != null && !test.getClassName().equals(mIncludedClass)) {
@@ -115,6 +152,12 @@
                 // skip
                 continue;
             }
+            if ((!mIncludedTests.isEmpty() || !mIncludedClasses.isEmpty())
+                    && !(mIncludedClasses.contains(test.getClassName())
+                            || mIncludedTests.contains(test))) {
+                // skip
+                continue;
+            }
             filteredTests.add(test);
         }
         Collections.sort(filteredTests, new TestIdComparator());
@@ -129,6 +172,13 @@
     }
 
     /**
+     * @return true if there are inclusion rules defined.
+     */
+    public boolean hasInclusion() {
+        return !mIncludedClasses.isEmpty() || !mIncludedTests.isEmpty();
+    }
+
+    /**
      * A {@link Comparator} for {@link TestIdentifier} that compares using
      * {@link TestIdentifier#toString()}
      */
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
index 675c986..bd67f78 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPackageXmlParser.java
@@ -84,7 +84,9 @@
                 mPackageDef.setTestType(getTestType(attributes));
                 mPackageDef.setJarPath(jarPath);
                 mPackageDef.setIsSignatureCheck(parseBoolean(signatureCheck));
-                mPackageDef.setTestPackageName(javaPackageFilter);
+                if (!"".equals(javaPackageFilter)) {
+                    mPackageDef.setTestPackageName(javaPackageFilter);
+                }
                 mPackageDef.setTargetBinaryName(targetBinaryName);
                 mPackageDef.setTargetNameSpace(targetNameSpace);
 
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPlan.java b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPlan.java
index 3639a9c..c2a1348 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPlan.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/testtype/TestPlan.java
@@ -47,6 +47,7 @@
     private static final String TEST_DELIM = ";";
     private static final String METHOD_DELIM = "#";
     private static final String EXCLUDE_ATTR = "exclude";
+    private static final String INCLUDE_ATTR = "include";
     private static final String URI_ATTR = "uri";
 
     private final String mName;
@@ -61,21 +62,23 @@
                 throws SAXException {
             if (ENTRY_TAG.equals(localName)) {
                 final String entryUriValue = attributes.getValue(URI_ATTR);
-                TestFilter filter = parseExcludedTests(attributes.getValue(EXCLUDE_ATTR));
+                TestFilter filter = parseTestList(
+                        attributes.getValue(EXCLUDE_ATTR), attributes.getValue(INCLUDE_ATTR));
                 mUriExcludedTestsMap.put(entryUriValue, filter);
             }
         }
 
         /**
-         * Parse the semi colon separated list of tests to exclude.
+         * Parse a semicolon separated list of tests.
          * <p/>
          * Expected format:
          * testClassName[#testMethodName][;testClassName2...]
          *
          * @param excludedString the excluded string list
+         * @param includedString the included string list
          * @return
          */
-        private TestFilter parseExcludedTests(String excludedString) {
+        private TestFilter parseTestList(String excludedString, String includedString) {
             TestFilter filter = new TestFilter();
             if (excludedString != null) {
                 String[] testStrings = excludedString.split(TEST_DELIM);
@@ -89,6 +92,19 @@
                     }
                 }
             }
+            if (includedString != null) {
+                String[] testStrings = includedString.split(TEST_DELIM);
+                for (String testString : testStrings) {
+                    String[] classMethodPair = testString.split(METHOD_DELIM);
+                    if (classMethodPair.length == 2) {
+                        filter.addIncludedTest(new TestIdentifier(classMethodPair[0],
+                                classMethodPair[1]));
+                    } else {
+                        filter.addIncludedClass(testString);
+                    }
+                }
+            }
+
             return filter;
         }
     }
@@ -198,16 +214,27 @@
      */
     private void serializeFilter(KXmlSerializer serializer, TestFilter testFilter)
             throws IOException {
-        if (!testFilter.hasExclusion()) {
-            return;
+        if (testFilter.hasExclusion()) {
+            List<String> exclusionStrings = new ArrayList<String>();
+            exclusionStrings.addAll(testFilter.getExcludedClasses());
+            for (TestIdentifier test : testFilter.getExcludedTests()) {
+                // TODO: this relies on TestIdentifier.toString() using METHOD_DELIM.
+                exclusionStrings.add(test.toString());
+            }
+            String exclusionAttrValue = ArrayUtil.join(TEST_DELIM, exclusionStrings);
+            serializer.attribute(null, EXCLUDE_ATTR, exclusionAttrValue);
         }
-        List<String> exclusionStrings = new ArrayList<String>();
-        exclusionStrings.addAll(testFilter.getExcludedClasses());
-        for (TestIdentifier test : testFilter.getExcludedTests()) {
-            // TODO: this relies on TestIdentifier.toString() using METHOD_DELIM.
-            exclusionStrings.add(test.toString());
+
+        if (testFilter.hasInclusion()) {
+            List<String> inclusionStrings = new ArrayList<String>();
+            inclusionStrings.addAll(testFilter.getIncludedClasses());
+            for (TestIdentifier test : testFilter.getIncludedTests()) {
+                // TODO: this relies on TestIdentifier.toString() using METHOD_DELIM.
+                inclusionStrings.add(test.toString());
+            }
+            String exclusionAttrValue = ArrayUtil.join(TEST_DELIM, inclusionStrings);
+            serializer.attribute(null, INCLUDE_ATTR, exclusionAttrValue);
         }
-        String exclusionAttrValue = ArrayUtil.join(TEST_DELIM, exclusionStrings);
-        serializer.attribute(null, EXCLUDE_ATTR, exclusionAttrValue);
+
     }
 }
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
index 9515446..5776568 100644
--- a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
@@ -15,6 +15,8 @@
  */
 package com.android.cts.tradefed.result;
 
+import static com.android.cts.tradefed.result.CtsXmlResultReporter.CTS_RESULT_FILE_VERSION;
+
 import com.android.ddmlib.testrunner.ITestRunListener.TestFailure;
 import com.android.ddmlib.testrunner.TestIdentifier;
 import com.android.tradefed.build.IFolderBuildInfo;
@@ -84,8 +86,9 @@
     public void testEmptyGeneration() {
         final String expectedHeaderOutput = "<?xml version='1.0' encoding='UTF-8' standalone='no' ?>" +
             "<?xml-stylesheet type=\"text/xsl\" href=\"cts_result.xsl\"?>";
-        final String expectedTestOutput =
-            "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" version=\"1.13\"> ";
+        final String expectedTestOutput = String.format(
+            "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" " +
+                    "version=\"%s\" suite=\"%s\"> ", CTS_RESULT_FILE_VERSION, "CTS" );
         final String expectedSummaryOutput =
             "<Summary failed=\"0\" notExecuted=\"0\" timeout=\"0\" pass=\"0\" />";
         final String expectedEndTag = "</TestResult>";
@@ -93,10 +96,10 @@
         mResultReporter.invocationEnded(1);
         String actualOutput = getOutput();
         assertTrue(actualOutput.startsWith(expectedHeaderOutput));
-        assertTrue(String.format("test output did not contain expected test result. Got %s",
-                actualOutput), actualOutput.contains(expectedTestOutput));
-        assertTrue(String.format("test output did not contain expected test summary. Got %s",
-                actualOutput), actualOutput.contains(expectedSummaryOutput));
+        assertTrue(String.format("test output did not contain expected test result [%s]. Got %s",
+                expectedTestOutput, actualOutput), actualOutput.contains(expectedTestOutput));
+        assertTrue(String.format("test output did not contain expected test summary [%s]. Got %s",
+                expectedTestOutput, actualOutput), actualOutput.contains(expectedSummaryOutput));
         assertTrue(String.format("test output did not contain expected TestResult end tag. Got %s",
                 actualOutput), actualOutput.endsWith(expectedEndTag));
     }
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/testtype/TestFilterTest.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/testtype/TestFilterTest.java
index 676b912..2f76e1f 100644
--- a/tools/tradefed-host/tests/src/com/android/cts/tradefed/testtype/TestFilterTest.java
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/testtype/TestFilterTest.java
@@ -25,7 +25,7 @@
 import java.util.List;
 
 /**
- *
+ * Unit tests for {@link TestFilter}.
  */
 public class TestFilterTest extends TestCase {
 
@@ -87,7 +87,7 @@
     }
 
     /**
-     * Test {@link TestFilter#filter(java.util.Collection)} with at class
+     * Test {@link TestFilter#filter(java.util.Collection)} with a class
      */
     public void testFilter_includeTest() {
         mFilter.setTestInclusion(TEST1.getClassName(), TEST1.getTestName());
@@ -96,4 +96,82 @@
         Iterator<TestIdentifier> iter = filteredList.iterator();
         assertEquals(TEST1, iter.next());
     }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} with an included test filter
+     */
+    public void testFilter_includeClasses() {
+        mFilter.addIncludedClass(TEST3.getClassName());
+        Collection<TestIdentifier> filteredList = mFilter.filter(mTestList);
+        assertEquals(1, filteredList.size());
+        assertEquals(TEST3, filteredList.iterator().next());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} with an included test filter
+     */
+    public void testFilter_includeTests() {
+        mFilter.addIncludedTest(TEST1);
+        mFilter.addIncludedTest(TEST3);
+        Collection<TestIdentifier> filteredList = mFilter.filter(mTestList);
+        assertEquals(2, filteredList.size());
+        Iterator<TestIdentifier> iter = filteredList.iterator();
+        assertEquals(TEST1, iter.next());
+        assertEquals(TEST3, iter.next());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)}. Exclusion overrides
+     * inclusion.
+     */
+    public void testFilter_includeAndExcludeClasses() {
+        String className = TEST3.getClassName();
+        mFilter.addExcludedClass(className);
+        mFilter.addIncludedClass(className);
+        assertTrue(mFilter.filter(mTestList).isEmpty());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} Exclusion overrides
+     * inclusion.
+     */
+    public void testFilter_includeAndExcludeTests() {
+        mFilter.addExcludedTest(TEST1);
+        mFilter.addIncludedTest(TEST1);
+        assertTrue(mFilter.filter(mTestList).isEmpty());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} Exclusion overrides
+     * inclusion.
+     */
+    public void testFilter_includeTestAndExcludeClass() {
+        mFilter.addExcludedClass(TEST1.getClassName());
+        mFilter.addIncludedTest(TEST1);
+        assertTrue(mFilter.filter(mTestList).isEmpty());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} Exclusion overrides
+     * inclusion.
+     */
+    public void testFilter_includeClassAndExcludeTest() {
+        mFilter.addExcludedTest(TEST1);
+        mFilter.addIncludedClass(TEST1.getClassName());
+        Collection<TestIdentifier> filteredList = mFilter.filter(mTestList);
+        assertEquals(1, filteredList.size());
+        Iterator<TestIdentifier> iter = filteredList.iterator();
+        assertEquals(TEST2, iter.next());
+    }
+
+    /**
+     * Test {@link TestFilter#filter(java.util.Collection)} Exclusion overrides
+     * inclusion.
+     */
+    public void testFilter_includeClassAndExcludeTests() {
+        mFilter.addExcludedTest(TEST1);
+        mFilter.addExcludedTest(TEST2);
+        mFilter.addIncludedClass(TEST1.getClassName());
+        assertTrue(mFilter.filter(mTestList).isEmpty());
+    }
 }