Loading core/java/com/android/internal/inputmethod/InputMethodUtils.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading services/core/java/com/android/server/InputMethodManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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); Loading Loading @@ -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(); Loading Loading
core/java/com/android/internal/inputmethod/InputMethodUtils.java +20 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading
services/core/java/com/android/server/InputMethodManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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); Loading Loading @@ -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(); Loading