Merge "Add cts coverage for new APIs in M" into mnc-dev
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index c66341d..4035af7 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -57,11 +57,17 @@
     CtsKeySetSigningBUpgradeB \
     CtsKeySetSigningAAndBUpgradeA \
     CtsKeySetSigningAAndCUpgradeB \
-    CtsKeySetSigningAUpgradeNone
+    CtsKeySetSigningAUpgradeNone \
+    CtsKeySetSharedUserSigningAUpgradeB \
+    CtsKeySetSharedUserSigningBUpgradeB \
+    CtsKeySetSigningABadUpgradeB \
+    CtsKeySetSigningCBadAUpgradeAB \
+    CtsKeySetSigningANoDefUpgradeB
 
 cts_support_packages := \
     CtsAccelerationTestStubs \
     CtsAppTestStubs \
+    CtsCertInstallerApp \
     CtsDeviceAdmin \
     CtsDeviceOpenGl \
     CtsDeviceOwnerApp \
@@ -178,6 +184,7 @@
 cts_host_libraries := \
     CtsAdbTests \
     CtsAppSecurityTests \
+    CtsAtraceHostTestCases \
     CtsDevicePolicyManagerTestCases \
     CtsDumpsysHostTestCases \
     CtsHostJank \
diff --git a/apps/CameraITS/pymodules/its/caps.py b/apps/CameraITS/pymodules/its/caps.py
index e57ff88..70bb2ca 100644
--- a/apps/CameraITS/pymodules/its/caps.py
+++ b/apps/CameraITS/pymodules/its/caps.py
@@ -257,6 +257,32 @@
     return props.has_key("android.control.awbLockAvailable") and \
            props["android.control.awbLockAvailable"] == 1
 
+def lsc_map(props):
+    """Returns whether a device supports lens shading map output
+
+    Args:
+        props: Camera properties object.
+
+    Return:
+        Boolean.
+    """
+    return props.has_key(
+            "android.statistics.info.availableLensShadingMapModes") and \
+        1 in props["android.statistics.info.availableLensShadingMapModes"]
+
+def lsc_off(props):
+    """Returns whether a device supports disabling lens shading correction
+
+    Args:
+        props: Camera properties object.
+
+    Return:
+        Boolean.
+    """
+    return props.has_key(
+            "android.shading.availableModes") and \
+        0 in props["android.shading.availableModes"]
+
 class __UnitTest(unittest.TestCase):
     """Run a suite of unit tests on this module.
     """
diff --git a/apps/CameraITS/tests/scene1/test_param_shading_mode.py b/apps/CameraITS/tests/scene1/test_param_shading_mode.py
index 65b7e97..8538675 100644
--- a/apps/CameraITS/tests/scene1/test_param_shading_mode.py
+++ b/apps/CameraITS/tests/scene1/test_param_shading_mode.py
@@ -35,11 +35,17 @@
     with its.device.ItsSession() as cam:
         props = cam.get_camera_properties()
 
-        its.caps.skip_unless(its.caps.per_frame_control(props))
+        its.caps.skip_unless(its.caps.per_frame_control(props) and
+                             its.caps.lsc_map(props) and
+                             its.caps.lsc_off(props))
 
         assert(props.has_key("android.lens.info.shadingMapSize") and
                props["android.lens.info.shadingMapSize"] != None)
 
+        # lsc_off devices should always support OFF(0), FAST(1), and HQ(2)
+        assert(props.has_key("android.shading.availableModes") and
+               set(props["android.shading.availableModes"]) == set([0, 1, 2]))
+
         num_map_gains = props["android.lens.info.shadingMapSize"]["width"] * \
                         props["android.lens.info.shadingMapSize"]["height"] * 4
 
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 4226bf2..a99408f 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -1337,6 +1337,14 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".managedprovisioning.WorkStatusTestActivity">
+            <intent-filter>
+                <action android:name="com.android.cts.verifier.managedprovisioning.WORK_STATUS_ICON" />
+                <action android:name="com.android.cts.verifier.managedprovisioning.WORK_STATUS_TOAST" />
+                <category android:name="android.intent.category.DEFAULT"></category>
+            </intent-filter>
+        </activity>
+
         <activity android:name=".managedprovisioning.WorkNotificationTestActivity">
             <intent-filter>
                 <action android:name="com.android.cts.verifier.managedprovisioning.WORK_NOTIFICATION" />
diff --git a/apps/CtsVerifier/res/drawable/stat_sys_managed_profile_status.xml b/apps/CtsVerifier/res/drawable/stat_sys_managed_profile_status.xml
new file mode 100644
index 0000000..b04059e
--- /dev/null
+++ b/apps/CtsVerifier/res/drawable/stat_sys_managed_profile_status.xml
@@ -0,0 +1,29 @@
+<!--
+Copyright (C) 2015 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="23.0dp"
+        android:height="18.0dp"
+        android:viewportWidth="21.0"
+        android:viewportHeight="17.0">
+    <group android:translateX="2.0">
+        <path
+            android:fillColor="#FFFFFFFF"
+            android:pathData="M9.9,11.6H7v-1.1H2.1v2.8c0,0.8,0.6,1.4,1.4,1.4h9.9c0.8,0,1.4,-0.6,1.4,-1.4v-2.8H9.9V11.6z"/>
+        <path
+            android:fillColor="#FFFFFFFF"
+            android:pathData="M14.1,4.2h-2.5V3.2l-1.1,-1.1H6.3L5.3,3.2v1H2.8C2,4.2,1.4,4.9,1.4,5.6v2.8c0,0.8,0.6,1.4,1.4,1.4H7V8.8h2.8v1.1h4.2     c0.8,0,1.4,-0.6,1.4,-1.4V5.6C15.5,4.9,14.8,4.2,14.1,4.2z M10.6,4.2H6.3V3.2h4.2V4.2z"/>
+    </group>
+</vector>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 9f8f4c1..675188a 100644
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -1361,6 +1361,32 @@
         Verify that the notification is badged (see sample badge below). Then mark this test accordingly.
     </string>
     <string name="provisioning_byod_work_notification_title">This is a work notification</string>
+    <string name="provisioning_byod_work_status_icon">Work status icon is displayed</string>
+    <string name="provisioning_byod_work_status_icon_instruction">
+        Verify that the current status bar does not have a work status icon (see sample icon below).
+        \n\n
+        Please press the Go button to launch a work activity.
+        \n\n
+        Verify that the status bar now has a work status icon. Then mark this test accordingly.
+    </string>
+    <string name="provisioning_byod_work_status_icon_activity">
+        Verify that the current status bar has a work status notification.
+        \n\n
+        Please press finish to return to the tests and then mark this test accordingly.
+    </string>
+    <string name="provisioning_byod_work_status_toast">Work status toast is displayed</string>
+    <string name="provisioning_byod_work_status_toast_instruction">
+        Please press the Go button to launch a work activity.
+        \n\n
+        Follow instructions and then return and mark this test accordingly.
+    </string>
+    <string name="provisioning_byod_work_status_toast_activity">
+        Turn off the screen and wait a few seconds then turn on the screen again.
+        \n\n
+        Verify that a toast was displayed saying you are in the work profile.
+        \n\n
+        Please press finish to return to the tests and then mark this test accordingly.
+    </string>
     <string name="provisioning_byod_profile_visible_instruction">
         Please press the Go button to open the Settings page.
         Navigate to Accounts and confirm that:\n
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
index e41c6d0..112a6e3 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
@@ -77,6 +77,8 @@
     private TestItem mDisableNonMarketTest;
     private TestItem mEnableNonMarketTest;
     private TestItem mWorkNotificationBadgedTest;
+    private TestItem mWorkStatusBarIconTest;
+    private TestItem mWorkStatusBarToastTest;
     private TestItem mAppSettingsVisibleTest;
     private TestItem mLocationSettingsVisibleTest;
     private TestItem mCredSettingsVisibleTest;
@@ -189,6 +191,21 @@
                 new Intent(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION),
                 R.drawable.ic_corp_icon);
 
+        Intent workStatusIcon = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
+        workStatusIcon.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        mWorkStatusBarIconTest = new TestItemWithIcon(this,
+                R.string.provisioning_byod_work_status_icon,
+                R.string.provisioning_byod_work_status_icon_instruction,
+                workStatusIcon,
+                R.drawable.stat_sys_managed_profile_status);
+
+        Intent workStatusToast = new Intent(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST);
+        workStatusToast.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        mWorkStatusBarToastTest = new TestItem(this,
+                R.string.provisioning_byod_work_status_toast,
+                R.string.provisioning_byod_work_status_toast_instruction,
+                workStatusToast);
+
         mDisableNonMarketTest = new TestItem(this, R.string.provisioning_byod_nonmarket_deny,
                 R.string.provisioning_byod_nonmarket_deny_info,
                 new Intent(ByodHelperActivity.ACTION_INSTALL_APK)
@@ -246,6 +263,8 @@
         // Badge related tests
         mTests.add(mWorkAppVisibleTest);
         mTests.add(mWorkNotificationBadgedTest);
+        mTests.add(mWorkStatusBarIconTest);
+        mTests.add(mWorkStatusBarToastTest);
 
         // Settings related tests.
         mTests.add(mProfileAccountVisibleTest);
@@ -465,6 +484,10 @@
                 this, WorkNotificationTestActivity.class),
                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                 PackageManager.DONT_KILL_APP);
+        getPackageManager().setComponentEnabledSetting(new ComponentName(
+                this, WorkStatusTestActivity.class),
+                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                PackageManager.DONT_KILL_APP);
     }
 
     private void showToast(int messageId) {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
index e95752e..9154307 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/DeviceAdminTestReceiver.java
@@ -56,6 +56,8 @@
             filter.addAction(CrossProfileTestActivity.ACTION_CROSS_PROFILE);
             filter.addAction(WorkNotificationTestActivity.ACTION_WORK_NOTIFICATION);
             filter.addAction(WorkNotificationTestActivity.ACTION_CLEAR_WORK_NOTIFICATION);
+            filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_TOAST);
+            filter.addAction(WorkStatusTestActivity.ACTION_WORK_STATUS_ICON);
             dpm.addCrossProfileIntentFilter(getWho(context), filter,
                     DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT);
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/WorkStatusTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/WorkStatusTestActivity.java
new file mode 100644
index 0000000..ee9aa44
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/WorkStatusTestActivity.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.verifier.managedprovisioning;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.TextView;
+
+import com.android.cts.verifier.R;
+
+/**
+ * Test activity for work status tests.
+ */
+public class WorkStatusTestActivity extends Activity {
+    public static final String ACTION_WORK_STATUS_ICON
+            = "com.android.cts.verifier.managedprovisioning.WORK_STATUS_ICON";
+    public static final String ACTION_WORK_STATUS_TOAST
+            = "com.android.cts.verifier.managedprovisioning.WORK_STATUS_TOAST";
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.provisioning_cross_profile);
+
+        findViewById(R.id.button_finish).setOnClickListener(new OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                WorkStatusTestActivity.this.finish();
+            }
+        });
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        String action = getIntent().getAction();
+        TextView textView = (TextView) findViewById(R.id.text);
+        if (ACTION_WORK_STATUS_ICON.equals(action)) {
+            textView.setText(R.string.provisioning_byod_work_status_icon_activity);
+        } else if (ACTION_WORK_STATUS_TOAST.equals(action)) {
+            textView.setText(R.string.provisioning_byod_work_status_toast_activity);
+        }
+    }
+}
diff --git a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/KeySetHostTest.java b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/KeySetHostTest.java
index dae5ee7..7f3737d 100644
--- a/hostsidetests/appsecurity/src/com/android/cts/appsecurity/KeySetHostTest.java
+++ b/hostsidetests/appsecurity/src/com/android/cts/appsecurity/KeySetHostTest.java
@@ -66,6 +66,16 @@
             "CtsKeySetSigningAAndBUpgradeB.apk";
     private static final String A_AND_C_SIGNED_B_UPGRADE =
             "CtsKeySetSigningAAndCUpgradeB.apk";
+    private static final String SHARED_USR_A_SIGNED_B_UPGRADE =
+            "CtsKeySetSharedUserSigningAUpgradeB.apk";
+    private static final String SHARED_USR_B_SIGNED_B_UPGRADE =
+            "CtsKeySetSharedUserSigningBUpgradeB.apk";
+    private static final String A_SIGNED_BAD_B_B_UPGRADE =
+            "CtsKeySetSigningABadUpgradeB.apk";
+    private static final String C_SIGNED_BAD_A_AB_UPGRADE =
+            "CtsKeySetSigningCBadAUpgradeAB.apk";
+    private static final String A_SIGNED_NO_B_B_UPGRADE =
+            "CtsKeySetSigningANoDefUpgradeB.apk";
 
     /* package which defines the KEYSET_PERM_NAME signature permission */
     private static final String KEYSET_PERM_DEF_PKG =
@@ -432,4 +442,48 @@
         testKeyRotationPerm(PERM_DEF_A_SIGNED, PERM_USE_A_SIGNED, PERM_DEF_B_SIGNED,
                 true, false);
     }
