diff options
author | 2014-04-10 08:47:20 +0000 | |
---|---|---|
committer | 2014-04-10 08:47:20 +0000 | |
commit | 2e967f66074fdc13ba2bc9b1932f036897e3b00a (patch) | |
tree | 407124d4e3a0a286cc2695c0e774f65c16174487 /java/src/com/android/inputmethod/latin | |
parent | 9eec53a2c227c791f62659aebcbe18fcf517e65b (diff) | |
parent | 4370ff0998d3240cfda7745d08edbdd11703b984 (diff) | |
download | latinime-2e967f66074fdc13ba2bc9b1932f036897e3b00a.tar.gz latinime-2e967f66074fdc13ba2bc9b1932f036897e3b00a.tar.xz latinime-2e967f66074fdc13ba2bc9b1932f036897e3b00a.zip |
Merge "Fix some flaky tests."
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
3 files changed, 23 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6d36af77a..1f15a9759 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -635,6 +635,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onDestroy(); } + @UsedForTesting + public void recycle() { + mInputLogic.recycle(); + } + @Override public void onConfigurationChanged(final Configuration conf) { // If orientation changed while predicting, commit the change diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 7cf8c5e49..0754b1fa9 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -148,6 +148,17 @@ public final class InputLogic { mInputLogicHandler.reset(); } + // Normally this class just gets out of scope after the process ends, but in unit tests, we + // create several instances of LatinIME in the same process, which results in several + // instances of InputLogic. This cleans up the associated handler so that tests don't leak + // handlers. + public void recycle() { + final InputLogicHandler inputLogicHandler = mInputLogicHandler; + mInputLogicHandler = InputLogicHandler.NULL_HANDLER; + inputLogicHandler.destroy(); + mSuggest.mDictionaryFacilitator.closeDictionaries(); + } + /** * React to a string input. * diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java index e3b8ab465..64bba681f 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java @@ -20,6 +20,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Message; +import com.android.inputmethod.compat.LooperCompatUtils; import com.android.inputmethod.latin.InputPointers; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.Suggest; @@ -80,6 +81,12 @@ class InputLogicHandler implements Handler.Callback { mNonUIThreadHandler.removeCallbacksAndMessages(null); } + // In unit tests, we create several instances of LatinIME, which results in several instances + // of InputLogicHandler. To avoid these handlers lingering, we call this. + public void destroy() { + LooperCompatUtils.quitSafely(mNonUIThreadHandler.getLooper()); + } + /** * Handle a message. * @see android.os.Handler.Callback#handleMessage(android.os.Message) |