From df401875f19ae667afb83e2bd6623fd654c493c8 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 22 Jul 2024 17:31:27 +0000 Subject: Reject pseudo userId in IMM#get*InputMethodList() As a preparation before removing the dependency on ImfLock.class from IME query APIs defined in InputMethodManager, this CL aims to clarify that pseudo userIds (e.g. UserHandle#USER_ALL) have never been supported in these APIs. Note that this refinement should be invisible to app developers, who cannot directly pass the userId to the underlying IPC methods such as IInputMethodManager#getCurrentInputMethodInfoAsUser(). Bug: 354323416 Test: presubmit Flag: EXEMPT refactor Change-Id: I93e6a6ba80cfe393b2d39ea03a5d7f97c091aed3 --- .../inputmethod/InputMethodManagerService.java | 41 +++++++++------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index a9e9dcfa6b2f..cbe202b5adc8 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1483,17 +1483,15 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mContext.enforceCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } + if (!mUserManagerInternal.exists(userId)) { + return InputMethodInfoSafeList.empty(); + } synchronized (ImfLock.class) { - final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, - mCurrentUserId, null); - if (resolvedUserIds.length != 1) { - return InputMethodInfoSafeList.empty(); - } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { return InputMethodInfoSafeList.create(getInputMethodListLocked( - resolvedUserIds[0], directBootAwareness, callingUid)); + userId, directBootAwareness, callingUid)); } finally { Binder.restoreCallingIdentity(ident); } @@ -1508,17 +1506,15 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mContext.enforceCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } + if (!mUserManagerInternal.exists(userId)) { + return InputMethodInfoSafeList.empty(); + } synchronized (ImfLock.class) { - final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, - mCurrentUserId, null); - if (resolvedUserIds.length != 1) { - return InputMethodInfoSafeList.empty(); - } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { return InputMethodInfoSafeList.create( - getEnabledInputMethodListLocked(resolvedUserIds[0], callingUid)); + getEnabledInputMethodListLocked(userId, callingUid)); } finally { Binder.restoreCallingIdentity(ident); } @@ -1534,17 +1530,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mContext.enforceCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } + if (!mUserManagerInternal.exists(userId)) { + return Collections.emptyList(); + } synchronized (ImfLock.class) { - final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, - mCurrentUserId, null); - if (resolvedUserIds.length != 1) { - return Collections.emptyList(); - } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { - return getInputMethodListLocked( - resolvedUserIds[0], directBootAwareness, callingUid); + return getInputMethodListLocked(userId, directBootAwareness, callingUid); } finally { Binder.restoreCallingIdentity(ident); } @@ -1559,16 +1552,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mContext.enforceCallingOrSelfPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); } + if (!mUserManagerInternal.exists(userId)) { + return Collections.emptyList(); + } synchronized (ImfLock.class) { - final int[] resolvedUserIds = InputMethodUtils.resolveUserId(userId, - mCurrentUserId, null); - if (resolvedUserIds.length != 1) { - return Collections.emptyList(); - } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { - return getEnabledInputMethodListLocked(resolvedUserIds[0], callingUid); + return getEnabledInputMethodListLocked(userId, callingUid); } finally { Binder.restoreCallingIdentity(ident); } -- cgit v1.2.3-59-g8ed1b