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

Commit a944a227 authored by Antonio Kantek's avatar Antonio Kantek
Browse files

Fix DefaultImeVisibilityApplierTest on auto surfaces

Make mUserId private in InputMethodBindingController so it can be
properly mocked in tests.

Fix: 350205242
Test: atest FrameworksInputMethodSystemServerTests:com.android.server.inputmethod.DefaultImeVisibilityApplierTest
Test: atest FrameworksInputMethodSystemServerTests:com.android.server.inputmethod.UserDataRepositoryTest
Flag: EXEMPT bug fix
Change-Id: I5e3f27411207355da7021213e28144c23670c062
parent 85dd6093
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -103,8 +103,8 @@ final class AutofillSuggestionsController {

        // Note that current user ID is guaranteed to be userId.
        final var imeId = mBindingController.getSelectedMethodId();
        final InputMethodInfo imi = InputMethodSettingsRepository.get(mBindingController.mUserId)
                .getMethodMap().get(imeId);
        final InputMethodInfo imi = InputMethodSettingsRepository.get(
                mBindingController.getUserId()).getMethodMap().get(imeId);
        if (imi == null || !isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) {
            callback.onInlineSuggestionsUnsupported();
            return;
+6 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ final class InputMethodBindingController {
    /** Time in milliseconds that the IME service has to bind before it is reconnected. */
    static final long TIME_TO_RECONNECT = 3 * 1000;

    @UserIdInt final int mUserId;
    @UserIdInt private final int mUserId;
    @NonNull private final InputMethodManagerService mService;
    @NonNull private final Context mContext;
    @NonNull private final AutofillSuggestionsController mAutofillController;
@@ -657,4 +657,9 @@ final class InputMethodBindingController {
    int getDeviceIdToShowIme() {
        return mDeviceIdToShowIme;
    }

    @UserIdInt
    int getUserId() {
        return mUserId;
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -2051,7 +2051,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher,
            @NonNull InputMethodBindingController bindingController) {

        final int userId = bindingController.mUserId;
        final int userId = bindingController.getUserId();
        final var userData = getUserData(userId);

        // Compute the final shown display ID with validated cs.selfReportedDisplayId for this
@@ -2068,8 +2068,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        // Potentially override the selected input method if the new display belongs to a virtual
        // device with a custom IME.
        String selectedMethodId = bindingController.getSelectedMethodId();
        final String deviceMethodId = computeCurrentDeviceMethodIdLocked(bindingController.mUserId,
                selectedMethodId);
        final String deviceMethodId = computeCurrentDeviceMethodIdLocked(
                bindingController.getUserId(), selectedMethodId);
        if (deviceMethodId == null) {
            mVisibilityStateComputer.getImePolicy().setImeHiddenByDisplayPolicy(true);
        } else if (!Objects.equals(deviceMethodId, selectedMethodId)) {
@@ -2567,7 +2567,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

    @GuardedBy("ImfLock.class")
    void clearClientSessionsLocked(@NonNull InputMethodBindingController bindingController) {
        final int userId = bindingController.mUserId;
        final int userId = bindingController.getUserId();
        final var userData = getUserData(userId);
        if (bindingController.getCurMethod() != null) {
            // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
@@ -3856,7 +3856,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    + " cs=" + cs);
        }

        final int userId = bindingController.mUserId;
        final int userId = bindingController.getUserId();
        final var userData = getUserData(userId);
        final boolean sameWindowFocused = userData.mImeBindingState.mFocusedWindow == windowToken;
        final boolean isTextEditor = (startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0;
@@ -3890,7 +3890,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    null, null, null, null, -1, false);
        }

        userData.mImeBindingState = new ImeBindingState(bindingController.mUserId, windowToken,
        userData.mImeBindingState = new ImeBindingState(bindingController.getUserId(), windowToken,
                softInputMode, cs, editorInfo);
        mFocusedWindowPerceptible.put(windowToken, true);

+1 −0
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public class InputMethodManagerServiceTestBase {
        // Injecting and mocked InputMethodBindingController and InputMethod.
        mMockInputMethodInvoker = IInputMethodInvoker.create(mMockInputMethod);
        mInputManagerGlobalSession = InputManagerGlobal.createTestSession(mMockIInputManager);
        when(mMockInputMethodBindingController.getUserId()).thenReturn(mCallingUserId);
        synchronized (ImfLock.class) {
            when(mMockInputMethodBindingController.getCurMethod())
                    .thenReturn(mMockInputMethodInvoker);
+2 −2
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public final class UserDataRepositoryTest {

        // Assert UserDataRepository called the InputMethodBindingController creator function.
        verify(bindingControllerFactorySpy).apply(ANY_USER_ID);
        assertThat(allUserData.get(0).mBindingController.mUserId).isEqualTo(ANY_USER_ID);
        assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID);
    }

    @Test
@@ -149,7 +149,7 @@ public final class UserDataRepositoryTest {
        assertThat(allUserData.get(0).mUserId).isEqualTo(ANY_USER_ID);

        // Assert UserDataRepository called the InputMethodBindingController creator function.
        assertThat(allUserData.get(0).mBindingController.mUserId).isEqualTo(ANY_USER_ID);
        assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID);
    }

    private List<UserDataRepository.UserData> collectUserData(UserDataRepository repository) {