Skip to content

Commit 9d69ecb

Browse files
author
Gilles Debunne
committed
InputConnection is warned when finished
As said in https://android-git.corp.google.com/g/#/c/155992 finishComposingText is indeed too broad of a method. Introducing a new dedicated method to warn the InputConnection. Should solve the problems with a negative counter value. Change-Id: I5525d776916f0c42d5e6d4a4282aed590d7f0e9a
1 parent a16c98c commit 9d69ecb

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

core/java/android/view/inputmethod/BaseInputConnection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ public boolean endBatchEdit() {
151151
return false;
152152
}
153153

154+
/**
155+
* Called when this InputConnection is no longer used by the InputMethodManager.
156+
*
157+
* @hide
158+
*/
159+
protected void reportFinish() {
160+
// Intentionaly empty
161+
}
162+
154163
/**
155164
* Default implementation uses
156165
* {@link MetaKeyKeyListener#clearMetaKeyState(long, int)

core/java/android/view/inputmethod/InputMethodManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.android.internal.view.InputBindResult;
2727

2828
import android.content.Context;
29-
import android.content.pm.PackageManager;
3029
import android.graphics.Rect;
3130
import android.os.Bundle;
3231
import android.os.Handler;
@@ -690,6 +689,10 @@ private void notifyInputConnectionFinished() {
690689
public void reportFinishInputConnection(InputConnection ic) {
691690
if (mServedInputConnection != ic) {
692691
ic.finishComposingText();
692+
// To avoid modifying the public InputConnection interface
693+
if (ic instanceof BaseInputConnection) {
694+
((BaseInputConnection) ic).reportFinish();
695+
}
693696
}
694697
}
695698

core/java/com/android/internal/widget/EditableInputConnection.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean beginBatchEdit() {
7070
public boolean endBatchEdit() {
7171
synchronized(this) {
7272
if (mBatchEditNesting > 0) {
73-
// When the connection is reset by the InputMethodManager and finishComposingText
73+
// When the connection is reset by the InputMethodManager and reportFinish
7474
// is called, some endBatchEdit calls may still be asynchronously received from the
7575
// IME. Do not take these into account, thus ensuring that this IC's final
7676
// contribution to mTextView's nested batch edit count is zero.
@@ -82,6 +82,19 @@ public boolean endBatchEdit() {
8282
return false;
8383
}
8484

85+
@Override
86+
protected void reportFinish() {
87+
super.reportFinish();
88+
89+
synchronized(this) {
90+
while (mBatchEditNesting > 0) {
91+
endBatchEdit();
92+
}
93+
// Will prevent any further calls to begin or endBatchEdit
94+
mBatchEditNesting = -1;
95+
}
96+
}
97+
8598
@Override
8699
public boolean clearMetaKeyStates(int states) {
87100
final Editable content = getEditable();
@@ -98,23 +111,6 @@ public boolean clearMetaKeyStates(int states) {
98111
return true;
99112
}
100113

101-
@Override
102-
public boolean finishComposingText() {
103-
final boolean superResult = super.finishComposingText();
104-
synchronized(this) {
105-
if (mBatchEditNesting < 0) {
106-
// The connection was already finished
107-
return false;
108-
}
109-
while (mBatchEditNesting > 0) {
110-
endBatchEdit();
111-
}
112-
// Will prevent any further calls to begin or endBatchEdit
113-
mBatchEditNesting = -1;
114-
}
115-
return superResult;
116-
}
117-
118114
@Override
119115
public boolean commitCompletion(CompletionInfo text) {
120116
if (DEBUG) Log.v(TAG, "commitCompletion " + text);

0 commit comments

Comments
 (0)