Merge "Fix NPE when IMM#invalidateInput() is called too early" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
92d4c63228
@@ -2031,14 +2031,20 @@ public final class InputMethodManager {
|
|||||||
* @param inputConnection the connection to be invalidated.
|
* @param inputConnection the connection to be invalidated.
|
||||||
* @param textSnapshot {@link TextSnapshot} to be used to update {@link EditorInfo}.
|
* @param textSnapshot {@link TextSnapshot} to be used to update {@link EditorInfo}.
|
||||||
* @param sessionId the session ID to be sent.
|
* @param sessionId the session ID to be sent.
|
||||||
|
* @return {@code true} if the operation is done. {@code false} if the caller needs to fall back
|
||||||
|
* to {@link InputMethodManager#restartInput(View)}.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void doInvalidateInput(@NonNull RemoteInputConnectionImpl inputConnection,
|
public boolean doInvalidateInput(@NonNull RemoteInputConnectionImpl inputConnection,
|
||||||
@NonNull TextSnapshot textSnapshot, int sessionId) {
|
@NonNull TextSnapshot textSnapshot, int sessionId) {
|
||||||
synchronized (mH) {
|
synchronized (mH) {
|
||||||
if (mServedInputConnection != inputConnection || mCurrentTextBoxAttribute == null) {
|
if (mServedInputConnection != inputConnection || mCurrentTextBoxAttribute == null) {
|
||||||
// OK to ignore because the calling InputConnection is already abandoned.
|
// OK to ignore because the calling InputConnection is already abandoned.
|
||||||
return;
|
return true;
|
||||||
|
}
|
||||||
|
if (mCurrentInputMethodSession == null) {
|
||||||
|
// IME is not yet bound to the client. Need to fall back to the restartInput().
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
final EditorInfo editorInfo = mCurrentTextBoxAttribute.createCopyInternal();
|
final EditorInfo editorInfo = mCurrentTextBoxAttribute.createCopyInternal();
|
||||||
editorInfo.initialSelStart = mCursorSelStart = textSnapshot.getSelectionStart();
|
editorInfo.initialSelStart = mCursorSelStart = textSnapshot.getSelectionStart();
|
||||||
@@ -2051,6 +2057,7 @@ public final class InputMethodManager {
|
|||||||
sessionId);
|
sessionId);
|
||||||
forAccessibilitySessions(wrapper -> wrapper.invalidateInput(editorInfo,
|
forAccessibilitySessions(wrapper -> wrapper.invalidateInput(editorInfo,
|
||||||
mServedInputConnection, sessionId));
|
mServedInputConnection, sessionId));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -282,9 +282,8 @@ public final class RemoteInputConnectionImpl extends IInputContext.Stub {
|
|||||||
|
|
||||||
if (!alwaysTrueEndBatchEditDetected) {
|
if (!alwaysTrueEndBatchEditDetected) {
|
||||||
final TextSnapshot textSnapshot = ic.takeSnapshot();
|
final TextSnapshot textSnapshot = ic.takeSnapshot();
|
||||||
if (textSnapshot != null) {
|
if (textSnapshot != null && mParentInputMethodManager.doInvalidateInput(
|
||||||
mParentInputMethodManager.doInvalidateInput(this, textSnapshot,
|
this, textSnapshot, nextSessionId)) {
|
||||||
nextSessionId);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user