Merge "CTS: Fix cts on gsi for statsd" into pi-dev
diff --git a/apps/CameraITS/tests/scene4/test_aspect_ratio_and_crop.py b/apps/CameraITS/tests/scene4/test_aspect_ratio_and_crop.py
index cf30457..75a95d2 100644
--- a/apps/CameraITS/tests/scene4/test_aspect_ratio_and_crop.py
+++ b/apps/CameraITS/tests/scene4/test_aspect_ratio_and_crop.py
@@ -63,23 +63,50 @@
         if np.isclose(sensor_ar, convert_ar_to_float(ar_string), atol=FMT_ATOL):
             match_ar = ar_string
     if not match_ar:
-        print "Error: no aspect ratio match with sensor parameters!"
+        print "Warning! RAW aspect ratio not in:", AR_CHECKED
     return match_ar
 
 
-def aspect_ratio_scale_factors(camera_ar_string):
+def aspect_ratio_scale_factors(ref_ar_string, props):
     """Determine scale factors for each aspect ratio to correct cropping.
 
     Args:
-        camera_ar_string:   camera aspect ratio that is the baseline
+        ref_ar_string:      camera aspect ratio that is the reference
+        props:              camera properties
     Returns:
         dict of correction ratios with AR_CHECKED values as keys
     """
-    ar_scaling = {}
-    camera_ar = convert_ar_to_float(camera_ar_string)
+    ref_ar = convert_ar_to_float(ref_ar_string)
+
+    # find sensor area
+    height_max = 0
+    width_max = 0
     for ar_string in AR_CHECKED:
-        ar = convert_ar_to_float(ar_string)
-        ar_scaling[ar_string] = ar / camera_ar
+        match_ar = [float(x) for x in ar_string.split(":")]
+        f = its.objects.get_largest_yuv_format(props, match_ar=match_ar)
+        if f["height"] > height_max:
+            height_max = f["height"]
+        if f["width"] > width_max:
+            width_max = f["width"]
+    sensor_ar = float(width_max) / height_max
+
+    # apply scaling
+    ar_scaling = {}
+    for ar_string in AR_CHECKED:
+        target_ar = convert_ar_to_float(ar_string)
+        # scale down to sensor with greater (or equal) dims
+        if ref_ar >= sensor_ar:
+            scaling = sensor_ar / ref_ar
+        else:
+            scaling = ref_ar / sensor_ar
+
+        # scale up due to cropping to other format
+        if target_ar >= sensor_ar:
+            scaling = scaling * target_ar / sensor_ar
+        else:
+            scaling = scaling * sensor_ar / target_ar
+
+        ar_scaling[ar_string] = scaling
     return ar_scaling
 
 
