Merge "Revert "UsbTest uses UsbDebuggingActivityAlias"" into oreo-mr1-cts-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 6aa1c71..868cefb 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -18,7 +18,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.android.cts.verifier"
       android:versionCode="5"
-      android:versionName="8.1_r2">
+      android:versionName="8.1_r3">
 
     <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27"/>
 
@@ -67,9 +67,6 @@
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 
-    <!-- Needed by UsbTest tapjacking -->
-    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
-
     <!-- Needed by the Audio Quality Verifier to store the sound samples that will be mailed. -->
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
@@ -97,14 +94,6 @@
         <provider android:name=".TestResultsProvider"
                 android:authorities="com.android.cts.verifier.testresultsprovider" />
 
-        <activity android:name=".admin.tapjacking.UsbTest" android:label="@string/usb_tapjacking_test">
-            <intent-filter>
-                <action android:name="android.intent.action.MAIN" />
-                <category android:name="android.cts.intent.category.MANUAL_TEST" />
-            </intent-filter>
-            <meta-data android:name="test_category" android:value="@string/test_category_device_admin" />
-        </activity>
-
         <activity android:name=".admin.PolicySerializationTestActivity"
                 android:label="@string/da_policy_serialization_test"
                 android:configChanges="keyboardHidden|orientation|screenSize">
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 9cec751..8c733ad 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -1510,6 +1510,7 @@
     <string name="ringer_mode_info">This test checks that Audio manager functionality that requires
         particular ringer mode states works properly.
     </string>
+    <string name="ringer_mode_pass_test">These tests are handled by CTS.</string>
     <string name="test_sound_effects">Test sound effects</string>
     <string name="test_vibrate_notification">Test vibrate notification</string>
     <string name="test_vibrate_ringer">Test vibrate ringer</string>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
index 9084441..2886478 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/RingerModeActivity.java
@@ -109,6 +109,7 @@
     protected List<InteractiveTestCase> createTestItems() {
         List<InteractiveTestCase> tests = new ArrayList<>();
         if (supportsConditionProviders()) {
+            tests.add(new PassTest());
             return tests;
         }
         tests.add(new SetModeAllTest());
@@ -179,6 +180,18 @@
 
     // Tests
 
+    protected class PassTest extends InteractiveTestCase {
+        @Override
+        protected View inflate(ViewGroup parent) {
+            return createRetryItem(parent, R.string.ringer_mode_pass_test);
+        }
+
+        @Override
+        protected void test() {
+           status = PASS;
+        }
+    }
+
 
     protected class SetModeAllTest extends InteractiveTestCase {
         @Override
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
index 83e68e4..871c2a0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
@@ -170,7 +170,8 @@
         } else {
             mTestStatusTx.setText("No Peripheral or No Matching Profile.");
         }
-
-        getPassButton().setEnabled(outPass && inPass);
+        // Headset not publicly available, violates CTS Verifier additional equipment guidelines.
+        // Allow skipping test. See b/67777923 for details.
+        getPassButton().setEnabled(true /*outPass && inPass*/);
     }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
index 98a7d18..861af28 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
@@ -122,7 +122,9 @@
             Log.i(TAG, "match:" + match);
             getPassButton().setEnabled(match);
         } else {
-            getPassButton().setEnabled(false);
+            // Headset not publicly available, violates CTS Verifier additional equipment
+            // guidelines. Allow skipping test. See b/67777923 for details.
+            getPassButton().setEnabled(true /*false*/);
         }
     }
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
index 5389afb..b4b0999 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
@@ -50,9 +50,10 @@
 
     //
     // USBAudioPeripheralActivity
-    //
+    // Headset not publicly available, violates CTS Verifier additional equipment guidelines.
+    // Allow skipping test. See b/67777923 for details.
     public void updateConnectStatus() {
-        getPassButton().setEnabled(mOutputDevInfo != null);
+        getPassButton().setEnabled(true /*mOutputDevInfo != null*/);
     }
 
     public class LocalClickListener implements View.OnClickListener {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
index f05bc9e..e878c82 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
@@ -134,9 +134,10 @@
 
     //
     // USBAudioPeripheralActivity
-    //
+    // Headset not publicly available, violates CTS Verifier additional equipment guidelines.
+    // Allow skipping test. See b/67777923 for details.
     public void updateConnectStatus() {
-        getPassButton().setEnabled(mOutputDevInfo != null);
+        getPassButton().setEnabled(true /*mOutputDevInfo != null*/);
     }
 
     public class LocalClickListener implements View.OnClickListener {
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java
index 87d8bd6..b9712a1 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java
@@ -257,6 +257,8 @@
                 runDeviceTests(READ_PKG, ".ReadMultiViewTest", "testROAccess", user);
             }
 
+            // for fuse file system
+            Thread.sleep(10000);
             for (int user : mUsers) {
                 runDeviceTests(WRITE_PKG, ".WriteMultiViewTest", "testMoveBack", user);
             }
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/StorageHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/StorageHostTest.java
index fa0120d..6bf71cf 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/StorageHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/StorageHostTest.java
@@ -79,6 +79,9 @@
             runDeviceTests(PKG_A, CLASS, "testAllocate", user);
         }
 
+        // for fuse file system
+        Thread.sleep(10000);
+
         // TODO: remove this once 34723223 is fixed
         getDevice().executeShellCommand("sync");
 
diff --git a/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java b/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
index 713ba17..9b69057 100644
--- a/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
+++ b/hostsidetests/appsecurity/test-apps/StorageStatsApp/src/com/android/cts/storagestatsapp/StorageStatsTest.java
@@ -223,6 +223,9 @@
         useWrite(makeUniqueFile(pics), 5 * MB_IN_BYTES);
         useWrite(makeUniqueFile(pics), 5 * MB_IN_BYTES);
 
+        // for fuse file system
+        Thread.sleep(10000);
+
         // TODO: remove this once 34723223 is fixed
         logCommand("sync");
 
diff --git a/hostsidetests/backup/src/android/cts/backup/FullbackupRulesHostSideTest.java b/hostsidetests/backup/src/android/cts/backup/FullbackupRulesHostSideTest.java
index 8dd589a..a508d47 100644
--- a/hostsidetests/backup/src/android/cts/backup/FullbackupRulesHostSideTest.java
+++ b/hostsidetests/backup/src/android/cts/backup/FullbackupRulesHostSideTest.java
@@ -20,6 +20,7 @@
 
 import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.log.LogUtil.CLog;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
