Merge "Improve logging in StagedInstallTest" into qt-dev
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/ConditionProviderVerifierActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/ConditionProviderVerifierActivity.java
index a3de878..1b14d2b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/notifications/ConditionProviderVerifierActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/notifications/ConditionProviderVerifierActivity.java
@@ -304,7 +304,14 @@
 
             if (!TextUtils.isEmpty(id)) {
                 AutomaticZenRule rule = mNm.getAutomaticZenRule(id);
-                if (Objects.equals(ruleToCreate, rule)) {
+                if (rule != null && ruleToCreate.getName().equals(rule.getName())
+                        && ruleToCreate.getOwner().equals(rule.getOwner())
+                        && ruleToCreate.getConditionId().equals(rule.getConditionId())
+                        && ruleToCreate.isEnabled() == rule.isEnabled()
+                        && ruleToCreate.getInterruptionFilter() == rule.getInterruptionFilter()
+                        && Objects.equals(ruleToCreate.getConfigurationActivity(),
+                        rule.getConfigurationActivity())
+                        && Objects.equals(ruleToCreate.getZenPolicy(), rule.getZenPolicy())) {
                     status = PASS;
                 } else {
                     logFail("created rule doesn't equal actual rule");
diff --git a/hostsidetests/devicepolicy/app/DeviceAdmin/api29/AndroidManifest.xml b/hostsidetests/devicepolicy/app/DeviceAdmin/api29/AndroidManifest.xml
index a0bf3c0..326e61f 100644
--- a/hostsidetests/devicepolicy/app/DeviceAdmin/api29/AndroidManifest.xml
+++ b/hostsidetests/devicepolicy/app/DeviceAdmin/api29/AndroidManifest.xml
@@ -17,8 +17,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.android.cts.deviceadmin29" >
 
-    <!-- STOPSHIP(b/114173216): Uncomment this once Q's API level is finalized -->
-    <!--<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29"/>-->
+    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29"/>
 
     <application
         android:testOnly="true">
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/Poc18_04.java b/hostsidetests/securitybulletin/src/android/security/cts/Poc18_04.java
index b1ed666..99a4692 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/Poc18_04.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/Poc18_04.java
@@ -27,6 +27,7 @@
      */
     @SecurityTest(minPatchLevel = "2018-04")
     public void testPocCVE_2017_13286() throws Exception {
+        getOomCatcher().setHighMemoryTest();
         LaunchSomeWhere.launchSomeWhere("CVE_2017_13286", getDevice());
     }
 
@@ -36,6 +37,7 @@
      */
     @SecurityTest(minPatchLevel = "2018-04")
     public void testPocCVE_2017_13288() throws Exception {
+        getOomCatcher().setHighMemoryTest();
         LaunchSomeWhere.launchSomeWhere("CVE_2017_13288", getDevice());
     }
 
@@ -45,6 +47,7 @@
      */
     @SecurityTest(minPatchLevel = "2018-04")
     public void testPocCVE_2017_13289() throws Exception {
+        getOomCatcher().setHighMemoryTest();
         LaunchSomeWhere.launchSomeWhere("CVE_2017_13289", getDevice());
     }
 }
diff --git a/hostsidetests/securitybulletin/src/android/security/cts/Poc18_05.java b/hostsidetests/securitybulletin/src/android/security/cts/Poc18_05.java
index 9364d28..69a4ed5 100644
--- a/hostsidetests/securitybulletin/src/android/security/cts/Poc18_05.java
+++ b/hostsidetests/securitybulletin/src/android/security/cts/Poc18_05.java
@@ -27,6 +27,7 @@
      */
     @SecurityTest(minPatchLevel = "2018-05")
     public void testPocCVE_2017_13315() throws Exception {
+        getOomCatcher().setHighMemoryTest();
         LaunchSomeWhere.launchSomeWhere("CVE_2017_13315", getDevice());
     }
 
@@ -36,6 +37,7 @@
      */
     @SecurityTest(minPatchLevel = "2018-05")
     public void testPocCVE_2017_13312() throws Exception {
+        getOomCatcher().setHighMemoryTest();
         LaunchSomeWhere.launchSomeWhere("CVE_2017_13312", getDevice());
     }
 }
diff --git a/hostsidetests/theme/app/AndroidManifest.xml b/hostsidetests/theme/app/AndroidManifest.xml
index 23b0561..d76c718 100755
--- a/hostsidetests/theme/app/AndroidManifest.xml
+++ b/hostsidetests/theme/app/AndroidManifest.xml
@@ -20,7 +20,7 @@
 
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 
-    <application>
+    <application android:requestLegacyExternalStorage="true">
         <uses-library android:name="android.test.runner" />
         <activity android:name=".ThemeDeviceActivity"
                   android:screenOrientation="portrait">
diff --git a/hostsidetests/theme/assets/29/140dpi.zip b/hostsidetests/theme/assets/29/140dpi.zip
new file mode 100644
index 0000000..cb385f1
--- /dev/null
+++ b/hostsidetests/theme/assets/29/140dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/180dpi.zip b/hostsidetests/theme/assets/29/180dpi.zip
new file mode 100644
index 0000000..b034a7f
--- /dev/null
+++ b/hostsidetests/theme/assets/29/180dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/200dpi.zip b/hostsidetests/theme/assets/29/200dpi.zip
new file mode 100644
index 0000000..9a0ca5e
--- /dev/null
+++ b/hostsidetests/theme/assets/29/200dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/220dpi.zip b/hostsidetests/theme/assets/29/220dpi.zip
new file mode 100644
index 0000000..b65a035
--- /dev/null
+++ b/hostsidetests/theme/assets/29/220dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/260dpi.zip b/hostsidetests/theme/assets/29/260dpi.zip
index ba5d363..9cdefe7 100644
--- a/hostsidetests/theme/assets/29/260dpi.zip
+++ b/hostsidetests/theme/assets/29/260dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/280dpi.zip b/hostsidetests/theme/assets/29/280dpi.zip
index 34ea14c..2e39de5 100644
--- a/hostsidetests/theme/assets/29/280dpi.zip
+++ b/hostsidetests/theme/assets/29/280dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/300dpi.zip b/hostsidetests/theme/assets/29/300dpi.zip
index 7595d24..fba9c6c 100644
--- a/hostsidetests/theme/assets/29/300dpi.zip
+++ b/hostsidetests/theme/assets/29/300dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/340dpi.zip b/hostsidetests/theme/assets/29/340dpi.zip
index 8ce960c..72e6f8f 100644
--- a/hostsidetests/theme/assets/29/340dpi.zip
+++ b/hostsidetests/theme/assets/29/340dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/360dpi.zip b/hostsidetests/theme/assets/29/360dpi.zip
index aae3adc..3970139 100644
--- a/hostsidetests/theme/assets/29/360dpi.zip
+++ b/hostsidetests/theme/assets/29/360dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/400dpi.zip b/hostsidetests/theme/assets/29/400dpi.zip
index 363d602..510eb94d 100644
--- a/hostsidetests/theme/assets/29/400dpi.zip
+++ b/hostsidetests/theme/assets/29/400dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/420dpi.zip b/hostsidetests/theme/assets/29/420dpi.zip
index 0f2ce47..a457bda 100644
--- a/hostsidetests/theme/assets/29/420dpi.zip
+++ b/hostsidetests/theme/assets/29/420dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/440dpi.zip b/hostsidetests/theme/assets/29/440dpi.zip
index 2328c61..07355d1 100644
--- a/hostsidetests/theme/assets/29/440dpi.zip
+++ b/hostsidetests/theme/assets/29/440dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/560dpi.zip b/hostsidetests/theme/assets/29/560dpi.zip
index 5f1bb0b..6a85ad8 100644
--- a/hostsidetests/theme/assets/29/560dpi.zip
+++ b/hostsidetests/theme/assets/29/560dpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/hdpi.zip b/hostsidetests/theme/assets/29/hdpi.zip
index 6d82318..e1a534a 100644
--- a/hostsidetests/theme/assets/29/hdpi.zip
+++ b/hostsidetests/theme/assets/29/hdpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/ldpi.zip b/hostsidetests/theme/assets/29/ldpi.zip
index cc60027..5475608 100644
--- a/hostsidetests/theme/assets/29/ldpi.zip
+++ b/hostsidetests/theme/assets/29/ldpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/mdpi.zip b/hostsidetests/theme/assets/29/mdpi.zip
index 66d41d4..67c5c03 100644
--- a/hostsidetests/theme/assets/29/mdpi.zip
+++ b/hostsidetests/theme/assets/29/mdpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/tvdpi.zip b/hostsidetests/theme/assets/29/tvdpi.zip
index b43032f..60f5afe 100644
--- a/hostsidetests/theme/assets/29/tvdpi.zip
+++ b/hostsidetests/theme/assets/29/tvdpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/xhdpi.zip b/hostsidetests/theme/assets/29/xhdpi.zip
index 64905f3..d2895a1 100644
--- a/hostsidetests/theme/assets/29/xhdpi.zip
+++ b/hostsidetests/theme/assets/29/xhdpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/xxhdpi.zip b/hostsidetests/theme/assets/29/xxhdpi.zip
index b2cb422..637649a 100644
--- a/hostsidetests/theme/assets/29/xxhdpi.zip
+++ b/hostsidetests/theme/assets/29/xxhdpi.zip
Binary files differ
diff --git a/hostsidetests/theme/assets/29/xxxhdpi.zip b/hostsidetests/theme/assets/29/xxxhdpi.zip
index d00dbbd..9ab19b1 100644
--- a/hostsidetests/theme/assets/29/xxxhdpi.zip
+++ b/hostsidetests/theme/assets/29/xxxhdpi.zip
Binary files differ
diff --git a/tests/JobScheduler/src/android/jobscheduler/cts/TimingConstraintsTest.java b/tests/JobScheduler/src/android/jobscheduler/cts/TimingConstraintsTest.java
index b968811..09af06b 100644
--- a/tests/JobScheduler/src/android/jobscheduler/cts/TimingConstraintsTest.java
+++ b/tests/JobScheduler/src/android/jobscheduler/cts/TimingConstraintsTest.java
@@ -95,16 +95,16 @@
      * {@link JobParameters#isOverrideDeadlineExpired()} returns the correct value.
      */
     public void testJobParameters_unexpiredDeadline() throws Exception {
-
         JobInfo deadlineJob =
                 new JobInfo.Builder(UNEXPIRED_JOB_ID, kJobServiceComponent)
                         .setMinimumLatency(500L)
-                        .setRequiresCharging(true)
+                        .setRequiresStorageNotLow(true)
                         .build();
         kTestEnvironment.setExpectedExecutions(1);
+        setStorageState(true);
         mJobScheduler.schedule(deadlineJob);
-        // Run everything by pretending the device was just plugged in.
-        sendExpediteStableChargingBroadcast();
+        // Run everything by making storage state not-low.
+        setStorageState(false);
         assertTrue("Failed to execute non-deadline job", kTestEnvironment.awaitExecution());
         assertFalse("Job that ran early (unexpired) didn't have" +
                         " JobParameters#isOverrideDeadlineExpired=false",
diff --git a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java
index fd4cea7..bb46489 100644
--- a/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java
+++ b/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java
@@ -43,9 +43,7 @@
         File publicLocation = new File(
                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
                 "publicFile.bin");
-        if (publicLocation.exists()) {
-            assertTrue(publicLocation.delete());
-        }
+        deleteFromShell(publicLocation);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -70,10 +68,8 @@
 
     @Test
     public void testSetDestinationUri_sdcardPath() throws Exception {
-        File path = new File("/sdcard/publicFile.bin");
-        if (path.exists()) {
-            assertTrue(path.delete());
-        }
+        final File path = new File("/sdcard/publicFile.bin");
+        deleteFromShell(path);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -101,9 +97,7 @@
         File publicLocation = new File(
                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
                 "publicFile.bin");
-        if (publicLocation.exists()) {
-            assertTrue(publicLocation.delete());
-        }
+        deleteFromShell(publicLocation);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -137,11 +131,12 @@
         };
 
         for (String path : filePaths) {
-            final String fileContents = path + "_" + System.nanoTime();
+            final String fileContents = "Test content:" + path + "_" + System.nanoTime();
 
+            final File file = new File(path);
             writeToFile(new File(path), fileContents);
 
-            final long id = mDownloadManager.addCompletedDownload("Test title", "Test desc", true,
+            final long id = mDownloadManager.addCompletedDownload(file.getName(), "Test desc", true,
                     "text/plain", path, fileContents.getBytes().length, true);
             final String actualContents = readFromFile(mDownloadManager.openDownloadedFile(id));
             assertEquals(fileContents, actualContents);
@@ -212,12 +207,13 @@
                 "/sdcard/file3.mp3",
         };
         for (String downloadLocation : downloadPath) {
-            final String fileContents = downloadLocation + "_" + System.nanoTime();
+            final String fileContents = "Test content:" + downloadLocation + "_" + System.nanoTime();
             final File file = new File(Uri.parse(downloadLocation).getPath());
             writeToFile(file, fileContents);
 
-            final long downloadId = mDownloadManager.addCompletedDownload("Test title", "Test desc",
-                    true, "text/plain", downloadLocation, fileContents.getBytes().length, true);
+            final long downloadId = mDownloadManager.addCompletedDownload(file.getName(),
+                    "Test desc", true,
+                    "text/plain", downloadLocation, fileContents.getBytes().length, true);
             assertTrue(downloadId >= 0);
             final Uri downloadUri = mDownloadManager.getUriForDownloadedFile(downloadId);
             mContext.grantUriPermission("com.android.shell", downloadUri,
diff --git a/tests/app/DownloadManagerLegacyTest/src/android/app/cts/DownloadManagerLegacyTest.java b/tests/app/DownloadManagerLegacyTest/src/android/app/cts/DownloadManagerLegacyTest.java
index 43efb20..32d6fd9 100644
--- a/tests/app/DownloadManagerLegacyTest/src/android/app/cts/DownloadManagerLegacyTest.java
+++ b/tests/app/DownloadManagerLegacyTest/src/android/app/cts/DownloadManagerLegacyTest.java
@@ -15,7 +15,6 @@
  */
 package android.app.cts;
 
-import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -31,7 +30,6 @@
 import org.junit.runner.RunWith;
 
 import java.io.File;
-import java.io.FileInputStream;
 
 @RunWith(AndroidJUnit4.class)
 public class DownloadManagerLegacyTest extends DownloadManagerTestBase {
@@ -44,11 +42,12 @@
         };
 
         for (String path : filePaths) {
-            final String fileContents = path + "_" + System.nanoTime();
+            final String fileContents = "Test content:" + path + "_" + System.nanoTime();
 
-            writeToFile(new File(path), fileContents);
+            final File file = new File(path);
+            writeToFile(file, fileContents);
 
-            final long id = mDownloadManager.addCompletedDownload("Test title", "Test desc", true,
+            final long id = mDownloadManager.addCompletedDownload(file.getName(), "Test desc", true,
                     "text/plain", path, fileContents.getBytes().length, true);
             final String actualContents = readFromFile(mDownloadManager.openDownloadedFile(id));
             assertEquals(fileContents, actualContents);
@@ -69,9 +68,9 @@
                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS),
                 "colors.txt");
         final String fileContents = "RED;GREEN;BLUE";
-        writeToFileFromShell(file, fileContents);
+        writeToFile(file, fileContents);
         try {
-            mDownloadManager.addCompletedDownload("Test title", "Test desc", true,
+            mDownloadManager.addCompletedDownload(file.getName(), "Test desc", true,
                     "text/plain", file.getPath(), fileContents.getBytes().length, true);
             fail(file + " is not valid for addCompletedDownload()");
         } catch (Exception e) {
@@ -85,25 +84,27 @@
      */
     @Test
     public void testAddCompletedDownload_mediaStoreEntry() throws Exception {
-        final String[] downloadPath = new String[] {
+        final String[] downloadPaths = {
                 new File(Environment.getExternalStoragePublicDirectory(
-                        Environment.DIRECTORY_DOWNLOADS), "file1.mp3").getPath(),
-                "/sdcard/Download/file2.mp3",
+                        Environment.DIRECTORY_DOWNLOADS), "file1.txt").getPath(),
+                "/sdcard/Download/file2.txt",
         };
-        for (String downloadLocation : downloadPath) {
-            final String fileContents = downloadLocation + "_" + System.nanoTime();
+        for (String downloadLocation : downloadPaths) {
+            final String fileContents =
+                    "Test content:" + downloadLocation + "_" + System.nanoTime();
             final File file = new File(downloadLocation);
             writeToFile(file, fileContents);
 
-            final long downloadId = mDownloadManager.addCompletedDownload("Test title", "Test desc",
+            final long downloadId = mDownloadManager.addCompletedDownload(
+                    file.getName(), "Test desc",
                     true, "text/plain", downloadLocation, fileContents.getBytes().length, true);
             assertTrue(downloadId >= 0);
             final Uri downloadUri = mDownloadManager.getUriForDownloadedFile(downloadId);
             mContext.grantUriPermission("com.android.shell", downloadUri,
                     Intent.FLAG_GRANT_READ_URI_PERMISSION);
             final Uri mediaStoreUri = getMediaStoreUri(downloadUri);
-            assertArrayEquals(hash(new FileInputStream(file)),
-                    hash(mContext.getContentResolver().openInputStream(mediaStoreUri)));
+
+            assertEquals(fileContents, readContentsFromUri(mediaStoreUri));
 
             // Delete entry in DownloadProvider and verify it's deleted from MediaProvider as well.
             assertRemoveDownload(downloadId, 0);
diff --git a/tests/app/src/android/app/cts/DownloadManagerTest.java b/tests/app/src/android/app/cts/DownloadManagerTest.java
index 4d365a4..e1a4591 100644
--- a/tests/app/src/android/app/cts/DownloadManagerTest.java
+++ b/tests/app/src/android/app/cts/DownloadManagerTest.java
@@ -218,21 +218,15 @@
     @Test
     public void testDownloadManagerDestination() throws Exception {
         File uriLocation = new File(mContext.getExternalFilesDir(null), "uriFile.bin");
-        if (uriLocation.exists()) {
-            assertTrue(uriLocation.delete());
-        }
+        deleteFromShell(uriLocation);
 
         File extFileLocation = new File(mContext.getExternalFilesDir(null), "extFile.bin");
-        if (extFileLocation.exists()) {
-            assertTrue(extFileLocation.delete());
-        }
+        deleteFromShell(extFileLocation);
 
         File publicLocation = new File(
                 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                 "publicFile.bin");
-        if (publicLocation.exists()) {
-            assertTrue(publicLocation.delete());
-        }
+        deleteFromShell(publicLocation);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -276,15 +270,11 @@
     public void testDownloadManagerDestinationExtension() throws Exception {
         String noExt = "noiseandchirps";
         File noExtLocation = new File(mContext.getExternalFilesDir(null), noExt);
-        if (noExtLocation.exists()) {
-            assertTrue(noExtLocation.delete());
-        }
+        deleteFromShell(noExtLocation);
 
         String wrongExt = "noiseandchirps.wrong";
         File wrongExtLocation = new File(mContext.getExternalFilesDir(null), wrongExt);
-        if (wrongExtLocation.exists()) {
-            assertTrue(wrongExtLocation.delete());
-        }
+        deleteFromShell(wrongExtLocation);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -319,9 +309,7 @@
         final File documentsFile = new File(
                 Environment.getExternalStoragePublicDirectory("TestDir"),
                 "uriFile.bin");
-        if (documentsFile.exists()) {
-            assertTrue(documentsFile.delete());
-        }
+        deleteFromShell(documentsFile);
 
         final Request badRequest = new Request(getGoodUrl());
         badRequest.setDestinationUri(Uri.fromFile(documentsFile));
@@ -480,9 +468,7 @@
     @Test
     public void testDownloadNotVisibleInUi() throws Exception {
         File uriLocation = new File(mContext.getExternalFilesDir(null), "uriFile.bin");
-        if (uriLocation.exists()) {
-            assertTrue(uriLocation.delete());
-        }
+        deleteFromShell(uriLocation);
 
         final DownloadCompleteReceiver receiver = new DownloadCompleteReceiver();
         try {
@@ -516,7 +502,7 @@
 
         writeToFile(file, fileContents);
 
-        final long id = mDownloadManager.addCompletedDownload("Test title", "Test desc", true,
+        final long id = mDownloadManager.addCompletedDownload(file.getName(), "Test desc", true,
                 "text/plain", file.getPath(), fileContents.getBytes().length, true);
         final String actualContents = readFromFile(mDownloadManager.openDownloadedFile(id));
         assertEquals(fileContents, actualContents);
diff --git a/tests/app/src/android/app/cts/DownloadManagerTestBase.java b/tests/app/src/android/app/cts/DownloadManagerTestBase.java
index 71eb4e9a..93ca1c9 100644
--- a/tests/app/src/android/app/cts/DownloadManagerTestBase.java
+++ b/tests/app/src/android/app/cts/DownloadManagerTestBase.java
@@ -131,6 +131,13 @@
         }
     }
 
+    protected static String readContentsFromUri(Uri uri) throws Exception {
+        final Context context = InstrumentationRegistry.getTargetContext();
+        try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
+            return readFromInputStream(inputStream);
+        }
+    }
+
     protected static String readFromRawFile(String filePath) throws Exception {
         Log.d(TAG, "Reading form file: " + filePath);
         return runShellCommand("cat " + filePath);
@@ -160,16 +167,62 @@
         return new File(baseDir, fileName);
     }
 
+    protected static void deleteFromShell(File file) {
+        runShellCommand("rm " + file);
+    }
+
     protected static void writeToFile(File file, String contents) throws Exception {
+        file.getParentFile().mkdirs();
+        file.delete();
+
         try (final PrintWriter out = new PrintWriter(file)) {
             out.print(contents);
         }
+
+        final String actual;
+        try (FileInputStream fis = new FileInputStream(file)) {
+            actual = readFromInputStream(fis);
+        }
+        assertEquals(contents, actual);
     }
 
     protected static void writeToFileFromShell(File file, String contents) throws Exception {
-        final String cmd = "echo \"" + contents + "\" > " + file;
-        final String res = runShellCommand(cmd);
+        runShellCommand("mkdir -p " + file.getParentFile());
+        runShellCommand("rm " + file);
+
+        final String cmd = "dd of=" + file.getAbsolutePath();
+        final ParcelFileDescriptor[] pfds = InstrumentationRegistry.getInstrumentation()
+                .getUiAutomation().executeShellCommandRw(cmd);
+        try (final PrintWriter out =
+                     new PrintWriter(new ParcelFileDescriptor.AutoCloseOutputStream(pfds[1]))) {
+            out.print(contents);
+        }
+
+        final String res;
+        try (FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfds[0])) {
+            res = readFromInputStream(fis);
+        }
         Log.d(TAG, "Output of '" + cmd + "': '" + res + "'");
+        runShellCommand("sync");
+
+        assertFileContents(file, contents);
+    }
+
+    private static String readFromInputStream(InputStream inputStream) throws Exception {
+        final StringBuffer res = new StringBuffer();
+        final byte[] buf = new byte[512];
+        int bytesRead;
+        while ((bytesRead = inputStream.read(buf)) != -1) {
+            res.append(new String(buf, 0, bytesRead));
+        }
+        return res.toString();
+    }
+
+    protected static void assertFileContents(File file, String contents) {
+        final String cmd = "cat " + file.getAbsolutePath();
+        final String output = runShellCommand(cmd);
+        Log.d(TAG, "Output of '" + cmd + "': '" + output + "'");
+        assertEquals(contents, output);
     }
 
     protected void clearDownloads() {
diff --git a/tests/camera/AndroidTest.xml b/tests/camera/AndroidTest.xml
index d1bae57..7705d19 100644
--- a/tests/camera/AndroidTest.xml
+++ b/tests/camera/AndroidTest.xml
@@ -29,7 +29,10 @@
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="android.camera.cts" />
         <option name="runtime-hint" value="12m7s" />
-        <!-- test-timeout unit is ms, value = 33 min -->
-        <option name="test-timeout" value="2000000" />
+        <!-- test-timeout unit is ms, value = 400 min -->
+        <!-- This (host side) timeout value needs to be at least as large as any
+              single test class/method (device side) timeout value set by timeout
+              annotation -->
+        <option name="test-timeout" value="24000000" />
     </test>
 </configuration>
diff --git a/tests/camera/src/android/hardware/camera2/cts/LogicalCameraDeviceTest.java b/tests/camera/src/android/hardware/camera2/cts/LogicalCameraDeviceTest.java
index be932b7..750e715 100644
--- a/tests/camera/src/android/hardware/camera2/cts/LogicalCameraDeviceTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/LogicalCameraDeviceTest.java
@@ -1182,7 +1182,7 @@
     private boolean deviceHasBattery() {
         final Intent batteryInfo = mContext.registerReceiver(null,
                 new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
-        return batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
+        return batteryInfo != null && batteryInfo.getBooleanExtra(BatteryManager.EXTRA_PRESENT, true);
     }
 
     private double getScreenSizeInInches() {
diff --git a/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java b/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
index 3ed4cfe..77fa6dd 100644
--- a/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
+++ b/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
@@ -61,6 +61,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestRule;
@@ -178,6 +179,7 @@
                 APP_A_FOREGROUND_ACTIVITY);
     }
 
+    @Ignore // test temporarily disabled due to bg activity start grace period introduction
     @Test
     public void testActivityNotBlockedwhenForegroundActivityLaunchInSameTask() throws Exception {
         // Start foreground activity, and foreground activity able to launch background activity
@@ -208,6 +210,7 @@
                 APP_A_FOREGROUND_ACTIVITY);
     }
 
+    @Ignore // test temporarily disabled due to bg activity start grace period introduction
     @Test
     public void testActivityNotBlockedWhenForegroundActivityLaunchInDifferentTask()
             throws Exception {
@@ -240,6 +243,7 @@
         assertTaskStack(null, APP_A_BACKGROUND_ACTIVITY);
     }
 
+    @Ignore // test temporarily disabled due to bg activity start grace period introduction
     @Test
     @FlakyTest(bugId = 130800326)
     public void testActivityBlockedWhenForegroundActivityRestartsItself() throws Exception {
diff --git a/tests/tests/car/src/android/car/cts/CarUxRestrictionsManagerTest.java b/tests/tests/car/src/android/car/cts/CarUxRestrictionsManagerTest.java
new file mode 100644
index 0000000..ca7364b
--- /dev/null
+++ b/tests/tests/car/src/android/car/cts/CarUxRestrictionsManagerTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2019 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.car.cts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import android.car.Car;
+import android.car.drivingstate.CarUxRestrictions;
+import android.car.drivingstate.CarUxRestrictionsManager;
+import android.platform.test.annotations.RequiresDevice;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RequiresDevice
+@RunWith(AndroidJUnit4.class)
+public class CarUxRestrictionsManagerTest extends CarApiTestBase {
+    private CarUxRestrictionsManager mManager;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+
+        mManager = (CarUxRestrictionsManager)
+                getCar().getCarManager(Car.CAR_UX_RESTRICTION_SERVICE);
+        assertNotNull(mManager);
+    }
+
+    @Test
+    public void testCarUxRestrictionsBuilder() {
+        int maxContentDepth = 1;
+        int maxCumulativeContentItems = 1;
+        int maxStringLength = 1;
+        CarUxRestrictions.Builder builder = new CarUxRestrictions.Builder(
+                true, CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED, 0L);
+        builder.setMaxContentDepth(maxContentDepth);
+        builder.setMaxCumulativeContentItems(maxCumulativeContentItems);
+        builder.setMaxStringLength(maxStringLength);
+
+        CarUxRestrictions restrictions = builder.build();
+
+        assertTrue(restrictions.toString(),
+                restrictions.isRequiresDistractionOptimization());
+        assertEquals(restrictions.toString(),
+                restrictions.getActiveRestrictions(),
+                CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED);
+        assertEquals(restrictions.toString(),
+                restrictions.getMaxContentDepth(), maxContentDepth);
+        assertEquals(restrictions.toString(),
+                restrictions.getMaxCumulativeContentItems(), maxCumulativeContentItems);
+        assertEquals(restrictions.toString(),
+                restrictions.getMaxRestrictedStringLength(), maxStringLength);
+    }
+
+    @Test
+    public void testCarUxRestrictions_isSameRestrictions() {
+        CarUxRestrictions.Builder oneBuilder = new CarUxRestrictions.Builder(
+                true, CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED, 0L);
+        CarUxRestrictions.Builder anotherBuilder = new CarUxRestrictions.Builder(
+                true, CarUxRestrictions.UX_RESTRICTIONS_FULLY_RESTRICTED, 0L);
+
+        assertTrue(oneBuilder.build().isSameRestrictions(anotherBuilder.build()));
+    }
+
+    @Test
+    public void testRegisterListener_noCrash() {
+        mManager.registerListener(restrictions -> {});
+        mManager.unregisterListener();
+    }
+}
diff --git a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
index a9a705a..e615e34 100644
--- a/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
+++ b/tests/tests/content/src/android/content/cts/AvailableIntentsTest.java
@@ -410,7 +410,9 @@
     }
 
     public void testPowerUsageSummarySettings() {
-        assertCanBeHandled(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));
+        if (isHandheld()) {
+            assertCanBeHandled(new Intent(Intent.ACTION_POWER_USAGE_SUMMARY));
+        }
     }
 
     public void testEasyConnectIntent() {
@@ -444,4 +446,14 @@
         Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS);
         assertCanBeHandled(intent);
     }
+
+    private boolean isHandheld() {
+        // handheld nature is not exposed to package manager, for now
+        // we check for touchscreen and NOT watch, NOT tv and NOT car
+        PackageManager pm = getContext().getPackageManager();
+        return pm.hasSystemFeature(pm.FEATURE_TOUCHSCREEN)
+                && !pm.hasSystemFeature(pm.FEATURE_WATCH)
+                && !pm.hasSystemFeature(pm.FEATURE_TELEVISION)
+                && !pm.hasSystemFeature(pm.FEATURE_AUTOMOTIVE);
+    }
 }
diff --git a/tests/tests/os/assets/minijail/isolated-common.policy b/tests/tests/os/assets/minijail/isolated-common.policy
index a8f4e25..11205ae 100644
--- a/tests/tests/os/assets/minijail/isolated-common.policy
+++ b/tests/tests/os/assets/minijail/isolated-common.policy
@@ -75,6 +75,7 @@
 # madvise: advice==MADV_DONTNEED
 madvise: arg2 == 4; return EPERM
 
+membarrier: 1
 memfd_create: return EPERM
 mkdirat: return EPERM
 mknodat: return EPERM
diff --git a/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java b/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
index c31491d..9e71c69 100644
--- a/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
+++ b/tests/tests/provider/src/android/provider/cts/MediaStore_FilesTest.java
@@ -300,6 +300,30 @@
         assertTrue(queryLong(uri, MediaColumns.DATE_ADDED) >= startTime);
     }
 
+    @Test
+    public void testInPlaceUpdate_mediaFileWithInvalidRelativePath() throws Exception {
+        final File file = new File(ProviderTestUtils.stageDownloadDir(mVolumeName),
+                "test" + System.nanoTime() + ".jpg");
+        ProviderTestUtils.stageFile(R.raw.scenery, file);
+        Log.d(TAG, "Staged image file at " + file.getAbsolutePath());
+
+        final ContentValues insertValues = new ContentValues();
+        insertValues.put(MediaColumns.DATA, file.getAbsolutePath());
+        insertValues.put(MediaStore.Images.ImageColumns.DESCRIPTION, "Not a cat photo");
+        final Uri uri = mResolver.insert(mExternalImages, insertValues);
+        assertEquals(0, queryLong(uri, MediaStore.Images.ImageColumns.IS_PRIVATE));
+        assertStringColumn(uri, MediaStore.Images.ImageColumns.DESCRIPTION, "Not a cat photo");
+
+        final ContentValues updateValues = new ContentValues();
+        updateValues.put(FileColumns.MEDIA_TYPE, FileColumns.MEDIA_TYPE_IMAGE);
+        updateValues.put(FileColumns.MIME_TYPE, "image/jpeg");
+        updateValues.put(MediaStore.Images.ImageColumns.IS_PRIVATE, 1);
+        int updateRows = mResolver.update(uri, updateValues, null, null);
+        assertEquals(1, updateRows);
+        // Only interested in update not throwing exception. No need in checking whenever values
+        // were actually updates, as it is not in the scope of this test.
+    }
+
     private long queryLong(Uri uri, String columnName) {
         try (Cursor c = mResolver.query(uri, new String[] { columnName }, null, null, null)) {
             assertTrue(c.moveToFirst());
diff --git a/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java b/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
index 220ef47..e748360 100644
--- a/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
+++ b/tests/tests/provider/src/android/provider/cts/ProviderTestUtils.java
@@ -183,6 +183,14 @@
                 "android.provider.cts");
     }
 
+    static File stageDownloadDir(String volumeName) throws IOException {
+        if (MediaStore.VOLUME_EXTERNAL.equals(volumeName)) {
+            volumeName = MediaStore.VOLUME_EXTERNAL_PRIMARY;
+        }
+        return Environment.buildPath(MediaStore.getVolumePath(volumeName),
+                Environment.DIRECTORY_DOWNLOADS, "android.provider.cts");
+    }
+
     static File stageFile(int resId, File file) throws IOException {
         // The caller may be trying to stage into a location only available to
         // the shell user, so we need to perform the entire copy as the shell
diff --git a/tests/tests/security/src/android/security/cts/RenderTarget.java b/tests/tests/security/src/android/security/cts/RenderTarget.java
new file mode 100644
index 0000000..3c0d1c4
--- /dev/null
+++ b/tests/tests/security/src/android/security/cts/RenderTarget.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2019 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 static android.opengl.EGL14.EGL_ALPHA_SIZE;
+import static android.opengl.EGL14.EGL_BLUE_SIZE;
+import static android.opengl.EGL14.EGL_CONFIG_CAVEAT;
+import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION;
+import static android.opengl.EGL14.EGL_DEFAULT_DISPLAY;
+import static android.opengl.EGL14.EGL_DEPTH_SIZE;
+import static android.opengl.EGL14.EGL_GREEN_SIZE;
+import static android.opengl.EGL14.EGL_HEIGHT;
+import static android.opengl.EGL14.EGL_NONE;
+import static android.opengl.EGL14.EGL_NO_CONTEXT;
+import static android.opengl.EGL14.EGL_OPENGL_ES2_BIT;
+import static android.opengl.EGL14.EGL_RED_SIZE;
+import static android.opengl.EGL14.EGL_RENDERABLE_TYPE;
+import static android.opengl.EGL14.EGL_SURFACE_TYPE;
+import static android.opengl.EGL14.EGL_WIDTH;
+import static android.opengl.EGL14.EGL_WINDOW_BIT;
+import static android.opengl.EGL14.eglChooseConfig;
+import static android.opengl.EGL14.eglCreateContext;
+import static android.opengl.EGL14.eglCreatePbufferSurface;
+import static android.opengl.EGL14.eglGetDisplay;
+import static android.opengl.EGL14.eglInitialize;
+import static android.opengl.EGL14.eglMakeCurrent;
+import static android.opengl.GLES20.glDeleteTextures;
+import static android.opengl.GLES20.glGenTextures;
+
+import android.graphics.SurfaceTexture;
+import android.opengl.EGLConfig;
+import android.opengl.EGLContext;
+import android.opengl.EGLDisplay;
+import android.opengl.EGLSurface;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.Message;
+import android.util.Log;
+import android.view.Surface;
+
+public final class RenderTarget {
+    static final String TAG = "RenderTarget";
+
+    private static final int SETUP_THREAD = 1;
+    private static final int CREATE_SINK = 2;
+    private static final int DESTROY_SINK = 3;
+    private static final int UPDATE_TEX_IMAGE = 4;
+
+    private static final Handler sHandler;
+    static {
+        HandlerThread thread = new HandlerThread("RenderTarget-GL");
+        thread.start();
+        sHandler = new Handler(thread.getLooper(), new RenderTargetThread());
+        sHandler.sendEmptyMessage(SETUP_THREAD);
+    }
+
+    public static RenderTarget create() {
+        GenericFuture<RenderTarget> future = new GenericFuture<>();
+        Message.obtain(sHandler, CREATE_SINK, future).sendToTarget();
+        try {
+            return future.get();
+        } catch (InterruptedException e) {
+            throw new RuntimeException("Failed to createSink()", e);
+        }
+    }
+
+    private final SurfaceTexture mSurfaceTexture;
+    private final int mGlTexId;
+    private Surface mSurface;
+
+    private RenderTarget(SurfaceTexture surfaceTexture, int glTexId) {
+        mSurfaceTexture = surfaceTexture;
+        mGlTexId = glTexId;
+        mSurface = new Surface(mSurfaceTexture);
+    }
+
+    public Surface getSurface() {
+        return mSurface;
+    }
+
+    public void setDefaultSize(int width, int height) {
+        mSurfaceTexture.setDefaultBufferSize(width, height);
+    }
+
+    public void destroy() {
+        mSurface = null;
+        Message.obtain(sHandler, DESTROY_SINK, this).sendToTarget();
+    }
+
+    private static class RenderTargetThread implements Handler.Callback,
+            SurfaceTexture.OnFrameAvailableListener {
+        @Override
+        public boolean handleMessage(Message msg) {
+            switch (msg.what) {
+                case SETUP_THREAD:
+                    setupThread();
+                    return true;
+                case CREATE_SINK:
+                    createSink((GenericFuture<RenderTarget>) msg.obj);
+                    return true;
+                case DESTROY_SINK:
+                    destroySink((RenderTarget) msg.obj);
+                    return true;
+                case UPDATE_TEX_IMAGE:
+                    updateTexImage((SurfaceTexture) msg.obj);
+                default:
+                    return false;
+            }
+        }
+
+        private void createSink(GenericFuture<RenderTarget> sinkFuture) {
+            int[] tex = new int[1];
+            glGenTextures(1, tex, 0);
+            SurfaceTexture texture = new SurfaceTexture(tex[0]);
+            texture.setOnFrameAvailableListener(this);
+            sinkFuture.setResult(new RenderTarget(texture, tex[0]));
+        }
+
+        private void destroySink(RenderTarget sink) {
+            sHandler.removeMessages(UPDATE_TEX_IMAGE, sink.mSurfaceTexture);
+            sink.mSurfaceTexture.setOnFrameAvailableListener(null);
+            sink.mSurfaceTexture.release();
+            glDeleteTextures(1, new int[] { sink.mGlTexId }, 0);
+        }
+
+        private void updateTexImage(SurfaceTexture texture) {
+            texture.updateTexImage();
+        }
+
+        private void setupThread() {
+            EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+            if (display == null) {
+                throw new IllegalStateException("eglGetDisplay failed");
+            }
+            int[] version = new int[2];
+            if (!eglInitialize(display, version, 0, version, 1)) {
+                throw new IllegalStateException("eglInitialize failed");
+            }
+            final int[] egl_attribs = new int[] {
+                    EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+                    EGL_RED_SIZE, 8,
+                    EGL_GREEN_SIZE, 8,
+                    EGL_BLUE_SIZE, 8,
+                    EGL_ALPHA_SIZE, 8,
+                    EGL_DEPTH_SIZE, 0,
+                    EGL_CONFIG_CAVEAT, EGL_NONE,
+                    EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+                    EGL_NONE
+            };
+            EGLConfig[] configs = new EGLConfig[1];
+            int[] num_configs = new int[1];
+            if (!eglChooseConfig(display, egl_attribs, 0, configs, 0, 1, num_configs, 0)
+                    || num_configs[0] <= 0 || configs[0] == null) {
+                throw new IllegalStateException("eglChooseConfig failed");
+            }
+            EGLConfig config = configs[0];
+            final int[] gl_attribs = new int[] {
+                    EGL_CONTEXT_CLIENT_VERSION, 2,
+                    EGL_NONE
+            };
+            EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, gl_attribs, 0);
+            if (context == null) {
+                throw new IllegalStateException("eglCreateContext failed");
+            }
+            final int[] pbuffer_attribs = new int[] { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
+            EGLSurface pbuffer = eglCreatePbufferSurface(display, config, pbuffer_attribs, 0);
+            if (pbuffer == null) {
+                throw new IllegalStateException("create pbuffer surface failed");
+            }
+            if (!eglMakeCurrent(display, pbuffer, pbuffer, context)) {
+                throw new IllegalStateException("Failed to make current");
+            }
+        }
+
+        @Override
+        public void onFrameAvailable(SurfaceTexture surfaceTexture) {
+            Log.i(TAG, "new frame available");
+            Message.obtain(sHandler, UPDATE_TEX_IMAGE, surfaceTexture).sendToTarget();
+        }
+    }
+
+    private static class GenericFuture<T> {
+        private boolean mHasResult = false;
+        private T mResult;
+        public void setResult(T result) {
+            synchronized (this) {
+                if (mHasResult) {
+                    throw new IllegalStateException("Result already set");
+                }
+                mHasResult = true;
+                mResult = result;
+                notifyAll();
+            }
+        }
+
+        public T get() throws InterruptedException {
+            synchronized (this) {
+                while (!mHasResult) {
+                    wait();
+                }
+                return mResult;
+            }
+        }
+    }
+}
diff --git a/tests/tests/security/src/android/security/cts/StagefrightTest.java b/tests/tests/security/src/android/security/cts/StagefrightTest.java
index 7b9cef0..b0e15e1 100644
--- a/tests/tests/security/src/android/security/cts/StagefrightTest.java
+++ b/tests/tests/security/src/android/security/cts/StagefrightTest.java
@@ -845,7 +845,8 @@
                 mp.setOnErrorListener(mpcl);
                 mp.setOnPreparedListener(mpcl);
                 mp.setOnCompletionListener(mpcl);
-                Surface surface = getDummySurface();
+                RenderTarget renderTarget = RenderTarget.create();
+                Surface surface = renderTarget.getSurface();
                 mp.setSurface(surface);
                 AssetFileDescriptor fd = null;
                 try {
@@ -858,6 +859,7 @@
                 }
                 Looper.loop();
                 mp.release();
+                renderTarget.destroy();
             }
         });
         t.start();
@@ -1109,32 +1111,6 @@
         doStagefrightTestMediaPlayerANR(rid, null);
     }
 
-    private Surface getDummySurface() {
-        int[] textures = new int[1];
-        GLES20.glGenTextures(1, textures, 0);
-        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]);
-        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES20.GL_TEXTURE_MIN_FILTER,
-                GLES20.GL_NEAREST);
-        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES20.GL_TEXTURE_MAG_FILTER,
-                GLES20.GL_LINEAR);
-        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES20.GL_TEXTURE_WRAP_S,
-                GLES20.GL_CLAMP_TO_EDGE);
-        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
-                GLES20.GL_TEXTURE_WRAP_T,
-                GLES20.GL_CLAMP_TO_EDGE);
-        SurfaceTexture surfaceTex = new SurfaceTexture(textures[0]);
-        surfaceTex.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() {
-            @Override
-            public void onFrameAvailable(SurfaceTexture surfaceTexture) {
-                Log.i(TAG, "new frame available");
-            }
-        });
-        return new Surface(surfaceTex);
-    }
-
     public JSONArray getCrashReport(String testname, long timeout)
         throws InterruptedException {
         Log.i(TAG, CrashUtils.UPLOAD_REQUEST);
@@ -1297,7 +1273,8 @@
                 mp.setOnErrorListener(mpcl);
                 mp.setOnPreparedListener(mpcl);
                 mp.setOnCompletionListener(mpcl);
-                Surface surface = getDummySurface();
+                RenderTarget renderTarget = RenderTarget.create();
+                Surface surface = renderTarget.getSurface();
                 mp.setSurface(surface);
                 AssetFileDescriptor fd = null;
                 try {
@@ -1320,6 +1297,7 @@
 
                 Looper.loop();
                 mp.release();
+                renderTarget.destroy();
             }
         });
 
