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

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

Support background users to call IMM#getLastInputMethodSubtype()

This is a follow up CL to my previous CL [1], which let query APIs
defined in InputMethodManager support background users.

With this CL,

  InputMethodManager#getLastInputMethodSubtype()

is also fully supported under multi-user / multi-profile environment.

 [1]: I192a0f5a1375170d17a4c08af94f23966dbaea8b
      7f8ee4b9

Bug: 34886274
Bug: 122164939
Test: atest CtsInputMethodTestCases:InputMethodSubtypeTest
Change-Id: I48f57dc7184e85bdb422fd9d1d56e60381654125
parent 19e18b6c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -101,9 +101,9 @@ final class IInputMethodManagerInvoker {

    @AnyThread
    @Nullable
    InputMethodSubtype getLastInputMethodSubtype() {
    InputMethodSubtype getLastInputMethodSubtype(@UserIdInt int userId) {
        try {
            return mTarget.getLastInputMethodSubtype();
            return mTarget.getLastInputMethodSubtype(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -3517,7 +3517,7 @@ public final class InputMethodManager {

    @Nullable
    public InputMethodSubtype getLastInputMethodSubtype() {
        return mServiceInvoker.getLastInputMethodSubtype();
        return mServiceInvoker.getLastInputMethodSubtype(UserHandle.myUserId());
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -50,7 +50,9 @@ interface IInputMethodManager {
    List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in @nullable String imiId,
            boolean allowsImplicitlySelectedSubtypes, int userId);

    @nullable InputMethodSubtype getLastInputMethodSubtype();
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    InputMethodSubtype getLastInputMethodSubtype(int userId);

    boolean showSoftInput(in IInputMethodClient client, @nullable IBinder windowToken, int flags,
            in @nullable ResultReceiver resultReceiver, int reason);
+12 −4
Original line number Diff line number Diff line
@@ -4160,13 +4160,21 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public InputMethodSubtype getLastInputMethodSubtype() {
        synchronized (ImfLock.class) {
            if (!calledFromValidUserLocked()) {
                return null;
    public InputMethodSubtype getLastInputMethodSubtype(@UserIdInt int userId) {
        if (UserHandle.getCallingUserId() != userId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }
        synchronized (ImfLock.class) {
            if (mSettings.getCurrentUserId() == userId) {
                return mSettings.getLastInputMethodSubtypeLocked();
            }

            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(
                    mContext.getResources(), mContext.getContentResolver(), methodMap,
                    userId, false);
            return settings.getLastInputMethodSubtypeLocked();
        }
    }

    @Override