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

Commit 364055a0 authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "Update flag value checks in IME tests" into main

parents d86200e7 5a55822f
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.LocaleList;
import android.os.Parcel;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableString;
@@ -87,6 +88,8 @@ public class EditorInfoTest {
        TEST_EDITOR_INFO.targetInputMethodUser = UserHandle.of(TEST_USER_ID);
    }

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    /**
     * Makes sure that {@code null} {@link EditorInfo#targetInputMethodUser} can be copied via
     * {@link Parcel}.
@@ -522,7 +525,9 @@ public class EditorInfoTest {
        info.setSupportedHandwritingGestures(Arrays.asList(SelectGesture.class));
        info.setSupportedHandwritingGesturePreviews(
                Stream.of(SelectGesture.class).collect(Collectors.toSet()));
        if (Flags.editorinfoHandwritingEnabled()) {
        final boolean isStylusHandwritingEnabled =
                mFlagsValueProvider.getBoolean(Flags.FLAG_EDITORINFO_HANDWRITING_ENABLED);
        if (isStylusHandwritingEnabled) {
            info.setStylusHandwritingEnabled(true);
        }
        info.packageName = "android.view.inputmethod";
@@ -548,8 +553,7 @@ public class EditorInfoTest {
                        + "prefix2: hintLocales=[en,es,zh]\n"
                        + "prefix2: supportedHandwritingGestureTypes=SELECT\n"
                        + "prefix2: supportedHandwritingGesturePreviewTypes=SELECT\n"
                        + "prefix2: isStylusHandwritingEnabled="
                                + Flags.editorinfoHandwritingEnabled() + "\n"
                        + "prefix2: isStylusHandwritingEnabled=" + isStylusHandwritingEnabled + "\n"
                        + "prefix2: contentMimeTypes=[image/png]\n"
                        + "prefix2: targetInputMethodUserId=10\n");
    }
+7 −5
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.Parcel;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -43,8 +45,9 @@ import org.junit.runner.RunWith;
public class InputMethodInfoTest {

    @Rule
    public SetFlagsRule mSetFlagsRule =
            new SetFlagsRule(SetFlagsRule.DefaultInitValueType.DEVICE_DEFAULT);
    public SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    @Test
    public void testEqualsAndHashCode() throws Exception {
@@ -70,7 +73,7 @@ public class InputMethodInfoTest {
        assertThat(imi.supportsInlineSuggestionsWithTouchExploration(), is(false));
        assertThat(imi.supportsStylusHandwriting(), is(false));
        assertThat(imi.createStylusHandwritingSettingsActivityIntent(), equalTo(null));
        if (Flags.imeSwitcherRevampApi()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_IME_SWITCHER_REVAMP_API)) {
            assertThat(imi.createImeLanguageSettingsActivityIntent(), equalTo(null));
        }
    }
@@ -121,9 +124,8 @@ public class InputMethodInfoTest {
    }

    @Test
    @EnableFlags(android.companion.virtual.flags.Flags.FLAG_VDM_CUSTOM_IME)
    public void testIsVirtualDeviceOnly() throws Exception {
        mSetFlagsRule.enableFlags(android.companion.virtual.flags.Flags.FLAG_VDM_CUSTOM_IME);

        final InputMethodInfo imi = buildInputMethodForTest(R.xml.ime_meta_virtual_device_only);

        assertThat(imi.isVirtualDeviceOnly(), is(true));
+7 −5
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ public class InputMethodServiceTest {
    private static final String DISABLE_SHOW_IME_WITH_HARD_KEYBOARD_CMD =
            "settings put secure " + Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD + " 0";

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    private Instrumentation mInstrumentation;
    private UiDevice mUiDevice;
    private Context mContext;
@@ -95,7 +97,7 @@ public class InputMethodServiceTest {
    private boolean mShowImeWithHardKeyboardEnabled;

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
    public final CheckFlagsRule mCheckFlagsRule = new CheckFlagsRule(mFlagsValueProvider);

    @Before
    public void setUp() throws Exception {
@@ -159,7 +161,7 @@ public class InputMethodServiceTest {

        // Press home key to hide soft keyboard.
        Log.i(TAG, "Press home");
        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            assertThat(mUiDevice.pressHome()).isTrue();
            // The IME visibility is only sent at the end of the animation. Therefore, we have to
            // wait until the visibility was sent to the server and the IME window hidden.
@@ -774,7 +776,7 @@ public class InputMethodServiceTest {
        backButtonUiObject.click();
        mInstrumentation.waitForIdleSync();

        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            // The IME visibility is only sent at the end of the animation. Therefore, we have to
            // wait until the visibility was sent to the server and the IME window hidden.
            eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isFalse());
@@ -812,7 +814,7 @@ public class InputMethodServiceTest {
        backButtonUiObject.longClick();
        mInstrumentation.waitForIdleSync();

        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            // The IME visibility is only sent at the end of the animation. Therefore, we have to
            // wait until the visibility was sent to the server and the IME window hidden.
            eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isFalse());
@@ -900,7 +902,7 @@ public class InputMethodServiceTest {
        assertWithMessage("Input Method Switcher Menu is shown")
                .that(isInputMethodPickerShown(imm))
                .isTrue();
        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            // The IME visibility is only sent at the end of the animation. Therefore, we have to
            // wait until the visibility was sent to the server and the IME window hidden.
            eventually(() -> assertThat(mInputMethodService.isInputViewShown()).isFalse());
+7 −5
Original line number Diff line number Diff line
@@ -76,8 +76,10 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTestBase {

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
    public final CheckFlagsRule mCheckFlagsRule = new CheckFlagsRule(mFlagsValueProvider);
    private DefaultImeVisibilityApplier mVisibilityApplier;

    @Before
@@ -151,7 +153,7 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
            mVisibilityApplier.applyImeVisibility(mWindowToken, ImeTracker.Token.empty(),
                    STATE_HIDE_IME_EXPLICIT, eq(SoftInputShowHideReason.NOT_SET), mUserId);
        }
        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            verifySetImeVisibility(true /* setVisible */, false /* invoked */);
            verifySetImeVisibility(false /* setVisible */, true /* invoked */);
        } else {
@@ -168,7 +170,7 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
            mVisibilityApplier.applyImeVisibility(mWindowToken, ImeTracker.Token.empty(),
                    STATE_HIDE_IME_NOT_ALWAYS, eq(SoftInputShowHideReason.NOT_SET), mUserId);
        }
        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            verifySetImeVisibility(true /* setVisible */, false /* invoked */);
            verifySetImeVisibility(false /* setVisible */, true /* invoked */);
        } else {
@@ -182,7 +184,7 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
            mVisibilityApplier.applyImeVisibility(mWindowToken, ImeTracker.Token.empty(),
                    STATE_SHOW_IME_IMPLICIT, eq(SoftInputShowHideReason.NOT_SET), mUserId);
        }
        if (Flags.refactorInsetsController()) {
        if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
            verifySetImeVisibility(true /* setVisible */, true /* invoked */);
            verifySetImeVisibility(false /* setVisible */, false /* invoked */);
        } else {
@@ -260,7 +262,7 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe
            verify(mVisibilityApplier).applyImeVisibility(
                    eq(mWindowToken), any(), eq(STATE_HIDE_IME),
                    eq(SoftInputShowHideReason.NOT_SET), eq(mUserId) /* userId */);
            if (!Flags.refactorInsetsController()) {
            if (!mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                verify(mInputMethodManagerService.mWindowManagerInternal).hideIme(eq(mWindowToken),
                        eq(displayIdToShowIme), and(not(eq(statsToken)), notNull()));
            }
+13 −8
Original line number Diff line number Diff line
@@ -39,8 +39,10 @@ import static org.mockito.Mockito.when;
import android.os.IBinder;
import android.os.LocaleList;
import android.os.RemoteException;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.Flags;
import android.window.ImeOnBackInvokedDispatcher;

import com.android.internal.inputmethod.IInputMethodClient;
@@ -89,6 +91,9 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            };
    private static final int DEFAULT_SOFT_INPUT_FLAG =
            StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.IS_TEXT_EDITOR;

    private final DeviceFlagsValueProvider mFlagsValueProvider = new DeviceFlagsValueProvider();

    @Mock
    VirtualDeviceManagerInternal mMockVdmInternal;

@@ -125,7 +130,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            case SOFT_INPUT_STATE_UNSPECIFIED:
                boolean showSoftInput =
                        (mSoftInputAdjustment == SOFT_INPUT_ADJUST_RESIZE) || mIsLargeScreen;
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    verifySetImeVisibility(true /* setVisible */, showSoftInput /* invoked */);
                    // A hide can only be triggered if there is no editorFocused, which this test
                    // always sets.
@@ -141,7 +146,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
                break;
            case SOFT_INPUT_STATE_VISIBLE:
            case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    verifySetImeVisibility(true /* setVisible */, true /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
@@ -150,7 +155,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
                }
                break;
            case SOFT_INPUT_STATE_UNCHANGED:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
@@ -160,7 +165,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
                break;
            case SOFT_INPUT_STATE_HIDDEN:
            case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    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
@@ -192,7 +197,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            case SOFT_INPUT_STATE_UNSPECIFIED:
                boolean hideSoftInput =
                        (mSoftInputAdjustment != SOFT_INPUT_ADJUST_RESIZE) && !mIsLargeScreen;
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    // 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
@@ -209,7 +214,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
            case SOFT_INPUT_STATE_VISIBLE:
            case SOFT_INPUT_STATE_HIDDEN:
            case SOFT_INPUT_STATE_UNCHANGED: // Do nothing
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    verifySetImeVisibility(true /* setVisible */, false /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
@@ -218,7 +223,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
                }
                break;
            case SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    verifySetImeVisibility(true /* setVisible */, true /* invoked */);
                    verifySetImeVisibility(false /* setVisible */, false /* invoked */);
                } else {
@@ -227,7 +232,7 @@ public class InputMethodManagerServiceWindowGainedFocusTest
                }
                break;
            case SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (mFlagsValueProvider.getBoolean(Flags.FLAG_REFACTOR_INSETS_CONTROLLER)) {
                    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