From 5408fec63a52015af9eefe3042eb1c435912195b Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 29 Jul 2013 17:47:13 +0900 Subject: [PATCH] Fix an NPE Also make mSuggest private for more security. Bug: 10045657 Change-Id: I712505e4d2a2606efff5d09ba9b4c656f9e7c7a9 --- .../android/inputmethod/latin/LatinIME.java | 19 ++++++++++++++++--- .../inputmethod/latin/InputTestsBase.java | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index fe5fedd59..cb7089670 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -154,7 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private SuggestionStripView mSuggestionStripView; // Never null private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; - @UsedForTesting Suggest mSuggest; + private Suggest mSuggest; private CompletionInfo[] mApplicationSpecifiedCompletions; private AppWorkaroundsUtils mAppWorkAroundsUtils = new AppWorkaroundsUtils(); @@ -2241,7 +2241,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private SuggestedWords getSuggestedWords(final int sessionId) { final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); - if (keyboard == null || mSuggest == null) { + final Suggest suggest = mSuggest; + if (keyboard == null || suggest == null) { return SuggestedWords.EMPTY; } // Get the word on which we should search the bigrams. If we are composing a word, it's @@ -2251,7 +2252,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final String prevWord = mConnection.getNthPreviousWord(mSettings.getCurrent().mWordSeparators, mWordComposer.isComposingWord() ? 2 : 1); - return mSuggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(), + return suggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(), mSettings.getBlockPotentiallyOffensive(), mSettings.getCurrent().mCorrectionEnabled, sessionId); } @@ -2855,6 +2856,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null; } + // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME. + @UsedForTesting + /* package for test */ boolean isCurrentlyWaitingForMainDictionary() { + return mSuggest.isCurrentlyWaitingForMainDictionary(); + } + + // DO NOT USE THIS for any other purpose than testing. This is information private to LatinIME. + @UsedForTesting + /* package for test */ boolean hasMainDictionary() { + return mSuggest.hasMainDictionary(); + } + public void debugDumpStateAndCrashWithException(final String context) { final StringBuilder s = new StringBuilder(mAppWorkAroundsUtils.toString()); s.append("\nAttributes : ").append(mSettings.getCurrent().mInputAttributes) diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index d1ce104b4..eb4f706cc 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -225,7 +225,7 @@ public class InputTestsBase extends ServiceTestCase { protected void waitForDictionaryToBeLoaded() { int remainingAttempts = 300; - while (remainingAttempts > 0 && mLatinIME.mSuggest.isCurrentlyWaitingForMainDictionary()) { + while (remainingAttempts > 0 && mLatinIME.isCurrentlyWaitingForMainDictionary()) { try { Thread.sleep(200); } catch (InterruptedException e) { @@ -234,7 +234,7 @@ public class InputTestsBase extends ServiceTestCase { --remainingAttempts; } } - if (!mLatinIME.mSuggest.hasMainDictionary()) { + if (!mLatinIME.hasMainDictionary()) { throw new RuntimeException("Can't initialize the main dictionary"); } }