Merge "Add caption bar consideration to SnapshotTaskTests." into android13-tests-dev am: afd8815ce6

Original change: https://android-review.googlesource.com/c/platform/cts/+/2506639

Change-Id: I11206fea975d7180a0e1bd2028ed06bb6f1bde12
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/tests/framework/base/windowmanager/src/android/server/wm/SnapshotTaskTests.java b/tests/framework/base/windowmanager/src/android/server/wm/SnapshotTaskTests.java
index 59a1a2b..198e4b3 100644
--- a/tests/framework/base/windowmanager/src/android/server/wm/SnapshotTaskTests.java
+++ b/tests/framework/base/windowmanager/src/android/server/wm/SnapshotTaskTests.java
@@ -17,6 +17,7 @@
 package android.server.wm;
 
 import static android.server.wm.WindowManagerTestBase.startActivity;
+import static android.view.WindowInsets.Type.captionBar;
 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
 
 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@@ -85,6 +86,9 @@
 
     @Test
     public void testSetDisablePreviewScreenshots() throws Exception {
+        final View decor = mActivity.getWindow().getDecorView();
+        final int captionBarHeight = decor.getRootWindowInsets().getInsets(captionBar()).top;
+
         BitmapPixelChecker pixelChecker = new BitmapPixelChecker(PixelColor.RED);
 
         int retries = 0;
@@ -93,7 +97,8 @@
             Bitmap bitmap = mWindowManager.snapshotTaskForRecents(mActivity.getTaskId());
             if (bitmap != null) {
                 int expectedMatching =
-                        bitmap.getWidth() * bitmap.getHeight() - MATCHING_PIXEL_MISMATCH_ALLOWED;
+                        bitmap.getWidth() * bitmap.getHeight() - MATCHING_PIXEL_MISMATCH_ALLOWED
+                                - (captionBarHeight * decor.getWidth());
                 Rect boundToCheck = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
                 int matchingPixels = pixelChecker.getNumMatchingPixels(bitmap, boundToCheck);
                 matchesPixels = matchingPixels >= expectedMatching;