@@ -1440,9 +1418,10 @@
                 Log.i(TAG, "Decoding track " + t + " using codec " + codecName);
                 ex.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
                 MediaCodec codec = MediaCodec.createByCodecName(codecName);
+                RenderTarget renderTarget = RenderTarget.create();
                 Surface surface = null;
                 if (mime.startsWith("video/")) {
-                    surface = getDummySurface();
+                    surface = renderTarget.getSurface();
                 }
                 try {
                     codec.configure(format, surface, null, 0);
@@ -1484,6 +1463,7 @@
                     // local exceptions ignored, not security issues
                 } finally {
                     codec.release();
+                    renderTarget.destroy();
                 }
             }
             ex.unselectTrack(t);
@@ -1921,7 +1901,8 @@
                 mp.setOnErrorListener(mpl);
                 mp.setOnPreparedListener(mpl);
                 mp.setOnCompletionListener(mpl);
-                Surface surface = getDummySurface();
+                RenderTarget renderTarget = RenderTarget.create();
+                Surface surface = renderTarget.getSurface();
                 mp.setSurface(surface);
                 AssetFileDescriptor fd = null;
                 try {
@@ -1943,6 +1924,7 @@
 
                 Looper.loop();
                 mp.release();
+                renderTarget.destroy();
             }
         });
 
diff --git a/tests/tests/telephony/current/src/android/telephony/cts/PhoneStateListenerTest.java b/tests/tests/telephony/current/src/android/telephony/cts/PhoneStateListenerTest.java
index 8c29609..a52123b 100644
--- a/tests/tests/telephony/current/src/android/telephony/cts/PhoneStateListenerTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/cts/PhoneStateListenerTest.java
@@ -807,14 +807,20 @@
                     public void onDataConnectionStateChanged(int state) {
                         synchronized(mLock) {
                             mOnDataConnectionStateChangedCalled = true;
-                            mLock.notify();
+                            if (mOnDataConnectionStateChangedCalled
+                                    && mOnDataConnectionStateChangedWithNetworkTypeCalled) {
+                                mLock.notify();
+                            }
                         }
                     }
                     @Override
                     public void onDataConnectionStateChanged(int state, int networkType) {
                         synchronized(mLock) {
                             mOnDataConnectionStateChangedWithNetworkTypeCalled = true;
-                            mLock.notify();
+                            if (mOnDataConnectionStateChangedCalled
+                                    && mOnDataConnectionStateChangedWithNetworkTypeCalled) {
+                                mLock.notify();
+                            }
                         }
                     }
                 };