diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 18f757c073696..aee4b1f638129 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -966,7 +966,26 @@ public final class InputMethodManager { */ public List getInputMethodList() { try { - return mService.getInputMethodList(); + // We intentionally do not use UserHandle.getCallingUserId() here because for system + // services InputMethodManagerInternal.getInputMethodListAsUser() should be used + // instead. + return mService.getInputMethodList(UserHandle.myUserId()); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Returns the list of installed input methods for the specified user. + * + * @param userId user ID to query + * @return {@link List} of {@link InputMethodInfo}. + * @hide + */ + @RequiresPermission(INTERACT_ACROSS_USERS_FULL) + public List getInputMethodListAsUser(@UserIdInt int userId) { + try { + return mService.getInputMethodList(userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index 98e854cc40a27..cb18ca1fb7fe3 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -34,7 +34,7 @@ interface IInputMethodManager { int untrustedDisplayId); // TODO: Use ParceledListSlice instead - List getInputMethodList(); + List getInputMethodList(int userId); // TODO: Use ParceledListSlice instead List getEnabledInputMethodList(int userId); List getEnabledInputMethodSubtypeList(in String imiId, diff --git a/packages/SettingsLib/src/com/android/settingslib/users/AppRestrictionsHelper.java b/packages/SettingsLib/src/com/android/settingslib/users/AppRestrictionsHelper.java index 9451b36204180..ec8bb80bee131 100644 --- a/packages/SettingsLib/src/com/android/settingslib/users/AppRestrictionsHelper.java +++ b/packages/SettingsLib/src/com/android/settingslib/users/AppRestrictionsHelper.java @@ -420,7 +420,7 @@ public class AppRestrictionsHelper { List getInputMethodList() { InputMethodManager imm = (InputMethodManager) getContext().getSystemService( Context.INPUT_METHOD_SERVICE); - return imm.getInputMethodList(); + return imm.getInputMethodListAsUser(mUser.getIdentifier()); } } } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index f0dce78722a2b..144f2b6b143fa 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1627,10 +1627,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } @Override - public List getInputMethodList() { - final int callingUserId = UserHandle.getCallingUserId(); + public List getInputMethodList(@UserIdInt int userId) { + if (UserHandle.getCallingUserId() != userId) { + mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); + } synchronized (mMethodMap) { - final int[] resolvedUserIds = InputMethodUtils.resolveUserId(callingUserId, + final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, mSettings.getCurrentUserId(), null); if (resolvedUserIds.length != 1) { return Collections.emptyList(); diff --git a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java index 109024d0d2f74..500c388ec99eb 100644 --- a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java @@ -1236,8 +1236,11 @@ public final class MultiClientInputMethodManagerService { @BinderThread @Override - public List getInputMethodList() { - return mInputMethodInfoMap.getAsList(UserHandle.getUserId(Binder.getCallingUid())); + public List getInputMethodList(@UserIdInt int userId) { + if (UserHandle.getCallingUserId() != userId) { + mContext.enforceCallingPermission(INTERACT_ACROSS_USERS_FULL, null); + } + return mInputMethodInfoMap.getAsList(userId); } @BinderThread