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

Commit fba00864 authored by Yohei Yukaw's avatar Yohei Yukaw Committed by Android (Google) Code Review
Browse files

Merge "Verify that EditorInfo.packageName and uid are consistent"

parents 32b7f9fb a0f3ad1b
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@

package com.android.server;

import android.annotation.NonNull;
import com.android.internal.content.PackageMonitor;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController;
import com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem;
@@ -1285,13 +1286,24 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        return startInputUncheckedLocked(cs, inputContext, attribute, controlFlags);
    }

    InputBindResult startInputUncheckedLocked(ClientState cs,
    InputBindResult startInputUncheckedLocked(@NonNull ClientState cs,
            IInputContext inputContext, EditorInfo attribute, int controlFlags) {
        // If no method is currently selected, do nothing.
        if (mCurMethodId == null) {
            return mNoBinding;
        }

        if (attribute != null) {
            // We accept an empty package name as a valid data.
            if (!TextUtils.isEmpty(attribute.packageName) &&
                    !InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid,
                            attribute.packageName)) {
                Slog.e(TAG, "Rejecting this client as it reported an invalid package name."
                        + " uid=" + cs.uid + " package=" + attribute.packageName);
                return mNoBinding;
            }
        }

        if (mCurClient != cs) {
            // Was the keyguard locked when switching over to the new client?
            mCurClientInKeyguard = isKeyguardLocked();
@@ -1855,17 +1867,11 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }

        if (mCurClient != null && mCurAttribute != null) {
            final int uid = mCurClient.uid;
            final String packageName = mCurAttribute.packageName;
            if (SystemConfig.getInstance().getFixedImeApps().contains(packageName)) {
                if (InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, uid, packageName)) {
            // We have already made sure that the package name belongs to the application's UID.
            // No further UID check is required.
            if (SystemConfig.getInstance().getFixedImeApps().contains(mCurAttribute.packageName)) {
                return;
            }
                // TODO: Do we need to lock the input method when the application reported an
                // incorrect package name?
                Slog.e(TAG, "Ignoring FixedImeApps due to the validation failure. uid=" + uid
                        + " package=" + packageName);
            }
        }

        // See if we need to notify a subtype change within the same IME.