-}
\ No newline at end of file
+
+    /*
+     * Check if an apk which indicates it uses a sharedUserId and defines an
+     * upgrade keyset is allowed to rotate to that keyset.
+     */
+    public void testUpgradeSharedUser() throws Exception {
+        String installResult = testPackageUpgrade(KEYSET_PKG, SHARED_USR_A_SIGNED_B_UPGRADE,
+                SHARED_USR_B_SIGNED_B_UPGRADE);
+        assertNotNull("upgrade allowed for app with shareduserid!", installResult);
+    }
+
+    /*
+     * Check that an apk with an upgrade key represented by a bad public key
+     * fails to install.
+     */
+    public void testBadUpgradeBadPubKey() throws Exception {
+        mDevice.uninstallPackage(KEYSET_PKG);
+        String installResult = mDevice.installPackage(getTestAppFile(A_SIGNED_BAD_B_B_UPGRADE),
+                false);
+        assertNotNull("Installation of apk with upgrade key referring to a bad public key succeeded!",
+                installResult);
+    }
+
+    /*
+     * Check that an apk with an upgrade keyset that includes a bad public key fails to install.
+     */
+    public void testBadUpgradeMissingPubKey() throws Exception {
+        mDevice.uninstallPackage(KEYSET_PKG);
+        String installResult = mDevice.installPackage(getTestAppFile(C_SIGNED_BAD_A_AB_UPGRADE),
+                false);
+        assertNotNull("Installation of apk with upgrade key referring to a bad public key succeeded!",
+                installResult);
+    }
+
+    /*
+     * Check that an apk with an upgrade key that has no corresponding public key fails to install.
+     */
+    public void testBadUpgradeNoPubKey() throws Exception {
+        mDevice.uninstallPackage(KEYSET_PKG);
+        String installResult = mDevice.installPackage(getTestAppFile(A_SIGNED_NO_B_B_UPGRADE),
+                false);
+        assertNotNull("Installation of apk with upgrade key referring to a bad public key succeeded!",
+                installResult);
+    }
+}
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk
new file mode 100644
index 0000000..207160f
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/Android.mk
@@ -0,0 +1,27 @@
+# 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)
+
+#apks signed cts-keyset-test-a
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_PACKAGE_NAME := CtsKeySetSigningABadUpgradeB
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malBadKey/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/AndroidManifest.xml
new file mode 100644
index 0000000..e18bde5
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malBadKey/AndroidManifest.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.cts.keysets">
+    <application android:hasCode="false">
+    </application>
+    <key-sets>
+        <key-set android:name="B" >
+          <public-key android:name="keyB"
+                      android:value="makebadpubkeyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoeFZqMqTbZiozFTXMkXtSKJRzn2qODZgvVXAAwKTi50xYcbPcHTfKxtif8+q7OCp/50JYDH32bg6wkUunn5+dEaHkxZY8d7uw46tQtl5dNGi+6cc4MezVLCS6nkqNDusAgdvgLU6Fl6SGi02KTp1vkt6CwLO977YJP7kt9ouDRTG7ASJiq3OyRRoOqYHhD9gpsbUq4w+1bXGfuuZujA1dXyovXtvrHUGOdFIEBYOVYGfCcwh3lXPmjNJMlHtKQkurq8/LH7a1B5ocoXCGsyR8YHdlWfrqRAfzgOB1KCnNNmWqskU9LOci3uQn9IDeMEFmAd8FqF8SwV+4Ludk/xWGQIDAQAB" />
+        </key-set>
+        <upgrade-key-set android:name="B"/>
+    </key-sets>
+</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk
new file mode 100644
index 0000000..84f3f75
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/Android.mk
@@ -0,0 +1,27 @@
+# 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)
+
+#apks signed cts-keyset-test-a
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_PACKAGE_NAME := CtsKeySetSigningANoDefUpgradeB
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malNoDef/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/AndroidManifest.xml
new file mode 100644
index 0000000..aac717b
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malNoDef/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.cts.keysets">
+    <application android:hasCode="false">
+    </application>
+    <key-sets>
+        <upgrade-key-set android:name="B"/>
+    </key-sets>
+</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk
new file mode 100644
index 0000000..7290f06
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/Android.mk
@@ -0,0 +1,27 @@
+# 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)
+
+#apks signed cts-keyset-test-a
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_PACKAGE_NAME := CtsKeySetSigningCBadAUpgradeAB
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-c
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/malOneDef/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/AndroidManifest.xml
new file mode 100644
index 0000000..8242f6c
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/malOneDef/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.cts.keysets">
+    <application android:hasCode="false">
+    </application>
+    <key-sets>
+        <key-set android:name="AB" >
+          <public-key android:name="keyA"
+                      android:value="makebadpubkeyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwf5zJblvYSB7Ym7or/7GggAAu7mp7RrykPJsXhod8doFhVT5s7eF3A4MCE55vvANP7HvwMw2b+T6qx7Pq0VJtbbSDtlBHBtIc47Pjq0CsDg590BUcgKp7PdJ9J6UVgtzDnV6cGEpXmSag3sY+lqiW04ytPhCVwzYTWGdYe9+TIl47cBrveRfLOlGrcuFQe+zCTmDFqzBKCRHK9b7l5PDWvXXyg65Uu/MBUA/TZWO0fEqOlxZG/nn6DUKQLhPdmJRXWJ3WqMNMhJGD+nKtkmdX703xRqmg4h+6g0S7M9Y3IQ2NUGyw05AYzCguHB/Mv6uVIiW659wpbyb45TgKG3UhQIDAQAB" />
+          <public-key android:name="keyB"
+                      android:value="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoeFZqMqTbZiozFTXMkXtSKJRzn2qODZgvVXAAwKTi50xYcbPcHTfKxtif8+q7OCp/50JYDH32bg6wkUunn5+dEaHkxZY8d7uw46tQtl5dNGi+6cc4MezVLCS6nkqNDusAgdvgLU6Fl6SGi02KTp1vkt6CwLO977YJP7kt9ouDRTG7ASJiq3OyRRoOqYHhD9gpsbUq4w+1bXGfuuZujA1dXyovXtvrHUGOdFIEBYOVYGfCcwh3lXPmjNJMlHtKQkurq8/LH7a1B5ocoXCGsyR8YHdlWfrqRAfzgOB1KCnNNmWqskU9LOci3uQn9IDeMEFmAd8FqF8SwV+4Ludk/xWGQIDAQAB" />
+        </key-set>
+        <upgrade-key-set android:name="AB"/>
+    </key-sets>
+</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk
new file mode 100644
index 0000000..1d6d5a5
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/Android.mk
@@ -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.
+
+LOCAL_PATH:= $(call my-dir)
+
+#apks signed cts-keyset-test-a
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_PACKAGE_NAME := CtsKeySetSharedUserSigningAUpgradeB
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-a
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
+
+#apks signed cts-keyset-test-b
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+LOCAL_SDK_VERSION := current
+LOCAL_STATIC_JAVA_LIBRARIES := android-support-test
+LOCAL_PACKAGE_NAME := CtsKeySetSharedUserSigningBUpgradeB
+LOCAL_CERTIFICATE := cts/hostsidetests/appsecurity/certs/keysets/cts-keyset-test-b
+LOCAL_DEX_PREOPT := false
+
+include $(BUILD_CTS_SUPPORT_PACKAGE)
diff --git a/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/AndroidManifest.xml
new file mode 100644
index 0000000..55a1c24
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/keysets/uBsharedUser/AndroidManifest.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        package="com.android.cts.keysets"
+        android:sharedUserId="com.android.cts.keysets.shareduser">
+    <application android:hasCode="false">
+    </application>
+    <key-sets>
+        <key-set android:name="B" >
+          <public-key android:name="keyB"
+                      android:value="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoeFZqMqTbZiozFTXMkXtSKJRzn2qODZgvVXAAwKTi50xYcbPcHTfKxtif8+q7OCp/50JYDH32bg6wkUunn5+dEaHkxZY8d7uw46tQtl5dNGi+6cc4MezVLCS6nkqNDusAgdvgLU6Fl6SGi02KTp1vkt6CwLO977YJP7kt9ouDRTG7ASJiq3OyRRoOqYHhD9gpsbUq4w+1bXGfuuZujA1dXyovXtvrHUGOdFIEBYOVYGfCcwh3lXPmjNJMlHtKQkurq8/LH7a1B5ocoXCGsyR8YHdlWfrqRAfzgOB1KCnNNmWqskU9LOci3uQn9IDeMEFmAd8FqF8SwV+4Ludk/xWGQIDAQAB" />
+        </key-set>
+        <upgrade-key-set android:name="B"/>
+    </key-sets>
+</manifest>
diff --git a/hostsidetests/atrace/Android.mk b/hostsidetests/atrace/Android.mk
new file mode 100644
index 0000000..4bde535
--- /dev/null
+++ b/hostsidetests/atrace/Android.mk
@@ -0,0 +1,32 @@
+# 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
+
+# Must match the package name in CtsTestCaseList.mk
+LOCAL_MODULE := CtsAtraceHostTestCases
+
+LOCAL_JAVA_LIBRARIES := cts-tradefed tradefed-prebuilt
+
+LOCAL_CTS_TEST_PACKAGE := android.host.atrace
+
+include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/hostsidetests/atrace/src/android/atrace/cts/AtraceHostTest.java b/hostsidetests/atrace/src/android/atrace/cts/AtraceHostTest.java
new file mode 100644
index 0000000..ae4a850
--- /dev/null
+++ b/hostsidetests/atrace/src/android/atrace/cts/AtraceHostTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2015 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.atrace.cts;
+
+import com.android.ddmlib.Log;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.testtype.DeviceTestCase;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Test to check that atrace is usable, to enable usage of systrace.
+ */
+public class AtraceHostTest extends DeviceTestCase {
+    private static final String TAG = "AtraceHostTest";
+
+    private ITestDevice mDevice;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDevice = getDevice();
+    }
+
+    // Collection of all userspace tags
+    private static final List<String> sRequiredCategoriesList = Arrays.asList(
+            "gfx",
+            "input",
+            "view",
+            "webview",
+            "wm",
+            "am",
+            "sm",
+            "audio",
+            "video",
+            "camera",
+            "hal",
+            "app",
+            "res",
+            "dalvik",
+            "rs",
+            "bionic",
+            "power"
+    );
+
+    /**
+     * Tests that atrace exists and is runnable with no args
+     */
+    public void testSimpleRun() throws Exception {
+        String output = mDevice.executeShellCommand("atrace");
+        String[] lines = output.split("\\r?\\n");
+
+        // check for expected stdout
+        assertEquals("capturing trace... done", lines[0]);
+        assertEquals("TRACE:", lines[1]);
+
+        // commented trace marker starts here
+        assertEquals("# tracer: nop", lines[2]);
+    }
+
+    /**
+     * Tests the output of "atrace --list_categories" to ensure required categories exist.
+     */
+    public void testCategories() throws Exception {
+        String output = mDevice.executeShellCommand("atrace --list_categories");
+        String[] categories = output.split("\\r?\\n");
+
+        Set<String> requiredCategories = new HashSet<String>(sRequiredCategoriesList);
+
+        for (String category : categories) {
+            int dashIndex = category.indexOf("-");
+
+            assertTrue(dashIndex > 1); // must match category output format
+            category = category.substring(0, dashIndex).trim();
+
+            requiredCategories.remove(category);
+        }
+
+        if (!requiredCategories.isEmpty()) {
+            for (String missingCategory : requiredCategories) {
+                Log.d(TAG, "missing category: " + missingCategory);
+            }
+            fail("Expected categories missing from atrace");
+        }
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/CertInstaller/Android.mk b/hostsidetests/devicepolicy/app/CertInstaller/Android.mk
new file mode 100644
index 0000000..22a78e2
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/CertInstaller/Android.mk
@@ -0,0 +1,31 @@
+# Copyright (C) 2015 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_PACKAGE_NAME := CtsCertInstallerApp
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_JAVA_LIBRARIES := android.test.runner
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_CTS_PACKAGE)
diff --git a/hostsidetests/devicepolicy/app/CertInstaller/AndroidManifest.xml b/hostsidetests/devicepolicy/app/CertInstaller/AndroidManifest.xml
new file mode 100644
index 0000000..c50e5fd
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/CertInstaller/AndroidManifest.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.cts.certinstaller">
+
+    <uses-sdk android:minSdkVersion="22"/>
+
+    <application>
+        <activity android:name="CertInstallerActivity">
+            <intent-filter>
+                <action android:name="com.android.cts.certinstaller.install_cert" />
+                <action android:name="com.android.cts.certinstaller.remove_cert" />
+                <action android:name="com.android.cts.certinstaller.verify_cert" />
+                <action android:name="com.android.cts.certinstaller.install_keypair" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
diff --git a/hostsidetests/devicepolicy/app/CertInstaller/src/com/android/cts/certinstaller/CertInstallerActivity.java b/hostsidetests/devicepolicy/app/CertInstaller/src/com/android/cts/certinstaller/CertInstallerActivity.java
new file mode 100644
index 0000000..b14822b
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/CertInstaller/src/com/android/cts/certinstaller/CertInstallerActivity.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2015 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.certinstaller;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Base64;
+import android.util.Base64InputStream;
+import android.util.Log;
+
+import java.io.ByteArrayInputStream;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.KeyFactory;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.util.List;
+
+/**
+ * Delegated certificate installer app that responds to specific intents and executes various DPM
+ * certificate manipulation APIs. The following APIs are exercised:
+ * {@link DevicePolicyManager#installCaCert},
+ * {@link DevicePolicyManager#uninstallCaCert},
+ * {@link DevicePolicyManager#hasCaCertInstalled},
+ * {@link DevicePolicyManager#getInstalledCaCerts},
+ * {@link DevicePolicyManager#installKeyPair}.
+ */
+public class CertInstallerActivity extends Activity {
+
+    private static final String TAG = "DelegatedCertInstaller";
+    // exercises {@link DevicePolicyManager#installCaCert} and
+    // {@link DevicePolicyManager#hasCaCertInstalled},
+    private static final String ACTION_INSTALL_CERT = "com.android.cts.certinstaller.install_cert";
+    // exercises {@link DevicePolicyManager#uninstallCaCert} and
+    // {@link DevicePolicyManager#hasCaCertInstalled},
+    private static final String ACTION_REMOVE_CERT = "com.android.cts.certinstaller.remove_cert";
+    // exercises {@link DevicePolicyManager#getInstalledCaCerts},
+    private static final String ACTION_VERIFY_CERT = "com.android.cts.certinstaller.verify_cert";
+    // exercises {@link DevicePolicyManager#installKeyPair},
+    private static final String ACTION_INSTALL_KEYPAIR =
+            "com.android.cts.certinstaller.install_keypair";
+
+    private static final String ACTION_CERT_OPERATION_DONE = "com.android.cts.certinstaller.done";
+
+    private static final String EXTRA_CERT_DATA = "extra_cert_data";
+    private static final String EXTRA_KEY_DATA = "extra_key_data";
+    private static final String EXTRA_KEY_ALIAS = "extra_key_alias";
+    private static final String EXTRA_RESULT_VALUE = "extra_result_value";
+    private static final String EXTRA_RESULT_EXCEPTION = "extra_result_exception";
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        Intent intent = getIntent();
+        if (intent == null) {
+            finish();
+            return;
+        }
+
+        String action = intent.getAction();
+        DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(
+                Context.DEVICE_POLICY_SERVICE);
+
+        byte[] certBuffer;
+
+        if (ACTION_INSTALL_CERT.equals(action)) {
+            try {
+                certBuffer = intent.getByteArrayExtra(EXTRA_CERT_DATA);
+                // Verify cert is not currently installed.
+                if (dpm.hasCaCertInstalled(null, certBuffer)) {
+                    throw new RuntimeException("Cert already on device?");
+                }
+                if (!dpm.installCaCert(null, certBuffer)) {
+                    throw new RuntimeException("installCaCert returned false.");
+                }
+                if (!dpm.hasCaCertInstalled(null, certBuffer)) {
+                    throw new RuntimeException("Cannot find cert after installation.");
+                }
+                sendResult(true, null);
+            } catch (Exception e) {
+                Log.e(TAG, "Exception raised duing ACTION_INSTALL_CERT", e);
+                sendResult(false, e);
+            }
+        } else if (ACTION_REMOVE_CERT.equals(action)) {
+            try {
+                certBuffer = intent.getByteArrayExtra(EXTRA_CERT_DATA);
+                if (!dpm.hasCaCertInstalled(null, certBuffer)) {
+                    throw new RuntimeException("Trying to uninstall a non-existent cert.");
+                }
+                dpm.uninstallCaCert(null, certBuffer);
+                sendResult(!dpm.hasCaCertInstalled(null, certBuffer), null);
+            } catch (Exception e) {
+                Log.e(TAG, "Exception raised duing ACTION_REMOVE_CERT", e);
+                sendResult(false, e);
+            }
+        } else if (ACTION_VERIFY_CERT.equals(action)) {
+            try {
+                certBuffer = intent.getByteArrayExtra(EXTRA_CERT_DATA);
+                sendResult(containsCertificate(dpm.getInstalledCaCerts(null), certBuffer), null);
+            } catch (Exception e) {
+                Log.e(TAG, "Exception raised duing ACTION_VERIFY_CERT", e);
+                sendResult(false, e);
+            }
+        } else if (ACTION_INSTALL_KEYPAIR.equals(action)) {
+            String alias = intent.getStringExtra(EXTRA_KEY_ALIAS);
+            String key = intent.getStringExtra(EXTRA_KEY_DATA);
+            String cert = intent.getStringExtra(EXTRA_CERT_DATA);
+            try {
+                PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(
+                        Base64.decode(key, Base64.DEFAULT));
+                KeyFactory kf = KeyFactory.getInstance("RSA");
+                PrivateKey privatekey = kf.generatePrivate(keySpec);
+
+                Certificate certificate = CertificateFactory.getInstance("X.509")
+                        .generateCertificate(
+                                new Base64InputStream(new ByteArrayInputStream(cert.getBytes()),
+                                        Base64.DEFAULT));
+                // Unfortunately there is no programmatically way to check if the given private key
+                // is indeed in the key store as a unprivileged app. So we just rely on
+                // installKeyPair() returning true as the success criteria of this test. Separate
+                // CTS keychain tests will make sure the API's behaviour is correct.
+                // Note: installKeyPair() will silently return false if there is no lockscreen
+                // password, however the test setup should have set one already.
+                sendResult(dpm.installKeyPair(null, privatekey, certificate,  alias), null);
+            } catch (Exception e) {
+                Log.e(TAG, "Exception raised duing ACTION_INSTALL_KEYPAIR", e);
+                sendResult(false, e);
+            }
+        }
+        finish();
+    }
+
+    private void sendResult(boolean succeed, Exception e) {
+        Intent intent = new Intent();
+        intent.setAction(ACTION_CERT_OPERATION_DONE);
+        intent.putExtra(EXTRA_RESULT_VALUE, succeed);
+        if (e != null) {
+            intent.putExtra(EXTRA_RESULT_EXCEPTION, e);
+        }
+        sendBroadcast(intent);
+    }
+
+    private boolean containsCertificate(List<byte[]> certificates, byte[] toMatch)
+            throws CertificateException {
+        Certificate certificateToMatch = readCertificate(toMatch);
+        for (byte[] certBuffer : certificates) {
+            Certificate cert = readCertificate(certBuffer);
+            if (certificateToMatch.equals(cert)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private Certificate readCertificate(byte[] certBuffer) throws CertificateException {
+        final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+        return certFactory.generateCertificate(new ByteArrayInputStream(certBuffer));
+    }
+
+}
diff --git a/hostsidetests/devicepolicy/app/IntentSender/Android.mk b/hostsidetests/devicepolicy/app/IntentSender/Android.mk
index e5246c5..21d2866 100644
--- a/hostsidetests/devicepolicy/app/IntentSender/Android.mk
+++ b/hostsidetests/devicepolicy/app/IntentSender/Android.mk
@@ -24,9 +24,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner
-
-LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 ctstestrunner
+LOCAL_JAVA_LIBRARIES := android.test.runner android-support-v4
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
index f4adb31..b74a7b6 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/Android.mk
@@ -24,9 +24,9 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 
-LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit
+LOCAL_JAVA_LIBRARIES := android.test.runner cts-junit android-support-v4
 
-LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 ctstestrunner
+LOCAL_STATIC_JAVA_LIBRARIES := ctstestrunner
 
 LOCAL_SDK_VERSION := current
 
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
index aeb6a45..82f6d6d 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
@@ -34,6 +34,15 @@
                 <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
             </intent-filter>
         </receiver>
+        <receiver
+            android:name="com.android.cts.managedprofile.PrimaryUserDeviceAdmin"
+            android:permission="android.permission.BIND_DEVICE_ADMIN">
+            <meta-data android:name="android.app.device_admin"
+                       android:resource="@xml/primary_device_admin" />
+            <intent-filter>
+                <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
+            </intent-filter>
+        </receiver>
         <activity android:name=".PrimaryUserFilterSetterActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/res/xml/primary_device_admin.xml b/hostsidetests/devicepolicy/app/ManagedProfile/res/xml/primary_device_admin.xml
new file mode 100644
index 0000000..a6aff49
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/res/xml/primary_device_admin.xml
@@ -0,0 +1,20 @@
+<!-- Copyright (C) 2015 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.
+-->
+<device-admin xmlns:android="http://schemas.android.com/apk/res/android" android:visible="false">
+    <uses-policies>
+         <reset-password />
+         <limit-password />
+    </uses-policies>
+</device-admin>
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DelegatedCertInstallerTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DelegatedCertInstallerTest.java
new file mode 100644
index 0000000..de859b4
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/DelegatedCertInstallerTest.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2015 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.managedprofile;
+
+import android.app.KeyguardManager;
+import android.app.admin.DevicePolicyManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.security.KeyChain;
+import android.security.KeyChainException;
+import android.test.AndroidTestCase;
+import android.util.Base64;
+import android.util.Base64InputStream;
+
+import java.io.ByteArrayInputStream;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+import static com.android.cts.managedprofile.BaseManagedProfileTest.ADMIN_RECEIVER_COMPONENT;
+
+/**
+ * Exercise delegated cert installer APIs in {@link DevicePolicyManager} by setting the test app
+ * (CtsCertInstallerApp) as a delegated cert installer and then asking it to invoke various
+ * cert-related APIs. The expected certificate changes are validated both remotely and locally.
+ */
+public class DelegatedCertInstallerTest extends AndroidTestCase {
+
+    private static final String CERT_INSTALLER_PACKAGE = "com.android.cts.certinstaller";
+
+    private static final String ACTION_INSTALL_CERT = "com.android.cts.certinstaller.install_cert";
+    private static final String ACTION_REMOVE_CERT = "com.android.cts.certinstaller.remove_cert";
+    private static final String ACTION_VERIFY_CERT = "com.android.cts.certinstaller.verify_cert";
+    private static final String ACTION_INSTALL_KEYPAIR =
+            "com.android.cts.certinstaller.install_keypair";
+    private static final String ACTION_CERT_OPERATION_DONE = "com.android.cts.certinstaller.done";
+
+    private static final String EXTRA_CERT_DATA = "extra_cert_data";
+    private static final String EXTRA_KEY_DATA = "extra_key_data";
+    private static final String EXTRA_KEY_ALIAS = "extra_key_alias";
+    private static final String EXTRA_RESULT_VALUE = "extra_result_value";
+    private static final String EXTRA_RESULT_EXCEPTION = "extra_result_exception";
+
+    /*
+     * The CA and keypair below are generated with:
+     *
+     * openssl req -new -x509 -days 3650 -extensions v3_ca -keyout cakey.pem -out cacert.pem
+     * openssl req -newkey rsa:1024 -keyout userkey.pem -nodes -days 3650 -out userkey.req
+     * mkdir -p demoCA/newcerts
+     * touch demoCA/index.txt
+     * echo "01" > demoCA/serial
+     * openssl ca -out usercert.pem -in userkey.req -cert cacert.pem -keyfile cakey.pem -days 3650
+     */
+
+     // Content from cacert.pem
+    private static final String TEST_CA =
+            "-----BEGIN CERTIFICATE-----\n" +
+            "MIIDXTCCAkWgAwIBAgIJAK9Tl/F9V8kSMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n" +
+            "BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n" +
+            "aWRnaXRzIFB0eSBMdGQwHhcNMTUwMzA2MTczMjExWhcNMjUwMzAzMTczMjExWjBF\n" +
+            "MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n" +
+            "ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" +
+            "CgKCAQEAvItOutsE75WBTgTyNAHt4JXQ3JoseaGqcC3WQij6vhrleWi5KJ0jh1/M\n" +
+            "Rpry7Fajtwwb4t8VZa0NuM2h2YALv52w1xivql88zce/HU1y7XzbXhxis9o6SCI+\n" +
+            "oVQSbPeXRgBPppFzBEh3ZqYTVhAqw451XhwdA4Aqs3wts7ddjwlUzyMdU44osCUg\n" +
+            "kVg7lfPf9sTm5IoHVcfLSCWH5n6Nr9sH3o2ksyTwxuOAvsN11F/a0mmUoPciYPp+\n" +
+            "q7DzQzdi7akRG601DZ4YVOwo6UITGvDyuAAdxl5isovUXqe6Jmz2/myTSpAKxGFs\n" +
+            "jk9oRoG6WXWB1kni490GIPjJ1OceyQIDAQABo1AwTjAdBgNVHQ4EFgQUH1QIlPKL\n" +
+            "p2OQ/AoLOjKvBW4zK3AwHwYDVR0jBBgwFoAUH1QIlPKLp2OQ/AoLOjKvBW4zK3Aw\n" +
+            "DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAcMi4voMMJHeQLjtq8Oky\n" +
+            "Azpyk8moDwgCd4llcGj7izOkIIFqq/lyqKdtykVKUWz2bSHO5cLrtaOCiBWVlaCV\n" +
+            "DYAnnVLM8aqaA6hJDIfaGs4zmwz0dY8hVMFCuCBiLWuPfiYtbEmjHGSmpQTG6Qxn\n" +
+            "ZJlaK5CZyt5pgh5EdNdvQmDEbKGmu0wpCq9qjZImwdyAul1t/B0DrsWApZMgZpeI\n" +
+            "d2od0VBrCICB1K4p+C51D93xyQiva7xQcCne+TAnGNy9+gjQ/MyR8MRpwRLv5ikD\n" +
+            "u0anJCN8pXo6IMglfMAsoton1J6o5/ae5uhC6caQU8bNUsCK570gpNfjkzo6rbP0\n" +
+            "wQ==\n" +
+            "-----END CERTIFICATE-----";
+    // Content from userkey.pem without the private key header and footer.
+    private static final String TEST_KEY =
+            "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALCYprGsTU+5L3KM\n" +
+            "fhkm0gXM2xjGUH+543YLiMPGVr3eVS7biue1/tQlL+fJsw3rqsPKJe71RbVWlpqU\n" +
+            "mhegxG4s3IvGYVB0KZoRIjDKmnnvlx6nngL2ZJ8O27U42pHsw4z4MKlcQlWkjL3T\n" +
+            "9sV6zW2Wzri+f5mvzKjhnArbLktHAgMBAAECgYBlfVVPhtZnmuXJzzQpAEZzTugb\n" +
+            "tN1OimZO0RIocTQoqj4KT+HkiJOLGFQPwbtFpMre+q4SRqNpM/oZnI1yRtKcCmIc\n" +
+            "mZgkwJ2k6pdSxqO0ofxFFTdT9czJ3rCnqBHy1g6BqUQFXT4olcygkxUpKYUwzlz1\n" +
+            "oAl487CoPxyr4sVEAQJBANwiUOHcdGd2RoRILDzw5WOXWBoWPOKzX/K9wt0yL+mO\n" +
+            "wlFNFSymqo9eLheHcEq/VD9qK9rT700dCewJfWj6+bECQQDNXmWNYIxGii5NJilT\n" +
+            "OBOHiMD/F0NE178j+/kmacbhDJwpkbLYXaP8rW4+Iswrm4ORJ59lvjNuXaZ28+sx\n" +
+            "fFp3AkA6Z7Bl/IO135+eATgbgx6ZadIqObQ1wbm3Qbmtzl7/7KyJvZXcnuup1icM\n" +
+            "fxa//jtwB89S4+Ad6ZJ0WaA4dj5BAkEAuG7V9KmIULE388EZy8rIfyepa22Q0/qN\n" +
+            "hdt8XasRGHsio5Jdc0JlSz7ViqflhCQde/aBh/XQaoVgQeO8jKyI8QJBAJHekZDj\n" +
+            "WA0w1RsBVVReN1dVXgjm1CykeAT8Qx8TUmBUfiDX6w6+eGQjKtS7f4KC2IdRTV6+\n" +
+            "bDzDoHBChHNC9ms=\n";
+
+    // Content from usercert.pem without the header and footer.
+    private static final String TEST_CERT =
+            "MIIDEjCCAfqgAwIBAgIBATANBgkqhkiG9w0BAQsFADBFMQswCQYDVQQGEwJBVTET\n" +
+            "MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ\n" +
+            "dHkgTHRkMB4XDTE1MDUwMTE2NTQwNVoXDTI1MDQyODE2NTQwNVowWzELMAkGA1UE\n" +
+            "BhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdp\n" +
+            "ZGdpdHMgUHR5IEx0ZDEUMBIGA1UEAwwLY2xpZW50IGNlcnQwgZ8wDQYJKoZIhvcN\n" +
+            "AQEBBQADgY0AMIGJAoGBALCYprGsTU+5L3KMfhkm0gXM2xjGUH+543YLiMPGVr3e\n" +
+            "VS7biue1/tQlL+fJsw3rqsPKJe71RbVWlpqUmhegxG4s3IvGYVB0KZoRIjDKmnnv\n" +
+            "lx6nngL2ZJ8O27U42pHsw4z4MKlcQlWkjL3T9sV6zW2Wzri+f5mvzKjhnArbLktH\n" +
+            "AgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2Vu\n" +
+            "ZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBQ8GL+jKSarvTn9fVNA2AzjY7qq\n" +
+            "gjAfBgNVHSMEGDAWgBRzBBA5sNWyT/fK8GrhN3tOqO5tgjANBgkqhkiG9w0BAQsF\n" +
+            "AAOCAQEAgwQEd2bktIDZZi/UOwU1jJUgGq7NiuBDPHcqgzjxhGFLQ8SQAAP3v3PR\n" +
+            "mLzcfxsxnzGynqN5iHQT4rYXxxaqrp1iIdj9xl9Wl5FxjZgXITxhlRscOd/UOBvG\n" +
+            "oMrazVczjjdoRIFFnjtU3Jf0Mich68HD1Z0S3o7X6sDYh6FTVR5KbLcxbk6RcoG4\n" +
+            "VCI5boR5LUXgb5Ed5UxczxvN12S71fyxHYVpuuI0z0HTIbAxKeRw43I6HWOmR1/0\n" +
+            "G6byGCNL/1Fz7Y+264fGqABSNTKdZwIU2K4ANEH7F+9scnhoO6OBp+gjBe5O+7jb\n" +
+            "wZmUCAoTka4hmoaOCj7cqt/IkmxozQ==\n";
+
+    private DevicePolicyManager mDpm;
+    private volatile boolean mReceivedResult;
+    private volatile Exception mReceivedException;
+    private Semaphore mAvailableResultSemaphore;
+
+    private final BroadcastReceiver receiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (ACTION_CERT_OPERATION_DONE.equals(intent.getAction())) {
+                synchronized (DelegatedCertInstallerTest.this) {
+                    mReceivedResult = intent.getBooleanExtra(EXTRA_RESULT_VALUE, false);
+                    mReceivedException =
+                            (Exception) intent.getSerializableExtra(EXTRA_RESULT_EXCEPTION);
+                    mAvailableResultSemaphore.release();
+                }
+            }
+        }
+    };
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        mDpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
+        mAvailableResultSemaphore = new Semaphore(0);
+        mReceivedResult = false;
+        mReceivedException = null;
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(ACTION_CERT_OPERATION_DONE);
+        getContext().registerReceiver(receiver, filter);
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        getContext().unregisterReceiver(receiver);
+        mDpm.uninstallCaCert(ADMIN_RECEIVER_COMPONENT, TEST_CA.getBytes());
+        // Installed private key pair will be removed once the lockscreen password is cleared,
+        // which is done in the hostside test.
+        mDpm.setCertInstallerPackage(ADMIN_RECEIVER_COMPONENT, null);
+        super.tearDown();
+    }
+
+    public void testCaCertsOperations() throws InterruptedException {
+        byte[] cert = TEST_CA.getBytes();
+
+        mDpm.setCertInstallerPackage(ADMIN_RECEIVER_COMPONENT, CERT_INSTALLER_PACKAGE);
+        assertEquals(CERT_INSTALLER_PACKAGE,
+                mDpm.getCertInstallerPackage(ADMIN_RECEIVER_COMPONENT));
+
+        // Exercise installCaCert()
+        installCaCert(cert);
+        assertResult("installCaCert", true);
+        assertTrue("Certificate is not installed properly", mDpm.hasCaCertInstalled(
+                ADMIN_RECEIVER_COMPONENT, cert));
+
+        // Exercise getInstalledCaCerts()
+        verifyCaCert(cert);
+        assertResult("getInstalledCaCerts()", true);
+
+        // Exercise uninstallCaCert()
+        removeCaCert(cert);
+        assertResult("uninstallCaCert()", true);
+        assertFalse("Certificate is not removed properly", mDpm.hasCaCertInstalled(
+                ADMIN_RECEIVER_COMPONENT, cert));
+
+        // Clear delegated cert installer.
+        // Tests after this are expected to fail.
+        mDpm.setCertInstallerPackage(ADMIN_RECEIVER_COMPONENT, null);
+
+        installCaCert(cert);
+        assertResult("installCaCert", false);
+    }
+
+    public void testInstallKeyPair() throws InterruptedException, KeyChainException {
+        final String alias = "delegated-cert-installer-test-key";
+
+        // Clear delegated cert installer.
+        mDpm.setCertInstallerPackage(ADMIN_RECEIVER_COMPONENT, null);
+        // The app is not the cert installer , it shouldn't have have privilege to call
+        // installKeyPair().
+        installKeyPair(TEST_KEY, TEST_CERT, alias);
+        assertResult("installKeyPair", false);
+
+        // Set the app to be cert installer.
+        mDpm.setCertInstallerPackage(ADMIN_RECEIVER_COMPONENT, CERT_INSTALLER_PACKAGE);
+        assertEquals(CERT_INSTALLER_PACKAGE,
+                mDpm.getCertInstallerPackage(ADMIN_RECEIVER_COMPONENT));
+
+        // Exercise installKeyPair()
+        checkKeyguardPrecondition();
+        installKeyPair(TEST_KEY, TEST_CERT, alias);
+        assertResult("installKeyPair", true);
+    }
+
+    /**
+     * installKeyPair() requires the system to have a lockscreen password, which should have been
+     * set by the host side test.
+     */
+    private void checkKeyguardPrecondition() throws InterruptedException {
+        KeyguardManager km = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
+        if (!km.isKeyguardSecure()) {
+            Thread.sleep(5000);
+          }
+          assertTrue("A lockscreen password is required before keypair can be installed",
+                          km.isKeyguardSecure());
+    }
+
+    private void installCaCert(byte[] cert) {
+        Intent intent = new Intent();
+        intent.setAction(ACTION_INSTALL_CERT);
+        intent.putExtra(EXTRA_CERT_DATA, cert);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        getContext().startActivity(intent);
+    }
+
+    private void removeCaCert(byte[] cert) {
+        Intent intent = new Intent();
+        intent.setAction(ACTION_REMOVE_CERT);
+        intent.putExtra(EXTRA_CERT_DATA, cert);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        getContext().startActivity(intent);
+    }
+
+    private void verifyCaCert(byte[] cert) {
+        Intent intent = new Intent();
+        intent.setAction(ACTION_VERIFY_CERT);
+        intent.putExtra(EXTRA_CERT_DATA, cert);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        getContext().startActivity(intent);
+    }
+
+    private void assertResult(String testName, Boolean expectSuccess) throws InterruptedException {
+        assertTrue("Cert installer did not respond in time.",
+                mAvailableResultSemaphore.tryAcquire(5, TimeUnit.SECONDS));
+        synchronized (this) {
+            if (expectSuccess) {
+                assertTrue(testName + " failed unexpectedly.", mReceivedResult);
+                assertNull(testName + " raised exception", mReceivedException);
+            } else {
+                assertFalse(testName + " succeeded unexpectedly.", mReceivedResult);
+                assertTrue(testName + " did not raise SecurityException",
+                        mReceivedException != null &&
+                        mReceivedException instanceof SecurityException);
+            }
+        }
+    }
+
+    private void installKeyPair(String key, String cert, String alias) {
+        Intent intent = new Intent();
+        intent.setAction(ACTION_INSTALL_KEYPAIR);
+        intent.putExtra(EXTRA_CERT_DATA, cert);
+        intent.putExtra(EXTRA_KEY_DATA, key);
+        intent.putExtra(EXTRA_KEY_ALIAS, alias);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        getContext().startActivity(intent);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserAdminHelper.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserAdminHelper.java
new file mode 100644
index 0000000..5b8af1f
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserAdminHelper.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 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.managedprofile;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.ComponentName;
+import android.content.Context;
+import android.test.AndroidTestCase;
+
+/**
+ * This test executes helper tasks as active device admin in the primary user. Current tasks are
+ * setting and clearing lockscreen password used by the host side delegated cert installer test.
+ */
+public class PrimaryUserAdminHelper extends AndroidTestCase {
+
+    private DevicePolicyManager mDpm;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDpm = (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
+    }
+
+    /**
+     * Device admin can only be deactivated by itself and this test should be executed before the
+     * device admin package can be uninstalled.
+     */
+    public void testClearDeviceAdmin() {
+        try {
+            removeActiveAdmin(mDpm, PrimaryUserDeviceAdmin.ADMIN_RECEIVER_COMPONENT);
+        } catch (InterruptedException e) {
+            fail("Removal of device admin interrupted.");
+        }
+        assertFalse(mDpm.isAdminActive(PrimaryUserDeviceAdmin.ADMIN_RECEIVER_COMPONENT));
+    }
+
+    /**
+     * Set lockscreen password.
+     */
+    public void testSetPassword() {
+        // Enable credential storage by setting a nonempty password.
+        assertTrue(mDpm.resetPassword("test", 0));
+    }
+
+    /**
+     * Clear lockscreen password.
+     */
+    public void testClearPassword() {
+        mDpm.setPasswordQuality(PrimaryUserDeviceAdmin.ADMIN_RECEIVER_COMPONENT,
+                DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
+        mDpm.setPasswordMinimumLength(
+                PrimaryUserDeviceAdmin.ADMIN_RECEIVER_COMPONENT, 0);
+        assertTrue(mDpm.resetPassword("", 0));
+    }
+
+    private void removeActiveAdmin(DevicePolicyManager dpm, ComponentName cn)
+            throws InterruptedException {
+        if (mDpm.isAdminActive(cn)) {
+            mDpm.removeActiveAdmin(cn);
+            // Wait until device admin is not active.
+            for (int i = 0; i < 1000 && dpm.isAdminActive(cn); i++) {
+                Thread.sleep(100);
+            }
+        }
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserDeviceAdmin.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserDeviceAdmin.java
new file mode 100644
index 0000000..8662daf
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/PrimaryUserDeviceAdmin.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2015 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.managedprofile;
+
+import android.app.admin.DeviceAdminReceiver;
+import android.content.ComponentName;
+
+/**
+ * A device admin class running in the primary user. Currently used by delegated cert installer
+ * test to set a lockscreen password which is prerequisite of installKeyPair().
+ */
+public class PrimaryUserDeviceAdmin extends DeviceAdminReceiver {
+    public static final ComponentName ADMIN_RECEIVER_COMPONENT = new ComponentName(
+            PrimaryUserDeviceAdmin.class.getPackage().getName(),
+            PrimaryUserDeviceAdmin.class.getName());
+}
\ No newline at end of file
diff --git a/hostsidetests/devicepolicy/app/SimpleApp/AndroidManifest.xml b/hostsidetests/devicepolicy/app/SimpleApp/AndroidManifest.xml
index 848317c..af74f57 100644
--- a/hostsidetests/devicepolicy/app/SimpleApp/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/SimpleApp/AndroidManifest.xml
@@ -31,6 +31,18 @@
         <activity android:name=".NonLauncherActivity">
             android:exported="true">
         </activity>
+        <activity android:name=".SimpleActivityImmediateExit" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+        <activity android:name=".SimpleActivityChainExit" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
     </application>
 
 </manifest>
diff --git a/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityChainExit.java b/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityChainExit.java
new file mode 100644
index 0000000..49f14da
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityChainExit.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 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.launcherapps.simpleapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+/**
+ * This activity starts another activity. Once the other activity gets terminated, this one will
+ * terminate as well.
+ */
+public class SimpleActivityChainExit extends Activity {
+    private static final String TAG = "SimpleActivityChainExit";
+    // This action.
+    private final static String ACTIVITY_CHAIN_EXIT_ACTION =
+            "com.android.cts.launchertests.LauncherAppsTests.CHAIN_EXIT_ACTION";
+    // The action which will be called from here and then immediately exit again.
+    private static final String SIMPLE_ACTIVITY_IMMEDIATE_EXIT = ".SimpleActivityImmediateExit";
+    // Our package name.
+    private static final String SIMPLE_PACKAGE_NAME = "com.android.cts.launcherapps.simpleapp";
+    // Set to true once the activity was paused. Upon next resume the activity gets finished.
+    private boolean mPaused = false;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        Log.i(TAG, "Created SimpleActivityChainExit.");
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        // Start our second activity which will quit itself immediately giving back control.
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(SIMPLE_PACKAGE_NAME,
+                SIMPLE_PACKAGE_NAME + SIMPLE_ACTIVITY_IMMEDIATE_EXIT);
+        startActivityForResult(intent, 0);
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        mPaused = true;
+    }
+
+    @Override
+    public void onResume() {
+        super.onResume();
+        // We ignore any resumes coming in before we got at least paused once.
+        if (mPaused) {
+            // Since we were paused once we can finish ourselves now.
+            finish();
+        }
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        // Notify a listener that this activity will end now.
+        Intent reply = new Intent();
+        reply.setAction(ACTIVITY_CHAIN_EXIT_ACTION);
+        sendBroadcast(reply);
+    }
+}
diff --git a/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityImmediateExit.java b/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityImmediateExit.java
new file mode 100644
index 0000000..15cc3f6
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/SimpleApp/src/com/android/cts/launcherapps/simpleapp/SimpleActivityImmediateExit.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 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.launcherapps.simpleapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+
+/**
+ * A simple activity which quits itself immediately after starting.
+ */
+public class SimpleActivityImmediateExit extends Activity {
+    private final static String ACTIVITY_EXIT_ACTION =
+            "com.android.cts.launchertests.LauncherAppsTests.EXIT_ACTION";
+    private static final String TAG = "SimpleActivityImmediateExit";
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+        Log.i(TAG, "Created SimpleActivityImmediateExit.");
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+        finish();
+    }
+
+    @Override
+    protected void onStop() {
+        super.onStop();
+        // Notify any listener that this activity is about to end now.
+        Intent reply = new Intent();
+        reply.setAction(ACTIVITY_EXIT_ACTION);
+        sendBroadcast(reply);
+    }
+}
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/BaseDevicePolicyTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/BaseDevicePolicyTest.java
index 7e0d959..5904a6f 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/BaseDevicePolicyTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/BaseDevicePolicyTest.java
@@ -335,4 +335,12 @@
         assertTrue(commandOutput + " expected to start with \"Success:\"",
                 commandOutput.startsWith("Success:"));
     }
+
+    protected void setDeviceAdmin(String componentName) throws DeviceNotAvailableException {
+        String command = "dpm set-active-admin '" + componentName + "'";
+        String commandOutput = getDevice().executeShellCommand(command);
+        CLog.logAndDisplay(LogLevel.INFO, "Output for command " + command + ": " + commandOutput);
+        assertTrue(commandOutput + " expected to start with \"Success:\"",
+                commandOutput.startsWith("Success:"));
+    }
 }
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index 3954bda..5c2048e 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -36,6 +36,9 @@
     private static final String INTENT_RECEIVER_PKG = "com.android.cts.intent.receiver";
     private static final String INTENT_RECEIVER_APK = "CtsIntentReceiverApp.apk";
 
+    private static final String CERT_INSTALLER_PKG = "com.android.cts.certinstaller";
+    private static final String CERT_INSTALLER_APK = "CtsCertInstallerApp.apk";
+
     private static final String ADMIN_RECEIVER_TEST_CLASS =
             MANAGED_PROFILE_PKG + ".BaseManagedProfileTest$BasicAdminReceiver";
 
@@ -66,6 +69,7 @@
             getDevice().uninstallPackage(MANAGED_PROFILE_PKG);
             getDevice().uninstallPackage(INTENT_SENDER_PKG);
             getDevice().uninstallPackage(INTENT_RECEIVER_PKG);
+            getDevice().uninstallPackage(CERT_INSTALLER_PKG);
         }
         super.tearDown();
     }
@@ -380,6 +384,28 @@
                 "testSetBluetoothContactSharingDisabled_setterAndGetter", mUserId));
     }
 
+    public void testDelegatedCertInstaller() throws Exception {
+        if (!mHasFeature) {
+            return;
+        }
+        installApp(CERT_INSTALLER_APK);
+        setDeviceAdmin(MANAGED_PROFILE_PKG + "/.PrimaryUserDeviceAdmin");
+
+        final String adminHelperClass = ".PrimaryUserAdminHelper";
+        try {
+            assertTrue("Set lockscreen password failed", runDeviceTestsAsUser(MANAGED_PROFILE_PKG,
+                    adminHelperClass, "testSetPassword", 0 /* user 0 */));
+            assertTrue("DelegatedCertInstaller failed", runDeviceTestsAsUser(MANAGED_PROFILE_PKG,
+                    ".DelegatedCertInstallerTest", mUserId));
+        } finally {
+            // Reset lockscreen password and remove device admin.
+            assertTrue("Clear lockscreen password failed", runDeviceTestsAsUser(MANAGED_PROFILE_PKG,
+                    adminHelperClass, "testClearPassword", 0 /* user 0 */));
+            assertTrue("Clear device admin failed", runDeviceTestsAsUser(MANAGED_PROFILE_PKG,
+                    adminHelperClass, "testClearDeviceAdmin", 0 /* user 0 */));
+        }
+    }
+
     private void disableActivityForUser(String activityName, int userId)
             throws DeviceNotAvailableException {
         String command = "am start -W --user " + userId
diff --git a/hostsidetests/dumpsys/src/android/dumpsys/cts/DumpsysHostTest.java b/hostsidetests/dumpsys/src/android/dumpsys/cts/DumpsysHostTest.java
index 94862e7..fec4b40 100644
--- a/hostsidetests/dumpsys/src/android/dumpsys/cts/DumpsysHostTest.java
+++ b/hostsidetests/dumpsys/src/android/dumpsys/cts/DumpsysHostTest.java
@@ -813,11 +813,76 @@
         assertInteger(parts[4]); // chargeTimeRemaining
     }
 
-    private static void assertInteger(String input) {
+    /**
+     * Tests the output of "dumpsys gfxinfo framestats".
+     *
+     * @throws Exception
+     */
+    public void testGfxinfoFramestats() throws Exception {
+        final String MARKER = "---PROFILEDATA---";
+
+        String frameinfo = mDevice.executeShellCommand("dumpsys gfxinfo com.android.systemui framestats");
+        assertNotNull(frameinfo);
+        assertTrue(frameinfo.length() > 0);
+        int profileStart = frameinfo.indexOf(MARKER);
+        int profileEnd = frameinfo.indexOf(MARKER, profileStart + 1);
+        assertTrue(profileStart >= 0);
+        assertTrue(profileEnd > profileStart);
+        String profileData = frameinfo.substring(profileStart + MARKER.length(), profileEnd);
+        assertTrue(profileData.length() > 0);
+        boolean foundAtLeastOneRow = false;
+        try (BufferedReader reader = new BufferedReader(
+                new StringReader(profileData))) {
+            String line;
+            // First line needs to be the headers
+            while ((line = reader.readLine()) != null && line.isEmpty()) {}
+
+            assertNotNull(line);
+            assertTrue("First line was not the expected header",
+                    line.startsWith("Flags,IntendedVsync,Vsync,OldestInputEvent" +
+                            ",NewestInputEvent,HandleInputStart,AnimationStart" +
+                            ",PerformTraversalsStart,DrawStart,SyncStart" +
+                            ",IssueDrawCommandsStart,SwapBuffers,FrameCompleted"));
+
+            long[] numparts = new long[13];
+            while ((line = reader.readLine()) != null && !line.isEmpty()) {
+
+                String[] parts = line.split(",");
+                assertTrue(parts.length >= 13);
+                for (int i = 0; i < 13; i++) {
+                    numparts[i] = assertInteger(parts[i]);
+                }
+                if (numparts[0] != 0) {
+                    continue;
+                }
+                // assert VSYNC >= INTENDED_VSYNC
+                assertTrue(numparts[2] >= numparts[1]);
+                // assert time is flowing forwards, skipping index 3 & 4
+                // as those are input timestamps that may or may not be present
+                assertTrue(numparts[5] >= numparts[2]);
+                for (int i = 6; i < 13; i++) {
+                    assertTrue("Index " + i + " did not flow forward, " +
+                            numparts[i] + " not larger than " + numparts[i - 1],
+                            numparts[i] >= numparts[i-1]);
+                }
+                long totalDuration = numparts[12] - numparts[1];
+                assertTrue("Frame did not take a positive amount of time to process",
+                        totalDuration > 0);
+                assertTrue("Bogus frame duration, exceeds 100 seconds",
+                        totalDuration < 100000000000L);
+                foundAtLeastOneRow = true;
+            }
+        }
+        assertTrue(foundAtLeastOneRow);
+    }
+
+    private static long assertInteger(String input) {
         try {
-            Long.parseLong(input);
+            return Long.parseLong(input);
         } catch (NumberFormatException e) {
             fail("Expected an integer but found \"" + input + "\"");
+            // Won't be hit, above throws AssertException
+            return -1;
         }
     }
 
diff --git a/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java b/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
index 28b4feb..d8c3afb 100644
--- a/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
+++ b/suite/cts/deviceTests/videoperf/src/com/android/cts/videoperf/VideoEncoderDecoderTest.java
@@ -23,11 +23,13 @@
 import android.media.Image;
 import android.media.Image.Plane;
 import android.media.MediaCodec;
+import android.media.MediaCodec.BufferInfo;
 import android.media.MediaCodecInfo;
 import android.media.MediaCodecInfo.CodecCapabilities;
 import android.media.MediaCodecList;
 import android.media.MediaFormat;
 import android.util.Log;
+import android.util.Pair;
 import android.util.Range;
 import android.util.Size;
 
@@ -40,6 +42,7 @@
 import java.nio.ByteBuffer;
 import java.lang.System;
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.Random;
 import java.util.Vector;
 
@@ -82,7 +85,7 @@
     private int mVideoHeight;
     private int mFrameRate;
 
-    private Vector<ByteBuffer> mEncodedOutputBuffer;
+    private LinkedList<Pair<ByteBuffer, BufferInfo>> mEncodedOutputBuffer;
     // check this many pixels per each decoded frame
     // checking too many points decreases decoder frame rates a lot.
     private static final int PIXEL_CHECK_PER_FRAME = 1000;
@@ -100,7 +103,7 @@
 
     @Override
     protected void setUp() throws Exception {
-        mEncodedOutputBuffer = new Vector<ByteBuffer>(TOTAL_FRAMES * 2);
+        mEncodedOutputBuffer = new LinkedList<Pair<ByteBuffer, BufferInfo>>();
         // Use time as a seed, hoping to prevent checking pixels in the same pattern
         long now = System.currentTimeMillis();
         mRandom = new Random(now);
@@ -803,7 +806,9 @@
         int l = info.size;
         ByteBuffer copied = ByteBuffer.allocate(l);
         output.get(copied.array(), 0, l);
-        mEncodedOutputBuffer.add(copied);
+        BufferInfo savedInfo = new BufferInfo();
+        savedInfo.set(0, l, info.presentationTimeUs, info.flags);
+        mEncodedOutputBuffer.addLast(Pair.create(copied, savedInfo));
         codec.releaseOutputBuffer(index, false /* render */);
     }
 
@@ -842,7 +847,8 @@
                 if (inputBufIndex >= 0) {
                     ByteBuffer dstBuf = codecInputBuffers[inputBufIndex];
                     dstBuf.clear();
-                    ByteBuffer src = mEncodedOutputBuffer.get(inputBufferCount);
+                    ByteBuffer src = mEncodedOutputBuffer.get(inputBufferCount).first;
+                    BufferInfo srcInfo = mEncodedOutputBuffer.get(inputBufferCount).second;
                     int writeSize = src.capacity();
                     dstBuf.put(src.array(), 0, writeSize);
 
@@ -850,8 +856,8 @@
                             inputBufIndex,
                             0 /* offset */,
                             writeSize,
-                            0,
-                            (inputLeft == 1) ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0);
+                            srcInfo.presentationTimeUs,
+                            srcInfo.flags);
                     inputLeft --;
                     inputBufferCount ++;
                 }
diff --git a/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java b/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
index 08a905b..41332c7 100644
--- a/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
+++ b/tests/tests/admin/src/android/admin/cts/DevicePolicyManagerTest.java
@@ -679,6 +679,19 @@
         }
     }
 
+    public void testInstallCaCert_failIfNotCertInstaller() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testInstallCaCert_failIfNotCertInstaller");
+            return;
+        }
+        try {
+            // Delegated cert installer is identified by using null as the first argument.
+            mDevicePolicyManager.installCaCert(null, TEST_CA_STRING1.getBytes());
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException expected) {
+        }
+    }
+
     public void testUninstallCaCert_failIfNotProfileOwner() {
         if (!mDeviceAdmin) {
             Log.w(TAG, "Skipping testUninstallCaCert_failIfNotProfileOwner");
@@ -693,6 +706,19 @@
         }
     }
 
+    public void testUninstallCaCert_failIfNotCertInstaller() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testUninstallCaCert_failIfNotCertInstaller");
+            return;
+        }
+        try {
+            // Delegated cert installer is identified by using null as the first argument.
+            mDevicePolicyManager.uninstallCaCert(null, TEST_CA_STRING1.getBytes());
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException expected) {
+        }
+    }
+
     public void testGetInstalledCaCerts_failIfNotProfileOwner() {
         if (!mDeviceAdmin) {
             Log.w(TAG, "Skipping testGetInstalledCaCerts_failIfNotProfileOwner");
@@ -706,6 +732,19 @@
         }
     }
 
+    public void testGetInstalledCaCerts_failIfNotCertInstaller() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testGetInstalledCaCerts_failIfNotCertInstaller");
+            return;
+        }
+        try {
+            // Delegated cert installer is identified by using null as the first argument.
+            mDevicePolicyManager.getInstalledCaCerts(null);
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException expected) {
+        }
+    }
+
     public void testHasCaCertInstalled_failIfNotProfileOwner() {
         if (!mDeviceAdmin) {
             Log.w(TAG, "Skipping testHasCaCertInstalled_failIfNotProfileOwner");
@@ -720,6 +759,19 @@
         }
     }
 
+    public void testHasCaCertInstalled_failIfNotCertInstaller() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testHasCaCertInstalled_failIfNotCertInstaller");
+            return;
+        }
+        try {
+            // Delegated cert installer is identified by using null as the first argument.
+            mDevicePolicyManager.hasCaCertInstalled(null, TEST_CA_STRING1.getBytes());
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException expected) {
+        }
+    }
+
     public void testUninstallAllUserCaCerts_failIfNotProfileOwner() {
         if (!mDeviceAdmin) {
             Log.w(TAG, "Skipping testUninstallAllUserCaCerts_failIfNotProfileOwner");
@@ -733,6 +785,19 @@
         }
     }
 
