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

Commit 15751451 authored by Tiger Huang's avatar Tiger Huang
Browse files

Send the attached frame to the client

The attached frame is the frame of the parent window that its child
attaches to, as long as the child is not
TYPE_APPLICATION_ATTACHED_DIALOG. It is a factor while computing the
window frame.

Previously, we let the child obtain the attached frame from its parent
view root. However, if the parent and the child are not in the same
process, it can be tricky.

This CL sends the attached frame from the server to the client via
ClientWindowFrames. In this way, the child can compute its window frame
without having to accessing the parent view root.

Bug: 161810301
Bug: 175861127
Test: atest ActivityRecordTests WindowLayoutTests
Change-Id: Ia844a4c927027e305a56114216eaee2bf7933b1f
parent 2b13efde
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.wm;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

import android.graphics.Rect;
import android.os.RemoteException;
import android.os.SystemClock;
import android.perftests.utils.ManualBenchmarkState;
@@ -86,6 +87,7 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
        final InsetsVisibilities mRequestedVisibilities = new InsetsVisibilities();
        final InsetsState mOutInsetsState = new InsetsState();
        final InsetsSourceControl[] mOutControls = new InsetsSourceControl[0];
        final Rect mOutAttachedFrame = new Rect();

        TestWindow() {
            mLayoutParams.setTitle(TestWindow.class.getName());
@@ -104,7 +106,7 @@ public class WindowAddRemovePerfTest extends WindowManagerPerfTestBase
                long startTime = SystemClock.elapsedRealtimeNanos();
                session.addToDisplay(this, mLayoutParams, View.VISIBLE,
                        Display.DEFAULT_DISPLAY, mRequestedVisibilities, inputChannel,
                        mOutInsetsState, mOutControls);
                        mOutInsetsState, mOutControls, mOutAttachedFrame);
                final long elapsedTimeNsOfAdd = SystemClock.elapsedRealtimeNanos() - startTime;
                state.addExtraResult("add", elapsedTimeNsOfAdd);

+4 −1
Original line number Diff line number Diff line
@@ -420,7 +420,10 @@ public class CompatibilityInfo implements Parcelable {
         * Translate a Rect in screen coordinates into the app window's coordinates.
         */
        @UnsupportedAppUsage
        public void translateRectInScreenToAppWindow(Rect rect) {
        public void translateRectInScreenToAppWindow(@Nullable Rect rect) {
            if (rect == null) {
                return;
            }
            rect.scale(applicationInvertedScale);
        }

+2 −3
Original line number Diff line number Diff line
@@ -1139,7 +1139,7 @@ public abstract class WallpaperService extends Service {

                        if (mSession.addToDisplay(mWindow, mLayout, View.VISIBLE,
                                mDisplay.getDisplayId(), mRequestedVisibilities, inputChannel,
                                mInsetsState, mTempControls) < 0) {
                                mInsetsState, mTempControls, new Rect()) < 0) {
                            Log.w(TAG, "Failed to add window while updating wallpaper surface.");
                            return;
                        }
@@ -1171,8 +1171,7 @@ public abstract class WallpaperService extends Service {
                        mInsetsState.getDisplayCutoutSafe(displayCutoutSafe);
                        mWindowLayout.computeFrames(mLayout, mInsetsState, displayCutoutSafe,
                                winConfig.getBounds(), winConfig.getWindowingMode(), mWidth,
                                mHeight, mRequestedVisibilities, null /* attachedWindowFrame */,
                                1f /* compatScale */, mWinFrames);
                                mHeight, mRequestedVisibilities, 1f /* compatScale */, mWinFrames);

                        mSession.updateLayout(mWindow, mLayout, 0 /* flags */, mWinFrames, mWidth,
                                mHeight);
+5 −3
Original line number Diff line number Diff line
@@ -50,13 +50,15 @@ interface IWindowSession {
    int addToDisplay(IWindow window, in WindowManager.LayoutParams attrs,
            in int viewVisibility, in int layerStackId, in InsetsVisibilities requestedVisibilities,
            out InputChannel outInputChannel, out InsetsState insetsState,
            out InsetsSourceControl[] activeControls);
            out InsetsSourceControl[] activeControls, out Rect attachedFrame);
    int addToDisplayAsUser(IWindow window, in WindowManager.LayoutParams attrs,
            in int viewVisibility, in int layerStackId, in int userId,
            in InsetsVisibilities requestedVisibilities, out InputChannel outInputChannel,
            out InsetsState insetsState, out InsetsSourceControl[] activeControls);
            out InsetsState insetsState, out InsetsSourceControl[] activeControls,
            out Rect attachedFrame);
    int addToDisplayWithoutInputChannel(IWindow window, in WindowManager.LayoutParams attrs,
            in int viewVisibility, in int layerStackId, out InsetsState insetsState);
            in int viewVisibility, in int layerStackId, out InsetsState insetsState,
            out Rect attachedFrame);
    @UnsupportedAppUsage
    void remove(IWindow window);

+21 −20
Original line number Diff line number Diff line
@@ -60,13 +60,11 @@ import static android.view.WindowInsetsController.BEHAVIOR_DEFAULT;
import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
import static android.view.WindowLayout.UNSPECIFIED_LENGTH;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_APPEARANCE_CONTROLLED;
@@ -77,7 +75,6 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_INSET_PARENT_
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_SIZE_EXTENDED_BY_CUTOUT;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL;
@@ -566,8 +563,6 @@ public final class ViewRootImpl implements ViewParent,

    private final WindowLayout mWindowLayout;

    private ViewRootImpl mParentViewRoot;

    // This is used to reduce the race between window focus changes being dispatched from
    // the window manager and input events coming through the input system.
    @GuardedBy("this")
