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

Commit e1434019 authored by Tiger's avatar Tiger
Browse files

Add public type and ID to InsetsSourceControl

This CL replaces the InternalInsetsType with the InsetsType and the ID
in InsetsSourceControl. The is a step to remove InternalInsetsType like
we did to InsetsSource.

Bug: 234093736
Test: atest ImeInsetsSourceConsumerTest InsetsAnimationControlImplTest
      InsetsControllerTest InsetsSourceConsumerTest DisplayImeControllerTest
      InsetsPolicyTest
Change-Id: I01aa4930cccf295abdc2efd9f762d035d03748ce
parent 71713dd5
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    public void updateSurfacePosition(SparseArray<InsetsSourceControl> controls) {
        for (int i = controls.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control = controls.valueAt(i);
            final InsetsSourceControl c = mControls.get(control.getType());
            final InsetsSourceControl c = mControls.get(control.getId());
            if (c == null) {
                continue;
            }
@@ -395,7 +395,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                // control may be null if it got revoked.
                continue;
            }
            state.getSource(control.getType()).setVisible(shown);
            state.getSource(control.getId()).setVisible(shown);
        }
        return getInsetsFromState(state, frame, typeSideMap);
    }
@@ -413,7 +413,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                // control may be null if it got revoked.
                continue;
            }
            if (state == null || state.getSource(control.getType()).isVisible()) {
            if (state == null || state.getSource(control.getId()).isVisible()) {
                insets = Insets.max(insets, control.getInsetsHint());
            }
        }
@@ -443,7 +443,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        // TODO: Implement behavior when inset spans over multiple types
        for (int i = controls.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control = controls.valueAt(i);
            final InsetsSource source = mInitialInsetsState.getSource(control.getType());
            final InsetsSource source = mInitialInsetsState.getSource(control.getId());
            final SurfaceControl leash = control.getLeash();

            mTmpMatrix.setTranslate(control.getSurfacePosition().x, control.getSurfacePosition().y);
@@ -521,7 +521,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                continue;
            }
            @InternalInsetsSide int side = InsetsState.getInsetSide(control.getInsetsHint());
            if (side == ISIDE_FLOATING && control.getType() == ITYPE_IME) {
            if (side == ISIDE_FLOATING && control.getType() == WindowInsets.Type.ime()) {
                side = ISIDE_BOTTOM;
            }
            sideControlsMap.add(side, control);
+12 −13
Original line number Diff line number Diff line
@@ -888,7 +888,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            for (InsetsSourceControl activeControl : activeControls) {
                if (activeControl != null) {
                    // TODO(b/122982984): Figure out why it can be null.
                    mTmpControlArray.put(activeControl.getType(), activeControl);
                    mTmpControlArray.put(activeControl.getId(), activeControl);
                }
            }
        }
