From 9ddd4cd83eb91c65e3f2529b187cc66041f6efcf Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 4 Oct 2022 15:25:45 -0700 Subject: [PATCH] Optimize IMMS#setAdditionalInputMethodSubtypes() a bit for bg users This is a follow up CL to my previous CL, which enabled background users to call InputMethodManager#setAdditionalInputMethodSubtypes(). One this this CL tries to optimize is the fact that its implementation is currently invoking AdditionalSubtypeUtils.load() twice when called for background usres. The double-call is happening in InputMethodManagerService#setAdditionalInputMethodSubtypes() itseif and inside InputMethodManagerService#queryMethodMapForUser() [2]. With this CL, the load operation should be happen only once. There should be no developer-observable behavior change. [1]: Iac778d95846843504f6e00b3b939ef0794013b02 0b169d04c113684b0213a3a15bac9e6f0d77e515 [2]: I4187468076705ac597d680f2f5dc32d7b166da1f b5f3d34def7b979e611ca4abc3f9aa4a071a0fdc Bug: 234882948 Test: presubmit Change-Id: I6eb4201ebd69ca8821cbe74fc69356f68f9bcb5e --- .../server/inputmethod/InputMethodManagerService.java | 9 ++++++--- 1 file changed, 6 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 894d0b6cda2f4..520a471224b2c 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -4186,12 +4186,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return; } - final ArrayMap methodMap = queryMethodMapForUser(userId); - final InputMethodSettings settings = new InputMethodSettings(mContext, methodMap, - userId, false); + final ArrayMap methodMap = new ArrayMap<>(); + final ArrayList methodList = new ArrayList<>(); final ArrayMap> additionalSubtypeMap = new ArrayMap<>(); AdditionalSubtypeUtils.load(additionalSubtypeMap, userId); + queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap, + methodList, DirectBootAwareness.AUTO); + final InputMethodSettings settings = new InputMethodSettings(mContext, methodMap, + userId, false); settings.setAdditionalInputMethodSubtypes(imiId, toBeAdded, additionalSubtypeMap, mPackageManagerInternal, callingUid); }