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

Commit a0fa5e68 authored by Tiger Huang's avatar Tiger Huang Committed by Automerger Merge Worker
Browse files

Merge "Push the frame to InsetsSourceProvider" into tm-dev am: 017ebacd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17252604

Change-Id: I2866433f3798176d82a2614fbaabadb31b41ae11
parents 7574087d 017ebacd
Loading
Loading
Loading
Loading
+26 −24
Original line number Original line Diff line number Diff line
@@ -114,6 +114,7 @@ import android.os.UserHandle;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.PrintWriterPrinter;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseArray;
import android.view.DisplayCutout;
import android.view.DisplayCutout;
import android.view.DisplayInfo;
import android.view.DisplayInfo;
import android.view.Gravity;
import android.view.Gravity;
@@ -1151,9 +1152,8 @@ public class DisplayPolicy {
                            }
                            }
                        },
                        },


                        // For IME we use regular frame.
                        (displayFrames, windowContainer, inOutFrame) -> {
                        (displayFrames, windowContainer, inOutFrame) -> {
                            inOutFrame.set(win.getFrame());
                            // For IME, we don't modify the frame.
                        });
                        });


                mDisplayContent.setInsetProvider(ITYPE_BOTTOM_MANDATORY_GESTURES, win,
                mDisplayContent.setInsetProvider(ITYPE_BOTTOM_MANDATORY_GESTURES, win,
@@ -1488,9 +1488,30 @@ public class DisplayPolicy {
                    displayFrames.mInsetsState, displayFrames.mDisplayCutoutSafe,
                    displayFrames.mInsetsState, displayFrames.mDisplayCutoutSafe,
                    displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
                    displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
                    UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
                    UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
                    null /* attachedWindowFrame */, win.mGlobalScale,
                    null /* attachedWindowFrame */, win.mGlobalScale, sTmpClientFrames);
                    sTmpClientFrames);
            final SparseArray<InsetsSource> sources = win.getProvidedInsetsSources();
            controller.computeSimulatedState(win, displayFrames, sTmpClientFrames.frame);
            final InsetsState state = displayFrames.mInsetsState;
            for (int index = sources.size() - 1; index >= 0; index--) {
                final int type = sources.keyAt(index);
                state.addSource(controller.getSourceProvider(type).createSimulatedSource(
                        displayFrames, sTmpClientFrames.frame));
            }
        }
    }

    // TODO(b/161810301): No one is calling this since we haven't moved window layout to the client.
    //                    When that happens, this should be called when the display rotation is
    //                    changed, so that we can dispatch the correct insets to all the clients
    //                    before the insets source windows report their frames to the server.
    void updateInsetsSourceFramesExceptIme(DisplayFrames displayFrames) {
        for (int i = mInsetsSourceWindowsExceptIme.size() - 1; i >= 0; i--) {
            final WindowState win = mInsetsSourceWindowsExceptIme.valueAt(i);
            mWindowLayout.computeFrames(win.getLayoutingAttrs(displayFrames.mRotation),
                    displayFrames.mInsetsState, displayFrames.mDisplayCutoutSafe,
                    displayFrames.mUnrestricted, win.getWindowingMode(), UNSPECIFIED_LENGTH,
                    UNSPECIFIED_LENGTH, win.getRequestedVisibilities(),
                    null /* attachedWindowFrame */, win.mGlobalScale, sTmpClientFrames);
            win.updateSourceFrame(sTmpClientFrames.frame);
        }
        }
    }
    }


