From faa4c7b6413b45a974022970b17eddf42b1c65ba Mon Sep 17 00:00:00 2001 From: Victoria Lease Date: Tue, 7 Jan 2014 23:26:54 +0000 Subject: [PATCH 1/2] Revert "Fix a race condition." This reverts commit 42e83c7f06a1683b27a11564aeb9f3999b10382f. Bug: 12434783 Change-Id: Id01b6d14906430b13e64f5fc4d7fb01572d0a960 --- .../android/inputmethod/latin/inputlogic/InputLogic.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index c867ab3d3..b365003a5 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1113,11 +1113,8 @@ public final class InputLogic { keyboardSwitcher.getKeyboard()); mWordComposer.setCursorPositionWithinWord( typedWord.codePointCount(0, numberOfCharsInWordBeforeCursor)); - // TODO: Change these two lines to setComposingRegion(cursorPosition, - // cursorPosition + range.getNumberOfCharsInWordAfterCursor()); - mConnection.deleteSurroundingText(numberOfCharsInWordBeforeCursor, - typedWord.length() - numberOfCharsInWordBeforeCursor); - mConnection.setComposingText(typedWord, 1); + mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor, + expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor()); if (suggestions.isEmpty()) { // We come here if there weren't any suggestion spans on this word. We will try to // compute suggestions for it instead. From 828886ca2480c826a2c134d5316f77c15839a0e7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 10 Jan 2014 13:07:30 +0900 Subject: [PATCH 2/2] Fix an NPE. Bug: 12397228 Change-Id: I7632931f0685fc8f0558946be66025b2bb2b5a3d --- .../latin/inputlogic/InputLogic.java | 7 ++--- .../latin/inputlogic/InputLogicHandler.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 3de7e3530..92b6a8544 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -69,7 +69,8 @@ public final class InputLogic { // TODO : Remove this member when we can. private final LatinIME mLatinIME; - private InputLogicHandler mInputLogicHandler; + // Never null. + private InputLogicHandler mInputLogicHandler = InputLogicHandler.NULL_HANDLER; // TODO : make all these fields private as soon as possible. // Current space state of the input method. This can be any of the above constants. @@ -105,7 +106,7 @@ public final class InputLogic { mWordComposer = new WordComposer(); mEventInterpreter = new EventInterpreter(latinIME); mConnection = new RichInputConnection(latinIME); - mInputLogicHandler = null; + mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } /** @@ -145,7 +146,7 @@ public final class InputLogic { } resetComposingState(true /* alsoResetLastComposedWord */); mInputLogicHandler.destroy(); - mInputLogicHandler = null; + mInputLogicHandler = InputLogicHandler.NULL_HANDLER; } /** diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java index 3258dcdfb..ea010b6f5 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java @@ -40,6 +40,33 @@ public class InputLogicHandler implements Handler.Callback { private static final int MSG_GET_SUGGESTED_WORDS = 1; + // A handler that never does anything. This is used for cases where events come before anything + // is initialized, though probably only the monkey can actually do this. + public static final InputLogicHandler NULL_HANDLER = new InputLogicHandler() { + @Override + public void destroy() {} + @Override + public boolean handleMessage(final Message msg) { return true; } + @Override + public void onStartBatchInput() {} + @Override + public void onUpdateBatchInput(final InputPointers batchPointers, + final int sequenceNumber) {} + @Override + public void onCancelBatchInput() {} + @Override + public void onEndBatchInput(final InputPointers batchPointers, final int sequenceNumber) {} + @Override + public void getSuggestedWords(final int sessionId, final int sequenceNumber, + final OnGetSuggestedWordsCallback callback) {} + }; + + private InputLogicHandler() { + mNonUIThreadHandler = null; + mLatinIME = null; + mInputLogic = null; + } + public InputLogicHandler(final LatinIME latinIME, final InputLogic inputLogic) { final HandlerThread handlerThread = new HandlerThread( InputLogicHandler.class.getSimpleName());