@@ -95,10 +122,20 @@
         ref_fov:    dict with [fmt, % coverage, w, h]
     """
     ref_fov = {}
-    ar = determine_sensor_aspect_ratio(props)
-    match_ar = [float(x) for x in ar.split(":")]
-    fmt = its.objects.get_largest_yuv_format(props, match_ar=match_ar)
-    cap = cam.do_capture(req, fmt)
+    pixels = []
+    fmt_list = []
+    # find number of pixels in different formats
+    for ar in AR_CHECKED:
+        match_ar = [float(x) for x in ar.split(":")]
+        f = its.objects.get_largest_yuv_format(props, match_ar=match_ar)
+        pixels.append(f["height"] * f["width"])
+        fmt_list.append(f)
+
+    # use image with largest coverage as reference
+    ar_max_pixels = np.argmax(pixels)
+
+    # capture and determine circle area in image
+    cap = cam.do_capture(req, fmt_list[ar_max_pixels])
     w = cap["width"]
     h = cap["height"]
     img = its.image.convert_capture_to_rgb_image(cap, props=props)
@@ -106,7 +143,7 @@
     img_name = "%s_%s_w%d_h%d.png" % (NAME, "yuv", w, h)
     _, _, circle_size = measure_aspect_ratio(img, False, img_name, True)
     fov_percent = calc_circle_image_ratio(circle_size[1], circle_size[0], w, h)
-    ref_fov["fmt"] = ar
+    ref_fov["fmt"] = AR_CHECKED[ar_max_pixels]
     ref_fov["percent"] = fov_percent
     ref_fov["w"] = w
     ref_fov["h"] = h
@@ -259,16 +296,20 @@
             factor_cp_thres = (min(size_raw[0:1])/4.0) / max(circle_size_raw)
             thres_l_cp_test = THRESH_L_CP * factor_cp_thres
             thres_xs_cp_test = THRESH_XS_CP * factor_cp_thres
+            # If RAW in AR_CHECKED, use it as reference
             ref_fov["fmt"] = determine_sensor_aspect_ratio(props)
-            ref_fov["percent"] = raw_fov_percent
-            ref_fov["w"] = w_raw
-            ref_fov["h"] = h_raw
-            print "Using RAW reference:", ref_fov
+            if ref_fov["fmt"]:
+                ref_fov["percent"] = raw_fov_percent
+                ref_fov["w"] = w_raw
+                ref_fov["h"] = h_raw
+                print "Using RAW reference:", ref_fov
+            else:
+                ref_fov = find_yuv_fov_reference(cam, req, props)
         else:
             ref_fov = find_yuv_fov_reference(cam, req, props)
 
         # Determine scaling factors for AR calculations
-        ar_scaling = aspect_ratio_scale_factors(ref_fov["fmt"])
+        ar_scaling = aspect_ratio_scale_factors(ref_fov["fmt"], props)
 
         # Take pictures of each settings with all the image sizes available.
         for fmt in format_list:
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index a19ad9c..797d855 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -1086,7 +1086,7 @@
         1. Connect device via usb to computer.\n
         2. Click \"Show overlay\" button.  Settings may appear if the CTS Verifier app doesn\'t have display over apps permission.  Enable this permission and then click back to navigate back to the app.\n
         3. Trigger USB debugging dialog (from computer terminal): \"adb shell am start -e fingerprints placeholder -e key placeholder com.android.systemui/.UsbDebuggingActivityAlias\"\n
-        4. USB debugging dialog should appear with the overlay on top saying \"This message covers the USB debugging RSA prompt\" to appear.\n
+        4. USB debugging dialog should appear.  If the overlay cannot be seen above the USB debugging dialog, PASS this test (no need to proceed to Step 5).  Else, if the overlay does appear on top saying \"This message covers the USB debugging RSA prompt\", continue to Step 5.\n
         5. Try clicking OK. \n
         Test pass if you cannot click OK when the text quoted above is on top of the USB debugging dialog.  Toast should appear saying there is an overlay so Settings cannot verify your response. \n
         Note: Fake message overlay may remain on screen until you leave the test. This is working as intended. \n
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
index 3cb0bce..58e232b 100644
--- a/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/AndroidManifest.xml
@@ -191,6 +191,13 @@
           </intent-filter>
         </receiver>
 
+        <receiver android:name=".WipeDataReceiver">
+            <intent-filter>
+                <action android:name="com.android.cts.managedprofile.WIPE_DATA" />
+                <action android:name="com.android.cts.managedprofile.WIPE_DATA_WITH_REASON" />
+            </intent-filter>
+        </receiver>
+
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/WipeDataReceiver.java b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/WipeDataReceiver.java
new file mode 100644
index 0000000..0abea7d
--- /dev/null
+++ b/hostsidetests/devicepolicy/app/ManagedProfile/src/com/android/cts/managedprofile/WipeDataReceiver.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.managedprofile;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/**
+ * Invoke wipeData(), optionally including a reason. This is used by host side tests to destroy the
+ * work profile. The call is triggered via a broadcast instead of run as a normal test case, since
+ * the test process will be killed after calling wipeData() which will result in a test failure if
+ * this were run as a test case.
+ */
+public class WipeDataReceiver extends BroadcastReceiver {
+
+    private static final String ACTION_WIPE_DATA = "com.android.cts.managedprofile.WIPE_DATA";
+    private static final String ACTION_WIPE_DATA_WITH_REASON =
+            "com.android.cts.managedprofile.WIPE_DATA_WITH_REASON";
+    private static final String TEST_WIPE_DATA_REASON = "cts test for WipeDataWithReason";
+
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        final DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+        if (ACTION_WIPE_DATA.equals(intent.getAction())) {
+            dpm.wipeData(0);
+        } else if (ACTION_WIPE_DATA_WITH_REASON.equals(intent.getAction())) {
+            dpm.wipeData(0, TEST_WIPE_DATA_REASON);
+        }
+    }
+}
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
index 2dd5a2a..360e141 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/ManagedProfileTest.java
@@ -160,11 +160,7 @@
             return;
         }
         assertTrue(listUsers().contains(mProfileUserId));
-        runDeviceTestsAsUser(
-                MANAGED_PROFILE_PKG,
-                ".WipeDataTest",
-                "testWipeDataWithReason",
-                mProfileUserId);
+        sendWipeProfileBroadcast("com.android.cts.managedprofile.WIPE_DATA_WITH_REASON");
         // Note: the managed profile is removed by this test, which will make removeUserCommand in
         // tearDown() to complain, but that should be OK since its result is not asserted.
         assertUserGetsRemoved(mProfileUserId);
@@ -186,14 +182,19 @@
             return;
         }
         assertTrue(listUsers().contains(mProfileUserId));
-        runDeviceTestsAsUser(
-                MANAGED_PROFILE_PKG, ".WipeDataTest",
-                "testWipeData", mProfileUserId);
+        sendWipeProfileBroadcast("com.android.cts.managedprofile.WIPE_DATA");
         // Note: the managed profile is removed by this test, which will make removeUserCommand in
         // tearDown() to complain, but that should be OK since its result is not asserted.
         assertUserGetsRemoved(mProfileUserId);
     }
 
+    private void sendWipeProfileBroadcast(String action) throws Exception {
+        final String cmd = "am broadcast --receiver-foreground --user " + mProfileUserId
+            + " -a " + action
+            + " com.android.cts.managedprofile/.WipeDataReceiver";
+        getDevice().executeShellCommand(cmd);
+    }
+
     public void testLockNowWithKeyEviction() throws Exception {
         if (!mHasFeature || !mSupportsFbe) {
             return;
diff --git a/hostsidetests/incident/src/com/android/server/cts/GraphicsStatsValidationTest.java b/hostsidetests/incident/src/com/android/server/cts/GraphicsStatsValidationTest.java
index 4454591..5237de9 100644
--- a/hostsidetests/incident/src/com/android/server/cts/GraphicsStatsValidationTest.java
+++ b/hostsidetests/incident/src/com/android/server/cts/GraphicsStatsValidationTest.java
@@ -169,7 +169,7 @@
         // valid ranges.
         assertTrue(summary.getJankyFrames() <= summary.getTotalFrames());
         assertTrue(summary.getMissedVsyncCount() <= summary.getJankyFrames());
-        assertTrue(summary.getHighInputLatencyCount() <= summary.getJankyFrames());
+        assertTrue(summary.getHighInputLatencyCount() <= summary.getTotalFrames());
         assertTrue(summary.getSlowUiThreadCount() <= summary.getJankyFrames());
         assertTrue(summary.getSlowBitmapUploadCount() <= summary.getJankyFrames());
         assertTrue(summary.getSlowDrawCount() <= summary.getJankyFrames());
diff --git a/hostsidetests/security/AndroidTest.xml b/hostsidetests/security/AndroidTest.xml
index 78aa311..6645dd5 100755
--- a/hostsidetests/security/AndroidTest.xml
+++ b/hostsidetests/security/AndroidTest.xml
@@ -49,6 +49,11 @@
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="CVE-2016-2460->/data/local/tmp/CVE-2016-2460" />
 
+        <!--__________________-->
+        <!-- Bulletin 2016-07 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2016-3818->/data/local/tmp/CVE-2016-3818" />
+
         <!-- Bulletin 2016-09 -->
         <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
         <option name="push" value="CVE-2016-2471->/data/local/tmp/CVE-2016-2471" />
diff --git a/hostsidetests/security/securityPatch/CVE-2016-3818/Android.mk b/hostsidetests/security/securityPatch/CVE-2016-3818/Android.mk
new file mode 100755
index 0000000..0fe16b7
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2016-3818/Android.mk
@@ -0,0 +1,32 @@
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := CVE-2016-3818
+LOCAL_SRC_FILES := poc.c
+LOCAL_MULTILIB := both
+LOCAL_MODULE_STEM_32 := $(LOCAL_MODULE)32
+LOCAL_MODULE_STEM_64 := $(LOCAL_MODULE)64
+
+# Tag this module as a cts test artifact
+LOCAL_COMPATIBILITY_SUITE := cts vts sts
+LOCAL_CTS_TEST_PACKAGE := android.security.cts
+
+LOCAL_ARM_MODE := arm
+LOCAL_CFLAGS += -Wall -Werror
+LOCAL_LDFLAGS += -fPIE -pie
+LOCAL_LDFLAGS += -rdynamic
+include $(BUILD_CTS_EXECUTABLE)
diff --git a/hostsidetests/security/securityPatch/CVE-2016-3818/poc.c b/hostsidetests/security/securityPatch/CVE-2016-3818/poc.c
new file mode 100644
index 0000000..4a204fc
--- /dev/null
+++ b/hostsidetests/security/securityPatch/CVE-2016-3818/poc.c
@@ -0,0 +1,55 @@
+/**
+ * Copyright (C) 2018 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.
+ */
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+int main(void) {
+  struct rlimit rlim;
+  size_t i;
+
+  int result = getrlimit(RLIMIT_AS, &rlim);
+  printf("%lu\n", rlim.rlim_cur);
+  printf("%lu\n", rlim.rlim_max);
+
+  rlim.rlim_cur = 384 * 1024 * 1024;
+  result = setrlimit(RLIMIT_AS, &rlim);
+
+  /*
+   * Issue exists only in kitkat. It passes in
+   * android M onwards. In failure scenario, device reboots.
+   */
+  size_t to_alloc = 1.6 * 1024 * 1024 * 1024;
+  char *mem = (char *)malloc(to_alloc);
+
+  printf("%p\n", mem);
+  if (mem) {
+    for (i = 0; i < to_alloc; i++) {
+      mem[i] = 0;
+    }
+    printf("filled\n");
+  }
+
+  free(mem);
+  return 0;
+}
diff --git a/hostsidetests/security/src/android/security/cts/Poc16_07.java b/hostsidetests/security/src/android/security/cts/Poc16_07.java
new file mode 100644
index 0000000..2601d43
--- /dev/null
+++ b/hostsidetests/security/src/android/security/cts/Poc16_07.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.security.cts;
+
+import android.platform.test.annotations.SecurityTest;
+
+@SecurityTest
+public class Poc16_07 extends SecurityTestCase {
+    /**
+     *  b/28740702
+     */
+    @SecurityTest
+    public void testPocCVE_2016_3818() throws Exception {
+        AdbUtils.runPoc("CVE-2016-3818", getDevice(), 60);
+    }
+}
diff --git a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
index 2418087..3347bde 100644
--- a/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
+++ b/hostsidetests/statsd/src/android/cts/statsd/atom/HostAtomTests.java
@@ -581,34 +581,6 @@
         }
     }
 
-    public void testBluetoothActivityInfo() throws Exception {
-        if (statsdDisabled()) {
-            return;
-        }
-        if (!hasFeature(FEATURE_BLUETOOTH, true)) return;
-        StatsdConfig.Builder config = getPulledConfig();
-        addGaugeAtom(config, Atom.BLUETOOTH_ACTIVITY_INFO_FIELD_NUMBER, null);
-
-        turnScreenOff();
-
-        uploadConfig(config);
-
-        Thread.sleep(WAIT_TIME_LONG);
-        turnScreenOn();
-        Thread.sleep(WAIT_TIME_LONG);
-
-        List<Atom> dataList = getGaugeMetricDataList();
-
-        for (Atom atom: dataList) {
-            assertTrue(atom.getBluetoothActivityInfo().getTimestampMillis() > 0);
-            assertTrue(atom.getBluetoothActivityInfo().getBluetoothStackState() >= 0);
-            assertTrue(atom.getBluetoothActivityInfo().getControllerIdleTimeMillis() > 0);
-            assertTrue(atom.getBluetoothActivityInfo().getControllerTxTimeMillis() >= 0);
-            assertTrue(atom.getBluetoothActivityInfo().getControllerRxTimeMillis() >= 0);
-            assertTrue(atom.getBluetoothActivityInfo().getEnergyUsed() >= 0);
-        }
-    }
-
     // Explicitly tests if the adb command to log a breadcrumb is working.
     public void testBreadcrumbAdb() throws Exception {
         if (statsdDisabled()) {
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
index d0bab51..5888273 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityTextTraversalTest.java
@@ -2970,162 +2970,6 @@
     }
 
     @MediumTest
-    public void testActionNextAndPreviousAtGranularityPageOverText() throws Exception {
-        final EditText editText = (EditText) getActivity().findViewById(R.id.edit);
-
-        getInstrumentation().runOnMainSync(new Runnable() {
-            @Override
-            public void run() {
-                editText.setVisibility(View.VISIBLE);
-                editText.setText(getString(R.string.android_wiki));
-                Selection.removeSelection(editText.getText());
-            }
-        });
-
-        final AccessibilityNodeInfo text = getInstrumentation().getUiAutomation()
-               .getRootInActiveWindow().findAccessibilityNodeInfosByText(getString(
-                       R.string.android_wiki)).get(0);
-
-        final int granularities = text.getMovementGranularities();
-        assertEquals(granularities, AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
-
-        final Bundle arguments = new Bundle();
-        arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
-                AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
-
-        // Move forward a few pages
-        for (int i = 0; i < CHARACTER_INDICES_OF_PAGE_START.length - 1; i++) {
-            AccessibilityEvent event = performMovementActionAndGetEvent(
-                    text,
-                    AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY,
-                    AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE,
-                    false);
-            assertEquals(event.getClassName(), EditText.class.getName());
-            assertTrue("Event should contain text", event.getText().size() > 0);
-            assertTrue("Event text doesn't match. Expected: " + getString(R.string.android_wiki)
-                    + ". Received:" + event.getText().get(0),
-                    TextUtils.equals(event.getText().get(0), getString(R.string.android_wiki)));
-            assertEquals("Event from should be start of text skipped.",
-                    CHARACTER_INDICES_OF_PAGE_START[i], event.getFromIndex());
-            assertEquals("Event to should be end of text skipped.",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1], event.getToIndex());
-            // Verify the selection position has changed.
-            assertEquals("Event selection start should match position it moved to.",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1],
-                    Selection.getSelectionStart(editText.getText()));
-            assertEquals("Event selection end should match position it moved to.",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1],
-                    Selection.getSelectionEnd(editText.getText()));
-        }
-
-        // Move back to the beginning
-        for (int i = CHARACTER_INDICES_OF_PAGE_START.length - 2; i >= 0; i--) {
-            AccessibilityEvent event = performMovementActionAndGetEvent(
-                    text,
-                    AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
-                    AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE,
-                    false);
-            assertEquals(event.getClassName(), EditText.class.getName());
-            assertTrue("Event should contain text", event.getText().size() > 0);
-            assertTrue("Event text doesn't match. Expected: " + getString(R.string.android_wiki)
-                            + ". Received:" + event.getText().get(0),
-                    TextUtils.equals(event.getText().get(0), getString(R.string.android_wiki)));
-            assertEquals("Event from should be start of text skipped.",
-                    CHARACTER_INDICES_OF_PAGE_START[i], event.getFromIndex());
-            assertEquals("Event to should be end of text skipped.",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1], event.getToIndex());
-            // Verify the selection position has changed.
-            assertEquals("Event selection start should match position it moved to.",
-                    CHARACTER_INDICES_OF_PAGE_START[i],
-                    Selection.getSelectionStart(editText.getText()));
-            assertEquals("Event selection end should match position it moved to.",
-                    CHARACTER_INDICES_OF_PAGE_START[i],
-                    Selection.getSelectionEnd(editText.getText()));
-        }
-    }
-
-    @MediumTest
-    public void testActionNextAndPreviousAtGranularityPageOverTextExtend() throws Exception {
-        final EditText editText = (EditText) getActivity().findViewById(R.id.edit);
-
-        getInstrumentation().runOnMainSync(new Runnable() {
-            @Override
-            public void run() {
-                editText.setVisibility(View.VISIBLE);
-                editText.setText(getString(R.string.android_wiki));
-                Selection.removeSelection(editText.getText());
-            }
-        });
-
-        final AccessibilityNodeInfo text = getInstrumentation().getUiAutomation()
-               .getRootInActiveWindow().findAccessibilityNodeInfosByText(getString(
-                       R.string.android_wiki)).get(0);
-
-        final int granularities = text.getMovementGranularities();
-        assertEquals(granularities, AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH
-                | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
-
-        final Bundle arguments = new Bundle();
-        arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
-                AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
-
-        // Move forward a few pages
-        for (int i = 0; i < CHARACTER_INDICES_OF_PAGE_START.length - 1; i++) {
-            AccessibilityEvent event = performMovementActionAndGetEvent(
-                    text,
-                    AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY,
-                    AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE,
-                    true);
-            assertEquals(event.getClassName(), EditText.class.getName());
-            assertTrue("Event should contain text", event.getText().size() > 0);
-            assertTrue("Event text doesn't match. Expected: " + getString(R.string.android_wiki)
-                            + ". Received:" + event.getText().get(0),
-                    TextUtils.equals(event.getText().get(0), getString(R.string.android_wiki)));
-            assertEquals("Event from should be start of text skipped",
-                    CHARACTER_INDICES_OF_PAGE_START[i], event.getFromIndex());
-            assertEquals("Event to should be end of text skipped",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1], event.getToIndex());
-            // Verify the selection position has changed.
-            assertEquals("Event selection start should stay at beginning",
-                    0, Selection.getSelectionStart(editText.getText()));
-            assertEquals("Event selection end should match current position",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1],
-                    Selection.getSelectionEnd(editText.getText()));
-        }
-
-        // Move back to the beginning
-        for (int i = CHARACTER_INDICES_OF_PAGE_START.length - 2; i >= 0; i--) {
-            AccessibilityEvent event = performMovementActionAndGetEvent(
-                    text,
-                    AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY,
-                    AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE,
-                    true);
-            assertEquals(event.getClassName(), EditText.class.getName());
-            assertTrue("Event should contain text", event.getText().size() > 0);
-            assertTrue("Event text doesn't match. Expected: " + getString(R.string.android_wiki)
-                            + ". Received:" + event.getText().get(0),
-                    TextUtils.equals(event.getText().get(0), getString(R.string.android_wiki)));
-            assertEquals("Event from should be start of text skipped",
-                    CHARACTER_INDICES_OF_PAGE_START[i], event.getFromIndex());
-            assertEquals("Event to should be end of text skipped",
-                    CHARACTER_INDICES_OF_PAGE_START[i + 1], event.getToIndex());
-            // Verify the selection position has changed.
-            assertEquals("Event selection start should stay at beginning",
-                    0, Selection.getSelectionStart(editText.getText()));
-            assertEquals("Event selection end should match current position",
-                    CHARACTER_INDICES_OF_PAGE_START[i],
-                    Selection.getSelectionEnd(editText.getText()));
-        }
-    }
-
-    @MediumTest
     public void testActionNextAndPreviousAtGranularityParagraphOverText() throws Exception {
         final TextView textView = (TextView) getActivity().findViewById(R.id.edit);
 
diff --git a/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java b/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java
index 9a4e42c..98fa7af 100644
--- a/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/CameraDeviceTest.java
@@ -2476,6 +2476,12 @@
                 // Skip unknown templates here
         }
 
+        // Check distortion correction mode
+        if (mStaticInfo.isDistortionCorrectionSupported()) {
+            mCollector.expectKeyValueNotEquals(request, DISTORTION_CORRECTION_MODE,
+                    CaptureRequest.DISTORTION_CORRECTION_MODE_OFF);
+        }
+
         // TODO: use the list of keys from CameraCharacteristics to avoid expecting
         //       keys which are not available by this CameraDevice.
     }
diff --git a/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java b/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java
index c4174ca..4146333 100644
--- a/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/CaptureResultTest.java
@@ -26,6 +26,7 @@
 import android.hardware.camera2.TotalCaptureResult;
 import android.media.Image;
 import android.media.ImageReader;
+import android.os.Build;
 import android.os.SystemClock;
 import android.platform.test.annotations.AppModeFull;
 import android.util.Pair;
@@ -473,6 +474,10 @@
                         errorCollector.expectEquals(msg,
                                 requestBuilder.get(CaptureRequest.STATISTICS_OIS_DATA_MODE),
                                 result.get(CaptureResult.STATISTICS_OIS_DATA_MODE));
+                    } else if (key.equals(CaptureResult.DISTORTION_CORRECTION_MODE)) {
+                         errorCollector.expectEquals(msg,
+                                requestBuilder.get(CaptureRequest.DISTORTION_CORRECTION_MODE),
+                                result.get(CaptureResult.DISTORTION_CORRECTION_MODE));
                     } else {
                         // Only do non-null check for the rest of keys.
                         errorCollector.expectKeyValueNotNull(failMsg, result, key);
@@ -552,23 +557,9 @@
         }
 
         //Keys for lens distortion correction
-        boolean distortionCorrectionSupported = false;
-        int[] distortionModes = staticInfo.getCharacteristics().get(
-                CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
-        if (distortionModes == null) {
+        boolean distortionCorrectionSupported = staticInfo.isDistortionCorrectionSupported();
+        if (!distortionCorrectionSupported) {
             waiverKeys.add(CaptureResult.DISTORTION_CORRECTION_MODE);
-        } else {
-            boolean gotNonOff = false;
-            for (int mode : distortionModes) {
-                if (mode != CaptureRequest.DISTORTION_CORRECTION_MODE_OFF) {
-                    gotNonOff = true;
-                    distortionCorrectionSupported = true;
-                    break;
-                }
-            }
-            if (!gotNonOff) {
-                waiverKeys.add(CaptureResult.DISTORTION_CORRECTION_MODE);
-            }
         }
 
         // These keys must present on either DEPTH or distortion correction devices
@@ -578,9 +569,16 @@
             waiverKeys.add(CaptureResult.LENS_INTRINSIC_CALIBRATION);
             waiverKeys.add(CaptureResult.LENS_RADIAL_DISTORTION);
             waiverKeys.add(CaptureResult.LENS_DISTORTION);
+        } else {
+            // Radial distortion doesn't need to be present for new devices, or old devices that
+            // opt in the new lens distortion tag.
+            CameraCharacteristics c = staticInfo.getCharacteristics();
+            if (Build.VERSION.FIRST_SDK_INT > Build.VERSION_CODES.O_MR1 ||
+                    c.get(CameraCharacteristics.LENS_DISTORTION) != null) {
+                waiverKeys.add(CaptureResult.LENS_RADIAL_DISTORTION);
+            }
         }
 
-
         // Waived if RAW output is not supported
         int[] outputFormats = staticInfo.getAvailableFormats(
                 StaticMetadata.StreamDirection.Output);
diff --git a/tests/camera/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java b/tests/camera/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
index 22851e6..7476747 100644
--- a/tests/camera/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/ExtendedCameraCharacteristicsTest.java
@@ -885,8 +885,34 @@
             Integer poseReference = c.get(CameraCharacteristics.LENS_POSE_REFERENCE);
             float[] cameraIntrinsics = c.get(CameraCharacteristics.LENS_INTRINSIC_CALIBRATION);
             float[] distortion = getLensDistortion(c);
+            Size pixelArraySize = c.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE);
             Rect precorrectionArray = c.get(
                 CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
+            Rect activeArray = c.get(
+                CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
+
+            // Verify pre-correction array encloses active array
+            mCollector.expectTrue("preCorrectionArray [" + precorrectionArray.left + ", " +
+                    precorrectionArray.top + ", " + precorrectionArray.right + ", " +
+                    precorrectionArray.bottom + "] does not enclose activeArray[" +
+                    activeArray.left + ", " + activeArray.top + ", " + activeArray.right +
+                    ", " + activeArray.bottom,
+                    precorrectionArray.contains(activeArray.left, activeArray.top) &&
+                    precorrectionArray.contains(activeArray.right-1, activeArray.bottom-1));
+
+            // Verify pixel array encloses pre-correction array
+            mCollector.expectTrue("preCorrectionArray [" + precorrectionArray.left + ", " +
+                    precorrectionArray.top + ", " + precorrectionArray.right + ", " +
+                    precorrectionArray.bottom + "] isn't enclosed by pixelArray[" +
+                    pixelArraySize.getWidth() + ", " + pixelArraySize.getHeight() + "]",
+                    precorrectionArray.left >= 0 &&
+                    precorrectionArray.left < pixelArraySize.getWidth() &&
+                    precorrectionArray.right > 0 &&
+                    precorrectionArray.right <= pixelArraySize.getWidth() &&
+                    precorrectionArray.top >= 0 &&
+                    precorrectionArray.top < pixelArraySize.getHeight() &&
+                    precorrectionArray.bottom > 0 &&
+                    precorrectionArray.bottom <= pixelArraySize.getHeight());
 
             if (supportDepth) {
                 mCollector.expectTrue("Supports DEPTH_OUTPUT but does not support DEPTH16",
diff --git a/tests/camera/src/android/hardware/cts/CameraTest.java b/tests/camera/src/android/hardware/cts/CameraTest.java
index 9efccf1..81b42ef 100644
--- a/tests/camera/src/android/hardware/cts/CameraTest.java
+++ b/tests/camera/src/android/hardware/cts/CameraTest.java
@@ -194,6 +194,13 @@
      * Terminates the message looper thread.
      */
     private void terminateMessageLooper() throws Exception {
+        terminateMessageLooper(false);
+    }
+
+    /*
+     * Terminates the message looper thread, optionally allowing evict error
+     */
+    private void terminateMessageLooper(boolean allowEvict) throws Exception {
         mLooper.quit();
         // Looper.quit() is asynchronous. The looper may still has some
         // preview callbacks in the queue after quit is called. The preview
@@ -203,7 +210,13 @@
         mLooper.getThread().join();
         mCamera.release();
         mCamera = null;
-        assertEquals("Got camera error callback.", NO_ERROR, mCameraErrorCode);
+        if (allowEvict) {
+            assertTrue("Got unexpected camera error callback.",
+                    (NO_ERROR == mCameraErrorCode ||
+                    Camera.CAMERA_ERROR_EVICTED == mCameraErrorCode));
+        } else {
+            assertEquals("Got camera error callback.", NO_ERROR, mCameraErrorCode);
+        }
     }
 
     // Align 'x' to 'to', which should be a power of 2
@@ -2501,7 +2514,7 @@
         mCamera.stopPreview();
 
         firstLooper.quit();
-        terminateMessageLooper();
+        terminateMessageLooper(true/*allowEvict*/);
     }
 
     // This callback just signals on the condition variable, making it useful for checking that
diff --git a/tests/camera/utils/src/android/hardware/camera2/cts/helpers/StaticMetadata.java b/tests/camera/utils/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
index 0d0e592..646dfe7 100644
--- a/tests/camera/utils/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
+++ b/tests/camera/utils/src/android/hardware/camera2/cts/helpers/StaticMetadata.java
@@ -2357,6 +2357,26 @@
     }
 
     /**
+     * Check if distortion correction is supported.
+     */
+    public boolean isDistortionCorrectionSupported() {
+        boolean distortionCorrectionSupported = false;
+        int[] distortionModes = mCharacteristics.get(
+                CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES);
+        if (distortionModes == null) {
+            return false;
+        }
+
+        for (int mode : distortionModes) {
+            if (mode != CaptureRequest.DISTORTION_CORRECTION_MODE_OFF) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * Get the value in index for a fixed-size array from a given key.
      *
      * <p>If the camera device is incorrectly reporting values, log a warning and return
diff --git a/tests/tests/keystore/src/android/keystore/cts/ImportWrappedKeyTest.java b/tests/tests/keystore/src/android/keystore/cts/ImportWrappedKeyTest.java
index 66514c4..c9d2e2b 100644
--- a/tests/tests/keystore/src/android/keystore/cts/ImportWrappedKeyTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/ImportWrappedKeyTest.java
@@ -58,6 +58,7 @@
 import java.util.Arrays;
 
 import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
 import javax.crypto.spec.GCMParameterSpec;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.OAEPParameterSpec;
@@ -120,12 +121,11 @@
       if (!TestUtils.supports3DES()) {
           return;
         }
-
-        random.setSeed(0);
-
-        byte[] keyMaterial = new byte[24]; //  192 bits in a 168-bit 3DES key
+        KeyGenerator kg = KeyGenerator.getInstance("DESEDE");
+        kg.init(168);
+        byte[] keyMaterial = kg.generateKey().getEncoded();
         random.nextBytes(keyMaterial);
-        byte[] mask = new byte[32]; // Zero mask
+        byte[] mask = new byte[24]; // Zero mask
 
         KeyPair kp;
         try {
@@ -169,17 +169,35 @@
       }
 
       if (TestUtils.hasStrongBox(getContext())) {
-            random.setSeed(0);
-
-            byte[] keyMaterial = new byte[32];
+            KeyGenerator kg = KeyGenerator.getInstance("DESEDE");
+            kg.init(168);
+            byte[] keyMaterial = kg.generateKey().getEncoded();
             random.nextBytes(keyMaterial);
-            byte[] mask = new byte[32]; // Zero mask
+            byte[] mask = new byte[24]; // Zero mask
 
             importWrappedKey(wrapKey(
                     genKeyPair(WRAPPING_KEY_ALIAS, true).getPublic(),
                     keyMaterial,
                     mask,
                     makeAuthList(168, KM_ALGORITHM_3DES)));
+
+            // Use Key
+            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
+            keyStore.load(null, null);
+
+            assertTrue("Failed to load key after wrapped import", keyStore.containsAlias(ALIAS));
+
+            Key key = keyStore.getKey(ALIAS, null);
+
+            Cipher c = Cipher.getInstance("DESede/CBC/PKCS7Padding");
+            c.init(Cipher.ENCRYPT_MODE, key);
+            IvParameterSpec paramSpec = new IvParameterSpec(c.getIV());
+            byte[] encrypted = c.doFinal("hello, world".getBytes());
+
+            c = Cipher.getInstance("DESede/CBC/PKCS7Padding");
+            c.init(Cipher.DECRYPT_MODE, key, paramSpec);
+
+            assertEquals(new String(c.doFinal(encrypted)), "hello, world");
         } else {
             try {
                 genKeyPair(WRAPPING_KEY_ALIAS, true);
@@ -202,6 +220,25 @@
                     keyMaterial,
                     mask,
                     makeAuthList(keyMaterial.length * 8, KM_ALGORITHM_AES)));
+
+            // Use Key
+            KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
+            keyStore.load(null, null);
+
+            assertTrue("Failed to load key after wrapped import", keyStore.containsAlias(ALIAS));
+
+            Key key = keyStore.getKey(ALIAS, null);
+
+            Cipher c = Cipher.getInstance("AES/CBC/PKCS7Padding");
+            c.init(Cipher.ENCRYPT_MODE, key);
+            IvParameterSpec paramSpec = new IvParameterSpec(c.getIV());
+
+            byte[] encrypted = c.doFinal("hello, world".getBytes());
+
+            c = Cipher.getInstance("AES/CBC/PKCS7Padding");
+            c.init(Cipher.DECRYPT_MODE, key, paramSpec);
+
+            assertEquals(new String(c.doFinal(encrypted)), "hello, world");
         } else {
             try {
               random.setSeed(0);
diff --git a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
index 92c8917..da99a12 100644
--- a/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
+++ b/tests/tests/media/src/android/media/cts/AdaptivePlaybackTest.java
@@ -1238,9 +1238,10 @@
         return copy;
     }
 
-    public MediaFormat getAdaptiveFormat(int width, int height) {
+    public MediaFormat getAdaptiveFormat(int width, int height, int maxInputSize) {
         mAdaptiveFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, width);
         mAdaptiveFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, height);
+        mAdaptiveFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
         return mAdaptiveFormat;
     }
 
@@ -1248,6 +1249,14 @@
         return mFormat.getString(MediaFormat.KEY_MIME);
     }
 
+    public int getMaxInputSize() {
+        return mFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE);
+    }
+
+    public void setMaxInputSize(int maxInputSize) {
+        mFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
+    }
+
     public int getWidth() {
         return mFormat.getInteger(MediaFormat.KEY_WIDTH);
     }
@@ -1305,6 +1314,7 @@
             }
         }
 
+        int maxInputSize = 0;
         ByteBuffer readBuf = ByteBuffer.allocate(2000000);
         for (int ix = 0; ix < numFrames; ix++) {
             int sampleSize = extractor.readSampleData(readBuf, 0 /* offset */);
@@ -1316,6 +1326,11 @@
                 for (ByteBuffer csd: csds) {
                     sampleSize += csd.capacity();
                 }
+
+                if (maxInputSize < sampleSize) {
+                    maxInputSize = sampleSize;
+                }
+
                 ByteBuffer buf = ByteBuffer.allocate(sampleSize);
                 for (ByteBuffer csd: csds) {
                     csd.clear();
@@ -1335,6 +1350,10 @@
         }
         extractor.release();
         testFd.close();
+
+        /* Override MAX_INPUT_SIZE in format, as CSD is being combined
+         * with one of the input buffers */
+        media.setMaxInputSize(maxInputSize);
         return media;
     }
 }
@@ -1587,10 +1606,16 @@
             format = c.mediaList[i].getFormat();
         } else if (mFormatType == FORMAT_ADAPTIVE_FIRST && c.adaptive) {
             format = c.mediaList[i].getAdaptiveFormat(
-                c.mediaList[i].getWidth(), c.mediaList[i].getHeight());
+                c.mediaList[i].getWidth(), c.mediaList[i].getHeight(), c.mediaList[i].getMaxInputSize());
+            for (Media media : c.mediaList) {
+                /* get the largest max input size for all media and use that */
+                if (media.getMaxInputSize() > format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE)) {
+                    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, media.getMaxInputSize());
+                }
+            }
         } else if (mFormatType == FORMAT_ADAPTIVE_LARGEST && c.adaptive) {
             /* update adaptive format to max size used */
-            format = c.mediaList[i].getAdaptiveFormat(0, 0);
+            format = c.mediaList[i].getAdaptiveFormat(0, 0, 0);
             for (Media media : c.mediaList) {
                 /* get the largest width, and the largest height independently */
                 if (media.getWidth() > format.getInteger(MediaFormat.KEY_MAX_WIDTH)) {
@@ -1599,6 +1624,9 @@
                 if (media.getHeight() > format.getInteger(MediaFormat.KEY_MAX_HEIGHT)) {
                     format.setInteger(MediaFormat.KEY_MAX_HEIGHT, media.getHeight());
                 }
+                if (media.getMaxInputSize() > format.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE)) {
+                    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, media.getMaxInputSize());
+                }
             }
         }
         return format;
diff --git a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
index 1b1e669..2f155d8 100644
--- a/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/ProtectedBroadcastsTest.java
@@ -86,7 +86,6 @@
         "android.intent.action.NETWORK_SET_TIME",
         "android.intent.action.NETWORK_SET_TIMEZONE",
         "com.android.internal.intent.action.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS",
-        "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED",
     };
 
     /**
diff --git a/tests/tests/security/res/raw/cve_2016_3920.mp3 b/tests/tests/security/res/raw/cve_2016_3920.mp3
new file mode 100644
index 0000000..8c2abfc
--- /dev/null
+++ b/tests/tests/security/res/raw/cve_2016_3920.mp3
Binary files differ
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index 07033c7..a588cf0 100755
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -303,6 +303,11 @@
      ***********************************************************/
 
     @SecurityTest
+    public void testStagefright_cve_2016_3920() throws Exception {
+        doStagefrightTest(R.raw.cve_2016_3920);
+    }
+
+    @SecurityTest
     public void testStagefright_bug_68953854() throws Exception {
         doStagefrightTest(R.raw.bug_68953854, 1 * 60 * 1000);
     }
diff --git a/tests/tests/view/res/layout/view_layout.xml b/tests/tests/view/res/layout/view_layout.xml
index c3b97c5..31d8918 100644
--- a/tests/tests/view/res/layout/view_layout.xml
+++ b/tests/tests/view/res/layout/view_layout.xml
@@ -27,12 +27,12 @@
     <android.view.cts.MockView
         android:id="@+id/mock_view"
         android:layout_width="100px"
-        android:layout_height="200px"/>
+        android:layout_height="100px"/>
 
     <android.view.cts.MockView
         android:id="@+id/scroll_view"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:fadingEdge="horizontal|vertical"
         android:scrollIndicators="top|bottom"
@@ -45,7 +45,7 @@
     <android.view.cts.MockView
         android:id="@+id/scroll_view_2"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:requiresFadingEdge="horizontal|vertical"
         android:fadingEdgeLength="20px"
@@ -57,7 +57,7 @@
     <android.view.cts.MockView
         android:id="@+id/scroll_view_3"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:scrollbarThumbVertical="@drawable/scrollbar_no_size"
         android:scrollbarTrackVertical="@null"
@@ -67,7 +67,7 @@
     <android.view.cts.MockView
         android:id="@+id/scroll_view_4"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
         android:scrollbarTrackVertical="@null"
@@ -77,7 +77,7 @@
     <android.view.cts.MockView
         android:id="@+id/scroll_view_5"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
         android:scrollbarTrackVertical="@drawable/scrollbar_track"
@@ -87,7 +87,7 @@
     <android.view.cts.MockView
         android:id="@+id/scroll_view_6"
         android:layout_width="100px"
-        android:layout_height="200px"
+        android:layout_height="20px"
         android:scrollbars="horizontal|vertical"
         android:scrollbarThumbVertical="@drawable/scrollbar_thumb"
         android:scrollbarTrackVertical="@drawable/scrollbar_no_size"
diff --git a/tests/tests/view/src/android/view/cts/SearchEventTest.java b/tests/tests/view/src/android/view/cts/SearchEventTest.java
index 9ae9e61..b679fac 100644
--- a/tests/tests/view/src/android/view/cts/SearchEventTest.java
+++ b/tests/tests/view/src/android/view/cts/SearchEventTest.java
@@ -21,6 +21,7 @@
 
 import android.app.Instrumentation;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.hardware.input.InputManager;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.MediumTest;
@@ -73,6 +74,10 @@
 
     @Test
     public void testBasics() {
+        // Only run for non-watch devices
+        if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)) {
+            return;
+        }
         mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_SEARCH);
         SearchEvent se = mActivity.getTestSearchEvent();
         assertNotNull(se);
diff --git a/tests/tests/view/src/android/view/cts/ViewTest.java b/tests/tests/view/src/android/view/cts/ViewTest.java
index a742816..346a513 100644
--- a/tests/tests/view/src/android/view/cts/ViewTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewTest.java
@@ -1885,14 +1885,14 @@
         final MockView view = (MockView) mActivity.findViewById(R.id.mock_view);
         assertTrue(view.hasCalledOnMeasure());
         assertEquals(100, view.getMeasuredWidth());
-        assertEquals(200, view.getMeasuredHeight());
+        assertEquals(100, view.getMeasuredHeight());
 
         view.reset();
         mActivityRule.runOnUiThread(view::requestLayout);
         mInstrumentation.waitForIdleSync();
         assertTrue(view.hasCalledOnMeasure());
         assertEquals(100, view.getMeasuredWidth());
-        assertEquals(200, view.getMeasuredHeight());
+        assertEquals(100, view.getMeasuredHeight());
 
         view.reset();
         final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 100);
@@ -2589,7 +2589,7 @@
         assertEquals(0, rect.left);
         assertEquals(0, rect.top);
         assertEquals(100, rect.right);
-        assertEquals(200, rect.bottom);
+        assertEquals(100, rect.bottom);
 
         final LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(0, 300);
         mActivityRule.runOnUiThread(() -> view.setLayoutParams(layoutParams1));
diff --git a/tests/tests/widget/src/android/widget/cts/PopupMenuTest.java b/tests/tests/widget/src/android/widget/cts/PopupMenuTest.java
index 3a85f47..e76382e 100644
--- a/tests/tests/widget/src/android/widget/cts/PopupMenuTest.java
+++ b/tests/tests/widget/src/android/widget/cts/PopupMenuTest.java
@@ -28,6 +28,7 @@
 
 import android.app.Activity;
 import android.app.Instrumentation;
+import android.content.res.Resources;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
 import android.support.test.filters.MediumTest;
@@ -323,7 +324,9 @@
             final int prevGroupId =
                     i - 1 >= 0 ? menu.getItem(i - 1).getGroupId() : currGroupId;
             View itemView = menuItemList.getChildAt(i);
-            ImageView groupDivider = itemView.findViewById(com.android.internal.R.id.group_divider);
+            // Find com.android.internal.R.id.group_divider
+            ImageView groupDivider = itemView.findViewById(
+                    Resources.getSystem().getIdentifier("group_divider", "id", "android"));
 
             assertNotNull(groupDivider);
             if (!groupDividerEnabled || currGroupId == prevGroupId) {