@@ -910,10 +910,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        // Ensure to create source consumers if not available yet.
        for (int i = mTmpControlArray.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control = mTmpControlArray.valueAt(i);
            final @InternalInsetsType int type = control.getType();
            final InsetsSourceConsumer consumer = getSourceConsumer(type);
            final InsetsSourceConsumer consumer = getSourceConsumer(control.getId());
            consumer.setControl(control, showTypes, hideTypes);
            controllableTypes |= InsetsState.toPublicType(type);
            controllableTypes |= control.getType();
        }

        if (mTmpControlArray.size() > 0) {
@@ -1265,7 +1264,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            }
            final InsetsSourceControl control = consumer.getControl();
            if (control != null && control.getLeash() != null) {
                controls.put(control.getType(), new InsetsSourceControl(control));
                controls.put(control.getId(), new InsetsSourceControl(control));
                typesReady |= consumer.getType();
            } else if (animationType == ANIMATION_TYPE_SHOW) {
                if (DEBUG) Log.d(TAG, "collectSourceControls no control for show(). fromIme: "
@@ -1422,14 +1421,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @VisibleForTesting
    public @NonNull InsetsSourceConsumer getSourceConsumer(@InternalInsetsType int type) {
        InsetsSourceConsumer controller = mSourceConsumers.get(type);
        if (controller != null) {
            return controller;
        }
        controller = mConsumerCreator.apply(this, type);
        mSourceConsumers.put(type, controller);
        return controller;
    public @NonNull InsetsSourceConsumer getSourceConsumer(int id) {
        InsetsSourceConsumer consumer = mSourceConsumers.get(id);
        if (consumer != null) {
            return consumer;
        }
        consumer = mConsumerCreator.apply(this, id);
        mSourceConsumers.put(id, consumer);
        return consumer;
    }

    @VisibleForTesting
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class InsetsSourceConsumer {
        mSourceControl = control;
        if (control != null) {
            if (DEBUG) Log.d(TAG, String.format("setControl -> %s on %s",
                    InsetsState.typeToString(control.getType()),
                    WindowInsets.Type.toString(control.getType()),
                    mController.getHost().getRootViewTitle()));
        }
        if (mSourceControl == null) {
+26 −12
Original line number Diff line number Diff line
@@ -22,13 +22,14 @@ import static android.view.InsetsSourceControlProto.LEASH;
import static android.view.InsetsSourceControlProto.POSITION;
import static android.view.InsetsSourceControlProto.TYPE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Insets;
import android.graphics.Point;
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;
@@ -40,7 +41,8 @@ import java.util.function.Consumer;
 */
public class InsetsSourceControl implements Parcelable {

    private final @InternalInsetsType int mType;
    private final int mId;
    private final @InsetsType int mType;
    private final @Nullable SurfaceControl mLeash;
    private final boolean mInitiallyVisible;
    private final Point mSurfacePosition;
@@ -52,8 +54,9 @@ public class InsetsSourceControl implements Parcelable {
    private boolean mSkipAnimationOnce;
    private int mParcelableFlags;

    public InsetsSourceControl(@InternalInsetsType int type, @Nullable SurfaceControl leash,
    public InsetsSourceControl(int id, @InsetsType int type, @Nullable SurfaceControl leash,
            boolean initiallyVisible, Point surfacePosition, Insets insetsHint) {
        mId = id;
        mType = type;
        mLeash = leash;
        mInitiallyVisible = initiallyVisible;
@@ -62,6 +65,7 @@ public class InsetsSourceControl implements Parcelable {
    }

    public InsetsSourceControl(InsetsSourceControl other) {
        mId = other.mId;
        mType = other.mType;
        if (other.mLeash != null) {
            mLeash = new SurfaceControl(other.mLeash, "InsetsSourceControl");
@@ -75,6 +79,7 @@ public class InsetsSourceControl implements Parcelable {
    }

    public InsetsSourceControl(Parcel in) {
        mId = in.readInt();
        mType = in.readInt();
        mLeash = in.readTypedObject(SurfaceControl.CREATOR);
        mInitiallyVisible = in.readBoolean();
@@ -83,6 +88,10 @@ public class InsetsSourceControl implements Parcelable {
        mSkipAnimationOnce = in.readBoolean();
    }

    public int getId() {
        return mId;
    }

    public int getType() {
        return mType;
    }
@@ -153,6 +162,7 @@ public class InsetsSourceControl implements Parcelable {

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(mId);
        dest.writeInt(mType);
        dest.writeTypedObject(mLeash, mParcelableFlags);
        dest.writeBoolean(mInitiallyVisible);
@@ -177,7 +187,8 @@ public class InsetsSourceControl implements Parcelable {
        }
        final InsetsSourceControl that = (InsetsSourceControl) o;
        final SurfaceControl thatLeash = that.mLeash;
        return mType == that.mType
        return mId == that.mId
                && mType == that.mType
                && ((mLeash == thatLeash)
                        || (mLeash != null && thatLeash != null && mLeash.isSameSurface(thatLeash)))
                && mInitiallyVisible == that.mInitiallyVisible
@@ -188,22 +199,26 @@ public class InsetsSourceControl implements Parcelable {

    @Override
    public int hashCode() {
        return Objects.hash(mType, mLeash, mInitiallyVisible, mSurfacePosition, mInsetsHint,
        return Objects.hash(mId, mType, mLeash, mInitiallyVisible, mSurfacePosition, mInsetsHint,
                mSkipAnimationOnce);
    }

    @Override
    public String toString() {
        return "InsetsSourceControl: {"
                + "type=" + InsetsState.typeToString(mType)
                + ", mSurfacePosition=" + mSurfacePosition
                + ", mInsetsHint=" + mInsetsHint
                + "mId=" + mId
                + " mType=" + WindowInsets.Type.toString(mType)
                + (mInitiallyVisible ? " initiallyVisible" : "")
                + " mSurfacePosition=" + mSurfacePosition
                + " mInsetsHint=" + mInsetsHint
                + (mSkipAnimationOnce ? " skipAnimationOnce" : "")
                + "}";
    }

    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        pw.print("InsetsSourceControl type="); pw.print(InsetsState.typeToString(mType));
        pw.print("InsetsSourceControl mId="); pw.print(mId);
        pw.print(" mType="); pw.print(WindowInsets.Type.toString(mType));
        pw.print(" mLeash="); pw.print(mLeash);
        pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible);
        pw.print(" mSurfacePosition="); pw.print(mSurfacePosition);
@@ -212,8 +227,7 @@ public class InsetsSourceControl implements Parcelable {
        pw.println();
    }

    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
            = new Creator<InsetsSourceControl>() {
    public static final @NonNull Creator<InsetsSourceControl> CREATOR = new Creator<>() {
        public InsetsSourceControl createFromParcel(Parcel in) {
            return new InsetsSourceControl(in);
        }
@@ -231,7 +245,7 @@ public class InsetsSourceControl 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));

        final long surfaceToken = proto.start(POSITION);
        proto.write(X, mSurfacePosition.x);
+8 −8
Original line number Diff line number Diff line
@@ -92,8 +92,8 @@ public class ImeInsetsSourceConsumerTest {

    @Test
    public void testImeVisibility() {
        final InsetsSourceControl ime =
                new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE);
        final InsetsSourceControl ime = new InsetsSourceControl(ITYPE_IME, WindowInsets.Type.ime(),
                mLeash, false, new Point(), Insets.NONE);
        mController.onControlsChanged(new InsetsSourceControl[] { ime });

        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
@@ -121,8 +121,8 @@ public class ImeInsetsSourceConsumerTest {
            mController.show(WindowInsets.Type.ime(), true /* fromIme */, null /* statsToken */);

            // set control and verify visibility is applied.
            InsetsSourceControl control =
                    new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE);
            InsetsSourceControl control = new InsetsSourceControl(ITYPE_IME,
                    WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE);
            mController.onControlsChanged(new InsetsSourceControl[] { control });
            // IME show animation should be triggered when control becomes available.
            verify(mController).applyAnimation(
@@ -161,8 +161,8 @@ public class ImeInsetsSourceConsumerTest {
            }

            // set control and verify visibility is applied.
            InsetsSourceControl control = Mockito.spy(
                    new InsetsSourceControl(ITYPE_IME, mLeash, false, new Point(), Insets.NONE));
            InsetsSourceControl control = Mockito.spy(new InsetsSourceControl(ITYPE_IME,
                    WindowInsets.Type.ime(), mLeash, false, new Point(), Insets.NONE));
            // Simulate IME source control set this flag when the target has starting window.
            control.setSkipAnimationOnce(true);

@@ -173,7 +173,7 @@ public class ImeInsetsSourceConsumerTest {
                verify(control).getAndClearSkipAnimationOnce();
                verify(mController).applyAnimation(eq(WindowInsets.Type.ime()),
                        eq(true) /* show */, eq(false) /* fromIme */,
                        eq(expectSkipAnim) /* skipAnim */, null /* statsToken */);
                        eq(expectSkipAnim) /* skipAnim */, eq(null) /* statsToken */);
            }

            // If previously hasViewFocus is false, verify when requesting the IME visible next
@@ -187,7 +187,7 @@ public class ImeInsetsSourceConsumerTest {
                verify(control).getAndClearSkipAnimationOnce();
                verify(mController).applyAnimation(eq(WindowInsets.Type.ime()),
                        eq(true) /* show */, eq(true) /* fromIme */,
                        eq(false) /* skipAnim */, null /* statsToken */);
                        eq(false) /* skipAnim */, eq(null) /* statsToken */);
            }
        });
    }
Loading