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 Original line Diff line number Diff line
@@ -4149,8 +4149,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
     */
    void setInputMethodWindowLocked(WindowState win) {
    void setInputMethodWindowLocked(WindowState win) {
        mInputMethodWindow = win;
        mInputMethodWindow = win;
        mInsetsStateController.getImeSourceProvider().setWindowContainer(win,
        mInsetsStateController.getImeSourceProvider().setWindow(win,
                mDisplayPolicy.getImeSourceFrameProvider(), null);
                mDisplayPolicy.getImeSourceFrameProvider(), null /* overrideFrameProviders */);
        computeImeLayeringTarget(true /* update */);
        computeImeLayeringTarget(true /* update */);
        updateImeControlTarget(false /* forceUpdateImeParent */);
        updateImeControlTarget(false /* forceUpdateImeParent */);
    }
    }
+11 −16
Original line number Original line Diff line number Diff line
@@ -1205,11 +1205,11 @@ public class DisplayPolicy {
                // The index of the provider and corresponding insets types cannot change at
                // 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
                // runtime as ensured in WMS. Make use of the index in the provider directly
                // to access the latest provided size at runtime.
                // 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);
                        getFrameProvider(win, i, INSETS_OVERRIDE_INDEX_INVALID);
                final InsetsFrameProvider.InsetsSizeOverride[] overrides =
                final InsetsFrameProvider.InsetsSizeOverride[] overrides =
                        provider.getInsetsSizeOverrides();
                        provider.getInsetsSizeOverrides();
                final SparseArray<TriFunction<DisplayFrames, WindowContainer, Rect, Integer>>
                final SparseArray<TriFunction<DisplayFrames, WindowState, Rect, Integer>>
                        overrideProviders;
                        overrideProviders;
                if (overrides != null) {
                if (overrides != null) {
                    overrideProviders = new SparseArray<>();
                    overrideProviders = new SparseArray<>();
@@ -1224,15 +1224,16 @@ public class DisplayPolicy {
                        .getInsetsStateController().getOrCreateSourceProvider(provider.getId(),
                        .getInsetsStateController().getOrCreateSourceProvider(provider.getId(),
                                provider.getType());
                                provider.getType());
                sourceProvider.getSource().setFlags(provider.getFlags());
                sourceProvider.getSource().setFlags(provider.getFlags());
                sourceProvider.setWindowContainer(win, frameProvider, overrideProviders);
                sourceProvider.setWindow(win, frameProvider, overrideProviders);
                mInsetsSourceWindowsExceptIme.add(win);
                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) {
            WindowState win, int index, int overrideIndex) {
        return (displayFrames, windowContainer, inOutFrame) -> {
        return (displayFrames, windowState, inOutFrame) -> {
            final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
            final LayoutParams lp = win.mAttrs.forRotation(displayFrames.mRotation);
            final InsetsFrameProvider ifp = lp.providedInsets[index];
            final InsetsFrameProvider ifp = lp.providedInsets[index];
            final Rect displayFrame = displayFrames.mUnrestricted;
            final Rect displayFrame = displayFrames.mUnrestricted;
@@ -1243,7 +1244,7 @@ public class DisplayPolicy {
                    inOutFrame.set(displayFrame);
                    inOutFrame.set(displayFrame);
                    break;
                    break;
                case SOURCE_CONTAINER_BOUNDS:
                case SOURCE_CONTAINER_BOUNDS:
                    inOutFrame.set(windowContainer.getBounds());
                    inOutFrame.set(windowState.getBounds());
                    break;
                    break;
                case SOURCE_FRAME:
                case SOURCE_FRAME:
                    extendByCutout =
                    extendByCutout =
@@ -1304,13 +1305,9 @@ public class DisplayPolicy {
        }
        }
    }
    }


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

            inOutFrame.inset(windowState.mGivenContentInsets);
            inOutFrame.inset(windowState.mGivenContentInsets);
            return 0;
            return 0;
        };
        };
@@ -1339,9 +1336,7 @@ public class DisplayPolicy {
            final InsetsStateController controller = mDisplayContent.getInsetsStateController();
            final InsetsStateController controller = mDisplayContent.getInsetsStateController();
            for (int index = providers.size() - 1; index >= 0; index--) {
            for (int index = providers.size() - 1; index >= 0; index--) {
                final InsetsSourceProvider provider = providers.valueAt(index);
                final InsetsSourceProvider provider = providers.valueAt(index);
                provider.setWindowContainer(
                provider.setWindow(null /* win */, null /* frameProvider */,
                        null /* windowContainer */,
                        null /* frameProvider */,
                        null /* overrideFrameProviders */);
                        null /* overrideFrameProviders */);
                controller.removeSourceProvider(provider.getSource().getId());
                controller.removeSourceProvider(provider.getSource().getId());
            }
            }
+21 −33
Original line number Original line Diff line number Diff line
@@ -70,7 +70,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    private boolean mFrozen;
    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}.
     * {@link InsetsSourceProvider#mServerVisible} while {@link #mFrozen} is {@code true}.
     *
     *
     * @see #setServerVisible
     * @see #setServerVisible
@@ -85,7 +85,7 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
    private boolean mGivenInsetsReady = false;
    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
     * the IME (temporarily) redrawing  (e.g. during a rotation), to dispatch the control with
     * leash again after it has finished drawing.
     * leash again after it has finished drawing.
     */
     */
@@ -103,10 +103,8 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
        super.onPostLayout();
        super.onPostLayout();


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


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

File changed.

Preview size limit exceeded, changes collapsed.

+1 −60
Original line number Original line Diff line number Diff line
@@ -144,14 +144,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    @Nullable
    @Nullable
    SparseArray<InsetsSource> mLocalInsetsSources = null;
    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
     * The combined excluded insets types (combined mExcludeInsetsTypes and the
     * mMergedExcludeInsetsTypes from its parent)
     * 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#mMergedLocalInsetsSources} by visiting the entire hierarchy.
     *
     *
     * {@link WindowState#mAboveInsetsState} is updated by visiting all the windows in z-order
     * {@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.
     * provided by the {@link WindowState}s at the top.
     * {@link WindowState#updateAboveInsetsState(InsetsState, SparseArray, ArraySet)} visits the
     * {@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
     * 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;
        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
     * Sets the excludeInsetsTypes of this window and updates the mMergedExcludeInsetsTypes of
     * all child nodes in the hierarchy.
     * 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() {
    public final DisplayContent getDisplayContent() {
        return mDisplayContent;
        return mDisplayContent;
    }
    }
@@ -1176,9 +1133,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
    }
    }


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


    void onMovedByResize() {
    void onMovedByResize() {
        if (mControllableInsetProvider != null) {
            mControllableInsetProvider.onWindowContainerBoundsChanged();
        }
        for (int i = mChildren.size() - 1; i >= 0; --i) {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final WindowContainer wc = mChildren.get(i);
            final WindowContainer wc = mChildren.get(i);
            wc.onMovedByResize();
            wc.onMovedByResize();
@@ -3047,16 +2998,6 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
        scheduleAnimation();
        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) {
    void reassignLayer(Transaction t) {
        final WindowContainer parent = getParent();
        final WindowContainer parent = getParent();
        if (parent != null) {
        if (parent != null) {
Loading