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

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

Introduce WindowlessWindowLayout

The window frame computed by WindowlessWindowManager doesn't take the
window bounds, insets state, gravity, ... into account, but only width
and height in LayoutParams. This CL introduces WindowlessWindowLayout
which aligns the logic in WindowlessWindowManager#relayout. When we
enable LOCAL_LAYOUT, the frame of windowless window will be compatible.

Bug: 161810301
Bug: 175858823
Test: atest SurfaceControlViewHostTests#testEmbeddedViewResizes
Change-Id: I460445e9d6b61117edbdaddeac6a00a838b3caa8
parent 83569534
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@ import android.os.Parcelable;
import android.os.RemoteException;
import android.util.Log;
import android.window.WindowTokenClient;
import android.view.InsetsState;
import android.view.WindowManagerGlobal;
import android.view.accessibility.IAccessibilityEmbeddedConnection;

import java.util.Objects;
@@ -280,7 +278,7 @@ public class SurfaceControlViewHost {
    public SurfaceControlViewHost(@NonNull Context c, @NonNull Display d,
            @NonNull WindowlessWindowManager wwm, boolean useSfChoreographer) {
        mWm = wwm;
        mViewRoot = new ViewRootImpl(c, d, mWm, useSfChoreographer);
        mViewRoot = new ViewRootImpl(c, d, mWm, new WindowlessWindowLayout(), useSfChoreographer);
        addConfigCallback(c, d);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
@@ -310,7 +308,7 @@ public class SurfaceControlViewHost {
        mWm = new WindowlessWindowManager(context.getResources().getConfiguration(),
                mSurfaceControl, hostToken);

        mViewRoot = new ViewRootImpl(context, display, mWm);
        mViewRoot = new ViewRootImpl(context, display, mWm, new WindowlessWindowLayout());
        addConfigCallback(context, display);

        WindowManagerGlobal.getInstance().addWindowlessRoot(mViewRoot);
+7 −5
Original line number Diff line number Diff line
@@ -559,7 +559,7 @@ public final class ViewRootImpl implements ViewParent,
    private final Rect mVisRect = new Rect(); // used to retrieve visible rect of focused view.
    private final Rect mTempRect = new Rect();

    private final WindowLayout mWindowLayout = new WindowLayout();
    private final WindowLayout mWindowLayout;

    private ViewRootImpl mParentViewRoot;

@@ -854,18 +854,20 @@ public final class ViewRootImpl implements ViewParent,
    private String mTag = TAG;

    public ViewRootImpl(Context context, Display display) {
        this(context, display, WindowManagerGlobal.getWindowSession(),
        this(context, display, WindowManagerGlobal.getWindowSession(), new WindowLayout(),
                false /* useSfChoreographer */);
    }

    public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session) {
        this(context, display, session, false /* useSfChoreographer */);
    public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session,
            WindowLayout windowLayout) {
        this(context, display, session, windowLayout, false /* useSfChoreographer */);
    }

    public ViewRootImpl(@UiContext Context context, Display display, IWindowSession session,
            boolean useSfChoreographer) {
            WindowLayout windowLayout, boolean useSfChoreographer) {
        mContext = context;
        mWindowSession = session;
        mWindowLayout = windowLayout;
        mDisplay = display;
        mBasePackageName = context.getBasePackageName();
        mThread = Thread.currentThread();
+1 −1
Original line number Diff line number Diff line
@@ -386,7 +386,7 @@ public final class WindowManagerGlobal {
                root = new ViewRootImpl(view.getContext(), display);
            } else {
                root = new ViewRootImpl(view.getContext(), display,
                        windowlessSession);
                        windowlessSession, new WindowlessWindowLayout());
            }

            view.setLayoutParams(wparams);
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view;

import android.app.WindowConfiguration.WindowingMode;
import android.graphics.Rect;
import android.window.ClientWindowFrames;

/**
 * Computes window frames for the windowless window.
 * @hide
 */
public class WindowlessWindowLayout extends WindowLayout {

    @Override
    public void computeFrames(WindowManager.LayoutParams attrs, InsetsState state,
            Rect displayCutoutSafe, Rect windowBounds, @WindowingMode int windowingMode,
            int requestedWidth, int requestedHeight, InsetsVisibilities requestedVisibilities,
            Rect attachedWindowFrame, float compatScale, ClientWindowFrames outFrames) {
        outFrames.frame.set(0, 0, attrs.width, attrs.height);
        outFrames.displayFrame.set(outFrames.frame);
        outFrames.parentFrame.set(outFrames.frame);
    }
}