Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +4 −7 Original line number Diff line number Diff line Loading @@ -69,7 +69,6 @@ import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationManager; Loading Loading @@ -307,7 +306,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final boolean mHasFeature; private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap = new ArrayMap<>(); private final AppOpsManager mAppOpsManager; private final UserManager mUserManager; private final UserManagerInternal mUserManagerInternal; private final InputMethodMenuController mMenuController; Loading Loading @@ -1734,7 +1732,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mInputMethodDeviceConfigs = new InputMethodDeviceConfigs(); mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy; mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); mAppOpsManager = mContext.getSystemService(AppOpsManager.class); mUserManager = mContext.getSystemService(UserManager.class); mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); mAccessibilityManager = AccessibilityManager.getInstance(context); Loading Loading @@ -2520,7 +2517,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub null, null, null, selectedMethodId, getSequenceNumberLocked(), null, false); } if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.mUid, if (!InputMethodUtils.checkIfPackageBelongsToUid(mPackageManagerInternal, cs.mUid, editorInfo.packageName)) { Slog.e(TAG, "Rejecting this client as it reported an invalid package name." + " uid=" + cs.mUid + " package=" + editorInfo.packageName); Loading Loading @@ -3957,7 +3954,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return false; } if (getCurIntentLocked() != null && InputMethodUtils.checkIfPackageBelongsToUid( mAppOpsManager, mPackageManagerInternal, uid, getCurIntentLocked().getComponent().getPackageName())) { return true; Loading Loading @@ -4208,8 +4205,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final int callingUid = Binder.getCallingUid(); final ComponentName imeComponentName = imeId != null ? ComponentName.unflattenFromString(imeId) : null; if (imeComponentName == null || !InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, callingUid, imeComponentName.getPackageName())) { if (imeComponentName == null || !InputMethodUtils.checkIfPackageBelongsToUid( mPackageManagerInternal, callingUid, imeComponentName.getPackageName())) { throw new SecurityException("Calling UID=" + callingUid + " does not belong to imeId=" + imeId); } Loading services/core/java/com/android/server/inputmethod/InputMethodUtils.java +10 −10 Original line number Diff line number Diff line Loading @@ -20,12 +20,12 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserHandleAware; import android.annotation.UserIdInt; import android.app.AppOpsManager; 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; Loading Loading @@ -218,20 +218,20 @@ final class InputMethodUtils { /** * 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. * <p>This is a simple wrapper of * {@link PackageManagerInternal#getPackageUid(String, long, int)}.</p> * @param packageManagerInternal the {@link PackageManagerInternal} 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. */ static boolean checkIfPackageBelongsToUid(AppOpsManager appOpsManager, static boolean checkIfPackageBelongsToUid(PackageManagerInternal packageManagerInternal, int uid, String packageName) { try { appOpsManager.checkPackage(uid, packageName); return true; } catch (SecurityException e) { return false; } // PackageManagerInternal#getPackageUid() doesn't check MATCH_INSTANT/MATCH_APEX as of // writing. So setting 0 should be fine. return packageManagerInternal.getPackageUid(packageName, 0 /* flags */, UserHandle.getUserId(uid)) == uid; } /** Loading Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +4 −7 Original line number Diff line number Diff line Loading @@ -69,7 +69,6 @@ import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.AppGlobals; import android.app.AppOpsManager; import android.app.KeyguardManager; import android.app.Notification; import android.app.NotificationManager; Loading Loading @@ -307,7 +306,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final boolean mHasFeature; private final ArrayMap<String, List<InputMethodSubtype>> mAdditionalSubtypeMap = new ArrayMap<>(); private final AppOpsManager mAppOpsManager; private final UserManager mUserManager; private final UserManagerInternal mUserManagerInternal; private final InputMethodMenuController mMenuController; Loading Loading @@ -1734,7 +1732,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mInputMethodDeviceConfigs = new InputMethodDeviceConfigs(); mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy; mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class); mAppOpsManager = mContext.getSystemService(AppOpsManager.class); mUserManager = mContext.getSystemService(UserManager.class); mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); mAccessibilityManager = AccessibilityManager.getInstance(context); Loading Loading @@ -2520,7 +2517,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub null, null, null, selectedMethodId, getSequenceNumberLocked(), null, false); } if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.mUid, if (!InputMethodUtils.checkIfPackageBelongsToUid(mPackageManagerInternal, cs.mUid, editorInfo.packageName)) { Slog.e(TAG, "Rejecting this client as it reported an invalid package name." + " uid=" + cs.mUid + " package=" + editorInfo.packageName); Loading Loading @@ -3957,7 +3954,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return false; } if (getCurIntentLocked() != null && InputMethodUtils.checkIfPackageBelongsToUid( mAppOpsManager, mPackageManagerInternal, uid, getCurIntentLocked().getComponent().getPackageName())) { return true; Loading Loading @@ -4208,8 +4205,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final int callingUid = Binder.getCallingUid(); final ComponentName imeComponentName = imeId != null ? ComponentName.unflattenFromString(imeId) : null; if (imeComponentName == null || !InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, callingUid, imeComponentName.getPackageName())) { if (imeComponentName == null || !InputMethodUtils.checkIfPackageBelongsToUid( mPackageManagerInternal, callingUid, imeComponentName.getPackageName())) { throw new SecurityException("Calling UID=" + callingUid + " does not belong to imeId=" + imeId); } Loading
services/core/java/com/android/server/inputmethod/InputMethodUtils.java +10 −10 Original line number Diff line number Diff line Loading @@ -20,12 +20,12 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserHandleAware; import android.annotation.UserIdInt; import android.app.AppOpsManager; 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; Loading Loading @@ -218,20 +218,20 @@ final class InputMethodUtils { /** * 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. * <p>This is a simple wrapper of * {@link PackageManagerInternal#getPackageUid(String, long, int)}.</p> * @param packageManagerInternal the {@link PackageManagerInternal} 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. */ static boolean checkIfPackageBelongsToUid(AppOpsManager appOpsManager, static boolean checkIfPackageBelongsToUid(PackageManagerInternal packageManagerInternal, int uid, String packageName) { try { appOpsManager.checkPackage(uid, packageName); return true; } catch (SecurityException e) { return false; } // PackageManagerInternal#getPackageUid() doesn't check MATCH_INSTANT/MATCH_APEX as of // writing. So setting 0 should be fine. return packageManagerInternal.getPackageUid(packageName, 0 /* flags */, UserHandle.getUserId(uid)) == uid; } /** Loading