Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d20eef82 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Query right user's system IMEs in AppRestrictionsHelper

It turns out that AppRestrictionsHelper#addSystemImes() has always
queried for the owner user's system IMEs despite the fact that it's
trying to query system IMEs for a restricted profile user.  This
behavior has not changed since its beginning [1].

Most likely people would not have noticed this though, because:

* Settings app does not show a menu item to create a restricted user
   on phone devices.
 * Even if it's available, most people do not use restricted users.
 * Even if someone created a restrected user, most likely the owner
   user and the restrected user share the same set of system IMEs,
   which are defined as "pre-installed" IMEs.

Anyway, AppRestrictionsHelper#addSystemImes() will start using a newly
introduced @hide API IMM#getEnabledInputMethodListAsUser() so that it
can query for the right user's system IMEs, instead of querying owner
user's ones.

 [1]: Ifced841ad3bfbde33d2403356216dd1749b7fa9a
      a7a93784d1f9798d37cb618def1a558f8d626f0f

Bug: 122164939
Test: atest SettingsLibTests:AppRestrictionsHelperTest
Test: manually done as follows.
  1. Build aosp_taimen-userdebug and flash it.
  2. adb shell pm create-user --restricted test_profile
  3. adb shell am start -a android.settings.USER_SETTINGS
  4. Click the gear icon next to the "test_profile" user.
  5. By adding a log, make sure that IMMS#getInputMethodList()
     gets called with userId = 10.
Change-Id: I5b50b5fe143c74c87b331bda3e5bcc4d6248436e
parent 3b9919d1
Loading
Loading
Loading
Loading
+20 −1
Original line number Original line Diff line number Diff line
@@ -966,7 +966,26 @@ public final class InputMethodManager {
     */
     */
    public List<InputMethodInfo> getInputMethodList() {
    public List<InputMethodInfo> getInputMethodList() {
        try {
        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<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) {
        try {
            return mService.getInputMethodList(userId);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+1 −1
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@ interface IInputMethodManager {
            int untrustedDisplayId);
            int untrustedDisplayId);


    // TODO: Use ParceledListSlice instead
    // TODO: Use ParceledListSlice instead
    List<InputMethodInfo> getInputMethodList();
    List<InputMethodInfo> getInputMethodList(int userId);
    // TODO: Use ParceledListSlice instead
    // TODO: Use ParceledListSlice instead
    List<InputMethodInfo> getEnabledInputMethodList(int userId);
    List<InputMethodInfo> getEnabledInputMethodList(int userId);
    List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in String imiId,
    List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in String imiId,
+1 −1
Original line number Original line Diff line number Diff line
@@ -420,7 +420,7 @@ public class AppRestrictionsHelper {
        List<InputMethodInfo> getInputMethodList() {
        List<InputMethodInfo> getInputMethodList() {
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
                    Context.INPUT_METHOD_SERVICE);
                    Context.INPUT_METHOD_SERVICE);
            return imm.getInputMethodList();
            return imm.getInputMethodListAsUser(mUser.getIdentifier());
        }
        }
    }
    }
}
}
+5 −3
Original line number Original line Diff line number Diff line
@@ -1627,10 +1627,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    }
    }


    @Override
    @Override
    public List<InputMethodInfo> getInputMethodList() {
    public List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) {
        final int callingUserId = UserHandle.getCallingUserId();
        if (UserHandle.getCallingUserId() != userId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }
        synchronized (mMethodMap) {
        synchronized (mMethodMap) {
            final int[] resolvedUserIds = InputMethodUtils.resolveUserId(callingUserId,
            final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId,
                    mSettings.getCurrentUserId(), null);
                    mSettings.getCurrentUserId(), null);
            if (resolvedUserIds.length != 1) {
            if (resolvedUserIds.length != 1) {
                return Collections.emptyList();
                return Collections.emptyList();
+5 −2
Original line number Original line Diff line number Diff line
@@ -1236,8 +1236,11 @@ public final class MultiClientInputMethodManagerService {


        @BinderThread
        @BinderThread
        @Override
        @Override
        public List<InputMethodInfo> getInputMethodList() {
        public List<InputMethodInfo> getInputMethodList(@UserIdInt int userId) {
            return mInputMethodInfoMap.getAsList(UserHandle.getUserId(Binder.getCallingUid()));
            if (UserHandle.getCallingUserId() != userId) {
                mContext.enforceCallingPermission(INTERACT_ACROSS_USERS_FULL, null);
            }
            return mInputMethodInfoMap.getAsList(userId);
        }
        }


        @BinderThread
        @BinderThread