Get the latest display info for overlay change

LocalDisplayAdapter.LocalDisplayDevice#updateDeviceInfoLocked
posts to display thread when receiving onOverlayChanged. So
the operation depends on it should run sequentially.

This partial relands commit 08a3049 to make sure that the display
info can include the latest cutout info after changing the cutout
overlay resources. The reconfigureDisplayLocked in previous commit
is not called in this change because that will require to fix
configuration calculation according to decor windows that provide
display config related insets.

Bug: 222572231
Bug: 240961743
Test: Toggle different types of cutout in developer options,
      the cutout change should be applied immediately on screen.
Change-Id: I393c7b2c2e95eabc21123b7c95c760323a5386ec
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index 14e2241..565d5cc 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -1882,8 +1882,10 @@
     /**
      * Called when the resource overlays change.
      */
-    public void onOverlayChangedLw() {
+    void onOverlayChanged() {
         updateCurrentUserResources();
+        // Update the latest display size, cutout.
+        mDisplayContent.updateDisplayInfo();
         onConfigurationChanged();
         mSystemGestures.onConfigurationChanged();
     }
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 08c4732..296390a 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -7046,13 +7046,14 @@
     }
 
     public void onOverlayChanged() {
-        synchronized (mGlobalLock) {
-            mRoot.forAllDisplays(displayContent -> {
-                displayContent.getDisplayPolicy().onOverlayChangedLw();
-                displayContent.updateDisplayInfo();
-            });
-            requestTraversal();
-        }
+        // Post to display thread so it can get the latest display info.
+        mH.post(() -> {
+            synchronized (mGlobalLock) {
+                mAtmService.deferWindowLayout();
+                mRoot.forAllDisplays(dc -> dc.getDisplayPolicy().onOverlayChanged());
+                mAtmService.continueWindowLayout();
+            }
+        });
     }
 
     @Override