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

Commit 13eb0595 authored by Tiger's avatar Tiger Committed by Tiger Huang
Browse files

Refine clearsCompatInsets

It is used to decide if the compat insets can be cleared by
FLAG_LAYOUT_NO_LIMITS.

Previously, it returns false if the window is in multi-window mode.
However, since NAV_BAR_FORCE_VISIBLE can also force consuming system
bars regardless of the windowing mode, this CL checks the activity type
and the force consuming types instead.

The reason why we need to check activity type is for compatibility that
we only reject to clear compat insets for apps which have
FLAG_LAYOUT_NO_LIMITS. For system windows, except wallpaper and system
error windows, they can always clear compat insets by using
FLAG_LAYOUT_NO_LIMITS.

Fix: 291825755
Test: InsetsStateTest InsetsControllerTest ImeInsetsSourceConsumerTest
Change-Id: I88271c6a45e5eb5c9770d0dab128a9806870f705
parent d73d60f4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1292,9 +1292,9 @@ public abstract class WallpaperService extends Service {
                    visibleFrame.intersect(mInsetsState.getDisplayFrame());
                    WindowInsets windowInsets = mInsetsState.calculateInsets(visibleFrame,
                            null /* ignoringVisibilityState */, config.isScreenRound(),
                            false /* alwaysConsumeSystemBars */, mLayout.softInputMode,
                            mLayout.flags, SYSTEM_UI_FLAG_VISIBLE, mLayout.type,
                            config.windowConfiguration.getWindowingMode(), null /* idSideMap */);
                            mLayout.softInputMode, mLayout.flags, SYSTEM_UI_FLAG_VISIBLE,
                            mLayout.type, config.windowConfiguration.getActivityType(),
                            null /* idSideMap */);

                    if (!fixedSize) {
                        final Rect padding = mIWallpaperEngine.mDisplayPadding;
+4 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.view;

import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
import static android.view.EventLogTags.IMF_IME_ANIM_CANCEL;
import static android.view.EventLogTags.IMF_IME_ANIM_FINISH;
import static android.view.EventLogTags.IMF_IME_ANIM_START;
@@ -40,6 +40,7 @@ import static android.view.InsetsState.ISIDE_LEFT;
import static android.view.InsetsState.ISIDE_RIGHT;
import static android.view.InsetsState.ISIDE_TOP;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY;
import static android.view.inputmethod.ImeTracker.TOKEN_NONE;
@@ -63,7 +64,6 @@ import android.view.InsetsState.InternalInsetsSide;
import android.view.SyncRtSurfaceTransactionApplier.SurfaceParams;
import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsAnimation.Bounds;
import android.view.WindowManager.LayoutParams;
import android.view.animation.Interpolator;
import android.view.inputmethod.ImeTracker;

@@ -401,10 +401,9 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    private Insets getInsetsFromState(InsetsState state, Rect frame,
            @Nullable @InternalInsetsSide SparseIntArray idSideMap) {
        return state.calculateInsets(frame, null /* ignoringVisibilityState */,
                false /* isScreenRound */, false /* alwaysConsumeSystemBars */,
                LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/,
                false /* isScreenRound */, SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode */,
                0 /* legacyWindowFlags */, 0 /* legacySystemUiFlags */, TYPE_APPLICATION,
                WINDOWING_MODE_UNDEFINED, idSideMap).getInsets(mTypes);
                ACTIVITY_TYPE_UNDEFINED, idSideMap).getInsets(mTypes);
    }

    /** Computes the insets relative to the given frame. */
+14 −15
Original line number Diff line number Diff line
@@ -652,7 +652,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private int mLastLegacySoftInputMode;
    private int mLastLegacyWindowFlags;
    private int mLastLegacySystemUiFlags;
    private int mLastWindowingMode;
    private int mLastActivityType;
    private boolean mStartingAnimation;
    private int mCaptionInsetsHeight = 0;
    private int mImeCaptionBarInsetsHeight = 0;
