diff options
3 files changed, 32 insertions, 19 deletions
diff --git a/core/java/android/inputmethodservice/IInputMethodWrapper.java b/core/java/android/inputmethodservice/IInputMethodWrapper.java index 2d67875..d59c7b8 100644 --- a/core/java/android/inputmethodservice/IInputMethodWrapper.java +++ b/core/java/android/inputmethodservice/IInputMethodWrapper.java @@ -284,6 +284,12 @@ class IInputMethodWrapper extends IInputMethod.Stub flags, resultReceiver)); } + @Override + public void removeSoftInputMessages() { + mCaller.removeMessages(DO_SHOW_SOFT_INPUT); + mCaller.removeMessages(DO_HIDE_SOFT_INPUT); + } + public void changeInputMethodSubtype(InputMethodSubtype subtype) { mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_CHANGE_INPUTMETHOD_SUBTYPE, subtype)); diff --git a/core/java/com/android/internal/view/IInputMethod.aidl b/core/java/com/android/internal/view/IInputMethod.aidl index c7fcab8..c2a7fc7 100644 --- a/core/java/com/android/internal/view/IInputMethod.aidl +++ b/core/java/com/android/internal/view/IInputMethod.aidl @@ -33,26 +33,28 @@ import com.android.internal.view.IInputMethodSession; * Service). * {@hide} */ -oneway interface IInputMethod { - void attachToken(IBinder token); +interface IInputMethod { + oneway void attachToken(IBinder token); - void bindInput(in InputBinding binding); + oneway void bindInput(in InputBinding binding); - void unbindInput(); + oneway void unbindInput(); - void startInput(in IInputContext inputContext, in EditorInfo attribute); + oneway void startInput(in IInputContext inputContext, in EditorInfo attribute); - void restartInput(in IInputContext inputContext, in EditorInfo attribute); + oneway void restartInput(in IInputContext inputContext, in EditorInfo attribute); - void createSession(IInputMethodCallback callback); + oneway void createSession(IInputMethodCallback callback); - void setSessionEnabled(IInputMethodSession session, boolean enabled); + oneway void setSessionEnabled(IInputMethodSession session, boolean enabled); - void revokeSession(IInputMethodSession session); + oneway void revokeSession(IInputMethodSession session); - void showSoftInput(int flags, in ResultReceiver resultReceiver); + oneway void showSoftInput(int flags, in ResultReceiver resultReceiver); - void hideSoftInput(int flags, in ResultReceiver resultReceiver); + oneway void hideSoftInput(int flags, in ResultReceiver resultReceiver); - void changeInputMethodSubtype(in InputMethodSubtype subtype); + void removeSoftInputMessages(); + + oneway void changeInputMethodSubtype(in InputMethodSubtype subtype); } diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index dbd743a..f037ea5 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -1204,7 +1204,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mCurId = info.getId(); mCurToken = new Binder(); try { - if (DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); + if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken); mIWindowManager.addWindowToken(mCurToken, WindowManager.LayoutParams.TYPE_INPUT_METHOD); } catch (RemoteException e) { @@ -1242,14 +1242,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub public void onServiceConnected(ComponentName name, IBinder service) { synchronized (mMethodMap) { if (mCurIntent != null && name.equals(mCurIntent.getComponent())) { + IInputMethod prevMethod = mCurMethod; mCurMethod = IInputMethod.Stub.asInterface(service); if (mCurToken == null) { Slog.w(TAG, "Service connected without a token!"); unbindCurrentMethodLocked(false, false); return; } - // Remove commands relating to the previous service. Otherwise WindowManagerService - // will reject the command because the token attached to these messages is invalid. + // Remove messages relating to the previous service. Otherwise WindowManagerService + // will throw a BadTokenException because the old token is being removed. + if (prevMethod != null) { + try { + prevMethod.removeSoftInputMessages(); + } catch (RemoteException e) { + } + } mCaller.removeMessages(MSG_SHOW_SOFT_INPUT); mCaller.removeMessages(MSG_HIDE_SOFT_INPUT); if (true || DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); @@ -2314,8 +2321,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub try { if (true || DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".showSoftInput(" + msg.arg1 + ", " + args.arg2 + ")"); - ((IInputMethod)args.arg1).showSoftInput(msg.arg1, - (ResultReceiver)args.arg2); + ((IInputMethod)args.arg1).showSoftInput(msg.arg1, (ResultReceiver)args.arg2); } catch (RemoteException e) { } args.recycle(); @@ -2325,8 +2331,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub try { if (true || DEBUG) Slog.v(TAG, "Calling " + args.arg1 + ".hideSoftInput(0, " + args.arg2 + ")"); - ((IInputMethod)args.arg1).hideSoftInput(0, - (ResultReceiver)args.arg2); + ((IInputMethod)args.arg1).hideSoftInput(0, (ResultReceiver)args.arg2); } catch (RemoteException e) { } args.recycle(); |