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

Commit 2422bcff authored by Taran Singh's avatar Taran Singh
Browse files

Introduce IMM#getCurrentInputMethodInfo(userId)

introduce an API for apps to query currently selected aka default input
method for current or a given user.
Existing API getEnabledInputMethodList() builds list for allenabled
IMEs, which is inefficient and redundant for several cases.

Bug: 255799034
Test: atest CtsInputMethodServiceHostTestCases:MultiUserTest
Change-Id: I60a0f67bf7d261d3a4a733adcb8a022ceac6e1db
parent 4190b857
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -54250,6 +54250,7 @@ package android.view.inputmethod {
  public final class InputMethodManager {
    method public void dispatchKeyEventFromInputMethod(@Nullable android.view.View, @NonNull android.view.KeyEvent);
    method public void displayCompletions(android.view.View, android.view.inputmethod.CompletionInfo[]);
    method @Nullable public android.view.inputmethod.InputMethodInfo getCurrentInputMethodInfo();
    method @Nullable public android.view.inputmethod.InputMethodSubtype getCurrentInputMethodSubtype();
    method @NonNull public java.util.List<android.view.inputmethod.InputMethodInfo> getEnabledInputMethodList();
    method @NonNull public java.util.List<android.view.inputmethod.InputMethodSubtype> getEnabledInputMethodSubtypeList(@Nullable android.view.inputmethod.InputMethodInfo, boolean);
+8 −0
Original line number Diff line number Diff line
@@ -16307,6 +16307,14 @@ package android.view.displayhash {
}
package android.view.inputmethod {
  public final class InputMethodManager {
    method @Nullable @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public android.view.inputmethod.InputMethodInfo getCurrentInputMethodInfoAsUser(@NonNull android.os.UserHandle);
  }
}
package android.view.translation {
  public final class TranslationCapability implements android.os.Parcelable {
+15 −0
Original line number Diff line number Diff line
@@ -210,6 +210,21 @@ final class IInputMethodManagerGlobalInvoker {
        }
    }

    @AnyThread
    @Nullable
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
    static InputMethodInfo getCurrentInputMethodInfoAsUser(@UserIdInt int userId) {
        final IInputMethodManager service = getService();
        if (service == null) {
            return null;
        }
        try {
            return service.getCurrentInputMethodInfoAsUser(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @AnyThread
    @NonNull
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
+22 −0
Original line number Diff line number Diff line
@@ -331,6 +331,28 @@ public final class InputMethodInfo implements Parcelable {
        mIsVrOnly = isVrOnly;
    }

    /**
     * @hide
     */
    public InputMethodInfo(InputMethodInfo source) {
        mId = source.mId;
        mSettingsActivityName = source.mSettingsActivityName;
        mIsDefaultResId = source.mIsDefaultResId;
        mIsAuxIme = source.mIsAuxIme;
        mSupportsSwitchingToNextInputMethod = source.mSupportsSwitchingToNextInputMethod;
        mInlineSuggestionsEnabled = source.mInlineSuggestionsEnabled;
        mSupportsInlineSuggestionsWithTouchExploration =
                source.mSupportsInlineSuggestionsWithTouchExploration;
        mSuppressesSpellChecker = source.mSuppressesSpellChecker;
        mShowInInputMethodPicker = source.mShowInInputMethodPicker;
        mIsVrOnly = source.mIsVrOnly;
        mService = source.mService;
        mSubtypes = source.mSubtypes;
        mHandledConfigChanges = source.mHandledConfigChanges;
        mSupportsStylusHandwriting = source.mSupportsStylusHandwriting;
        mForceDefault = source.mForceDefault;
    }

    InputMethodInfo(Parcel source) {
        mId = source.readString();
        mSettingsActivityName = source.readString();
+33 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UiThread;
@@ -1594,6 +1596,37 @@ public final class InputMethodManager {
        return IInputMethodManagerGlobalInvoker.getInputMethodList(userId, directBootAwareness);
    }

    /**
     * Returns the {@link InputMethodInfo} of the currently selected input method (for the process's
     * user).
     *
     * <p>On multi user environment, this API returns a result for the calling process user.</p>
     */
    @Nullable
    public InputMethodInfo getCurrentInputMethodInfo() {
        // We intentionally do not use UserHandle.getCallingUserId() here because for system
        // services InputMethodManagerInternal.getCurrentInputMethodInfoForUser() should be used
        // instead.
        return IInputMethodManagerGlobalInvoker.getCurrentInputMethodInfoAsUser(
                UserHandle.myUserId());
    }

    /**
     * Returns the {@link InputMethodInfo} for currently selected input method for the given user.
     *
     * @param user user to query.
     * @hide
     */
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL)
    @Nullable
    @SystemApi
    @SuppressLint("UserHandle")
    public InputMethodInfo getCurrentInputMethodInfoAsUser(@NonNull UserHandle user) {
        Objects.requireNonNull(user);
        return IInputMethodManagerGlobalInvoker.getCurrentInputMethodInfoAsUser(
                user.getIdentifier());
    }

    /**
     * Returns the list of enabled input methods.
     *
Loading