Merge "Camera: HAL3.3 LSC keys CTS update" into mnc-dev
diff --git a/CtsTestCaseList.mk b/CtsTestCaseList.mk
index c66341d..21b4027 100644
--- a/CtsTestCaseList.mk
+++ b/CtsTestCaseList.mk
@@ -57,7 +57,12 @@
     CtsKeySetSigningBUpgradeB \
     CtsKeySetSigningAAndBUpgradeA \
     CtsKeySetSigningAAndCUpgradeB \
-    CtsKeySetSigningAUpgradeNone
+    CtsKeySetSigningAUpgradeNone \
+    CtsKeySetSharedUserSigningAUpgradeB \
+    CtsKeySetSharedUserSigningBUpgradeB \
+    CtsKeySetSigningABadUpgradeB \
+    CtsKeySetSigningCBadAUpgradeAB \
+    CtsKeySetSigningANoDefUpgradeB
 
 cts_support_packages := \
     CtsAccelerationTestStubs \
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/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/src/com/android/cts/managedprofile/ContactsTest.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ContactsTest.java
index b76d9e4..77ecfe1 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ContactsTest.java
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/ContactsTest.java
@@ -31,11 +31,13 @@
 import android.provider.ContactsContract.CommonDataKinds.Email;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
 import android.provider.ContactsContract.CommonDataKinds.Photo;
+import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.PhoneLookup;
 import android.provider.ContactsContract.RawContacts;
 import android.test.AndroidTestCase;
 
 import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -49,20 +51,26 @@
     private static final String PRIMARY_CONTACT_DISPLAY_NAME = "Primary";
     private static final String PRIMARY_CONTACT_PHONE = "00000001";
     private static final String PRIMARY_CONTACT_EMAIL = "one@primary.com";
+    private static final String PRIMARY_CONTACT_SIP = "foo@sip";
+
     // details of a sample managed contact
     private static final String MANAGED_CONTACT_DISPLAY_NAME = "Managed";
     private static final String MANAGED_CONTACT_PHONE = "6891999";
     private static final String MANAGED_CONTACT_EMAIL = "one@managed.com";
+    private static final String MANAGED_CONTACT_SIP = "bar@sip";
+
     // details of a sample primary and a sample managed contact, with the same phone & email
     private static final String PRIMARY_CONTACT_DISPLAY_NAME_2 = "PrimaryShared";
     private static final String MANAGED_CONTACT_DISPLAY_NAME_2 = "ManagedShared";
     private static final String SHARED_CONTACT_PHONE = "00000002";
     private static final String SHARED_CONTACT_EMAIL = "shared@shared.com";
+    private static final String SHARED_CONTACT_SIP = "baz@sip";
 
     private DevicePolicyManager mDevicePolicyManager;
     private ContentResolver mResolver;
 
