Test for Ignore presentation windows - RESTRICT AUTOMERGE

Windows of TYPE_PRESENTATION should not be counted as visible windows to
determine if BAL is allowed.

Test: atest BackgroundActivityLaunchTest
Bug: 264029851, 205130886
Merged-In: I90fa57414ab21205efaff53185ef8eb2815a55f8
Change-Id: I61b0096ec0fcd923ea30b20df8af8264d203c9e2
diff --git a/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/Components.java b/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/Components.java
index d65dfc5..2bd1d5e 100644
--- a/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/Components.java
+++ b/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/Components.java
@@ -67,4 +67,8 @@
                 "START_ACTIVITY_FROM_FG_ACTIVITY_DELAY_MS_EXTRA";
     }
 
+    /** Extra key constants for {@link #APP_A_VIRTUAL_DISPLAY_RECEIVER} */
+    public static class VirtualDisplayReceiver {
+        public static final String USE_PUBLIC_PRESENTATION = "USE_PUBLIC_PRESENTATION";
+    }
 }
diff --git a/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/VirtualDisplayReceiver.java b/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/VirtualDisplayReceiver.java
index f445a17..829e073 100644
--- a/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/VirtualDisplayReceiver.java
+++ b/tests/framework/base/windowmanager/backgroundactivity/AppA/src/android/server/wm/backgroundactivity/appa/VirtualDisplayReceiver.java
@@ -30,7 +30,23 @@
 
     @Override
     public void onReceive(Context context, Intent intent) {
-        createVirtualDisplayAndShowPresentation(context);
+        boolean usePublicPresentation = intent.getBooleanExtra(
+                Components.VirtualDisplayReceiver.USE_PUBLIC_PRESENTATION, false);
+        if (usePublicPresentation) {
+            createPublicVirtualDisplayAndShowPresentation(context);
+        } else {
+            createVirtualDisplayAndShowPresentation(context);
+        }
+    }
+
+    private void createPublicVirtualDisplayAndShowPresentation(Context context) {
+        DisplayManager displayManager = context.getSystemService(DisplayManager.class);
+        VirtualDisplay virtualDisplay = displayManager.createVirtualDisplay(
+                "VirtualDisplay1", 10, 10, 10, null,
+                DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC
+                        + DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION
+                        + DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY);
+        new Presentation(context, virtualDisplay.getDisplay()).show();
     }
 
     private void createVirtualDisplayAndShowPresentation(Context context) {
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 fee76a0..36607e1 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
@@ -37,6 +37,7 @@
 import static android.server.wm.backgroundactivity.appa.Components.ForegroundActivity.START_ACTIVITY_FROM_FG_ACTIVITY_NEW_TASK_EXTRA;
 import static android.server.wm.backgroundactivity.appa.Components.SendPendingIntentReceiver.IS_BROADCAST_EXTRA;
 import static android.server.wm.backgroundactivity.appa.Components.StartBackgroundActivityReceiver.START_ACTIVITY_DELAY_MS_EXTRA;
+import static android.server.wm.backgroundactivity.appa.Components.VirtualDisplayReceiver.USE_PUBLIC_PRESENTATION;
 import static android.server.wm.backgroundactivity.appb.Components.APP_B_FOREGROUND_ACTIVITY;
 import static android.server.wm.backgroundactivity.common.CommonComponents.EVENT_NOTIFIER_EXTRA;
 import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
@@ -166,6 +167,24 @@
     }
 
     @Test
+    public void testBackgroundActivityBlocked_PublicVirtualDisplay() throws Exception {
+        mContext.sendBroadcast(new Intent().setComponent(APP_A_VIRTUAL_DISPLAY_RECEIVER)
+                .putExtra(USE_PUBLIC_PRESENTATION, true));
+        int TYPE_PRESENTATION = 2037; // constant is @hide
+        assertTrue(mWmState.waitFor((wmState) ->
+                wmState.getWindowByPackageName(APP_A_PACKAGE_NAME, TYPE_PRESENTATION)
+                        != null, "Private presentation was never created"));
+
+        // Start AppA background activity and blocked
+        Intent intent = new Intent();
+        intent.setComponent(APP_A_START_ACTIVITY_RECEIVER);
+        mContext.sendBroadcast(intent);
+        boolean result = waitForActivityFocused(APP_A_BACKGROUND_ACTIVITY);
+        assertFalse("Should not able to launch background activity", result);
+        assertTaskStack(null, APP_A_BACKGROUND_ACTIVITY);
+    }
+
+    @Test
     @FlakyTest(bugId = 155454710)
     public void testBackgroundActivityNotBlockedWithinGracePeriod() throws Exception {
         // Start AppA foreground activity