+    public void testUninstallAllUserCaCerts_failIfNotCertInstaller() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testUninstallAllUserCaCerts_failIfNotCertInstaller");
+            return;
+        }
+        try {
+            // Delegated cert installer is identified by using null as the first argument.
+            mDevicePolicyManager.uninstallAllUserCaCerts(null);
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException expected) {
+        }
+    }
+
     public void testSetScreenCaptureDisabled_failIfNotProfileOwner() {
         if (!mDeviceAdmin) {
             Log.w(TAG, "Skipping testSetScreenCaptureDisabled_failIfNotProfileOwner");
@@ -961,4 +1026,30 @@
         assertTrue("Password '" + password + "' failed on " + restriction, passwordResetResult);
         assertTrue(mDevicePolicyManager.isActivePasswordSufficient());
     }
+
+    public void testSetDelegatedCertInstaller_failIfNotProfileOwner() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testSetDelegatedCertInstaller_failIfNotProfileOwner");
+            return;
+        }
+        try {
+            mDevicePolicyManager.setCertInstallerPackage(mComponent, "com.test.package");
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException e) {
+            assertProfileOwnerMessage(e.getMessage());
+        }
+    }
+
+    public void testGetDelegatedCertInstaller_failIfNotProfileOwner() {
+        if (!mDeviceAdmin) {
+            Log.w(TAG, "Skipping testGetDelegatedCertInstaller_failIfNotProfileOwner");
+            return;
+        }
+        try {
+            mDevicePolicyManager.getCertInstallerPackage(mComponent);
+            fail("did not throw expected SecurityException");
+        } catch (SecurityException e) {
+            assertProfileOwnerMessage(e.getMessage());
+        }
+    }
 }
diff --git a/tests/tests/app/AndroidTest.xml b/tests/tests/app/AndroidTest.xml
new file mode 100644
index 0000000..01ebbcb
--- /dev/null
+++ b/tests/tests/app/AndroidTest.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+<configuration description="Base config for CTS package preparer">
+    <include name="common-config" />
+    <option name="cts-apk-installer:test-file-name" value="CtsSimpleApp.apk" />
+</configuration>
diff --git a/tests/tests/app/src/android/app/cts/ActivityManagerTest.java b/tests/tests/app/src/android/app/cts/ActivityManagerTest.java
index 998a005..e531ac6 100644
--- a/tests/tests/app/src/android/app/cts/ActivityManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/ActivityManagerTest.java
@@ -21,17 +21,22 @@
 
 import android.app.Activity;
 import android.app.ActivityManager;
-import android.app.Instrumentation;
 import android.app.ActivityManager.ProcessErrorStateInfo;
 import android.app.ActivityManager.RecentTaskInfo;
 import android.app.ActivityManager.RunningAppProcessInfo;
 import android.app.ActivityManager.RunningServiceInfo;
 import android.app.ActivityManager.RunningTaskInfo;
+import android.app.ActivityOptions;
+import android.app.Instrumentation;
 import android.app.Instrumentation.ActivityMonitor;
 import android.app.Instrumentation.ActivityResult;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.ConfigurationInfo;
+import android.os.Bundle;
 import android.test.InstrumentationTestCase;
 
 public class ActivityManagerTest extends InstrumentationTestCase {
@@ -39,6 +44,27 @@
     private static final int WAITFOR_MSEC = 5000;
     private static final String SERVICE_NAME = "android.app.cts.MockService";
     private static final int WAIT_TIME = 2000;
+    // A secondary test activity from another APK.
+    private static final String SIMPLE_PACKAGE_NAME = "com.android.cts.launcherapps.simpleapp";
+    private static final String SIMPLE_ACTIVITY = ".SimpleActivity";
+    private static final String SIMPLE_ACTIVITY_IMMEDIATE_EXIT = ".SimpleActivityImmediateExit";
+    private static final String SIMPLE_ACTIVITY_CHAIN_EXIT = ".SimpleActivityChainExit";
+    // The action sent back by the SIMPLE_APP after a restart.
+    private static final String ACTIVITY_LAUNCHED_ACTION =
+            "com.android.cts.launchertests.LauncherAppsTests.LAUNCHED_ACTION";
+    // The action sent back by the SIMPLE_APP_IMMEDIATE_EXIT when it terminates.
+    private static final String ACTIVITY_EXIT_ACTION =
+            "com.android.cts.launchertests.LauncherAppsTests.EXIT_ACTION";
+    // The action sent back by the SIMPLE_APP_CHAIN_EXIT when the task chain ends. 
+    private static final String ACTIVITY_CHAIN_EXIT_ACTION =
+            "com.android.cts.launchertests.LauncherAppsTests.CHAIN_EXIT_ACTION";
+    // The action sent to identify the time track info.
+    private static final String ACTIVITY_TIME_TRACK_INFO = "com.android.cts.TIME_TRACK_INFO";
+    // Return states of the ActivityReceiverFilter.
+    public static final int RESULT_PASS = 1;
+    public static final int RESULT_FAIL = 2;
+    public static final int RESULT_TIMEOUT = 3;
+
     private Context mContext;
     private ActivityManager mActivityManager;
     private Intent mIntent;
@@ -119,6 +145,79 @@
         }
     }
 
+    public void testGetRecentTasksLimitedToCurrentAPK() throws Exception {
+        int maxNum = 0;
+        int flags = 0;
+
+        // Check the number of tasks at this time.
+        List<RecentTaskInfo>  recentTaskList;
+        recentTaskList = mActivityManager.getRecentTasks(maxNum, flags);
+        int numberOfEntriesFirstRun = recentTaskList.size();
+
+        // Start another activity from another APK.
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(SIMPLE_PACKAGE_NAME, SIMPLE_PACKAGE_NAME + SIMPLE_ACTIVITY);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        ActivityReceiverFilter receiver = new ActivityReceiverFilter(ACTIVITY_LAUNCHED_ACTION);
+        mContext.startActivity(intent);
+
+        // Make sure the activity has really started.
+        assertEquals(RESULT_PASS, receiver.waitForActivity());
+        receiver.close();
+
+        // There shouldn't be any more tasks in this list at this time.
+        recentTaskList = mActivityManager.getRecentTasks(maxNum, flags);
+        int numberOfEntriesSecondRun = recentTaskList.size();
+        assertTrue(numberOfEntriesSecondRun == numberOfEntriesFirstRun);
+    }
+
+    // The receiver filter needs to be instantiated with the command to filter for before calling
+    // startActivity.
+    private class ActivityReceiverFilter extends BroadcastReceiver {
+        // The activity we want to filter for.
+        private String mActivityToFilter;
+        private int result = RESULT_TIMEOUT;
+        public long mTimeUsed = 0;
+        private static final int TIMEOUT_IN_MS = 1000;
+
+        // Create the filter with the intent to look for.
+        public ActivityReceiverFilter(String activityToFilter) {
+            mActivityToFilter = activityToFilter;
+            IntentFilter filter = new IntentFilter();
+            filter.addAction(mActivityToFilter);
+            mInstrumentation.getTargetContext().registerReceiver(this, filter);
+        }
+
+        // Turn off the filter.
+        public void close() {
+            mInstrumentation.getTargetContext().unregisterReceiver(this);
+        }
+
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (intent.getAction().equals(mActivityToFilter)) {
+                synchronized(this) {
+                   result = RESULT_PASS;
+                   if (mActivityToFilter.equals(ACTIVITY_TIME_TRACK_INFO)) {
+                       mTimeUsed = intent.getExtras().getLong(
+                               ActivityOptions.EXTRA_USAGE_REPORT_TIME);
+                   }
+                   notifyAll();
+                }
+            }
+        }
+
+        public int waitForActivity() {
+            synchronized(this) {
+                try {
+                    wait(TIMEOUT_IN_MS);
+                } catch (InterruptedException e) {
+                }
+            }
+            return result;
+        }
+    }
+
     private final <T extends Activity> void startSubActivity(Class<T> activityClass) {
         final Instrumentation.ActivityResult result = new ActivityResult(0, new Intent());
         final ActivityMonitor monitor = new ActivityMonitor(activityClass.getName(), result, false);
@@ -273,4 +372,158 @@
         assertFalse("isRunningInTestHarness must be false in production builds",
                 ActivityManager.isRunningInTestHarness());
     }
+
+    /**
+     * Go back to the home screen since running applications can interfere with application
+     * lifetime tests.
+     */
+    private void launchHome() throws Exception {
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.addCategory(Intent.CATEGORY_HOME);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        mContext.startActivity(intent);
+        Thread.sleep(WAIT_TIME);
+    }
+
+    /**
+     * Verify that the TimeTrackingAPI works properly when starting and ending an activity.
+     */
+    public void testTimeTrackingAPI_SimpleStartExit() throws Exception {
+        launchHome();
+        // Prepare to start an activity from another APK.
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(SIMPLE_PACKAGE_NAME,
+                SIMPLE_PACKAGE_NAME + SIMPLE_ACTIVITY_IMMEDIATE_EXIT);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        // Prepare the time receiver action.
+        Context context = mInstrumentation.getTargetContext();
+        ActivityOptions options = ActivityOptions.makeBasic();
+        Intent receiveIntent = new Intent(ACTIVITY_TIME_TRACK_INFO);
+        options.requestUsageTimeReport(PendingIntent.getBroadcast(context,
+                0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT));
+
+        // The application finished tracker.
+        ActivityReceiverFilter appEndReceiver = new ActivityReceiverFilter(ACTIVITY_EXIT_ACTION);
+
+        // The filter for the time event.
+        ActivityReceiverFilter timeReceiver = new ActivityReceiverFilter(ACTIVITY_TIME_TRACK_INFO);
+
+        // Run the activity.
+        mContext.startActivity(intent, options.toBundle());
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, appEndReceiver.waitForActivity());
+        appEndReceiver.close();
+
+        // At this time the timerReceiver should not fire, even though the activity has shut down,
+        // because we are back to the home screen.
+        assertEquals(RESULT_TIMEOUT, timeReceiver.waitForActivity());
+        assertTrue(timeReceiver.mTimeUsed == 0);
+
+        // Issuing now another activity will trigger the timing information release.
+        final Intent dummyIntent = new Intent(context, MockApplicationActivity.class);
+        dummyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        final Activity activity = mInstrumentation.startActivitySync(dummyIntent);
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, timeReceiver.waitForActivity());
+        timeReceiver.close();
+        assertTrue(timeReceiver.mTimeUsed != 0);
+    }
+
+    /**
+     * Verify that the TimeTrackingAPI works properly when switching away from the monitored task.
+     */
+    public void testTimeTrackingAPI_SwitchAwayTriggers() throws Exception {
+        launchHome();
+
+        // Prepare to start an activity from another APK.
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(SIMPLE_PACKAGE_NAME, SIMPLE_PACKAGE_NAME + SIMPLE_ACTIVITY);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        // Prepare the time receiver action.
+        Context context = mInstrumentation.getTargetContext();
+        ActivityOptions options = ActivityOptions.makeBasic();
+        Intent receiveIntent = new Intent(ACTIVITY_TIME_TRACK_INFO);
+        options.requestUsageTimeReport(PendingIntent.getBroadcast(context,
+                0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT));
+
+        // The application started tracker.
+        ActivityReceiverFilter appStartedReceiver = new ActivityReceiverFilter(
+                ACTIVITY_LAUNCHED_ACTION);
+
+        // The filter for the time event.
+        ActivityReceiverFilter timeReceiver = new ActivityReceiverFilter(ACTIVITY_TIME_TRACK_INFO);
+
+        // Run the activity.
+        mContext.startActivity(intent, options.toBundle());
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, appStartedReceiver.waitForActivity());
+        appStartedReceiver.close();
+
+        // At this time the timerReceiver should not fire since our app is running.
+        assertEquals(RESULT_TIMEOUT, timeReceiver.waitForActivity());
+        assertTrue(timeReceiver.mTimeUsed == 0);
+
+        // Starting now another activity will put ours into the back hence releasing the timing.
+        final Intent dummyIntent = new Intent(context, MockApplicationActivity.class);
+        dummyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        final Activity activity = mInstrumentation.startActivitySync(dummyIntent);
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, timeReceiver.waitForActivity());
+        timeReceiver.close();
+        assertTrue(timeReceiver.mTimeUsed != 0);
+    }
+
+    /**
+     * Verify that the TimeTrackingAPI works properly when handling an activity chain gets started
+     * and ended.
+     */
+    public void testTimeTrackingAPI_ChainedActivityExit() throws Exception {
+        launchHome();
+        // Prepare to start an activity from another APK.
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.setClassName(SIMPLE_PACKAGE_NAME,
+                SIMPLE_PACKAGE_NAME + SIMPLE_ACTIVITY_CHAIN_EXIT);
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+        // Prepare the time receiver action.
+        Context context = mInstrumentation.getTargetContext();
+        ActivityOptions options = ActivityOptions.makeBasic();
+        Intent receiveIntent = new Intent(ACTIVITY_TIME_TRACK_INFO);
+        options.requestUsageTimeReport(PendingIntent.getBroadcast(context,
+                0, receiveIntent, PendingIntent.FLAG_CANCEL_CURRENT));
+
+        // The application finished tracker.
+        ActivityReceiverFilter appEndReceiver = new ActivityReceiverFilter(
+                ACTIVITY_CHAIN_EXIT_ACTION);
+
+        // The filter for the time event.
+        ActivityReceiverFilter timeReceiver = new ActivityReceiverFilter(ACTIVITY_TIME_TRACK_INFO);
+
+        // Run the activity.
+        mContext.startActivity(intent, options.toBundle());
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, appEndReceiver.waitForActivity());
+        appEndReceiver.close();
+
+        // At this time the timerReceiver should not fire, even though the activity has shut down.
+        assertEquals(RESULT_TIMEOUT, timeReceiver.waitForActivity());
+        assertTrue(timeReceiver.mTimeUsed == 0);
+
+        // Issue another activity so that the timing information gets released.
+        final Intent dummyIntent = new Intent(context, MockApplicationActivity.class);
+        dummyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        final Activity activity = mInstrumentation.startActivitySync(dummyIntent);
+
+        // Wait until it finishes and end the reciever then.
+        assertEquals(RESULT_PASS, timeReceiver.waitForActivity());
+        timeReceiver.close();
+        assertTrue(timeReceiver.mTimeUsed != 0);
+    }
 }
diff --git a/tests/tests/app/src/android/app/cts/ProgressDialogTest.java b/tests/tests/app/src/android/app/cts/ProgressDialogTest.java
index 038b57b..b2037b6 100644
--- a/tests/tests/app/src/android/app/cts/ProgressDialogTest.java
+++ b/tests/tests/app/src/android/app/cts/ProgressDialogTest.java
@@ -97,8 +97,7 @@
 
     @UiThreadTest
     public void testShow2() {
-        ProgressDialog dialog = buildDialog();
-        dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, false);
+        ProgressDialog dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, false);
 
         /*
          * note: the progress bar's style only supports indeterminate mode,
@@ -120,11 +119,11 @@
         // cancelable is false
         runTestOnUiThread(new Runnable() {
             public void run() {
-                ProgressDialog dialog = buildDialog();
-                dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, false);
+                ProgressDialog dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, false);
 
                 dialog.setOnCancelListener(cL);
                 dialog.onBackPressed();
+                dialog.dismiss();
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -134,8 +133,7 @@
         // cancelable is true
         runTestOnUiThread(new Runnable() {
             public void run() {
-                ProgressDialog dialog = buildDialog();
-                dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, true);
+                ProgressDialog dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, true);
                 assertFalse(mCanceled);
                 dialog.setOnCancelListener(cL);
                 dialog.onBackPressed();
@@ -156,10 +154,11 @@
         // cancelable is false
         runTestOnUiThread(new Runnable() {
             public void run() {
-                ProgressDialog dialog = buildDialog();
-                dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, false, cL);
+                ProgressDialog dialog = ProgressDialog.show(
+                        mContext, TITLE, MESSAGE, true, false, cL);
 
                 dialog.onBackPressed();
+                dialog.dismiss();;
             }
         });
         mInstrumentation.waitForIdleSync();
@@ -169,8 +168,8 @@
         // cancelable is true
         runTestOnUiThread(new Runnable() {
             public void run() {
-                ProgressDialog dialog = buildDialog();
-                dialog = ProgressDialog.show(mContext, TITLE, MESSAGE, true, true, cL);
+                ProgressDialog dialog = ProgressDialog.show(
+                        mContext, TITLE, MESSAGE, true, true, cL);
 
                 assertFalse(mCanceled);
                 dialog.onBackPressed();
diff --git a/tests/tests/content/AndroidManifest.xml b/tests/tests/content/AndroidManifest.xml
index d54bc02..6cddfd1 100644
--- a/tests/tests/content/AndroidManifest.xml
+++ b/tests/tests/content/AndroidManifest.xml
@@ -39,7 +39,10 @@
                     android:label="Test Tree"/>
 
     <!-- Used for PackageManager test, don't delete this permission-group -->
-    <permission-group android:name="android.permission-group.COST_MONEY"/>
+    <permission-group android:name="android.permission-group.COST_MONEY"
+            android:label="@string/permlab_costMoney"
+            android:description="@string/permdesc_costMoney"/>
+
     <!-- Used for PackageManager test, don't delete! -->
     <uses-configuration/>
     <uses-feature android:name="android.hardware.camera" />
diff --git a/tests/tests/content/res/values/strings.xml b/tests/tests/content/res/values/strings.xml
index c167278..c546d8a 100644
--- a/tests/tests/content/res/values/strings.xml
+++ b/tests/tests/content/res/values/strings.xml
@@ -176,4 +176,8 @@
 text, I would love to see the kind of devices you guys now use! Guys, maybe some devices need longer string!
 I think so, so how about double this string, like copy and paste! </string>
     <string name="rectangle200">"M 0,0 l 200,0 l 0, 200 l -200, 0 z"</string>
+
+    <string name="permlab_costMoney">Cost money</string>
+    <string name="permdesc_costMoney">Do things that can cost you money.</string>
+
 </resources>
diff --git a/tests/tests/content/src/android/content/cts/ContentResolverTest.java b/tests/tests/content/src/android/content/cts/ContentResolverTest.java
index 4176da3..628f956 100644
--- a/tests/tests/content/src/android/content/cts/ContentResolverTest.java
+++ b/tests/tests/content/src/android/content/cts/ContentResolverTest.java
@@ -58,6 +58,11 @@
     private static final Uri SELF_URI = Uri.parse("content://" + AUTHORITY + "/self/");
     private static final Uri CRASH_URI = Uri.parse("content://" + AUTHORITY + "/crash/");
 
+    private static final Uri LEVEL1_URI = Uri.parse("content://" + AUTHORITY + "/level/");
+    private static final Uri LEVEL2_URI = Uri.parse("content://" + AUTHORITY + "/level/child");
+    private static final Uri LEVEL3_URI = Uri.parse("content://" + AUTHORITY
+            + "/level/child/grandchild/");
+
     private static final String REMOTE_AUTHORITY = "remotectstest";
     private static final Uri REMOTE_TABLE1_URI = Uri.parse("content://"
                 + REMOTE_AUTHORITY + "/testtable1/");
@@ -88,7 +93,7 @@
         mContext = getContext();
         mContentResolver = mContext.getContentResolver();
 
-        android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 0);
+        MockContentProvider.setCrashOnLaunch(mContext, false);
 
         // add three rows to database when every test case start.
         ContentValues values = new ContentValues();
@@ -151,13 +156,12 @@
             fail("Content provider process is not gone!");
         }
         try {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 1);
+            MockContentProvider.setCrashOnLaunch(mContext, true);
             String type1 = mContentResolver.getType(REMOTE_TABLE1_URI);
-            assertEquals(android.provider.Settings.System.getInt(mContentResolver,
-                "__cts_crash_on_launch", 0), 0);
+            assertFalse(MockContentProvider.getCrashOnLaunch(mContext));
             assertTrue(type1.startsWith(ContentResolver.CURSOR_DIR_BASE_TYPE, 0));
         } finally {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 0);
+            MockContentProvider.setCrashOnLaunch(mContext, false);
         }
     }
 
@@ -352,12 +356,11 @@
 
     public void testCrashingQuery() {
         try {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 1);
+            MockContentProvider.setCrashOnLaunch(mContext, true);
             mCursor = mContentResolver.query(REMOTE_CRASH_URI, null, null, null, null);
-            assertEquals(android.provider.Settings.System.getInt(mContentResolver,
-                "__cts_crash_on_launch", 0), 0);
+            assertFalse(MockContentProvider.getCrashOnLaunch(mContext));
         } finally {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 0);
+            MockContentProvider.setCrashOnLaunch(mContext, false);
         }
 
         assertNotNull(mCursor);
@@ -570,16 +573,15 @@
     public void testCrashingOpenAssetFileDescriptor() throws IOException {
         AssetFileDescriptor afd = null;
         try {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 1);
+            MockContentProvider.setCrashOnLaunch(mContext, true);
             afd = mContentResolver.openAssetFileDescriptor(REMOTE_CRASH_URI, "rw");
-            assertEquals(android.provider.Settings.System.getInt(mContentResolver,
-                    "__cts_crash_on_launch", 0), 0);
+            assertFalse(MockContentProvider.getCrashOnLaunch(mContext));
             assertNotNull(afd);
             String str = consumeAssetFileDescriptor(afd);
             afd = null;
             assertEquals(str, "This is the openAssetFile test data!");
         } finally {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 0);
+            MockContentProvider.setCrashOnLaunch(mContext, false);
             if (afd != null) {
                 afd.close();
             }
@@ -602,17 +604,16 @@
     public void testCrashingOpenTypedAssetFileDescriptor() throws IOException {
         AssetFileDescriptor afd = null;
         try {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 1);
+            MockContentProvider.setCrashOnLaunch(mContext, true);
             afd = mContentResolver.openTypedAssetFileDescriptor(
                     REMOTE_CRASH_URI, "text/plain", null);
-            assertEquals(android.provider.Settings.System.getInt(mContentResolver,
-                    "__cts_crash_on_launch", 0), 0);
+            assertFalse(MockContentProvider.getCrashOnLaunch(mContext));
             assertNotNull(afd);
             String str = consumeAssetFileDescriptor(afd);
             afd = null;
             assertEquals(str, "This is the openTypedAssetFile test data!");
         } finally {
-            android.provider.Settings.System.putInt(mContentResolver, "__cts_crash_on_launch", 0);
+            MockContentProvider.setCrashOnLaunch(mContext, false);
             if (afd != null) {
                 afd.close();
             }
@@ -957,6 +958,53 @@
         }
     }
 
+    public void testRegisterContentObserverDescendantBehavior() throws Exception {
+        final MockContentObserver mco1 = new MockContentObserver();
+        final MockContentObserver mco2 = new MockContentObserver();
+
+        // Register one content observer with notifyDescendants set to false, and
+        // another with true.
+        mContentResolver.registerContentObserver(LEVEL2_URI, false, mco1);
+        mContentResolver.registerContentObserver(LEVEL2_URI, true, mco2);
+
+        // Initially nothing has happened.
+        assertFalse(mco1.hadOnChanged());
+        assertFalse(mco2.hadOnChanged());
+
+        // Fire a change with the exact URI.
+        // Should signal both observers due to exact match, notifyDescendants doesn't matter.
+        mContentResolver.notifyChange(LEVEL2_URI, null);
+        Thread.sleep(200);
+        assertTrue(mco1.hadOnChanged());
+        assertTrue(mco2.hadOnChanged());
+        mco1.reset();
+        mco2.reset();
+
+        // Fire a change with a descendant URI.
+        // Should only signal observer with notifyDescendants set to true.
+        mContentResolver.notifyChange(LEVEL3_URI, null);
+        Thread.sleep(200);
+        assertFalse(mco1.hadOnChanged());
+        assertTrue(mco2.hadOnChanged());
+        mco2.reset();
+
+        // Fire a change with an ancestor URI.
+        // Should signal both observers due to ancestry, notifyDescendants doesn't matter.
+        mContentResolver.notifyChange(LEVEL1_URI, null);
+        Thread.sleep(200);
+        assertTrue(mco1.hadOnChanged());
+        assertTrue(mco2.hadOnChanged());
+        mco1.reset();
+        mco2.reset();
+
+        // Fire a change with an unrelated URI.
+        // Should signal neither observer.
+        mContentResolver.notifyChange(TABLE1_URI, null);
+        Thread.sleep(200);
+        assertFalse(mco1.hadOnChanged());
+        assertFalse(mco2.hadOnChanged());
+    }
+
     public void testNotifyChange1() {
         final MockContentObserver mco = new MockContentObserver();
 
diff --git a/tests/tests/content/src/android/content/cts/MockContentProvider.java b/tests/tests/content/src/android/content/cts/MockContentProvider.java
index de82c0d..bddc82d 100644
--- a/tests/tests/content/src/android/content/cts/MockContentProvider.java
+++ b/tests/tests/content/src/android/content/cts/MockContentProvider.java
@@ -16,6 +16,7 @@
 
 package android.content.cts;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -28,6 +29,7 @@
 import android.content.ContentUris;
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.content.UriMatcher;
 import android.content.ContentProvider.PipeDataWriter;
 import android.content.res.AssetFileDescriptor;
@@ -122,15 +124,7 @@
     @Override
     public boolean onCreate() {
         mOpenHelper = new DatabaseHelper(getContext(), mDbName);
-        if (android.provider.Settings.System.getInt(getContext().getContentResolver(),
-                "__cts_crash_on_launch", 0) != 0) {
-            // The test case wants us to crash our process on first launch.
-            // Well, okay then!
-            Log.i("MockContentProvider", "TEST IS CRASHING SELF, CROSS FINGERS!");
-            android.provider.Settings.System.putInt(getContext().getContentResolver(),
-                    "__cts_crash_on_launch", 0);
-            android.os.Process.killProcess(android.os.Process.myPid());
-        }
+        crashOnLaunchIfNeeded();
         return true;
     }
 
@@ -277,15 +271,7 @@
             break;
 
         case CRASH_ID:
-            if (android.provider.Settings.System.getInt(getContext().getContentResolver(),
-                    "__cts_crash_on_launch", 0) != 0) {
-                // The test case wants us to crash while querying.
-                // Well, okay then!
-                Log.i("MockContentProvider", "TEST IS CRASHING SELF, CROSS FINGERS!");
-                android.provider.Settings.System.putInt(getContext().getContentResolver(),
-                        "__cts_crash_on_launch", 0);
-                android.os.Process.killProcess(android.os.Process.myPid());
-            }
+            crashOnLaunchIfNeeded();
             qb.setTables("TestTable1");
             qb.setProjectionMap(CTSDBTABLE1_LIST_PROJECTION_MAP);
             break;
@@ -351,15 +337,7 @@
     public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
         switch (URL_MATCHER.match(uri)) {
             case CRASH_ID:
-                if (android.provider.Settings.System.getInt(getContext().getContentResolver(),
-                        "__cts_crash_on_launch", 0) != 0) {
-                    // The test case wants us to crash while querying.
-                    // Well, okay then!
-                    Log.i("MockContentProvider", "TEST IS CRASHING SELF, CROSS FINGERS!");
-                    android.provider.Settings.System.putInt(getContext().getContentResolver(),
-                            "__cts_crash_on_launch", 0);
-                    android.os.Process.killProcess(android.os.Process.myPid());
-                }
+                crashOnLaunchIfNeeded();
                 return new AssetFileDescriptor(
                         openPipeHelper(uri, null, null,
                                 "This is the openAssetFile test data!", this), 0,
@@ -375,15 +353,7 @@
             throws FileNotFoundException {
         switch (URL_MATCHER.match(uri)) {
             case CRASH_ID:
-                if (android.provider.Settings.System.getInt(getContext().getContentResolver(),
-                        "__cts_crash_on_launch", 0) != 0) {
-                    // The test case wants us to crash while querying.
-                    // Well, okay then!
-                    Log.i("MockContentProvider", "TEST IS CRASHING SELF, CROSS FINGERS!");
-                    android.provider.Settings.System.putInt(getContext().getContentResolver(),
-                            "__cts_crash_on_launch", 0);
-                    android.os.Process.killProcess(android.os.Process.myPid());
-                }
+                crashOnLaunchIfNeeded();
                 return new AssetFileDescriptor(
                         openPipeHelper(uri, null, null,
                                 "This is the openTypedAssetFile test data!", this), 0,
@@ -414,4 +384,36 @@
             }
         }
     }
+
+    private void crashOnLaunchIfNeeded() {
+        if (getCrashOnLaunch(getContext())) {
+            // The test case wants us to crash our process on first launch.
+            // Well, okay then!
+            Log.i("MockContentProvider", "TEST IS CRASHING SELF, CROSS FINGERS!");
+            setCrashOnLaunch(getContext(), false);
+            android.os.Process.killProcess(android.os.Process.myPid());
+        }
+    }
+
+    public static boolean getCrashOnLaunch(Context context) {
+        File file = getCrashOnLaunchFile(context);
+        return file.exists();
+    }
+
+    public static void setCrashOnLaunch(Context context, boolean value) {
+        File file = getCrashOnLaunchFile(context);
+        if (value) {
+            try {
+                file.createNewFile();
+            } catch (IOException ex) {
+                throw new RuntimeException("Could not create crash on launch file.", ex);
+            }
+        } else {
+            file.delete();
+        }
+    }
+
+    private static File getCrashOnLaunchFile(Context context) {
+        return context.getFileStreamPath("MockContentProvider.crashonlaunch");
+    }
 }
diff --git a/tests/tests/content/src/android/content/pm/cts/PermissionGroupInfoTest.java b/tests/tests/content/src/android/content/pm/cts/PermissionGroupInfoTest.java
index fc8d9b8..8b00624 100644
--- a/tests/tests/content/src/android/content/pm/cts/PermissionGroupInfoTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/PermissionGroupInfoTest.java
@@ -24,8 +24,9 @@
 import android.test.AndroidTestCase;
 
 public class PermissionGroupInfoTest extends AndroidTestCase {
-    private static final String PERMISSIONGROUP_NAME = "android.permission-group.COST_MONEY";
-    private static final String DEFAULT_DISCRIPTION = "Do things that can cost you money.";
+    private static final String GROUP = "android.permission-group.COST_MONEY";
+    private static final String GROUP_NAME = "Cost money";
+    private static final String GROUP_DESCRIPTION = "Do things that can cost you money.";
 
     public void testPermissionGroupInfo() throws NameNotFoundException {
         PackageManager pm = getContext().getPackageManager();
@@ -33,14 +34,15 @@
         // Test constructors
         new PermissionGroupInfo();
         PermissionGroupInfo permissionGroupInfo = pm
-                .getPermissionGroupInfo(PERMISSIONGROUP_NAME, 0);
+                .getPermissionGroupInfo(GROUP, 0);
         PermissionGroupInfo infoFromExisted = new PermissionGroupInfo(permissionGroupInfo);
         checkInfoSame(permissionGroupInfo, infoFromExisted);
 
         // Test toString, describeContents, loadDescription
         assertNotNull(permissionGroupInfo.toString());
         assertEquals(0, permissionGroupInfo.describeContents());
-        assertEquals(DEFAULT_DISCRIPTION, permissionGroupInfo.loadDescription(pm));
+        assertEquals(GROUP_NAME, permissionGroupInfo.loadLabel(pm));
+        assertEquals(GROUP_DESCRIPTION, permissionGroupInfo.loadDescription(pm));
 
         // Test writeToParcel
         permissionGroupInfo.writeToParcel(p, 0);
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/ClipDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/ClipDrawableTest.java
index da96cdc..e727350 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/ClipDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/ClipDrawableTest.java
@@ -68,19 +68,21 @@
     }
 
     public void testGetChangingConfigurations() {
+        final int SUPER_CONFIG = 1;
+        final int CONTAINED_DRAWABLE_CONFIG = 2;
+
         MockDrawable mockDrawable = new MockDrawable();
         ClipDrawable clipDrawable = new ClipDrawable(mockDrawable,
                 Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
+
         assertEquals(0, clipDrawable.getChangingConfigurations());
 
-        clipDrawable.setChangingConfigurations(1);
-        assertEquals(1, clipDrawable.getChangingConfigurations());
+        mockDrawable.setChangingConfigurations(CONTAINED_DRAWABLE_CONFIG);
+        assertEquals(CONTAINED_DRAWABLE_CONFIG, clipDrawable.getChangingConfigurations());
 
-        mockDrawable.setChangingConfigurations(2);
-        clipDrawable = new ClipDrawable(mockDrawable,
-                Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
-        clipDrawable.setChangingConfigurations(1);
-        assertEquals(3, clipDrawable.getChangingConfigurations());
+        clipDrawable.setChangingConfigurations(SUPER_CONFIG);
+        assertEquals(SUPER_CONFIG | CONTAINED_DRAWABLE_CONFIG,
+                clipDrawable.getChangingConfigurations());
     }
 
     public void testGetConstantState() {
@@ -126,16 +128,28 @@
 
     @SuppressWarnings("deprecation")
     public void testGetOpacity() {
-        BitmapDrawable bmpDrawable =
-            new BitmapDrawable(Bitmap.createBitmap(100, 50, Config.RGB_565));
-        ClipDrawable clipDrawable = new ClipDrawable(bmpDrawable,
-                Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
-        assertEquals(PixelFormat.OPAQUE, clipDrawable.getOpacity());
+        MockDrawable dr;
+        ClipDrawable clipDrawable;
 
-        bmpDrawable = new BitmapDrawable(Bitmap.createBitmap(100, 50, Config.RGB_565));
-        bmpDrawable.setGravity(Gravity.CENTER);
-        clipDrawable = new ClipDrawable(bmpDrawable, Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
-        assertEquals(PixelFormat.TRANSLUCENT, clipDrawable.getOpacity());
+        dr = new MockDrawable();
+        dr.setOpacity(PixelFormat.OPAQUE);
+        clipDrawable = new ClipDrawable(dr, Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
+        clipDrawable.setLevel(0);
+        assertEquals("Fully-clipped opaque drawable is transparent",
+                PixelFormat.TRANSPARENT, clipDrawable.getOpacity());
+        clipDrawable.setLevel(5000);
+        assertEquals("Partially-clipped opaque drawable is translucent",
+                PixelFormat.TRANSLUCENT, clipDrawable.getOpacity());
+        clipDrawable.setLevel(10000);
+        assertEquals("Unclipped opaque drawable is opaque",
+                PixelFormat.OPAQUE, clipDrawable.getOpacity());
+
+        dr = new MockDrawable();
+        dr.setOpacity(PixelFormat.TRANSLUCENT);
+        clipDrawable = new ClipDrawable(dr, Gravity.BOTTOM, ClipDrawable.HORIZONTAL);
+        clipDrawable.setLevel(10000);
+        assertEquals("Unclipped translucent drawable is translucent",
+                PixelFormat.TRANSLUCENT, clipDrawable.getOpacity());
     }
 
     public void testGetPadding() {
@@ -220,7 +234,7 @@
         MockCallback callback = new MockCallback();
         mockClipDrawable.setCallback(callback);
 
-        assertEquals(0, mockDrawable.getLevel());
+        assertEquals("Default level is 0", 0, mockDrawable.getLevel());
         mockClipDrawable.onLevelChange(1000);
         assertEquals(1000, mockDrawable.getLevel());
         assertSame(mockClipDrawable, callback.getInvalidateDrawable());
@@ -344,6 +358,7 @@
     private class MockDrawable extends Drawable {
         private ColorFilter mColorFilter;
         private ConstantState mConstantState;
+        private int mOpacity;
         private boolean mCalledDraw = false;
         private int mAlpha;
 
@@ -372,7 +387,11 @@
         }
 
         public int getOpacity() {
-            return 0;
+            return mOpacity;
+        }
+
+        public void setOpacity(int opacity) {
+            mOpacity = opacity;
         }
 
         protected void onBoundsChange(Rect bounds) {
diff --git a/tests/tests/graphics/src/android/graphics/drawable/cts/ScaleDrawableTest.java b/tests/tests/graphics/src/android/graphics/drawable/cts/ScaleDrawableTest.java
index 3d758fe..b58e40f 100644
--- a/tests/tests/graphics/src/android/graphics/drawable/cts/ScaleDrawableTest.java
+++ b/tests/tests/graphics/src/android/graphics/drawable/cts/ScaleDrawableTest.java
@@ -21,6 +21,7 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
+import java.util.Arrays;
 
 import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
@@ -28,6 +29,7 @@
 import android.graphics.ColorFilter;
 import android.graphics.Rect;
 import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ClipDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.Drawable.ConstantState;
 import android.graphics.drawable.ScaleDrawable;
@@ -275,19 +277,23 @@
     }
 
     public void testOnStateChange() {
-        MockDrawable mockDrawable = new MockDrawable();
-        MockScaleDrawable mockScaleDrawable = new MockScaleDrawable(
-                mockDrawable, Gravity.CENTER, 100, 200);
+        Drawable d = new MockDrawable();
+        MockScaleDrawable scaleDrawable = new MockScaleDrawable(d, Gravity.CENTER, 100, 200);
+        assertEquals("initial child state is empty", d.getState(), StateSet.WILD_CARD);
 
-        assertFalse(mockScaleDrawable.onStateChange(StateSet.WILD_CARD));
-        assertTrue(mockDrawable.hasCalledSetState());
-        assertTrue(mockScaleDrawable.hasCalledOnBoundsChange());
+        int[] state = new int[] {1, 2, 3};
+        assertFalse("child did not change", scaleDrawable.onStateChange(state));
+        assertEquals("child state did not change", d.getState(), StateSet.WILD_CARD);
 
-        mockDrawable.reset();
-        mockScaleDrawable.reset();
-        assertFalse(mockScaleDrawable.onStateChange(null));
-        assertTrue(mockDrawable.hasCalledSetState());
-        assertTrue(mockScaleDrawable.hasCalledOnBoundsChange());
+        d = mContext.getDrawable(R.drawable.statelistdrawable);
+        scaleDrawable = new MockScaleDrawable(d, Gravity.CENTER, 100, 200);
+        assertEquals("initial child state is empty", d.getState(), StateSet.WILD_CARD);
+        scaleDrawable.onStateChange(state);
+        assertTrue("child state changed", Arrays.equals(state, d.getState()));
+
+        // input null as param
+        scaleDrawable.onStateChange(null);
+        // expected, no Exception thrown out, test success
     }
 
     public void testOnLevelChange() {
@@ -413,25 +419,25 @@
         parser = res.getXml(R.xml.scaledrawable);
         attrs = DrawableTestUtils.getAttributeSet(parser, "scale_nodrawable");
         try {
-            scaleDrawable.inflate(res, parser, attrs);
-            fail("Should throw XmlPullParserException");
+            Drawable.createFromXmlInner(res, parser, attrs);
+            fail("Should throw XmlPullParserException if missing drawable");
         } catch (XmlPullParserException e) {
         }
 
         try {
-            scaleDrawable.inflate(null, parser, attrs);
+            Drawable.createFromXmlInner(null, parser, attrs);
             fail("Should throw NullPointerException if resource is null");
         } catch (NullPointerException e) {
         }
 
         try {
-            scaleDrawable.inflate(res, null, attrs);
+            Drawable.createFromXmlInner(res, null, attrs);
             fail("Should throw NullPointerException if parser is null");
         } catch (NullPointerException e) {
         }
 
         try {
-            scaleDrawable.inflate(res, parser, null);
+            Drawable.createFromXmlInner(res, parser, null);
             fail("Should throw NullPointerException if attribute set is null");
         } catch (NullPointerException e) {
         }
diff --git a/tests/tests/hardware/Android.mk b/tests/tests/hardware/Android.mk
index 1c144ff..9523d87 100644
--- a/tests/tests/hardware/Android.mk
+++ b/tests/tests/hardware/Android.mk
@@ -34,6 +34,7 @@
     src/android/hardware/cts/SensorIntegrationTests.java \
     src/android/hardware/cts/SensorBatchingTests.java \
     src/android/hardware/cts/SensorTest.java \
+    src/android/hardware/cts/SensorManagerStaticTest.java \
 
 LOCAL_STATIC_JAVA_LIBRARIES := ctsdeviceutil
 
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
index d39ff1f..423577e 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
@@ -32,7 +32,6 @@
 import android.hardware.camera2.params.InputConfiguration;
 import android.hardware.camera2.TotalCaptureResult;
 import android.hardware.cts.helpers.CameraUtils;
-import android.util.Size;
 import android.hardware.camera2.params.MeteringRectangle;
 import android.hardware.camera2.params.StreamConfigurationMap;
 import android.media.Image;
@@ -41,6 +40,8 @@
 import android.media.Image.Plane;
 import android.os.Handler;
 import android.util.Log;
+import android.util.Pair;
+import android.util.Size;
 import android.view.Surface;
 
 import com.android.ex.camera2.blocking.BlockingCameraManager;
@@ -313,12 +314,23 @@
     public static class SimpleCaptureCallback extends CameraCaptureSession.CaptureCallback {
         private final LinkedBlockingQueue<TotalCaptureResult> mQueue =
                 new LinkedBlockingQueue<TotalCaptureResult>();
+        private final LinkedBlockingQueue<CaptureFailure> mFailureQueue =
+                new LinkedBlockingQueue<>();
+        // Pair<CaptureRequest, Long> is a pair of capture request and timestamp.
+        private final LinkedBlockingQueue<Pair<CaptureRequest, Long>> mCaptureStartQueue =
+                new LinkedBlockingQueue<>();
+
         private AtomicLong mNumFramesArrived = new AtomicLong(0);
 
         @Override
         public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request,
-                long timestamp, long frameNumber)
-        {
+                long timestamp, long frameNumber) {
+            try {
+                mCaptureStartQueue.put(new Pair(request, timestamp));
+            } catch (InterruptedException e) {
+                throw new UnsupportedOperationException(
+                        "Can't handle InterruptedException in onCaptureStarted");
+            }
         }
 
         @Override
@@ -336,6 +348,12 @@
         @Override
         public void onCaptureFailed(CameraCaptureSession session, CaptureRequest request,
                 CaptureFailure failure) {
+            try {
+                mFailureQueue.put(failure);
+            } catch (InterruptedException e) {
+                throw new UnsupportedOperationException(
+                        "Can't handle InterruptedException in onCaptureFailed");
+            }
         }
 
         @Override
@@ -481,6 +499,66 @@
                     + "waiting for " + numResultsWait + " results");
         }
 
+        /**
+         * Get an array list of {@link #CaptureFailure capture failure} with maxNumFailures entries
+         * at most. If it times out before maxNumFailures failures are received, return the failures
+         * received so far.
+         *
+         * @param maxNumFailures The maximal number of failures to return. If it times out before
+         *                       the maximal number of failures are received, return the received
+         *                       failures so far.
+         * @throws UnsupportedOperationException If an error happens while waiting on the failure.
+         */
+        public ArrayList<CaptureFailure> getCaptureFailures(long maxNumFailures) {
+            ArrayList<CaptureFailure> failures = new ArrayList<>();
+            try {
+                for (int i = 0; i < maxNumFailures; i++) {
+                    CaptureFailure failure = mFailureQueue.poll(CAPTURE_RESULT_TIMEOUT_MS,
+                            TimeUnit.MILLISECONDS);
+                    if (failure == null) {
+                        // If waiting on a failure times out, return the failures so far.
+                        break;
+                    }
+                    failures.add(failure);
+                }
+            }  catch (InterruptedException e) {
+                throw new UnsupportedOperationException("Unhandled interrupted exception", e);
+            }
+
+            return failures;
+        }
+
+        /**
+         * Wait until the capture start of a request and expected timestamp arrives or it times
+         * out after a number of capture starts.
+         *
+         * @param request The request for the capture start to wait for.
+         * @param timestamp The timestamp for the capture start to wait for.
+         * @param numCaptureStartsWait The number of capture start events to wait for before timing
+         *                             out.
+         */
+        public void waitForCaptureStart(CaptureRequest request, Long timestamp,
+                int numCaptureStartsWait) throws Exception {
+            Pair<CaptureRequest, Long> expectedShutter = new Pair<>(request, timestamp);
+
+            int i = 0;
+            do {
+                Pair<CaptureRequest, Long> shutter = mCaptureStartQueue.poll(
+                        CAPTURE_RESULT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+
+                if (shutter == null) {
+                    throw new TimeoutRuntimeException("Unable to get any more capture start " +
+                            "event after waiting for " + CAPTURE_RESULT_TIMEOUT_MS + " ms.");
+                } else if (expectedShutter.equals(shutter)) {
+                    return;
+                }
+
+            } while (i++ < numCaptureStartsWait);
+
+            throw new TimeoutRuntimeException("Unable to get the expected capture start " +
+                    "event after waiting for " + numCaptureStartsWait + " capture starts");
+        }
+
         public boolean hasMoreResults()
         {
             return mQueue.isEmpty();
@@ -489,6 +567,8 @@
         public void drain() {
             mQueue.clear();
             mNumFramesArrived.getAndSet(0);
+            mFailureQueue.clear();
+            mCaptureStartQueue.clear();
         }
     }
 
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
index f3acf4c..42da12e 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CaptureRequestTest.java
@@ -188,45 +188,61 @@
                 openDevice(mCameraIds[i]);
 
                 if (!mStaticInfo.isManualLensShadingMapSupported()) {
+                    Log.i(TAG, "Camera " + mCameraIds[i] +
+                            " doesn't support lens shading controls, skipping test");
+                    continue;
+                }
+
+                List<Integer> lensShadingMapModes = Arrays.asList(CameraTestUtils.toObject(
+                        mStaticInfo.getAvailableLensShadingMapModesChecked()));
+
+                if (!lensShadingMapModes.contains(STATISTICS_LENS_SHADING_MAP_MODE_ON)) {
                     continue;
                 }
 
                 SimpleCaptureCallback listener = new SimpleCaptureCallback();
                 CaptureRequest.Builder requestBuilder =
                         mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
-
-                // Shading map mode OFF, lensShadingMapMode ON, camera device
-                // should output unity maps.
-                requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_OFF);
                 requestBuilder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE,
                         STATISTICS_LENS_SHADING_MAP_MODE_ON);
 
                 Size previewSz =
                         getMaxPreviewSize(mCamera.getId(), mCameraManager, PREVIEW_SIZE_BOUND);
