Skip to content

Commit a6e4134

Browse files
author
Dianne Hackborn
committed
Fix issue #5680541: onStartInputView called upon focus loss
We should tell the app that it is inactive, before unbinding. Otherwise when it is told to unbind it will see that it is still supposed to be active and immediately re-bind. Also change the calls to set the active state to go through the message dispatch path, to ensure ordering is correct. Change-Id: I246241eac8f7521f42c4c1eee7f46097337e7303
1 parent 2bccea2 commit a6e4134

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
139139

140140
static final int MSG_UNBIND_METHOD = 3000;
141141
static final int MSG_BIND_METHOD = 3010;
142+
static final int MSG_SET_ACTIVE = 3020;
142143

143144
static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
144145

@@ -413,13 +414,9 @@ public void onReceive(Context context, Intent intent) {
413414
}
414415

415416
// Inform the current client of the change in active status
416-
try {
417-
if (mCurClient != null && mCurClient.client != null) {
418-
mCurClient.client.setActive(mScreenOn);
419-
}
420-
} catch (RemoteException e) {
421-
Slog.w(TAG, "Got RemoteException sending 'screen on/off' notification to pid "
422-
+ mCurClient.pid + " uid " + mCurClient.uid);
417+
if (mCurClient != null && mCurClient.client != null) {
418+
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
419+
MSG_SET_ACTIVE, mScreenOn ? 1 : 0, mCurClient));
423420
}
424421
}
425422
}
@@ -882,17 +879,12 @@ void unbindCurrentClientLocked() {
882879
MSG_UNBIND_INPUT, mCurMethod));
883880
}
884881
}
882+
883+
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
884+
MSG_SET_ACTIVE, 0, mCurClient));
885885
executeOrSendMessage(mCurClient.client, mCaller.obtainMessageIO(
886886
MSG_UNBIND_METHOD, mCurSeq, mCurClient.client));
887887
mCurClient.sessionRequested = false;
888-
889-
// Call setActive(false) on the old client
890-
try {
891-
mCurClient.client.setActive(false);
892-
} catch (RemoteException e) {
893-
Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
894-
+ mCurClient.pid + " uid " + mCurClient.uid);
895-
}
896888
mCurClient = null;
897889

898890
hideInputMethodMenuLocked();
@@ -987,12 +979,8 @@ InputBindResult startInputUncheckedLocked(ClientState cs,
987979

988980
// If the screen is on, inform the new client it is active
989981
if (mScreenOn) {
990-
try {
991-
cs.client.setActive(mScreenOn);
992-
} catch (RemoteException e) {
993-
Slog.w(TAG, "Got RemoteException sending setActive notification to pid "
994-
+ cs.pid + " uid " + cs.uid);
995-
}
982+
executeOrSendMessage(cs.client, mCaller.obtainMessageIO(
983+
MSG_SET_ACTIVE, mScreenOn ? 1 : 0, cs));
996984
}
997985
}
998986

@@ -2140,6 +2128,15 @@ public boolean handleMessage(Message msg) {
21402128
Slog.w(TAG, "Client died receiving input method " + args.arg2);
21412129
}
21422130
return true;
2131+
case MSG_SET_ACTIVE:
2132+
try {
2133+
((ClientState)msg.obj).client.setActive(msg.arg1 != 0);
2134+
} catch (RemoteException e) {
2135+
Slog.w(TAG, "Got RemoteException sending setActive(false) notification to pid "
2136+
+ ((ClientState)msg.obj).pid + " uid "
2137+
+ ((ClientState)msg.obj).uid);
2138+
}
2139+
return true;
21432140

21442141
// --------------------------------------------------------------
21452142
case MSG_HARD_KEYBOARD_SWITCH_CHANGED:

0 commit comments

Comments
 (0)