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

Commit af0dc32c authored by Felix Stern's avatar Felix Stern
Browse files

Adjusting InputMethodManagerServiceWindowGainedFocusTest for refactor

Previously, we called directly into IMMS#{show,hide}SoftInput, but with the refactor, we only set the IME visibility. Therefore, adjusting the test.

Test: atest FrameworksInputMethodSystemServerTests:com.android.server.inputmethod.InputMethodManagerServiceWindowGainedFocusTest
Flag: android.view.inputmethod.refactor_insets_controller
Fix: 355145573
Change-Id: I70c8a1d625304182f840ede792a9b9a8dc7e9234
parent 9cd20e70
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.ServiceManager;
import android.util.ArraySet;
import android.view.InputChannel;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ImeTracker;
import android.window.ImeOnBackInvokedDispatcher;

import androidx.test.platform.app.InstrumentationRegistry;
@@ -260,6 +261,11 @@ public class InputMethodManagerServiceTestBase {
                unusedUserId -> mMockInputMethodBindingController);
        spyOn(mInputMethodManagerService);

        synchronized (ImfLock.class) {
            doReturn(true).when(mInputMethodManagerService).setImeVisibilityOnFocusedWindowClient(
                    anyBoolean(), any(UserData.class), any(ImeTracker.Token.class));
        }

        // Start a InputMethodManagerService.Lifecycle to publish and manage the lifecycle of
        // InputMethodManagerService, which is closer to the real situation.
        InputMethodManagerService.Lifecycle lifecycle =
@@ -347,6 +353,14 @@ public class InputMethodManagerServiceTestBase {
                        anyInt() /* flags */, any() /* resultReceiver */);
    }

    protected void verifySetImeVisibility(boolean setVisible, boolean invoked) {
        synchronized (ImfLock.class) {
            verify(mInputMethodManagerService,
                    times(invoked ? 1 : 0)).setImeVisibilityOnFocusedWindowClient(eq(setVisible),
                    any(UserData.class), any(ImeTracker.Token.class));
        }
    }

    protected void createSessionForClient(IInputMethodClient client) {
        synchronized (ImfLock.class) {
            ClientState cs = mInputMethodManagerService.getClientStateLocked(client);
+77 −26
Original line number Diff line number Diff line
@@ -125,27 +125,52 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            case SOFT_INPUT_STATE_UNSPECIFIED:
                boolean showSoftInput =
                        (mSoftInputAdjustment == SOFT_INPUT_ADJUST_RESIZE) || mIsLargeScreen;
                verifyShowSoftInput(
                        showSoftInput /* setVisible */, showSoftInput /* showSoftInput */);
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, showSoftInput /* invoked */);
                    // A hide can only be triggered if there is no editorFocused, which this test
                    // always sets.
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(showSoftInput /* setVisible */,
                            showSoftInput /* showSoftInput */);
                    // Soft input was hidden by default, so it doesn't need to call
                    // {@code IMS#hideSoftInput()}.
                verifyHideSoftInput(!showSoftInput /* setNotVisible */, false /* hideSoftInput */);
                    verifyHideSoftInput(!showSoftInput /* setNotVisible */,
                            false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_VISIBLE:
            case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, true /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(true /* setVisible */, true /* showSoftInput */);
                    verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_UNCHANGED: // Do nothing
            case SOFT_INPUT_STATE_UNCHANGED:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
                    verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_HIDDEN:
            case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    // In this case, we don't have to manipulate the requested visible types of
                    // the WindowState, as they're already in the correct state
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
                    // Soft input was hidden by default, so it doesn't need to call
                    // {@code IMS#hideSoftInput()}.
                    verifyHideSoftInput(true /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            default:
                throw new IllegalStateException(
@@ -167,26 +192,52 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            case SOFT_INPUT_STATE_UNSPECIFIED:
                boolean hideSoftInput =
                        (mSoftInputAdjustment != SOFT_INPUT_ADJUST_RESIZE) && !mIsLargeScreen;
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    // A show can only be triggered in forward navigation
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                    // A hide can only be triggered if there is no editorFocused, which this test
                    // always sets.
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
                    // Soft input was hidden by default, so it doesn't need to call
                    // {@code IMS#hideSoftInput()}.
                verifyHideSoftInput(hideSoftInput /* setNotVisible */, false /* hideSoftInput */);
                    verifyHideSoftInput(hideSoftInput /* setNotVisible */,
                            false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_VISIBLE:
            case SOFT_INPUT_STATE_HIDDEN:
            case SOFT_INPUT_STATE_UNCHANGED: // Do nothing
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
                    verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, true /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(true /* setVisible */, true /* showSoftInput */);
                    verifyHideSoftInput(false /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    // In this case, we don't have to manipulate the requested visible types of
                    // the WindowState, as they're already in the correct state
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
                    verifyShowSoftInput(false /* setVisible */, false /* showSoftInput */);
                    // Soft input was hidden by default, so it doesn't need to call
                    // {@code IMS#hideSoftInput()}.
                    verifyHideSoftInput(true /* setNotVisible */, false /* hideSoftInput */);
                }
                break;
            default:
                throw new IllegalStateException(