From 8a875de0ca757e3b578d501cf3bb4d7c53545660 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 3 Oct 2022 20:22:07 -0700 Subject: [PATCH] Make IMMS#updateStatusIcon() multi-user aware It turns out that InputMethodManagerService#updateStatusIcon() still uses PakcageManager for user 0 when loading the IME application label. This CL fixes such a user mismatch. Note that the code in question was originally added [1] before multi-user support was added into InputMethodManagerService. We just forgot to update the code when making IMMS multi-user aware [2]. [1]: I1c1bd123d828fb10911bca92130e9a05c1f020b3 6179ea3196e9306d3f14361fe9ef14191b1edba6 [2]: Ib23849d352db33f0747aa9d5a178f00ac726c13b 4e1ab15b305aac26ad8819fc3b2951e20985944d Fix: 250716279 Test: presubmit Change-Id: I37106c3c82950d4f6f3a7b149b21579b0314a287 --- .../InputMethodManagerService.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 31e0693ed47c9..fef6154e47f66 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2960,19 +2960,17 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub hideStatusBarIconLocked(); } else if (packageName != null) { if (DEBUG) Slog.d(TAG, "show a small icon for the input method"); - CharSequence contentDescription = null; + final PackageManager userAwarePackageManager = + getPackageManagerForUser(mContext, mSettings.getCurrentUserId()); + ApplicationInfo applicationInfo = null; try { - // Use PackageManager to load label - final PackageManager packageManager = mContext.getPackageManager(); - final ApplicationInfo applicationInfo = mIPackageManager - .getApplicationInfo(packageName, 0, mSettings.getCurrentUserId()); - if (applicationInfo != null) { - contentDescription = packageManager - .getApplicationLabel(applicationInfo); - } - } catch (RemoteException e) { - /* ignore */ + applicationInfo = userAwarePackageManager.getApplicationInfo(packageName, + PackageManager.ApplicationInfoFlags.of(0)); + } catch (PackageManager.NameNotFoundException e) { } + final CharSequence contentDescription = applicationInfo != null + ? userAwarePackageManager.getApplicationLabel(applicationInfo) + : null; if (mStatusBar != null) { mStatusBar.setIcon(mSlotIme, packageName, iconId, 0, contentDescription != null