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

Commit 71713dd5 authored by Tiger's avatar Tiger
Browse files

Split InternalInsetsType into InsetsType and the ID of InsetsSource

The is a step to remove InternalInsetsType which is used to categorize
insets sources and is also used to identify the corresponding objects
like InsetsSourceControl, InsetsSourceConsumer, ..., etc.

This CL migrates the usage of categorizing to the public types, and uses
the internal type as the identifier for now. Eventually, the ID will be
specified by the source producer, and we won't need the pre-defined ID
then.

Bug: 234093736
Test: atest InsetsSourceConsumerTest InsetsSourceTest
      DisplayImeControllerTest CompatUIControllerTest
      CompatUIWindowManagerTest ActivityRecordTests DisplayPolicyTests
      ImeInsetsSourceProviderTest SizeCompatTests
      WindowContainerInsetsSourceProviderTest WindowContainerTests
      WindowOrganizerTests WindowStateTests
Change-Id: Id574f98af18ab95b11fed13a09e08bc6a7929957
parent 39f6ecbe
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -455,8 +455,8 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                    : inset != 0;

            if (outState != null) {
                outState.getSource(source.getType()).setVisible(visible);
                outState.getSource(source.getType()).setFrame(mTmpFrame);
                outState.getSource(source.getId()).setVisible(visible);
                outState.getSource(source.getId()).setFrame(mTmpFrame);
            }

            // If the system is controlling the insets source, the leash can be null.
+1 −1
Original line number Diff line number Diff line
@@ -835,7 +835,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                    && !fromSource.getFrame().equals(toSource.getFrame())
                    && (Rect.intersects(mFrame, fromSource.getFrame())
                            || Rect.intersects(mFrame, toSource.getFrame()))) {
                types |= InsetsState.toPublicType(toSource.getType());
                types |= toSource.getType();
                if (toState == null) {
                    toState = new InsetsState();
                }
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class InsetsResizeAnimationRunner implements InsetsAnimationControlRunner
                    (int) (fromFrame.top + fraction * (toFrame.top - fromFrame.top)),
                    (int) (fromFrame.right + fraction * (toFrame.right - fromFrame.right)),
                    (int) (fromFrame.bottom + fraction * (toFrame.bottom - fromFrame.bottom)));
            final InsetsSource source = new InsetsSource(type);
            final InsetsSource source = new InsetsSource(type, fromSource.getType());
            source.setFrame(frame);
            source.setVisible(toSource.isVisible());
            outState.addSource(source);
+35 −25
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import static android.view.InsetsSourceProto.FRAME;
import static android.view.InsetsSourceProto.TYPE;
import static android.view.InsetsSourceProto.VISIBLE;
import static android.view.InsetsSourceProto.VISIBLE_FRAME;
import static android.view.InsetsState.ITYPE_CAPTION_BAR;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.ViewRootImpl.CAPTION_ON_SHELL;

import android.annotation.NonNull;
@@ -31,34 +29,42 @@ import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsState.InternalInsetsType;
import android.view.WindowInsets.Type.InsetsType;

import java.io.PrintWriter;
import java.util.Objects;

/**
 * Represents the state of a single window generating insets for clients.
 * Represents the state of a single entity generating insets for clients.
 * @hide
 */
public class InsetsSource implements Parcelable {

    private final @InternalInsetsType int mType;
    /**
     * An unique integer to identify this source across processes.
     */
    private final int mId;

    private final @InsetsType int mType;

    /** Frame of the source in screen coordinate space */
    private final Rect mFrame;
    private @Nullable Rect mVisibleFrame;

    private boolean mVisible;
    private boolean mInsetsRoundedCornerFrame;

    private final Rect mTmpFrame = new Rect();

