Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af3a400e authored by Bryce Lee's avatar Bryce Lee
Browse files

Do not defer wm display logic when called from am.

Currently we process any remove/add/change logic from the activity
manager to the window manager through a handler message. This opens
the possibility of the activity manager requesting display state
from a window manager that is a step behind.

This change modifies the call behavior so that these changes are done
synchronously between the two managers.

Change-Id: Icd19f37c62bfb7aad10fab2e1b21e41ac75052b5
Fixes: 35741135
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test CtsServicesHostTestCases android.server.cts.ActivityManagerDisplayTests#testCreateMultipleVirtualDisplaysH
parent 44277fbd
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -399,6 +399,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    /** Mapping from (ActivityStack/TaskStack).mStackId to their current state */
    SparseArray<ActivityContainer> mActivityContainers = new SparseArray<>();

    // TODO: There should be an ActivityDisplayController coordinating am/wm interaction.
    /** Mapping from displayId to display current state */
    private final SparseArray<ActivityDisplay> mActivityDisplays = new SparseArray<>();

@@ -3719,12 +3720,10 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                }
                mActivityDisplays.put(displayId, activityDisplay);
                calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay);
            }
        }
        if (newDisplay) {
                mWindowManager.onDisplayAdded(displayId);
            }
        }
    }

    /** Check if display with specified id is added to the list. */
    boolean isDisplayAdded(int displayId) {
@@ -3762,9 +3761,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                    }
                }
                mActivityDisplays.remove(displayId);
                mWindowManager.onDisplayRemoved(displayId);
            }
        }
        mWindowManager.onDisplayRemoved(displayId);
    }

    private void handleDisplayChanged(int displayId) {
@@ -3773,9 +3772,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            if (activityDisplay != null) {
                // TODO: Update the bounds.
            }
        }
            mWindowManager.onDisplayChanged(displayId);
        }
    }

    private StackInfo getStackInfoLocked(ActivityStack stack) {
        final ActivityDisplay display = mActivityDisplays.get(DEFAULT_DISPLAY);
@@ -4734,7 +4733,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D

            init(mVirtualDisplay.getDisplay());

            mWindowManager.handleDisplayAdded(mDisplayId);
            mWindowManager.onDisplayAdded(mDisplayId);
        }

        void setSurface(Surface surface) {
+13 −41
Original line number Diff line number Diff line
@@ -4634,10 +4634,6 @@ public class WindowManagerService extends IWindowManager.Stub
        public static final int SHOW_STRICT_MODE_VIOLATION = 25;
        public static final int DO_ANIMATION_CALLBACK = 26;

        public static final int DO_DISPLAY_ADDED = 27;
        public static final int DO_DISPLAY_REMOVED = 28;
        public static final int DO_DISPLAY_CHANGED = 29;

        public static final int CLIENT_FREEZE_TIMEOUT = 30;
        public static final int TAP_OUTSIDE_TASK = 31;
        public static final int NOTIFY_ACTIVITY_DRAWN = 32;
@@ -4981,22 +4977,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    break;
                }

                case DO_DISPLAY_ADDED:
                    handleDisplayAdded(msg.arg1);
                    break;

                case DO_DISPLAY_REMOVED:
                    synchronized (mWindowMap) {
                        handleDisplayRemovedLocked(msg.arg1);
                    }
                    break;

                case DO_DISPLAY_CHANGED:
                    synchronized (mWindowMap) {
                        handleDisplayChangedLocked(msg.arg1);
                    }
                    break;

                case TAP_OUTSIDE_TASK: {
                    handleTapOutsideTask((DisplayContent)msg.obj, msg.arg1, msg.arg2);
                }
@@ -6710,10 +6690,6 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    public void onDisplayAdded(int displayId) {
        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_ADDED, displayId, 0));
    }

    public void handleDisplayAdded(int displayId) {
        synchronized (mWindowMap) {
            final Display display = mDisplayManager.getDisplay(displayId);
            if (display != null) {
@@ -6725,10 +6701,7 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    public void onDisplayRemoved(int displayId) {
        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_REMOVED, displayId, 0));
    }

    private void handleDisplayRemovedLocked(int displayId) {
        synchronized (mWindowMap) {
            final DisplayContent displayContent = mRoot.getDisplayContentOrCreate(displayId);
            if (displayContent != null) {
                displayContent.removeIfPossible();
@@ -6736,18 +6709,17 @@ public class WindowManagerService extends IWindowManager.Stub
            mAnimator.removeDisplayLocked(displayId);
            mWindowPlacerLocked.requestTraversal();
        }

    public void onDisplayChanged(int displayId) {
        mH.sendMessage(mH.obtainMessage(H.DO_DISPLAY_CHANGED, displayId, 0));
    }

    private void handleDisplayChangedLocked(int displayId) {
    public void onDisplayChanged(int displayId) {
        synchronized (mWindowMap) {
            final DisplayContent displayContent = mRoot.getDisplayContentOrCreate(displayId);
            if (displayContent != null) {
                displayContent.updateDisplayInfo();
            }
            mWindowPlacerLocked.requestTraversal();
        }
    }

    @Override
    public Object getWindowManagerLock() {