From 9859b8b0b01a4fca8793aecfc6d5fb3d93de9a31 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Fri, 15 Feb 2019 15:46:58 -0800 Subject: [PATCH] Fix failing robotest Fixes: 124531152 Test: robotests Change-Id: I4442ae543b062ef17b4bfd828134ede879d2b22d --- .../UserDictionaryListPreferenceController.java | 11 +++++------ .../inputmethod/UserDictionaryListControllerTest.java | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/inputmethod/UserDictionaryListPreferenceController.java b/src/com/android/settings/inputmethod/UserDictionaryListPreferenceController.java index 4be70d566ae..4a409e1c789 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryListPreferenceController.java +++ b/src/com/android/settings/inputmethod/UserDictionaryListPreferenceController.java @@ -79,7 +79,7 @@ public class UserDictionaryListPreferenceController extends BasePreferenceContro @NonNull public static TreeSet getUserDictionaryLocalesSet(Context context) { final Cursor cursor = context.getContentResolver().query( - UserDictionary.Words.CONTENT_URI, new String[] {UserDictionary.Words.LOCALE}, + UserDictionary.Words.CONTENT_URI, new String[]{UserDictionary.Words.LOCALE}, null, null, null); final TreeSet localeSet = new TreeSet<>(); if (cursor == null) { @@ -124,14 +124,14 @@ public class UserDictionaryListPreferenceController extends BasePreferenceContro // enabled subtypes. If we already have the locale-without-country version of the system // locale, we don't add the system locale to avoid confusion even though it's technically // correct to add it. - if (!localeSet.contains(Locale.getDefault().getLanguage().toString())) { + if (!localeSet.contains(Locale.getDefault().getLanguage())) { localeSet.add(Locale.getDefault().toString()); } return localeSet; } - @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) + @VisibleForTesting TreeSet getUserDictLocalesSet(Context context) { return getUserDictionaryLocalesSet(context); } @@ -140,7 +140,6 @@ public class UserDictionaryListPreferenceController extends BasePreferenceContro * Creates the entries that allow the user to go into the user dictionary for each locale. */ private void createUserDictSettings() { - final TreeSet localeSet = getUserDictLocalesSet(mContext); final int prefCount = mScreen.getPreferenceCount(); String prefKey; @@ -160,8 +159,8 @@ public class UserDictionaryListPreferenceController extends BasePreferenceContro if (prefCount > 0) { for (int i = prefCount - 1; i >= 0; i--) { prefKey = mScreen.getPreference(i).getKey(); - if (KEY_ALL_LANGUAGE.equals(prefKey)) { - prefKey = ""; + if (TextUtils.isEmpty(prefKey) || TextUtils.equals(KEY_ALL_LANGUAGE, prefKey)) { + continue; } if (!localeSet.isEmpty() && localeSet.contains(prefKey)) { localeSet.remove(prefKey); diff --git a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListControllerTest.java b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListControllerTest.java index ff3f0ecfc14..fd6d6a163a0 100644 --- a/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListControllerTest.java +++ b/tests/robotests/src/com/android/settings/inputmethod/UserDictionaryListControllerTest.java @@ -142,9 +142,9 @@ public class UserDictionaryListControllerTest { String sortOrder) { if (hasDictionary) { final MatrixCursor cursor = new MatrixCursor( - new String[] {UserDictionary.Words.LOCALE}); - cursor.addRow(new Object[] {"en"}); - cursor.addRow(new Object[] {"es"}); + new String[]{UserDictionary.Words.LOCALE}); + cursor.addRow(new Object[]{"en"}); + cursor.addRow(new Object[]{"es"}); return cursor; } else { return null;