Merge changes I16312592,Iadfc226e into nyc-dev
* changes: Revert "Remove redundant IMM#mServedInputConnection." Revert "Make sure to call back reportFinish() on the desired Handler."
This commit is contained in:
@@ -3287,6 +3287,7 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
private final static int MSG_DISPATCH_APP_VISIBILITY = 8;
|
private final static int MSG_DISPATCH_APP_VISIBILITY = 8;
|
||||||
private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9;
|
private final static int MSG_DISPATCH_GET_NEW_SURFACE = 9;
|
||||||
private final static int MSG_DISPATCH_KEY_FROM_IME = 11;
|
private final static int MSG_DISPATCH_KEY_FROM_IME = 11;
|
||||||
|
private final static int MSG_FINISH_INPUT_CONNECTION = 12;
|
||||||
private final static int MSG_CHECK_FOCUS = 13;
|
private final static int MSG_CHECK_FOCUS = 13;
|
||||||
private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14;
|
private final static int MSG_CLOSE_SYSTEM_DIALOGS = 14;
|
||||||
private final static int MSG_DISPATCH_DRAG_EVENT = 15;
|
private final static int MSG_DISPATCH_DRAG_EVENT = 15;
|
||||||
@@ -3326,6 +3327,8 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
return "MSG_DISPATCH_GET_NEW_SURFACE";
|
return "MSG_DISPATCH_GET_NEW_SURFACE";
|
||||||
case MSG_DISPATCH_KEY_FROM_IME:
|
case MSG_DISPATCH_KEY_FROM_IME:
|
||||||
return "MSG_DISPATCH_KEY_FROM_IME";
|
return "MSG_DISPATCH_KEY_FROM_IME";
|
||||||
|
case MSG_FINISH_INPUT_CONNECTION:
|
||||||
|
return "MSG_FINISH_INPUT_CONNECTION";
|
||||||
case MSG_CHECK_FOCUS:
|
case MSG_CHECK_FOCUS:
|
||||||
return "MSG_CHECK_FOCUS";
|
return "MSG_CHECK_FOCUS";
|
||||||
case MSG_CLOSE_SYSTEM_DIALOGS:
|
case MSG_CLOSE_SYSTEM_DIALOGS:
|
||||||
@@ -3546,6 +3549,12 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
}
|
}
|
||||||
enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true);
|
enqueueInputEvent(event, null, QueuedInputEvent.FLAG_DELIVER_POST_IME, true);
|
||||||
} break;
|
} break;
|
||||||
|
case MSG_FINISH_INPUT_CONNECTION: {
|
||||||
|
InputMethodManager imm = InputMethodManager.peekInstance();
|
||||||
|
if (imm != null) {
|
||||||
|
imm.reportFinishInputConnection((InputConnection)msg.obj);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case MSG_CHECK_FOCUS: {
|
case MSG_CHECK_FOCUS: {
|
||||||
InputMethodManager imm = InputMethodManager.peekInstance();
|
InputMethodManager imm = InputMethodManager.peekInstance();
|
||||||
if (imm != null) {
|
if (imm != null) {
|
||||||
@@ -5856,6 +5865,11 @@ public final class ViewRootImpl implements ViewParent,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dispatchFinishInputConnection(InputConnection connection) {
|
||||||
|
Message msg = mHandler.obtainMessage(MSG_FINISH_INPUT_CONNECTION, connection);
|
||||||
|
mHandler.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
|
public void dispatchResized(Rect frame, Rect overscanInsets, Rect contentInsets,
|
||||||
Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
|
Rect visibleInsets, Rect stableInsets, Rect outsets, boolean reportDraw,
|
||||||
Configuration newConfig, Rect backDropFrame, boolean forceLayout,
|
Configuration newConfig, Rect backDropFrame, boolean forceLayout,
|
||||||
|
|||||||
@@ -158,8 +158,8 @@ public class BaseInputConnection implements InputConnection {
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void reportFinish() {
|
protected void reportFinish() {
|
||||||
// Intentionally empty
|
// Intentionaly empty
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ public final class InputMethodManager {
|
|||||||
/**
|
/**
|
||||||
* The InputConnection that was last retrieved from the served view.
|
* The InputConnection that was last retrieved from the served view.
|
||||||
*/
|
*/
|
||||||
|
InputConnection mServedInputConnection;
|
||||||
ControlledInputConnectionWrapper mServedInputConnectionWrapper;
|
ControlledInputConnectionWrapper mServedInputConnectionWrapper;
|
||||||
/**
|
/**
|
||||||
* The completions that were last provided by the served view.
|
* The completions that were last provided by the served view.
|
||||||
@@ -497,7 +498,7 @@ public final class InputMethodManager {
|
|||||||
// from a thread that created mServedView. That could happen
|
// from a thread that created mServedView. That could happen
|
||||||
// the current activity is running in the system process.
|
// the current activity is running in the system process.
|
||||||
// In that case, we really should not call
|
// In that case, we really should not call
|
||||||
// mServedInputConnectionWrapper.finishComposingText().
|
// mServedInputConnection.finishComposingText.
|
||||||
if (checkFocusNoStartInput(mHasBeenInactive, false)) {
|
if (checkFocusNoStartInput(mHasBeenInactive, false)) {
|
||||||
final int reason = active ?
|
final int reason = active ?
|
||||||
InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS :
|
InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS :
|
||||||
@@ -531,25 +532,22 @@ public final class InputMethodManager {
|
|||||||
|
|
||||||
private static class ControlledInputConnectionWrapper extends IInputConnectionWrapper {
|
private static class ControlledInputConnectionWrapper extends IInputConnectionWrapper {
|
||||||
private final InputMethodManager mParentInputMethodManager;
|
private final InputMethodManager mParentInputMethodManager;
|
||||||
|
private boolean mActive;
|
||||||
|
|
||||||
public ControlledInputConnectionWrapper(final Looper mainLooper, final InputConnection conn,
|
public ControlledInputConnectionWrapper(final Looper mainLooper, final InputConnection conn,
|
||||||
final InputMethodManager inputMethodManager) {
|
final InputMethodManager inputMethodManager) {
|
||||||
super(mainLooper, conn);
|
super(mainLooper, conn);
|
||||||
mParentInputMethodManager = inputMethodManager;
|
mParentInputMethodManager = inputMethodManager;
|
||||||
|
mActive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return mParentInputMethodManager.mActive && !isFinished();
|
return mParentInputMethodManager.mActive && mActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deactivate() {
|
void deactivate() {
|
||||||
if (isFinished()) {
|
mActive = false;
|
||||||
// This is a small performance optimization. Still only the 1st call of
|
|
||||||
// reportFinish() will take effect.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
reportFinish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -564,9 +562,7 @@ public final class InputMethodManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ControlledInputConnectionWrapper{"
|
return "ControlledInputConnectionWrapper{mActive=" + mActive
|
||||||
+ "connection=" + getInputConnection()
|
|
||||||
+ " finished=" + isFinished()
|
|
||||||
+ " mParentInputMethodManager.mActive=" + mParentInputMethodManager.mActive
|
+ " mParentInputMethodManager.mActive=" + mParentInputMethodManager.mActive
|
||||||
+ "}";
|
+ "}";
|
||||||
}
|
}
|
||||||
@@ -784,8 +780,7 @@ public final class InputMethodManager {
|
|||||||
*/
|
*/
|
||||||
public boolean isAcceptingText() {
|
public boolean isAcceptingText() {
|
||||||
checkFocus();
|
checkFocus();
|
||||||
return mServedInputConnectionWrapper != null &&
|
return mServedInputConnection != null;
|
||||||
mServedInputConnectionWrapper.getInputConnection() != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -820,6 +815,7 @@ public final class InputMethodManager {
|
|||||||
*/
|
*/
|
||||||
void clearConnectionLocked() {
|
void clearConnectionLocked() {
|
||||||
mCurrentTextBoxAttribute = null;
|
mCurrentTextBoxAttribute = null;
|
||||||
|
mServedInputConnection = null;
|
||||||
if (mServedInputConnectionWrapper != null) {
|
if (mServedInputConnectionWrapper != null) {
|
||||||
mServedInputConnectionWrapper.deactivate();
|
mServedInputConnectionWrapper.deactivate();
|
||||||
mServedInputConnectionWrapper = null;
|
mServedInputConnectionWrapper = null;
|
||||||
@@ -840,6 +836,7 @@ public final class InputMethodManager {
|
|||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notifyInputConnectionFinished();
|
||||||
mServedView = null;
|
mServedView = null;
|
||||||
mCompletions = null;
|
mCompletions = null;
|
||||||
mServedConnecting = false;
|
mServedConnecting = false;
|
||||||
@@ -847,6 +844,37 @@ public final class InputMethodManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies the served view that the current InputConnection will no longer be used.
|
||||||
|
*/
|
||||||
|
private void notifyInputConnectionFinished() {
|
||||||
|
if (mServedView != null && mServedInputConnection != null) {
|
||||||
|
// We need to tell the previously served view that it is no
|
||||||
|
// longer the input target, so it can reset its state. Schedule
|
||||||
|
// this call on its window's Handler so it will be on the correct
|
||||||
|
// thread and outside of our lock.
|
||||||
|
ViewRootImpl viewRootImpl = mServedView.getViewRootImpl();
|
||||||
|
if (viewRootImpl != null) {
|
||||||
|
// This will result in a call to reportFinishInputConnection() below.
|
||||||
|
viewRootImpl.dispatchFinishInputConnection(mServedInputConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called from the FINISH_INPUT_CONNECTION message above.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void reportFinishInputConnection(InputConnection ic) {
|
||||||
|
if (mServedInputConnection != ic) {
|
||||||
|
ic.finishComposingText();
|
||||||
|
// To avoid modifying the public InputConnection interface
|
||||||
|
if (ic instanceof BaseInputConnection) {
|
||||||
|
((BaseInputConnection) ic).reportFinish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void displayCompletions(View view, CompletionInfo[] completions) {
|
public void displayCompletions(View view, CompletionInfo[] completions) {
|
||||||
checkFocus();
|
checkFocus();
|
||||||
synchronized (mH) {
|
synchronized (mH) {
|
||||||
@@ -1212,10 +1240,9 @@ public final class InputMethodManager {
|
|||||||
// Hook 'em up and let 'er rip.
|
// Hook 'em up and let 'er rip.
|
||||||
mCurrentTextBoxAttribute = tba;
|
mCurrentTextBoxAttribute = tba;
|
||||||
mServedConnecting = false;
|
mServedConnecting = false;
|
||||||
if (mServedInputConnectionWrapper != null) {
|
// Notify the served view that its previous input connection is finished
|
||||||
mServedInputConnectionWrapper.deactivate();
|
notifyInputConnectionFinished();
|
||||||
mServedInputConnectionWrapper = null;
|
mServedInputConnection = ic;
|
||||||
}
|
|
||||||
ControlledInputConnectionWrapper servedContext;
|
ControlledInputConnectionWrapper servedContext;
|
||||||
final int missingMethodFlags;
|
final int missingMethodFlags;
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
@@ -1240,6 +1267,9 @@ public final class InputMethodManager {
|
|||||||
servedContext = null;
|
servedContext = null;
|
||||||
missingMethodFlags = 0;
|
missingMethodFlags = 0;
|
||||||
}
|
}
|
||||||
|
if (mServedInputConnectionWrapper != null) {
|
||||||
|
mServedInputConnectionWrapper.deactivate();
|
||||||
|
}
|
||||||
mServedInputConnectionWrapper = servedContext;
|
mServedInputConnectionWrapper = servedContext;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -1383,7 +1413,7 @@ public final class InputMethodManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ControlledInputConnectionWrapper ic;
|
InputConnection ic = null;
|
||||||
synchronized (mH) {
|
synchronized (mH) {
|
||||||
if (mServedView == mNextServedView && !forceNewFocus) {
|
if (mServedView == mNextServedView && !forceNewFocus) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1403,7 +1433,7 @@ public final class InputMethodManager {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ic = mServedInputConnectionWrapper;
|
ic = mServedInputConnection;
|
||||||
|
|
||||||
mServedView = mNextServedView;
|
mServedView = mNextServedView;
|
||||||
mCurrentTextBoxAttribute = null;
|
mCurrentTextBoxAttribute = null;
|
||||||
@@ -2252,7 +2282,7 @@ public final class InputMethodManager {
|
|||||||
} else {
|
} else {
|
||||||
p.println(" mCurrentTextBoxAttribute: null");
|
p.println(" mCurrentTextBoxAttribute: null");
|
||||||
}
|
}
|
||||||
p.println(" mServedInputConnectionWrapper=" + mServedInputConnectionWrapper);
|
p.println(" mServedInputConnection=" + mServedInputConnection);
|
||||||
p.println(" mCompletions=" + Arrays.toString(mCompletions));
|
p.println(" mCompletions=" + Arrays.toString(mCompletions));
|
||||||
p.println(" mCursorRect=" + mCursorRect);
|
p.println(" mCursorRect=" + mCursorRect);
|
||||||
p.println(" mCursorSelStart=" + mCursorSelStart
|
p.println(" mCursorSelStart=" + mCursorSelStart
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package com.android.internal.view;
|
package com.android.internal.view;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.annotation.Nullable;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -27,7 +23,6 @@ import android.os.Message;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.inputmethod.BaseInputConnection;
|
|
||||||
import android.view.inputmethod.CompletionInfo;
|
import android.view.inputmethod.CompletionInfo;
|
||||||
import android.view.inputmethod.CorrectionInfo;
|
import android.view.inputmethod.CorrectionInfo;
|
||||||
import android.view.inputmethod.ExtractedTextRequest;
|
import android.view.inputmethod.ExtractedTextRequest;
|
||||||
@@ -61,16 +56,11 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
|
|||||||
private static final int DO_PERFORM_PRIVATE_COMMAND = 120;
|
private static final int DO_PERFORM_PRIVATE_COMMAND = 120;
|
||||||
private static final int DO_CLEAR_META_KEY_STATES = 130;
|
private static final int DO_CLEAR_META_KEY_STATES = 130;
|
||||||
private static final int DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO = 140;
|
private static final int DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO = 140;
|
||||||
private static final int DO_REPORT_FINISH = 150;
|
|
||||||
|
|
||||||
@NonNull
|
private WeakReference<InputConnection> mInputConnection;
|
||||||
private final WeakReference<InputConnection> mInputConnection;
|
|
||||||
|
|
||||||
private Looper mMainLooper;
|
private Looper mMainLooper;
|
||||||
private Handler mH;
|
private Handler mH;
|
||||||
private Object mLock = new Object();
|
|
||||||
@GuardedBy("mLock")
|
|
||||||
private boolean mFinished = false;
|
|
||||||
|
|
||||||
static class SomeArgs {
|
static class SomeArgs {
|
||||||
Object arg1;
|
Object arg1;
|
||||||
@@ -96,17 +86,6 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
|
|||||||
mH = new MyHandler(mMainLooper);
|
mH = new MyHandler(mMainLooper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public InputConnection getInputConnection() {
|
|
||||||
return mInputConnection.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isFinished() {
|
|
||||||
synchronized (mLock) {
|
|
||||||
return mFinished;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract protected boolean isActive();
|
abstract protected boolean isActive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -219,10 +198,6 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
|
|||||||
seq, callback));
|
seq, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportFinish() {
|
|
||||||
dispatchMessage(obtainMessage(DO_REPORT_FINISH));
|
|
||||||
}
|
|
||||||
|
|
||||||
void dispatchMessage(Message msg) {
|
void dispatchMessage(Message msg) {
|
||||||
// If we are calling this from the main thread, then we can call
|
// If we are calling this from the main thread, then we can call
|
||||||
// right through. Otherwise, we need to send the message to the
|
// right through. Otherwise, we need to send the message to the
|
||||||
@@ -235,7 +210,7 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
|
|||||||
|
|
||||||
mH.sendMessage(msg);
|
mH.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeMessage(Message msg) {
|
void executeMessage(Message msg) {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case DO_GET_TEXT_AFTER_CURSOR: {
|
case DO_GET_TEXT_AFTER_CURSOR: {
|
||||||
@@ -498,36 +473,6 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case DO_REPORT_FINISH: {
|
|
||||||
// Note that we do not need to worry about race condition here, because 1) mFinished
|
|
||||||
// is updated only inside this block, and 2) the code here is running on a Handler
|
|
||||||
// hence we assume multiple DO_REPORT_FINISH messages will not be handled at the
|
|
||||||
// same time.
|
|
||||||
if (isFinished()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
InputConnection ic = mInputConnection.get();
|
|
||||||
// Note we do NOT check isActive() here, because this is safe
|
|
||||||
// for an IME to call at any time, and we need to allow it
|
|
||||||
// through to clean up our state after the IME has switched to
|
|
||||||
// another client.
|
|
||||||
if (ic == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ic.finishComposingText();
|
|
||||||
// TODO: Make reportFinish() public method of InputConnection to remove this
|
|
||||||
// check.
|
|
||||||
if (ic instanceof BaseInputConnection) {
|
|
||||||
((BaseInputConnection) ic).reportFinish();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
synchronized (mLock) {
|
|
||||||
mFinished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Log.w(TAG, "Unhandled message code: " + msg.what);
|
Log.w(TAG, "Unhandled message code: " + msg.what);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,11 +83,8 @@ public class EditableInputConnection extends BaseInputConnection {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void reportFinish() {
|
protected void reportFinish() {
|
||||||
super.reportFinish();
|
super.reportFinish();
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user