@@ -1185,7 +1180,6 @@ public final class ViewRootImpl implements ViewParent,
                if (panelParentView != null) {
                    mAttachInfo.mPanelParentWindowToken
                            = panelParentView.getApplicationWindowToken();
                    mParentViewRoot = panelParentView.getViewRootImpl();
                }
                mAdded = true;
                int res; /* = WindowManagerImpl.ADD_OKAY; */
@@ -1216,14 +1210,21 @@ public final class ViewRootImpl implements ViewParent,
                    collectViewAttributes();
                    adjustLayoutParamsForCompatibility(mWindowAttributes);
                    controlInsetsForCompatibility(mWindowAttributes);

                    Rect attachedFrame = new Rect();
                    res = mWindowSession.addToDisplayAsUser(mWindow, mWindowAttributes,
                            getHostVisibility(), mDisplay.getDisplayId(), userId,
                            mInsetsController.getRequestedVisibilities(), inputChannel, mTempInsets,
                            mTempControls);
                            mTempControls, attachedFrame);
                    if (!attachedFrame.isValid()) {
                        attachedFrame = null;
                    }
                    if (mTranslator != null) {
                        mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
                        mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
                        mTranslator.translateRectInScreenToAppWindow(attachedFrame);
                    }
                    mTmpFrames.attachedFrame = attachedFrame;
                } catch (RemoteException e) {
                    mAdded = false;
                    mView = null;
@@ -1250,8 +1251,8 @@ public final class ViewRootImpl implements ViewParent,
                mWindowLayout.computeFrames(mWindowAttributes, state,
                        displayCutoutSafe, winConfig.getBounds(), winConfig.getWindowingMode(),
                        UNSPECIFIED_LENGTH, UNSPECIFIED_LENGTH,
                        mInsetsController.getRequestedVisibilities(),
                        getAttachedWindowFrame(), 1f /* compactScale */, mTmpFrames);
                        mInsetsController.getRequestedVisibilities(), 1f /* compactScale */,
                        mTmpFrames);
                setFrame(mTmpFrames.frame);
                registerBackCallbackOnWindow();
                if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
@@ -1373,14 +1374,6 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    private Rect getAttachedWindowFrame() {
        final int type = mWindowAttributes.type;
        final boolean layoutAttached = (mParentViewRoot != null
                && type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW
                && type != TYPE_APPLICATION_ATTACHED_DIALOG);
        return layoutAttached ? mParentViewRoot.mWinFrame : null;
    }

    /**
     * Register any kind of listeners if setView was success.
     */
@@ -1738,16 +1731,20 @@ public final class ViewRootImpl implements ViewParent,

        final Rect frame = frames.frame;
        final Rect displayFrame = frames.displayFrame;
        final Rect attachedFrame = frames.attachedFrame;
        if (mTranslator != null) {
            mTranslator.translateRectInScreenToAppWindow(frame);
            mTranslator.translateRectInScreenToAppWindow(displayFrame);
            mTranslator.translateRectInScreenToAppWindow(attachedFrame);
        }
        final boolean frameChanged = !mWinFrame.equals(frame);
        final boolean configChanged = !mLastReportedMergedConfiguration.equals(mergedConfiguration);
        final boolean attachedFrameChanged = LOCAL_LAYOUT
                && !Objects.equals(mTmpFrames.attachedFrame, attachedFrame);
        final boolean displayChanged = mDisplay.getDisplayId() != displayId;
        final boolean resizeModeChanged = mResizeMode != resizeMode;
        if (msg == MSG_RESIZED && !frameChanged && !configChanged && !displayChanged
                && !resizeModeChanged && !forceNextWindowRelayout) {
        if (msg == MSG_RESIZED && !frameChanged && !configChanged && !attachedFrameChanged
                && !displayChanged && !resizeModeChanged && !forceNextWindowRelayout) {
            return;
        }

@@ -1765,6 +1762,9 @@ public final class ViewRootImpl implements ViewParent,

        setFrame(frame);
        mTmpFrames.displayFrame.set(displayFrame);
        if (mTmpFrames.attachedFrame != null && attachedFrame != null) {
            mTmpFrames.attachedFrame.set(attachedFrame);
        }

        if (mDragResizing && mUseMTRenderer) {
            boolean fullscreen = frame.equals(mPendingBackDropFrame);
@@ -8039,7 +8039,7 @@ public final class ViewRootImpl implements ViewParent,
            mWindowLayout.computeFrames(mWindowAttributes, state, displayCutoutSafe,
                    winConfig.getBounds(), winConfig.getWindowingMode(), requestedWidth,
                    requestedHeight, mInsetsController.getRequestedVisibilities(),
                    getAttachedWindowFrame(), 1f /* compatScale */, mTmpFrames);
                    1f /* compatScale */, mTmpFrames);

            mWindowSession.updateLayout(mWindow, params,
                    insetsPending ? WindowManagerGlobal.RELAYOUT_INSETS_PENDING : 0, mTmpFrames,
@@ -8059,6 +8059,7 @@ public final class ViewRootImpl implements ViewParent,
            if (mTranslator != null) {
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.frame);
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.displayFrame);
                mTranslator.translateRectInScreenToAppWindow(mTmpFrames.attachedFrame);
                mTranslator.translateInsetsStateInScreenToAppWindow(mTempInsets);
                mTranslator.translateSourceControlsInScreenToAppWindow(mTempControls);
            }
Loading