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

Commit 5ec9f867 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Simplify the parameter of getWindowInsets

Since getLayoutHint is removed, it no longer needs a window
layout parameter to get insets. And because the param is empty,
enforceInsetsPolicyForTarget was also no-op.

This can reduce write/read fifty unused fields to parcel, and
ensure the insets sources are only copied once to the output.

Bug: 151908239
Test: atest android.view.WindowMetricsTest
Change-Id: I086aa229a9e2468b0c2c302deabe2234abd90080
parent 099f8243
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -721,8 +721,7 @@ interface IWindowManager
     *
     * @return {@code true} if system bars are always consumed.
     */
    boolean getWindowInsets(in WindowManager.LayoutParams attrs, int displayId,
            out InsetsState outInsetsState);
    boolean getWindowInsets(int displayId, in IBinder token, out InsetsState outInsetsState);

    /**
     * Returns a list of {@link android.view.DisplayInfo} for the logical display. This is not
+20 −22
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ import android.annotation.NonNull;
import android.app.ResourcesManager;
import android.app.WindowConfiguration;
import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.DisplayMetrics;
import android.view.Display;
@@ -89,23 +91,16 @@ public final class WindowMetricsController {
            isScreenRound = config.isScreenRound();
            windowingMode = winConfig.getWindowingMode();
        }
        final WindowInsets windowInsets = computeWindowInsets(bounds, isScreenRound, windowingMode);
        final IBinder token = Context.getToken(mContext);
        final WindowInsets windowInsets = getWindowInsetsFromServerForCurrentDisplay(token,
                bounds, isScreenRound, windowingMode);
        return new WindowMetrics(bounds, windowInsets, density);
    }

    private WindowInsets computeWindowInsets(Rect bounds, boolean isScreenRound,
            @WindowConfiguration.WindowingMode int windowingMode) {
        // Initialize params which used for obtaining all system insets.
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.token = Context.getToken(mContext);
        return getWindowInsetsFromServerForCurrentDisplay(params, bounds, isScreenRound,
                windowingMode);
    }

    private WindowInsets getWindowInsetsFromServerForCurrentDisplay(
            WindowManager.LayoutParams attrs, Rect bounds, boolean isScreenRound,
            IBinder token, Rect bounds, boolean isScreenRound,
            @WindowConfiguration.WindowingMode int windowingMode) {
        return getWindowInsetsFromServerForDisplay(mContext.getDisplayId(), attrs, bounds,
        return getWindowInsetsFromServerForDisplay(mContext.getDisplayId(), token, bounds,
                isScreenRound, windowingMode);
    }

@@ -113,22 +108,26 @@ public final class WindowMetricsController {
     * Retrieves WindowInsets for the given context and display, given the window bounds.
     *
     * @param displayId the ID of the logical display to calculate insets for
     * @param attrs the LayoutParams for the calling app
     * @param token the token of Activity or WindowContext
     * @param bounds the window bounds to calculate insets for
     * @param isScreenRound if the display identified by displayId is round
     * @param windowingMode the windowing mode of the window to calculate insets for
     * @return WindowInsets calculated for the given window bounds, on the given display
     */
    private static WindowInsets getWindowInsetsFromServerForDisplay(int displayId,
            WindowManager.LayoutParams attrs, Rect bounds, boolean isScreenRound,
            int windowingMode) {
    private static WindowInsets getWindowInsetsFromServerForDisplay(int displayId, IBinder token,
            Rect bounds, boolean isScreenRound, int windowingMode) {
        try {
            final InsetsState insetsState = new InsetsState();
            final boolean alwaysConsumeSystemBars = WindowManagerGlobal.getWindowManagerService()
                    .getWindowInsets(attrs, displayId, insetsState);
                    .getWindowInsets(displayId, token, insetsState);
            final float overrideInvScale = CompatibilityInfo.getOverrideInvertedScale();
            if (overrideInvScale != 1f) {
                insetsState.scale(overrideInvScale);
            }
            return insetsState.calculateInsets(bounds, null /* ignoringVisibilityState */,
                    isScreenRound, alwaysConsumeSystemBars, SOFT_INPUT_ADJUST_NOTHING, attrs.flags,
                    SYSTEM_UI_FLAG_VISIBLE, attrs.type, windowingMode,
                    isScreenRound, alwaysConsumeSystemBars, SOFT_INPUT_ADJUST_NOTHING,
                    0 /* flags */, SYSTEM_UI_FLAG_VISIBLE,
                    WindowManager.LayoutParams.INVALID_WINDOW_TYPE, windowingMode,
                    null /* typeSideMap */);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
@@ -149,7 +148,6 @@ public final class WindowMetricsController {
        Set<WindowMetrics> maxMetrics = new HashSet<>();
        WindowInsets windowInsets;
        DisplayInfo currentDisplayInfo;
        final WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        for (int i = 0; i < possibleDisplayInfos.size(); i++) {
            currentDisplayInfo = possibleDisplayInfos.get(i);

@@ -162,7 +160,7 @@ public final class WindowMetricsController {
            // Initialize insets based upon display rotation. Note any window-provided insets
            // will not be set.
            windowInsets = getWindowInsetsFromServerForDisplay(
                    currentDisplayInfo.displayId, params,
                    currentDisplayInfo.displayId, null /* token */,
                    new Rect(0, 0, currentDisplayInfo.getNaturalWidth(),
                            currentDisplayInfo.getNaturalHeight()), isScreenRound,
                    WINDOWING_MODE_FULLSCREEN);
+15 −17
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.wm;
import static android.app.StatusBarManager.WINDOW_STATE_HIDDEN;
import static android.app.StatusBarManager.WINDOW_STATE_SHOWING;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.view.InsetsController.ANIMATION_TYPE_HIDE;
@@ -42,7 +41,6 @@ import android.app.StatusBarManager;
import android.app.WindowConfiguration;
import android.content.ComponentName;
import android.content.res.Resources;
import android.graphics.Rect;
import android.util.ArrayMap;
import android.util.IntArray;
import android.util.SparseArray;
@@ -276,21 +274,22 @@ class InsetsPolicy {
    /**
     * @see WindowState#getInsetsState()
     */
    InsetsState getInsetsForWindowMetrics(@NonNull WindowManager.LayoutParams attrs) {
        final WindowToken token = mDisplayContent.getWindowToken(attrs.token);
        if (token != null) {
            final InsetsState rotatedState = token.getFixedRotationTransformInsetsState();
            if (rotatedState != null) {
                return rotatedState;
    void getInsetsForWindowMetrics(@Nullable WindowToken token,
            @NonNull InsetsState outInsetsState) {
        final InsetsState srcState = token != null && token.isFixedRotationTransforming()
                ? token.getFixedRotationTransformInsetsState()
                : mStateController.getRawInsetsState();
        outInsetsState.set(srcState, true /* copySources */);
        for (int i = mShowingTransientTypes.size() - 1; i >= 0; i--) {
            final InsetsSource source = outInsetsState.peekSource(mShowingTransientTypes.get(i));
            if (source != null) {
                source.setVisible(false);
            }
        }
        adjustInsetsForRoundedCorners(token, outInsetsState, false /* copyState */);
        if (token != null && token.hasSizeCompatBounds()) {
            outInsetsState.scale(1f / token.getCompatScale());
        }
        final boolean alwaysOnTop = token != null && token.isAlwaysOnTop();
        // Always use windowing mode fullscreen when get insets for window metrics to make sure it
        // contains all insets types.
        final InsetsState originalState = enforceInsetsPolicyForTarget(attrs,
                WINDOWING_MODE_FULLSCREEN, alwaysOnTop, mStateController.getRawInsetsState());
        InsetsState state = adjustVisibilityForTransientTypes(originalState);
        return adjustInsetsForRoundedCorners(token, state, state == originalState);
    }

    /**
@@ -423,10 +422,9 @@ class InsetsPolicy {
            final Task task = activityRecord != null ? activityRecord.getTask() : null;
            if (task != null && !task.getWindowConfiguration().tasksAreFloating()) {
                // Use task bounds to calculating rounded corners if the task is not floating.
                final Rect roundedCornerFrame = new Rect(task.getBounds());
                final InsetsState state = copyState ? new InsetsState(originalState)
                        : originalState;
                state.setRoundedCornerFrame(roundedCornerFrame);
                state.setRoundedCornerFrame(task.getBounds());
                return state;
            }
        }
+4 −15
Original line number Diff line number Diff line
@@ -8924,28 +8924,17 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    @Override
    public boolean getWindowInsets(WindowManager.LayoutParams attrs, int displayId,
            InsetsState outInsetsState) {
        final int uid = Binder.getCallingUid();
    public boolean getWindowInsets(int displayId, IBinder token, InsetsState outInsetsState) {
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                final DisplayContent dc = getDisplayContentOrCreate(displayId, attrs.token);
                final DisplayContent dc = getDisplayContentOrCreate(displayId, token);
                if (dc == null) {
                    throw new WindowManager.InvalidDisplayException("Display#" + displayId
                            + "could not be found!");
                }
                final WindowToken token = dc.getWindowToken(attrs.token);
                final float overrideScale = mAtmService.mCompatModePackages.getCompatScale(
                        attrs.packageName, uid);
                final InsetsState state = dc.getInsetsPolicy().getInsetsForWindowMetrics(attrs);
                outInsetsState.set(state, true /* copySources */);
                if (WindowState.hasCompatScale(attrs, token, overrideScale)) {
                    final float compatScale = token != null && token.hasSizeCompatBounds()
                            ? token.getCompatScale() * overrideScale
                            : overrideScale;
                    outInsetsState.scale(1f / compatScale);
                }
                final WindowToken winToken = dc.getWindowToken(token);
                dc.getInsetsPolicy().getInsetsForWindowMetrics(winToken, outInsetsState);
                return dc.getDisplayPolicy().areSystemBarsForcedConsumedLw();
            }
        } finally {
+4 −13
Original line number Diff line number Diff line
@@ -1276,24 +1276,15 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
     * @see ActivityRecord#hasSizeCompatBounds()
     */
    boolean hasCompatScale() {
        return hasCompatScale(mAttrs, mActivityRecord, mOverrideScale);
    }

    /**
     * @return {@code true} if the application runs in size compatibility mode.
     * @see android.content.res.CompatibilityInfo#supportsScreen
     * @see ActivityRecord#hasSizeCompatBounds()
     */
    static boolean hasCompatScale(WindowManager.LayoutParams attrs, WindowToken token,
            float overrideScale) {
        if ((attrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0) {
        if ((mAttrs.privateFlags & PRIVATE_FLAG_COMPATIBLE_WINDOW) != 0) {
            return true;
        }
        if (attrs.type == TYPE_APPLICATION_STARTING) {
        if (mAttrs.type == TYPE_APPLICATION_STARTING) {
            // Exclude starting window because it is not displayed by the application.
            return false;
        }
        return token != null && token.hasSizeCompatBounds() || overrideScale != 1f;
        return mActivityRecord != null && mActivityRecord.hasSizeCompatBounds()
                || mOverrideScale != 1f;
    }

    /**
Loading