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

Commit 84b0ff6d authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Simplify InputMethodUtils#setAdditionalInputMethodSubtypes()

This CL simplifies

  InputMethodUtils#setAdditionalInputMethodSubtypes()

without changing any observable behavior.

Bug: 234882948
Test: presubmit
Change-Id: I9fb99cf1fb6e6e72155a0ef84a6d96a63102406d
parent d32b7a0a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -4169,6 +4169,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        if (UserHandle.getCallingUserId() != userId) {
            mContext.enforceCallingPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
        }
        final int callingUid = Binder.getCallingUid();

        // By this IPC call, only a process which shares the same uid with the IME can add
        // additional input method subtypes to the IME.
@@ -4189,7 +4190,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub

            if (mSettings.getCurrentUserId() == userId) {
                if (!mSettings.setAdditionalInputMethodSubtypes(imiId, toBeAdded,
                        mAdditionalSubtypeMap, mIPackageManager)) {
                        mAdditionalSubtypeMap, mPackageManagerInternal, callingUid)) {
                    return;
                }
                final long ident = Binder.clearCallingIdentity();
@@ -4208,7 +4209,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                    new ArrayMap<>();
            AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
            settings.setAdditionalInputMethodSubtypes(imiId, toBeAdded, additionalSubtypeMap,
                    mIPackageManager);
                    mPackageManagerInternal, callingUid);
        }
    }

+3 −14
Original line number Diff line number Diff line
@@ -23,13 +23,10 @@ import android.annotation.UserIdInt;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.res.Resources;
import android.os.Binder;
import android.os.Build;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
@@ -45,7 +42,6 @@ import android.view.textservice.SpellCheckerInfo;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.util.ArrayUtils;
import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
import com.android.server.textservices.TextServicesManagerInternal;
@@ -877,20 +873,13 @@ final class InputMethodUtils {
        boolean setAdditionalInputMethodSubtypes(@NonNull String imeId,
                @NonNull ArrayList<InputMethodSubtype> subtypes,
                @NonNull ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap,
                @NonNull IPackageManager packageManager) {
                @NonNull PackageManagerInternal packageManagerInternal, int callingUid) {
            final InputMethodInfo imi = mMethodMap.get(imeId);
            if (imi == null) {
                return false;
            }
            final String[] packageInfos;
            try {
                packageInfos = packageManager.getPackagesForUid(Binder.getCallingUid());
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to get package infos");
                return false;
            }
            if (ArrayUtils.find(packageInfos,
                    packageInfo -> TextUtils.equals(packageInfo, imi.getPackageName())) == null) {
            if (!InputMethodUtils.checkIfPackageBelongsToUid(packageManagerInternal, callingUid,
                    imi.getPackageName())) {
                return false;
            }