diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java index 89aba3ca1e831..7ec53980876be 100644 --- a/core/java/android/view/inputmethod/BaseInputConnection.java +++ b/core/java/android/view/inputmethod/BaseInputConnection.java @@ -151,6 +151,15 @@ public class BaseInputConnection implements InputConnection { return false; } + /** + * Called when this InputConnection is no longer used by the InputMethodManager. + * + * @hide + */ + protected void reportFinish() { + // Intentionaly empty + } + /** * Default implementation uses * {@link MetaKeyKeyListener#clearMetaKeyState(long, int) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index c51d2440f893a..15afb394a91a6 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -26,7 +26,6 @@ import com.android.internal.view.IInputMethodSession; import com.android.internal.view.InputBindResult; import android.content.Context; -import android.content.pm.PackageManager; import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; @@ -690,6 +689,10 @@ public final class InputMethodManager { public void reportFinishInputConnection(InputConnection ic) { if (mServedInputConnection != ic) { ic.finishComposingText(); + // To avoid modifying the public InputConnection interface + if (ic instanceof BaseInputConnection) { + ((BaseInputConnection) ic).reportFinish(); + } } } diff --git a/core/java/com/android/internal/widget/EditableInputConnection.java b/core/java/com/android/internal/widget/EditableInputConnection.java index 9579bce468dad..4cbdf784e1a95 100644 --- a/core/java/com/android/internal/widget/EditableInputConnection.java +++ b/core/java/com/android/internal/widget/EditableInputConnection.java @@ -70,7 +70,7 @@ public class EditableInputConnection extends BaseInputConnection { public boolean endBatchEdit() { synchronized(this) { if (mBatchEditNesting > 0) { - // When the connection is reset by the InputMethodManager and finishComposingText + // When the connection is reset by the InputMethodManager and reportFinish // is called, some endBatchEdit calls may still be asynchronously received from the // IME. Do not take these into account, thus ensuring that this IC's final // contribution to mTextView's nested batch edit count is zero. @@ -82,6 +82,19 @@ public class EditableInputConnection extends BaseInputConnection { return false; } + @Override + protected void reportFinish() { + super.reportFinish(); + + synchronized(this) { + while (mBatchEditNesting > 0) { + endBatchEdit(); + } + // Will prevent any further calls to begin or endBatchEdit + mBatchEditNesting = -1; + } + } + @Override public boolean clearMetaKeyStates(int states) { final Editable content = getEditable(); @@ -98,23 +111,6 @@ public class EditableInputConnection extends BaseInputConnection { return true; } - @Override - public boolean finishComposingText() { - final boolean superResult = super.finishComposingText(); - synchronized(this) { - if (mBatchEditNesting < 0) { - // The connection was already finished - return false; - } - while (mBatchEditNesting > 0) { - endBatchEdit(); - } - // Will prevent any further calls to begin or endBatchEdit - mBatchEditNesting = -1; - } - return superResult; - } - @Override public boolean commitCompletion(CompletionInfo text) { if (DEBUG) Log.v(TAG, "commitCompletion " + text);