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

Commit 8f56e5be authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Remove getSourceConsumer special case for IME

Previously there was a cyclic dependency in getSourceConsumer, as it
reads the value of mImeSourceConsumer, but it is also used to initialize
that field.

This removes the special case for IME from getSourceConsumer, as we
always add the IME to the mSourceConsumers array, and we never remove
it. If the type of the consumer is ime, the id must be ID_IME, so this
will always retrieve the same already-created instance.

This also allows making the ID field in InsetsSourceConsumer final.

Flag: EXEMPT bugfix
Test: n/a
Bug: 281029564
Change-Id: Ib197e50bcb1059d3ae9d9ee0d47a2fab1b1a57d0
parent 626cf178
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -1816,13 +1816,12 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                cancelAnimation(runner, true /* invokeCallback */);
            }
        }
        if (type == ime()) {
            abortPendingImeControlRequest();
        }
        if (consumer.getType() != ime()) {
        if (type != ime()) {
            // IME consumer should always be there since we need to communicate with
            // InputMethodManager no matter we have the control or not.
            // InputMethodManager no matter if we have the control or not.
            mSourceConsumers.remove(consumer.getId());
        } else {
            abortPendingImeControlRequest();
        }
    }

@@ -1901,20 +1900,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    }

    @VisibleForTesting
    public @NonNull InsetsSourceConsumer getSourceConsumer(int id, int type) {
    @NonNull
    public final InsetsSourceConsumer getSourceConsumer(int id, @InsetsType int type) {
        InsetsSourceConsumer consumer = mSourceConsumers.get(id);
        if (consumer != null) {
            return consumer;
        }
        // ImeSourceConsumer is created using getSourceConsumer, so it is initially null here.
        if (type == ime() && mImeSourceConsumer != null) {
            // WindowInsets.Type.ime() should be only provided by one source.
            mSourceConsumers.remove(mImeSourceConsumer.getId());
            consumer = mImeSourceConsumer;
            consumer.setId(id);
        } else {
        consumer = mConsumerCreator.apply(this, id, type);
        }
        mSourceConsumers.put(id, consumer);
        return consumer;
    }
+1 −5
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class InsetsSourceConsumer {

    protected final InsetsController mController;
    protected final InsetsState mState;
    private int mId;
    private final int mId;
    @InsetsType
    private final int mType;

@@ -235,10 +235,6 @@ public class InsetsSourceConsumer {
        return mId;
    }

    void setId(int id) {
        mId = id;
    }

    @InsetsType int getType() {
        return mType;
    }