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

Commit f2e6749d authored by danielwbhuang's avatar danielwbhuang
Browse files

Filter locales with U extension in language selection stage

1. SystemLocaleCollector#getSupportedLocaleList API may return locales with U extension.
2. In language selection, suggested list should not contain locale which has U extension.

Bug: 388943958
Test: check hsv, atest SystemLocaleSuggestedListPreferenceControllerTest
Flag: EXEMPT bugfix
Change-Id: If975c16fa6ae651076e26ca5ece00ba6d7bd7629
parent 6f1af730
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -131,6 +131,11 @@ public abstract class LocalePickerBaseListPreferenceController extends
                ? getSuggestedLocaleList()
                : getSupportedLocaleList());

        // In language selection, list should not contain locale with U extension.
        if (mParentLocale == null && mIsSuggestedCategory) {
            result.removeAll(getLocalesWithExtension(result));
        }

        final Map<String, Preference> existingPreferences = mPreferences;
        mPreferences = new ArrayMap<>();
        setupPreference(result, existingPreferences);
@@ -246,7 +251,6 @@ public abstract class LocalePickerBaseListPreferenceController extends
        } else {
            Log.d(TAG, "Can not get suggested locales because the locale list is null or empty.");
        }

        return mLocaleOptions;
    }

@@ -337,6 +341,18 @@ public abstract class LocalePickerBaseListPreferenceController extends
                || isNumberingMode();
    }

    @VisibleForTesting
    protected List<LocaleStore.LocaleInfo> getLocalesWithExtension(
            List<LocaleStore.LocaleInfo> inputList) {
        List<LocaleStore.LocaleInfo> checklist = new ArrayList<>();
        for (LocaleStore.LocaleInfo localeInfo : inputList) {
            if (localeInfo.getLocale().hasExtensions()) {
                checklist.add(localeInfo);
            }
        }
        return checklist;
    }

    private List<LocaleStore.LocaleInfo> getUserLocaleList() {
        final List<LocaleStore.LocaleInfo> result = new ArrayList<>();
        final LocaleList localeList = LocalePicker.getLocales();
+30 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ public class SystemLocaleSuggestedListPreferenceControllerTest {
    private static final String KEY_CATEGORY_SYSTEM_SUGGESTED_LIST =
            "system_language_suggested_category";
    private static final String KEY_SUGGESTED = "system_locale_suggested_list";
    private static final String LOCALE_URDU_INDIA = "اردو (بھارت)";

    private Context mContext;
    private FragmentActivity mActivity;
@@ -150,6 +151,35 @@ public class SystemLocaleSuggestedListPreferenceControllerTest {
        mLocaleList.add(mSuggestedLocaleInfo_2);
    }

    private void setupLocaleWithExtensionConditions() {
        mLocaleList = new ArrayList<>();
        when(mSuggestedLocaleInfo_1.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA);
        when(mSuggestedLocaleInfo_1.getLocale()).thenReturn(
                LocaleList.forLanguageTags("ur-IN").get(0));
        mLocaleList.add(mSuggestedLocaleInfo_1);
        when(mSuggestedLocaleInfo_2.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA);
        when(mSuggestedLocaleInfo_2.getLocale()).thenReturn(
                LocaleList.forLanguageTags("ur-IN-u-nu-latn").get(0));
        mLocaleList.add(mSuggestedLocaleInfo_2);
    }

    @Test
    public void removeLocalesWithExtension_localesHasExtension_filterNoExtensionLocales() {
        setupLocaleWithExtensionConditions();
        List<LocaleStore.LocaleInfo> localesWithExtension =
                mController.getLocalesWithExtension(mLocaleList);
        mController.displayPreference(mPreferenceScreen);

        mLocaleList.removeAll(localesWithExtension);
        mController.setupPreference(mLocaleList, mPreferences);

        assertThat(mLocaleList.size()).isEqualTo(1);
        assertThat(mLocaleList.get(0).getFullNameNative()).isEqualTo(LOCALE_URDU_INDIA);
        assertThat(mLocaleList.get(0).getLocale().hasExtensions()).isFalse();
        assertTrue(mPreferenceCategory.isVisible());
        assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1);
    }

    @Test
    public void displayPreference_hasSuggestedPreference_categoryIsVisible() {
        mController.displayPreference(mPreferenceScreen);