Tell the reason why IMM called startInput().
As a preparation to fix Bug 25373872, this CL introduces an additional
int parameter into the following two methods
- IInputMethodManager.startInput()
- IInputMethodManager.windowGainedFocus()
so that IMMS can know why IMM needs to start input. Currently the
"startInputReason" parameter is used only for debug message only when
the OS is rebuilt with flipping IMMS#DEBUG to true. Basically this
should have no impact in production builds except for a tiny overhead
of having one int parameter in some internal IPC calls.
Note that since 7663d80f6b6fd6ca7a736c3802013a09c0abdeb9 [1] basically
IMMS#windowGainedFocus() has been a superset of IMMS#startInput().
Hence we should pass to "startInputReason" parameter to
IMMS#windowGainedFocus() as well as IMMS#startInput().
[1]: Icb58bef75ef4bf9979f3e2ba88cea20db2e2c3fb
Bug: 25373872
Change-Id: Ia1fe120af7d71495c5f3a4fc0ec6390efb8240ca
diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java
index 5e4f2b2..78a4e35 100644
--- a/services/core/java/com/android/server/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/InputMethodManagerService.java
@@ -1225,7 +1225,7 @@
void unbindCurrentClientLocked(
/* @InputMethodClient.UnbindReason */ final int unbindClientReason) {
if (mCurClient != null) {
- if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client = "
+ if (DEBUG) Slog.v(TAG, "unbindCurrentInputLocked: client="
+ mCurClient.client.asBinder());
if (mBoundToMethod) {
mBoundToMethod = false;
@@ -1290,8 +1290,10 @@
mCurId, mCurSeq, mCurUserActionNotificationSequenceNumber);
}
- InputBindResult startInputLocked(IInputMethodClient client,
- IInputContext inputContext, EditorInfo attribute, int controlFlags) {
+ InputBindResult startInputLocked(
+ /* @InputMethodClient.StartInputReason */ final int startInputReason,
+ IInputMethodClient client, IInputContext inputContext, EditorInfo attribute,
+ int controlFlags) {
// If no method is currently selected, do nothing.
if (mCurMethodId == null) {
return mNoBinding;
@@ -1320,8 +1322,8 @@
return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
}
- InputBindResult startInputUncheckedLocked(@NonNull ClientState cs,
- IInputContext inputContext, @NonNull EditorInfo attribute, int controlFlags) {
+ InputBindResult startInputUncheckedLocked(@NonNull ClientState cs, IInputContext inputContext,
+ @NonNull EditorInfo attribute, int controlFlags) {
// If no method is currently selected, do nothing.
if (mCurMethodId == null) {
return mNoBinding;
@@ -1340,7 +1342,7 @@
// If the client is changing, we need to switch over to the new
// one.
unbindCurrentClientLocked(InputMethodClient.UNBIND_REASON_SWITCH_CLIENT);
- if (DEBUG) Slog.v(TAG, "switching to client: client = "
+ if (DEBUG) Slog.v(TAG, "switching to client: client="
+ cs.client.asBinder() + " keyguard=" + mCurClientInKeyguard);
// If the screen is on, inform the new client it is active
@@ -1442,15 +1444,26 @@
}
@Override
- public InputBindResult startInput(IInputMethodClient client,
- IInputContext inputContext, EditorInfo attribute, int controlFlags) {
+ public InputBindResult startInput(
+ /* @InputMethodClient.StartInputReason */ final int startInputReason,
+ IInputMethodClient client, IInputContext inputContext, EditorInfo attribute,
+ int controlFlags) {
if (!calledFromValidUser()) {
return null;
}
synchronized (mMethodMap) {
+ if (DEBUG) {
+ Slog.v(TAG, "startInput: reason="
+ + InputMethodClient.getStartInputReason(startInputReason)
+ + " client = " + client.asBinder()
+ + " inputContext=" + inputContext
+ + " attribute=" + attribute
+ + " controlFlags=#" + Integer.toHexString(controlFlags));
+ }
final long ident = Binder.clearCallingIdentity();
try {
- return startInputLocked(client, inputContext, attribute, controlFlags);
+ return startInputLocked(startInputReason, client, inputContext, attribute,
+ controlFlags);
} finally {
Binder.restoreCallingIdentity(ident);
}
@@ -2151,17 +2164,21 @@
}
@Override
- public InputBindResult windowGainedFocus(IInputMethodClient client, IBinder windowToken,
- int controlFlags, int softInputMode, int windowFlags,
- EditorInfo attribute, IInputContext inputContext) {
+ public InputBindResult windowGainedFocus(
+ /* @InputMethodClient.StartInputReason */ final int startInputReason,
+ IInputMethodClient client, IBinder windowToken, int controlFlags, int softInputMode,
+ int windowFlags, EditorInfo attribute, IInputContext inputContext) {
// Needs to check the validity before clearing calling identity
final boolean calledFromValidUser = calledFromValidUser();
-
InputBindResult res = null;
long ident = Binder.clearCallingIdentity();
try {
synchronized (mMethodMap) {
- if (DEBUG) Slog.v(TAG, "windowGainedFocus: " + client.asBinder()
+ if (DEBUG) Slog.v(TAG, "windowGainedFocus: reason="
+ + InputMethodClient.getStartInputReason(startInputReason)
+ + " client=" + client.asBinder()
+ + " inputContext=" + inputContext
+ + " attribute=" + attribute
+ " controlFlags=#" + Integer.toHexString(controlFlags)
+ " softInputMode=#" + Integer.toHexString(softInputMode)
+ " windowFlags=#" + Integer.toHexString(windowFlags));