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

Commit bde15130 authored by lumark's avatar lumark
Browse files

Call WC#onDisplayChanged in setParent

WC#mDisplayContent will update when received from WC#onDisplayChanged.

Currently, for Task#mDisplayContent, will update when its stack position change,
or the Task reparented to new display,
but for new activity launch flow, it won't receive onDisplayChanged callback
for the Task,

because before the Task added the stack, the stack has already called
onDisplayChanged when it created and added into TaskStackContainer.

The fix is add a check in WC#setParent to see if the display of new parent is
is same as the current one, if not, calling onDisplayChanged to update
the display from the new parent.

Also, add a unit-test to test this scenerio.

Bug: 142617871
Test: atest WindowContainerTests#testOnDisplayChanged TaskTests \
      TaskStackTests

Change-Id: I84c91dc63508b270a3576335bc9c8a005b72eba6
parent c9b6967e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1176,7 +1176,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            // First time we are adding the activity to the system.
            mVoiceInteraction = newTask.voiceSession != null;
            mInputDispatchingTimeoutNanos = getInputDispatchingTimeoutLocked(this) * 1000000L;
            onDisplayChanged(task.getDisplayContent());

            // TODO(b/36505427): Maybe this call should be moved inside
            // updateOverrideConfiguration()
            newTask.updateOverrideConfigurationFromLaunchBounds();
+1 −5
Original line number Diff line number Diff line
@@ -728,7 +728,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
    }

    ActivityStack(DisplayContent display, int stackId, ActivityStackSupervisor supervisor,
            int windowingMode, int activityType, boolean onTop) {
            int activityType) {
        super(supervisor.mService.mWindowManager);
        mStackId = stackId;
        mDockedStackMinimizeThickness =
@@ -746,10 +746,6 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
        // stacks on a wrong display.
        mDisplayId = display.mDisplayId;
        setActivityType(activityType);
        display.addStack(this, onTop ? POSITION_TOP : POSITION_BOTTOM);
        setWindowingMode(windowingMode, false /* animate */, false /* showRecents */,
                false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */,
                true /* creating */);
    }

    /**
+14 −4
Original line number Diff line number Diff line
@@ -1084,7 +1084,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return token.asActivityRecord();
    }

    private void addWindowToken(IBinder binder, WindowToken token) {
    void addWindowToken(IBinder binder, WindowToken token) {
        final DisplayContent dc = mWmService.mRoot.getWindowTokenDisplay(token);
        if (dc != null) {
            // We currently don't support adding a window token to the display if the display
@@ -1106,6 +1106,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        mTokenMap.put(binder, token);

        if (token.asActivityRecord() == null) {
            // Set displayContent for non-app token to prevent same token will add twice after
            // onDisplayChanged.
            // TODO: Check if it's fine that super.onDisplayChanged of WindowToken
            //  (WindowsContainer#onDisplayChanged) may skipped when token.mDisplayContent assigned.
            token.mDisplayContent = this;
            // Add non-app token to container hierarchy on the display. App tokens are added through
            // the parent container managing them (e.g. Tasks).
            switch (token.windowType) {
@@ -4278,7 +4283,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            // The reparenting case is handled in WindowContainer.
            if (!stack.mReparenting) {
                setLayoutNeeded();
                stack.onDisplayChanged(DisplayContent.this);
            }
        }

@@ -5736,8 +5740,14 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            throw new IllegalArgumentException("Stack with windowing mode cannot with non standard "
                    + "activity type.");
        }
        return new ActivityStack(this, stackId, mRootActivityContainer.mStackSupervisor,
                windowingMode, activityType, onTop);
        final ActivityStack stack = new ActivityStack(this, stackId,
                mRootActivityContainer.mStackSupervisor, activityType);
        addStack(stack, onTop ? POSITION_TOP : POSITION_BOTTOM);
        stack.setWindowingMode(windowingMode, false /* animate */, false /* showRecents */,
                false /* enteringSplitScreenMode */, false /* deferEnsuringVisibility */,
                true /* creating */);

        return stack;
    }

    /**
+4 −0
Original line number Diff line number Diff line
@@ -315,6 +315,10 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
            mParent.onChildAdded(this);
        }
        if (!mReparenting) {
            if (mParent != null && mParent.mDisplayContent != null
                    && mDisplayContent != mParent.mDisplayContent) {
                onDisplayChanged(mParent.mDisplayContent);
            }
            onParentChanged(mParent, oldParent);
        }
    }
+7 −3
Original line number Diff line number Diff line
@@ -797,9 +797,6 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            mSubLayer = mPolicy.getSubWindowLayerFromTypeLw(a.type);
            mIsChildWindow = true;

            ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow);
            parentWindow.addChild(this, sWindowSubLayerComparator);

            mLayoutAttached = mAttrs.type !=
                    WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
            mIsImWindow = parentWindow.mAttrs.type == TYPE_INPUT_METHOD
@@ -836,6 +833,13 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        mInputWindowHandle = new InputWindowHandle(
                mActivityRecord != null ? mActivityRecord.mInputApplicationHandle : null,
                    getDisplayId());

        // Make sure we initial all fields before adding to parentWindow, to prevent exception
        // during onDisplayChanged.
        if (mIsChildWindow) {
            ProtoLog.v(WM_DEBUG_ADD_REMOVE, "Adding %s to %s", this, parentWindow);
            parentWindow.addChild(this, sWindowSubLayerComparator);
        }
    }

    void attach() {
Loading