From 49007de565a1f4feac9b4e9ae280881a25f35f22 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 19 Apr 2013 14:51:47 +0900 Subject: [PATCH 1/2] Fix an NPE in recapitalize Bug: 8657736 Change-Id: I459d1c200826c1c394f8207475ecf60a4f356793 --- java/src/com/android/inputmethod/latin/LatinIME.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 0e1c4dc31..b8203ff74 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1970,9 +1970,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // If we have a recapitalize in progress, use it; otherwise, create a new one. if (!mRecapitalizeStatus.isActive() || !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) { + final CharSequence selectedText = + mConnection.getSelectedText(0 /* flags, 0 for no styles */); + if (TextUtils.isEmpty(selectedText)) return; // Race condition with the input connection mRecapitalizeStatus.initialize(mLastSelectionStart, mLastSelectionEnd, - mConnection.getSelectedText(0 /* flags, 0 for no styles */).toString(), - mSettings.getCurrentLocale(), mSettings.getWordSeparators()); + selectedText.toString(), mSettings.getCurrentLocale(), + mSettings.getWordSeparators()); // We trim leading and trailing whitespace. mRecapitalizeStatus.trim(); // Trimming the object may have changed the length of the string, and we need to From fbc113f32113a1af012a3a0886c43f1910d40419 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 19 Apr 2013 11:48:14 +0900 Subject: [PATCH 2/2] Fix an NPE in recorrection Also, theoretically, we don't want to retrieve older suggestions if there are no results for a recorrection - that would look random. This bug addresses this too. Bug: 8657919 Change-Id: I44f36d34a708a968ab71fa0592da57f4c97d4b7f --- .../android/inputmethod/latin/LatinIME.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b8203ff74..4cae37c51 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1678,7 +1678,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction private SuggestedWords getSuggestedWordsGestureLocked(final InputPointers batchPointers) { mLatinIme.mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = - mLatinIme.getSuggestedWords(Suggest.SESSION_GESTURE); + mLatinIme.getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_GESTURE); final int suggestionCount = suggestedWords.size(); if (suggestionCount <= 1) { final String mostProbableSuggestion = (suggestionCount == 0) ? null @@ -2155,7 +2155,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction return; } - final SuggestedWords suggestedWords = getSuggestedWords(Suggest.SESSION_TYPING); + final SuggestedWords suggestedWords = + getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_TYPING); final String typedWord = mWordComposer.getTypedWord(); showSuggestionStrip(suggestedWords, typedWord); } @@ -2165,7 +2166,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction if (keyboard == null || mSuggest == null) { return SuggestedWords.EMPTY; } - final String typedWord = mWordComposer.getTypedWord(); // Get the word on which we should search the bigrams. If we are composing a word, it's // whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we // should just skip whitespace if any, so 1. @@ -2173,10 +2173,13 @@ public final class LatinIME extends InputMethodService implements KeyboardAction final String prevWord = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, mWordComposer.isComposingWord() ? 2 : 1); - final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, - prevWord, keyboard.getProximityInfo(), mSettings.getCurrent().mCorrectionEnabled, - sessionId); - return maybeRetrieveOlderSuggestions(typedWord, suggestedWords); + return mSuggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(), + mSettings.getCurrent().mCorrectionEnabled, sessionId); + } + + private SuggestedWords getSuggestedWordsOrOlderSuggestions(final int sessionId) { + return maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(), + getSuggestedWords(sessionId)); } private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, @@ -2189,7 +2192,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction // old suggestions. Also, if we are showing the "add to dictionary" hint, we need to // revert to suggestions - although it is unclear how we can come here if it's displayed. if (suggestedWords.size() > 1 || typedWord.length() <= 1 - || suggestedWords.mTypedWordValid + || suggestedWords.mTypedWordValid || null == mSuggestionStripView || mSuggestionStripView.isShowingAddToDictionaryHint()) { return suggestedWords; } else {