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

Commit 45477b57 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Fix issue with where display is removed while creating it in AM and WM

It is possible to a display to be removed while we are in the ctor of
ActivityDisplay in AM, but before we can get the Display object in the
ctor of DisplayWindowController in WM. This causes us to throw an
exception becuase the caller is trying to add a display we can't find in
display manager. Unfortunately there isn't a good way to handle this race.
To work around it we will now pass the Display object from AM to WM to use
and depend on the fact that AM will remove the display shortly after.

Change-Id: Ie3f9d86bad67f5a023e3e7dfce5219b98c796864
Fixes: 72893961
Test: go/wm-smoke
parent d7cf0e16
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -106,21 +106,21 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>

    private DisplayWindowController mWindowContainerController;

    @VisibleForTesting
    ActivityDisplay(ActivityStackSupervisor supervisor, int displayId) {
        mSupervisor = supervisor;
        mDisplayId = displayId;
        final Display display = supervisor.mDisplayManager.getDisplay(displayId);
        if (display == null) {
            throw new IllegalStateException("Display does not exist displayId=" + displayId);
        this(supervisor, supervisor.mDisplayManager.getDisplay(displayId));
    }

    ActivityDisplay(ActivityStackSupervisor supervisor, Display display) {
        mSupervisor = supervisor;
        mDisplayId = display.getDisplayId();
        mDisplay = display;
        mWindowContainerController = createWindowContainerController();

        updateBounds();
    }

    protected DisplayWindowController createWindowContainerController() {
        return new DisplayWindowController(mDisplayId, this);
        return new DisplayWindowController(mDisplay, this);
    }

    void updateBounds() {
+4 −4
Original line number Diff line number Diff line
@@ -652,9 +652,9 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D

            Display[] displays = mDisplayManager.getDisplays();
            for (int displayNdx = displays.length - 1; displayNdx >= 0; --displayNdx) {
                final int displayId = displays[displayNdx].getDisplayId();
                ActivityDisplay activityDisplay = new ActivityDisplay(this, displayId);
                mActivityDisplays.put(displayId, activityDisplay);
                final Display display = displays[displayNdx];
                ActivityDisplay activityDisplay = new ActivityDisplay(this, display);
                mActivityDisplays.put(display.getDisplayId(), activityDisplay);
                calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay);
            }

@@ -4085,7 +4085,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            return null;
        }
        // The display hasn't been added to ActivityManager yet, create a new record now.
        activityDisplay = new ActivityDisplay(this, displayId);
        activityDisplay = new ActivityDisplay(this, display);
        attachDisplay(activityDisplay);
        calculateDefaultMinimalSizeOfResizeableTasks(activityDisplay);
        mWindowManager.onDisplayAdded(displayId);
+9 −13
Original line number Diff line number Diff line
@@ -34,25 +34,21 @@ public class DisplayWindowController

    private final int mDisplayId;

    public DisplayWindowController(int displayId, WindowContainerListener listener) {
    public DisplayWindowController(Display display, WindowContainerListener listener) {
        super(listener, WindowManagerService.getInstance());
        mDisplayId = displayId;
        mDisplayId = display.getDisplayId();

        synchronized (mWindowMap) {
            final Display display = mService.mDisplayManager.getDisplay(displayId);
            if (display != null) {
            final long callingIdentity = Binder.clearCallingIdentity();
            try {
                mRoot.createDisplayContent(display, this /* controller */);
            } finally {
                Binder.restoreCallingIdentity(callingIdentity);
            }
            }

            if (mContainer == null) {
                throw new IllegalArgumentException("Trying to add displayId=" + displayId
                        + " display=" + display
                        + " dc=" + mRoot.getDisplayContent(displayId));
                throw new IllegalArgumentException("Trying to add display=" + display
                        + " dc=" + mRoot.getDisplayContent(mDisplayId));
            }
        }
    }