Do not crash when the user dictionary service is disabled.

This still does not remove the UI. It only prevents the Settings
application from crashing.

Bug: 5024166
Change-Id: I6e8c0a8953af6c02273de2a881e85a5248cb8bd6
This commit is contained in:
Jean Chalard
2011-07-21 18:10:20 +09:00
parent c29c6d3f8c
commit ea41e087f9
2 changed files with 12 additions and 9 deletions

View File

@@ -223,6 +223,7 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
} }
private String getWord(int position) { private String getWord(int position) {
if (null == mCursor) return null;
mCursor.moveToPosition(position); mCursor.moveToPosition(position);
// Handle a possible race-condition // Handle a possible race-condition
if (mCursor.isAfterLast()) return null; if (mCursor.isAfterLast()) return null;
@@ -298,7 +299,7 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_CURRENT); FREQUENCY_FOR_USER_DICTIONARY_ADDS, UserDictionary.Words.LOCALE_TYPE_CURRENT);
Locale.setDefault(prevLocale); Locale.setDefault(prevLocale);
} }
if (!mCursor.requery()) { if (null != mCursor && !mCursor.requery()) {
throw new IllegalStateException("can't requery on already-closed cursor."); throw new IllegalStateException("can't requery on already-closed cursor.");
} }
mAddedWordAlready = true; mAddedWordAlready = true;
@@ -333,23 +334,25 @@ public class UserDictionarySettings extends ListFragment implements DialogCreata
super(context, layout, c, from, to); super(context, layout, c, from, to);
mSettings = settings; mSettings = settings;
int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); if (null != c) {
String alphabet = context.getString( final String alphabet = context.getString(
com.android.internal.R.string.fast_scroll_alphabet); com.android.internal.R.string.fast_scroll_alphabet);
final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD);
mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet);
}
setViewBinder(mViewBinder); setViewBinder(mViewBinder);
} }
public int getPositionForSection(int section) { public int getPositionForSection(int section) {
return mIndexer.getPositionForSection(section); return null == mIndexer ? 0 : mIndexer.getPositionForSection(section);
} }
public int getSectionForPosition(int position) { public int getSectionForPosition(int position) {
return mIndexer.getSectionForPosition(position); return null == mIndexer ? 0 : mIndexer.getSectionForPosition(position);
} }
public Object[] getSections() { public Object[] getSections() {
return mIndexer.getSections(); return null == mIndexer ? null : mIndexer.getSections();
} }
public void onClick(View v) { public void onClick(View v) {

View File

@@ -49,7 +49,7 @@ public class UserDictionaryList extends SettingsPreferenceFragment {
new String[] { UserDictionary.Words.LOCALE }, new String[] { UserDictionary.Words.LOCALE },
null, null, null); null, null, null);
final Set<String> localeList = new TreeSet<String>(); final Set<String> localeList = new TreeSet<String>();
if (cursor.moveToFirst()) { if (null != cursor && cursor.moveToFirst()) {
final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE); final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE);
do { do {
String locale = cursor.getString(columnIndex); String locale = cursor.getString(columnIndex);