Pass in window layout when setting initial state.

The bounds returned here may affect result later, but we didn't pass in
all information we have at this moment.

Also stop inferring freeform windowing mode if activity is resizeable
and specified layout bounds or activity option bounds, because these
activities may be launched in freeform mode accidentally on primary
displays.

Bug: 113252871
Test: Apps with layout can be launched correct on external displays,
e.g. Calculator. It still launches in fullscreen on primary display.
atest FrameworksServicesTests:TaskLaunchParamsModifierTests
atest FrameworksServicesTests:ActivityStarterTests
go/wm-smoke.

Change-Id: If19122c1c0d010df5d69a14a867c7bb2f37bd461
diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java b/services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java
index bac4a52..5c01fac 100644
--- a/services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/ActivityStarterTests.java
@@ -408,8 +408,9 @@
                 .setActivityOptions(new SafeActivityOptions(options))
                 .execute();
 
-        // verify that values are passed to the modifier.
-        verify(modifier, times(1)).onCalculate(any(), eq(windowLayout), any(), any(), eq(options),
+        // verify that values are passed to the modifier. Values are passed twice -- once for
+        // setting initial state, another when task is created.
+        verify(modifier, times(2)).onCalculate(any(), eq(windowLayout), any(), any(), eq(options),
                 any(), any());
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/am/TaskLaunchParamsModifierTests.java b/services/tests/servicestests/src/com/android/server/am/TaskLaunchParamsModifierTests.java
index 0d1302f..ea1320c 100644
--- a/services/tests/servicestests/src/com/android/server/am/TaskLaunchParamsModifierTests.java
+++ b/services/tests/servicestests/src/com/android/server/am/TaskLaunchParamsModifierTests.java
@@ -189,7 +189,7 @@
         assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, /* layout */ null,
                 mActivity, /* source */ null, options, mCurrent, mResult));
 
-        assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
+        assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
                 WINDOWING_MODE_FULLSCREEN);
     }
 
@@ -277,7 +277,7 @@
     }
 
     @Test
-    public void testNonEmptyLayoutInfersFreeformWithResizeableActivity() {
+    public void testNonEmptyLayoutUsesFullscreenWithResizeableActivity() {
         final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
                 .setWidth(120).setHeight(80).build();
 
@@ -286,7 +286,7 @@
         assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
                 /* source */ null, /* options */ null, mCurrent, mResult));
 
-        assertEquivalentWindowingMode(WINDOWING_MODE_FREEFORM, mResult.mWindowingMode,
+        assertEquivalentWindowingMode(WINDOWING_MODE_FULLSCREEN, mResult.mWindowingMode,
                 WINDOWING_MODE_FULLSCREEN);
     }
 
@@ -713,21 +713,6 @@
     }
 
     @Test
-    public void testNonEmptyLayoutBoundsWithResizeableActivity() {
-        final ActivityDisplay display = mSupervisor.getActivityDisplay(DEFAULT_DISPLAY);
-        display.setBounds(new Rect(0, 0, 1920, 1080));
-        final ActivityInfo.WindowLayout layout = new WindowLayoutBuilder()
-                .setWidth(120).setHeight(80).build();
-
-        mCurrent.mPreferredDisplayId = DEFAULT_DISPLAY;
-
-        assertEquals(RESULT_CONTINUE, mTarget.onCalculate(/* task */ null, layout, mActivity,
-                /* source */ null, /* options */ null, mCurrent, mResult));
-
-        assertEquals(new Rect(900, 500, 1020, 580), mResult.mBounds);
-    }
-
-    @Test
     public void testRespectBoundsFromFullyResolvedCurrentParam_NonEmptyBounds() {
         final TestActivityDisplay freeformDisplay = createNewActivityDisplay(
                 WINDOWING_MODE_FREEFORM);