@@ -1519,10 +1540,6 @@ public class DisplayPolicy {
        displayFrames = win.getDisplayFrames(displayFrames);
        displayFrames = win.getDisplayFrames(displayFrames);


        final WindowManager.LayoutParams attrs = win.getLayoutingAttrs(displayFrames.mRotation);
        final WindowManager.LayoutParams attrs = win.getLayoutingAttrs(displayFrames.mRotation);
        final WindowFrames windowFrames = win.getWindowFrames();
        final Rect pf = windowFrames.mParentFrame;
        final Rect df = windowFrames.mDisplayFrame;
        final Rect f = windowFrames.mFrame;
        final Rect attachedWindowFrame = attached != null ? attached.getFrame() : null;
        final Rect attachedWindowFrame = attached != null ? attached.getFrame() : null;


        // If this window has different LayoutParams for rotations, we cannot trust its requested
        // If this window has different LayoutParams for rotations, we cannot trust its requested
@@ -1531,25 +1548,10 @@ public class DisplayPolicy {
        final int requestedWidth = trustedSize ? win.mRequestedWidth : UNSPECIFIED_LENGTH;
        final int requestedWidth = trustedSize ? win.mRequestedWidth : UNSPECIFIED_LENGTH;
        final int requestedHeight = trustedSize ? win.mRequestedHeight : UNSPECIFIED_LENGTH;
        final int requestedHeight = trustedSize ? win.mRequestedHeight : UNSPECIFIED_LENGTH;


        sTmpLastParentFrame.set(pf);

        mWindowLayout.computeFrames(attrs, win.getInsetsState(), displayFrames.mDisplayCutoutSafe,
        mWindowLayout.computeFrames(attrs, win.getInsetsState(), displayFrames.mDisplayCutoutSafe,
                win.getBounds(), win.getWindowingMode(), requestedWidth, requestedHeight,
                win.getBounds(), win.getWindowingMode(), requestedWidth, requestedHeight,
                win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
                win.getRequestedVisibilities(), attachedWindowFrame, win.mGlobalScale,
                sTmpClientFrames);
                sTmpClientFrames);
        windowFrames.setParentFrameWasClippedByDisplayCutout(
                sTmpClientFrames.isParentFrameClippedByDisplayCutout);

        if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
                + ": sim=#" + Integer.toHexString(attrs.softInputMode)
                + " attach=" + attached + " type=" + attrs.type
                + " flags=" + ViewDebug.flagsToString(LayoutParams.class, "flags", attrs.flags)
                + " pf=" + pf.toShortString() + " df=" + df.toShortString()
                + " f=" + f.toShortString());

        if (!sTmpLastParentFrame.equals(pf)) {
            windowFrames.setContentChanged(true);
        }


        win.setFrames(sTmpClientFrames);
        win.setFrames(sTmpClientFrames);
    }
    }
+3 −2
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.server.wm.WindowManagerService.H.UPDATE_MULTI_WINDOW_S


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.os.Trace;
import android.os.Trace;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsSource;
import android.view.InsetsSource;
@@ -79,8 +80,8 @@ final class ImeInsetsSourceProvider extends WindowContainerInsetsSourceProvider
    }
    }


    @Override
    @Override
    void updateSourceFrame() {
    void updateSourceFrame(Rect frame) {
        super.updateSourceFrame();
        super.updateSourceFrame(frame);
        onSourceChanged();
        onSourceChanged();
    }
    }


