From 19e18b6c85ae3f0947e06f9d67f4abda6687672b Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 26 Jul 2022 08:12:26 +0900 Subject: [PATCH] Let getEnabledInputMethodSubtypeList() take userId This CL lets IInputMethodManager#getEnabledInputMethodSubtypeList() take the useId as an input parameter for consistency with other query methods. There should be no developer observable behavior change because now InputMethodManager#getEnabledInputMethodSubtypeList() specifies its own user ID. Bug: 34886274 Test: make -j CtsInputMethod1 \ CtsInputMethod2 \ CtsInputMethodServiceDeviceTests \ CtsInputMethodServiceEventProvider \ CtsInputMethodServiceHostTestCases \ EditTextApp && atest CtsInputMethodServiceHostTestCases Change-Id: Ie213ef7e04d6337e303ea331d0a00c7d7f9a6d1a --- .../view/inputmethod/IInputMethodManagerInvoker.java | 4 ++-- .../android/view/inputmethod/InputMethodManager.java | 6 ++++-- .../com/android/internal/view/IInputMethodManager.aidl | 5 ++++- .../server/inputmethod/InputMethodManagerService.java | 10 +++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java b/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java index fc1ede0948259..7783b343bdc82 100644 --- a/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java +++ b/core/java/android/view/inputmethod/IInputMethodManagerInvoker.java @@ -90,10 +90,10 @@ final class IInputMethodManagerInvoker { @AnyThread @NonNull List getEnabledInputMethodSubtypeList(@Nullable String imiId, - boolean allowsImplicitlySelectedSubtypes) { + boolean allowsImplicitlySelectedSubtypes, @UserIdInt int userId) { try { return mTarget.getEnabledInputMethodSubtypeList(imiId, - allowsImplicitlySelectedSubtypes); + allowsImplicitlySelectedSubtypes, userId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 654713be416da..d73eecdf3e3ff 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1514,7 +1514,8 @@ public final class InputMethodManager { boolean allowsImplicitlySelectedSubtypes) { return mServiceInvoker.getEnabledInputMethodSubtypeList( imi == null ? null : imi.getId(), - allowsImplicitlySelectedSubtypes); + allowsImplicitlySelectedSubtypes, + UserHandle.myUserId()); } /** @@ -3320,7 +3321,8 @@ public final class InputMethodManager { return false; } final List enabledSubtypes = - mServiceInvoker.getEnabledInputMethodSubtypeList(imeId, true); + mServiceInvoker.getEnabledInputMethodSubtypeList(imeId, true, + UserHandle.myUserId()); final int numSubtypes = enabledSubtypes.size(); for (int i = 0; i < numSubtypes; ++i) { final InputMethodSubtype enabledSubtype = enabledSubtypes.get(i); diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl index 9e0b2495969e0..84412bced26a6 100644 --- a/core/java/com/android/internal/view/IInputMethodManager.aidl +++ b/core/java/com/android/internal/view/IInputMethodManager.aidl @@ -45,8 +45,11 @@ interface IInputMethodManager { + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)") List getEnabledInputMethodList(int userId); + @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = " + + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)") List getEnabledInputMethodSubtypeList(in @nullable String imiId, - boolean allowsImplicitlySelectedSubtypes); + boolean allowsImplicitlySelectedSubtypes, int userId); + @nullable InputMethodSubtype getLastInputMethodSubtype(); boolean showSoftInput(in IInputMethodClient client, @nullable IBinder windowToken, int flags, diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 74eb91afb4bf2..71aaf0bc7a610 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2202,16 +2202,20 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub * @param imiId if null, returns enabled subtypes for the current {@link InputMethodInfo}. * @param allowsImplicitlySelectedSubtypes {@code true} to return the implicitly selected * subtypes. + * @param userId the user ID to be queried about. */ @Override public List getEnabledInputMethodSubtypeList(String imiId, - boolean allowsImplicitlySelectedSubtypes) { - final int callingUserId = UserHandle.getCallingUserId(); + boolean allowsImplicitlySelectedSubtypes, @UserIdInt int userId) { + if (UserHandle.getCallingUserId() != userId) { + mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); + } + synchronized (ImfLock.class) { final long ident = Binder.clearCallingIdentity(); try { return getEnabledInputMethodSubtypeListLocked(imiId, - allowsImplicitlySelectedSubtypes, callingUserId); + allowsImplicitlySelectedSubtypes, userId); } finally { Binder.restoreCallingIdentity(ident); }