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

Commit 0b169d04 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Enable background users to call IMM#setAdditionalInputMethodSubtypes

With this CL,

  InputMethodManager#setAdditionalInputMethodSubtypes()

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

Bug: 34886274
Bug: 237316307
Test: atest CtsInputMethodTestCases:InputMethodSubtypeTest
Change-Id: Iac778d95846843504f6e00b3b939ef0794013b02
parent ce335c39
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -192,9 +192,9 @@ final class IInputMethodManagerInvoker {

    @AnyThread
    void setAdditionalInputMethodSubtypes(@NonNull String imeId,
            @NonNull InputMethodSubtype[] subtypes) {
            @NonNull InputMethodSubtype[] subtypes, @UserIdInt int userId) {
        try {
            mTarget.setAdditionalInputMethodSubtypes(imeId, subtypes);
            mTarget.setAdditionalInputMethodSubtypes(imeId, subtypes, userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+1 −1
Original line number Diff line number Diff line
@@ -3610,7 +3610,7 @@ public final class InputMethodManager {
    @Deprecated
    public void setAdditionalInputMethodSubtypes(@NonNull String imiId,
            @NonNull InputMethodSubtype[] subtypes) {
        mServiceInvoker.setAdditionalInputMethodSubtypes(imiId, subtypes);
        mServiceInvoker.setAdditionalInputMethodSubtypes(imiId, subtypes, UserHandle.myUserId());
    }

    @Nullable
+5 −1
Original line number Diff line number Diff line
@@ -92,7 +92,11 @@ interface IInputMethodManager {
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    @nullable InputMethodSubtype getCurrentInputMethodSubtype(int userId);

    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes,
            int userId);

    // This is kept due to @UnsupportedAppUsage.
    // TODO(Bug 113914148): Consider removing this.
    int getInputMethodWindowVisibleHeight(in IInputMethodClient client);
+26 −12
Original line number Diff line number Diff line
@@ -4161,7 +4161,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    }

    @Override
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes,
            @UserIdInt int userId) {
        if (UserHandle.getCallingUserId() != userId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }

        // By this IPC call, only a process which shares the same uid with the IME can add
        // additional input method subtypes to the IME.
        if (TextUtils.isEmpty(imiId) || subtypes == null) return;
@@ -4175,23 +4180,32 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            }
        }
        synchronized (ImfLock.class) {
            if (!calledFromValidUserLocked()) {
                return;
            }
            if (!mSystemReady) {
                return;
            }

            if (mSettings.getCurrentUserId() == userId) {
                if (!mSettings.setAdditionalInputMethodSubtypes(imiId, toBeAdded,
                        mAdditionalSubtypeMap, mIPackageManager)) {
                    return;
                }

                final long ident = Binder.clearCallingIdentity();
                try {
                    buildInputMethodListLocked(false /* resetDefaultEnabledIme */);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
                return;
            }

            final ArrayMap<String, InputMethodInfo> methodMap = queryMethodMapForUser(userId);
            final InputMethodSettings settings = new InputMethodSettings(mContext, methodMap,
                    userId, false);
            final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap =
                    new ArrayMap<>();
            AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
            settings.setAdditionalInputMethodSubtypes(imiId, toBeAdded, additionalSubtypeMap,
                    mIPackageManager);
        }
    }