+                List<Integer> lensShadingModes = Arrays.asList(CameraTestUtils.toObject(
+                        mStaticInfo.getAvailableLensShadingModesChecked()));
 
-                listener = new SimpleCaptureCallback();
-                startPreview(requestBuilder, previewSz, listener);
-                waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
-                verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_OFF);
+                // Shading map mode OFF, lensShadingMapMode ON, camera device
+                // should output unity maps.
+                if (lensShadingModes.contains(SHADING_MODE_OFF)) {
+                    requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_OFF);
+                    listener = new SimpleCaptureCallback();
+                    startPreview(requestBuilder, previewSz, listener);
+                    waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
+                    verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_OFF);
+                }
 
                 // Shading map mode FAST, lensShadingMapMode ON, camera device
                 // should output valid maps.
-                requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_FAST);
+                if (lensShadingModes.contains(SHADING_MODE_FAST)) {
+                    requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_FAST);
 
-                listener = new SimpleCaptureCallback();
-                startPreview(requestBuilder, previewSz, listener);
-                waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
-                // Allow at most one lock OFF state as the exposure is changed once.
-                verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_FAST);
+                    listener = new SimpleCaptureCallback();
+                    startPreview(requestBuilder, previewSz, listener);
+                    waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
+                    // Allow at most one lock OFF state as the exposure is changed once.
+                    verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_FAST);
+                }
 
                 // Shading map mode HIGH_QUALITY, lensShadingMapMode ON, camera device
                 // should output valid maps.
-                requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_HIGH_QUALITY);
+                if (lensShadingModes.contains(SHADING_MODE_HIGH_QUALITY)) {
+                    requestBuilder.set(CaptureRequest.SHADING_MODE, SHADING_MODE_HIGH_QUALITY);
 
-                listener = new SimpleCaptureCallback();
-                startPreview(requestBuilder, previewSz, listener);
-                waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
-                verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_HIGH_QUALITY);
+                    listener = new SimpleCaptureCallback();
+                    startPreview(requestBuilder, previewSz, listener);
+                    waitForSettingsApplied(listener, NUM_FRAMES_WAITED_FOR_UNKNOWN_LATENCY);
+                    verifyShadingMap(listener, NUM_FRAMES_VERIFIED, SHADING_MODE_HIGH_QUALITY);
+                }
 
                 stopPreview();
             } finally {
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
index 38332a1..04375cb 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
@@ -259,8 +259,10 @@
                 expectKeyAvailable(c, CameraCharacteristics.SENSOR_ORIENTATION                              , LEGACY   ,   BC                   );
                 expectKeyAvailable(c, CameraCharacteristics.SENSOR_REFERENCE_ILLUMINANT1                    , OPT      ,   RAW                  );
                 expectKeyAvailable(c, CameraCharacteristics.SENSOR_REFERENCE_ILLUMINANT2                    , OPT      ,   RAW                  );
+                expectKeyAvailable(c, CameraCharacteristics.SHADING_AVAILABLE_MODES                         , LIMITED  ,   MANUAL_POSTPROC, RAW );
                 expectKeyAvailable(c, CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES     , LEGACY   ,   BC                   );
                 expectKeyAvailable(c, CameraCharacteristics.STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES   , OPT      ,   RAW                  );
+                expectKeyAvailable(c, CameraCharacteristics.STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, LIMITED  ,   RAW                  );
                 expectKeyAvailable(c, CameraCharacteristics.STATISTICS_INFO_MAX_FACE_COUNT                  , LEGACY   ,   BC                   );
                 expectKeyAvailable(c, CameraCharacteristics.SYNC_MAX_LATENCY                                , LEGACY   ,   BC                   );
                 expectKeyAvailable(c, CameraCharacteristics.TONEMAP_AVAILABLE_TONE_MAP_MODES                , FULL     ,   MANUAL_POSTPROC      );
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java b/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
index 94cbbf7..a115fbe 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/ReprocessCaptureTest.java
@@ -24,6 +24,7 @@
 import android.media.ImageWriter;
 import android.hardware.camera2.CameraCharacteristics;
 import android.hardware.camera2.CameraDevice;
+import android.hardware.camera2.CaptureFailure;
 import android.hardware.camera2.CaptureRequest;
 import android.hardware.camera2.CaptureResult;
 import android.hardware.camera2.TotalCaptureResult;
@@ -75,7 +76,9 @@
     private enum CaptureTestCase {
         SINGLE_SHOT,
         BURST,
-        MIXED_BURST
+        MIXED_BURST,
+        ABORT_CAPTURE,
+        TIMESTAMPS
     }
 
     /**
@@ -334,26 +337,109 @@
     }
 
     /**
+     * Test aborting reprocess capture requests of the largest input and output sizes for each
+     * supported format.
+     */
+    public void testReprocessAbort() throws Exception {
+        for (String id : mCameraIds) {
+            if (!isYuvReprocessSupported(id) && !isOpaqueReprocessSupported(id)) {
+                continue;
+            }
+
+            try {
+                // open Camera device
+                openDevice(id);
+
+                int[] supportedInputFormats =
+                    mStaticInfo.getAvailableFormats(StaticMetadata.StreamDirection.Input);
+                for (int inputFormat : supportedInputFormats) {
+                    int[] supportedReprocessOutputFormats =
+                            mStaticInfo.getValidOutputFormatsForInput(inputFormat);
+                    for (int reprocessOutputFormat : supportedReprocessOutputFormats) {
+                        testReprocessingMaxSizes(id, inputFormat, reprocessOutputFormat,
+                                /*previewSize*/null, CaptureTestCase.ABORT_CAPTURE);
+                    }
+                }
+            } finally {
+                closeDevice();
+            }
+        }
+    }
+
+    /**
+     * Test reprocess timestamps for the largest input and output sizes for each supported format.
+     */
+    public void testReprocessTimestamps() throws Exception {
+        for (String id : mCameraIds) {
+            if (!isYuvReprocessSupported(id) && !isOpaqueReprocessSupported(id)) {
+                continue;
+            }
+
+            try {
+                // open Camera device
+                openDevice(id);
+
+                int[] supportedInputFormats =
+                    mStaticInfo.getAvailableFormats(StaticMetadata.StreamDirection.Input);
+                for (int inputFormat : supportedInputFormats) {
+                    int[] supportedReprocessOutputFormats =
+                            mStaticInfo.getValidOutputFormatsForInput(inputFormat);
+                    for (int reprocessOutputFormat : supportedReprocessOutputFormats) {
+                        testReprocessingMaxSizes(id, inputFormat, reprocessOutputFormat,
+                                /*previewSize*/null, CaptureTestCase.TIMESTAMPS);
+                    }
+                }
+            } finally {
+                closeDevice();
+            }
+        }
+    }
+
+    /**
      * Test the input format and output format with the largest input and output sizes.
      */
-    private void testBasicReprocessing(String cameraId, int inputFormat, int reprocessOutputFormat)
-            throws Exception {
+    private void testBasicReprocessing(String cameraId, int inputFormat,
+            int reprocessOutputFormat) throws Exception {
         try {
             openDevice(cameraId);
 
-            Size maxInputSize =
-                    getMaxSize(inputFormat, StaticMetadata.StreamDirection.Input);
-            Size maxReprocessOutputSize =
-                    getMaxSize(reprocessOutputFormat, StaticMetadata.StreamDirection.Output);
-
-            testReprocess(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize,
-                    reprocessOutputFormat, /* previewSize */null, /*numReprocessCaptures*/1);
+            testReprocessingMaxSizes(cameraId, inputFormat, reprocessOutputFormat,
+                    /* previewSize */null, CaptureTestCase.SINGLE_SHOT);
         } finally {
             closeDevice();
         }
     }
 
     /**
+     * Test the input format and output format with the largest input and output sizes for a
+     * certain test case.
+     */
+    private void testReprocessingMaxSizes(String cameraId, int inputFormat,
+            int reprocessOutputFormat, Size previewSize, CaptureTestCase captureTestCase)
+            throws Exception {
+        Size maxInputSize = getMaxSize(inputFormat, StaticMetadata.StreamDirection.Input);
+        Size maxReprocessOutputSize =
+                getMaxSize(reprocessOutputFormat, StaticMetadata.StreamDirection.Output);
+
+        switch (captureTestCase) {
+            case SINGLE_SHOT:
+                testReprocess(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize,
+                        reprocessOutputFormat, previewSize, NUM_REPROCESS_CAPTURES);
+                break;
+            case ABORT_CAPTURE:
+                testReprocessAbort(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize,
+                        reprocessOutputFormat);
+                break;
+            case TIMESTAMPS:
+                testReprocessTimestamps(cameraId, maxInputSize, inputFormat, maxReprocessOutputSize,
+                        reprocessOutputFormat);
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid test case");
+        }
+    }
+
+    /**
      * Test all input format, input size, output format, and output size combinations.
      */
     private void testReprocessingAllCombinations(String cameraId, Size previewSize,
@@ -393,7 +479,7 @@
                                         NUM_REPROCESS_BURST);
                                 break;
                             default:
-                                throw new IllegalArgumentException("Invalid capture type");
+                                throw new IllegalArgumentException("Invalid test case");
                         }
                     }
                 }
