From f62c0b837a6d2f20b103db749c5cb46ada9f9e43 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 29 Jul 2022 00:50:25 +0800 Subject: [PATCH] Use user-aware context when calling getImeAndSubtypeDisplayName Ensure we get the corresponding PackageManager instance from the user context to load the text resources of the IME package and the subType. Fix: 223418203 Test: manual as steps 0) Pair a physical keyboard or use "adb shell setprop qemu.hw.mainkeys 1` to disable navigation bar 0-1) Restart device with "adb shell am restart" 0-2) After the system restarted, add a new user from Settings > System > Multiple users 0-3) Switch to the new user to setup and install some IME apps. 1) Switch to the owner user from Status bar -> Select user icon 2) Tap the editor from the google search box to show soft-keyboard 3) After the soft-keyboard displayed, verify "Choose input method" notification has popuped on the notification shade, and check the current IME subType display name & the IME package label are displyed correctly. 4) Repeat step 1-3 for the new user again. Change-Id: I58421143bee25be459f4f744688b37614a750051 --- .../server/inputmethod/InputMethodManagerService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index cddbad64f2fdd..408bcfe0bbf01 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3202,8 +3202,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // Used to load label final CharSequence title = mRes.getText( com.android.internal.R.string.select_input_method); + final int currentUserId = mSettings.getCurrentUserId(); + final Context userAwareContext = mContext.getUserId() == currentUserId + ? mContext + : mContext.createContextAsUser(UserHandle.of(currentUserId), 0 /* flags */); final CharSequence summary = InputMethodUtils.getImeAndSubtypeDisplayName( - mContext, imi, mCurrentSubtype); + userAwareContext, imi, mCurrentSubtype); mImeSwitcherNotification.setContentTitle(title) .setContentText(summary) .setContentIntent(mImeSwitchPendingIntent);