-    private static class ContactInfo {
+    private class ContactInfo { // Not static to access outer world.
+
         String contactId;
         String displayName;
         String photoUri;
@@ -78,8 +86,14 @@
             this.photoId = photoId;
         }
 
-        private boolean hasPhotoUri() {
-            return photoUri != null && photoThumbnailUri != null;
+        private void assertNoPhotoUri() {
+            assertNull(photoUri);
+            assertNull(photoThumbnailUri);
+        }
+
+        private void assertPhotoUrisReadable() throws IOException {
+            assertPhotoUriReadable(photoUri);
+            assertPhotoUriReadable(photoThumbnailUri);
         }
 
         private boolean hasPhotoId() {
@@ -100,19 +114,19 @@
         assertFalse(isManagedProfile());
         // Do not insert to primary contact
         insertContact(PRIMARY_CONTACT_DISPLAY_NAME, PRIMARY_CONTACT_PHONE,
-                PRIMARY_CONTACT_EMAIL, 0);
+                PRIMARY_CONTACT_EMAIL, PRIMARY_CONTACT_SIP, 0);
 
         ContactInfo contactInfo = getContactInfo(PRIMARY_CONTACT_PHONE);
         assertNotNull(contactInfo);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
 
         contactInfo = getContactInfoFromEmail(PRIMARY_CONTACT_EMAIL);
         assertNotNull(contactInfo);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
 
@@ -125,19 +139,20 @@
         insertContact(MANAGED_CONTACT_DISPLAY_NAME,
                 MANAGED_CONTACT_PHONE,
                 MANAGED_CONTACT_EMAIL,
+                MANAGED_CONTACT_SIP,
                 com.android.cts.managedprofile.R.raw.ic_contact_picture);
 
         ContactInfo contactInfo = getContactInfo(MANAGED_CONTACT_PHONE);
         assertNotNull(contactInfo);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
 
         contactInfo = getContactInfoFromEmail(MANAGED_CONTACT_EMAIL);
         assertNotNull(contactInfo);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -145,21 +160,23 @@
     public void testPrimaryProfileDuplicatedPhoneEmailContact_insertedAndfound() throws
             RemoteException, OperationApplicationException, NotFoundException, IOException {
         assertFalse(isManagedProfile());
-        insertContact(PRIMARY_CONTACT_DISPLAY_NAME_2, SHARED_CONTACT_PHONE,
+        insertContact(PRIMARY_CONTACT_DISPLAY_NAME_2,
+                SHARED_CONTACT_PHONE,
                 SHARED_CONTACT_EMAIL,
+                SHARED_CONTACT_SIP,
                 com.android.cts.managedprofile.R.raw.ic_contact_picture);
 
         ContactInfo contactInfo = getContactInfo(SHARED_CONTACT_PHONE);
         assertNotNull(contactInfo);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
 
         contactInfo = getContactInfoFromEmail(SHARED_CONTACT_EMAIL);
         assertNotNull(contactInfo);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -168,57 +185,73 @@
             RemoteException, OperationApplicationException, NotFoundException, IOException {
         assertTrue(isManagedProfile());
         insertContact(MANAGED_CONTACT_DISPLAY_NAME_2, SHARED_CONTACT_PHONE,
-                SHARED_CONTACT_EMAIL, 0);
+                SHARED_CONTACT_EMAIL, SHARED_CONTACT_SIP , 0);
 
         ContactInfo contactInfo = getContactInfo(SHARED_CONTACT_PHONE);
         assertNotNull(contactInfo);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
 
         contactInfo = getContactInfoFromEmail(SHARED_CONTACT_EMAIL);
         assertNotNull(contactInfo);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testPrimaryProfileEnterprisePhoneLookup_canAccessEnterpriseContact() {
+    public void testPrimaryProfileEnterprisePhoneLookup_canAccessEnterpriseContact()
+            throws IOException {
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfo(MANAGED_CONTACT_PHONE);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         // Cannot get photo id in ENTERPRISE_CONTENT_FILTER_URI
         assertFalse(contactInfo.hasPhotoId());
         assertTrue(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testPrimaryProfileEnterpriseEmailLookup_canAccessEnterpriseContact() {
+    public void testPrimaryProfileEnterpriseSipLookup_canAccessEnterpriseContact()
+            throws IOException {
+        assertFalse(isManagedProfile());
+        ContactInfo contactInfo = getEnterpriseContactInfoFromSipAddress(MANAGED_CONTACT_SIP);
+        assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
+        contactInfo.assertPhotoUrisReadable();
+        assertFalse(contactInfo.hasPhotoId());
+
+        // Quirk: the _id column from the SIP lookup is actually of the data id, not the contact id.
+        // assertTrue(isEnterpriseContactId(contactInfo.contactId));
+    }
+
+    public void testPrimaryProfileEnterpriseEmailLookup_canAccessEnterpriseContact()
+            throws IOException {
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfoFromEmail(MANAGED_CONTACT_EMAIL);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         // Cannot get photo id in ENTERPRISE_CONTENT_FILTER_URI
         assertFalse(contactInfo.hasPhotoId());
         assertTrue(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testPrimaryProfileEnterprisePhoneLookupDuplicated_canAccessPrimaryContact() {
+    public void testPrimaryProfileEnterprisePhoneLookupDuplicated_canAccessPrimaryContact()
+            throws IOException {
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfo(SHARED_CONTACT_PHONE);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testPrimaryProfileEnterpriseEmailLookupDuplicated_canAccessPrimaryContact() {
+    public void testPrimaryProfileEnterpriseEmailLookupDuplicated_canAccessPrimaryContact()
+            throws IOException {
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfoFromEmail(SHARED_CONTACT_EMAIL);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -227,7 +260,7 @@
         assertTrue(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfo(SHARED_CONTACT_PHONE);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -236,12 +269,11 @@
         assertTrue(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfoFromEmail(SHARED_CONTACT_EMAIL);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME_2, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
 
-
     public void testPrimaryProfilePhoneLookup_canNotAccessEnterpriseContact() {
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getContactInfo(MANAGED_CONTACT_PHONE);
@@ -258,7 +290,7 @@
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfo(PRIMARY_CONTACT_PHONE);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -267,25 +299,27 @@
         assertFalse(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfoFromEmail(PRIMARY_CONTACT_EMAIL);
         assertEquals(PRIMARY_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertFalse(contactInfo.hasPhotoUri());
+        contactInfo.assertNoPhotoUri();
         assertFalse(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testManagedProfileEnterprisePhoneLookup_canAccessEnterpriseContact() {
+    public void testManagedProfileEnterprisePhoneLookup_canAccessEnterpriseContact()
+            throws IOException {
         assertTrue(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfo(MANAGED_CONTACT_PHONE);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
 
-    public void testManagedProfileEnterpriseEmailLookup_canAccessEnterpriseContact() {
+    public void testManagedProfileEnterpriseEmailLookup_canAccessEnterpriseContact()
+            throws IOException {
         assertTrue(isManagedProfile());
         ContactInfo contactInfo = getEnterpriseContactInfoFromEmail(MANAGED_CONTACT_EMAIL);
         assertEquals(MANAGED_CONTACT_DISPLAY_NAME, contactInfo.displayName);
-        assertTrue(contactInfo.hasPhotoUri());
+        contactInfo.assertPhotoUrisReadable();
         assertTrue(contactInfo.hasPhotoId());
         assertFalse(isEnterpriseContactId(contactInfo.contactId));
     }
@@ -358,12 +392,8 @@
         return mDevicePolicyManager.isProfileOwnerApp(adminPackage);
     }
 
-    private void insertContact(String displayName, String phoneNumber, int photoResId) throws
-            RemoteException, OperationApplicationException, NotFoundException, IOException {
-        insertContact(displayName, phoneNumber, null, photoResId);
-    }
-
-    private void insertContact(String displayName, String phoneNumber, String email, int photoResId)
+    private void insertContact(String displayName, String phoneNumber, String email,
+            String sipAddress, int photoResId)
             throws RemoteException, OperationApplicationException, NotFoundException, IOException {
         ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
         ops.add(ContentProviderOperation
@@ -403,26 +433,50 @@
                 .withValue(ContactsContract.CommonDataKinds.Email.TYPE,
                         Email.TYPE_WORK)
                 .build());
+        ops.add(ContentProviderOperation
+                .newInsert(ContactsContract.Data.CONTENT_URI)
+                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+                .withValue(
+                        ContactsContract.Data.MIMETYPE,
+                        ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE)
+                .withValue(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS,
+                        sipAddress)
+                .withValue(ContactsContract.CommonDataKinds.SipAddress.TYPE,
+                        ContactsContract.CommonDataKinds.SipAddress.TYPE_WORK)
+                .build());
 
         if (photoResId != 0) {
             InputStream phoneInputStream = mContext.getResources().openRawResource(photoResId);
-            byte[] rawPhoto = getByteFromStream(phoneInputStream);
-            ops.add(ContentProviderOperation
-                    .newInsert(ContactsContract.Data.CONTENT_URI)
-                    .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
-                    .withValue(
-                            ContactsContract.Data.MIMETYPE,
-                            ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
-                    .withValue(Photo.PHOTO, rawPhoto)
-                    .build());
+            try {
+                byte[] rawPhoto = getByteFromStream(phoneInputStream);
+                ops.add(ContentProviderOperation
+                        .newInsert(ContactsContract.Data.CONTENT_URI)
+                        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
+                        .withValue(
+                                ContactsContract.Data.MIMETYPE,
+                                ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
+                        .withValue(Photo.PHOTO, rawPhoto)
+                        .build());
+            } finally {
+                phoneInputStream.close();
+            }
         }
 
         mResolver.applyBatch(ContactsContract.AUTHORITY, ops);
     }
 
     private ContactInfo getContactInfoFromUri(Uri phoneLookupUri, String phoneNumber) {
-        Uri uri = Uri.withAppendedPath(phoneLookupUri,
-                Uri.encode(phoneNumber));
+        return getContactInfoFromPhoneLookup(Uri.withAppendedPath(phoneLookupUri,
+                        Uri.encode(phoneNumber)), /* forSip =*/ false);
+    }
+
+    private ContactInfo getContactInfoFromSipUri(Uri phoneLookupUri, String sipAddress) {
+        return getContactInfoFromPhoneLookup(
+                phoneLookupUri.buildUpon().appendEncodedPath(sipAddress).appendQueryParameter(
+                        PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, "1").build(), /* forSip =*/ true);
+    }
+
+    private ContactInfo getContactInfoFromPhoneLookup(Uri uri, boolean isForSip) {
         Cursor cursor = mResolver.query(uri,
                 new String[] {
                         PhoneLookup._ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.PHOTO_URI,
@@ -490,6 +544,11 @@
                 phoneNumber);
     }
 
+    private ContactInfo getEnterpriseContactInfoFromSipAddress(String phoneNumber) {
+        return getContactInfoFromSipUri(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
+                phoneNumber);
+    }
+
     private ContactInfo getEnterpriseContactInfoFromEmail(String email) {
         return getContactInfoFromEmailUri(Email.ENTERPRISE_CONTENT_LOOKUP_URI, email);
     }
@@ -520,4 +579,18 @@
     private boolean isEnterpriseContactId(String contactId) {
         return ContactsContract.Contacts.isEnterpriseContactId(Long.valueOf(contactId));
     }
+
+    private void assertPhotoUriReadable(String uri) throws IOException {
+        assertNotNull(uri);
+        final InputStream is = mResolver.openInputStream(Uri.parse(uri));
+        try {
+            // Make sure it's readabe.  Don't have to read all content.
+            is.read();
+        } finally {
+            try {
+                is.close();
+            } catch (IOException ignore) {
+            }
+        }
+    }
 }
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/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index bb8cd3f..3954bda 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -294,6 +294,10 @@
                     "testPrimaryProfileEnterprisePhoneLookupDuplicated_canAccessPrimaryContact",
                     0));
 
+            // Make sure SIP enterprise lookup works too.
+            assertTrue(runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".ContactsTest",
+                    "testPrimaryProfileEnterpriseSipLookup_canAccessEnterpriseContact", 0));
+
             // Managed user cannot use ordinary phone/email lookup api to access primary contacts
             assertTrue(runDeviceTestsAsUser(MANAGED_PROFILE_PKG, ".ContactsTest",
                     "testManagedProfilePhoneLookup_canNotAccessPrimaryContact", mUserId));
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/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/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/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..f062545 100644
--- a/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
+++ b/tests/tests/hardware/src/android/hardware/camera2/cts/CameraTestUtils.java
@@ -313,6 +313,9 @@
     public static class SimpleCaptureCallback extends CameraCaptureSession.CaptureCallback {
         private final LinkedBlockingQueue<TotalCaptureResult> mQueue =
                 new LinkedBlockingQueue<TotalCaptureResult>();
+        private final LinkedBlockingQueue<CaptureFailure> mFailureQueue =
+                new LinkedBlockingQueue<>();
+
         private AtomicLong mNumFramesArrived = new AtomicLong(0);
 
         @Override
@@ -336,6 +339,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 +490,35 @@
                     + "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;
+        }
+
         public boolean hasMoreResults()
         {
             return mQueue.isEmpty();
@@ -489,6 +527,7 @@
         public void drain() {
             mQueue.clear();
             mNumFramesArrived.getAndSet(0);
+            mFailureQueue.clear();
         }
     }
 
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..4061412 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,8 @@
     private enum CaptureTestCase {
         SINGLE_SHOT,
         BURST,
-        MIXED_BURST
+        MIXED_BURST,
+        ABORT_CAPTURE
     }
 
     /**
@@ -334,26 +336,76 @@
     }
 
     /**
+     * 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 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;
+            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 +445,7 @@
                                         NUM_REPROCESS_BURST);
                                 break;
                             default:
-                                throw new IllegalArgumentException("Invalid capture type");
+                                throw new IllegalArgumentException("Invalid test case");
                         }
                     }
                 }
@@ -597,6 +649,99 @@
     }
 
     /**
+     * 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();
+        }
+    }
+
+    /**
      * 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/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..bf0d6cf 100644
--- a/tests/tests/media/src/android/media/cts/EnumDevicesTest.java
+++ b/tests/tests/media/src/android/media/cts/EnumDevicesTest.java
@@ -95,6 +95,53 @@
         }
     }
 
+    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];
+            // 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;
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/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/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/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..81006c1 100644
--- a/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/PhoneNumberUtilsTest.java
@@ -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.addPhoneTtsSpan(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);
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