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

Commit 5f79ba7d authored by Wilson Wu's avatar Wilson Wu
Browse files

Clean up setInputChannelLocked

-. Rename setInputChannelLocked and add a static
   method for checking same InputChannel.

Suppose we need to handle the flush pending events
when the input channel is modified based on CL[1],
CL[2] and CL[3].

This is a mechanical refactor and it should no
user visible change.

[1]: Ibe26311edd0060cdcae80194f1753482e635786f
[2]: I7e0b6a3c43cbe72f8762991f5d36560feebd214b
[3]: If8317941dd1c6d5db77f1239b9a9f45d49997df9

Bug: 236920321
Test: atest CtsInputMethodTestCases
Change-Id: I4f0d2404705a8f93de345571136690dd408d1132
parent 62447342
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -921,7 +921,7 @@ public final class InputMethodManager {
                        mRequestUpdateCursorAnchorInfoMonitorMode =
                                REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE;

                        setInputChannelLocked(res.channel);
                        updateInputChannelLocked(res.channel);
                        mCurMethod = res.method; // for @UnsupportedAppUsage
                        mCurBindState = new BindState(res);
                        mCurId = res.id; // for @UnsupportedAppUsage
@@ -1623,7 +1623,7 @@ public final class InputMethodManager {
    void clearBindingLocked() {
        if (DEBUG) Log.v(TAG, "Clearing binding!");
        clearConnectionLocked();
        setInputChannelLocked(null);
        updateInputChannelLocked(null);
        mCurId = null; // for @UnsupportedAppUsage
        mCurMethod = null; // for @UnsupportedAppUsage
        // We only reset sequence number for input method, but not accessibility.
@@ -1648,28 +1648,38 @@ public final class InputMethodManager {
        mAccessibilityInputMethodSession.clear();
    }

    void setInputChannelLocked(InputChannel channel) {
        if (mCurChannel == channel) {
    @GuardedBy("mH")
    private void updateInputChannelLocked(InputChannel channel) {
        if (areSameInputChannel(mCurChannel, channel)) {
            return;
        }
        if (mCurChannel != null && channel != null
                && mCurChannel.getToken() == channel.getToken()) {
        // TODO(b/238720598) : Requirements when design a new protocol for InputChannel
        // channel is a dupe of 'mCurChannel', because they have the same token, and represent
        // the same connection. Ignore the incoming channel and keep using 'mCurChannel' to
        // avoid confusing the InputEventReceiver.
            return;
        }
        if (mCurSender != null) {
            flushPendingEventsLocked();
            mCurSender.dispose();
            mCurSender = null;
        }

        if (mCurChannel != null) {
            mCurChannel.dispose();
        }
        mCurChannel = channel;
    }

    private static boolean areSameInputChannel(@Nullable InputChannel lhs,
            @Nullable InputChannel rhs) {
        if (lhs == rhs) {
            return true;
        }
        if (lhs == null || rhs == null) {
            return false;
        }
        return lhs.getToken() == rhs.getToken();
    }

    /**
     * Reset all of the state associated with a served view being connected
     * to an input method
@@ -2384,7 +2394,7 @@ public final class InputMethodManager {
            }
            mVirtualDisplayToScreenMatrix = res.getVirtualDisplayToScreenMatrix();
            if (res.id != null) {
                setInputChannelLocked(res.channel);
                updateInputChannelLocked(res.channel);
                mCurMethod = res.method; // for @UnsupportedAppUsage
                mCurBindState = new BindState(res);
                mAccessibilityInputMethodSession.clear();