@@ -597,6 +683,182 @@
     }
 
     /**
+     * Test aborting a burst reprocess capture and multiple single reprocess captures.
+     */
+    private void testReprocessAbort(String cameraId, Size inputSize, int inputFormat,
+            Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
+        if (VERBOSE) {
+            Log.v(TAG, "testReprocessAbort: cameraId: " + cameraId + " inputSize: " +
+                    inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " +
+                    reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
+        }
+
+        try {
+            setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat,
+                    NUM_REPROCESS_CAPTURES);
+            setupReprocessableSession(/*previewSurface*/null, NUM_REPROCESS_CAPTURES);
+
+            // Test two cases: submitting reprocess requests one by one and in a burst.
+            boolean submitInBursts[] = {false, true};
+            for (boolean submitInBurst : submitInBursts) {
+                // Prepare reprocess capture requests.
+                ArrayList<CaptureRequest> reprocessRequests =
+                        new ArrayList<>(NUM_REPROCESS_CAPTURES);
+
+                for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
+                    TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(),
+                            /*inputResult*/null);
+
+                    mImageWriter.queueInputImage(
+                            mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
+                    CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
+                    if (mShareOneImageReader) {
+                        builder.addTarget(mFirstImageReader.getSurface());
+                    } else {
+                        builder.addTarget(mSecondImageReader.getSurface());
+                    }
+                    reprocessRequests.add(builder.build());
+                }
+
+                SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
+
+                // Submit reprocess capture requests.
+                if (submitInBurst) {
+                    mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
+                } else {
+                    for (CaptureRequest request : reprocessRequests) {
+                        mSession.capture(request, captureCallback, mHandler);
+                    }
+                }
+
+                // Abort after getting the first result
+                TotalCaptureResult reprocessResult =
+                        captureCallback.getTotalCaptureResultForRequest(reprocessRequests.get(0),
+                        CAPTURE_TIMEOUT_FRAMES);
+                mSession.abortCaptures();
+
+                // Wait until the session is ready again.
+                mSessionListener.getStateWaiter().waitForState(
+                        BlockingSessionCallback.SESSION_READY, SESSION_CLOSE_TIMEOUT_MS);
+
+                // Gather all failed requests.
+                ArrayList<CaptureFailure> failures =
+                        captureCallback.getCaptureFailures(NUM_REPROCESS_CAPTURES - 1);
+                ArrayList<CaptureRequest> failedRequests = new ArrayList<>();
+                for (CaptureFailure failure : failures) {
+                    failedRequests.add(failure.getRequest());
+                }
+
+                // For each request that didn't fail must have a valid result.
+                for (int i = 1; i < reprocessRequests.size(); i++) {
+                    CaptureRequest request = reprocessRequests.get(i);
+                    if (!failedRequests.contains(request)) {
+                        captureCallback.getTotalCaptureResultForRequest(request,
+                                CAPTURE_TIMEOUT_FRAMES);
+                    }
+                }
+
+                // Drain the image reader listeners.
+                mFirstImageReaderListener.drain();
+                if (!mShareOneImageReader) {
+                    mSecondImageReaderListener.drain();
+                }
+
+                // Make sure all input surfaces are released.
+                for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
+                    mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
+                }
+            }
+        } finally {
+            closeReprossibleSession();
+            closeImageReaders();
+        }
+    }
+
+    /**
+     * Test timestamps for reprocess requests. Reprocess request's shutter timestamp, result's
+     * sensor timestamp, and output image's timestamp should match the reprocess input's timestamp.
+     */
+    private void testReprocessTimestamps(String cameraId, Size inputSize, int inputFormat,
+            Size reprocessOutputSize, int reprocessOutputFormat) throws Exception {
+        if (VERBOSE) {
+            Log.v(TAG, "testReprocessTimestamps: cameraId: " + cameraId + " inputSize: " +
+                    inputSize + " inputFormat: " + inputFormat + " reprocessOutputSize: " +
+                    reprocessOutputSize + " reprocessOutputFormat: " + reprocessOutputFormat);
+        }
+
+        try {
+            setupImageReaders(inputSize, inputFormat, reprocessOutputSize, reprocessOutputFormat,
+                    NUM_REPROCESS_CAPTURES);
+            setupReprocessableSession(/*previewSurface*/null, NUM_REPROCESS_CAPTURES);
+
+            // Prepare reprocess capture requests.
+            ArrayList<CaptureRequest> reprocessRequests = new ArrayList<>(NUM_REPROCESS_CAPTURES);
+            ArrayList<Long> expectedTimestamps = new ArrayList<>(NUM_REPROCESS_CAPTURES);
+
+            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
+                TotalCaptureResult result = submitCaptureRequest(mFirstImageReader.getSurface(),
+                        /*inputResult*/null);
+
+                mImageWriter.queueInputImage(
+                        mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS));
+                CaptureRequest.Builder builder = mCamera.createReprocessCaptureRequest(result);
+                if (mShareOneImageReader) {
+                    builder.addTarget(mFirstImageReader.getSurface());
+                } else {
+                    builder.addTarget(mSecondImageReader.getSurface());
+                }
+                reprocessRequests.add(builder.build());
+                // Reprocess result's timestamp should match input image's timestamp.
+                expectedTimestamps.add(result.get(CaptureResult.SENSOR_TIMESTAMP));
+            }
+
+            // Submit reprocess requests.
+            SimpleCaptureCallback captureCallback = new SimpleCaptureCallback();
+            mSession.captureBurst(reprocessRequests, captureCallback, mHandler);
+
+            // Verify we get the expected timestamps.
+            for (int i = 0; i < reprocessRequests.size(); i++) {
+                captureCallback.waitForCaptureStart(reprocessRequests.get(i),
+                        expectedTimestamps.get(i), CAPTURE_TIMEOUT_FRAMES);
+            }
+
+            TotalCaptureResult[] reprocessResults =
+                    captureCallback.getTotalCaptureResultsForRequests(reprocessRequests,
+                    CAPTURE_TIMEOUT_FRAMES);
+
+            for (int i = 0; i < expectedTimestamps.size(); i++) {
+                // Verify the result timestamps match the input image's timestamps.
+                long expected = expectedTimestamps.get(i);
+                long timestamp = reprocessResults[i].get(CaptureResult.SENSOR_TIMESTAMP);
+                assertEquals("Reprocess result timestamp (" + timestamp + ") doesn't match input " +
+                        "image's timestamp (" + expected + ")", expected, timestamp);
+
+                // Verify the reprocess output image timestamps match the input image's timestamps.
+                Image image;
+                if (mShareOneImageReader) {
+                    image = mFirstImageReaderListener.getImage(CAPTURE_TIMEOUT_MS);
+                } else {
+                    image = mSecondImageReaderListener.getImage(CAPTURE_TIMEOUT_MS);
+                }
+                timestamp = image.getTimestamp();
+                image.close();
+
+                assertEquals("Reprocess output timestamp (" + timestamp + ") doesn't match input " +
+                        "image's timestamp (" + expected + ")", expected, timestamp);
+            }
+
+            // Make sure all input surfaces are released.
+            for (int i = 0; i < NUM_REPROCESS_CAPTURES; i++) {
+                mImageWriterListener.waitForImageReleased(CAPTURE_TIMEOUT_MS);
+            }
+        } finally {
+            closeReprossibleSession();
+            closeImageReaders();
+        }
+    }
+
+    /**
      * Set up two image readers: one for regular capture (used for reprocess input) and one for
      * reprocess capture.
      */
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/helpers/StaticMetadata.java b/tests/tests/hardware/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
index b63541b..36fedae 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
@@ -1655,6 +1655,52 @@
     }
 
     /**
+     * Get available lens shading modes.
+     */
+     public int[] getAvailableLensShadingModesChecked() {
+         Key<int[]> key =
+                 CameraCharacteristics.SHADING_AVAILABLE_MODES;
+         int[] modes = getValueFromKeyNonNull(key);
+         if (modes == null) {
+             return new int[0];
+         }
+
+         List<Integer> modeList = Arrays.asList(CameraTestUtils.toObject(modes));
+         // FAST must be included.
+         checkTrueForKey(key, " FAST must be included",
+                 modeList.contains(CameraMetadata.SHADING_MODE_FAST));
+
+         if (isCapabilitySupported(
+                 CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING)) {
+             checkTrueForKey(key, " OFF must be included for MANUAL_POST_PROCESSING devices",
+                     modeList.contains(CameraMetadata.SHADING_MODE_OFF));
+         }
+         return modes;
+     }
+
+     /**
+      * Get available lens shading map modes.
+      */
+      public int[] getAvailableLensShadingMapModesChecked() {
+          Key<int[]> key =
+                  CameraCharacteristics.STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES;
+          int[] modes = getValueFromKeyNonNull(key);
+          if (modes == null) {
+              return new int[0];
+          }
+
+          List<Integer> modeList = Arrays.asList(CameraTestUtils.toObject(modes));
+
+          if (isCapabilitySupported(
+                  CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_RAW)) {
+              checkTrueForKey(key, " ON must be included for RAW capability devices",
+                      modeList.contains(CameraMetadata.STATISTICS_LENS_SHADING_MAP_MODE_ON));
+          }
+          return modes;
+      }
+
+
+    /**
      * Get available capabilities and do the sanity check.
      *
      * @return reported available capabilities list, empty list if the value is unavailable.
diff --git a/tests/tests/hardware/src/android/hardware/camera2/cts/rs/raw_converter.rs b/tests/tests/hardware/src/android/hardware/camera2/cts/rs/raw_converter.rs
index c8b353e..fb467bb 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/rs/raw_converter.rs
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/rs/raw_converter.rs
@@ -169,6 +169,9 @@
         case 4: // impossible
         case 5: // impossible
         default:
+            finalRGB.x = 0.f;
+            finalRGB.y = 0.f;
+            finalRGB.z = 0.f;
             LOGD("raw_converter.rs: Logic error in tonemap.", 0);
             break;
     }
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorManagerStaticTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorManagerStaticTest.java
new file mode 100644
index 0000000..11ac701
--- /dev/null
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorManagerStaticTest.java
@@ -0,0 +1,776 @@
+/*
+ * 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.hardware.cts;
+
+import junit.framework.Assert;
+
+import android.content.Context;
+import android.hardware.SensorManager;
+import android.os.PowerManager;
+
+import java.util.Random;
+
+public class SensorManagerStaticTest extends SensorTestCase {
+    private static final String TAG = "SensorManagerTest";
+
+    // local float version of PI
+    private static final float FLOAT_PI = (float) Math.PI;
+
+
+    private PowerManager.WakeLock mWakeLock;
+
+    @Override
+    protected void setUp() throws Exception {
+        Context context = getContext();
+        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
+        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
+
+        mWakeLock.acquire();
+    }
+
+    @Override
+    protected void tearDown(){
+        if (mWakeLock != null && mWakeLock.isHeld()) {
+            mWakeLock.release();
+        }
+    }
+
+    // SensorManager Tests
+    public void testGetAltitude() throws Exception {
+        float r, q;
+        float altitude;
+
+        // identity property
+        for (r = 0.5f; r < 1.3f; r += 0.1f) {
+
+            altitude = SensorManager.getAltitude(r * SensorManager.PRESSURE_STANDARD_ATMOSPHERE,
+                                                 r * SensorManager.PRESSURE_STANDARD_ATMOSPHERE);
+            assertRoughlyEqual("getAltitude identity property violated.", altitude, 0.0f, 0.1f);
+        }
+
+        // uniform increasing as pressure decreases property
+        float prevAltitude = 1e5f; // 100km ceiling
+        for (r = 0.5f; r < 1.3f; r += 0.01f) {
+            altitude = SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE,
+                                                 r * SensorManager.PRESSURE_STANDARD_ATMOSPHERE);
+
+            assertTrue("getAltitude result has to decrease as p increase.", prevAltitude > altitude);
+            prevAltitude = altitude;
+        }
+
+        // compare to a reference algorithm
+        final float coef = 1.0f / 5.255f;
+        for (r = 0.8f; r < 1.3f; r += 0.1f) {
+            for (q = 1.1f * r; q > 0.5f * r; q -= 0.1f * r) {
+                float p0 = r * SensorManager.PRESSURE_STANDARD_ATMOSPHERE;
+                float p  = q * SensorManager.PRESSURE_STANDARD_ATMOSPHERE;
+
+                float t1 = SensorManager.getAltitude(p0, p);
+                float t2 = 44330.f*(1.0f- (float) Math.pow(p/p0, coef));
+
+                assertRoughlyEqual(
+                      String.format("getAltitude comparing to reference algorithm failed. " +
+                          "Detail: getAltitude(%f, %f) => %f, reference => %f",
+                          p0, p, t1, t2),
+                      t1, t2, 100.f);
+            }
+        }
+
+    }
+
+    public void testGetAngleChange() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i;
+        float [] rotv = new float[3];
+        float [] rotv2 = new float[3];
+
+        // test many instances
+        for (i=0; i<100; ++i) {
+            float [] R1, R12, R2;
+            // azimuth(yaw) pitch roll
+            data.nextRotationAngles(rotv);
+            R1 = mat9VRot(rotv); // random base
+
+            // azimuth(yaw) pitch roll
+            data.nextRotationAngles(rotv);
+            R12 = mat9VRot(rotv);
+            R2 = mat9Mul(R1, R12); // apply another random rotation
+
+            // test different variations of input matrix format
+            switch(i & 3) {
+                case 0:
+                    SensorManager.getAngleChange(rotv2, R2, R1);
+                    break;
+                case 1:
+                    SensorManager.getAngleChange(rotv2, mat9to16(R2), R1);
+                    break;
+                case 2:
+                    SensorManager.getAngleChange(rotv2, R2, mat9to16(R1));
+                    break;
+                case 3:
+                    SensorManager.getAngleChange(rotv2, mat9to16(R2), mat9to16(R1));
+                    break;
+            }
+
+            // check range
+            assertRotationAnglesValid("getAngleChange result out of range.", rotv2);
+
+            // avoid directly checking the rotation angles to avoid corner cases
+            float [] R12rt = mat9T(mat9VRot(rotv2));
+            float [] RI = mat9Mul(R12rt, R12);
+
+            assertRoughlyEqual(
+                String.format("getAngleChange result is incorrect. Details: case %d, " +
+                    "truth = [%f, %f, %f], result = [%f, %f, %f]", i, rotv[0], rotv[1], rotv[2],
+                    rotv2[0], rotv2[1], rotv2[2]),
+                RI[0] + RI[4] + RI[8], 3.f, 1e-4f);
+        }
+    }
+
+    public void testGetInclination() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i;
+        float [] rotv = new float[3];
+        float [] rotv2 = new float[3];
+        float [] rotv3;
+
+        // test many instances
+        for (i = 0; i < 100; ++i) {
+            float [] R;
+            float angle;
+            angle = (data.nextFloat()-0.5f) * FLOAT_PI;
+            R = mat9Rot(SensorManager.AXIS_X, -angle);
+
+            float angler = ((i&1) != 0) ?
+                    SensorManager.getInclination(mat9to16(R)) : SensorManager.getInclination(R);
+            assertRoughlyEqual(
+                String.format(
+                    "getInclination return incorrect result. Detail: case %d, truth %f, result %f.",
+                    i, angle, angler),
+                angle, angler, 1e-4f);
+        }
+    }
+
+    public void testGetOrientation() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i;
+        float [] rotv = new float[3];
+        float [] rotv2 = new float[3];
+        float [] rotv3;
+
+        // test many instances
+        for (i=0; i<100; ++i) {
+            float [] R;
+            // yaw pitch roll
+            data.nextRotationAngles(rotv);
+            R = mat9VRot(rotv);
+
+            rotv3 = SensorManager.getOrientation( ((i&1) != 0) ? R : mat9to16(R), rotv2);
+            assertTrue("getOrientaion has to return the array passed in argument", rotv3 == rotv2);
+
+            // check range
+            assertRotationAnglesValid("getOrientation result out of range.", rotv2);
+
+            // Avoid directly comparing rotation angles. Instead, compare the rotation matrix.
+            float [] Rr = mat9T(mat9VRot(rotv2));
+            float [] RI = mat9Mul(Rr, R);
+
+            assertRoughlyEqual(
+                String.format("getOrientation result is incorrect. Details: case %d, " +
+                    "truth = [%f, %f, %f], result = [%f, %f, %f]", i, rotv[0], rotv[1], rotv[2],
+                    rotv2[0], rotv2[1], rotv2[2]),
+                RI[0] + RI[4] + RI[8], 3.f, 1e-4f);
+        }
+    }
+
+    public void testGetQuaternionFromVector() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i;
+        float [] v;
+        float [] q = new float[4];
+        float [] q2 = new float[4];
+        float [] v3 = new float[3];
+        float [] v4 = new float[4];
+        float [] v5 = new float[5];
+        float [][] vs = new float[][] {v3, v4, v5};
+
+        float [] xyzth = new float[4];
+        for (i = 0; i < 100; ++i) {
+            float c, s;
+
+            data.nextRotationAxisAngle(xyzth);
+
+            c = (float) Math.cos(xyzth[3]);
+            s = (float) Math.sin(xyzth[3]);
+            if (c < 0.f) {
+                c = -c;
+                s = -s;
+            }
+
+            v = vs[i%3];
+            switch(i%3) {
+                case 2:
+                    v[4] = data.nextBoolean() ? data.nextFloat() : -1.f;
+                case 1:
+                    v[3] = c;
+                case 0:
+                    v[0] = s * xyzth[0];
+                    v[1] = s * xyzth[1];
+                    v[2] = s * xyzth[2];
+            }
+
+            q2[0] = c;
+            q2[1] = v[0];
+            q2[2] = v[1];
+            q2[3] = v[2];
+
+            SensorManager.getQuaternionFromVector(q, v);
+            assertVectorRoughlyEqual(
+                String.format("getQuaternionFromVector returns wrong results, Details: case %d, " +
+                    "truth = (%f, %f, %f, %f), result = (%f, %f, %f, %f).",
+                    i, q2[0], q2[1], q2[2], q2[3], q[0], q[1], q[2], q[3]),
+                q, q2, 1e-4f);
+        }
+    }
+
+    public void testGetRotationMatrix() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+        final float gravity = 9.81f;
+        final float magStrength = 50.f;
+
+        int i;
+        float [] gm = new float[9];
+        float [] rotv = new float[3];
+        float [] gI = null;
+        float [] mI = null;
+        float [] Rr = new float[9];
+        float [] Ir = new float[9];
+
+        gm[6] = gravity; // m/s^2, first column gravity
+
+        // test many instances
+        for (i=0; i<100; ++i) {
+            float [] Rt;
+            float incline;
+            // yaw pitch roll
+            data.nextRotationAngles(rotv);
+            Rt = mat9T(mat9VRot(rotv)); // from world frame to phone frame
+            //Rt = mat9I();
+
+            incline = -0.9f * (data.nextFloat() - 0.5f) * FLOAT_PI; // ~ +-80 degrees
+            //incline = 0.f;
+            gm[4] = magStrength * (float) Math.cos(-incline); // positive means rotate downwards
+            gm[7] = magStrength * (float) Math.sin(-incline);
+
+            float [] gmb = mat9Mul(Rt, gm); // do not care about right most column
+            gI = mat9Axis(gmb, SensorManager.AXIS_X);
+            mI = mat9Axis(gmb, SensorManager.AXIS_Y);
+
+            assertTrue("getRotationMatrix returns false on valid inputs",
+                SensorManager.getRotationMatrix(Rr, Ir, gI, mI));
+
+            float [] n = mat9Mul(Rr, Rt);
+            assertRoughlyEqual(
+                String.format("getRotationMatrix returns incorrect R matrix. " +
+                    "Details: case %d, truth R = %s, result R = %s.",
+                    i, mat9ToStr(mat9T(Rt)), mat9ToStr(Rr)),
+                n[0] + n[4] + n[8], 3.f, 1e-4f);
+
+
+            // Magnetic incline is defined so that it means the magnetic field lines is formed
+            // by rotate local y axis around -x axis by incline angle. However, I matrix is
+            // defined as (according to document):
+            //     [0 m 0] = I * R * geomagnetic,
+            // which means,
+            //     I' * [0 m 0] = R * geomagnetic.
+            // Thus, I' = Rot(-x, incline) and I = Rot(-x, incline)' = Rot(x, incline)
+            float [] Ix = mat9Rot(SensorManager.AXIS_X, incline);
+            assertVectorRoughlyEqual(
+                String.format("getRotationMatrix returns incorrect I matrix. " +
+                    "Details: case %d, truth I = %s, result I = %s.",
+                    i, mat9ToStr(Ix), mat9ToStr(Ir)),
+                Ix, Ir, 1e-4f);
+        }
+
+        // test 16 element inputs
+        float [] Rr2 = new float[16];
+        float [] Ir2 = new float[16];
+
+        assertTrue("getRotationMatrix returns false on valid inputs",
+            SensorManager.getRotationMatrix(Rr2, Ir2, gI, mI));
+
+        assertVectorRoughlyEqual(
+            "getRotationMatrix acts inconsistent with 9- and 16- elements matrix buffer",
+            mat16to9(Rr2), Rr, 1e-4f);
+
+        assertVectorRoughlyEqual(
+            "getRotationMatrix acts inconsistent with 9- and 16- elements matrix buffer",
+            mat16to9(Ir2), Ir, 1e-4f);
+
+        // test null inputs
+        assertTrue("getRotationMatrix does not handle null inputs",
+            SensorManager.getRotationMatrix(Rr, null, gI, mI));
+
+        assertTrue("getRotationMatrix does not handle null inputs",
+            SensorManager.getRotationMatrix(null, Ir, gI, mI));
+
+        assertTrue("getRotationMatrix does not handle null inputs",
+            SensorManager.getRotationMatrix(null, null, gI, mI));
+
+        // test fail cases
+        // free fall, if the acc reading is less than 10% of gravity
+        gI[0] = gI[1] = gI[2] = data.nextFloat() * gravity * 0.05f; // sqrt(3) * 0.05 < 0.1
+         assertFalse("getRotationMatrix does not fail when it supposed to fail (gravity too small)",
+            SensorManager.getRotationMatrix(Rr, Ir, gI, mI));
+
+        // wrong input
+        assertFalse("getRotationMatrix does not fail when it supposed to fail (singular axis)",
+            SensorManager.getRotationMatrix(Rr, Ir, gI, gI));
+    }
+
+    public void testGetRotationMatrixFromVector() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i;
+        float [] v;
+        float [] q = new float[4];
+
+        float [] v3 = new float[3];
+        float [] v4 = new float[4];
+        float [] v5 = new float[5];
+        float [][] vs = new float[][]{v3, v4, v5};
+
+        float [] m9 = new float[9];
+        float [] m16 = new float[16];
+
+        // format: x y z theta/2
+        float [] xyzth = new float[4];
+        // test the orthogonal property of returned matrix
+        for (i=0; i<20; ++i) {
+            float c, s;
+            data.nextRotationAxisAngle(xyzth);
+
+            c = (float) Math.cos(xyzth[3]);
+            s = (float) Math.sin(xyzth[3]);
+            if (c < 0.f) {
+                c = -c;
+                s = -s;
+            }
+
+            v = vs[i%3];
+            switch(i%3) {
+                case 2:
+                    v[4] = data.nextBoolean() ? data.nextFloat() : -1.f;
+                case 1:
+                    v[3] = c;
+                case 0:
+                    v[0] = s * xyzth[0];
+                    v[1] = s * xyzth[1];
+                    v[2] = s * xyzth[2];
+            }
+
+            if ((i % 1) != 0) {
+                SensorManager.getRotationMatrixFromVector(m16, v);
+                m9 = mat16to9(m16);
+            }else {
+                SensorManager.getRotationMatrixFromVector(m9, v);
+            }
+
+            float [] n = mat9Mul(m9, mat9T(m9));
+            assertRoughlyEqual("getRotationMatrixFromVector do not return proper matrix",
+                    n[0]+ n[4] + n[8], 3.f, 1e-4f);
+        }
+
+        // test if multiple rotation (total 2pi) about an axis result in identity
+        v = v3;
+        float [] Rr = new float[9];
+
+        for (i=0; i<20; ++i) {
+            float j, halfTheta, residualHalfTheta = FLOAT_PI;
+            float [] R = mat9I();
+            float c, s;
+
+            data.nextRotationAxisAngle(xyzth);  // half theta is ignored
+
+            j = data.nextInt(5) + 2;  // 2 ~ 6 rotations
+
+            while(j-- > 0) {
+                if (j == 0) {
+                    halfTheta = residualHalfTheta;
+                } else {
+                    halfTheta = data.nextFloat() * FLOAT_PI;
+                }
+
+                c = (float) Math.cos(halfTheta);
+                s = (float) Math.sin(halfTheta);
+                if (c < 0.f) {
+                    c = -c;
+                    s = -s;
+                }
+
+                v[0] = s * xyzth[0];
+                v[1] = s * xyzth[1];
+                v[2] = s * xyzth[2];
+
+                SensorManager.getRotationMatrixFromVector(Rr, v);
+                R = mat9Mul(Rr, R);
+
+                residualHalfTheta -= halfTheta;
+            }
+
+            assertRoughlyEqual("getRotationMatrixFromVector returns incorrect matrix",
+                    R[0] + R[4] + R[8], 3.f, 1e-4f);
+        }
+
+        // test if rotation about trival axis works
+        v = v3;
+        for (i=0; i<20; ++i) {
+            int axis = (i % 3) + 1;
+            float theta = data.nextFloat() * 2.f * FLOAT_PI;
+            float [] R;
+
+            v[0] = v[1] = v[2] = 0.f;
+            v[axis - 1] = (float) Math.sin(theta / 2.f);
+            if ( (float) Math.cos(theta / 2.f) < 0.f) {
+                v[axis-1] = -v[axis-1];
+            }
+
+            SensorManager.getRotationMatrixFromVector(m9, v);
+            R = mat9Rot(axis, theta);
+
+            assertVectorRoughlyEqual(
+                String.format("getRotationMatrixFromVector returns incorrect matrix with "+
+                    "simple rotation. Details: case %d, truth R = %s, result R = %s.",
+                    i, mat9ToStr(R), mat9ToStr(m9)),
+                R, m9, 1e-4f);
+        }
+    }
+
+    public void testRemapCoordinateSystem() throws Exception {
+        TestDataGenerator data = new TestDataGenerator();
+
+        int i, j, k;
+        float [] rotv = new float[3];
+        float [] Rout = new float[9];
+        float [] Rout2 = new float[16];
+        int a1, a2; // AXIS_X/Y/Z
+        int b1, b2, b3; // AXIS_X/Y/Z w/ or w/o MINUS
+
+        // test a few instances
+        for (i=0; i<10; ++i) {
+            float [] R;
+            // yaw pitch roll
+            data.nextRotationAngles(rotv);
+            R = mat9VRot(rotv);
+
+            // total of 6*4 = 24 variations
+            // 6 = A(3,2)
+            for (j=0; j<9; ++j) {
+                // axis without minus
+                a1 = j/3 + 1;
+                a2 = j%3 + 1;
+
+                // skip cases when two axis are the same
+                if (a1 == a2) continue;
+
+                for (k=0; k<3; ++k) {
+                    // test all minus axis combination: ++, +-, -+, --
+                    b1 = a1 | (((k & 2) != 0) ? 0x80 : 0);
+                    b2 = a2 | (((k & 1) != 0) ? 0x80 : 0);
+                    // the third axis
+                    b3 = (6 - a1 -a2) |
+                         ( (((a2 + 3 - a1) % 3 == 2) ? 0x80 : 0) ^ (b1 & 0x80) ^ (b2 & 0x80));
+
+                    // test both input formats
+                    if ( (i & 1) != 0 ) {
+                      assertTrue(SensorManager.remapCoordinateSystem(R, b1, b2, Rout));
+                    } else {
+                      assertTrue(SensorManager.remapCoordinateSystem(mat9to16(R), b1, b2, Rout2));
+                      Rout = mat16to9(Rout2);
+                    }
+
+                    float [] v1, v2;
+
+                    String detail = String.format(
+                            "Details: case %d (%x %x %x), original R = %s, result R = %s.",
+                            i, b1, b2, b3, mat9ToStr(R), mat9ToStr(Rout));
+
+                    v1 = mat9Axis(R, SensorManager.AXIS_X);
+                    v2 = mat9Axis(Rout, b1);
+                    assertVectorRoughlyEqual(
+                        "remapCoordinateSystem gives incorrect result (x)." + detail,
+                        v1, v2, 1e-4f);
+
+                    v1 = mat9Axis(R, SensorManager.AXIS_Y);
+                    v2 = mat9Axis(Rout, b2);
+                    assertVectorRoughlyEqual(
+                        "remapCoordinateSystem gives incorrect result (y)." + detail,
+                        v1, v2, 1e-4f);
+
+                    v1 = mat9Axis(R, SensorManager.AXIS_Z);
+                    v2 = mat9Axis(Rout, b3);
+                    assertVectorRoughlyEqual(
+                        "remapCoordinateSystem gives incorrect result (z)." + detail,
+                        v1, v2, 1e-4f);
+                }
+            }
+
+        }
+
+        // test cases when false should be returned
+        assertTrue("remapCoordinateSystem should return false with mismatch size input and output",
+                   !SensorManager.remapCoordinateSystem(Rout,
+                     SensorManager.AXIS_Y, SensorManager.AXIS_Z, Rout2));
+        assertTrue("remapCoordinateSystem should return false with invalid axis setting",
+                   !SensorManager.remapCoordinateSystem(Rout,
+                     SensorManager.AXIS_X, SensorManager.AXIS_X, Rout));
+        assertTrue("remapCoordinateSystem should return false with invalid axis setting",
+                   !SensorManager.remapCoordinateSystem(Rout,
+                     SensorManager.AXIS_X, SensorManager.AXIS_MINUS_X, Rout));
+
+    }
+
+    // Utilities class & functions
+
+    private class TestDataGenerator {
+        // carry out test deterministically without manually picking numbers
+        private final long DEFAULT_SEED = 0xFEDCBA9876543210l;
+
+        private Random mRandom;
+
+        TestDataGenerator(long seed) {
+            mRandom = new Random(seed);
+        }
+
+        TestDataGenerator() {
+            mRandom = new Random(DEFAULT_SEED);
+        }
+
+        void nextRotationAngles(float [] rotv) {
+            assertTrue(rotv.length == 3);
+
+            rotv[0] = (mRandom.nextFloat()-0.5f) * 2.0f * FLOAT_PI; // azimuth(yaw) -pi ~ pi
+            rotv[1] = (mRandom.nextFloat()-0.5f) * FLOAT_PI; // pitch -pi/2 ~ +pi/2
+            rotv[2] = (mRandom.nextFloat()-0.5f) * 2.f * FLOAT_PI; // roll -pi ~ +pi
+        }
+
+        void nextRotationAxisAngle(float [] aa) {
+            assertTrue(aa.length == 4);
+
+            aa[0] = (mRandom.nextFloat() - 0.5f) * 2.f;
+            aa[1] = (mRandom.nextFloat() - 0.5f ) * 2.f * (float) Math.sqrt(1.f - aa[0] * aa[0]);
+            aa[2] = (mRandom.nextBoolean() ? 1.f : -1.f) *
+                        (float) Math.sqrt(1.f - aa[0] * aa[0] - aa[1] * aa[1]);
+            aa[3] = mRandom.nextFloat() * FLOAT_PI;
+        }
+
+        int nextInt(int i) {
+            return mRandom.nextInt(i);
+        }
+
+        float nextFloat() {
+            return mRandom.nextFloat();
+        }
+
+        boolean nextBoolean() {
+            return mRandom.nextBoolean();
+        }
+    }
+
+    private static void assertRotationAnglesValid(String message, float[] ra) {
+
+        assertTrue(message, ra.length == 3 &&
+            ra[0] >= -FLOAT_PI && ra[0] <= FLOAT_PI &&         // azimuth
+            ra[1] >= -FLOAT_PI / 2.f && ra[1] <= FLOAT_PI / 2.f && // pitch
+            ra[2] >= -FLOAT_PI && ra[2] <= FLOAT_PI);          // roll
+    }
+
+    private static void assertRoughlyEqual(String message, float a, float b, float bound) {
+        assertTrue(message, Math.abs(a-b) < bound);
+    }
+
+    private static void assertVectorRoughlyEqual(String message, float [] v1, float [] v2,
+                                                 float bound) {
+        assertTrue(message, v1.length == v2.length);
+        int i;
+        float sum = 0.f;
+        for (i=0; i<v1.length; ++i) {
+            sum += (v1[i] - v2[i]) * (v1[i] - v2[i]);
+        }
+        assertRoughlyEqual(message, (float)Math.sqrt(sum), 0.f, bound);
+    }
+
+    private static float [] mat9to16(float [] m) {
+        assertTrue(m.length == 9);
+
+        float [] n  = new float[16];
+        int i;
+        for (i=0; i<9; ++i) {
+            n[i+i/3] = m[i];
+        }
+        n[15] = 1.f;
+        return n;
+    }
+
+    private static float [] mat16to9(float [] m) {
+        assertTrue(m.length == 16);
+
+        float [] n = new float[9];
+        int i;
+        for (i=0; i<9; ++i) {
+            n[i] = m[i + i/3];
+        }
+        return n;
+    }
+
+    private static float [] mat9Mul(float [] m, float [] n) {
+        assertTrue(m.length == 9 && n.length == 9);
+
+        float [] r = new float[9];
+        int i, j, k;
+
+        for (i = 0; i < 3; ++i)
+            for (j = 0; j < 3; ++j)
+                for (k = 0; k < 3; ++k)
+                    r[i * 3 + j] += m[i * 3 + k] * n[k * 3 + j];
+
+        return r;
+    }
+
+    private static float [] mat9T(float [] m) {
+        assertTrue(m.length == 9);
+
+        int i, j;
+        float [] n = new float[9];
+
+        for (i = 0; i < 3; ++i)
+            for (j = 0; j < 3; ++j)
+                n[i * 3 + j] = m[j * 3 + i];
+
+        return n;
+    }
+
+    private static float [] mat9I() {
+        float [] m = new float[9];
+        m[0] = m[4] = m[8] = 1.f;
+        return m;
+    }
+
+    private static float [] mat9Rot(int axis, float angle) {
+        float [] m = new float[9];
+        switch (axis) {
+            case SensorManager.AXIS_X:
+                m[0] = 1.f;
+                m[4] = m[8] = (float) Math.cos(angle);
+                m[5] = - (m[7] = (float) Math.sin(angle));
+                break;
+            case SensorManager.AXIS_Y:
+                m[4] = 1.f;
+                m[0] = m[8] = (float) Math.cos(angle);
+                m[6] = - (m[2] = (float) Math.sin(angle));
+                break;
+            case SensorManager.AXIS_Z:
+                m[8] = 1.f;
+                m[0] = m[4] = (float) Math.cos(angle);
+                m[1] = - (m[3] = (float) Math.sin(angle));
+                break;
+            default:
+                // should never be here
+                assertTrue(false);
+        }
+        return m;
+    }
+
+    private static float [] mat9VRot(float [] angles) {
+        assertTrue(angles.length == 3);
+        // yaw, android yaw rotate to -z
+        float [] R = mat9Rot(SensorManager.AXIS_Z, -angles[0]);
+        // pitch, android pitch rotate to -x
+        R = mat9Mul(R, mat9Rot(SensorManager.AXIS_X, -angles[1]));
+        // roll
+        R = mat9Mul(R, mat9Rot(SensorManager.AXIS_Y, angles[2]));
+
+        return R;
+    }
+
+    private static float [] mat9Axis(float m[], int axis) {
+        assertTrue(m.length == 9);
+
+        boolean negative = (axis & 0x80) != 0;
+        float [] v = new float[3];
+        int offset;
+
+        offset = (axis & ~0x80) - 1;
+        v[0] = negative ? -m[offset]   : m[offset];
+        v[1] = negative ? -m[offset+3] : m[offset+3];
+        v[2] = negative ? -m[offset+6] : m[offset+6];
+        return v;
+    }
+
+    private static float vecInner(float u[], float v[]) {
+        assertTrue(u.length == v.length);
+
+        int i;
+        float sum = 0.f;
+
+        for (i=0; i < v.length; ++i) {
+            sum += u[i]*v[i];
+        }
+        return (float)Math.sqrt(sum);
+    }
+
+    private static String vecToStr(float u[]) {
+        int i;
+        String s;
+        switch (u.length) {
+            case 3:
+                return String.format("[%f, %f, %f]", u[0], u[1], u[2]);
+            case 4:
+                return String.format("(%f, %f, %f, %f)", u[0], u[1], u[2], u[3]);
+            default:
+                s = "[";
+                for (i = 0; i < u.length-1; ++i) {
+                    s += String.format("%f, ", u[i]);
+                }
+                s += String.format("%f]", u[i]);
+                return s;
+        }
+    }
+
+    private static String mat9ToStr(float m[]) {
+        assertTrue(m.length == 9);
+        return String.format("[%f, %f, %f; %f, %f, %f; %f, %f, %f]",
+            m[0], m[1], m[2],
+            m[3], m[4], m[5],
+            m[6], m[7], m[8]);
+    }
+
+    private static String mat16ToStr(float m[]) {
+        assertTrue(m.length == 16);
+        return String.format("[%f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f; %f, %f, %f, %f]",
+            m[0], m[1], m[2], m[3],
+            m[4], m[5], m[6], m[7],
+            m[8], m[9], m[10], m[11],
+            m[12], m[13], m[14], m[15]);
+    }
+
+}
+
diff --git a/tests/tests/hardware/src/android/hardware/cts/SensorTest.java b/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
index 6703c47..d76152f 100644
--- a/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
+++ b/tests/tests/hardware/src/android/hardware/cts/SensorTest.java
@@ -47,6 +47,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -353,6 +354,40 @@
         listener.assertEventsReceivedInHandler();
     }
 
+    /**
+     *  Explicit testing the SensorManager.registerListener(SensorEventListener, Sensor, int, int).
+     */
+    @TimeoutReq(minutes=10)
+    public void testBatchAndFlushUseDefaultHandler() throws Exception {
+        Sensor sensor = null;
+        for (Sensor s : mSensorList) {
+            if (s.getReportingMode() == Sensor.REPORTING_MODE_CONTINUOUS) {
+                sensor = s;
+                break;
+            }
+        }
+        if (sensor == null) {
+            throw new SensorTestStateNotSupportedException(
+                    "There are no Continuous sensors in the device.");
+        }
+
+        TestSensorEnvironment environment = new TestSensorEnvironment(
+                getContext(),
+                sensor,
+                SensorManager.SENSOR_DELAY_FASTEST,
+                (int) TimeUnit.SECONDS.toMicros(5));
+        mTestSensorManager = new TestSensorManager(environment);
+
+        TestSensorEventListener listener = new TestSensorEventListener(environment, null);
+
+        // specifyHandler <= false, use the SensorManager API without Handler parameter
+        CountDownLatch eventLatch = mTestSensorManager.registerListener(listener, 1, false);
+        listener.waitForEvents(eventLatch, 1);
+        CountDownLatch flushLatch = mTestSensorManager.requestFlush();
+        listener.waitForFlushComplete(flushLatch);
+        listener.assertEventsReceivedInHandler();
+    }
+
     // TODO: after L release move to SensorBatchingTests and run in all sensors with default
     //       verifications enabled
     public void testBatchAndFlushWithMutipleSensors() throws Exception {
@@ -568,4 +603,5 @@
         @Override
         public void onAccuracyChanged(Sensor sensor, int accuracy) {}
     }
+
 }
diff --git a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
index 2468bd1..23580de 100644
--- a/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
+++ b/tests/tests/hardware/src/android/hardware/cts/helpers/TestSensorManager.java
@@ -77,6 +77,7 @@
 
         mTestSensorEventListener = listener;
         String message = SensorCtsHelper.formatAssertionMessage("registerListener", mEnvironment);
