From 41f3427381d77fa9fcd12ed820716ebff7011c16 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 14 Dec 2015 15:41:52 -0800 Subject: [PATCH] Fix IMM#showInputMethodAndSubtypeEnabler(). At least on AOSP InputMethodManager#showInputMethodAndSubtypeEnabler() has been broken since its beginning. As of Android M, there are three separate issues: 1. Type mismatch in message dispatching layer. 2. It does not correctly reject API calls from clients that do not have IME focus. 3. Context#startActivityAsUser(intent, null, UserHandle.CURRENT) ends up with java.lang.SecurityException: Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL. Given that we have a good alternative to achieve the same result, it would make sense to deprecate that method and encourage developers to use Intent-based solution instead. Before doing that, this CL fixes the issues just for the record. Bug: 26189558 Change-Id: Ic7a0df3203fee19542a3143abba9bc31baf9698a --- .../android/server/InputMethodManagerService.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index 04abccace0a74..15b55026ae662 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -2383,10 +2383,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return; } synchronized (mMethodMap) { - if (mCurClient == null || client == null - || mCurClient.client.asBinder() != client.asBinder()) { - Slog.w(TAG, "Ignoring showInputMethodAndSubtypeEnablerFromClient of: " + client); - } executeOrSendMessage(mCurMethod, mCaller.obtainMessageO( MSG_SHOW_IM_SUBTYPE_ENABLER, inputMethodId)); } @@ -2716,9 +2712,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return true; case MSG_SHOW_IM_SUBTYPE_ENABLER: - args = (SomeArgs)msg.obj; - showInputMethodAndSubtypeEnabler((String)args.arg1); - args.recycle(); + showInputMethodAndSubtypeEnabler((String)msg.obj); return true; case MSG_SHOW_IM_CONFIG: @@ -3005,7 +2999,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (!TextUtils.isEmpty(inputMethodId)) { intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, inputMethodId); } - mContext.startActivityAsUser(intent, null, UserHandle.CURRENT); + final int userId; + synchronized (mMethodMap) { + userId = mSettings.getCurrentUserId(); + } + mContext.startActivityAsUser(intent, null, UserHandle.of(userId)); } private void showConfigureInputMethods() {