+26 −28
Original line number Original line Diff line number Diff line
@@ -84,6 +84,7 @@ abstract class InsetsSourceProvider {
    private TriConsumer<DisplayFrames, WindowContainer, Rect> mImeFrameProvider;
    private TriConsumer<DisplayFrames, WindowContainer, Rect> mImeFrameProvider;
    private final Rect mImeOverrideFrame = new Rect();
    private final Rect mImeOverrideFrame = new Rect();
    private boolean mIsLeashReadyForDispatching;
    private boolean mIsLeashReadyForDispatching;
    private final Rect mSourceFrame = new Rect();
    private final Rect mLastSourceFrame = new Rect();
    private final Rect mLastSourceFrame = new Rect();


    private final Consumer<Transaction> mSetLeashPositionConsumer = t -> {
    private final Consumer<Transaction> mSetLeashPositionConsumer = t -> {
@@ -183,8 +184,8 @@ abstract class InsetsSourceProvider {
        mImeFrameProvider = imeFrameProvider;
        mImeFrameProvider = imeFrameProvider;
        if (windowContainer == null) {
        if (windowContainer == null) {
            setServerVisible(false);
            setServerVisible(false);
            mSource.setFrame(new Rect());
            mSource.setVisibleFrame(null);
            mSource.setVisibleFrame(null);
            mSourceFrame.setEmpty();
        } else {
        } else {
            mWindowContainer.getProvidedInsetsSources().put(mSource.getType(), mSource);
            mWindowContainer.getProvidedInsetsSources().put(mSource.getType(), mSource);
            if (mControllable) {
            if (mControllable) {
@@ -208,7 +209,7 @@ abstract class InsetsSourceProvider {
     * The source frame can affect the layout of other windows, so this should be called once the
     * The source frame can affect the layout of other windows, so this should be called once the
     * window container gets laid out.
     * window container gets laid out.
     */
     */
    void updateSourceFrame() {
    void updateSourceFrame(Rect frame) {
        if (mWindowContainer == null) {
        if (mWindowContainer == null) {
            return;
            return;
        }
        }
@@ -230,39 +231,25 @@ abstract class InsetsSourceProvider {
            return;
            return;
        }
        }


        if (win.mGivenInsetsPending) {
        mSourceFrame.set(frame);
            // If the given insets are pending, they are not reliable for now. The source frame
            // should be updated after the new given insets are sent to window manager.
            return;
        }

        // Make sure we set the valid source frame only when server visible is true, because the
        // frame may not yet determined that server side doesn't think the window is ready to
        // visible. (i.e. No surface, pending insets that were given during layout, etc..)
        if (mServerVisible) {
            mTmpRect.set(win.getFrame());
        if (mFrameProvider != null) {
        if (mFrameProvider != null) {
            mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
            mFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
                        mWindowContainer, mTmpRect);
                    mWindowContainer, mSourceFrame);
            } else {
                mTmpRect.inset(win.mGivenContentInsets);
            }
        } else {
        } else {
            mTmpRect.setEmpty();
            mSourceFrame.inset(win.mGivenContentInsets);
        }
        }
        mSource.setFrame(mTmpRect);
        updateSourceFrameForServerVisibility();


        if (mImeFrameProvider != null) {
        if (mImeFrameProvider != null) {
            mImeOverrideFrame.set(win.getFrame());
            mImeOverrideFrame.set(frame);
            mImeFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
            mImeFrameProvider.accept(mWindowContainer.getDisplayContent().mDisplayFrames,
                    mWindowContainer,
                    mWindowContainer, mImeOverrideFrame);
                    mImeOverrideFrame);
        }
        }


        if (win.mGivenVisibleInsets.left != 0 || win.mGivenVisibleInsets.top != 0
        if (win.mGivenVisibleInsets.left != 0 || win.mGivenVisibleInsets.top != 0
                || win.mGivenVisibleInsets.right != 0
                || win.mGivenVisibleInsets.right != 0
                || win.mGivenVisibleInsets.bottom != 0) {
                || win.mGivenVisibleInsets.bottom != 0) {
            mTmpRect.set(win.getFrame());
            mTmpRect.set(frame);
            mTmpRect.inset(win.mGivenVisibleInsets);
            mTmpRect.inset(win.mGivenVisibleInsets);
            mSource.setVisibleFrame(mTmpRect);
            mSource.setVisibleFrame(mTmpRect);
        } else {
        } else {
@@ -270,13 +257,24 @@ abstract class InsetsSourceProvider {
        }
        }
    }
    }


    private void updateSourceFrameForServerVisibility() {
        // Make sure we set the valid source frame only when server visible is true, because the
        // frame may not yet determined that server side doesn't think the window is ready to
        // visible. (i.e. No surface, pending insets that were given during layout, etc..)
        if (mServerVisible) {
            mSource.setFrame(mSourceFrame);
        } else {
            mSource.setFrame(0, 0, 0, 0);
        }
    }

    /** @return A new source computed by the specified window frame in the given display frames. */
    /** @return A new source computed by the specified window frame in the given display frames. */
    InsetsSource createSimulatedSource(DisplayFrames displayFrames, Rect winFrame) {
    InsetsSource createSimulatedSource(DisplayFrames displayFrames, Rect frame) {
        // Don't copy visible frame because it might not be calculated in the provided display
        // Don't copy visible frame because it might not be calculated in the provided display
        // frames and it is not significant for this usage.
        // frames and it is not significant for this usage.
        final InsetsSource source = new InsetsSource(mSource.getType());
        final InsetsSource source = new InsetsSource(mSource.getType());
        source.setVisible(mSource.isVisible());
        source.setVisible(mSource.isVisible());
        mTmpRect.set(winFrame);
        mTmpRect.set(frame);
        if (mFrameProvider != null) {
        if (mFrameProvider != null) {
            mFrameProvider.accept(displayFrames, mWindowContainer, mTmpRect);
            mFrameProvider.accept(displayFrames, mWindowContainer, mTmpRect);
        }
        }
@@ -296,7 +294,6 @@ abstract class InsetsSourceProvider {
                ? windowState.wouldBeVisibleIfPolicyIgnored() && windowState.isVisibleByPolicy()
                ? windowState.wouldBeVisibleIfPolicyIgnored() && windowState.isVisibleByPolicy()
                : mWindowContainer.isVisibleRequested();
                : mWindowContainer.isVisibleRequested();
        setServerVisible(isServerVisible);
        setServerVisible(isServerVisible);
        updateSourceFrame();
        if (mControl != null) {
        if (mControl != null) {
            boolean changed = false;
            boolean changed = false;
            final Point position = getWindowFrameSurfacePosition();
            final Point position = getWindowFrameSurfacePosition();
@@ -496,6 +493,7 @@ abstract class InsetsSourceProvider {
    @VisibleForTesting
    @VisibleForTesting
    void setServerVisible(boolean serverVisible) {
    void setServerVisible(boolean serverVisible) {
        mServerVisible = serverVisible;
        mServerVisible = serverVisible;
        updateSourceFrameForServerVisibility();
        updateVisibility();
        updateVisibility();
    }
    }


+0 −18
Original line number Original line Diff line number Diff line
@@ -30,7 +30,6 @@ import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_IME;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.graphics.Rect;
import android.os.Trace;
import android.os.Trace;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
@@ -204,23 +203,6 @@ class InsetsStateController {
        }
        }
    }
    }


    /**
     * Computes insets state of the insets provider window in the display frames.
     *
     * @param win The owner window of insets provider.
     * @param displayFrames The display frames to create insets source.
     * @param winFrame The frame of the insets source window.
     */
    void computeSimulatedState(WindowState win, DisplayFrames displayFrames, Rect winFrame) {
        final InsetsState state = displayFrames.mInsetsState;
        for (int i = mProviders.size() - 1; i >= 0; i--) {
            final WindowContainerInsetsSourceProvider provider = mProviders.valueAt(i);
            if (provider.mWindowContainer == win) {
                state.addSource(provider.createSimulatedSource(displayFrames, winFrame));
            }
        }
    }

    boolean isFakeTarget(@InternalInsetsType int type, InsetsControlTarget target) {
    boolean isFakeTarget(@InternalInsetsType int type, InsetsControlTarget target) {
        return mTypeFakeControlTargetMap.get(type) == target;
        return mTypeFakeControlTargetMap.get(type) == target;
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -2156,6 +2156,7 @@ public class WindowManagerService extends IWindowManager.Stub
                        w.mGivenTouchableRegion.scale(w.mGlobalScale);
                        w.mGivenTouchableRegion.scale(w.mGlobalScale);
                    }
                    }
                    w.setDisplayLayoutNeeded();
                    w.setDisplayLayoutNeeded();
                    w.updateSourceFrame(w.getFrame());
                    mWindowPlacerLocked.performSurfacePlacement();
                    mWindowPlacerLocked.performSurfacePlacement();
                    w.getDisplayContent().getInputMonitor().updateInputWindowsLw(true);
                    w.getDisplayContent().getInputMonitor().updateInputWindowsLw(true);


Loading