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

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

Merge "Remove locale and language from ImeSubtypeListItem" into main

parents ce42c9f2 723142ae
Loading
Loading
Loading
Loading
+3 −29
Original line number Diff line number Diff line
@@ -118,14 +118,9 @@ final class InputMethodSubtypeSwitchingController {
         */
        final boolean mSuitableForHardware;

        final boolean mIsSystemLocale;

        final boolean mIsSystemLanguage;

        ImeSubtypeListItem(@NonNull CharSequence imeName, @Nullable CharSequence subtypeName,
                @Nullable CharSequence layoutName, @NonNull InputMethodInfo imi, int subtypeIndex,
                boolean showInImeSwitcherMenu, boolean isAuxiliary, boolean suitableForHardware,
                @Nullable String subtypeLocale, @NonNull String systemLocale) {
                boolean showInImeSwitcherMenu, boolean isAuxiliary, boolean suitableForHardware) {
            mImeName = imeName;
            mSubtypeName = subtypeName;
            mLayoutName = layoutName;
@@ -134,22 +129,6 @@ final class InputMethodSubtypeSwitchingController {
            mShowInImeSwitcherMenu = showInImeSwitcherMenu;
            mIsAuxiliary = isAuxiliary;
            mSuitableForHardware = suitableForHardware;
            if (TextUtils.isEmpty(subtypeLocale)) {
                mIsSystemLocale = false;
                mIsSystemLanguage = false;
            } else {
                mIsSystemLocale = subtypeLocale.equals(systemLocale);
                if (mIsSystemLocale) {
                    mIsSystemLanguage = true;
                } else {
                    final String systemLanguage = LocaleUtils.getLanguageFromLocaleString(
                            systemLocale);
                    final String subtypeLanguage = LocaleUtils.getLanguageFromLocaleString(
                            subtypeLocale);
                    mIsSystemLanguage = systemLanguage.length() >= 2
                            && systemLanguage.equals(subtypeLanguage);
                }
            }
        }

        /**
@@ -190,8 +169,6 @@ final class InputMethodSubtypeSwitchingController {
                    + " mShowInImeSwitcherMenu=" + mShowInImeSwitcherMenu
                    + " mIsAuxiliary=" + mIsAuxiliary
                    + " mSuitableForHardware=" + mSuitableForHardware
                    + " mIsSystemLocale=" + mIsSystemLocale
                    + " mIsSystemLanguage=" + mIsSystemLanguage
                    + "}";
        }

@@ -279,7 +256,6 @@ final class InputMethodSubtypeSwitchingController {
        final int userId = settings.getUserId();
        final Context userAwareContext = context.getUserId() == userId
                ? context : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
        final String mSystemLocaleStr = SystemLocaleWrapper.get(userId).get(0).toLanguageTag();

        final var res = new ArrayList<ImeSubtypeListItem>();
        final var imis = settings.getEnabledInputMethodList();
@@ -296,8 +272,7 @@ final class InputMethodSubtypeSwitchingController {
            if (subtypes.isEmpty()) {
                res.add(new ImeSubtypeListItem(imeLabel, null /* subtypeName */,
                        null /* layoutName */, imi, NOT_A_SUBTYPE_INDEX, showInImeSwitcherMenu,
                        false /* isAuxiliary */, true /* suitableForHardware */, null,
                        mSystemLocaleStr));
                        false /* isAuxiliary */, true /* suitableForHardware */));
            } else {
                final var hashCodes = new ArraySet<Integer>();
                for (int j = 0; j < subtypes.size(); j++) {
@@ -321,8 +296,7 @@ final class InputMethodSubtypeSwitchingController {
                            : subtype.getLayoutDisplayName(userAwareContext, appInfo);
                    res.add(new ImeSubtypeListItem(imeLabel, subtypeLabel, layoutName,
                            imi, j, showInImeSwitcherMenu, subtype.isAuxiliary(),
                            subtype.isSuitableForPhysicalKeyboardLayoutMapping(),
                            subtype.getLocale(), mSystemLocaleStr));
                            subtype.isSuitableForPhysicalKeyboardLayoutMapping()));
                }
            }
        }
