Merge "EncoderProfileTest: Fix aac input configuration" into rvc-dev
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/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/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java b/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
index dbafec8..3599107 100644
--- a/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
+++ b/tests/BlobStore/src/com/android/cts/blob/BlobStoreManagerTest.java
@@ -133,6 +133,7 @@
     public void tearDown() throws Exception {
         runShellCmd("cmd blob_store clear-all-sessions");
         runShellCmd("cmd blob_store clear-all-blobs");
+        mContext.getFilesDir().delete();
     }
 
     @Test
@@ -938,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);
 
@@ -1163,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;
@@ -1218,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;
@@ -1242,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)
@@ -1293,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();
@@ -1322,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);
 
@@ -1340,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);
 
@@ -1362,11 +1531,12 @@
 
     @Test
     public void testCreateSession_countLimitExceeded() throws Exception {
-        final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
-        blobData1.prepare();
-        final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
-        blobData2.prepare();
         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()));
@@ -1375,11 +1545,12 @@
 
     @Test
     public void testCommitSession_countLimitExceeded() throws Exception {
-        final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
-        blobData1.prepare();
-        final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
-        blobData2.prepare();
         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)));
@@ -1387,11 +1558,12 @@
 
     @Test
     public void testLeaseBlob_countLimitExceeded() throws Exception {
-        final DummyBlobData blobData1 = new DummyBlobData.Builder(mContext).build();
-        blobData1.prepare();
-        final DummyBlobData blobData2 = new DummyBlobData.Builder(mContext).build();
-        blobData2.prepare();
         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);
 
@@ -1402,10 +1574,41 @@
     }
 
     @Test
-    public void testAllowPackageAccess_countLimitExceeded() throws Exception {
-        final DummyBlobData blobData = new DummyBlobData.Builder(mContext).build();
-        blobData.prepare();
+    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)) {
@@ -1555,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/tests/content/src/android/content/cts/AvailableIntentsTest.java b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
index 609bd29..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() {
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/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/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/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/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
index 8ad29c7..fd61914 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java
@@ -2781,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);