From c131c6e5f769bbd1e260c7e03ac4760baf602301 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 30 Sep 2022 11:21:13 +0800 Subject: [PATCH] Use user-aware context in IMMS#queryInputMethodServicesInternal As queryInputMethodServicesInternal is to query the installed IME apps of the given userId with returning the list of InputMethodInfo, however, there is a bug that it always initializes InputMethodInfo with user 0's XML resources from the system context. Fix this issue by using user-aware context to ensure creating InputMethodInfo will load the correct resources settings with the corresponding context of the userId. Fix: 249081323 Test: atest CtsInputMethodTestCases Change-Id: I47578c8bba5d9e04301ed3727ad1efa6496653e6 --- .../server/inputmethod/InputMethodManagerService.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 08ccccd49e541..31e0693ed47c9 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -5034,6 +5034,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @UserIdInt int userId, ArrayMap> additionalSubtypeMap, ArrayMap methodMap, ArrayList methodList, @DirectBootAwareness int directBootAwareness) { + final Context userAwareContext = context.getUserId() == userId + ? context + : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */); + methodList.clear(); methodMap.clear(); @@ -5055,8 +5059,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub final int flags = PackageManager.GET_META_DATA | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS | directBootAwarenessFlags; - final List services = context.getPackageManager().queryIntentServicesAsUser( - new Intent(InputMethod.SERVICE_INTERFACE), flags, userId); + final List services = userAwareContext.getPackageManager().queryIntentServices( + new Intent(InputMethod.SERVICE_INTERFACE), + PackageManager.ResolveInfoFlags.of(flags)); methodList.ensureCapacity(services.size()); methodMap.ensureCapacity(services.size()); @@ -5075,7 +5080,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (DEBUG) Slog.d(TAG, "Checking " + imeId); try { - final InputMethodInfo imi = new InputMethodInfo(context, ri, + final InputMethodInfo imi = new InputMethodInfo(userAwareContext, ri, additionalSubtypeMap.get(imeId)); if (imi.isVrOnly()) { continue; // Skip VR-only IME, which isn't supported for now.