+3 −59
Original line number Diff line number Diff line
@@ -54,37 +54,6 @@ public final class InputMethodSubtypeSwitchingControllerTest {
    private static final int TEST_IS_DEFAULT_RES_ID = 0;
    private static final String SYSTEM_LOCALE = "en_US";

    @Test
    public void testImeSubtypeListItem() {
        final var items = new ArrayList<ImeSubtypeListItem>();
        createTestItems(items, "LatinIme",
                List.of("en_US", "fr", "en", "en_uk", "enn", "e", "EN_US"),
                true /* suitableForHardware */);
        final ImeSubtypeListItem item_en_us = items.get(0);
        final ImeSubtypeListItem item_fr = items.get(1);
        final ImeSubtypeListItem item_en = items.get(2);
        final ImeSubtypeListItem item_en_uk = items.get(3);
        final ImeSubtypeListItem item_enn = items.get(4);
        final ImeSubtypeListItem item_e = items.get(5);
        final ImeSubtypeListItem item_en_us_allcaps = items.get(6);

        assertTrue(item_en_us.mIsSystemLocale);
        assertFalse(item_fr.mIsSystemLocale);
        assertFalse(item_en.mIsSystemLocale);
        assertFalse(item_en_uk.mIsSystemLocale);
        assertFalse(item_enn.mIsSystemLocale);
        assertFalse(item_e.mIsSystemLocale);
        assertFalse(item_en_us_allcaps.mIsSystemLocale);

        assertTrue(item_en_us.mIsSystemLanguage);
        assertFalse(item_fr.mIsSystemLanguage);
        assertTrue(item_en.mIsSystemLanguage);
        assertTrue(item_en_uk.mIsSystemLanguage);
        assertFalse(item_enn.mIsSystemLanguage);
        assertFalse(item_e.mIsSystemLanguage);
        assertFalse(item_en_us_allcaps.mIsSystemLanguage);
    }

    /** Verifies the static mode. */
    @Test
    public void testModeStatic() {
@@ -552,31 +521,6 @@ public final class InputMethodSubtypeSwitchingControllerTest {
        assertEquals("Equivalent items should have the same order.", 0, item.compareTo(equivalent));
    }

    /**
     * Verifies that the system locale and system language do not the influence comparison order.
     */
    @Test
    public void testCompareSystemLocaleSystemLanguage() {
        final var component = new ComponentName("com.example.ime", "Ime");
        final var japanese = createTestItem(component, "Ime", "A", "ja_JP", 0);
        final var systemLanguage = createTestItem(component, "Ime", "A", "en_GB", 0);
        final var systemLocale = createTestItem(component, "Ime", "A", "en_US", 0);

        assertFalse(japanese.mIsSystemLanguage);
        assertFalse(japanese.mIsSystemLocale);
        assertTrue(systemLanguage.mIsSystemLanguage);
        assertFalse(systemLanguage.mIsSystemLocale);
        assertTrue(systemLocale.mIsSystemLanguage);
        assertTrue(systemLocale.mIsSystemLocale);

        assertEquals("System language shouldn't influence comparison over non-system language.",
                0, japanese.compareTo(systemLanguage));
        assertEquals("System locale shouldn't influence comparison over non-system locale.",
                0, japanese.compareTo(systemLocale));
        assertEquals("System locale shouldn't influence comparison over system language.",
                0, systemLanguage.compareTo(systemLocale));
    }

    /** Verifies that the subtype name does not influence the comparison order. */
    @Test
    public void testCompareSubtypeName() {
@@ -672,12 +616,12 @@ public final class InputMethodSubtypeSwitchingControllerTest {
                final String subtypeLocale = subtypeLocales.get(i);
                items.add(new ImeSubtypeListItem(imeName, subtypeLocale, null /* layoutName */,
                        imi, i, true /* showInImeSwitcherMenu */, false /* isAuxiliary */,
                        suitableForHardware, subtypeLocale, SYSTEM_LOCALE));
                        suitableForHardware));
            }
        } else {
            items.add(new ImeSubtypeListItem(imeName, null /* subtypeName */, null /* layoutName */,
                    imi, NOT_A_SUBTYPE_INDEX, false /* showInImeSwitcherMenu */,
                    false /* isAuxiliary */, suitableForHardware, null, SYSTEM_LOCALE));
                    false /* isAuxiliary */, suitableForHardware));
        }
    }

@@ -701,7 +645,7 @@ public final class InputMethodSubtypeSwitchingControllerTest {
                true /* supportsSwitchingToNextInputMethod */);
        return new ImeSubtypeListItem(imeName, subtypeName, null /* layoutName */,
                imi, subtypeIndex, true /* showInImeSwitcherMenu */, false /* isAuxiliary */,
                true /* suitableForHardware */, subtypeLocale, SYSTEM_LOCALE);
                true /* suitableForHardware */);
    }

    /**