diff --git a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
index 9ef4587..cb8f163 100644
--- a/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
+++ b/hostsidetests/content/test-apps/CtsSyncAccountAccessOtherCertTests/src/com/android/cts/content/CtsSyncAccountAccessOtherCertTestCases.java
@@ -80,7 +80,7 @@
 
     @Test
     public void testAccountAccess_otherCertAsAuthenticatorCanNotSeeAccount() throws Exception {
-        if (!hasDataConnection() || !hasNotificationSupport()) {
+        if (!hasDataConnection() || !hasNotificationSupport() || isRunningInVR()) {
             return;
         }
 
@@ -225,4 +225,11 @@
         SystemUtil.runShellCommand(InstrumentationRegistry.getInstrumentation(),
                 "cmd netpolicy remove restrict-background-whitelist " + Process.myUid());
     }
+
+    private boolean isRunningInVR() {
+        final Context context = InstrumentationRegistry.getTargetContext();
+        return ((context.getResources().getConfiguration().uiMode &
+                 Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_VR_HEADSET);
+    }
+
 }
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AlwaysOnVpnMultiStageTest.java b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AlwaysOnVpnMultiStageTest.java
index e445347c..6eed964 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AlwaysOnVpnMultiStageTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AlwaysOnVpnMultiStageTest.java
@@ -25,11 +25,15 @@
 
 import com.android.cts.deviceandprofileowner.vpn.VpnTestHelper;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * Contains methods to test always-on VPN invoked by DeviceAndProfileOwnerTest
  */
 public class AlwaysOnVpnMultiStageTest extends BaseDeviceAdminTest {
 
+    private final int MAX_NUMBER_OF_ATTEMPTS = 5;
+
     public void testAlwaysOnSet() throws Exception {
         // Setup always-on vpn
         VpnTestHelper.waitForVpn(mContext, VPN_PACKAGE, /* usable */ true);
@@ -46,6 +50,9 @@
         // After the vpn app being force-stop, expect that always-on package stays the same
         assertEquals(VPN_PACKAGE, mDevicePolicyManager.getAlwaysOnVpnPackage(
                 ADMIN_RECEIVER_COMPONENT));
+        for(int i = 0; i < MAX_NUMBER_OF_ATTEMPTS && VpnTestHelper.isNetworkVpn(mContext); ++i) {
+            Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+        }
         assertFalse(VpnTestHelper.isNetworkVpn(mContext));
         // Expect the network is still locked down after the vpn app process is killed
         try {
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AssistScreenCaptureDisabledTest.java b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AssistScreenCaptureDisabledTest.java
index db54ac3..d076920 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AssistScreenCaptureDisabledTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/AssistScreenCaptureDisabledTest.java
@@ -87,7 +87,11 @@
             Intent showSessionIntent = new Intent(ACTION_SHOW_SESSION);
             showSessionIntent.setPackage(ASSIST_PACKAGE);
             mContext.sendBroadcast(showSessionIntent);
-            Intent screenShotIntent = receiver.awaitForBroadcast();
+            Intent screenShotIntent = null;
+            for (int i = 0; i < MAX_ATTEMPTS_COUNT && (screenShotIntent == null); ++ i) {
+                Log.d(TAG, "has not received intent yet: wait for intent, attempt " + i);
+                screenShotIntent = receiver.awaitForBroadcast();
+            }
             Assert.assertNotNull(screenShotIntent);
             Assert.assertTrue(screenShotIntent.hasExtra(KEY_HAS_SCREENSHOT));
             assertEquals(possible, screenShotIntent.getBooleanExtra(KEY_HAS_SCREENSHOT, false));
diff --git a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/CreateAndManageUserTest.java b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/CreateAndManageUserTest.java
index a540c27..0159b128 100644
--- a/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/CreateAndManageUserTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceOwner/src/com/android/cts/deviceowner/CreateAndManageUserTest.java
@@ -34,7 +34,7 @@
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
 import java.lang.reflect.Field;
-import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -303,7 +303,7 @@
     }
 
     static class LocalBroadcastReceiver extends BroadcastReceiver {
-        private SynchronousQueue<UserHandle> mQueue = new SynchronousQueue<UserHandle>();
+        private LinkedBlockingQueue<UserHandle> mQueue = new LinkedBlockingQueue<UserHandle>(1);
 
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
old mode 100644
new mode 100755
index fc90f91..e08c4cf
--- a/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
+++ b/hostsidetests/services/activityandwindowmanager/activitymanager/src/android/server/cts/ActivityManagerAppConfigurationTests.java
@@ -492,9 +492,7 @@
         logSeparator = clearLogcat();
         moveActivityToStack(activityName, DOCKED_STACK_ID);
         final ReportedSizes finalDockedSizes = getActivityDisplaySize(activityName, logSeparator);
-
-        // After activity configuration was changed twice it must report same size as original one.
-        assertSizesAreSame(initialDockedSizes, finalDockedSizes);
+        assertSizesAreSane(fullscreenSizes, finalDockedSizes);
     }
 
     /**
@@ -508,16 +506,6 @@
         assertEquals(rotationB.displayWidth, rotationB.metricsWidth);
         assertEquals(rotationB.displayHeight, rotationB.metricsHeight);
 
-        final boolean beforePortrait = rotationA.displayWidth < rotationA.displayHeight;
-        final boolean afterPortrait = rotationB.displayWidth < rotationB.displayHeight;
-        assertFalse(beforePortrait == afterPortrait);
-
-        final boolean beforeConfigPortrait = rotationA.widthDp < rotationA.heightDp;
-        final boolean afterConfigPortrait = rotationB.widthDp < rotationB.heightDp;
-        assertEquals(beforePortrait, beforeConfigPortrait);
-        assertEquals(afterPortrait, afterConfigPortrait);
-
-        assertEquals(rotationA.smallestWidthDp, rotationB.smallestWidthDp);
     }
 
     /**
diff --git a/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/AlertWindowsTests.java b/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/AlertWindowsTests.java
index bfed6d5..3290ddb 100644
--- a/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/AlertWindowsTests.java
+++ b/hostsidetests/services/activityandwindowmanager/windowmanager/src/android/server/cts/AlertWindowsTests.java
@@ -106,15 +106,34 @@
         assertAlertWindows(packageName, hasAlertWindowPermission, atLeastO);
     }
 
+    private boolean allWindowsHidden(ArrayList<WindowManagerState.WindowState> windows) {
+        for (WindowManagerState.WindowState ws : windows) {
+            if (ws.isShown()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     private void assertAlertWindows(String packageName, boolean hasAlertWindowPermission,
-            boolean atLeastO) {
+            boolean atLeastO) throws DeviceNotAvailableException {
         final WindowManagerState wMState = mAmWmState.getWmState();
 
         final ArrayList<WindowManagerState.WindowState> alertWindows = new ArrayList();
         wMState.getWindowsByPackageName(packageName, mAlertWindowTypes, alertWindows);
 
         if (!hasAlertWindowPermission) {
-            assertTrue("Should be empty alertWindows=" + alertWindows, alertWindows.isEmpty());
+            // When running in VR Mode, an App Op restriction is
+            // in place for SYSTEM_ALERT_WINDOW, which allows the window
+            // to be created, but will be hidden instead.
+            if (isUiModeLockedToVrHeadset()) {
+                assertTrue("Should not be empty alertWindows=" + alertWindows,
+                        !alertWindows.isEmpty());
+                assertTrue("All alert windows should be hidden",
+                        allWindowsHidden(alertWindows));
+            } else {
+                assertTrue("Should be empty alertWindows=" + alertWindows, alertWindows.isEmpty());
+            }
             return;
         }
 
diff --git a/hostsidetests/theme/app/src/android/theme/app/ThemeDeviceActivity.java b/hostsidetests/theme/app/src/android/theme/app/ThemeDeviceActivity.java
index 78dc3d4..8709f14 100644
--- a/hostsidetests/theme/app/src/android/theme/app/ThemeDeviceActivity.java
+++ b/hostsidetests/theme/app/src/android/theme/app/ThemeDeviceActivity.java
@@ -415,6 +415,5 @@
                     new TimePickerModifier()),
             new Layout(R.layout.togglebutton_checked, "togglebutton_checked"),
             new Layout(R.layout.togglebutton, "togglebutton"),
-            new Layout(R.layout.zoomcontrols, "zoomcontrols"),
     };
 }
diff --git a/tests/accessibilityservice/AndroidManifest.xml b/tests/accessibilityservice/AndroidManifest.xml
index cf6b774..c40f7aa 100644
--- a/tests/accessibilityservice/AndroidManifest.xml
+++ b/tests/accessibilityservice/AndroidManifest.xml
@@ -52,7 +52,8 @@
 
         <activity
             android:label="Full screen activity for gesture dispatch testing"
-            android:name=".AccessibilityGestureDispatchTest$GestureDispatchActivity" />
+            android:name=".AccessibilityGestureDispatchTest$GestureDispatchActivity"
+            android:screenOrientation="portrait" />
 
         <service
             android:name=".StubGestureAccessibilityService"
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
index df8c6f3..aa30f77 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
@@ -34,6 +34,8 @@
 import android.os.SystemClock;
 import android.test.ActivityInstrumentationTestCase2;
 import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.Display;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
@@ -52,6 +54,8 @@
  */
 public class AccessibilityGestureDispatchTest extends
         ActivityInstrumentationTestCase2<AccessibilityGestureDispatchTest.GestureDispatchActivity> {
+    private static final String TAG = AccessibilityGestureDispatchTest.class.getSimpleName();
+
     private static final int GESTURE_COMPLETION_TIMEOUT = 5000; // millis
     private static final int MOTION_EVENT_TIMEOUT = 1000; // millis
 
@@ -300,6 +304,12 @@
             return;
         }
 
+        int displayId = getActivity().getWindow().getDecorView().getDisplay().getDisplayId();
+        if (displayId != Display.DEFAULT_DISPLAY) {
+            Log.i(TAG, "Magnification is not supported on virtual displays.");
+            return;
+        }
+
         final WindowManager wm = (WindowManager) getInstrumentation().getContext().getSystemService(
                 Context.WINDOW_SERVICE);
         final StubMagnificationAccessibilityService magnificationService =
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
index 31292c3..18c02e5 100755
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityWindowQueryTest.java
@@ -26,7 +26,9 @@
 
 import android.accessibilityservice.AccessibilityService;
 import android.accessibilityservice.AccessibilityServiceInfo;
+import android.app.ActivityManager;
 import android.app.UiAutomation;
+import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.graphics.Rect;
@@ -43,6 +45,8 @@
 import android.widget.Button;
 import android.accessibilityservice.cts.R;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
@@ -617,13 +621,22 @@
             // Do nothing, assume split screen multi window is supported.
         }
 
-        // Get com.android.internal.R.bool.config_supportsMultiWindow
-        if (!getInstrumentation().getContext().getResources().getBoolean(
-                Resources.getSystem().getIdentifier("config_supportsMultiWindow", "bool",
-                        "android"))) {
-            // Check if multiWindow is supported.
+        /* In P as ActivityManager.supportsMultiWindow() becomes a @TestAPI
+           i.e. a compatibility requirement, make the test fail in the next API */
+        try {
+            final Method method = ActivityManager.class
+                    .getMethod("supportsMultiWindow", Context.class);
+            if (!(Boolean)method.invoke(getInstrumentation().getContext().getSystemService(
+                    ActivityManager.class), getInstrumentation().getContext())) {
+                // Check if multiWindow is supported.
+                return;
+            }
+        } catch (NoSuchMethodException e) {
+        } catch (IllegalAccessException e) {
+        } catch (InvocationTargetException e) {
             return;
         }
+
         setAccessInteractiveWindowsFlag();
         final UiAutomation uiAutomation = getInstrumentation().getUiAutomation();
         assertFalse(isDividerWindowPresent(uiAutomation));
diff --git a/tests/app/src/android/app/cts/ApplicationTest.java b/tests/app/src/android/app/cts/ApplicationTest.java
index 664d3ee..ee1758d 100644
--- a/tests/app/src/android/app/cts/ApplicationTest.java
+++ b/tests/app/src/android/app/cts/ApplicationTest.java
@@ -21,16 +21,25 @@
 import android.app.Instrumentation;
 import android.app.stubs.MockApplication;
 import android.app.stubs.MockApplicationActivity;
-import android.app.stubs.OrientationTestUtils;
 import android.content.Context;
 import android.content.Intent;
-import android.content.pm.PackageManager;
 import android.test.InstrumentationTestCase;
 
+import com.android.compatibility.common.util.SystemUtil;
+
 /**
  * Test {@link Application}.
  */
 public class ApplicationTest extends InstrumentationTestCase {
+    private static final String ERASE_FONT_SCALE_CMD = "settings delete system font_scale";
+    // 2 is an arbitrary value.
+    private static final String PUT_FONT_SCALE_CMD = "settings put system font_scale 2";
+
+    @Override
+    public void tearDown() throws Exception {
+        SystemUtil.runShellCommand(getInstrumentation(), ERASE_FONT_SCALE_CMD);
+    }
+
 
     public void testApplication() throws Throwable {
         final Instrumentation instrumentation = getInstrumentation();
@@ -43,27 +52,30 @@
         final MockApplication mockApp = (MockApplication) activity.getApplication();
         assertTrue(mockApp.isConstructorCalled);
         assertTrue(mockApp.isOnCreateCalled);
+        toggleFontScale();
+        assertTrue(waitForOnConfigurationChange(mockApp));
+    }
 
-        //skip if the device doesn't support both of portrait and landscape orientation screens.
-        final PackageManager pm = targetContext.getPackageManager();
-        if(!(pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE)
-                && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT))){
-            return;
-        }
+    // Font scale is a global configuration.
+    // This function will delete any previous font scale changes, apply one, and remove it.
+    private void toggleFontScale() throws Throwable {
+        SystemUtil.runShellCommand(getInstrumentation(), ERASE_FONT_SCALE_CMD);
+        getInstrumentation().waitForIdleSync();
+        SystemUtil.runShellCommand(getInstrumentation(), PUT_FONT_SCALE_CMD);
+        getInstrumentation().waitForIdleSync();
+        SystemUtil.runShellCommand(getInstrumentation(), ERASE_FONT_SCALE_CMD);
+    }
 
-        runTestOnUiThread(new Runnable() {
-            public void run() {
-               OrientationTestUtils.toggleOrientation(activity);
+    // Wait for a maximum of 5 seconds for global config change to occur.
+    private boolean waitForOnConfigurationChange(MockApplication mockApp) throws Throwable {
+        int retriesLeft = 5;
+        while(retriesLeft-- > 0) {
+            if (mockApp.isOnConfigurationChangedCalled) {
+                return true;
             }
-        });
-        instrumentation.waitForIdleSync();
-        final boolean isInMultiwindowMode = activity.isInMultiWindowMode();
-        if (activity.isInMultiWindowMode()) {
-            assertFalse("Orientation change should not trigger global configuration change when "
-                    + " in multi-window mode.", mockApp.isOnConfigurationChangedCalled);
-        } else {
-            assertTrue(mockApp.isOnConfigurationChangedCalled);
+            Thread.sleep(1000);
         }
+        return false;
     }
 
 }
diff --git a/tests/autofillservice/src/android/autofillservice/cts/CustomDescriptionWithLinkTestCase.java b/tests/autofillservice/src/android/autofillservice/cts/CustomDescriptionWithLinkTestCase.java
index 33f0943..210fab8 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/CustomDescriptionWithLinkTestCase.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/CustomDescriptionWithLinkTestCase.java
@@ -25,6 +25,7 @@
 import android.support.test.uiautomator.UiObject2;
 import android.widget.RemoteViews;
 
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -166,6 +167,7 @@
      * the Save UI should have been canceled.
      */
     @Test
+    @Ignore("Test fail on some devices because Recents UI is not well defined: b/72044685")
     public final void testTapLink_backToPreviousActivityByTappingRecents()
             throws Exception {
         saveUiCancelledAfterTappingLinkTest(PostSaveLinkTappedAction.TAP_RECENTS);
diff --git a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
index 898ca84..ab25326 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/LoginActivityTest.java
@@ -86,6 +86,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -1188,6 +1189,7 @@
     }
 
     @Test
+    @Ignore("Test fail on some devices because Recents UI is not well defined: b/72044685")
     public void testSaveGoesAwayWhenTappingRecentsButton() throws Exception {
         // Launches new activity first...
         startCheckoutActivityAsNewTask();
diff --git a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
index 9fb16a2..8e4ec03 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
@@ -35,6 +35,7 @@
 import android.support.test.uiautomator.UiObject2;
 import android.view.View;
 
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -298,6 +299,7 @@
     }
 
     @Test
+    @Ignore("Test fail on some devices because Recents UI is not well defined: b/72044685")
     public void testDismissSave_byTappingRecents() throws Exception {
         // Launches a different activity first.
         startWelcomeActivityOnNewTask();
diff --git a/tests/tests/assist/AndroidManifest.xml b/tests/tests/assist/AndroidManifest.xml
index a81ced2..0114ef5 100644
--- a/tests/tests/assist/AndroidManifest.xml
+++ b/tests/tests/assist/AndroidManifest.xml
@@ -24,8 +24,11 @@
 
     <application>
       <uses-library android:name="android.test.runner" />
+      <!-- resizeableActivity makes the TestStartActivity run on Primary display to accommodate
+           stack behavior assumptions in this test. See b/70032125 -->
       <activity android:name="android.assist.cts.TestStartActivity"
-                android:label="Assist Test Start Activity">
+                android:label="Assist Test Start Activity"
+                android:resizeableActivity="false">
           <intent-filter>
               <action android:name="android.intent.action.TEST_START_ACTIVITY_ASSIST_STRUCTURE" />
               <action android:name="android.intent.action.TEST_START_ACTIVITY_DISABLE_CONTEXT" />
diff --git a/tests/tests/assist/testapp/AndroidManifest.xml b/tests/tests/assist/testapp/AndroidManifest.xml
index fa08f55..ee4c68f 100644
--- a/tests/tests/assist/testapp/AndroidManifest.xml
+++ b/tests/tests/assist/testapp/AndroidManifest.xml
@@ -55,8 +55,12 @@
                 <category android:name="android.intent.category.VOICE" />
             </intent-filter>
         </activity>
+        <!-- resizeableActivity makes the ScreenshotActivity run on Primary display to accommodate
+             assumptions about screenshot display vs TestStartActivity display in this test.
+             See b/70032125 -->
         <activity android:name=".ScreenshotActivity"
-                  android:label="Screenshot Test Activity">
+                  android:label="Screenshot Test Activity"
+                  android:resizeableActivity="false">
             <intent-filter>
                 <action android:name="android.intent.action.TEST_APP_SCREENSHOT" />
                 <category android:name="android.intent.category.DEFAULT" />
diff --git a/tests/tests/display/src/android/display/cts/DisplayTest.java b/tests/tests/display/src/android/display/cts/DisplayTest.java
index beeee3e..1a2753b 100644
--- a/tests/tests/display/src/android/display/cts/DisplayTest.java
+++ b/tests/tests/display/src/android/display/cts/DisplayTest.java
@@ -22,8 +22,10 @@
 import android.app.Instrumentation;
 import android.app.Presentation;
 import android.app.UiAutomation;
+import android.app.UiModeManager;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Configuration;
 import android.graphics.Color;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
@@ -69,6 +71,7 @@
 
     private DisplayManager mDisplayManager;
     private WindowManager mWindowManager;
+    private UiModeManager mUiModeManager;
     private Context mContext;
 
     // To test display mode switches.
@@ -88,6 +91,7 @@
         mContext = getInstrumentation().getContext();
         mDisplayManager = (DisplayManager)mContext.getSystemService(Context.DISPLAY_SERVICE);
         mWindowManager = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
+        mUiModeManager = (UiModeManager)mContext.getSystemService(Context.UI_MODE_SERVICE);
     }
 
     @Override
@@ -290,6 +294,12 @@
      * Tests that mode switch requests are correctly executed.
      */
     public void testModeSwitch() throws Exception {
+        // Standalone VR devices globally ignore SYSTEM_ALERT_WINDOW via AppOps.
+        // Skip this test, which depends on a Presentation SYSTEM_ALERT_WINDOW to pass.
+        if (mUiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_VR_HEADSET) {
+            return;
+        }
+
         enableAppOps();
         final Display display = getSecondaryDisplay(mDisplayManager.getDisplays());
         Display.Mode[] modes = display.getSupportedModes();
diff --git a/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_30fps.mp4 b/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_30fps.mp4
new file mode 100644
index 0000000..9a899b2
--- /dev/null
+++ b/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_30fps.mp4
Binary files differ
diff --git a/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_60fps.mp4 b/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_60fps.mp4
deleted file mode 100644
index 362568c..0000000
--- a/tests/tests/media/assets/video_decode_with_cropping-h264_520x360_60fps.mp4
+++ /dev/null
Binary files differ
diff --git a/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_30fps.webm b/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_30fps.webm
new file mode 100644
index 0000000..df2723c
--- /dev/null
+++ b/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_30fps.webm
Binary files differ
diff --git a/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_60fps.webm b/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_60fps.webm
deleted file mode 100644
index 2ad27ed..0000000
--- a/tests/tests/media/assets/video_decode_with_cropping-vp9_520x360_60fps.webm
+++ /dev/null
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
index 2840b16..7042213 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTest.java
@@ -129,8 +129,8 @@
         "video_decode_accuracy_and_capability-vp9_2880x2160_30fps.webm",
         "video_decode_accuracy_and_capability-vp9_1216x2160_30fps.webm",
         // cropped
-        "video_decode_with_cropping-h264_520x360_60fps.mp4",
-        "video_decode_with_cropping-vp9_520x360_60fps.webm"
+        "video_decode_with_cropping-h264_520x360_30fps.mp4",
+        "video_decode_with_cropping-vp9_520x360_30fps.webm"
     };
 
     private View videoView;
diff --git a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
index 0720b2f..72eddf1 100644
--- a/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
+++ b/tests/tests/media/src/android/media/cts/DecodeAccuracyTestBase.java
@@ -643,18 +643,16 @@
             handler.post(viewCleaner);
         }
 
-        public synchronized Bitmap generateBitmapFromVideoViewSnapshot(VideoViewSnapshot snapshot) {
-            final long timeOutMs = TimeUnit.SECONDS.toMillis(30);
-            final long start = SystemClock.elapsedRealtime();
+        public Bitmap generateBitmapFromVideoViewSnapshot(VideoViewSnapshot snapshot) {
             handler.post(snapshot);
-            try {
-                while (!snapshot.isBitmapReady()
-                        && (SystemClock.elapsedRealtime() - start < timeOutMs)) {
-                    Thread.sleep(100);
+            synchronized (snapshot.getSyncObject()) {
+                try {
+                    snapshot.getSyncObject().wait(snapshot.SNAPSHOT_TIMEOUT_MS + 100);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                    Log.e(TAG, "Unable to finish generateBitmapFromVideoViewSnapshot().");
+                    return null;
                 }
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-                return null;
             }
             if (!snapshot.isBitmapReady()) {
                 Log.e(TAG, "Time out in generateBitmapFromVideoViewSnapshot().");
@@ -1304,10 +1302,16 @@
 /* Definition of a VideoViewSnapshot and a runnable to get a bitmap from a view. */
 abstract class VideoViewSnapshot implements Runnable {
 
+    public static final long SNAPSHOT_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(30);
+    public static final long SLEEP_TIME_MS = 30;
+    public static final Object SYNC_TOKEN = new Object();
+
     public abstract Bitmap getBitmap();
 
     public abstract boolean isBitmapReady();
 
+    public abstract Object getSyncObject();
+
 }
 
 /* Runnable to get a bitmap from a texture view on the UI thread via a handler.
@@ -1324,9 +1328,12 @@
     }
 
     @Override
-    public synchronized void run() {
+    public void run() {
         bitmap = null;
         bitmap = tv.getBitmap();
+        synchronized (SYNC_TOKEN) {
+            SYNC_TOKEN.notify();
+        }
     }
 
     @Override
@@ -1339,6 +1346,11 @@
         return bitmap != null;
     }
 
+    @Override
+    public Object getSyncObject() {
+        return SYNC_TOKEN;
+    }
+
 }
 
 /**
@@ -1350,7 +1362,6 @@
 class SurfaceViewSnapshot extends VideoViewSnapshot  {
 
     private static final String TAG = SurfaceViewSnapshot.class.getSimpleName();
-    private static final int PIXELCOPY_REQUEST_SLEEP_MS = 30;
     private static final int PIXELCOPY_TIMEOUT_MS = 1000;
     private static final int INITIAL_STATE = -1;
 
@@ -1358,7 +1369,6 @@
     private final int width;
     private final int height;
 
-    private SynchronousPixelCopy copyHelper;
     private Bitmap bitmap;
     private int copyResult;
 
@@ -1371,20 +1381,26 @@
     }
 
     @Override
-    public synchronized void run() {
+    public void run() {
+        final long start = SystemClock.elapsedRealtime();
         copyResult = INITIAL_STATE;
         final SynchronousPixelCopy copyHelper = new SynchronousPixelCopy();
         bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
         try {
             // Wait for PixelCopy to finish.
-            while ((copyResult = copyHelper.request(surfaceView, bitmap)) != PixelCopy.SUCCESS) {
-                Thread.sleep(PIXELCOPY_REQUEST_SLEEP_MS);
+            while ((copyResult = copyHelper.request(surfaceView, bitmap)) != PixelCopy.SUCCESS
+                    && (SystemClock.elapsedRealtime() - start) < SNAPSHOT_TIMEOUT_MS) {
+                Thread.sleep(SLEEP_TIME_MS);
             }
         } catch (InterruptedException e) {
             Log.e(TAG, "Pixel Copy is stopped/interrupted before it finishes.", e);
             bitmap = null;
+        } finally {
+            copyHelper.release();
+            synchronized (SYNC_TOKEN) {
+                SYNC_TOKEN.notify();
+            }
         }
-        copyHelper.release();
     }
 
     @Override
@@ -1397,6 +1413,11 @@
         return bitmap != null && copyResult == PixelCopy.SUCCESS;
     }
 
+    @Override
+    public Object getSyncObject() {
+        return SYNC_TOKEN;
+    }
+
     private static class SynchronousPixelCopy implements OnPixelCopyFinishedListener {
 
         private final Handler handler;
@@ -1457,8 +1478,6 @@
 class GLSurfaceViewSnapshot extends VideoViewSnapshot {
 
     private static final String TAG = GLSurfaceViewSnapshot.class.getSimpleName();
-    private static final int GET_BYTEBUFFER_SLEEP_MS = 30;
-    private static final int GET_BYTEBUFFER_MAX_ATTEMPTS = 30;
 
     private final GLSurfaceViewFactory glSurfaceViewFactory;
     private final int width;
@@ -1474,7 +1493,7 @@
     }
 
     @Override
-    public synchronized void run() {
+    public void run() {
         bitmapIsReady = false;
         bitmap = null;
         try {
@@ -1482,6 +1501,7 @@
         } catch (InterruptedException exception) {
             Log.e(TAG, exception.getMessage());
             bitmap = null;
+            notifyObject();
             return;
         }
         try {
@@ -1494,6 +1514,8 @@
         } catch (NullPointerException exception) {
             Log.e(TAG, "glSurfaceViewFactory or byteBuffer may have been released", exception);
             bitmap = null;
+        } finally {
+            notifyObject();
         }
     }
 
@@ -1507,13 +1529,25 @@
         return bitmapIsReady;
     }
 
+    @Override
+    public Object getSyncObject() {
+        return SYNC_TOKEN;
+    }
+
+    private void notifyObject() {
+        synchronized (SYNC_TOKEN) {
+            SYNC_TOKEN.notify();
+        }
+    }
+
     private void waitForByteBuffer() throws InterruptedException {
         // Wait for byte buffer to be ready.
-        for (int i = 0; i < GET_BYTEBUFFER_MAX_ATTEMPTS; i++) {
+        final long start = SystemClock.elapsedRealtime();
+        while (SystemClock.elapsedRealtime() - start < SNAPSHOT_TIMEOUT_MS) {
             if (glSurfaceViewFactory.byteBufferIsReady()) {
                 return;
             }
-            Thread.sleep(GET_BYTEBUFFER_SLEEP_MS);
+            Thread.sleep(SLEEP_TIME_MS);
         }
         throw new InterruptedException("Taking too long to read pixels into a ByteBuffer.");
     }
diff --git a/tests/tests/permission2/res/raw/automotive_android_manifest.xml b/tests/tests/permission2/res/raw/automotive_android_manifest.xml
new file mode 100644
index 0000000..4a68183
--- /dev/null
+++ b/tests/tests/permission2/res/raw/automotive_android_manifest.xml
@@ -0,0 +1,203 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+        package="com.android.car"
+        coreApp="true"
+        android:sharedUserId="android.uid.system">
+
+    <original-package android:name="com.android.car" />
+
+    <permission-group
+        android:name="android.car.permission-group.CAR_INFORMATION"
+        android:icon="@drawable/car_ic_mode"
+        android:description="@string/car_permission_desc"
+        android:label="@string/car_permission_label" />
+    <permission
+        android:name="android.car.permission.CAR_CABIN"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_cabin"
+        android:description="@string/car_permission_desc_cabin" />
+    <permission
+        android:name="android.car.permission.CAR_CAMERA"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_camera"
+        android:description="@string/car_permission_desc_camera" />
+    <permission
+        android:name="android.car.permission.CAR_FUEL"
+        android:permissionGroup="android.car.permission-group.CAR_INFORMATION"
+        android:protectionLevel="dangerous"
+        android:label="@string/car_permission_label_fuel"
+        android:description="@string/car_permission_desc_fuel" />
+    <permission
+        android:name="android.car.permission.CAR_HVAC"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_hvac"
+        android:description="@string/car_permission_desc_hvac" />
+    <permission
+        android:name="android.car.permission.CAR_MILEAGE"
+        android:permissionGroup="android.car.permission-group.CAR_INFORMATION"
+        android:protectionLevel="dangerous"
+        android:label="@string/car_permission_label_mileage"
+        android:description="@string/car_permission_desc_mileage" />
+    <permission
+        android:name="android.car.permission.CAR_SPEED"
+        android:permissionGroup="android.permission-group.LOCATION"
+        android:protectionLevel="dangerous"
+        android:label="@string/car_permission_label_speed"
+        android:description="@string/car_permission_desc_speed" />
+    <permission
+        android:name="android.car.permission.VEHICLE_DYNAMICS_STATE"
+        android:permissionGroup="android.car.permission-group.CAR_INFORMATION"
+        android:protectionLevel="dangerous"
+        android:label="@string/car_permission_label_vehicle_dynamics_state"
+        android:description="@string/car_permission_desc_vehicle_dynamics_state" />
+    <permission
+        android:name="android.car.permission.CAR_VENDOR_EXTENSION"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_vendor_extension"
+        android:description="@string/car_permission_desc_vendor_extension" />
+    <permission
+        android:name="android.car.permission.CAR_RADIO"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_radio"
+        android:description="@string/car_permission_desc_radio" />
+    <permission
+        android:name="android.car.permission.CAR_PROJECTION"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_projection"
+        android:description="@string/car_permission_desc_projection" />
+    <permission
+        android:name="android.car.permission.CAR_MOCK_VEHICLE_HAL"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_mock_vehicle_hal"
+        android:description="@string/car_permission_desc_mock_vehicle_hal" />
+    <permission
+        android:name="android.car.permission.CAR_NAVIGATION_MANAGER"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_car_navigation_manager"
+        android:description="@string/car_permission_desc_car_navigation_manager" />
+    <permission
+      android:name="android.car.permission.DIAGNOSTIC_READ_ALL"
+      android:protectionLevel="system|signature"
+      android:label="@string/car_permission_label_diag_read"
+      android:description="@string/car_permission_desc_diag_read" />
+    <permission
+      android:name="android.car.permission.DIAGNOSTIC_CLEAR"
+      android:protectionLevel="system|signature"
+      android:label="@string/car_permission_label_diag_clear"
+      android:description="@string/car_permission_desc_diag_clear" />
+    <permission
+        android:name="android.car.permission.VMS_PUBLISHER"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_vms_publisher"
+        android:description="@string/car_permission_desc_vms_publisher" />
+    <permission
+        android:name="android.car.permission.VMS_SUBSCRIBER"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_vms_subscriber"
+        android:description="@string/car_permission_desc_vms_subscriber" />
+
+    <!--  may replace this with system permission if proper one is defined. -->
+    <permission
+        android:name="android.car.permission.CONTROL_APP_BLOCKING"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_control_app_blocking"
+        android:description="@string/car_permission_desc_control_app_blocking" />
+
+    <permission
+        android:name="android.car.permission.CAR_CONTROL_AUDIO_VOLUME"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_audio_volume"
+        android:description="@string/car_permission_desc_audio_volume" />
+
+    <permission
+        android:name="android.car.permission.CAR_CONTROL_AUDIO_SETTINGS"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_audio_settings"
+        android:description="@string/car_permission_desc_audio_settings" />
+
+    <permission
+            android:name="android.car.permission.BIND_INSTRUMENT_CLUSTER_RENDERER_SERVICE"
+            android:protectionLevel="signature"
+            android:label="@string/car_permission_label_bind_instrument_cluster_rendering"
+            android:description="@string/car_permission_desc_bind_instrument_cluster_rendering"/>
+
+    <permission
+            android:name="android.car.permission.BIND_CAR_INPUT_SERVICE"
+            android:protectionLevel="signature"
+            android:label="@string/car_permission_label_bind_input_service"
+            android:description="@string/car_permission_desc_bind_input_service"/>
+
+    <permission
+            android:name="android.car.permission.CAR_DISPLAY_IN_CLUSTER"
+            android:protectionLevel="system|signature"
+            android:label="@string/car_permission_car_display_in_cluster"
+            android:description="@string/car_permission_desc_car_display_in_cluster" />
+
+    <permission android:name="android.car.permission.CAR_INSTRUMENT_CLUSTER_CONTROL"
+                android:protectionLevel="system|signature"
+                android:label="@string/car_permission_car_cluster_control"
+                android:description="@string/car_permission_desc_car_cluster_control" />
+
+    <permission android:name="android.car.permission.STORAGE_MONITORING"
+        android:protectionLevel="system|signature"
+        android:label="@string/car_permission_label_storage_monitoring"
+        android:description="@string/car_permission_desc_storage_monitoring" />
+
+    <uses-permission android:name="android.permission.CALL_PHONE" />
+    <uses-permission android:name="android.permission.DEVICE_POWER" />
+    <uses-permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS" />
+    <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
+    <uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS" />
+    <uses-permission android:name="android.permission.MODIFY_AUDIO_ROUTING" />
+    <uses-permission android:name="android.permission.MODIFY_DAY_NIGHT_MODE" />
+    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
+    <uses-permission android:name="android.permission.READ_CALL_LOG" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.REAL_GET_TASKS" />
+    <uses-permission android:name="android.permission.REBOOT" />
+    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+    <uses-permission android:name="android.permission.REMOVE_TASKS" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
+    <uses-permission android:name="android.permission.BLUETOOTH" />
+    <uses-permission android:name="android.permission.MANAGE_USERS" />
+
+    <application android:label="Car service"
+                 android:directBootAware="true"
+                 android:allowBackup="false"
+                 android:persistent="true">
+
+       
+        <uses-library android:name="android.test.runner" />
+ <service android:name=".CarService"
+                android:singleUser="true">
+            <intent-filter>
+                <action android:name="android.car.ICar" />
+            </intent-filter>
+        </service>
+        <service android:name=".PerUserCarService" android:exported="false" />
+        <activity android:name="com.android.car.pm.ActivityBlockingActivity"
+                  android:excludeFromRecents="true"
+                  android:exported="false">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+            </intent-filter>
+        </activity>
+    </application>
+</manifest>
diff --git a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
index 35a99da..50a5bce 100644
--- a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
@@ -16,8 +16,12 @@
 
 package android.permission2.cts;
 
+import static android.os.Build.VERSION.SECURITY_PATCH;
+
+import android.content.Context;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.PermissionGroupInfo;
 import android.content.pm.PermissionInfo;
 import android.test.AndroidTestCase;
@@ -26,10 +30,10 @@
 import android.util.ArraySet;
 import android.util.Log;
 import android.util.Xml;
+
 import org.xmlpull.v1.XmlPullParser;
 
 import java.io.InputStream;
-import java.lang.String;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -38,8 +42,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import static android.os.Build.VERSION.SECURITY_PATCH;
-
 /**
  * Tests for permission policy on the platform.
  */
@@ -54,6 +56,8 @@
 
     private static final String PLATFORM_ROOT_NAMESPACE = "android.";
 
+    private static final String AUTOMOTIVE_SERVICE_PACKAGE_NAME = "com.android.car";
+
     private static final String TAG_PERMISSION = "permission";
 
     private static final String ATTR_NAME = "name";
@@ -61,14 +65,10 @@
     private static final String ATTR_PROTECTION_LEVEL = "protectionLevel";
 
     public void testPlatformPermissionPolicyUnaltered() throws Exception {
-        PackageInfo platformPackage = getContext().getPackageManager()
-                .getPackageInfo(PLATFORM_PACKAGE_NAME, PackageManager.GET_PERMISSIONS);
-        Map<String, PermissionInfo> declaredPermissionsMap = new ArrayMap<>();
-        List<String> offendingList = new ArrayList<String>();
+        Map<String, PermissionInfo> declaredPermissionsMap =
+                getPermissionsForPackage(getContext(), PLATFORM_PACKAGE_NAME);
 
-        for (PermissionInfo declaredPermission : platformPackage.permissions) {
-            declaredPermissionsMap.put(declaredPermission.name, declaredPermission);
-        }
+        List<String> offendingList = new ArrayList<>();
 
         List<PermissionGroupInfo> declaredGroups = getContext().getPackageManager()
                 .getAllPermissionGroups(0);
@@ -77,9 +77,16 @@
             declaredGroupsSet.add(declaredGroup.name);
         }
 
-        Set<String> expectedPermissionGroups = new ArraySet<String>();
+        Set<String> expectedPermissionGroups = new ArraySet<>();
+        List<PermissionInfo> expectedPermissions = loadExpectedPermissions(R.raw.android_manifest);
 
-        for (PermissionInfo expectedPermission : loadExpectedPermissions()) {
+        if (getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
+            expectedPermissions.addAll(loadExpectedPermissions(R.raw.automotive_android_manifest));
+            declaredPermissionsMap.putAll(
+                    getPermissionsForPackage(getContext(), AUTOMOTIVE_SERVICE_PACKAGE_NAME));
+        }
+
+        for (PermissionInfo expectedPermission : expectedPermissions) {
             String expectedPermissionName = expectedPermission.name;
             if (shouldSkipPermission(expectedPermissionName)) {
                 continue;
@@ -132,7 +139,7 @@
 
                 if (!declaredGroupsSet.contains(declaredPermission.group)) {
                     offendingList.add(
-                            "Permission group " + expectedPermission.group + "must be defined");
+                            "Permission group " + expectedPermission.group + " must be defined");
                 }
             }
         }
@@ -149,7 +156,7 @@
             if (!expectedPermissionGroups.contains(declaredGroup.name)) {
                 if (declaredGroup.name != null) {
                     if (declaredGroup.packageName.equals(PLATFORM_PACKAGE_NAME)
-                            || declaredGroup.name.startsWith(PLATFORM_ROOT_NAMESPACE)) {
+                            && declaredGroup.name.startsWith(PLATFORM_ROOT_NAMESPACE)) {
                         offendingList.add(
                                 "Cannot define group "
                                         + declaredGroup.name
@@ -177,12 +184,9 @@
         assertTrue(errMsg, offendingList.isEmpty());
     }
 
-    private List<PermissionInfo> loadExpectedPermissions() throws Exception {
+    private List<PermissionInfo> loadExpectedPermissions(int resourceId) throws Exception {
         List<PermissionInfo> permissions = new ArrayList<>();
-        try (
-                InputStream in = getContext().getResources()
-                        .openRawResource(android.permission2.cts.R.raw.android_manifest)
-        ) {
+        try (InputStream in = getContext().getResources().openRawResource(resourceId)) {
             XmlPullParser parser = Xml.newPullParser();
             parser.setInput(in, null);
 
@@ -264,6 +268,18 @@
         return protectionLevel;
     }
 
+    private static Map<String, PermissionInfo> getPermissionsForPackage(Context context, String pkg)
+            throws NameNotFoundException {
+        PackageInfo packageInfo = context.getPackageManager()
+                .getPackageInfo(pkg, PackageManager.GET_PERMISSIONS);
+        Map<String, PermissionInfo> declaredPermissionsMap = new ArrayMap<>();
+
+        for (PermissionInfo declaredPermission : packageInfo.permissions) {
+            declaredPermissionsMap.put(declaredPermission.name, declaredPermission);
+        }
+        return declaredPermissionsMap;
+    }
+
     private static Date parseDate(String date) {
         Date patchDate = new Date();
         try {
diff --git a/tests/tests/security/res/raw/bug_65483665.mp4 b/tests/tests/security/res/raw/bug_65483665.mp4
new file mode 100644
index 0000000..105e274
--- /dev/null
+++ b/tests/tests/security/res/raw/bug_65483665.mp4
Binary files differ
diff --git a/tests/tests/security/res/raw/bug_69478425.mp4 b/tests/tests/security/res/raw/bug_69478425.mp4
new file mode 100644
index 0000000..b8ff0c5
--- /dev/null
+++ b/tests/tests/security/res/raw/bug_69478425.mp4
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 ee36ca8..39286a1 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -244,6 +244,11 @@
      ***********************************************************/
 
     @SecurityTest
+    public void testStagefright_bug_65483665() throws Exception {
+        doStagefrightTest(R.raw.bug_65483665);
+    }
+
+    @SecurityTest
     public void testStagefright_cve_2017_0852_b_62815506() throws Exception {
         doStagefrightTest(R.raw.cve_2017_0852_b_62815506);
     }
@@ -254,6 +259,11 @@
      ***********************************************************/
 
     @SecurityTest
+    public void testStagefright_bug_69478425() throws Exception {
+        doStagefrightTest(R.raw.bug_69478425);
+    }
+
+    @SecurityTest
     public void testStagefright_bug_65717533() throws Exception {
         doStagefrightTest(R.raw.bug_65717533_header_corrupt);
     }
diff --git a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
index 5c67190..81638f9 100644
--- a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
+++ b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
@@ -298,6 +298,9 @@
      */
     public static SelfManagedConnection waitForAndGetConnection(Uri address) {
         // Wait for creation of the new connection.
+        if (!CtsSelfManagedConnectionService.waitForBinding()) {
+            TestCase.fail("Could not bind to Self-Managed ConnectionService");
+        }
         CtsSelfManagedConnectionService connectionService =
                 CtsSelfManagedConnectionService.getConnectionService();
         TestCase.assertTrue(connectionService.waitForUpdate(
diff --git a/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java b/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
index a1423af..f93b297 100644
--- a/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
+++ b/tests/tests/telephony/src/android/telephony/cts/CellInfoTest.java
@@ -125,8 +125,13 @@
 
         int earfcn = lte.getCellIdentity().getEarfcn();
         // Reference 3GPP 36.101 Table 5.7.3-1
-        assertTrue("getEarfcn() out of range [0,47000], earfcn=" + earfcn,
-            earfcn >= 0 && earfcn <= 47000);
+        // As per NOTE 1 in the table, although 0-6 are valid channel numbers for
+        // LTE, the reported EARFCN is the center frequency, rendering these channels
+        // out of the range of the narrowest 1.4Mhz deployment.
+        // TODO: cross-reference with the bandwidth to adjust the minimum for 5, 10, and 20
+        // MHz channels
+        assertTrue("getEarfcn() out of range [7,47000], earfcn=" + earfcn,
+            earfcn >= 7 && earfcn <= 47000);
         CellSignalStrengthLte cellSignalStrengthLte = lte.getCellSignalStrength();
         //Integer.MAX_VALUE indicates an unavailable field
         int rsrp = cellSignalStrengthLte.getRsrp();
@@ -159,8 +164,10 @@
 
         int uarfcn = wcdma.getCellIdentity().getUarfcn();
         // Reference 3GPP 25.101 Table 5.2
-        assertTrue("getUarfcn() out of range [400,11000], uarfcn=" + uarfcn,
-            uarfcn >= 400 && uarfcn <= 11000);
+        // From Appendix E.1, even though UARFCN is numbered from 400, the minumum
+        // usable channel is 412 due to the fixed bandwidth of 5Mhz
+        assertTrue("getUarfcn() out of range [412,11000], uarfcn=" + uarfcn,
+            uarfcn >= 412 && uarfcn <= 11000);
 
         int level = wcdma.getCellSignalStrength().getLevel();
         assertTrue("getLevel() out of range [0,4], level=" + level, level >=0 && level <= 4);
diff --git a/tests/tests/transition/src/android/transition/cts/TransitionActivity.java b/tests/tests/transition/src/android/transition/cts/TransitionActivity.java
index afc48be..692d323 100644
--- a/tests/tests/transition/src/android/transition/cts/TransitionActivity.java
+++ b/tests/tests/transition/src/android/transition/cts/TransitionActivity.java
@@ -18,12 +18,31 @@
 
 import android.app.Activity;
 import android.os.Bundle;
+import android.view.View;
+import android.view.WindowInsets;
+import android.widget.FrameLayout;
 
-public class TransitionActivity extends Activity {
+public class TransitionActivity extends Activity implements View.OnApplyWindowInsetsListener{
+
+    private View mContent;
+
     @Override
     public void onCreate(Bundle bundle){
         super.onCreate(bundle);
         setContentView(R.layout.transition_main);
+        mContent = findViewById(R.id.container);
+        mContent.setOnApplyWindowInsetsListener(this);
+    }
+
+    @Override
+    public WindowInsets onApplyWindowInsets(View v, WindowInsets in) {
+        if (in.isRound()) {
+            FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mContent.getLayoutParams();
+            params.setMargins(in.getSystemWindowInsetLeft(), in.getSystemWindowInsetTop(),
+                    in.getSystemWindowInsetRight(), in.getSystemWindowInsetBottom());
+            mContent.setLayoutParams(params);
+        }
+        return in;
     }
 }
 
diff --git a/tests/tests/view/AndroidManifest.xml b/tests/tests/view/AndroidManifest.xml
index 7c35627..823704c 100644
--- a/tests/tests/view/AndroidManifest.xml
+++ b/tests/tests/view/AndroidManifest.xml
@@ -316,8 +316,7 @@
         </activity>
 
         <activity android:name="android.view.cts.HoverCtsActivity"
-                  android:screenOrientation="locked"
-                  android:theme="@style/WhiteBackgroundTheme">
+                  android:screenOrientation="locked">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
diff --git a/tests/tests/view/src/android/view/cts/HoverTest.java b/tests/tests/view/src/android/view/cts/HoverTest.java
index 45b56e9..d3734c8 100644
--- a/tests/tests/view/src/android/view/cts/HoverTest.java
+++ b/tests/tests/view/src/android/view/cts/HoverTest.java
@@ -103,9 +103,8 @@
     }
 
     private void injectHoverMove(View view, int offsetX, int offsetY) {
-        mActivity.getWindow().injectInputEvent(
+        mInstrumentation.sendPointerSync(
                 obtainMouseEvent(MotionEvent.ACTION_HOVER_MOVE, view, offsetX, offsetY));
-        mInstrumentation.waitForIdleSync();
     }
 
     private void remove(View view) throws Throwable {
diff --git a/tests/tests/view/src/android/view/cts/TextureViewTest.java b/tests/tests/view/src/android/view/cts/TextureViewTest.java
index d9b84a4..f66e137 100644
--- a/tests/tests/view/src/android/view/cts/TextureViewTest.java
+++ b/tests/tests/view/src/android/view/cts/TextureViewTest.java
@@ -20,16 +20,17 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import android.app.Instrumentation;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.Point;
-import android.support.test.InstrumentationRegistry;
 import android.support.test.filters.MediumTest;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
+import android.view.PixelCopy;
 import android.view.View;
+import android.view.Window;
 
+import com.android.compatibility.common.util.SynchronousPixelCopy;
 import com.android.compatibility.common.util.WidgetTestUtils;
 
 import org.junit.Before;
@@ -42,8 +43,9 @@
 @MediumTest
 @RunWith(AndroidJUnit4.class)
 public class TextureViewTest {
-    private Instrumentation mInstrumentation;
     private TextureViewCtsActivity mActivity;
+    private SynchronousPixelCopy mPixelCopy;
+    private Window mWindow;
 
     @Rule
     public ActivityTestRule<TextureViewCtsActivity> mActivityRule =
@@ -51,10 +53,9 @@
 
     @Before
     public void setup() {
-        mInstrumentation = InstrumentationRegistry.getInstrumentation();
         mActivity = mActivityRule.getActivity();
+        mPixelCopy = new SynchronousPixelCopy();
         assertNotNull(mActivity);
-        assertNotNull(mInstrumentation);
     }
 
     @Test
@@ -68,6 +69,7 @@
             content.getLocationOnScreen(outLocation);
             center.x = outLocation[0] + (content.getWidth() / 2);
             center.y = outLocation[1] + (content.getHeight() / 2);
+            mWindow = mActivity.getWindow();
         });
         assertTrue(center.x > 0);
         assertTrue(center.y > 0);
@@ -94,7 +96,10 @@
     }
 
     private int getPixel(Point point) {
-        Bitmap screenshot = mInstrumentation.getUiAutomation().takeScreenshot();
+        Bitmap screenshot = Bitmap.createBitmap(mWindow.getDecorView().getWidth(),
+                mWindow.getDecorView().getHeight(), Bitmap.Config.ARGB_8888);
+        int result = mPixelCopy.request(mWindow, screenshot);
+        assertEquals("Copy request failed", PixelCopy.SUCCESS, result);
         int pixel = screenshot.getPixel(point.x, point.y);
         screenshot.recycle();
         return pixel;
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
index b02deec..f10e7fd 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebSettingsTest.java
@@ -20,10 +20,13 @@
 import android.net.http.SslError;
 import android.os.Build;
 import android.test.ActivityInstrumentationTestCase2;
+import android.util.Base64;
 import android.util.Log;
 import android.webkit.ConsoleMessage;
 import android.webkit.SslErrorHandler;
 import android.webkit.WebIconDatabase;
+import android.webkit.WebResourceResponse;
+import android.webkit.WebResourceRequest;
 import android.webkit.WebSettings;
 import android.webkit.WebSettings.TextSize;
 import android.webkit.WebStorage;
@@ -35,7 +38,9 @@
 import com.android.compatibility.common.util.NullWebViewUtils;
 import com.android.compatibility.common.util.PollingCheck;
 
+import java.io.ByteArrayInputStream;
 import java.io.FileOutputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -944,61 +949,77 @@
         if (!NullWebViewUtils.isWebViewAvailable()) {
             return;
         }
-        final class SslWebViewClient extends WaitForLoadedClient {
-            public SslWebViewClient() {
+
+        final String INSECURE_BASE_URL = "http://www.example.com/";
+        final String INSECURE_JS_URL = INSECURE_BASE_URL + "insecure.js";
+        final String INSECURE_IMG_URL = INSECURE_BASE_URL + "insecure.png";
+        final String SECURE_URL = "/secure.html";
+        final String JS_HTML = "<script src=\"" + INSECURE_JS_URL + "\"></script>";
+        final String IMG_HTML = "<img src=\"" + INSECURE_IMG_URL + "\" />";
+        final String SECURE_HTML = "<body>" + IMG_HTML + " " + JS_HTML + "</body>";
+        final String JS_CONTENT = "window.loaded_js = 42;";
+        final String IMG_CONTENT = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
+
+        final class InterceptClient extends WaitForLoadedClient {
+            public int mInsecureJsCounter;
+            public int mInsecureImgCounter;
+
+            public InterceptClient() {
                 super(mOnUiThread);
             }
+
             @Override
-            public void onReceivedSslError(WebView view,
-                    SslErrorHandler handler, SslError error) {
+            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                 handler.proceed();
             }
+
+            @Override
+            public WebResourceResponse shouldInterceptRequest(
+                    WebView view, WebResourceRequest request) {
+                if (request.getUrl().toString().equals(INSECURE_JS_URL)) {
+                    mInsecureJsCounter++;
+                    return new WebResourceResponse("text/javascript", "utf-8",
+                        new ByteArrayInputStream(JS_CONTENT.getBytes(StandardCharsets.UTF_8)));
+                } else if (request.getUrl().toString().equals(INSECURE_IMG_URL)) {
+                    mInsecureImgCounter++;
+                    return new WebResourceResponse("image/gif", "utf-8",
+                        new ByteArrayInputStream(Base64.decode(IMG_CONTENT, Base64.DEFAULT)));
+                }
+
+                if (request.getUrl().toString().startsWith(INSECURE_BASE_URL)) {
+                    return new WebResourceResponse("text/html", "UTF-8", null);
+                }
+                return null;
+            }
         }
 
+        InterceptClient interceptClient = new InterceptClient();
+        mOnUiThread.setWebViewClient(interceptClient);
         mSettings.setJavaScriptEnabled(true);
         TestWebServer httpsServer = null;
-        TestWebServer httpServer = null;
         try {
             httpsServer = new TestWebServer(true);
-            httpServer = new TestWebServer(false);
-            final String JS_URL = "/insecure.js";
-            final String IMG_URL = "/insecure.png";
-            final String SECURE_URL = "/secure.html";
-            final String JS_HTML = "<script src=\"" + httpServer.getResponseUrl(JS_URL) +
-                "\"></script>";
-            final String IMG_HTML = "<img src=\"" + httpServer.getResponseUrl(IMG_URL) + "\" />";
-            final String SECURE_HTML = "<body>" + IMG_HTML + " " + JS_HTML + "</body>";
-            httpServer.setResponse(JS_URL, "window.loaded_js = 42;", null);
-            httpServer.setResponseBase64(IMG_URL,
-                    "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
-                    null);
             String secureUrl = httpsServer.setResponse(SECURE_URL, SECURE_HTML, null);
-
             mOnUiThread.clearSslPreferences();
 
-            mOnUiThread.setWebViewClient(new SslWebViewClient());
-
             mSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
             mOnUiThread.loadUrlAndWaitForCompletion(secureUrl);
             assertEquals(1, httpsServer.getRequestCount(SECURE_URL));
-            assertEquals(0, httpServer.getRequestCount(JS_URL));
-            assertEquals(0, httpServer.getRequestCount(IMG_URL));
+            assertEquals(0, interceptClient.mInsecureJsCounter);
+            assertEquals(0, interceptClient.mInsecureImgCounter);
 
             mSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
             mOnUiThread.loadUrlAndWaitForCompletion(secureUrl);
             assertEquals(2, httpsServer.getRequestCount(SECURE_URL));
-            assertEquals(1, httpServer.getRequestCount(JS_URL));
-            assertEquals(1, httpServer.getRequestCount(IMG_URL));
+            assertEquals(1, interceptClient.mInsecureJsCounter);
+            assertEquals(1, interceptClient.mInsecureImgCounter);
 
             mSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
             mOnUiThread.loadUrlAndWaitForCompletion(secureUrl);
             assertEquals(3, httpsServer.getRequestCount(SECURE_URL));
-            assertEquals(1, httpServer.getRequestCount(JS_URL));
-            assertEquals(2, httpServer.getRequestCount(IMG_URL));
+            assertEquals(1, interceptClient.mInsecureJsCounter);
+            assertEquals(2, interceptClient.mInsecureImgCounter);
         } finally {
-            if (httpServer != null) {
-                httpServer.shutdown();
-            }
             if (httpsServer != null) {
                 httpsServer.shutdown();
             }
diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk
index 234ecaf..9a2f84f 100644
--- a/tools/cts-tradefed/Android.mk
+++ b/tools/cts-tradefed/Android.mk
@@ -29,7 +29,7 @@
 LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH)
 LOCAL_SUITE_NAME := CTS
 LOCAL_SUITE_FULLNAME := "Compatibility Test Suite"
-LOCAL_SUITE_VERSION := 8.1_r2
+LOCAL_SUITE_VERSION := 8.1_r3
 LOCAL_STATIC_JAVA_LIBRARIES += cts-tradefed-harness
 
 LOCAL_MODULE := cts-tradefed