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

Commit 6e3b3b84 authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "Use WindowState for InsetsSourceProvider" into main

parents 52784190 e1b363d5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4149,8 +4149,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    void setInputMethodWindowLocked(WindowState win) {
        mInputMethodWindow = win;
        mInsetsStateController.getImeSourceProvider().setWindowContainer(win,
                mDisplayPolicy.getImeSourceFrameProvider(), null);
        mInsetsStateController.getImeSourceProvider().setWindow(win,
                mDisplayPolicy.getImeSourceFrameProvider(), null /* overrideFrameProviders */);
        computeImeLayeringTarget(true /* update */);
        updateImeControlTarget(false /* forceUpdateImeParent */);
    }
+11 −16
Original line number Diff line number Diff line
@@ -1205,11 +1205,11 @@ public class DisplayPolicy {
                // The index of the provider and corresponding insets types cannot change at
                // runtime as ensured in WMS. Make use of the index in the provider directly
                // to access the latest provided size at runtime.
                final TriFunction<DisplayFrames, WindowContainer, Rect, Integer> frameProvider =
                final TriFunction<DisplayFrames, WindowState, Rect, Integer> frameProvider =
                        getFrameProvider(win, i, INSETS_OVERRIDE_INDEX_INVALID);
                final InsetsFrameProvider.InsetsSizeOverride[] overrides =
                        provider.getInsetsSizeOverrides();
                final SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
                final SparseArray<TriFunction<DisplayFrames, WindowState, Rect, Integer>>
                        overrideProviders;
                if (overrides != null) {
                    overrideProviders = new SparseArray<>();
@@ -1224,15 +1224,16 @@ public class DisplayPolicy {
                        .getInsetsStateController().getOrCreateSourceProvider(provider.getId(),
                                provider.getType());
                sourceProvider.getSource().setFlags(provider.getFlags());
                sourceProvider.setWindowContainer(win, frameProvider, overrideProviders);
                sourceProvider.setWindow(win, frameProvider, overrideProviders);
                mInsetsSourceWindowsExceptIme.add(win);
            }
        }
    }

    private static TriFunction<DisplayFrames, WindowContainer, Rect, Integer> getFrameProvider(
    @NonNull
    private static TriFunction<DisplayFrames, WindowState, Rect, Integer> getFrameProvider(
            WindowState win, int index, int overrideIndex) {
        return (displayFrames, windowContainer, inOutFrame) -> {
        return (displayFrames, windowState, inOutFrame) -> {
            final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
            final InsetsFrameProvider ifp = lp.providedInsets[index];
            final Rect displayFrame = displayFrames.mUnrestricted;
@@ -1243,7 +1244,7 @@ public class DisplayPolicy {
                    inOutFrame.set(displayFrame);
                    break;
                case SOURCE_CONTAINER_BOUNDS:
                    inOutFrame.set(windowContainer.getBounds());
                    inOutFrame.set(windowState.getBounds());
                    break;
                case SOURCE_FRAME:
                    extendByCutout =
@@ -1304,13 +1305,9 @@ public class DisplayPolicy {
        }
    }

    TriFunction<DisplayFrames, WindowContainer, Rect, Integer> getImeSourceFrameProvider() {
        return (displayFrames, windowContainer, inOutFrame) -> {
            WindowState windowState = windowContainer.asWindowState();
            if (windowState == null) {
                throw new IllegalArgumentException("IME insets must be provided by a window.");
            }

    @NonNull
    TriFunction<DisplayFrames, WindowState, Rect, Integer> getImeSourceFrameProvider() {
        return (displayFrames, windowState, inOutFrame) -> {
            inOutFrame.inset(windowState.mGivenContentInsets);
            return 0;
        };
@@ -1339,9 +1336,7 @@ public class DisplayPolicy {
            final InsetsStateController controller = mDisplayContent.getInsetsStateController();
            for (int index = providers.size() - 1; index >= 0; index--) {
                final InsetsSourceProvider provider = providers.valueAt(index);
                provider.setWindowContainer(
                        null /* windowContainer */,
                        null /* frameProvider */,
                provider.setWindow(null /* win */, null /* frameProvider */,
                        null /* overrideFrameProviders */);
                controller.removeSourceProvider(provider.getSource().getId());
            }
+21 −33
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    private boolean mFrozen;

    /**
     * The server visibility of the source provider's window container. This is out of sync with
     * The server visibility of the source provider's window. This is out of sync with
     * {@link InsetsSourceProvider#mServerVisible} while {@link #mFrozen} is {@code true}.
     *
     * @see #setServerVisible
@@ -85,7 +85,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    private boolean mGivenInsetsReady = false;

    /**
     * The last state of the windowContainer. This is used to reset server visibility, in case of
     * The last drawn state of the window. This is used to reset server visibility, in case of
     * the IME (temporarily) redrawing  (e.g. during a rotation), to dispatch the control with
     * leash again after it has finished drawing.
     */
@@ -103,10 +103,8 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        super.onPostLayout();

        if (android.view.inputmethod.Flags.refactorInsetsController()) {
            final WindowState ws =
                    mWindowContainer != null ? mWindowContainer.asWindowState() : null;
            final boolean givenInsetsPending = ws != null && ws.mGivenInsetsPending;
            mLastDrawn = ws != null && ws.isDrawn();
            final boolean givenInsetsPending = mWin != null && mWin.mGivenInsetsPending;
            mLastDrawn = mWin != null && mWin.isDrawn();

            // isLeashReadyForDispatching (used to dispatch the leash of the control) is
            // depending on mGivenInsetsReady. Therefore, triggering notifyControlChanged here
@@ -158,9 +156,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            // 1. parent isLeashReadyForDispatching, 2. mGivenInsetsReady (means there are no
            // givenInsetsPending), 3. the IME surface is drawn, 4. either the IME is
            // serverVisible (the unfrozen state)
            final WindowState ws =
                    mWindowContainer != null ? mWindowContainer.asWindowState() : null;
            final boolean isDrawn = ws != null && ws.isDrawn();
            final boolean isDrawn = mWin != null && mWin.isDrawn();
            return super.isLeashReadyForDispatching()
                    && isServerVisible() && isDrawn && mGivenInsetsReady;
        } else {
@@ -176,14 +172,13 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    protected boolean isSurfaceVisible() {
        final boolean isSurfaceVisible = super.isSurfaceVisible();
        if (android.view.inputmethod.Flags.refactorInsetsController()) {
            final WindowState windowState = mWindowContainer.asWindowState();
            if (mControl != null && windowState != null) {
                final boolean isDrawn = windowState.isDrawn();
            if (mControl != null) {
                final boolean isDrawn = mWin != null && mWin.isDrawn();
                if (!isServerVisible() && isSurfaceVisible) {
                    // In case the IME becomes visible, we need to check if it is already drawn and
                    // does not have given insets pending. If it's not yet drawn, we do not set
                    // server visibility
                    return isDrawn && !windowState.mGivenInsetsPending;
                    return isDrawn && !mWin.mGivenInsetsPending;
                } else if (mLastDrawn && !isDrawn) {
                    // If the IME was drawn before, but is not drawn anymore, we need to reset
                    // server visibility, which will also reset {@link
@@ -507,11 +502,10 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        if (callerWindow == null) {
            return;
        }
        WindowToken imeToken = mWindowContainer.asWindowState() != null
                ? mWindowContainer.asWindowState().mToken : null;
        final WindowToken imeToken = mWin != null ? mWin.mToken : null;
        final var rotationController = mDisplayContent.getAsyncRotationController();
        if ((rotationController != null && rotationController.isTargetToken(imeToken)) || (
                imeToken != null && imeToken.isSelfAnimating(0 /* flags */,
        if ((rotationController != null && rotationController.isTargetToken(imeToken))
                || (imeToken != null && imeToken.isSelfAnimating(0 /* flags */,
                    SurfaceAnimator.ANIMATION_TYPE_TOKEN_TRANSFORM))) {
            // Skip reporting IME drawn state when the control target is in fixed
            // rotation, AsyncRotationController will report after the animation finished.
@@ -526,7 +520,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            return;
        }
        if (callerWindow.getTask().isOrganized()) {
            mWindowContainer.mWmService.mAtmService.mTaskOrganizerController
            mWin.mWmService.mAtmService.mTaskOrganizerController
                    .reportImeDrawnOnTask(caller.getWindow().getTask());
        }
    }
@@ -661,19 +655,15 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            return false;
        }
        if (!mServerVisible || mFrozen) {
            // The window container is not available and considered visible.
            // The window is not available and considered visible.
            // If frozen, the server visibility is not set until unfrozen.
            return false;
        }
        if (mWindowContainer == null) {
            // No window container set.
        if (mWin == null) {
            // No window set.
            return false;
        }
        final WindowState windowState = mWindowContainer.asWindowState();
        if (windowState == null) {
            throw new IllegalArgumentException("IME insets must be provided by a window.");
        }
        if (!windowState.isDrawn() || windowState.mGivenInsetsPending) {
        if (!mWin.isDrawn() || mWin.mGivenInsetsPending) {
            // The window is not drawn, or it has pending insets.
            return false;
        }
@@ -745,7 +735,6 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
     * @param aborted whether the scheduled show IME request was aborted or cancelled.
     */
    private void logIsScheduledAndReadyToShowIme(boolean aborted) {
        final var windowState = mWindowContainer != null ? mWindowContainer.asWindowState() : null;
        final var imeLayeringTarget = mDisplayContent.getImeLayeringTarget();
        final var controlTarget = getControlTarget();
        final var sb = new StringBuilder();
@@ -754,11 +743,10 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        sb.append(", mImeRequester: ").append(mImeRequester);
        sb.append(", serverVisible: ").append(mServerVisible);
        sb.append(", frozen: ").append(mFrozen);
        sb.append(", mWindowContainer is: ").append(mWindowContainer != null ? "non-null" : "null");
        sb.append(", windowState: ").append(windowState);
        if (windowState != null) {
            sb.append(", isDrawn: ").append(windowState.isDrawn());
            sb.append(", mGivenInsetsPending: ").append(windowState.mGivenInsetsPending);
        sb.append(", mWin is: ").append(mWin != null ? "non-null" : "null");
        if (mWin != null) {
            sb.append(", isDrawn: ").append(mWin.isDrawn());
            sb.append(", mGivenInsetsPending: ").append(mWin.mGivenInsetsPending);
        }
        sb.append(", imeLayeringTarget: ").append(imeLayeringTarget);
        sb.append(", controlTarget: ").append(controlTarget);
+69 −105

File changed.

Preview size limit exceeded, changes collapsed.

+1 −60
Original line number Diff line number Diff line
@@ -144,14 +144,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    @Nullable
    SparseArray<InsetsSource> mLocalInsetsSources = null;

    @Nullable
    protected InsetsSourceProvider mControllableInsetProvider;

    /**
     * The {@link InsetsSourceProvider}s provided by this window container.
     */
    protected SparseArray<InsetsSourceProvider> mInsetsSourceProviders = null;

    /**
     * The combined excluded insets types (combined mExcludeInsetsTypes and the
     * mMergedExcludeInsetsTypes from its parent)
@@ -328,7 +320,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
     * {@link WindowState#mMergedLocalInsetsSources} by visiting the entire hierarchy.
     *
     * {@link WindowState#mAboveInsetsState} is updated by visiting all the windows in z-order
     * top-to-bottom manner and considering the {@link WindowContainer#mInsetsSourceProviders}
     * top-to-bottom manner and considering the {@link WindowState#mInsetsSourceProviders}
     * provided by the {@link WindowState}s at the top.
     * {@link WindowState#updateAboveInsetsState(InsetsState, SparseArray, ArraySet)} visits the
     * IME container in the correct order to make sure the IME insets are passed correctly to the
@@ -512,24 +504,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        return true;
    }

    /**
     * Sets an {@link InsetsSourceProvider} to be associated with this {@code WindowContainer},
     * but only if the provider itself is controllable, as one window can be the provider of more
     * than one inset type (i.e. gesture insets). If this {code WindowContainer} is controllable,
     * all its animations must be controlled by its control target, and the visibility of this
     * {code WindowContainer} should be taken account into the state of the control target.
     *
     * @param insetProvider the provider which should not be visible to the client.
     * @see WindowState#getInsetsState()
     */
    void setControllableInsetProvider(InsetsSourceProvider insetProvider) {
        mControllableInsetProvider = insetProvider;
    }

    InsetsSourceProvider getControllableInsetProvider() {
        return mControllableInsetProvider;
    }

    /**
     * Sets the excludeInsetsTypes of this window and updates the mMergedExcludeInsetsTypes of
     * all child nodes in the hierarchy.
@@ -1129,23 +1103,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        }
    }

    /**
     * Returns {@code true} if this node provides insets.
     */
    public boolean hasInsetsSourceProvider() {
        return mInsetsSourceProviders != null;
    }

    /**
     * Returns {@link InsetsSourceProvider}s provided by this node.
     */
    public SparseArray<InsetsSourceProvider> getInsetsSourceProviders() {
        if (mInsetsSourceProviders == null) {
            mInsetsSourceProviders = new SparseArray<>();
        }
        return mInsetsSourceProviders;
    }

    public final DisplayContent getDisplayContent() {
        return mDisplayContent;
    }
@@ -1176,9 +1133,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    }

    void onResize() {
        if (mControllableInsetProvider != null) {
            mControllableInsetProvider.onWindowContainerBoundsChanged();
        }
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            wc.onParentResize();
@@ -1198,9 +1152,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    }

    void onMovedByResize() {
        if (mControllableInsetProvider != null) {
            mControllableInsetProvider.onWindowContainerBoundsChanged();
        }
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            wc.onMovedByResize();
@@ -3047,16 +2998,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        scheduleAnimation();
    }

    void transformFrameToSurfacePosition(int left, int top, Point outPoint) {
        outPoint.set(left, top);
        final WindowContainer parentWindowContainer = getParent();
        if (parentWindowContainer == null) {
            return;
        }
        final Rect parentBounds = parentWindowContainer.getBounds();
        outPoint.offset(-parentBounds.left, -parentBounds.top);
    }

    void reassignLayer(Transaction t) {
        final WindowContainer parent = getParent();
        if (parent != null) {
Loading