+
         boolean result = mSensorManager.registerListener(
                 mTestSensorEventListener,
                 mEnvironment.getSensor(),
@@ -94,7 +95,10 @@
      * @throws AssertionError if there was an error registering the listener with the
      * {@link SensorManager}
      */
-    public CountDownLatch registerListener(TestSensorEventListener listener, int eventCount) {
+    public CountDownLatch registerListener(
+            TestSensorEventListener listener,
+            int eventCount,
+            boolean specifyHandler) {
         if (mTestSensorEventListener != null) {
             Log.w(LOG_TAG, "Listener already registered, returning.");
             return null;
@@ -103,17 +107,41 @@
         CountDownLatch latch = listener.getLatchForSensorEvents(eventCount);
         mTestSensorEventListener = listener;
         String message = SensorCtsHelper.formatAssertionMessage("registerListener", mEnvironment);
-        boolean result = mSensorManager.registerListener(
-                mTestSensorEventListener,
-                mEnvironment.getSensor(),
-                mEnvironment.getRequestedSamplingPeriodUs(),
-                mEnvironment.getMaxReportLatencyUs(),
-                mTestSensorEventListener.getHandler());
+
+        boolean result;
+        if (specifyHandler) {
+            result = mSensorManager.registerListener(
+                    mTestSensorEventListener,
+                    mEnvironment.getSensor(),
+                    mEnvironment.getRequestedSamplingPeriodUs(),
+                    mEnvironment.getMaxReportLatencyUs(),
+                    mTestSensorEventListener.getHandler());
+        } else {
+            result = mSensorManager.registerListener(
+                    mTestSensorEventListener,
+                    mEnvironment.getSensor(),
+                    mEnvironment.getRequestedSamplingPeriodUs(),
+                    mEnvironment.getMaxReportLatencyUs());
+        }
         Assert.assertTrue(message, result);
         return latch;
     }
 
     /**
+     * Register the listener. This method will perform a no-op if the sensor is already registered.
+     *
+     * @return A CountDownLatch initialized with eventCount which is used to wait for sensor
+     * events.
+     * @throws AssertionError if there was an error registering the listener with the
+     * {@link SensorManager}
+     */
+    public CountDownLatch registerListener(
+            TestSensorEventListener listener,
+            int eventCount) {
+        return registerListener(listener, eventCount, true);
+    }
+
+    /**
      * Unregister the listener. This method will perform a no-op if the sensor is not registered.
      */
     public void unregisterListener() {
diff --git a/tests/tests/location/src/android/location/cts/BaseMockLocationTest.java b/tests/tests/location/src/android/location/cts/BaseMockLocationTest.java
new file mode 100644
index 0000000..fbc7d8d
--- /dev/null
+++ b/tests/tests/location/src/android/location/cts/BaseMockLocationTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2015 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
+ *
+ */
+
+package android.location.cts;
+
+import android.os.ParcelFileDescriptor;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Base class for instrumentations tests that use mock location.
+ */
+public abstract class BaseMockLocationTest extends InstrumentationTestCase {
+    private static final String LOG_TAG = "BaseMockLocationTest";
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        setAsMoskLocationProvider(true);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        setAsMoskLocationProvider(false);
+        super.tearDown();
+    }
+
+    private void setAsMoskLocationProvider(boolean enable) {
+        StringBuilder command = new StringBuilder();
+        command.append("appops set ");
+        command.append(getInstrumentation().getContext().getPackageName());
+        command.append(" android:mock_location ");
+        command.append(enable ? "allow" : "deny");
+
+        ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation()
+                .executeShellCommand(command.toString());
+
+        InputStream is = new FileInputStream(pfd.getFileDescriptor());
+        try {
+            final byte[] buffer = new byte[8192];
+            while ((is.read(buffer)) != -1);
+        } catch (IOException e) {
+            Log.e(LOG_TAG, "Error managing mock locaiton app", e);
+        }
+    }
+}
diff --git a/tests/tests/location/src/android/location/cts/LocationManagerTest.java b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
index 3168335..8ac56ae 100644
--- a/tests/tests/location/src/android/location/cts/LocationManagerTest.java
+++ b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
@@ -16,7 +16,6 @@
 
 package android.location.cts;
 
-
 import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
@@ -37,7 +36,6 @@
 import android.os.Looper;
 import android.os.SystemClock;
 import android.provider.Settings;
-import android.test.InstrumentationTestCase;
 import android.test.UiThreadTest;
 
 import java.util.List;
@@ -49,7 +47,7 @@
  * android.permission.ACCESS_FINE_LOCATION to access GPS provider
  * android.permission.ACCESS_LOCATION_EXTRA_COMMANDS to send extra commands to GPS provider
  */
-public class LocationManagerTest extends InstrumentationTestCase {
+public class LocationManagerTest extends BaseMockLocationTest {
     private static final long TEST_TIME_OUT = 5000;
 
     private static final String TEST_MOCK_PROVIDER_NAME = "test_provider";
@@ -73,13 +71,6 @@
 
         mManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
 
-        // test that mock locations are allowed so a more descriptive error message can be logged
-        if (Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 0) {
-            fail("Mock locations are currently disabled in Settings - this test requires "
-                    + "mock locations");
-        }
-
         // remove test provider if left over from an aborted run
         LocationProvider lp = mManager.getProvider(TEST_MOCK_PROVIDER_NAME);
         if (lp != null) {
diff --git a/tests/tests/location/src/android/location/cts/LocationProviderTest.java b/tests/tests/location/src/android/location/cts/LocationProviderTest.java
index 716801d..1e6feda 100644
--- a/tests/tests/location/src/android/location/cts/LocationProviderTest.java
+++ b/tests/tests/location/src/android/location/cts/LocationProviderTest.java
@@ -16,14 +16,11 @@
 
 package android.location.cts;
 
-
-import android.content.Context;
 import android.location.Criteria;
 import android.location.LocationManager;
 import android.location.LocationProvider;
-import android.test.AndroidTestCase;
 
-public class LocationProviderTest extends AndroidTestCase {
+public class LocationProviderTest extends BaseMockLocationTest {
     private static final String PROVIDER_NAME = "location_provider_test";
 
     private LocationManager mLocationManager;
@@ -31,8 +28,8 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mLocationManager =
-            (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
+        mLocationManager = getInstrumentation().getContext().getSystemService(
+                LocationManager.class);
         addTestProvider(PROVIDER_NAME);
     }
 
diff --git a/tests/tests/location2/AndroidManifest.xml b/tests/tests/location2/AndroidManifest.xml
index ad77b7e..b2e0802 100644
--- a/tests/tests/location2/AndroidManifest.xml
+++ b/tests/tests/location2/AndroidManifest.xml
@@ -23,7 +23,6 @@
         <uses-library android:name="android.test.runner" />
     </application>
 
-    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
 
diff --git a/tests/tests/location2/src/android/location2/cts/LocationManagerTest.java b/tests/tests/location2/src/android/location2/cts/LocationManagerTest.java
index b298b97..6764223 100644
--- a/tests/tests/location2/src/android/location2/cts/LocationManagerTest.java
+++ b/tests/tests/location2/src/android/location2/cts/LocationManagerTest.java
@@ -16,31 +16,29 @@
 
 package android.location2.cts;
 
-
 import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.PackageManager;
 import android.location.Criteria;
-import android.location.GpsStatus;
 import android.location.GpsStatus.Listener;
 import android.location.GpsStatus.NmeaListener;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
-import android.location.LocationProvider;
 import android.os.Bundle;
 import android.os.HandlerThread;
-import android.os.Looper;
+import android.os.ParcelFileDescriptor;
 import android.os.SystemClock;
-import android.provider.Settings;
 import android.test.InstrumentationTestCase;
 import android.test.UiThreadTest;
+import android.util.Log;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
-import java.lang.Thread;
 
 /**
  * Requires the permissions
@@ -50,6 +48,8 @@
  */
 public class LocationManagerTest extends InstrumentationTestCase {
 
+    public static final String LOG_TAG = "LocationManagerTest";
+
     private static final long TEST_TIME_OUT_MS = 10 * 1000;
 
     private static final double LAT = 10.0;
@@ -71,12 +71,13 @@
 
         mManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
 
-        // test that mock locations are allowed so a more descriptive error message can be logged
-        if (Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.ALLOW_MOCK_LOCATION, 0) == 0) {
-            fail("Mock locations are currently disabled in Settings - this test requires "
-                    + "mock locations");
-        }
+        setAsMoskLocationProvider(true);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        setAsMoskLocationProvider(false);
+        super.tearDown();
     }
 
     public void testGetGpsProvider_notAllowed() {
@@ -319,6 +320,25 @@
         mManager.setTestProviderLocation(providerName, location);
     }
 
+    private void setAsMoskLocationProvider(boolean enable) {
+        StringBuilder command = new StringBuilder();
+        command.append("appops set ");
+        command.append(getInstrumentation().getContext().getPackageName());
+        command.append(" android:mock_location ");
+        command.append(enable ? "allow" : "deny");
+
+        ParcelFileDescriptor pfd = getInstrumentation().getUiAutomation()
+                .executeShellCommand(command.toString());
+
+        InputStream is = new FileInputStream(pfd.getFileDescriptor());
+        try {
+            final byte[] buffer = new byte[8192];
+            while ((is.read(buffer)) != -1);
+        } catch (IOException e) {
+            Log.e(LOG_TAG, "Error managing mock locaiton app", e);
+        }
+    }
+
     /**
      * Helper class that receives a proximity intent and notifies the main class
      * when received
diff --git a/tests/tests/media/src/android/media/cts/EnumDevicesTest.java b/tests/tests/media/src/android/media/cts/EnumDevicesTest.java
index 0e1621d..f513709 100644
--- a/tests/tests/media/src/android/media/cts/EnumDevicesTest.java
+++ b/tests/tests/media/src/android/media/cts/EnumDevicesTest.java
@@ -37,11 +37,6 @@
     boolean mAddCallbackCalled = false;
     boolean mRemoveCallbackCalled = false;
 
-    static {
-        // We're going to use a Handler
-        Looper.prepare();
-    }
-
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -95,6 +90,57 @@
         }
     }
 
+    public void test_devicesInfoFields() {
+        AudioDeviceInfo[] deviceList;
+        deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_ALL);
+        for (int index = 0; index < deviceList.length; index++) {
+            AudioDeviceInfo deviceInfo = deviceList[index];
+
+            // we don't say anything about the returned value.
+            int id = deviceInfo.getId();
+
+            // Product Name
+            CharSequence productName = deviceInfo.getProductName();
+            assertNotNull(productName);
+            assertTrue(productName.length() != 0);
+
+            // Address
+            String address = deviceInfo.getAddress();
+            assertNotNull(address);
+            // address may be empty
+
+            // isSource() XOR isSink()
+            assertTrue(deviceInfo.isSource() != deviceInfo.isSink());
+
+            // Sample Rates
+            int[] sampleRates = deviceInfo.getSampleRates();
+            assertNotNull(sampleRates);
+            // "analog" devices won't list any sample rates
+
+            // Channel Masks
+            int[] channelMasks = deviceInfo.getChannelMasks();
+            assertNotNull(channelMasks);
+            // "analog" devices won't list any channel masks
+
+            // Channel Index Masks
+            int[] indexMasks = deviceInfo.getChannelIndexMasks();
+            assertNotNull(channelMasks);
+
+            // Channel Counts
+            int[] channelCounts = deviceInfo.getChannelCounts();
+            assertNotNull(channelCounts);
+            // "analog" devices won't list any channel Counts
+
+            // Encodings
+            int[] encodings = deviceInfo.getEncodings();
+            assertNotNull(encodings);
+            // "analog" devices won't list any encodings
+
+            int type = deviceInfo.getType();
+            assert(type > AudioDeviceInfo.TYPE_UNKNOWN);
+        }
+    }
+
     private class EmptyDeviceCallback extends AudioDeviceCallback {
         public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
             mAddCallbackCalled = true;
@@ -105,16 +151,56 @@
         }
     }
 
+    /*
+     * tests if the Looper for the current thread has been prepared,
+     * If not, it makes one, prepares it and returns it.
+     * If this returns non-null, the caller is reponsible for calling quit()
+     * on the returned Looper.
+     */
+    private Looper prepareIfNeededLooper() {
+        // non-null Handler
+        Looper myLooper = null;
+        if (Looper.myLooper() == null) {
+            Looper.prepare();
+            myLooper = Looper.myLooper();
+            assertNotNull(myLooper);
+        }
+        return myLooper;
+    }
+    
     public void test_deviceCallback() {
+        // null callback?
         mAudioManager.registerAudioDeviceCallback(null,null);
-        assertTrue(true);
 
         AudioDeviceCallback callback =  new EmptyDeviceCallback();
+        AudioDeviceCallback someOtherCallback =  new EmptyDeviceCallback();
+        // null Handler
         mAudioManager.registerAudioDeviceCallback(callback, null);
-        assertTrue(true);
 
+        // unregister null callback
+        mAudioManager.unregisterAudioDeviceCallback(null);
+        // unregister callback not registered
+        mAudioManager.unregisterAudioDeviceCallback(someOtherCallback);
+        // nominal case
+        mAudioManager.unregisterAudioDeviceCallback(callback);
+        // remove twice
+        mAudioManager.unregisterAudioDeviceCallback(callback);
+
+        Looper myLooper = prepareIfNeededLooper();
+        
         mAudioManager.registerAudioDeviceCallback(callback, new Handler());
-        assertTrue(true);
+        // unregister null callback
+        mAudioManager.unregisterAudioDeviceCallback(null);
+        // unregister callback not registered
+        mAudioManager.unregisterAudioDeviceCallback(someOtherCallback);
+        // nominal case
+        mAudioManager.unregisterAudioDeviceCallback(callback);
+        // remove twice
+        mAudioManager.unregisterAudioDeviceCallback(callback);
+
+        if (myLooper != null) {
+            myLooper.quit();
+        }
     }
 
     //TODO - Need tests for device connect/disconnect callbacks
diff --git a/tests/tests/media/src/android/media/cts/MediaBrowserTest.java b/tests/tests/media/src/android/media/cts/MediaBrowserTest.java
index b53aa92..976e5a6 100644
--- a/tests/tests/media/src/android/media/cts/MediaBrowserTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaBrowserTest.java
@@ -20,6 +20,8 @@
 import android.media.browse.MediaBrowser;
 import android.test.InstrumentationTestCase;
 
+import java.util.List;
+
 /**
  * Test {@link android.media.browse.MediaBrowser}.
  */
@@ -28,12 +30,15 @@
     private static final long TIME_OUT_MS = 1000L;
     private static final ComponentName TEST_BROWSER_SERVICE = new ComponentName(
             "com.android.cts.media", "android.media.cts.StubMediaBrowserService");
+    private static final ComponentName TEST_INVALID_BROWSER_SERVICE = new ComponentName(
+            "invalid.package", "invalid.ServiceClassName");
     private final StubConnectionCallback mConnectionCallback = new StubConnectionCallback();
+    private final StubSubscriptionCallback mSubscriptionCallback = new StubSubscriptionCallback();
 
     private MediaBrowser mMediaBrowser;
 
     public void testMediaBrowser() {
-        mConnectionCallback.resetCounts();
+        resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
         assertEquals(false, mMediaBrowser.isConnected());
 
@@ -52,7 +57,7 @@
     }
 
     public void testConnectTwice() {
-        mConnectionCallback.resetCounts();
+        resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
         connectMediaBrowserService();
         try {
@@ -63,8 +68,23 @@
         }
     }
 
+    public void testConnectionFailed() {
+        resetCallbacks();
+        createMediaBrowser(TEST_INVALID_BROWSER_SERVICE);
+
+        mMediaBrowser.connect();
+        new PollingCheck(TIME_OUT_MS) {
+            @Override
+            protected boolean check() {
+                return mConnectionCallback.mConnectionFailedCount > 0
+                        && mConnectionCallback.mConnectedCount == 0
+                        && mConnectionCallback.mConnectionSuspendedCount == 0;
+            }
+        }.run();
+    }
+
     public void testGetServiceComponentBeforeConnection() {
-        mConnectionCallback.resetCounts();
+        resetCallbacks();
         createMediaBrowser(TEST_BROWSER_SERVICE);
         try {
             ComponentName serviceComponent = mMediaBrowser.getServiceComponent();
@@ -74,6 +94,27 @@
         }
     }
 
+    public void testSubscribe() {
+        resetCallbacks();
+        createMediaBrowser(TEST_BROWSER_SERVICE);
+        connectMediaBrowserService();
+        mMediaBrowser.subscribe(StubMediaBrowserService.MEDIA_ID_ROOT, mSubscriptionCallback);
+        new PollingCheck(TIME_OUT_MS) {
+            @Override
+            protected boolean check() {
+                return mSubscriptionCallback.mChildrenLoadedCount > 0;
+            }
+        }.run();
+
+        assertEquals(StubMediaBrowserService.MEDIA_ID_ROOT, mSubscriptionCallback.mLastParentId);
+        assertEquals(StubMediaBrowserService.MEDIA_ID_CHILDREN.length,
+                mSubscriptionCallback.mLastChildMediaItems.size());
+        for (int i = 0; i < StubMediaBrowserService.MEDIA_ID_CHILDREN.length; i++) {
+            assertEquals(StubMediaBrowserService.MEDIA_ID_CHILDREN[i],
+                    mSubscriptionCallback.mLastChildMediaItems.get(i).getMediaId());
+        }
+    }
+
     private void createMediaBrowser(final ComponentName component) {
         getInstrumentation().runOnMainSync(new Runnable() {
             @Override
@@ -94,12 +135,17 @@
         }.run();
     }
 
+    private void resetCallbacks() {
+        mConnectionCallback.reset();
+        mSubscriptionCallback.reset();
+    }
+
     private static class StubConnectionCallback extends MediaBrowser.ConnectionCallback {
         volatile int mConnectedCount;
         volatile int mConnectionFailedCount;
         volatile int mConnectionSuspendedCount;
 
-        public void resetCounts() {
+        public void reset() {
             mConnectedCount = 0;
             mConnectionFailedCount = 0;
             mConnectionSuspendedCount = 0;
@@ -120,4 +166,32 @@
             mConnectionSuspendedCount++;
         }
     }
+
+    private static class StubSubscriptionCallback extends MediaBrowser.SubscriptionCallback {
+        private volatile int mChildrenLoadedCount;
+        private volatile int mErrorCount;
+        private volatile String mLastErrorId;
+        private volatile String mLastParentId;
+        private volatile List<MediaBrowser.MediaItem> mLastChildMediaItems;
+
+        public void reset() {
+            mChildrenLoadedCount = 0;
+            mErrorCount = 0;
+            mLastErrorId = null;
+            mLastParentId = null;
+            mLastChildMediaItems = null;
+        }
+
+        @Override
+        public void onChildrenLoaded(String parentId, List<MediaBrowser.MediaItem> children) {
+            mChildrenLoadedCount++;
+            mLastParentId = parentId;
+            mLastChildMediaItems = children;
+        }
+
+        @Override
+        public void onError(String id) {
+            mLastErrorId = id;
+        }
+    }
 }
diff --git a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
index 18cd353..86f0313 100644
--- a/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaPlayerTest.java
@@ -896,7 +896,7 @@
         assertEquals("MediaPlayer had error in clockRate " + ts1.getMediaClockRate(),
                 playbackRate, ts1.getMediaClockRate(), 0.001f);
         assertTrue("The nanoTime of Media timestamp should be taken when getTimestamp is called.",
-                nt1 <= ts1.nanoTime && ts1.nanoTime <= nt2);
+                nt1 <= ts1.getAnchorSytemNanoTime() && ts1.getAnchorSytemNanoTime() <= nt2);
 
         mMediaPlayer.pause();
         ts1 = mMediaPlayer.getTimestamp();
diff --git a/tests/tests/media/src/android/media/cts/MediaSessionTest.java b/tests/tests/media/src/android/media/cts/MediaSessionTest.java
index df68392..7999092 100644
--- a/tests/tests/media/src/android/media/cts/MediaSessionTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaSessionTest.java
@@ -29,18 +29,30 @@
 import android.media.session.MediaSessionManager;
 import android.media.session.PlaybackState;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.Parcel;
 import android.test.AndroidTestCase;
 
 import java.util.ArrayList;
 import java.util.Set;
 
 public class MediaSessionTest extends AndroidTestCase {
+    // The maximum time to wait for an operation.
+    private static final long TIME_OUT_MS = 5000L;
+    private static final String SESSION_TAG = "test-session";
+    private static final String EXTRAS_KEY = "test-key";
+    private static final String EXTRAS_VALUE = "test-val";
+    private static final String SESSION_EVENT = "test-session-event";
+
     private AudioManager mAudioManager;
+    private Handler mHandler = new Handler(Looper.getMainLooper());
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
+        mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
     }
 
     /**
@@ -48,15 +60,33 @@
      * initialized correctly.
      */
     public void testCreateSession() throws Exception {
-        String tag = "test session";
-        MediaSession session = new MediaSession(getContext(), tag);
+        MediaSession session = new MediaSession(getContext(), SESSION_TAG);
         assertNotNull(session.getSessionToken());
         assertFalse("New session should not be active", session.isActive());
 
         // Verify by getting the controller and checking all its fields
         MediaController controller = session.getController();
         assertNotNull(controller);
-        verifyNewSession(controller, tag);
+        verifyNewSession(controller, SESSION_TAG);
+    }
+
+    /**
+     * Tests MediaSession.Token created in the constructor of MediaSession.
+     */
+    public void testSessionToken() throws Exception {
+        MediaSession session = new MediaSession(getContext(), SESSION_TAG);
+        MediaSession.Token sessionToken = session.getSessionToken();
+
+        assertNotNull(sessionToken);
+        assertEquals(0, sessionToken.describeContents());
+
+        // Test writeToParcel
+        Parcel p = Parcel.obtain();
+        sessionToken.writeToParcel(p, 0);
+        p.setDataPosition(0);
+        MediaSession.Token token = MediaSession.Token.CREATOR.createFromParcel(p);
+        assertEquals(token, sessionToken);
+        p.recycle();
     }
 
     /**
@@ -64,30 +94,28 @@
      * controller.
      */
     public void testConfigureSession() throws Exception {
-        String tag = "test session";
-        String key = "test-key";
-        String val = "test-val";
-        MediaSession session = new MediaSession(getContext(), tag);
+        MediaSession session = new MediaSession(getContext(), SESSION_TAG);
         MediaController controller = session.getController();
 
         // test setExtras
         Bundle extras = new Bundle();
-        extras.putString(key, val);
+        extras.putString(EXTRAS_KEY, EXTRAS_VALUE);
         session.setExtras(extras);
         Bundle extrasOut = controller.getExtras();
         assertNotNull(extrasOut);
-        assertEquals(val, extrasOut.get(key));
+        assertEquals(EXTRAS_VALUE, extrasOut.get(EXTRAS_KEY));
 
         // test setFlags
         session.setFlags(5);
         assertEquals(5, controller.getFlags());
 
         // test setMetadata
-        MediaMetadata metadata = new MediaMetadata.Builder().putString(key, val).build();
+        MediaMetadata metadata =
+                new MediaMetadata.Builder().putString(EXTRAS_KEY, EXTRAS_VALUE).build();
         session.setMetadata(metadata);
         MediaMetadata metadataOut = controller.getMetadata();
         assertNotNull(metadataOut);
-        assertEquals(val, metadataOut.getString(key));
+        assertEquals(EXTRAS_VALUE, metadataOut.getString(EXTRAS_KEY));
 
         // test setPlaybackState
         PlaybackState state = new PlaybackState.Builder().setActions(55).build();
@@ -114,27 +142,27 @@
         assertEquals(VolumeProvider.VOLUME_CONTROL_FIXED, info.getVolumeControl());
 
         // test setPlaybackToLocal
-        AudioAttributes attrs = new AudioAttributes.Builder().addTag(val).build();
+        AudioAttributes attrs = new AudioAttributes.Builder().addTag(EXTRAS_VALUE).build();
         session.setPlaybackToLocal(attrs);
         info = controller.getPlaybackInfo();
         assertNotNull(info);
         assertEquals(MediaController.PlaybackInfo.PLAYBACK_TYPE_LOCAL, info.getPlaybackType());
         Set<String> tags = info.getAudioAttributes().getTags();
         assertNotNull(tags);
-        assertTrue(tags.contains(val));
+        assertTrue(tags.contains(EXTRAS_VALUE));
 
         // test setQueue and setQueueTitle
         ArrayList<MediaSession.QueueItem> queue = new ArrayList<MediaSession.QueueItem>();
         MediaSession.QueueItem item = new MediaSession.QueueItem(new MediaDescription.Builder()
-                .setMediaId(val).setTitle("title").build(), 11);
+                .setMediaId(EXTRAS_VALUE).setTitle("title").build(), 11);
         queue.add(item);
         session.setQueue(queue);
-        session.setQueueTitle(val);
+        session.setQueueTitle(EXTRAS_VALUE);
 
-        assertEquals(val, controller.getQueueTitle());
+        assertEquals(EXTRAS_VALUE, controller.getQueueTitle());
         assertEquals(1, controller.getQueue().size());
         assertEquals(11, controller.getQueue().get(0).getQueueId());
-        assertEquals(val, controller.getQueue().get(0).getDescription().getMediaId());
+        assertEquals(EXTRAS_VALUE, controller.getQueue().get(0).getDescription().getMediaId());
 
         session.setQueue(null);
         session.setQueueTitle(null);
@@ -149,6 +177,24 @@
         assertEquals(pi, controller.getSessionActivity());
     }
 
+    public void testSendSessionEvent() throws Exception {
+        MediaSession session = new MediaSession(getContext(), SESSION_TAG);
+        MediaController controller = new MediaController(getContext(), session.getSessionToken());
+        Object lock = new Object();
+        MediaControllerCallback callback = new MediaControllerCallback(lock);
+        controller.registerCallback(callback, mHandler);
+
+        Bundle extras = new Bundle();
+        extras.putString(EXTRAS_KEY, EXTRAS_VALUE);
+
+        synchronized (lock) {
+            session.sendSessionEvent(SESSION_EVENT, extras);
+            lock.wait(TIME_OUT_MS);
+            assertEquals(SESSION_EVENT, callback.mEvent);
+            assertEquals(EXTRAS_VALUE, callback.mExtras.getString(EXTRAS_KEY));
+        }
+    }
+
     /**
      * Verifies that a new session hasn't had any configuration bits set yet.
      *
@@ -180,4 +226,23 @@
         assertEquals(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC),
                 info.getCurrentVolume());
     }
+
+    private class MediaControllerCallback extends MediaController.Callback {
+        private Object mLock;
+        private String mEvent;
+        private Bundle mExtras;
+
+        MediaControllerCallback(Object lock) {
+            mLock = lock;
+        }
+
+        @Override
+        public void onSessionEvent(String event, Bundle extras) {
+            synchronized (mLock) {
+                mEvent = event;
+                mExtras = (Bundle) extras.clone();
+                mLock.notify();
+            }
+        }
+    }
 }
diff --git a/tests/tests/media/src/android/media/cts/MidiSoloTest.java b/tests/tests/media/src/android/media/cts/MidiSoloTest.java
new file mode 100644
index 0000000..4c1a5e8
--- /dev/null
+++ b/tests/tests/media/src/android/media/cts/MidiSoloTest.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2015 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.media.cts;
+
+import java.io.IOException;
+
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.cts.util.CtsAndroidTestCase;
+import android.media.midi.MidiDevice;
+import android.media.midi.MidiDevice.MidiConnection;
+import android.media.midi.MidiDeviceInfo;
+import android.media.midi.MidiDeviceStatus;
+import android.media.midi.MidiInputPort;
+import android.media.midi.MidiManager;
+import android.media.midi.MidiReceiver;
+import android.media.midi.MidiSender;
+import android.os.Handler;
+import android.os.Looper;
+
+/**
+ * Test MIDI when there may be no MIDI devices available. There is not much we
+ * can test without a device.
+ */
+public class MidiSoloTest extends CtsAndroidTestCase {
+    private static final String TAG = "MidiSoloTest";
+    private final static int LOCAL_STORAGE_SIZE = 256;
+
+    // Store received data so we can check it later.
+    class MyMidiReceiver extends MidiReceiver {
+        public int byteCount;
+        public byte[] data = new byte[LOCAL_STORAGE_SIZE];
+
+        public MyMidiReceiver(int maxMessageSize) {
+            super(maxMessageSize);
+        }
+
+        @Override
+        // Abstract method declared in MidiReceiver
+        public void onSend(byte[] msg, int offset, int count, long timestamp)
+                throws IOException {
+            assertTrue("Message too large.", (count <= getMaxMessageSize()));
+            try {
+                System.arraycopy(msg, offset, data, byteCount, count);
+            } catch (ArrayIndexOutOfBoundsException e) {
+                throw new IOException("Exceeded local storage.", e);
+            }
+            byteCount += count;
+        }
+
+        @Override
+        public void onFlush() {
+            byteCount = 0;
+        }
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        // setup for each test case.
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        // Test case clean up.
+        super.tearDown();
+    }
+
+    public void testMidiManager() throws Exception {
+        PackageManager pm = getContext().getPackageManager();
+        if (!pm.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
+            return; // Not supported so don't test it.
+        }
+
+        MidiManager midiManager = (MidiManager) getContext().getSystemService(
+                Context.MIDI_SERVICE);
+        assertTrue("MidiManager not supported.", midiManager != null);
+
+        MidiDeviceInfo[] infos = midiManager.getDevices();
+        assertTrue("Device list was null.", infos != null);
+
+        MidiManager.DeviceCallback callback = new MidiManager.DeviceCallback();
+
+        // These should not crash.
+        midiManager.unregisterDeviceCallback(null);
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.registerDeviceCallback(null, null);
+        midiManager.registerDeviceCallback(callback, null);
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.registerDeviceCallback(callback, new Handler(Looper.getMainLooper()));
+        midiManager.registerDeviceCallback(callback, new Handler(Looper.getMainLooper()));
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.registerDeviceCallback(null, new Handler(Looper.getMainLooper()));
+        midiManager.unregisterDeviceCallback(callback);
+        midiManager.unregisterDeviceCallback(null);
+    }
+
+    public void testMidiReceiver() throws Exception {
+        PackageManager pm = getContext().getPackageManager();
+        if (!pm.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
+            return; // Not supported so don't test it.
+        }
+
+        MidiReceiver receiver = new MidiReceiver() {
+                @Override
+            public void onSend(byte[] msg, int offset, int count,
+                    long timestamp) throws IOException {
+            }
+        };
+        assertEquals("MidiReceiver default size wrong.", Integer.MAX_VALUE,
+                receiver.getMaxMessageSize());
+
+        int maxSize = 11;
+        MyMidiReceiver myReceiver = new MyMidiReceiver(maxSize);
+        assertEquals("MidiReceiver set size wrong.", maxSize,
+                myReceiver.getMaxMessageSize());
+
+        // Fill array with predictable data.
+        byte[] bar = new byte[200];
+        for (int i = 0; i < bar.length; i++) {
+            bar[i] = (byte) (i ^ 15);
+        }
+        // Small message with no offset.
+        int offset = 0;
+        int count = 3;
+        checkReceivedData(myReceiver, bar, offset, count);
+
+        // Small with an offset.
+        offset = 50;
+        count = 3;
+        checkReceivedData(myReceiver, bar, offset, count);
+
+        // Entire array.
+        offset = 0;
+        count = bar.length;
+        checkReceivedData(myReceiver, bar, offset, count);
+
+        offset = 20;
+        count = 100;
+        checkReceivedData(myReceiver, bar, offset, count);
+    }
+
+    public void testMidiReceiverException() throws Exception {
+        PackageManager pm = getContext().getPackageManager();
+        if (!pm.hasSystemFeature(PackageManager.FEATURE_MIDI)) {
+            return; // Not supported so don't test it.
+        }
+
+        int maxSize = 11;
+        MyMidiReceiver myReceiver = new MyMidiReceiver(maxSize);
+        assertEquals("MidiReceiver set size wrong.", maxSize,
+                myReceiver.getMaxMessageSize());
+
+        // Fill array with predictable data.
+        byte[] bar = new byte[200];
+        int offset = 0;
+        int count = bar.length;
+        myReceiver.flush(); // reset byte counter
+        IOException exception = null;
+        // Send too much data and intentionally cause an IOException.
+        try {
+            int sent = 0;
+            while (sent < LOCAL_STORAGE_SIZE) {
+                myReceiver.send(bar, offset, count);
+                sent += count;
+            }
+        } catch (IOException e) {
+            exception = e;
+        }
+        assertTrue("We should have caught an IOException", exception != null);
+    }
+
+    // Does the data we sent match the data received by the MidiReceiver?
+    private void checkReceivedData(MyMidiReceiver myReceiver, byte[] bar,
+            int offset, int count) throws IOException {
+        myReceiver.flush(); // reset byte counter
+        assertEquals("MidiReceiver flush ", 0, myReceiver.byteCount);
+        myReceiver.send(bar, offset, count);
+        // Did we get all the data
+        assertEquals("MidiReceiver count ", count, myReceiver.byteCount);
+        for (int i = 0; i < count; i++) {
+            assertEquals("MidiReceiver byte " + i + " + " + offset,
+                    bar[i + offset], myReceiver.data[i]);
+        }
+    }
+}
diff --git a/tests/tests/media/src/android/media/cts/ParamsTest.java b/tests/tests/media/src/android/media/cts/ParamsTest.java
index 4e42004..5e32828 100644
--- a/tests/tests/media/src/android/media/cts/ParamsTest.java
+++ b/tests/tests/media/src/android/media/cts/ParamsTest.java
@@ -20,6 +20,7 @@
 
 import android.media.PlaybackParams;
 import android.media.SyncParams;
+import android.os.Parcel;
 import android.test.AndroidTestCase;
 
 /**
@@ -346,6 +347,28 @@
         }
     }
 
+    public void testPlaybackParamsDescribeContents() {
+        PlaybackParams p = new PlaybackParams();
+        assertEquals(0, p.describeContents());
+    }
 
+    public void testPlaybackParamsWriteToParcel() {
+        PlaybackParams p = new PlaybackParams();
+        p.setAudioFallbackMode(PlaybackParams.AUDIO_FALLBACK_MODE_FAIL);
+        p.setAudioStretchMode(PlaybackParams.AUDIO_STRETCH_MODE_VOICE);
+        p.setPitch(.5f);
+        p.setSpeed(.0001f);
+
+        Parcel parcel = Parcel.obtain();
+        p.writeToParcel(parcel, 0 /* flags */);
+        parcel.setDataPosition(0);
+        PlaybackParams q = PlaybackParams.CREATOR.createFromParcel(parcel);
+
+        assertEquals(p.getAudioFallbackMode(), q.getAudioFallbackMode());
+        assertEquals(p.getAudioStretchMode(), q.getAudioStretchMode());
+        assertEquals(p.getPitch(), q.getPitch());
+        assertEquals(p.getSpeed(), q.getSpeed());
+        parcel.recycle();
+    }
 
 }
diff --git a/tests/tests/media/src/android/media/cts/RoutingTest.java b/tests/tests/media/src/android/media/cts/RoutingTest.java
index fcb61dd..c0e9a3e 100644
--- a/tests/tests/media/src/android/media/cts/RoutingTest.java
+++ b/tests/tests/media/src/android/media/cts/RoutingTest.java
@@ -26,10 +26,15 @@
 import android.media.AudioTrack;
 import android.media.MediaRecorder;
 
+import android.os.Handler;
+import android.os.Looper;
+
 import android.test.AndroidTestCase;
 
 import android.util.Log;
 
+import java.lang.Runnable;
+
 /**
  * TODO: Insert description here. (generated by pmclean)
  */
@@ -47,17 +52,12 @@
         assertNotNull(mAudioManager);
     }
 
-    public void test_audioTrack_preferredDevice() {
-        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
-            // Can't do it so skip this test
-            return;
-        }
-
+    private AudioTrack allocAudioTrack() {
         int bufferSize =
-            AudioTrack.getMinBufferSize(
-                41000,
-                AudioFormat.CHANNEL_OUT_STEREO,
-                AudioFormat.ENCODING_PCM_16BIT);
+                AudioTrack.getMinBufferSize(
+                    41000,
+                    AudioFormat.CHANNEL_OUT_STEREO,
+                    AudioFormat.ENCODING_PCM_16BIT);
         AudioTrack audioTrack =
             new AudioTrack(
                 AudioManager.STREAM_MUSIC,
@@ -66,6 +66,16 @@
                 AudioFormat.ENCODING_PCM_16BIT,
                 bufferSize,
                 AudioTrack.MODE_STREAM);
+        return audioTrack;
+    }
+
+    public void test_audioTrack_preferredDevice() {
+        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
+            // Can't do it so skip this test
+            return;
+        }
+
+        AudioTrack audioTrack = allocAudioTrack();
         assertNotNull(audioTrack);
 
         // None selected (new AudioTrack), so check for default
@@ -76,7 +86,7 @@
 
         // test each device
         AudioDeviceInfo[] deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
-        for(int index = 0; index < deviceList.length; index++) {
+        for (int index = 0; index < deviceList.length; index++) {
             assertTrue(audioTrack.setPreferredDevice(deviceList[index]));
             assertTrue(audioTrack.getPreferredDevice() == deviceList[index]);
         }
@@ -84,6 +94,104 @@
         // Check defaults again
         assertTrue(audioTrack.setPreferredDevice(null));
         assertNull(audioTrack.getPreferredDevice());
+
+        audioTrack.release();
+    }
+
+    /*
+     * tests if the Looper for the current thread has been prepared,
+     * If not, it makes one, prepares it and returns it.
+     * If this returns non-null, the caller is reponsible for calling quit()
+     * on the returned Looper.
+     */
+    private Looper prepareIfNeededLooper() {
+        // non-null Handler
+        Looper myLooper = null;
+        if (Looper.myLooper() == null) {
+            Looper.prepare();
+            myLooper = Looper.myLooper();
+            assertNotNull(myLooper);
+        }
+        return myLooper;
+    }
+
+    private class AudioTrackRoutingListener implements AudioTrack.OnRoutingChangedListener {
+        public void onRoutingChanged(AudioTrack audioTrack) {}
+    }
+
+    public void test_audioTrack_RoutingListener() {
+        AudioTrack audioTrack = allocAudioTrack();
+
+        audioTrack.addOnRoutingChangedListener(null, null);
+
+        AudioTrackRoutingListener listener = new AudioTrackRoutingListener();
+        AudioTrackRoutingListener someOtherListener = new AudioTrackRoutingListener();
+
+        audioTrack.addOnRoutingChangedListener(listener, null);
+
+        // remove a listener we didn't add
+        audioTrack.removeOnRoutingChangedListener(someOtherListener);
+
+        audioTrack.removeOnRoutingChangedListener(listener);
+
+        Looper myLooper = prepareIfNeededLooper();
+        audioTrack.addOnRoutingChangedListener(listener, new Handler());
+
+        audioTrack.removeOnRoutingChangedListener(listener);
+
+        audioTrack.release();
+        if (myLooper != null) {
+            myLooper.quit();
+        }
+   }
+
+    private AudioRecord allocAudioRecord() {
+        int bufferSize =
+                AudioRecord.getMinBufferSize(
+                    41000,
+                    AudioFormat.CHANNEL_OUT_DEFAULT,
+                    AudioFormat.ENCODING_PCM_16BIT);
+        AudioRecord audioRecord =
+            new AudioRecord(
+                MediaRecorder.AudioSource.DEFAULT,
+                41000, AudioFormat.CHANNEL_OUT_DEFAULT,
+                AudioFormat.ENCODING_PCM_16BIT,
+                bufferSize);
+        return audioRecord;
+    }
+
+    private class AudioRecordRoutingListener implements AudioRecord.OnRoutingChangedListener {
+        public void onRoutingChanged(AudioRecord audioRecord) {}
+    }
+
+    public void test_audioRecord_RoutingListener() {
+        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) {
+            // Can't do it so skip this test
+            return;
+        }
+        AudioRecord audioRecord = allocAudioRecord();
+
+        audioRecord.addOnRoutingChangedListener(null, null);
+
+        AudioRecordRoutingListener listener = new AudioRecordRoutingListener();
+        AudioRecordRoutingListener someOtherListener = new AudioRecordRoutingListener();
+
+        audioRecord.addOnRoutingChangedListener(listener, null);
+
+        // remove a listener we didn't add
+        audioRecord.removeOnRoutingChangedListener(someOtherListener);
+
+        audioRecord.removeOnRoutingChangedListener(listener);
+
+        Looper myLooper = prepareIfNeededLooper();
+        audioRecord.addOnRoutingChangedListener(listener, new Handler());
+
+        audioRecord.removeOnRoutingChangedListener(listener);
+
+        audioRecord.release();
+        if (myLooper != null) {
+            myLooper.quit();
+        }
     }
 
     public void test_audioRecord_preferredDevice() {
@@ -92,17 +200,7 @@
             return;
         }
 
-        int bufferSize =
-            AudioRecord.getMinBufferSize(
-                41000,
-                AudioFormat.CHANNEL_OUT_DEFAULT,
-                AudioFormat.ENCODING_PCM_16BIT);
-        AudioRecord audioRecord =
-            new AudioRecord(
-                MediaRecorder.AudioSource.DEFAULT,
-                41000, AudioFormat.CHANNEL_OUT_DEFAULT,
-                AudioFormat.ENCODING_PCM_16BIT,
-                bufferSize);
+        AudioRecord audioRecord = allocAudioRecord();
         assertNotNull(audioRecord);
 
         // None selected (new AudioRecord), so check for default
@@ -113,7 +211,7 @@
 
         // test each device
         AudioDeviceInfo[] deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS);
-        for(int index = 0; index < deviceList.length; index++) {
+        for (int index = 0; index < deviceList.length; index++) {
             assertTrue(audioRecord.setPreferredDevice(deviceList[index]));
             assertTrue(audioRecord.getPreferredDevice() == deviceList[index]);
         }
@@ -121,5 +219,133 @@
         // Check defaults again
         assertTrue(audioRecord.setPreferredDevice(null));
         assertNull(audioRecord.getPreferredDevice());
+
+        audioRecord.release();
+    }
+
+    private class AudioTrackFiller implements Runnable {
+        AudioTrack mAudioTrack;
+        int mBufferSize;
+
+        boolean mPlaying;
+
+        short[] mAudioData;
+
+        public AudioTrackFiller(AudioTrack audioTrack, int bufferSize) {
+            mAudioTrack = audioTrack;
+            mBufferSize = bufferSize;
+            mPlaying = false;
+
+            // setup audio data (silence will suffice)
+            mAudioData = new short[mBufferSize];
+            for (int index = 0; index < mBufferSize; index++) {
+                mAudioData[index] = 0;
+            }
+        }
+
+        public void start() { mPlaying = true; }
+        public void stop() { mPlaying = false; }
+
+        @Override
+        public void run() {
+            while (mAudioTrack != null && mPlaying) {
+                mAudioTrack.write(mAudioData, 0, mBufferSize);
+            }
+        }
+    }
+
+    public void test_audioTrack_getRoutedDevice() {
+        int bufferSize =
+                AudioTrack.getMinBufferSize(
+                    41000,
+                    AudioFormat.CHANNEL_OUT_STEREO,
+                    AudioFormat.ENCODING_PCM_16BIT);
+        AudioTrack audioTrack =
+            new AudioTrack(
+                AudioManager.STREAM_MUSIC,
+                41000,
+                AudioFormat.CHANNEL_OUT_STEREO,
+                AudioFormat.ENCODING_PCM_16BIT,
+                bufferSize,
+                AudioTrack.MODE_STREAM);
+
+        AudioTrackFiller filler = new AudioTrackFiller(audioTrack, bufferSize);
+        filler.start();
+
+        audioTrack.play();
+
+        Thread fillerThread = new Thread(filler);
+        fillerThread.start();
+
+        try { Thread.sleep(1000); } catch (InterruptedException ex) {}
+
+        // No explicit route
+        AudioDeviceInfo routedDevice = audioTrack.getRoutedDevice();
+        assertNotNull(routedDevice); // we probably can't say anything more than this
+
+        filler.stop();
+        audioTrack.stop();
+        audioTrack.release();
+    }
+
+    private class AudioRecordPuller implements Runnable {
+        AudioRecord mAudioRecord;
+        int mBufferSize;
+
+        boolean mRecording;
+
+        short[] mAudioData;
+
+        public AudioRecordPuller(AudioRecord audioRecord, int bufferSize) {
+            mAudioRecord = audioRecord;
+            mBufferSize = bufferSize;
+            mRecording = false;
+        }
+
+        public void start() { mRecording = true; }
+        public void stop() { mRecording = false; }
+
+        @Override
+        public void run() {
+            while (mAudioRecord != null && mRecording) {
+                mAudioRecord.read(mAudioData, 0, mBufferSize);
+           }
+        }
+    }
+
+    public void test_audioRecord_getRoutedDevice() {
+        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) {
+            return;
+        }
+
+        int bufferSize =
+                AudioRecord.getMinBufferSize(
+                    41000,
+                    AudioFormat.CHANNEL_OUT_DEFAULT,
+                    AudioFormat.ENCODING_PCM_16BIT);
+        AudioRecord audioRecord =
+            new AudioRecord(
+                MediaRecorder.AudioSource.DEFAULT,
+                41000, AudioFormat.CHANNEL_OUT_DEFAULT,
+                AudioFormat.ENCODING_PCM_16BIT,
+                bufferSize);
+
+        AudioRecordPuller puller = new AudioRecordPuller(audioRecord, bufferSize);
+        puller.start();
+
+        audioRecord.startRecording();
+
+        Thread pullerThread = new Thread(puller);
+        pullerThread.start();
+
+        try { Thread.sleep(1000); } catch (InterruptedException ex) {}
+
+        // No explicit route
+        AudioDeviceInfo routedDevice = audioRecord.getRoutedDevice();
+        assertNotNull(routedDevice); // we probably can't say anything more than this
+
+        puller.stop();
+        audioRecord.stop();
+        audioRecord.release();
     }
 }
