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

Commit 3d0d262b authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Add a method to create the insets source ID"

parents 9154b286 c0f54227
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1242,7 +1242,7 @@ public abstract class WallpaperService extends Service {
                            null /* ignoringVisibilityState */, config.isScreenRound(),
                            false /* alwaysConsumeSystemBars */, mLayout.softInputMode,
                            mLayout.flags, SYSTEM_UI_FLAG_VISIBLE, mLayout.type,
                            config.windowConfiguration.getWindowingMode(), null /* typeSideMap */);
                            config.windowConfiguration.getWindowingMode(), null /* idSideMap */);

                    if (!fixedSize) {
                        final Rect padding = mIWallpaperEngine.mDisplayPadding;
+15 −15
Original line number Diff line number Diff line
@@ -33,12 +33,12 @@ import static android.view.InsetsController.AnimationType;
import static android.view.InsetsController.DEBUG;
import static android.view.InsetsController.LAYOUT_INSETS_DURING_ANIMATION_SHOWN;
import static android.view.InsetsController.LayoutInsetsDuringAnimation;
import static android.view.InsetsSource.ID_IME;
import static android.view.InsetsState.ISIDE_BOTTOM;
import static android.view.InsetsState.ISIDE_FLOATING;
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.InsetsState.ITYPE_IME;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY;
@@ -132,19 +132,19 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        mController = controller;
        mInitialInsetsState = new InsetsState(state, true /* copySources */);
        if (frame != null) {
            final SparseIntArray typeSideMap = new SparseIntArray();
            mCurrentInsets = getInsetsFromState(mInitialInsetsState, frame, null /* typeSideMap */);
            final SparseIntArray idSideMap = new SparseIntArray();
            mCurrentInsets = getInsetsFromState(mInitialInsetsState, frame, null /* idSideMap */);
            mHiddenInsets = calculateInsets(mInitialInsetsState, frame, controls, false /* shown */,
                    null /* typeSideMap */);
                    null /* idSideMap */);
            mShownInsets = calculateInsets(mInitialInsetsState, frame, controls, true /* shown */,
                    typeSideMap);
                    idSideMap);
            mHasZeroInsetsIme = mShownInsets.bottom == 0 && controlsType(WindowInsets.Type.ime());
            if (mHasZeroInsetsIme) {
                // IME has shownInsets of ZERO, and can't map to a side by default.
                // Map zero insets IME to bottom, making it a special case of bottom insets.
                typeSideMap.put(ITYPE_IME, ISIDE_BOTTOM);
                idSideMap.put(ID_IME, ISIDE_BOTTOM);
            }
            buildSideControlsMap(typeSideMap, mSideControlsMap, controls);
            buildSideControlsMap(idSideMap, mSideControlsMap, controls);
        } else {
            // Passing a null frame indicates the caller wants to play the insets animation anyway,
            // no matter the source provides insets to the frame or not.
@@ -399,18 +399,18 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    }

    private Insets getInsetsFromState(InsetsState state, Rect frame,
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
            @Nullable @InternalInsetsSide SparseIntArray idSideMap) {
        return state.calculateInsets(frame, null /* ignoringVisibilityState */,
                false /* isScreenRound */, false /* alwaysConsumeSystemBars */,
                LayoutParams.SOFT_INPUT_ADJUST_RESIZE /* legacySoftInputMode*/,
                0 /* legacyWindowFlags */, 0 /* legacySystemUiFlags */, TYPE_APPLICATION,
                WINDOWING_MODE_UNDEFINED, typeSideMap).getInsets(mTypes);
                WINDOWING_MODE_UNDEFINED, idSideMap).getInsets(mTypes);
    }

    /** Computes the insets relative to the given frame. */
    private Insets calculateInsets(InsetsState state, Rect frame,
            SparseArray<InsetsSourceControl> controls, boolean shown,
            @Nullable @InternalInsetsSide SparseIntArray typeSideMap) {
            @Nullable @InternalInsetsSide SparseIntArray idSideMap) {
        for (int i = controls.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control  = controls.valueAt(i);
            if (control == null) {
@@ -419,7 +419,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
            }
            state.setSourceVisible(control.getId(), shown);
        }
        return getInsetsFromState(state, frame, typeSideMap);
        return getInsetsFromState(state, frame, idSideMap);
    }

    /** Computes the insets from the insets hints of controls. */
