Don't kill LatinIME if the spellchecker crashes.

If the spellchecker encounters a bug and happens to crash,
it may be sensible to avoid killing the keyboard in response.
This is a possible way to do it, which comes with the big
drawback of making bugs in the spell checker harder to find.

Change-Id: Idb26fb592b9718e1dbdadeda8fbd1a8a1d805c28
main
Jean Chalard 2011-09-14 21:30:29 +09:00
parent fa52a09f21
commit 199dc5e0e4
1 changed files with 67 additions and 56 deletions

View File

@ -327,6 +327,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
@Override
public SuggestionsInfo onGetSuggestions(final TextInfo textInfo,
final int suggestionsLimit) {
try {
final String text = textInfo.getText();
if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO;
@ -343,7 +344,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
proximities = new int[] { character };
} else {
proximities = Arrays.copyOfRange(SpellCheckerProximityInfo.PROXIMITY,
proximityIndex, proximityIndex + SpellCheckerProximityInfo.ROW_SIZE);
proximityIndex,
proximityIndex + SpellCheckerProximityInfo.ROW_SIZE);
}
composer.add(character, proximities,
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
@ -388,6 +390,15 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
| (result.mLooksLikeTypo
? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
return new SuggestionsInfo(flags, result.mSuggestions);
} catch (RuntimeException e) {
// Don't kill the keyboard if there is a bug in the spell checker
if (DBG) {
throw e;
} else {
Log.e(TAG, "Exception while spellcheking: " + e);
return EMPTY_SUGGESTIONS_INFO;
}
}
}
}
}