diff --git a/tests/tests/media/src/android/media/cts/StubMediaBrowserService.java b/tests/tests/media/src/android/media/cts/StubMediaBrowserService.java
index d559c72..bfd6db7 100644
--- a/tests/tests/media/src/android/media/cts/StubMediaBrowserService.java
+++ b/tests/tests/media/src/android/media/cts/StubMediaBrowserService.java
@@ -16,11 +16,13 @@
 
 package android.media.cts;
 
+import android.media.MediaDescription;
 import android.media.browse.MediaBrowser.MediaItem;
 import android.media.session.MediaSession;
 import android.os.Bundle;
 import android.service.media.MediaBrowserService;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -30,6 +32,10 @@
     static final String MEDIA_ID_ROOT = "test_media_id_root";
     static final String EXTRAS_KEY = "test_extras_key";
     static final String EXTRAS_VALUE = "test_extras_value";
+    static final String[] MEDIA_ID_CHILDREN = new String[] {
+        "test_media_id_children_0", "test_media_id_children_1",
+        "test_media_id_children_2", "test_media_id_children_3"
+    };
 
     /* package private */ static MediaSession sSession;
     private Bundle mExtras;
@@ -50,5 +56,13 @@
 
     @Override
     public void onLoadChildren(final String parentMediaId, final Result<List<MediaItem>> result) {
+        List<MediaItem> mediaItems = new ArrayList<>();
+        if (MEDIA_ID_ROOT.equals(parentMediaId)) {
+            for (String id : MEDIA_ID_CHILDREN) {
+                mediaItems.add(new MediaItem(new MediaDescription.Builder()
+                        .setMediaId(id).build(), MediaItem.FLAG_BROWSABLE));
+            }
+        }
+        result.sendResult(mediaItems);
     }
 }
diff --git a/tests/tests/os/src/android/os/cts/MessageQueueTest.java b/tests/tests/os/src/android/os/cts/MessageQueueTest.java
index 8906c42..0c051bf 100644
--- a/tests/tests/os/src/android/os/cts/MessageQueueTest.java
+++ b/tests/tests/os/src/android/os/cts/MessageQueueTest.java
@@ -25,6 +25,8 @@
 import android.os.ParcelFileDescriptor;
 import android.os.ParcelFileDescriptor.AutoCloseInputStream;
 import android.os.ParcelFileDescriptor.AutoCloseOutputStream;
+import android.system.ErrnoException;
+import android.system.Os;
 import android.os.SystemClock;
 import android.os.MessageQueue.IdleHandler;
 import android.test.AndroidTestCase;
@@ -66,7 +68,7 @@
         }
     }
 
-    private enum Test {ADD_IDLE_HANDLER, REMOVE_IDLE_HANDLER};
+    private enum Test {ADD_IDLE_HANDLER, REMOVE_IDLE_HANDLER}
 
     /**
      * {@link HandlerThread} that adds or removes an idle handler depending on the {@link Test}
@@ -91,6 +93,7 @@
             super.onLooperPrepared();
 
             IdleHandler idleHandler = new IdleHandler() {
+                @Override
                 public boolean queueIdle() {
                     mIdleLatch.countDown();
                     return false;
@@ -168,6 +171,7 @@
     public void testMessageOrder() throws Exception {
 
         OrderTestHelper tester = new OrderTestHelper() {
+            @Override
             public void init() {
                 super.init();
                 long now = SystemClock.uptimeMillis() + 200;
@@ -191,6 +195,7 @@
 
         OrderTestHelper tester = new OrderTestHelper() {
 
+            @Override
             public void init() {
                 super.init();
                 long now = SystemClock.uptimeMillis() + 200;
@@ -200,6 +205,7 @@
                 mHandler.sendMessageAtFrontOfQueue(mHandler.obtainMessage(0));
             }
 
+            @Override
             public void handleMessage(Message msg) {
                 super.handleMessage(msg);
                 if (msg.what == 0) {
@@ -386,9 +392,9 @@
      * edge cases around closing file descriptors within the callback and adding
      * new ones with the same number.
      *
-     * Register a file descriptor, close it from within the callback before
-     * returning, return.  Then create a new file descriptor (with the same number),
-     * register it.  Ensure that we start getting events for the new file descriptor.
+     * Register a file descriptor, close it from within the callback, then return.
+     * Later, create a new file descriptor register it.  Ensure that we start getting
+     * events for the new file descriptor.
      *
      * This test exercises special logic in Looper.cpp for EPOLL_CTL_DEL handling EBADF.
      */
@@ -401,23 +407,19 @@
             final Handler handler = new Handler(thread.getLooper());
 
             final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
-            final int oldReaderFd = pipe[0].getFd();
             try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
                     final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
                 // Register the callback.
-                final boolean[] awoke = new boolean[1];
+                final CountDownLatch awoke = new CountDownLatch(1);
                 queue.addOnFileDescriptorEventListener(reader.getFD(),
-                        OnFileDescriptorEventListener.EVENT_ERROR, new OnFileDescriptorEventListener() {
+                        OnFileDescriptorEventListener.EVENT_ERROR,
+                        new OnFileDescriptorEventListener() {
                     @Override
                     public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                        awoke[0] = true;
+                        awoke.countDown();
 
-                        // Close the file descriptor before we return.
-                        try {
-                            reader.close();
-                        } catch (IOException ex) {
-                            throw new RuntimeException(ex);
-                        }
+                        // Close the reader before we return.
+                        closeQuietly(reader);
 
                         // Return 0 to unregister the callback.
                         return 0;
@@ -428,26 +430,23 @@
                 writer.close();
 
                 // Wait for the looper to catch up and run the callback.
+                assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
                 syncWait(handler);
-                assertTrue(awoke[0]);
             }
 
             // At this point, the reader and writer are both closed.
-            // If we're lucky, we can create a new pipe with the same file
-            // descriptor numbers as before.
+            // Make a new pipe and ensure that things still work as expected.
             final ParcelFileDescriptor[] pipe2 = ParcelFileDescriptor.createPipe();
-            assertEquals("Expected new pipe to be created with same fd number as "
-                    + "previous pipe we just closed for the purpose of this test.",
-                    oldReaderFd, pipe2[0].getFd());
             try (final FileInputStream reader2 = new AutoCloseInputStream(pipe2[0]);
                     final FileOutputStream writer2 = new AutoCloseOutputStream(pipe2[1])) {
                 // Register the callback.
-                final boolean[] awoke = new boolean[1];
+                final CountDownLatch awoke = new CountDownLatch(1);
                 queue.addOnFileDescriptorEventListener(reader2.getFD(),
-                        OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {
+                        OnFileDescriptorEventListener.EVENT_INPUT,
+                        new OnFileDescriptorEventListener() {
                     @Override
                     public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                        awoke[0] = true;
+                        awoke.countDown();
 
                         // Return 0 to unregister the callback.
                         return 0;
@@ -458,8 +457,8 @@
                 writer2.close();
 
                 // Wait for the looper to catch up and run the callback.
+                assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
                 syncWait(handler);
-                assertTrue(awoke[0]);
             }
         } finally {
             thread.quitAndRethrow();
@@ -471,10 +470,10 @@
      * edge cases around closing file descriptors within the callback and adding
      * new ones with the same number.
      *
-     * Register a file descriptor, close it from within the callback before
-     * returning, create a new file descriptor (with the same number) and return.
-     * Then register the same file descriptor.  Ensure that we start getting events for
-     * the new file descriptor.
+     * Register a file descriptor, close it from within the callback, reassign its
+     * number to a different pipe, then return.  Later, register the same file descriptor
+     * again (now referring to a new pipe).  Ensure that we start getting
+     * events for the new file descriptor.
      *
      * This test exercises special logic in Looper.cpp for EPOLL_CTL_DEL handling ENOENT.
      */
@@ -487,69 +486,67 @@
             final Handler handler = new Handler(thread.getLooper());
 
             final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
-            final int oldReaderFd = pipe[0].getFd();
-            try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
-                    final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
-                // Register the callback.
-                final boolean[] awoke = new boolean[1];
-                queue.addOnFileDescriptorEventListener(reader.getFD(),
-                        OnFileDescriptorEventListener.EVENT_ERROR, new OnFileDescriptorEventListener() {
-                    @Override
-                    public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                        awoke[0] = true;
+            final ParcelFileDescriptor[] pipe2 = ParcelFileDescriptor.createPipe();
+            try {
+                final int oldReaderFd = pipe[0].getFd();
+                try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
+                        final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
+                    // Register the callback.
+                    final CountDownLatch awoke = new CountDownLatch(1);
+                    queue.addOnFileDescriptorEventListener(reader.getFD(),
+                            OnFileDescriptorEventListener.EVENT_ERROR,
+                            new OnFileDescriptorEventListener() {
+                        @Override
+                        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
+                            awoke.countDown();
 
-                        try {
-                            // Close the file descriptor before we return.
-                            reader.close();
+                            // Close the reader before we return and hijack its fd.
+                            hijackFd(pipe2, pipe);
 
-                            // At this point, the reader and writer are both closed.
-                            // Assuming no one else has created a file descriptor in the meantime,
-                            // when we recreate the pipe we will get the same number as before.
-                            final ParcelFileDescriptor[] pipe2 = ParcelFileDescriptor.createPipe();
-                            assertEquals("Expected new pipe to be created with same fd number as "
-                                    + "previous pipe we just closed for the purpose of this test.",
-                                    oldReaderFd, pipe2[0].getFd());
-                            pipe[0] = pipe2[0];
-                            pipe[1] = pipe2[1];
-                        } catch (IOException ex) {
-                            throw new RuntimeException(ex);
+                            // Return 0 to unregister the callback.
+                            return 0;
                         }
+                    });
 
-                        // Return 0 to unregister the callback.
-                        return 0;
-                    }
-                });
+                    // Close the writer to wake up the callback (due to hangup).
+                    writer.close();
 
-                // Close the writer to wake up the callback (due to hangup).
-                writer.close();
+                    // Wait for the looper to catch up and run the callback.
+                    assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
+                    syncWait(handler);
+                }
 
-                // Wait for the looper to catch up and run the callback.
-                syncWait(handler);
-                assertTrue(awoke[0]);
-            }
+                // Now we have a new pipe with the same file descriptor, make sure we can
+                // register it successfully.
+                assertEquals(oldReaderFd, pipe2[0].getFd());
+                try (final FileInputStream reader2 = new AutoCloseInputStream(pipe2[0]);
+                        final FileOutputStream writer2 = new AutoCloseOutputStream(pipe2[1])) {
+                    // Register the callback.
+                    final CountDownLatch awoke = new CountDownLatch(1);
+                    queue.addOnFileDescriptorEventListener(reader2.getFD(),
+                            OnFileDescriptorEventListener.EVENT_INPUT,
+                            new OnFileDescriptorEventListener() {
+                        @Override
+                        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
+                            awoke.countDown();
 
-            // Now we have a new pipe, make sure we can register it successfully.
-            try (final FileInputStream reader2 = new AutoCloseInputStream(pipe[0]);
-                    final FileOutputStream writer2 = new AutoCloseOutputStream(pipe[1])) {
-                // Register the callback.
-                final boolean[] awoke = new boolean[1];
-                queue.addOnFileDescriptorEventListener(reader2.getFD(),
-                        OnFileDescriptorEventListener.EVENT_INPUT, new OnFileDescriptorEventListener() {
-                    @Override
-                    public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                        awoke[0] = true;
+                            // Return 0 to unregister the callback.
+                            return 0;
+                        }
+                    });
 
-                        // Return 0 to unregister the callback.
-                        return 0;
-                    }
-                });
+                    // Close the writer to wake up the callback (due to hangup).
+                    writer2.close();
 
-                // Close the writer to wake up the callback (due to hangup).
-                writer2.close();
-
-                // Wait for the looper to catch up and run the callback.
-                syncWait(handler);
-                assertTrue(awoke[0]);
+                    // Wait for the looper to catch up and run the callback.
+                    assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
+                    syncWait(handler);
+                }
+            } finally {
+                closeQuietly(pipe[0]);
+                closeQuietly(pipe[1]);
+                closeQuietly(pipe2[0]);
+                closeQuietly(pipe2[1]);
             }
         } finally {
             thread.quitAndRethrow();
@@ -561,10 +558,9 @@
      * edge cases around closing file descriptors within the callback and adding
      * new ones with the same number.
      *
-     * Register a file descriptor, close it from within the callback before
-     * returning, create a new file descriptor (with the same number),
-     * register it, and return.  Ensure that we start getting events for the
-     * new file descriptor.
+     * Register a file descriptor, close it from within the callback, reassign its
+     * number to a different pipe, register it, then return.
+     * Ensure that we start getting events for the new file descriptor.
      *
      * This test exercises special logic in Looper.cpp for EPOLL_CTL_MOD handling
      * ENOENT and fallback to EPOLL_CTL_ADD as well as sequence number checks when removing
@@ -579,71 +575,66 @@
             final Handler handler = new Handler(thread.getLooper());
 
             final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
-            final boolean[] awoke2 = new boolean[1];
-            final int oldReaderFd = pipe[0].getFd();
-            try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
-                    final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
-                // Register the callback.
-                final boolean[] awoke = new boolean[1];
-                queue.addOnFileDescriptorEventListener(reader.getFD(),
-                        OnFileDescriptorEventListener.EVENT_ERROR, new OnFileDescriptorEventListener() {
-                    @Override
-                    public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                        awoke[0] = true;
+            final ParcelFileDescriptor[] pipe2 = ParcelFileDescriptor.createPipe();
+            try {
+                final CountDownLatch awoke2 = new CountDownLatch(1);
+                final int oldReaderFd = pipe[0].getFd();
+                try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
+                        final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
+                    // Register the callback.
+                    final CountDownLatch awoke = new CountDownLatch(1);
+                    queue.addOnFileDescriptorEventListener(reader.getFD(),
+                            OnFileDescriptorEventListener.EVENT_ERROR,
+                            new OnFileDescriptorEventListener() {
+                        @Override
+                        public int onFileDescriptorEvents(FileDescriptor fd, int events) {
+                            awoke.countDown();
 
-                        final ParcelFileDescriptor[] pipe2;
-                        try {
-                            // Close the file descriptor before we return.
-                            reader.close();
+                            // Close the reader before we return and hijack its fd.
+                            hijackFd(pipe2, pipe);
 
-                            // At this point, the reader and writer are both closed.
-                            // Assuming no one else has created a file descriptor in the meantime,
-                            // when we recreate the pipe we will get the same number as before.
-                            pipe2 = ParcelFileDescriptor.createPipe();
-                            assertEquals("Expected new pipe to be created with same fd number as "
-                                    + "previous pipe we just closed for the purpose of this test.",
-                                    oldReaderFd, pipe2[0].getFd());
-                            pipe[0] = pipe2[0];
-                            pipe[1] = pipe2[1];
-                        } catch (IOException ex) {
-                            throw new RuntimeException(ex);
+                            // Now we have a new pipe, make sure we can register it successfully.
+                            queue.addOnFileDescriptorEventListener(pipe2[0].getFileDescriptor(),
+                                    OnFileDescriptorEventListener.EVENT_INPUT,
+                                    new OnFileDescriptorEventListener() {
+                                @Override
+                                public int onFileDescriptorEvents(FileDescriptor fd, int events) {
+                                    awoke2.countDown();
+
+                                    // Return 0 to unregister the callback.
+                                    return 0;
+                                }
+                            });
+
+                            // Return 0 to unregister the callback.
+                            return 0;
                         }
+                    });
 
-                        // Now we have a new pipe, make sure we can register it successfully.
-                        queue.addOnFileDescriptorEventListener(pipe[0].getFileDescriptor(),
-                                OnFileDescriptorEventListener.EVENT_INPUT,
-                                new OnFileDescriptorEventListener() {
-                            @Override
-                            public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                                awoke2[0] = true;
+                    // Close the writer to wake up the callback (due to hangup).
+                    writer.close();
 
-                                // Return 0 to unregister the callback.
-                                return 0;
-                            }
-                        });
+                    // Wait for the looper to catch up and run the callback.
+                    assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
+                    syncWait(handler);
+                }
 
-                        // Return 0 to unregister the callback.
-                        return 0;
-                    }
-                });
-
-                // Close the writer to wake up the callback (due to hangup).
-                writer.close();
+                // Close the second writer to wake up the second callback (due to hangup).
+                pipe2[1].close();
 
                 // Wait for the looper to catch up and run the callback.
+                assertTrue("awoke2", awoke2.await(TIMEOUT, TimeUnit.MILLISECONDS));
                 syncWait(handler);
-                assertTrue(awoke[0]);
+
+                // Close the second reader now that we're done with the test.
+                assertEquals(oldReaderFd, pipe2[0].getFd());
+                pipe2[0].close();
+            } finally {
+                closeQuietly(pipe[0]);
+                closeQuietly(pipe[1]);
+                closeQuietly(pipe2[0]);
+                closeQuietly(pipe2[1]);
             }
-
-            // Close the second writer to wake up the second callback (due to hangup).
-            pipe[1].close();
-
-            // Wait for the looper to catch up and run the callback.
-            syncWait(handler);
-            assertTrue(awoke2[0]);
-
-            // Close the second reader now that we're done with the test.
-            pipe[0].close();
         } finally {
             thread.quitAndRethrow();
         }
@@ -655,7 +646,7 @@
      * new ones with the same number.
      *
      * Register a file descriptor, make a duplicate of it, close it from within the
-     * callback before returning, return.  Look for signs that the Looper is spinning
+     * callback, then return.  Look for signs that the Looper is spinning
      * and never getting a chance to block.
      *
      * This test exercises special logic in Looper.cpp for rebuilding the epoll set
@@ -676,12 +667,12 @@
                 try (final FileInputStream reader = new AutoCloseInputStream(pipe[0]);
                         final FileOutputStream writer = new AutoCloseOutputStream(pipe[1])) {
                     // Register the callback.
-                    final boolean[] awoke = new boolean[1];
+                    final CountDownLatch awoke = new CountDownLatch(1);
                     queue.addOnFileDescriptorEventListener(reader.getFD(),
                             OnFileDescriptorEventListener.EVENT_ERROR, new OnFileDescriptorEventListener() {
                         @Override
                         public int onFileDescriptorEvents(FileDescriptor fd, int events) {
-                            awoke[0] = true;
+                            awoke.countDown();
 
                             // Close the file descriptor before we return.
                             try {
@@ -699,8 +690,8 @@
                     writer.close();
 
                     // Wait for the looper to catch up and run the callback.
+                    assertTrue("awoke", awoke.await(TIMEOUT, TimeUnit.MILLISECONDS));
                     syncWait(handler);
-                    assertTrue(awoke[0]);
                 }
 
                 // Wait a little bit before we stop the thread.
@@ -729,6 +720,7 @@
             private int mBarrierToken1;
             private int mBarrierToken2;
 
+            @Override
             public void init() {
                 super.init();
                 mLastMessage = 10;
@@ -741,6 +733,7 @@
                 mHandler.sendEmptyMessage(6);
             }
 
+            @Override
             public void handleMessage(Message msg) {
                 super.handleMessage(msg);
                 if (msg.what == 3) {
@@ -797,7 +790,35 @@
                 latch.countDown();
             }
         });
-        latch.await(TIMEOUT, TimeUnit.MILLISECONDS);
+        assertTrue("Handler got stuck.", latch.await(TIMEOUT, TimeUnit.MILLISECONDS));
+    }
+
+    private static void closeQuietly(AutoCloseable c) {
+        if (c != null) {
+            try {
+                c.close();
+            } catch (RuntimeException rethrown) {
+                throw rethrown;
+            } catch (Exception ex) {
+            }
+        }
+    }
+
+    private static void hijackFd(ParcelFileDescriptor[] newPipe, ParcelFileDescriptor[] oldPipe) {
+        // Detach the old pipe's first fd and get its number.
+        int fd = oldPipe[0].detachFd();
+
+        // Assign the new pipe's first fd to the same number as the old pipe's first fd.
+        // This causes the old pipe's first fd to be closed and reassigned.
+        try {
+            Os.dup2(newPipe[0].getFileDescriptor(), fd);
+        } catch (ErrnoException ex) {
+            throw new RuntimeException(ex);
+        }
+
+        // Fix up the new pipe's first fd object.
+        closeQuietly(newPipe[0]);
+        newPipe[0] = ParcelFileDescriptor.adoptFd(fd);
     }
 
     /**
@@ -814,6 +835,7 @@
 
         public void init() {
             mHandler = new Handler() {
+                @Override
                 public void handleMessage(Message msg) {
                     OrderTestHelper.this.handleMessage(msg);
                 }
@@ -863,6 +885,7 @@
                 super("MessengerLooperThread");
             }
 
+            @Override
             public void onLooperPrepared() {
                 init();
                 mLooper = getLooper();
@@ -908,7 +931,7 @@
      * A HandlerThread that propagates exceptions out of the event loop
      * instead of crashing the process.
      */
-    private class AssertableHandlerThread extends HandlerThread {
+    private static class AssertableHandlerThread extends HandlerThread {
         private Throwable mThrowable;
         private long mRuntime;
 
diff --git a/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java b/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
index 51e54df..984fd6c 100644
--- a/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
+++ b/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
@@ -16,12 +16,7 @@
 
 package android.permission.cts;
 
-import android.os.RemoteException;
-import android.content.ContentProviderClient;
-import android.content.ContentResolver;
 import android.content.ContentValues;
-import android.database.Cursor;
-import android.provider.Contacts;
 import android.provider.ContactsContract;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
@@ -71,7 +66,7 @@
      * Verifies that query(ContactsContract.Profile.CONTENT_URI) requires
      * Permission.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#READ_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#READ_CONTACTS}.
      */
     @SmallTest
     public void testQueryProfile() {
@@ -91,7 +86,7 @@
      * permission, but trying to do it without the permission should throw a
      * SecurityException anyway.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#WRITE_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#WRITE_CONTACTS}.
      */
     @SmallTest
     public void testInsertProfile() {
@@ -109,7 +104,7 @@
      * Verifies that update(ContactsContract.Profile.CONTENT_URI) requires
      * Permission.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#WRITE_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#WRITE_CONTACTS}.
      */
     @SmallTest
     public void testUpdateProfile() {
@@ -122,4 +117,41 @@
             // Expected Exception
         }
     }
+
+    /**
+    * Verifies that query(ContactsContract.CommonDataKinds.Phone.ENTERPRISE_CONTENT_URI) requires
+    * Permission.
+    * <p>
+    * Requires Permission: {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
+    */
+    @SmallTest
+    public void testQueryPhoneEnterprise() {
+        try {
+            getContext().getContentResolver().query(
+                    ContactsContract.CommonDataKinds.Phone.ENTERPRISE_CONTENT_URI,
+                    null, null, null, null);
+            fail("query(ContactsContract.CommonDataKinds.Phone.ENTERPRISE_CONTENT_URI) did not"
+                    + " throw SecurityException as expected");
+        } catch (SecurityException se) {
+            // Expected Exception
+        }
+    }
+
+    /**
+    * Verifies that query(ContactsContract.RawContactsEntity.CORP_CONTENT_URI) requires
+    * Permission.
+    * <p>
+    * Requires Permission: {@link android.Manifest.permission#INTERACT_ACROSS_USERS}.
+    */
+    @SmallTest
+    public void testRawContactsEntityCorp() {
+        try {
+            getContext().getContentResolver().query(
+                    ContactsContract.RawContactsEntity.CORP_CONTENT_URI, null, null, null, null);
+            fail("query(ContactsContract.RawContactsEntity.CORP_CONTENT_URI) did not throw"
+                    + " SecurityException as expected");
+        } catch (SecurityException se) {
+            // Expected Exception
+        }
+    }
 }
diff --git a/tests/tests/permission2/AndroidManifest.xml b/tests/tests/permission2/AndroidManifest.xml
index c0b78c4..984d124 100755
--- a/tests/tests/permission2/AndroidManifest.xml
+++ b/tests/tests/permission2/AndroidManifest.xml
@@ -45,6 +45,12 @@
     <!-- need app that has RECORD_AUDIO but not CAPTURE_AUDIO_OUTPUT -->
     <uses-permission android:name="android.permission.RECORD_AUDIO"/>
 
+    <!-- need app that has READ_CONTACTS but not READ_PROFILE -->
+    <uses-permission android:name="android.permission.READ_CONTACTS"/>
+
+    <!-- need app that has WRITE_CONTACTS but not WRITE_PROFILE -->
+    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
+
     <!-- need a permission that would ordinarily be granted, but has a maxSdkVersion that
          causes it to be withheld under the current API level -->
     <uses-permission
diff --git a/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java b/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java
new file mode 100644
index 0000000..5a04079
--- /dev/null
+++ b/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 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.permission2.cts;
+
+import android.content.ContentValues;
+import android.provider.ContactsContract;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Verify that deprecated contacts permissions are not enforced.
+ */
+public class ContactsProviderTest extends AndroidTestCase {
+
+    /**
+     * Verifies that query(ContactsContract.Contacts.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#READ_CONTACTS}.
+     */
+    @SmallTest
+    public void testQueryContacts() {
+        getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
+                null, null, null, null);
+    }
+
+    /**
+     * Verifies that insert(ContactsContract.Contacts.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}.
+     */
+    @SmallTest
+    public void testInsertContacts() {
+        try {
+            getContext().getContentResolver().insert(ContactsContract.Contacts.CONTENT_URI,
+                    new ContentValues());
+        } catch (SecurityException e) {
+            fail("insert(ContactsContract.Contacts.CONTENT_URI) threw SecurityException");
+        } catch (UnsupportedOperationException e) {
+            // It is okay for this fail in this manner.
+        }
+    }
+
+    /**
+     * Verifies that query(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#READ_CONTACTS}.
+     */
+    @SmallTest
+    public void testQueryProfile() {
+        getContext().getContentResolver().query(ContactsContract.Profile.CONTENT_URI,
+                null, null, null, null);
+    }
+
+    /**
+     * Verifies that insert(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}. The provider won't
+     * actually let us execute this. But at least it shouldn't throw a security exception.
+     */
+    @SmallTest
+    public void testInsertProfile() {
+     try {
+         getContext().getContentResolver().insert(ContactsContract.Profile.CONTENT_URI,
+                new ContentValues(0));
+        } catch (SecurityException e) {
+            fail("insert(ContactsContract.Profile.CONTENT_URI) threw SecurityException");
+        } catch (UnsupportedOperationException e) {
+            // It is okay for this fail in this manner.
+        }
+    }
+
+    /**
+     * Verifies that update(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}.
+     */
+    @SmallTest
+    public void testUpdateProfile() {
+        getContext().getContentResolver().update(ContactsContract.Profile.CONTENT_URI,
+                new ContentValues(0), null, null);
+    }
+}
diff --git a/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java b/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
index c17583f..9f1e3a5 100644
--- a/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
+++ b/tests/tests/print/src/android/print/cts/PrintDocumentAdapterContractTest.java
@@ -160,6 +160,7 @@
                 .setResolution(new Resolution("300x300", "300x300", 300, 300))
                 .setMinMargins(Margins.NO_MARGINS)
                 .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setDuplexMode(PrintAttributes.DUPLEX_MODE_LONG_EDGE)
                 .build();
         verifyLayoutCall(inOrder, adapter, secondOldAttributes, secondNewAttributes, true);
 
@@ -588,6 +589,7 @@
                 .setResolution(new Resolution("PDF resolution", "PDF resolution", 300, 300))
                 .setMinMargins(new Margins(0, 0, 0, 0))
                 .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setDuplexMode(PrintAttributes.DUPLEX_MODE_LONG_EDGE)
                 .build();
         verifyLayoutCall(inOrder, adapter, secondOldAttributes, secondNewAttributes, true);
 
@@ -598,6 +600,7 @@
                 .setResolution(new Resolution("PDF resolution", "PDF resolution", 300, 300))
                 .setMinMargins(new Margins(0, 0, 0, 0))
                 .setColorMode(PrintAttributes.COLOR_MODE_MONOCHROME)
+                .setDuplexMode(PrintAttributes.DUPLEX_MODE_LONG_EDGE)
                 .build();
         verifyLayoutCall(inOrder, adapter, thirdOldAttributes, thirdNewAttributes, true);
 
@@ -729,7 +732,9 @@
         PrintAttributes secondNewAttributes = new PrintAttributes.Builder()
                 .setMediaSize(MediaSize.ISO_A3)
                 .setResolution(new Resolution("300x300", "300x300", 300, 300))
-                .setMinMargins(Margins.NO_MARGINS).setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setMinMargins(Margins.NO_MARGINS)
+                .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setDuplexMode(PrintAttributes.DUPLEX_MODE_LONG_EDGE)
                 .build();
         verifyLayoutCall(inOrder, adapter, secondOldAttributes, secondNewAttributes, true);
 
@@ -960,7 +965,9 @@
         PrintAttributes secondNewAttributes = new PrintAttributes.Builder()
                 .setMediaSize(MediaSize.ISO_A3)
                 .setResolution(new Resolution("300x300", "300x300", 300, 300))
-                .setMinMargins(Margins.NO_MARGINS).setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setMinMargins(Margins.NO_MARGINS)
+                .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
+                .setDuplexMode(PrintAttributes.DUPLEX_MODE_LONG_EDGE)
                 .build();
         verifyLayoutCall(inOrder, adapter, secondOldAttributes, secondNewAttributes, true);
 
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsContract_ContactsTest.java b/tests/tests/provider/src/android/provider/cts/ContactsContract_ContactsTest.java
index d16cb9d..f8f610a 100644
--- a/tests/tests/provider/src/android/provider/cts/ContactsContract_ContactsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/ContactsContract_ContactsTest.java
@@ -27,6 +27,7 @@
 import android.net.Uri;
 import android.os.SystemClock;
 import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.StructuredName;
 import android.provider.ContactsContract.Contacts;
 import android.provider.cts.ContactsContract_TestDataBuilder.TestContact;
 import android.provider.cts.ContactsContract_TestDataBuilder.TestRawContact;
@@ -167,6 +168,74 @@
         RawContactUtil.delete(mResolver, ids.mRawContactId, true);
     }
 
+    public void testProjection() throws Exception {
+        final TestRawContact rawContact = mBuilder.newRawContact().insert().load();
+        rawContact.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
+                .with(StructuredName.GIVEN_NAME, "xxx")
+                .insert();
+
+        final TestContact contact = rawContact.getContact().load();
+        final long contactId = contact.getId();
+        final String lookupKey = contact.getString(Contacts.LOOKUP_KEY);
+
+        final String[] PROJECTION = new String[]{
+                Contacts._ID,
+                Contacts.DISPLAY_NAME,
+                Contacts.DISPLAY_NAME_PRIMARY,
+                Contacts.DISPLAY_NAME_ALTERNATIVE,
+                Contacts.DISPLAY_NAME_SOURCE,
+                Contacts.PHONETIC_NAME,
+                Contacts.PHONETIC_NAME_STYLE,
+                Contacts.SORT_KEY_PRIMARY,
+                Contacts.SORT_KEY_ALTERNATIVE,
+                Contacts.LAST_TIME_CONTACTED,
+                Contacts.TIMES_CONTACTED,
+                Contacts.STARRED,
+                Contacts.PINNED,
+                Contacts.IN_DEFAULT_DIRECTORY,
+                Contacts.IN_VISIBLE_GROUP,
+                Contacts.PHOTO_ID,
+                Contacts.PHOTO_FILE_ID,
+                Contacts.PHOTO_URI,
+                Contacts.PHOTO_THUMBNAIL_URI,
+                Contacts.CUSTOM_RINGTONE,
+                Contacts.HAS_PHONE_NUMBER,
+                Contacts.SEND_TO_VOICEMAIL,
+                Contacts.IS_USER_PROFILE,
+                Contacts.LOOKUP_KEY,
+                Contacts.NAME_RAW_CONTACT_ID,
+                Contacts.CONTACT_PRESENCE,
+                Contacts.CONTACT_CHAT_CAPABILITY,
+                Contacts.CONTACT_STATUS,
+                Contacts.CONTACT_STATUS_TIMESTAMP,
+                Contacts.CONTACT_STATUS_RES_PACKAGE,
+                Contacts.CONTACT_STATUS_LABEL,
+                Contacts.CONTACT_STATUS_ICON,
+                Contacts.CONTACT_LAST_UPDATED_TIMESTAMP
+        };
+
+        // Contacts.CONTENT_URI
+        DatabaseAsserts.checkProjection(mResolver,
+                Contacts.CONTENT_URI,
+                PROJECTION,
+                new long[]{contact.getId()}
+        );
+
+        // Contacts.CONTENT_FILTER_URI
+        DatabaseAsserts.checkProjection(mResolver,
+                Contacts.CONTENT_FILTER_URI.buildUpon().appendEncodedPath("xxx").build(),
+                PROJECTION,
+                new long[]{contact.getId()}
+        );
+
+        // Contacts.CONTENT_LOOKUP_URI
+        DatabaseAsserts.checkProjection(mResolver,
+                Contacts.getLookupUri(contactId, lookupKey),
+                PROJECTION,
+                new long[]{contact.getId()}
+        );
+    }
+
     /**
      * Create a contact.  Delete it.  And assert that the contact record is no longer present.
      *
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsContract_FrequentsStrequentsTest.java b/tests/tests/provider/src/android/provider/cts/ContactsContract_FrequentsStrequentsTest.java
index b515550..b52915c 100644
--- a/tests/tests/provider/src/android/provider/cts/ContactsContract_FrequentsStrequentsTest.java
+++ b/tests/tests/provider/src/android/provider/cts/ContactsContract_FrequentsStrequentsTest.java
@@ -48,6 +48,85 @@
     private ContentResolver mResolver;
     private ContactsContract_TestDataBuilder mBuilder;
 
+    private static final String[] STREQUENT_PROJECTION = new String[]{
+            Contacts._ID,
+            Contacts.HAS_PHONE_NUMBER,
+            Contacts.NAME_RAW_CONTACT_ID,
+            Contacts.IS_USER_PROFILE,
+            Contacts.CUSTOM_RINGTONE,
+            Contacts.DISPLAY_NAME,
+            Contacts.DISPLAY_NAME_ALTERNATIVE,
+            Contacts.DISPLAY_NAME_SOURCE,
+            Contacts.IN_DEFAULT_DIRECTORY,
+            Contacts.IN_VISIBLE_GROUP,
+            Contacts.LAST_TIME_CONTACTED,
+            Contacts.LOOKUP_KEY,
+            Contacts.PHONETIC_NAME,
+            Contacts.PHONETIC_NAME_STYLE,
+            Contacts.PHOTO_ID,
+            Contacts.PHOTO_FILE_ID,
+            Contacts.PHOTO_URI,
+            Contacts.PHOTO_THUMBNAIL_URI,
+            Contacts.SEND_TO_VOICEMAIL,
+            Contacts.SORT_KEY_ALTERNATIVE,
+            Contacts.SORT_KEY_PRIMARY,
+            Contacts.STARRED,
+            Contacts.PINNED,
+            Contacts.TIMES_CONTACTED,
+            Contacts.CONTACT_LAST_UPDATED_TIMESTAMP,
+            Contacts.CONTACT_PRESENCE,
+            Contacts.CONTACT_CHAT_CAPABILITY,
+            Contacts.CONTACT_STATUS,
+            Contacts.CONTACT_STATUS_TIMESTAMP,
+            Contacts.CONTACT_STATUS_RES_PACKAGE,
+            Contacts.CONTACT_STATUS_LABEL,
+            Contacts.CONTACT_STATUS_ICON,
+            Data.TIMES_USED,
+            Data.LAST_TIME_USED,
+    };
+
+    private static final String[] STREQUENT_PHONE_ONLY_PROJECTION = new String[]{
+            Data._ID,
+            Contacts.HAS_PHONE_NUMBER,
+            Contacts.NAME_RAW_CONTACT_ID,
+            Contacts.IS_USER_PROFILE,
+            Contacts.CUSTOM_RINGTONE,
+            Contacts.DISPLAY_NAME,
+            Contacts.DISPLAY_NAME_ALTERNATIVE,
+            Contacts.DISPLAY_NAME_SOURCE,
+            Contacts.IN_DEFAULT_DIRECTORY,
+            Contacts.IN_VISIBLE_GROUP,
+            Contacts.LAST_TIME_CONTACTED,
+            Contacts.LOOKUP_KEY,
+            Contacts.PHONETIC_NAME,
+            Contacts.PHONETIC_NAME_STYLE,
+            Contacts.PHOTO_ID,
+            Contacts.PHOTO_FILE_ID,
+            Contacts.PHOTO_URI,
+            Contacts.PHOTO_THUMBNAIL_URI,
+            Contacts.SEND_TO_VOICEMAIL,
+            Contacts.SORT_KEY_ALTERNATIVE,
+            Contacts.SORT_KEY_PRIMARY,
+            Contacts.STARRED,
+            Contacts.PINNED,
+            Contacts.TIMES_CONTACTED,
+            Contacts.CONTACT_LAST_UPDATED_TIMESTAMP,
+            Contacts.CONTACT_PRESENCE,
+            Contacts.CONTACT_CHAT_CAPABILITY,
+            Contacts.CONTACT_STATUS,
+            Contacts.CONTACT_STATUS_TIMESTAMP,
+            Contacts.CONTACT_STATUS_RES_PACKAGE,
+            Contacts.CONTACT_STATUS_LABEL,
+            Contacts.CONTACT_STATUS_ICON,
+            Data.TIMES_USED,
+            Data.LAST_TIME_USED,
+            Phone.NUMBER,
+            Phone.TYPE,
+            Phone.LABEL,
+            Phone.IS_SUPER_PRIMARY,
+            Phone.CONTACT_ID,
+    };
+
     public static ContentValues[] sContentValues = new ContentValues[3];
     static {
         ContentValues cv1 = new ContentValues();
@@ -182,48 +261,18 @@
         starContact(ids[0]);
         markDataAsUsed(mDataIds[2], 1);
 
-        // Construct a uri for phone only favorites.
-        Uri uri = Contacts.CONTENT_STREQUENT_URI;
-
-        DatabaseAsserts.checkProjection(mResolver, uri,
-                new String[]{
-                        Contacts._ID,
-                        Contacts.HAS_PHONE_NUMBER,
-                        Contacts.NAME_RAW_CONTACT_ID,
-                        Contacts.IS_USER_PROFILE,
-                        Contacts.CUSTOM_RINGTONE,
-                        Contacts.DISPLAY_NAME,
-                        Contacts.DISPLAY_NAME_ALTERNATIVE,
-                        Contacts.DISPLAY_NAME_SOURCE,
-                        Contacts.IN_DEFAULT_DIRECTORY,
-                        Contacts.IN_VISIBLE_GROUP,
-                        Contacts.LAST_TIME_CONTACTED,
-                        Contacts.LOOKUP_KEY,
-                        Contacts.PHONETIC_NAME,
-                        Contacts.PHONETIC_NAME_STYLE,
-                        Contacts.PHOTO_ID,
-                        Contacts.PHOTO_FILE_ID,
-                        Contacts.PHOTO_URI,
-                        Contacts.PHOTO_THUMBNAIL_URI,
-                        Contacts.SEND_TO_VOICEMAIL,
-                        Contacts.SORT_KEY_ALTERNATIVE,
-                        Contacts.SORT_KEY_PRIMARY,
-                        Contacts.STARRED,
-                        Contacts.PINNED,
-                        Contacts.TIMES_CONTACTED,
-                        Contacts.CONTACT_LAST_UPDATED_TIMESTAMP,
-                        Contacts.CONTACT_PRESENCE,
-                        Contacts.CONTACT_CHAT_CAPABILITY,
-                        Contacts.CONTACT_STATUS,
-                        Contacts.CONTACT_STATUS_TIMESTAMP,
-                        Contacts.CONTACT_STATUS_RES_PACKAGE,
-                        Contacts.CONTACT_STATUS_LABEL,
-                        Contacts.CONTACT_STATUS_ICON,
-                        Data.TIMES_USED,
-                        Data.LAST_TIME_USED,
-                },
+        DatabaseAsserts.checkProjection(mResolver, Contacts.CONTENT_STREQUENT_URI,
+                STREQUENT_PROJECTION,
                 new long[]{ids[0], ids[2]}
         );
+
+        // Strequent filter.
+        DatabaseAsserts.checkProjection(mResolver,
+                Contacts.CONTENT_STREQUENT_FILTER_URI.buildUpon()
+                        .appendEncodedPath("Hot Tamale").build(),
+                STREQUENT_PROJECTION,
+                new long[]{ids[0]}
+        );
     }
 
     public void testStrequents_phoneOnly() throws Exception {
@@ -277,48 +326,8 @@
                 appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build();
 
         DatabaseAsserts.checkProjection(mResolver, uri,
-                new String[] {
-                        Data._ID,
-                        Contacts.HAS_PHONE_NUMBER,
-                        Contacts.NAME_RAW_CONTACT_ID,
-                        Contacts.IS_USER_PROFILE,
-                        Contacts.CUSTOM_RINGTONE,
-                        Contacts.DISPLAY_NAME,
-                        Contacts.DISPLAY_NAME_ALTERNATIVE,
-                        Contacts.DISPLAY_NAME_SOURCE,
-                        Contacts.IN_DEFAULT_DIRECTORY,
-                        Contacts.IN_VISIBLE_GROUP,
-                        Contacts.LAST_TIME_CONTACTED,
-                        Contacts.LOOKUP_KEY,
-                        Contacts.PHONETIC_NAME,
-                        Contacts.PHONETIC_NAME_STYLE,
-                        Contacts.PHOTO_ID,
-                        Contacts.PHOTO_FILE_ID,
-                        Contacts.PHOTO_URI,
-                        Contacts.PHOTO_THUMBNAIL_URI,
-                        Contacts.SEND_TO_VOICEMAIL,
-                        Contacts.SORT_KEY_ALTERNATIVE,
-                        Contacts.SORT_KEY_PRIMARY,
-                        Contacts.STARRED,
-                        Contacts.PINNED,
-                        Contacts.TIMES_CONTACTED,
-                        Contacts.CONTACT_LAST_UPDATED_TIMESTAMP,
-                        Contacts.CONTACT_PRESENCE,
-                        Contacts.CONTACT_CHAT_CAPABILITY,
-                        Contacts.CONTACT_STATUS,
-                        Contacts.CONTACT_STATUS_TIMESTAMP,
-                        Contacts.CONTACT_STATUS_RES_PACKAGE,
-                        Contacts.CONTACT_STATUS_LABEL,
-                        Contacts.CONTACT_STATUS_ICON,
-                        Data.TIMES_USED,
-                        Data.LAST_TIME_USED,
-                        Phone.NUMBER,
-                        Phone.TYPE,
-                        Phone.LABEL,
-                        Phone.IS_SUPER_PRIMARY,
-                        Phone.CONTACT_ID,
-                },
-                new long[] {mDataIds[0], mDataIds[2]} // Note _id from phone_only is data._id
+                STREQUENT_PHONE_ONLY_PROJECTION,
+                new long[]{mDataIds[0], mDataIds[2]} // Note _id from phone_only is data._id
         );
     }
 
@@ -345,6 +354,17 @@
                 true /* inOrder */, sContentValues[1], sContentValues[2], sContentValues[0]);
     }
 
