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

Commit 5c3d18d1 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android Git Automerger
Browse files

am b5d063dc: Merge "Work on issue #17506095: Plumb a new configuration to IMMS" into lmp-dev

* commit 'b5d063dc8126d9cddf5dd5172f32213469b2c11b':
  Work on issue #17506095: Plumb a new configuration to IMMS
parents d498da74 ca5e72c5
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.inputmethod;

import android.app.AppOpsManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -636,6 +637,25 @@ public class InputMethodUtils {
                : imiLabel;
    }

    /**
     * Returns true if a package name belongs to a UID.
     *
     * <p>This is a simple wrapper of {@link AppOpsManager#checkPackage(int, String)}.</p>
     * @param appOpsManager the {@link AppOpsManager} object to be used for the validation.
     * @param uid the UID to be validated.
     * @param packageName the package name.
     * @return {@code true} if the package name belongs to the UID.
     */
    public static boolean checkIfPackageBelongsToUid(final AppOpsManager appOpsManager,
            final int uid, final String packageName) {
        try {
            appOpsManager.checkPackage(uid, packageName);
            return true;
        } catch (SecurityException e) {
            return false;
        }
    }

    /**
     * Utility class for putting and getting settings for InputMethod
     * TODO: Move all putters and getters of settings to this class.
+17 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import org.xmlpull.v1.XmlSerializer;
import android.app.ActivityManagerNative;
import android.app.AppGlobals;
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.app.IUserSwitchObserver;
import android.app.KeyguardManager;
import android.app.Notification;
@@ -175,6 +176,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    private InputMethodFileManager mFileManager;
    private final HardKeyboardListener mHardKeyboardListener;
    private final WindowManagerService mWindowManagerService;
    private final AppOpsManager mAppOpsManager;

    final InputBindResult mNoBinding = new InputBindResult(null, null, null, -1, -1);

@@ -643,6 +645,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            }
        }, true /*asyncHandler*/);
        mWindowManagerService = windowManager;
        mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
        mHardKeyboardListener = new HardKeyboardListener();
        mHasFeature = context.getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_INPUT_METHODS);
@@ -1746,6 +1749,20 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            throw new IllegalArgumentException("Unknown id: " + id);
        }

        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)) {
                    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.
        if (id.equals(mCurMethodId)) {
            final int subtypeCount = info.getSubtypeCount();