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 Original line Diff line number Diff line
@@ -217,7 +217,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    public void updateSurfacePosition(SparseArray<InsetsSourceControl> controls) {
    public void updateSurfacePosition(SparseArray<InsetsSourceControl> controls) {
        for (int i = controls.size() - 1; i >= 0; i--) {
        for (int i = controls.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control = controls.valueAt(i);
            final InsetsSourceControl control = controls.valueAt(i);
            final InsetsSourceControl c = mControls.get(control.getType());
            final InsetsSourceControl c = mControls.get(control.getId());
            if (c == null) {
            if (c == null) {
                continue;
                continue;
            }
            }
@@ -395,7 +395,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                // control may be null if it got revoked.
                // control may be null if it got revoked.
                continue;
                continue;
            }
            }
            state.getSource(control.getType()).setVisible(shown);
            state.getSource(control.getId()).setVisible(shown);
        }
        }
        return getInsetsFromState(state, frame, typeSideMap);
        return getInsetsFromState(state, frame, typeSideMap);
    }
    }
@@ -413,7 +413,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
                // control may be null if it got revoked.
                // control may be null if it got revoked.
                continue;
                continue;
            }
            }
            if (state == null || state.getSource(control.getType()).isVisible()) {
            if (state == null || state.getSource(control.getId()).isVisible()) {
                insets = Insets.max(insets, control.getInsetsHint());
                insets = Insets.max(insets, control.getInsetsHint());
            }
            }
        }
        }
@@ -443,7 +443,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        // TODO: Implement behavior when inset spans over multiple types
        // TODO: Implement behavior when inset spans over multiple types
        for (int i = controls.size() - 1; i >= 0; i--) {
        for (int i = controls.size() - 1; i >= 0; i--) {
            final InsetsSourceControl control = controls.valueAt(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();
            final SurfaceControl leash = control.getLeash();


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


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


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


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


import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.graphics.Insets;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Point;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsState.InternalInsetsType;
import android.view.WindowInsets.Type.InsetsType;


import java.io.PrintWriter;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Objects;
@@ -40,7 +41,8 @@ import java.util.function.Consumer;
 */
 */
public class InsetsSourceControl implements Parcelable {
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 @Nullable SurfaceControl mLeash;
    private final boolean mInitiallyVisible;
    private final boolean mInitiallyVisible;
    private final Point mSurfacePosition;
    private final Point mSurfacePosition;
@@ -52,8 +54,9 @@ public class InsetsSourceControl implements Parcelable {
    private boolean mSkipAnimationOnce;
    private boolean mSkipAnimationOnce;
    private int mParcelableFlags;
    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) {
            boolean initiallyVisible, Point surfacePosition, Insets insetsHint) {
        mId = id;
        mType = type;
        mType = type;
        mLeash = leash;
        mLeash = leash;
        mInitiallyVisible = initiallyVisible;
        mInitiallyVisible = initiallyVisible;
@@ -62,6 +65,7 @@ public class InsetsSourceControl implements Parcelable {
    }
    }


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


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


    public int getId() {
        return mId;
    }

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


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


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


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


    public void dump(String prefix, PrintWriter pw) {
    public void dump(String prefix, PrintWriter pw) {
        pw.print(prefix);
        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(" mLeash="); pw.print(mLeash);
        pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible);
        pw.print(" mInitiallyVisible="); pw.print(mInitiallyVisible);
        pw.print(" mSurfacePosition="); pw.print(mSurfacePosition);
        pw.print(" mSurfacePosition="); pw.print(mSurfacePosition);
@@ -212,8 +227,7 @@ public class InsetsSourceControl implements Parcelable {
        pw.println();
        pw.println();
    }
    }


    public static final @android.annotation.NonNull Creator<InsetsSourceControl> CREATOR
    public static final @NonNull Creator<InsetsSourceControl> CREATOR = new Creator<>() {
            = new Creator<InsetsSourceControl>() {
        public InsetsSourceControl createFromParcel(Parcel in) {
        public InsetsSourceControl createFromParcel(Parcel in) {
            return new InsetsSourceControl(in);
            return new InsetsSourceControl(in);
        }
        }
@@ -231,7 +245,7 @@ public class InsetsSourceControl implements Parcelable {
     */
     */
    public void dumpDebug(ProtoOutputStream proto, long fieldId) {
    public void dumpDebug(ProtoOutputStream proto, long fieldId) {
        final long token = proto.start(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);
        final long surfaceToken = proto.start(POSITION);
        proto.write(X, mSurfacePosition.x);
        proto.write(X, mSurfacePosition.x);
+8 −8
Original line number Original line Diff line number Diff line
@@ -92,8 +92,8 @@ public class ImeInsetsSourceConsumerTest {


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


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


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


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


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