+    public void testFrequent_projection() throws Exception {
+        long[] ids = setupTestData();
+
+        markDataAsUsed(mDataIds[0], 10);
+
+        DatabaseAsserts.checkProjection(mResolver, Contacts.CONTENT_FREQUENT_URI,
+                STREQUENT_PROJECTION,
+                new long[]{ids[0]}
+        );
+    }
+
     /**
      * Given a uri, performs a query on the contacts provider for that uri and asserts that the
      * cursor returned from the query matches the expected results.
diff --git a/tests/tests/provider/src/android/provider/cts/ContactsContract_ProviderStatus.java b/tests/tests/provider/src/android/provider/cts/ContactsContract_ProviderStatus.java
new file mode 100644
index 0000000..9c38ec0
--- /dev/null
+++ b/tests/tests/provider/src/android/provider/cts/ContactsContract_ProviderStatus.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 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.provider.cts;
+
+import android.content.ContentProviderClient;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.provider.ContactsContract.ProviderStatus;
+import android.provider.ContactsContract.RawContacts;
+import android.provider.cts.ContactsContract_TestDataBuilder.TestRawContact;
+import android.provider.cts.contacts.DatabaseAsserts;
+import android.test.AndroidTestCase;
+
+/**
+ * CTS tests for {@link android.provider.ContactsContract.ProviderStatus}.
+ *
+ * Unfortunately, we can't check that the value of ProviderStatus equals
+ * {@link ProviderStatus#STATUS_EMPTY} initially. Some carriers pre-install
+ * accounts. As a result, the value STATUS_EMPTY will never be achieved.
+ */
+public class ContactsContract_ProviderStatus extends AndroidTestCase {
+    private ContentResolver mResolver;
+    private ContactsContract_TestDataBuilder mBuilder;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mResolver = getContext().getContentResolver();
+        ContentProviderClient provider =
+                mResolver.acquireContentProviderClient(ContactsContract.AUTHORITY);
+        mBuilder = new ContactsContract_TestDataBuilder(provider);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        mBuilder.cleanup();
+    }
+
+    public void testProviderStatus_addedContacts() throws Exception {
+        // Setup: add a contact to CP2.
+        TestRawContact rawContact1 = mBuilder.newRawContact()
+                .with(RawContacts.ACCOUNT_TYPE, "test_account")
+                .with(RawContacts.ACCOUNT_NAME, "test_name")
+                .insert();
+        rawContact1.newDataRow(StructuredName.CONTENT_ITEM_TYPE)
+                .with(StructuredName.GIVEN_NAME, "first1")
+                .with(StructuredName.FAMILY_NAME, "last1")
+                .insert();
+
+        // Execute: fetch CP2 status
+        Cursor cursor = mResolver.query(ProviderStatus.CONTENT_URI, null, null, null, null);
+
+        // Verify: CP2 status is normal instead of STATUS_EMPTY.
+        try {
+            assertEquals(1, cursor.getCount());
+            cursor.moveToFirst();
+            ContentValues values = new ContentValues();
+            values.put(ProviderStatus.STATUS, ProviderStatus.STATUS_NORMAL);
+            DatabaseAsserts.assertCursorValuesMatchExactly(cursor, values);
+        } finally {
+            if (cursor != null) {
+                cursor.close();
+            }
+        }
+    }
+}
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java
index f6b3176..eeef6e7 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicBLAS.java
@@ -22,6 +22,7 @@
 
 public class IntrinsicBLAS extends IntrinsicBase {
     private ScriptIntrinsicBLAS mBLAS;
+    private boolean mInitialized = false;
 
     private ArrayList<Allocation> mMatrixS;
     private final float alphaS = 1.0f;
@@ -63,35 +64,34 @@
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        mBLAS = ScriptIntrinsicBLAS.create(mRS);
 
         //now populate the test Matrixes and Vectors.
-        mMatrixS = new ArrayList<Allocation>();
-        mMatrixD = new ArrayList<Allocation>();
-        mMatrixC = new ArrayList<Allocation>();
-        mMatrixZ = new ArrayList<Allocation>();
-        for (int x : mDim) {
-            for (int y : mDim) {
-                mMatrixS.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F32(mRS), x, y)));
-                mMatrixD.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F64(mRS), x, y)));
-                mMatrixC.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F32_2(mRS), x, y)));
-                mMatrixZ.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F64_2(mRS), x, y)));
+        if (!mInitialized) {
+            mBLAS = ScriptIntrinsicBLAS.create(mRS);
+            mMatrixS = new ArrayList<Allocation>();
+            mMatrixD = new ArrayList<Allocation>();
+            mMatrixC = new ArrayList<Allocation>();
+            mMatrixZ = new ArrayList<Allocation>();
+            for (int x : mDim) {
+                for (int y : mDim) {
+                    mMatrixS.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F32(mRS), x, y)));
+                    mMatrixD.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F64(mRS), x, y)));
+                    mMatrixC.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F32_2(mRS), x, y)));
+                    mMatrixZ.add(Allocation.createTyped(mRS, Type.createXY(mRS, Element.F64_2(mRS), x, y)));
+                }
             }
+            //also need Allocation with mismatch Element.
+            Allocation misAlloc = Allocation.createTyped(mRS, Type.createXY(mRS, Element.U8(mRS), 1, 1));
+            mMatrixS.add(misAlloc);
+            mMatrixD.add(misAlloc);
+            mMatrixC.add(misAlloc);
+            mMatrixZ.add(misAlloc);
+            mInitialized = true;
         }
-        //also need Allocation with mismatch Element.
-        Allocation misAlloc = Allocation.createTyped(mRS, Type.createXY(mRS, Element.U8(mRS), 1, 1));
-        mMatrixS.add(misAlloc);
-        mMatrixD.add(misAlloc);
-        mMatrixC.add(misAlloc);
-        mMatrixZ.add(misAlloc);
     }
 
     @Override
     protected void tearDown() throws Exception {
-        if (mBLAS != null) {
-            mBLAS.destroy();
-            mBLAS = null;
-        }
         super.tearDown();
     }
 
@@ -135,6 +135,13 @@
         return true;
     }
 
+    private boolean validateVecInput(Allocation X) {
+        if (X.getType().getY() > 2) {
+            //for testing vector, need a mismatch Y for complete test coverage.
+            return false;
+        }
+        return true;
+    }
 
     private boolean validateGEMV(Element e, int TransA, Allocation A, Allocation X, int incX, Allocation Y, int incY) {
         if (!validateTranspose(TransA)) {
@@ -172,7 +179,13 @@
     private void xGEMV_API_test(int trans, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateGEMV(elemA, trans, matA, vecX, incX, vecY, incY)) {
                         try {
@@ -218,9 +231,7 @@
     public void L2_xGEMV_API(ArrayList<Allocation> mMatrix) {
         for (int trans : mTranspose) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xGEMV_API_test(trans, incX, incY, mMatrix);
-                }
+                xGEMV_API_test(trans, incX, incX, mMatrix);
             }
         }
     }
@@ -245,7 +256,13 @@
     private void xGBMV_API_test(int trans, int KL, int KU, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateGEMV(elemA, trans, matA, vecX, incX, vecY, incY) && KU >= 0 && KL >= 0) {
                         try {
@@ -291,10 +308,8 @@
     public void L2_xGBMV_API(ArrayList<Allocation> mMatrix) {
         for (int trans : mTranspose) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    for (int K : mK) {
-                        xGBMV_API_test(trans, K, K, incX, incY, mMatrix);
-                    }
+                for (int K : mK) {
+                    xGBMV_API_test(trans, K, K, incX, incX, mMatrix);
                 }
             }
         }
@@ -320,7 +335,13 @@
     private void xHEMV_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -352,9 +373,7 @@
     public void L2_xHEMV_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xHEMV_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xHEMV_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -371,7 +390,13 @@
     private void xHBMV_API_test(int Uplo, int K, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYR2(elemA, Uplo, vecX, incX, vecY, incY, matA) && K >= 0) {
                         try {
@@ -404,9 +429,7 @@
         for (int Uplo : mUplo) {
             for (int K : mK) {
                 for (int incX : mInc) {
-                    for (int incY : mInc) {
-                        xHBMV_API_test(Uplo, K, incX, incY, mMatrix);
-                    }
+                        xHBMV_API_test(Uplo, K, incX, incX, mMatrix);
                 }
             }
         }
@@ -424,7 +447,13 @@
     private void xHPMV_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSPR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -456,9 +485,7 @@
     public void L2_xHPMV_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xHPMV_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xHPMV_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -507,7 +534,13 @@
     private void xSYMV_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYMV(elemA, Uplo, matA, vecX, incX, vecY, incY)) {
                         try {
@@ -539,9 +572,7 @@
     public void L2_xSYMV_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xSYMV_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xSYMV_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -559,7 +590,13 @@
     private void xSBMV_API_test(int Uplo, int K, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYMV(elemA, Uplo, matA, vecX, incX, vecY, incY) && K >= 0) {
                         try {
@@ -592,9 +629,7 @@
         for (int Uplo : mUplo) {
             for (int K : mK) {
                 for (int incX : mInc) {
-                    for (int incY : mInc) {
-                        xSBMV_API_test(Uplo, K, incX, incY, mMatrix);
-                    }
+                    xSBMV_API_test(Uplo, K, incX, incX, mMatrix);
                 }
             }
         }
@@ -649,7 +684,13 @@
     private void xSPMV_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSPMV(elemA, Uplo, matA, vecX, incX, vecY, incY)) {
                         try {
@@ -681,9 +722,7 @@
     public void L2_xSPMV_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xSPMV_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xSPMV_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -733,6 +772,9 @@
     private void xTRMV_API_test(int Uplo, int TransA, int Diag, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTRMV(elemA, Uplo, TransA, Diag, matA, vecX, incX)) {
                     try {
@@ -807,6 +849,9 @@
     private void xTBMV_API_test(int Uplo, int TransA, int Diag, int K, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTRMV(elemA, Uplo, TransA, Diag, matA, vecX, incX) && K >= 0) {
                     try {
@@ -919,6 +964,9 @@
     private void xTPMV_API_test(int Uplo, int TransA, int Diag, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTPMV(elemA, Uplo, TransA, Diag, matA, vecX, incX)) {
                     try {
@@ -992,6 +1040,9 @@
     private void xTRSV_API_test(int Uplo, int TransA, int Diag, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTRMV(elemA, Uplo, TransA, Diag, matA, vecX, incX)) {
                     try {
@@ -1065,6 +1116,9 @@
     private void xTBSV_API_test(int Uplo, int TransA, int Diag, int K, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTRMV(elemA, Uplo, TransA, Diag, matA, vecX, incX) && K >= 0) {
                     try {
@@ -1140,6 +1194,9 @@
     private void xTPSV_API_test(int Uplo, int TransA, int Diag, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateTPMV(elemA, Uplo, TransA, Diag, matA, vecX, incX)) {
                     try {
@@ -1245,7 +1302,13 @@
     private void xGER_API_test(int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateGER(elemA, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1321,7 +1384,13 @@
     private void xGERU_API_test(int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateGERU(elemA, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1370,7 +1439,13 @@
     private void xGERC_API_test(int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateGERU(elemA, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1420,6 +1495,9 @@
     private void xHER_API_test(int Uplo, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateSYR(elemA, Uplo, vecX, incX, matA)) {
                     try {
@@ -1467,6 +1545,9 @@
     private void xHPR_API_test(int Uplo, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateSPR(elemA, Uplo, vecX, incX, matA)) {
                     try {
@@ -1514,7 +1595,13 @@
     private void xHER2_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1546,9 +1633,7 @@
     public void L2_xHER2_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xHER2_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xHER2_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -1566,7 +1651,13 @@
     private void xHPR2_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSPR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1598,9 +1689,7 @@
     public void L2_xHPR2_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xHPR2_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xHPR2_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -1645,6 +1734,9 @@
     private void xSYR_API_test(int Uplo, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateSYR(elemA, Uplo, vecX, incX, matA)) {
                     try {
@@ -1726,6 +1818,9 @@
     private void xSPR_API_test(int Uplo, int incX, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 Element elemA = matA.getType().getElement();
                 if (validateSPR(elemA, Uplo, vecX, incX, matA)) {
                     try {
@@ -1805,7 +1900,13 @@
     private void xSYR2_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSYR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1837,9 +1938,7 @@
     public void L2_xSYR2_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xSYR2_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xSYR2_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
@@ -1891,7 +1990,13 @@
     private void xSPR2_API_test(int Uplo, int incX, int incY, ArrayList<Allocation> mMatrix) {
         for (Allocation matA : mMatrix) {
             for (Allocation vecX : mMatrix) {
+                if (!validateVecInput(vecX)) {
+                    continue;
+                }
                 for (Allocation vecY : mMatrix) {
+                    if (!validateVecInput(vecY)) {
+                        continue;
+                    }
                     Element elemA = matA.getType().getElement();
                     if (validateSPR2(elemA, Uplo, vecX, incX, vecY, incY, matA)) {
                         try {
@@ -1923,9 +2028,7 @@
     public void L2_xSPR2_API(ArrayList<Allocation> mMatrix) {
         for (int Uplo : mUplo) {
             for (int incX : mInc) {
-                for (int incY : mInc) {
-                    xSPR2_API_test(Uplo, incX, incY, mMatrix);
-                }
+                xSPR2_API_test(Uplo, incX, incX, mMatrix);
             }
         }
     }
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
index 24e56d7..c8b3640 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
@@ -24,7 +24,7 @@
     static final int inX = 307;
     static final int inY = 157;
 
-    private void testReszie(int w, int h, Element.DataType dt, int vecSize, float scaleX, float scaleY) {
+    private void testResize(int w, int h, Element.DataType dt, int vecSize, float scaleX, float scaleY) {
 
         Element e = makeElement(dt, vecSize);
 
@@ -98,343 +98,343 @@
 
 
     public void test_U8_4_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
         checkError();
     }
     public void test_U8_3_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
         checkError();
     }
     public void test_U8_2_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
         checkError();
     }
     public void test_U8_1_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
         checkError();
     }
 
     public void test_U8_4_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
         checkError();
     }
     public void test_U8_3_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
         checkError();
     }
     public void test_U8_2_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
         checkError();
     }
     public void test_U8_1_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
         checkError();
     }
 
     public void test_U8_4_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_3_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_2_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_1_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
         checkError();
     }
 
     public void test_U8_4_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_3_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_2_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_1_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
         checkError();
     }
 
     public void test_U8_4_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_3_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_2_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_1_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
         checkError();
     }
 
     public void test_U8_4_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
         checkError();
     }
     public void test_U8_3_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
         checkError();
     }
     public void test_U8_2_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
         checkError();
     }
     public void test_U8_1_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
         checkError();
     }
 
     public void test_U8_4_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
         checkError();
     }
     public void test_U8_3_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
         checkError();
     }
     public void test_U8_2_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
         checkError();
     }
     public void test_U8_1_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
         checkError();
     }
 
     public void test_U8_4_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_3_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_2_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
         checkError();
     }
     public void test_U8_1_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
         checkError();
     }
 
     public void test_U8_4_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_3_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_2_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
         checkError();
     }
     public void test_U8_1_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
         checkError();
     }
 
     public void test_U8_4_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_3_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_2_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
         checkError();
     }
     public void test_U8_1_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
         checkError();
     }
 
 
     public void test_F32_4_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
         checkError();
     }
     public void test_F32_3_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
         checkError();
     }
     public void test_F32_2_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
         checkError();
     }
     public void test_F32_1_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
         checkError();
     }
 
     public void test_F32_4_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
         checkError();
     }
     public void test_F32_3_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
         checkError();
     }
     public void test_F32_2_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
         checkError();
     }
     public void test_F32_1_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
         checkError();
     }
 
     public void test_F32_4_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_3_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_2_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_1_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
         checkError();
     }
 
     public void test_F32_4_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_3_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_2_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_1_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
         checkError();
     }
 
     public void test_F32_4_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_3_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_2_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_1_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
         checkError();
     }
 
     public void test_F32_4_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
         checkError();
     }
     public void test_F32_3_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
         checkError();
     }
     public void test_F32_2_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
         checkError();
     }
     public void test_F32_1_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
         checkError();
     }
 
     public void test_F32_4_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
         checkError();
     }
     public void test_F32_3_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
         checkError();
     }
     public void test_F32_2_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
         checkError();
     }
     public void test_F32_1_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
         checkError();
     }
 
     public void test_F32_4_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_3_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_2_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
         checkError();
     }
     public void test_F32_1_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
         checkError();
     }
 
     public void test_F32_4_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_3_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_2_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
         checkError();
     }
     public void test_F32_1_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
         checkError();
     }
 
     public void test_F32_4_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_3_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_2_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
         checkError();
     }
     public void test_F32_1_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
         checkError();
     }
 
diff --git a/tests/tests/rscpp/src/android/cts/rscpp/RSResizeTest.java b/tests/tests/rscpp/src/android/cts/rscpp/RSResizeTest.java
index b4864b5..51ae26e 100644
--- a/tests/tests/rscpp/src/android/cts/rscpp/RSResizeTest.java
+++ b/tests/tests/rscpp/src/android/cts/rscpp/RSResizeTest.java
@@ -34,7 +34,7 @@
     native boolean resizeTest(String path, int w, int h, float scaleX, float scaleY,
                               boolean useByte, int vecSize, byte[] inB, byte[] outB,
                               float[] inF, float[] outF);
-    private void testReszie(int w, int h, Element.DataType dt, int vecSize, float scaleX, float scaleY) {
+    private void testResize(int w, int h, Element.DataType dt, int vecSize, float scaleX, float scaleY) {
 
         boolean useByte = false;
         if (dt == Element.DataType.UNSIGNED_8) {
@@ -91,263 +91,263 @@
     }
 
     public void test_U8_4_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
     }
     public void test_U8_3_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
     }
     public void test_U8_2_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
     }
     public void test_U8_1_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
     }
 
     public void test_U8_4_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
     }
     public void test_U8_3_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
     }
     public void test_U8_2_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
     }
     public void test_U8_1_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
     }
 
     public void test_U8_4_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
     }
     public void test_U8_3_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
     }
     public void test_U8_2_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
     }
     public void test_U8_1_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
     }
 
     public void test_U8_4_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
     }
     public void test_U8_3_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
     }
     public void test_U8_2_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
     }
     public void test_U8_1_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
     }
 
     public void test_U8_4_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
     }
     public void test_U8_3_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
     }
     public void test_U8_2_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
     }
     public void test_U8_1_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
     }
 
     public void test_U8_4_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 1.f, 1.f);
     }
     public void test_U8_3_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 1.f, 1.f);
     }
     public void test_U8_2_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 1.f, 1.f);
     }
     public void test_U8_1_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 1.f, 1.f);
     }
 
     public void test_U8_4_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 2.f);
     }
     public void test_U8_3_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 2.f);
     }
     public void test_U8_2_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 2.f);
     }
     public void test_U8_1_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 2.f);
     }
 
     public void test_U8_4_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 2.f);
     }
     public void test_U8_3_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 2.f);
     }
     public void test_U8_2_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 2.f);
     }
     public void test_U8_1_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 2.f);
     }
 
     public void test_U8_4_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 2.f, 0.5f);
     }
     public void test_U8_3_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 2.f, 0.5f);
     }
     public void test_U8_2_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 2.f, 0.5f);
     }
     public void test_U8_1_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 2.f, 0.5f);
     }
 
     public void test_U8_4_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 4, 0.5f, 0.5f);
     }
     public void test_U8_3_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 3, 0.5f, 0.5f);
     }
     public void test_U8_2_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 2, 0.5f, 0.5f);
     }
     public void test_U8_1_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
     }
 
 
     public void test_F32_4_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
     }
     public void test_F32_3_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
     }
     public void test_F32_2_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
     }
     public void test_F32_1_SCALE10_10_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
     }
 
     public void test_F32_4_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
     }
     public void test_F32_3_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
     }
     public void test_F32_2_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
     }
     public void test_F32_1_SCALE20_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
     }
 
     public void test_F32_4_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
     }
     public void test_F32_3_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
     }
     public void test_F32_2_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
     }
     public void test_F32_1_SCALE05_20_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
     }
 
     public void test_F32_4_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
     }
     public void test_F32_3_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
     }
     public void test_F32_2_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
     }
     public void test_F32_1_SCALE20_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
     }
 
     public void test_F32_4_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
     }
     public void test_F32_3_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
     }
     public void test_F32_2_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
     }
     public void test_F32_1_SCALE05_05_inSqure() {
-        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        testResize(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
     }
 
     public void test_F32_4_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
     }
     public void test_F32_3_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
     }
     public void test_F32_2_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
     }
     public void test_F32_1_SCALE10_10_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
     }
 
     public void test_F32_4_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
     }
     public void test_F32_3_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
     }
     public void test_F32_2_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
     }
     public void test_F32_1_SCALE20_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
     }
 
     public void test_F32_4_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
     }
     public void test_F32_3_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
     }
     public void test_F32_2_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
     }
     public void test_F32_1_SCALE05_20_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
     }
 
     public void test_F32_4_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
     }
     public void test_F32_3_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
     }
     public void test_F32_2_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
     }
     public void test_F32_1_SCALE20_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
     }
 
     public void test_F32_4_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
     }
     public void test_F32_3_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
     }
     public void test_F32_2_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
     }
     public void test_F32_1_SCALE05_05_inRectangle() {
-        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        testResize(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
     }
 }
diff --git a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
index 4dcca0d..f49a820 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
@@ -335,7 +335,7 @@
         // exercising the underlying PhoneNumberUtil or constraining localization changes.
         String phoneNumber = "6512223333";
         // Execute
-        TtsSpan ttsSpan = PhoneNumberUtils.getPhoneTtsSpan(phoneNumber);
+        TtsSpan ttsSpan = PhoneNumberUtils.createTtsSpan(phoneNumber);
         // Verify: the created TtsSpan contains the phone number.
         assertEquals("6512223333", ttsSpan.getArgs().get(TtsSpan.ARG_NUMBER_PARTS));
     }
@@ -345,7 +345,7 @@
         // exercising the underlying PhoneNumberUtil or constraining localization changes.
         Spannable spannable = new SpannableString("Hello 6502223333");
         // Execute
-        PhoneNumberUtils.addPhoneTtsSpan(spannable, 5, spannable.length() - 1);
+        PhoneNumberUtils.addTtsSpan(spannable, 5, spannable.length());
         // Verify: the Spannable is annotated with a TtsSpan in the correct location.
         TtsSpan[] ttsSpans = spannable.getSpans(5, spannable.length() - 1, TtsSpan.class);
         assertEquals(1, ttsSpans.length);
@@ -357,7 +357,7 @@
         // exercising the underlying PhoneNumberUtil or constraining localization changes.
         CharSequence phoneNumber = "6512223333";
         // Execute
-        Spannable spannable = (Spannable) PhoneNumberUtils.getPhoneTtsSpannable(phoneNumber);
+        Spannable spannable = (Spannable) PhoneNumberUtils.createTtsSpannable(phoneNumber);
         // Verify: returned char sequence contains a TtsSpan with the phone number in it
         TtsSpan[] ttsSpans = spannable.getSpans(0, spannable.length() - 1, TtsSpan.class);
         assertEquals(1, ttsSpans.length);
diff --git a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
index c14bb03..706ad8d 100644
--- a/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
+++ b/tests/tests/widget/src/android/widget/cts/PopupWindowTest.java
@@ -189,8 +189,7 @@
 
     public void testAccessHeight() {
         mPopupWindow = new PopupWindow(mActivity);
-        // default is 0
-        assertEquals(0, mPopupWindow.getHeight());
+        assertEquals(WindowManager.LayoutParams.WRAP_CONTENT, mPopupWindow.getHeight());
 
         int height = getDisplay().getHeight() / 2;
         mPopupWindow.setHeight(height);
@@ -224,7 +223,7 @@
 
     public void testAccessWidth() {
         mPopupWindow = new PopupWindow(mActivity);
-        assertEquals(0, mPopupWindow.getWidth());
+        assertEquals(WindowManager.LayoutParams.WRAP_CONTENT, mPopupWindow.getWidth());
 
         int width = getDisplay().getWidth() / 2;
         mPopupWindow.setWidth(width);
@@ -418,7 +417,7 @@
         mPopupWindow.setOutsideTouchable(true);
 
         WindowManager.LayoutParams p = (WindowManager.LayoutParams)
-                mPopupWindow.getContentView().getLayoutParams();
+                mPopupWindow.getContentView().getRootView().getLayoutParams();
 
         assertEquals(0, WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES & p.flags);
         assertEquals(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
@@ -748,7 +747,7 @@
         mPopupWindow = new PopupWindow(new TextView(mActivity));
         showPopup();
 
-        ViewGroup.LayoutParams p = mPopupWindow.getContentView().getLayoutParams();
+        ViewGroup.LayoutParams p = mPopupWindow.getContentView().getRootView().getLayoutParams();
         assertEquals(0, p.width);
         assertEquals(0, p.height);
 
diff --git a/tests/uiautomator/test-apps/CtsUiAutomatorApp/Android.mk b/tests/uiautomator/test-apps/CtsUiAutomatorApp/Android.mk
index 3827754..60a0ba6 100644
--- a/tests/uiautomator/test-apps/CtsUiAutomatorApp/Android.mk
+++ b/tests/uiautomator/test-apps/CtsUiAutomatorApp/Android.mk
@@ -24,7 +24,7 @@
 LOCAL_SDK_VERSION := current
 
 LOCAL_PACKAGE_NAME := CtsUiAutomatorApp
-LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4
+LOCAL_JAVA_LIBRARIES = android-support-v4
 
 LOCAL_PROGUARD_ENABLED := disabled