Restore window to undefined instead of freeform windowing mode

On freeform display, this will act in the exact same way as before. When
click the restore button to switch windowing mode, it will get into
freeform windowing mode.

This patch makes a difference when the display runtime changes from
freeform to fullscreen. If the window restored to undefined, when the
runtime change happens, it can properly match the parent's windowing
mode. Otherwise, we will see a freeform window on fullscreen display
without any explicit user action.

Bug: 128853293
Test: manual
Test: go/wm-smoke
Change-Id: I12480dedbdea3da65f7fa925eed0fa5664c76f5b
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 3fa0268..3cab3d8 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -3372,6 +3372,11 @@
 
                 if (stack.inFreeformWindowingMode()) {
                     stack.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
+                } else if (stack.getParent().inFreeformWindowingMode()) {
+                    // If the window is on a freeform display, set it to undefined. It will be
+                    // resolved to freeform and it can adjust windowing mode when the display mode
+                    // changes in runtime.
+                    stack.setWindowingMode(WINDOWING_MODE_UNDEFINED);
                 } else {
                     stack.setWindowingMode(WINDOWING_MODE_FREEFORM);
                 }