summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2024-07-22 17:31:27 +0000
committer Yohei Yukawa <yukawa@google.com> 2024-07-22 17:31:27 +0000
commitdf401875f19ae667afb83e2bd6623fd654c493c8 (patch)
tree42e56438e387a926e38cdaf9526687e55eaf8d27
parentebb7fb76138b923f148cfc9ba64dc25036815d48 (diff)
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
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java41
1 files 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);
}