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

Commit 0c728209 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Move setAttachedClientForTesting() to DefaultImeVisibilityApplierTest

This is a mechanical refactoring CL, which moves

  InputMethodManagerService#setAttachedClientForTesting()

to DefaultImeVisibilityApplierTest, where it is being used.

This is test only change. There must be no observable behavior change.

Bug: 350386877
Bug: 352615651
Flag: TEST_ONLY
Test: atest FrameworksInputMethodSystemServerTests
Change-Id: I6c1c9f10d35f6bc1ed1f40640b8ff06434b3fe92
parent 58c0e6fb
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -1846,13 +1846,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        }
    }

    @VisibleForTesting
    void setAttachedClientForTesting(@NonNull ClientState cs) {
        synchronized (ImfLock.class) {
            getUserData(mCurrentUserId).mCurClient = cs;
        }
    }

    @GuardedBy("ImfLock.class")
    private boolean isShowRequestedForCurrentWindow(@UserIdInt int userId) {
        final var userData = getUserData(userId);
+14 −3
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import static org.mockito.Mockito.when;

import static java.util.Objects.requireNonNull;

import android.annotation.Nullable;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
@@ -50,6 +51,7 @@ import android.view.inputmethod.ImeTracker;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.InputBindResult;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.inputmethod.StartInputFlags;
@@ -75,7 +77,7 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
        super.setUp();
        synchronized (ImfLock.class) {
            mVisibilityApplier = mInputMethodManagerService.getVisibilityApplierLocked();
            mInputMethodManagerService.setAttachedClientForTesting(requireNonNull(
            setAttachedClientLocked(requireNonNull(
                    mInputMethodManagerService.getClientStateLocked(mMockInputMethodClient)));
        }
    }
@@ -168,7 +170,9 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
        // Init a IME target client on the secondary display to show IME.
        mInputMethodManagerService.addClient(mMockInputMethodClient, mMockRemoteInputConnection,
                10 /* selfReportedDisplayId */);
        mInputMethodManagerService.setAttachedClientForTesting(null);
        synchronized (ImfLock.class) {
            setAttachedClientLocked(null);
        }
        startInputOrWindowGainedFocus(mWindowToken, SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        final var statsToken = ImeTracker.Token.empty();
@@ -206,7 +210,9 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe

    @Test
    public void testApplyImeVisibility_hideImeWhenUnbinding() {
        mInputMethodManagerService.setAttachedClientForTesting(null);
        synchronized (ImfLock.class) {
            setAttachedClientLocked(null);
        }
        startInputOrWindowGainedFocus(mWindowToken, SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        ExtendedMockito.spyOn(mVisibilityApplier);

@@ -233,6 +239,11 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
        }
    }

    @GuardedBy("ImfLock.class")
    private void setAttachedClientLocked(@Nullable ClientState cs) {
        mInputMethodManagerService.getUserData(mUserId).mCurClient = cs;
    }

    private InputBindResult startInputOrWindowGainedFocus(IBinder windowToken, int softInputMode) {
        return mInputMethodManagerService.startInputOrWindowGainedFocus(
                StartInputReason.WINDOW_FOCUS_GAIN /* startInputReason */,