Skip to content

Commit 1b3d01d

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "InputConnection is warned when finished"
2 parents a6bae56 + 9d69ecb commit 1b3d01d

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ private void notifyInputConnectionFinished() {
708708
public void reportFinishInputConnection(InputConnection ic) {
709709
if (mServedInputConnection != ic) {
710710
ic.finishComposingText();
711+
// To avoid modifying the public InputConnection interface
712+
if (ic instanceof BaseInputConnection) {
713+
((BaseInputConnection) ic).reportFinish();
714+
}
711715
}
712716
}
713717

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)