    public InsetsSource(@InternalInsetsType int type) {
    public InsetsSource(int id, @InsetsType int type) {
        mId = id;
        mType = type;
        mFrame = new Rect();
        mVisible = InsetsState.getDefaultVisibility(type);
        mVisible = (WindowInsets.Type.defaultVisible() & type) != 0;
    }

    public InsetsSource(InsetsSource other) {
        mId = other.mId;
        mType = other.mType;
        mFrame = new Rect(other.mFrame);
        mVisible = other.mVisible;
@@ -86,14 +92,18 @@ public class InsetsSource implements Parcelable {
    }

    public void setVisibleFrame(@Nullable Rect visibleFrame) {
        mVisibleFrame = visibleFrame != null ? new Rect(visibleFrame) : visibleFrame;
        mVisibleFrame = visibleFrame != null ? new Rect(visibleFrame) : null;
    }

    public void setVisible(boolean visible) {
        mVisible = visible;
    }

    public @InternalInsetsType int getType() {
    public int getId() {
        return mId;
    }

    public @InsetsType int getType() {
        return mType;
    }

@@ -149,7 +159,7 @@ public class InsetsSource implements Parcelable {
        // During drag-move and drag-resizing, the caption insets position may not get updated
        // before the app frame get updated. To layout the app content correctly during drag events,
        // we always return the insets with the corresponding height covering the top.
        if (!CAPTION_ON_SHELL && getType() == ITYPE_CAPTION_BAR) {
        if (!CAPTION_ON_SHELL && getType() == WindowInsets.Type.captionBar()) {
            return Insets.of(0, frame.height(), 0, 0);
        }
        // Checks for whether there is shared edge with insets for 0-width/height window.
@@ -162,7 +172,7 @@ public class InsetsSource implements Parcelable {

        // TODO: Currently, non-floating IME always intersects at bottom due to issues with cutout.
        // However, we should let the policy decide from the server.
        if (getType() == ITYPE_IME) {
        if (getType() == WindowInsets.Type.ime()) {
            return Insets.of(0, 0, 0, mTmpFrame.height());
        }

@@ -220,7 +230,7 @@ public class InsetsSource implements Parcelable {
     */
    public void dumpDebug(ProtoOutputStream proto, long fieldId) {
        final long token = proto.start(fieldId);
        proto.write(TYPE, InsetsState.typeToString(mType));
        proto.write(TYPE, WindowInsets.Type.toString(mType));
        mFrame.dumpDebug(proto, FRAME);
        if (mVisibleFrame != null) {
            mVisibleFrame.dumpDebug(proto, VISIBLE_FRAME);
@@ -231,7 +241,8 @@ public class InsetsSource implements Parcelable {

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("InsetsSource type="); pw.print(InsetsState.typeToString(mType));
        pw.print("InsetsSource id="); pw.print(mId);
        pw.print(" type="); pw.print(WindowInsets.Type.toString(mType));
        pw.print(" frame="); pw.print(mFrame.toShortString());
        if (mVisibleFrame != null) {
            pw.print(" visibleFrame="); pw.print(mVisibleFrame.toShortString());
@@ -256,9 +267,10 @@ public class InsetsSource implements Parcelable {

        InsetsSource that = (InsetsSource) o;

        if (mId != that.mId) return false;
        if (mType != that.mType) return false;
        if (mVisible != that.mVisible) return false;
        if (excludeInvisibleImeFrames && !mVisible && mType == ITYPE_IME) return true;
        if (excludeInvisibleImeFrames && !mVisible && mType == WindowInsets.Type.ime()) return true;
        if (!Objects.equals(mVisibleFrame, that.mVisibleFrame)) return false;
        if (mInsetsRoundedCornerFrame != that.mInsetsRoundedCornerFrame) return false;
        return mFrame.equals(that.mFrame);
@@ -266,15 +278,11 @@ public class InsetsSource implements Parcelable {

    @Override
    public int hashCode() {
        int result = mType;
        result = 31 * result + mFrame.hashCode();
        result = 31 * result + (mVisibleFrame != null ? mVisibleFrame.hashCode() : 0);
        result = 31 * result + (mVisible ? 1 : 0);
        result = 31 * result + (mInsetsRoundedCornerFrame ? 1 : 0);
        return result;
        return Objects.hash(mId, mType, mFrame, mVisibleFrame, mVisible, mInsetsRoundedCornerFrame);
    }

    public InsetsSource(Parcel in) {
        mId = in.readInt();
        mType = in.readInt();
        mFrame = Rect.CREATOR.createFromParcel(in);
        if (in.readInt() != 0) {
@@ -293,6 +301,7 @@ public class InsetsSource implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mId);
        dest.writeInt(mType);
        mFrame.writeToParcel(dest, 0);
        if (mVisibleFrame != null) {
@@ -308,14 +317,15 @@ public class InsetsSource implements Parcelable {
    @Override
    public String toString() {
        return "InsetsSource: {"
                + "mType=" + InsetsState.typeToString(mType)
                + ", mFrame=" + mFrame.toShortString()
                + ", mVisible=" + mVisible
                + ", mInsetsRoundedCornerFrame=" + mInsetsRoundedCornerFrame
                + "mId=" + mId
                + " mType=" + WindowInsets.Type.toString(mType)
                + " mFrame=" + mFrame.toShortString()
                + " mVisible=" + mVisible
                + (mInsetsRoundedCornerFrame ? " insetsRoundedCornerFrame" : "")
                + "}";
    }

    public static final @android.annotation.NonNull Creator<InsetsSource> CREATOR = new Creator<InsetsSource>() {
    public static final @NonNull Creator<InsetsSource> CREATOR = new Creator<>() {

        public InsetsSource createFromParcel(Parcel in) {
            return new InsetsSource(in);
+5 −5
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ public class InsetsState implements Parcelable {

            // IME won't be reported in max insets as the size depends on the EditorInfo of the IME
            // target.
            if (source.getType() != ITYPE_IME) {
            if (source.getType() != WindowInsets.Type.ime()) {
                InsetsSource ignoringVisibilitySource = ignoringVisibilityState != null
                        ? ignoringVisibilityState.getSource(type)
                        : source;
@@ -442,7 +442,7 @@ public class InsetsState implements Parcelable {
            @Nullable boolean[] typeVisibilityMap) {
        Insets insets = source.calculateInsets(relativeFrame, ignoreVisibility);

        int type = toPublicType(source.getType());
        final int type = source.getType();
        processSourceAsPublicType(source, typeInsetsMap, typeSideMap, typeVisibilityMap,
                insets, type);

@@ -486,7 +486,7 @@ public class InsetsState implements Parcelable {
        if (typeSideMap != null) {
            @InternalInsetsSide int insetSide = getInsetSide(insets);
            if (insetSide != ISIDE_UNKNOWN) {
                typeSideMap.put(source.getType(), insetSide);
                typeSideMap.put(source.getId(), insetSide);
            }
        }
    }
@@ -519,7 +519,7 @@ public class InsetsState implements Parcelable {
        if (source != null) {
            return source;
        }
        source = new InsetsSource(type);
        source = new InsetsSource(type, toPublicType(type));
        mSources[type] = source;
        return source;
    }
@@ -708,7 +708,7 @@ public class InsetsState implements Parcelable {
    }

    public void addSource(InsetsSource source) {
        mSources[source.getType()] = source;
        mSources[source.getId()] = source;
    }

    public static boolean clearsCompatInsets(int windowType, int windowFlags, int windowingMode) {
Loading