@@ -521,12 +521,12 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        }
    }

    private static void buildSideControlsMap(SparseIntArray typeSideMap,
    private static void buildSideControlsMap(SparseIntArray idSideMap,
            SparseSetArray<InsetsSourceControl> sideControlsMap,
            SparseArray<InsetsSourceControl> controls) {
        for (int i = typeSideMap.size() - 1; i >= 0; i--) {
            final int type = typeSideMap.keyAt(i);
            final int side = typeSideMap.valueAt(i);
        for (int i = idSideMap.size() - 1; i >= 0; i--) {
            final int type = idSideMap.keyAt(i);
            final int side = idSideMap.valueAt(i);
            final InsetsSourceControl control = controls.get(type);
            if (control == null) {
                // If the types that we are controlling are less than the types that the system has,
+10 −8
Original line number Diff line number Diff line
@@ -19,8 +19,7 @@ package android.view;
import static android.os.Trace.TRACE_TAG_VIEW;
import static android.view.InsetsControllerProto.CONTROL;
import static android.view.InsetsControllerProto.STATE;
import static android.view.InsetsState.ITYPE_CAPTION_BAR;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.InsetsSource.ID_IME;
import static android.view.ViewRootImpl.CAPTION_ON_SHELL;
import static android.view.WindowInsets.Type.FIRST;
import static android.view.WindowInsets.Type.LAST;
@@ -249,6 +248,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    /** The amount IME will move up/down when animating in floating mode. */
    private static final int FLOATING_IME_BOTTOM_INSET_DP = -80;

    private static final int ID_CAPTION_BAR =
            InsetsSource.createId(null /* owner */, 0 /* index */, captionBar());

    static final boolean DEBUG = false;
    static final boolean WARN = false;

@@ -744,7 +746,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            WindowInsets insets = state.calculateInsets(mFrame, mState /* ignoringVisibilityState*/,
                    mLastInsets.isRound(), mLastInsets.shouldAlwaysConsumeSystemBars(),
                    mLastLegacySoftInputMode, mLastLegacyWindowFlags, mLastLegacySystemUiFlags,
                    mWindowType, mLastWindowingMode, null /* typeSideMap */);
                    mWindowType, mLastWindowingMode, null /* idSideMap */);
            mHost.dispatchWindowInsetsAnimationProgress(insets,
                    Collections.unmodifiableList(runningAnimations));
            if (DEBUG) {
@@ -760,7 +762,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        };

        // Make mImeSourceConsumer always non-null.
        mImeSourceConsumer = getSourceConsumer(new InsetsSource(ITYPE_IME, ime()));
        mImeSourceConsumer = getSourceConsumer(new InsetsSource(ID_IME, ime()));
    }

    @VisibleForTesting
@@ -882,7 +884,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (CAPTION_ON_SHELL) {
            return false;
        }
        final InsetsSource source = mState.peekSource(ITYPE_CAPTION_BAR);
        final InsetsSource source = mState.peekSource(ID_CAPTION_BAR);
        if (source == null && mCaptionInsetsHeight == 0) {
            return false;
        }
@@ -908,7 +910,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mLastLegacySystemUiFlags = legacySystemUiFlags;
        mLastInsets = mState.calculateInsets(mFrame, null /* ignoringVisibilityState*/,
                isScreenRound, alwaysConsumeSystemBars, legacySoftInputMode, legacyWindowFlags,
                legacySystemUiFlags, windowType, windowingMode, null /* typeSideMap */);
                legacySystemUiFlags, windowType, windowingMode, null /* idSideMap */);
        return mLastInsets;
    }

@@ -1780,10 +1782,10 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if (mCaptionInsetsHeight != height) {
            mCaptionInsetsHeight = height;
            if (mCaptionInsetsHeight != 0) {
                mState.getOrCreateSource(ITYPE_CAPTION_BAR, captionBar()).setFrame(
                mState.getOrCreateSource(ID_CAPTION_BAR, captionBar()).setFrame(
                        mFrame.left, mFrame.top, mFrame.right, mFrame.top + mCaptionInsetsHeight);
            } else {
                mState.removeSource(ITYPE_CAPTION_BAR);
                mState.removeSource(ID_CAPTION_BAR);
            }
            mHost.notifyInsetsChanged();
        }
+31 −4
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@ import static android.view.InsetsSourceProto.TYPE;
import static android.view.InsetsSourceProto.VISIBLE;
import static android.view.InsetsSourceProto.VISIBLE_FRAME;
import static android.view.ViewRootImpl.CAPTION_ON_SHELL;
import static android.view.WindowInsets.Type.ime;

import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Insets;
@@ -40,6 +42,9 @@ import java.util.Objects;
 */
public class InsetsSource implements Parcelable {

    /** The insets source ID of IME */
    public static final int ID_IME = createId(null, 0, ime());

    /**
     * An unique integer to identify this source across processes.
     */
@@ -227,6 +232,29 @@ public class InsetsSource implements Parcelable {
        return false;
    }

    /**
     * Creates an identifier of an {@link InsetsSource}.
     *
     * @param owner An object owned by the owner. Only the owner can modify its own sources.
     * @param index An owner may have multiple sources with the same type. For example, the system
     *              server might have multiple display cutout sources. This is used to identify
     *              which one is which. The value must be in a range of [0, 2047].
     * @param type The {@link WindowInsets.Type.InsetsType type} of the source.
     * @return a unique integer as the identifier.
     */
    public static int createId(Object owner, @IntRange(from = 0, to = 2047) int index,
            @InsetsType int type) {
        if (index < 0 || index >= 2048) {
            throw new IllegalArgumentException();
        }
        // owner takes top 16 bits;
        // index takes 11 bits since the 6th bit;
        // type takes bottom 5 bits.
        return (((owner != null ? owner.hashCode() : 1) % (1 << 16)) << 16)
                + (index << 5)
                + WindowInsets.Type.indexOf(type);
    }

    /**
     * Export the state of {@link InsetsSource} into a protocol buffer output stream.
     *
@@ -246,7 +274,7 @@ public class InsetsSource implements Parcelable {

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("InsetsSource id="); pw.print(mId);
        pw.print("InsetsSource id="); pw.print(Integer.toHexString(mId));
        pw.print(" type="); pw.print(WindowInsets.Type.toString(mType));
        pw.print(" frame="); pw.print(mFrame.toShortString());
        if (mVisibleFrame != null) {
@@ -263,7 +291,7 @@ public class InsetsSource implements Parcelable {
    }

    /**
     * @param excludeInvisibleImeFrames If {@link InsetsState#ITYPE_IME} frames should be ignored
     * @param excludeInvisibleImeFrames If {@link WindowInsets.Type#ime()} frames should be ignored
     *                                  when IME is not visible.
     */
    public boolean equals(@Nullable Object o, boolean excludeInvisibleImeFrames) {
@@ -321,8 +349,7 @@ public class InsetsSource implements Parcelable {

    @Override
    public String toString() {
        return "InsetsSource: {"
                + "mId=" + mId
        return "InsetsSource: {" + Integer.toHexString(mId)
                + " mType=" + WindowInsets.Type.toString(mType)
                + " mFrame=" + mFrame.toShortString()
                + " mVisible=" + mVisible
+2 −3
Original line number Diff line number Diff line
@@ -205,8 +205,7 @@ public class InsetsSourceControl implements Parcelable {

    @Override
    public String toString() {
        return "InsetsSourceControl: {"
                + "mId=" + mId
        return "InsetsSourceControl: {" + Integer.toHexString(mId)
                + " mType=" + WindowInsets.Type.toString(mType)
                + (mInitiallyVisible ? " initiallyVisible" : "")
                + " mSurfacePosition=" + mSurfacePosition
@@ -217,7 +216,7 @@ public class InsetsSourceControl implements Parcelable {

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("InsetsSourceControl mId="); pw.print(mId);
        pw.print("InsetsSourceControl mId="); pw.print(Integer.toHexString(mId));
        pw.print(" mType="); pw.print(WindowInsets.Type.toString(mType));
        pw.print(" mLeash="); pw.print(mLeash);
        pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible);
Loading