summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2023-11-30 00:45:50 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-11-30 00:45:50 +0000
commitd5e50c5bb0c694b2df336e81898853e4098e57db (patch)
treefaffd3499e2c2406df7192c2f01fed0d325fda45
parent7f209cba1e628b0eef4f9a89c3616531c622a511 (diff)
parent23d665cf2fe44c0217b9214fa120aafd7ac283ed (diff)
Merge "Simplify InputMethodUtils a bit" into main
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java46
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodUtils.java10
2 files changed, 10 insertions, 46 deletions
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index f4b050f8ad3f..43305c219e7e 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -5442,47 +5442,21 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
*/
@GuardedBy("ImfLock.class")
private InputMethodInfo queryDefaultInputMethodForUserIdLocked(@UserIdInt int userId) {
- final String imeId = mSettings.getSelectedInputMethodForUser(userId);
- if (TextUtils.isEmpty(imeId)) {
- Slog.e(TAG, "No default input method found for userId " + userId);
- return null;
- }
-
- InputMethodInfo curInputMethodInfo;
- if (userId == mSettings.getCurrentUserId()
- && (curInputMethodInfo = mMethodMap.get(imeId)) != null) {
- // clone the InputMethodInfo before returning.
- return new InputMethodInfo(curInputMethodInfo);
+ if (userId == mSettings.getCurrentUserId()) {
+ return mMethodMap.get(mSettings.getSelectedInputMethod());
}
+ final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
+ final ArrayList<InputMethodInfo> methodList = new ArrayList<>();
final ArrayMap<String, List<InputMethodSubtype>> additionalSubtypeMap = new ArrayMap<>();
AdditionalSubtypeUtils.load(additionalSubtypeMap, userId);
- Context userAwareContext =
- mContext.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
-
- final int flags = PackageManager.GET_META_DATA
- | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
- | PackageManager.MATCH_DIRECT_BOOT_AUTO;
- final List<ResolveInfo> services =
- userAwareContext.getPackageManager().queryIntentServicesAsUser(
- new Intent(InputMethod.SERVICE_INTERFACE),
- PackageManager.ResolveInfoFlags.of(flags),
- userId);
- for (ResolveInfo ri : services) {
- final String imeIdResolved = InputMethodInfo.computeId(ri);
- if (imeId.equals(imeIdResolved)) {
- try {
- return new InputMethodInfo(
- userAwareContext, ri, additionalSubtypeMap.get(imeId));
- } catch (Exception e) {
- Slog.wtf(TAG, "Unable to load input method " + imeId, e);
- }
- }
- }
- // we didn't find the InputMethodInfo for imeId. This shouldn't happen.
- Slog.e(TAG, "Error while locating input method info for imeId: " + imeId);
- return null;
+ queryInputMethodServicesInternal(mContext, userId, additionalSubtypeMap, methodMap,
+ methodList, DirectBootAwareness.AUTO);
+ InputMethodSettings settings = new InputMethodSettings(mContext, methodMap, userId,
+ true /* copyOnWrite */);
+ return methodMap.get(settings.getSelectedInputMethod());
}
+
private ArrayMap<String, InputMethodInfo> queryMethodMapForUser(@UserIdInt int userId) {
final ArrayMap<String, InputMethodInfo> methodMap = new ArrayMap<>();
final ArrayList<InputMethodInfo> methodList = new ArrayList<>();
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
index 83fcf3facff1..7c42ee83dc15 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodUtils.java
@@ -756,16 +756,6 @@ final class InputMethodUtils {
return imi;
}
- @Nullable
- String getSelectedInputMethodForUser(@UserIdInt int userId) {
- final String imi =
- getStringForUser(Settings.Secure.DEFAULT_INPUT_METHOD, null, userId);
- if (DEBUG) {
- Slog.d(TAG, "getSelectedInputMethodForUserStr: " + imi);
- }
- return imi;
- }
-
void putDefaultVoiceInputMethod(String imeId) {
if (DEBUG) {
Slog.d(TAG, "putDefaultVoiceInputMethodStr: " + imeId + ", " + mCurrentUserId);