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

Commit bedef9c2 authored by Rhed Jao's avatar Rhed Jao Committed by Android (Google) Code Review
Browse files

Merge "Enforce package visibility rules on switch input method apis"

parents 3f98c7d7 567dafb8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2268,6 +2268,8 @@ public class InputMethodService extends AbstractInputMethodService {
     * current input field.
     * 
     * @param id Unique identifier of the new input method to start.
     * @throws IllegalArgumentException if the input method is unknown or filtered
     * by the rules of <a href="/training/basics/intents/package-visibility">package visibility</a>.
     */
    public void switchInputMethod(String id) {
        mPrivOps.setInputMethod(id);
@@ -2280,6 +2282,8 @@ public class InputMethodService extends AbstractInputMethodService {
     *
     * @param id Unique identifier of the new input method to start.
     * @param subtype The new subtype of the new input method to be switched to.
     * @throws IllegalArgumentException if the input method is unknown or filtered
     * by the rules of <a href="/training/basics/intents/package-visibility">package visibility</a>.
     */
    public final void switchInputMethod(String id, InputMethodSubtype subtype) {
        mPrivOps.setInputMethodAndSubtype(id, subtype);
+4 −0
Original line number Diff line number Diff line
@@ -3115,6 +3115,8 @@ public final class InputMethodManager {
     * when it was started, which allows it to perform this operation on
     * itself.
     * @param id The unique identifier for the new input method to be switched to.
     * @throws IllegalArgumentException if the input method is unknown or filtered by the rules of
     * <a href="/training/basics/intents/package-visibility">package visibility</a>.
     * @deprecated Use {@link InputMethodService#switchInputMethod(String)}
     * instead. This method was intended for IME developers who should be accessing APIs through
     * the service. APIs in this class are intended for app developers interacting with the IME.
@@ -3185,6 +3187,8 @@ public final class InputMethodManager {
     * itself.
     * @param id The unique identifier for the new input method to be switched to.
     * @param subtype The new subtype of the new input method to be switched to.
     * @throws IllegalArgumentException if the input method is unknown or filtered by the rules of
     * <a href="/training/basics/intents/package-visibility">package visibility</a>.
     * @deprecated Use
     * {@link InputMethodService#switchInputMethod(String, InputMethodSubtype)}
     * instead. This method was intended for IME developers who should be accessing APIs through
+22 −3
Original line number Diff line number Diff line
@@ -3204,7 +3204,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    void setInputMethodLocked(String id, int subtypeId) {
        InputMethodInfo info = mMethodMap.get(id);
        if (info == null) {
            throw new IllegalArgumentException("Unknown id: " + id);
            throw getExceptionForUnknownImeId(id);
        }

        // See if we need to notify a subtype change within the same IME.
@@ -3946,12 +3946,25 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    @NonNull
    private static IllegalArgumentException getExceptionForUnknownImeId(
            @Nullable String imeId) {
        return new IllegalArgumentException("Unknown id: " + imeId);
    }

    @BinderThread
    private void setInputMethod(@NonNull IBinder token, String id) {
        final int callingUid = Binder.getCallingUid();
        final int userId = UserHandle.getUserId(callingUid);
        synchronized (ImfLock.class) {
            if (!calledWithValidTokenLocked(token)) {
                return;
            }
            final InputMethodInfo imi = mMethodMap.get(id);
            if (imi == null || !canCallerAccessInputMethod(
                    imi.getPackageName(), callingUid, userId, mSettings)) {
                throw getExceptionForUnknownImeId(id);
            }
            setInputMethodWithSubtypeIdLocked(token, id, NOT_A_SUBTYPE_ID);
        }
    }
@@ -3959,14 +3972,20 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    @BinderThread
    private void setInputMethodAndSubtype(@NonNull IBinder token, String id,
            InputMethodSubtype subtype) {
        final int callingUid = Binder.getCallingUid();
        final int userId = UserHandle.getUserId(callingUid);
        synchronized (ImfLock.class) {
            if (!calledWithValidTokenLocked(token)) {
                return;
            }
            final InputMethodInfo imi = mMethodMap.get(id);
            if (imi == null || !canCallerAccessInputMethod(
                    imi.getPackageName(), callingUid, userId, mSettings)) {
                throw getExceptionForUnknownImeId(id);
            }
            if (subtype != null) {
                setInputMethodWithSubtypeIdLocked(token, id,
                        SubtypeUtils.getSubtypeIdFromHashCode(mMethodMap.get(id),
                                subtype.hashCode()));
                        SubtypeUtils.getSubtypeIdFromHashCode(imi, subtype.hashCode()));
            } else {
                setInputMethod(token, id);
            }