@@ -803,10 +803,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                }
            }

            WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/,
                    mLastInsets.isRound(), false /* alwaysConsumeSystemBars */,
            WindowInsets insets = state.calculateInsets(mFrame,
                    mState /* ignoringVisibilityState */, mLastInsets.isRound(),
                    mLastLegacySoftInputMode, mLastLegacyWindowFlags, mLastLegacySystemUiFlags,
                    mWindowType, mLastWindowingMode, null /* idSideMap */);
                    mWindowType, mLastActivityType, null /* idSideMap */);
            mHost.dispatchWindowInsetsAnimationProgress(insets,
                    Collections.unmodifiableList(runningAnimations));
            if (DEBUG) {
@@ -969,30 +969,29 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    /**
     * @see InsetsState#calculateInsets(Rect, InsetsState, boolean, boolean, int, int, int, int,
     *      int, android.util.SparseIntArray)
     * @see InsetsState#calculateInsets(Rect, InsetsState, boolean, int, int, int, int, int,
     *      android.util.SparseIntArray)
     */
    @VisibleForTesting
    public WindowInsets calculateInsets(boolean isScreenRound, boolean alwaysConsumeSystemBars,
            int windowType, int windowingMode, int legacySoftInputMode, int legacyWindowFlags,
            int legacySystemUiFlags) {
    public WindowInsets calculateInsets(boolean isScreenRound, int windowType, int activityType,
            int legacySoftInputMode, int legacyWindowFlags, int legacySystemUiFlags) {
        mWindowType = windowType;
        mLastWindowingMode = windowingMode;
        mLastActivityType = activityType;
        mLastLegacySoftInputMode = legacySoftInputMode;
        mLastLegacyWindowFlags = legacyWindowFlags;
        mLastLegacySystemUiFlags = legacySystemUiFlags;
        mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState */,
                isScreenRound, alwaysConsumeSystemBars, legacySoftInputMode, legacyWindowFlags,
                legacySystemUiFlags, windowType, windowingMode, null /* idSideMap */);
                isScreenRound, legacySoftInputMode, legacyWindowFlags,
                legacySystemUiFlags, windowType, activityType, null /* idSideMap */);
        return mLastInsets;
    }

    /**
     * @see InsetsState#calculateVisibleInsets(Rect, int, int, int, int)
     */
    public Insets calculateVisibleInsets(int windowType, int windowingMode,
    public Insets calculateVisibleInsets(int windowType, int activityType,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
        return mState.calculateVisibleInsets(mFrame, windowType, windowingMode, softInputMode,
        return mState.calculateVisibleInsets(mFrame, windowType, activityType, softInputMode,
                windowFlags);
    }

+20 −15
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.view.InsetsSource.FLAG_FORCE_CONSUMING;
import static android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER;
import static android.view.InsetsStateProto.DISPLAY_CUTOUT;
@@ -39,7 +40,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.WindowConfiguration;
import android.app.WindowConfiguration.ActivityType;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Parcel;
@@ -136,9 +137,8 @@ public class InsetsState implements Parcelable {
     * @return The calculated insets.
     */
    public WindowInsets calculateInsets(Rect frame, @Nullable InsetsState ignoringVisibilityState,
            boolean isScreenRound, boolean alwaysConsumeSystemBars,
            int legacySoftInputMode, int legacyWindowFlags, int legacySystemUiFlags,
            int windowType, @WindowConfiguration.WindowingMode int windowingMode,
            boolean isScreenRound, int legacySoftInputMode, int legacyWindowFlags,
            int legacySystemUiFlags, int windowType, @ActivityType int activityType,
            @Nullable @InternalInsetsSide SparseIntArray idSideMap) {
        Insets[] typeInsetsMap = new Insets[Type.SIZE];
        Insets[] typeMaxInsetsMap = new Insets[Type.SIZE];
@@ -185,9 +185,8 @@ public class InsetsState implements Parcelable {
        if ((legacyWindowFlags & FLAG_FULLSCREEN) != 0) {
            compatInsetsTypes &= ~statusBars();
        }
        if (clearsCompatInsets(windowType, legacyWindowFlags, windowingMode)) {
            // Clear all types but forceConsumingTypes.
            compatInsetsTypes &= forceConsumingTypes;
        if (clearsCompatInsets(windowType, legacyWindowFlags, activityType, forceConsumingTypes)) {
            compatInsetsTypes = 0;
        }

        return new WindowInsets(typeInsetsMap, typeMaxInsetsMap, typeVisibilityMap, isScreenRound,
@@ -295,26 +294,27 @@ public class InsetsState implements Parcelable {
        return insets;
    }

    public Insets calculateVisibleInsets(Rect frame, int windowType, int windowingMode,
    public Insets calculateVisibleInsets(Rect frame, int windowType, @ActivityType int activityType,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
        final boolean clearsCompatInsets = clearsCompatInsets(
                windowType, windowFlags, windowingMode);
        final int softInputAdjustMode = softInputMode & SOFT_INPUT_MASK_ADJUST;
        final int visibleInsetsTypes = softInputAdjustMode != SOFT_INPUT_ADJUST_NOTHING
                ? systemBars() | ime()
                : systemBars();
        @InsetsType int forceConsumingTypes = 0;
        Insets insets = Insets.NONE;
        for (int i = mSources.size() - 1; i >= 0; i--) {
            final InsetsSource source = mSources.valueAt(i);
            if ((source.getType() & visibleInsetsTypes) == 0) {
                continue;
            }
            if (clearsCompatInsets && !source.hasFlags(FLAG_FORCE_CONSUMING)) {
                continue;
            if (source.hasFlags(FLAG_FORCE_CONSUMING)) {
                forceConsumingTypes |= source.getType();
            }
            insets = Insets.max(source.calculateVisibleInsets(frame), insets);
        }
        return insets;
        return clearsCompatInsets(windowType, windowFlags, activityType, forceConsumingTypes)
                ? Insets.NONE
                : insets;
    }

    /**
@@ -662,10 +662,15 @@ public class InsetsState implements Parcelable {
        mSources.put(source.getId(), source);
    }

    public static boolean clearsCompatInsets(int windowType, int windowFlags, int windowingMode) {
    public static boolean clearsCompatInsets(int windowType, int windowFlags,
            @ActivityType int activityType, @InsetsType int forceConsumingTypes) {
        return (windowFlags & FLAG_LAYOUT_NO_LIMITS) != 0
                // For compatibility reasons, this excludes the wallpaper, the system error windows,
                // and the app windows while any system bar is forcibly consumed.
                && windowType != TYPE_WALLPAPER && windowType != TYPE_SYSTEM_ERROR
                && !WindowConfiguration.inMultiWindowMode(windowingMode);
                // This ensures the app content won't be obscured by compat insets even if the app
                // has FLAG_LAYOUT_NO_LIMITS.
                && (forceConsumingTypes == 0 || activityType != ACTIVITY_TYPE_STANDARD);
    }

    public void dump(String prefix, PrintWriter pw) {
+4 −5
Original line number Diff line number Diff line
@@ -2851,16 +2851,15 @@ public final class ViewRootImpl implements ViewParent,
        if (mLastWindowInsets == null || forceConstruct) {
            final Configuration config = getConfiguration();
            mLastWindowInsets = mInsetsController.calculateInsets(
                    config.isScreenRound(), mAttachInfo.mAlwaysConsumeSystemBars,
                    mWindowAttributes.type, config.windowConfiguration.getWindowingMode(),
                    mWindowAttributes.softInputMode, mWindowAttributes.flags,
                    (mWindowAttributes.systemUiVisibility
                    config.isScreenRound(), mWindowAttributes.type,
                    config.windowConfiguration.getActivityType(), mWindowAttributes.softInputMode,
                    mWindowAttributes.flags, (mWindowAttributes.systemUiVisibility
                            | mWindowAttributes.subtreeSystemUiVisibility));

            mAttachInfo.mContentInsets.set(mLastWindowInsets.getSystemWindowInsets().toRect());
            mAttachInfo.mStableInsets.set(mLastWindowInsets.getStableInsets().toRect());
            mAttachInfo.mVisibleInsets.set(mInsetsController.calculateVisibleInsets(
                    mWindowAttributes.type, config.windowConfiguration.getWindowingMode(),
                    mWindowAttributes.type, config.windowConfiguration.getActivityType(),
                    mWindowAttributes.softInputMode, mWindowAttributes.flags).toRect());
        }
        return mLastWindowInsets;
Loading