Merge "DO NOT MERGE: Restore the logic of verifying the size of DisplayMetrics" into android14-tests-dev
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
index e0c94ae..869b922 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/ManifestTestListAdapter.java
@@ -687,6 +687,8 @@
                 if (test.applicableFeatures == null || hasAnyFeature(test.applicableFeatures)) {
                     // Add suffix in test name if the test is in the folded mode.
                     test.testName = setTestNameSuffix(mode, test.testName);
+                    // Remove suffix in test name if the test is in the unfolded mode.
+                    test.testName = removeTestNameSuffix(mode, test.testName);
                     filteredTests.add(test);
                 } else {
                     Log.d(LOG_TAG, "Skipping " + test.testName + " due to metadata filtering");
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 dcdfdd0..f812073 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
@@ -37,6 +37,7 @@
 import android.dynamicmime.testapp.assertions.MimeGroupAssertions;
 import android.dynamicmime.testapp.commands.MimeGroupCommands;
 import android.dynamicmime.testapp.util.Utils;
+import android.os.SystemClock;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.uiautomator.By;
@@ -376,6 +377,7 @@
             if (scrollable.exists()) {
                 scrollable.scrollToBeginning(Integer.MAX_VALUE);
                 scrollable.scrollIntoView(selector);
+                SystemClock.sleep(1000L);
             }
         } catch (UiObjectNotFoundException ignore) {
             throw new AssertionError("Scrollable view was lost.");
diff --git a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
index a35a6ac..341adec 100644
--- a/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
+++ b/tests/tests/database/src/android/database/cts/DatabaseUtilsTest.java
@@ -153,6 +153,7 @@
         assertEquals(1, cursor.getCount());
         cursor.moveToFirst();
         assertEquals("Mike", cursor.getString(1));
+        db.close();
         getContext().deleteDatabase(dbName);
     }
 
diff --git a/tests/tests/gameframerate/src/GameFrameRateCtsActivity.java b/tests/tests/gameframerate/src/GameFrameRateCtsActivity.java
index f5687f9..361052c 100644
--- a/tests/tests/gameframerate/src/GameFrameRateCtsActivity.java
+++ b/tests/tests/gameframerate/src/GameFrameRateCtsActivity.java
@@ -47,7 +47,7 @@
     private static final int PRECONDITION_WAIT_MAX_ATTEMPTS = 5;
     private static final long PRECONDITION_WAIT_TIMEOUT_NANOSECONDS = 20 * 1_000_000_000L;
     private static final long PRECONDITION_VIOLATION_WAIT_TIMEOUT_NANOSECONDS = 3 * 1_000_000_000L;
-    private static final float FRAME_RATE_TOLERANCE = 0.01f;
+    private static final float FRAME_RATE_TOLERANCE = 1.01f;
     private static final float FPS_TOLERANCE_FOR_FRAME_RATE_OVERRIDE = 5;
     private static final long FRAME_RATE_MIN_WAIT_TIME_NANOSECONDS = 1 * 1_000_000_000L;
     private static final long FRAME_RATE_MAX_WAIT_TIME_NANOSECONDS = 10 * 1_000_000_000L;
diff --git a/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java b/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
index 887d031..f70ea7b 100644
--- a/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/ImageDecoderTest.java
@@ -541,27 +541,18 @@
                 }
             }
         };
-        Listener l = new Listener();
 
-        // This test relies on ImageDecoder *not* scaling to account for density.
-        // Temporarily change the DisplayMetrics to prevent that scaling.
-        Resources res = getResources();
-        final int originalDensity = res.getDisplayMetrics().densityDpi;
-        res.getDisplayMetrics().densityDpi = DisplayMetrics.DENSITY_DEFAULT;
-        ImageDecoder.Source src = ImageDecoder.createSource(res, record.resId);
-        assertNotNull(src);
+        Listener l = new Listener();
         l.doCrop = doCrop;
         l.doScale = doScale;
         l.allocator = allocator;
 
         Bitmap bm = null;
         try {
-            bm = ImageDecoder.decodeBitmap(src, l);
+            bm = decodeUnscaledBitmap(record.resId, l);
         } catch (IOException e) {
             fail("Failed " + Utils.getAsResourceUri(record.resId)
                     + " with exception " + e);
-        } finally {
-            res.getDisplayMetrics().densityDpi = originalDensity;
         }
         assertNotNull(bm);
 
@@ -576,6 +567,7 @@
                 assertNotEquals(Bitmap.Config.HARDWARE, bm.getConfig());
 
                 if (!doScale && !doCrop) {
+                    Resources res = getResources();
                     BitmapFactory.Options options = new BitmapFactory.Options();
                     options.inScaled = false;
                     Bitmap reference = BitmapFactory.decodeResource(res,
diff --git a/tests/tests/os/src/android/os/cts/SecurityFeaturesTest.java b/tests/tests/os/src/android/os/cts/SecurityFeaturesTest.java
index 5958ad3..c7c98d9 100644
--- a/tests/tests/os/src/android/os/cts/SecurityFeaturesTest.java
+++ b/tests/tests/os/src/android/os/cts/SecurityFeaturesTest.java
@@ -19,6 +19,7 @@
 import static android.system.OsConstants.PR_GET_DUMPABLE;
 
 import android.os.Build;
+import android.os.SystemProperties;
 import android.platform.test.annotations.AppModeFull;
 import android.platform.test.annotations.RestrictedBuildTest;
 import android.system.Os;
@@ -50,7 +51,7 @@
     }
 
     /**
-     * Verifies that prctl(PR_GET_DUMPABLE) == ro.debuggable
+     * Verifies prctl(PR_GET_DUMPABLE)
      *
      * When PR_SET_DUMPABLE is 0, an application will not generate a
      * coredump, and PTRACE_ATTACH is disallowed. It's a security best
@@ -61,8 +62,8 @@
      * By default, PR_SET_DUMPABLE is 0 for zygote spawned apps, except
      * in the following circumstances:
      *
-     * 1) ro.debuggable=1 (global debuggable enabled, i.e., userdebug or
-     * eng builds).
+     * 1) eng build or userdebug build when one of property "persist.debug.ptrace.enabled"
+     * and "persist.debug.dalvik.vm.jdwp.enabled" is set.
      *
      * 2) android:debuggable="true" in the manifest for an individual
      * application.
@@ -73,15 +74,16 @@
      * <meta-data android:name="com.android.graphics.injectLayers.enable" android:value="true"/>
      * in the application manifest.
      *
-     * For this test, neither #2, #3, nor #4 are true, so we expect ro.debuggable
-     * to exactly equal prctl(PR_GET_DUMPABLE).
+     * For this test, neither #2, #3, nor #4 are true, so we only test #1.
      */
     @AppModeFull(reason = "Instant apps cannot access APIs")
-    @RestrictedBuildTest
     public void testPrctlDumpable() throws Exception {
-        boolean userBuild = "user".equals(Build.TYPE);
+        boolean userDebugBuild = "userdebug".equals(Build.TYPE);
+        boolean engBuild = "eng".equals(Build.TYPE);
+        boolean enablePtrace = SystemProperties.get("persist.debug.ptrace.enabled").equals("1");
+        boolean enableJDWP = SystemProperties.get("persist.debug.dalvik.vm.jdwp.enabled").equals("1");
         int prctl_dumpable = Os.prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
-        int expected = userBuild ? 0 : 1;
+        int expected = ((userDebugBuild && (enablePtrace || enableJDWP)) || engBuild) ? 1 : 0;
         assertEquals(expected, prctl_dumpable);
     }
 }