Merge "Make InputMethodManagerService#mMethodMap private" into main
diff --git a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
index 0faae35..2d6b013 100644
--- a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
+++ b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
@@ -21,7 +21,6 @@
import android.annotation.UserIdInt;
import android.os.IBinder;
import android.os.RemoteException;
-import android.util.ArrayMap;
import android.util.Slog;
import android.view.autofill.AutofillId;
import android.view.inputmethod.InlineSuggestionsRequest;
@@ -40,7 +39,6 @@
private static final String TAG = AutofillSuggestionsController.class.getSimpleName();
@NonNull private final InputMethodManagerService mService;
- @NonNull private final ArrayMap<String, InputMethodInfo> mMethodMap;
@NonNull private final InputMethodUtils.InputMethodSettings mSettings;
private static final class CreateInlineSuggestionsRequest {
@@ -78,7 +76,6 @@
AutofillSuggestionsController(@NonNull InputMethodManagerService service) {
mService = service;
- mMethodMap = mService.mMethodMap;
mSettings = mService.mSettings;
}
@@ -88,7 +85,8 @@
boolean touchExplorationEnabled) {
clearPendingInlineSuggestionsRequest();
mInlineSuggestionsRequestCallback = callback;
- final InputMethodInfo imi = mMethodMap.get(mService.getSelectedMethodIdLocked());
+ final InputMethodInfo imi = mService.queryInputMethodForCurrentUserLocked(
+ mService.getSelectedMethodIdLocked());
try {
if (userId == mSettings.getCurrentUserId()
&& imi != null && isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) {
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java
index 2fe2271..e76aa1a 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java
@@ -34,7 +34,6 @@
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
-import android.util.ArrayMap;
import android.util.EventLog;
import android.util.Slog;
import android.view.WindowManager;
@@ -64,7 +63,6 @@
@NonNull private final InputMethodManagerService mService;
@NonNull private final Context mContext;
- @NonNull private final ArrayMap<String, InputMethodInfo> mMethodMap;
@NonNull private final InputMethodUtils.InputMethodSettings mSettings;
@NonNull private final PackageManagerInternal mPackageManagerInternal;
@NonNull private final WindowManagerInternal mWindowManagerInternal;
@@ -115,7 +113,6 @@
int imeConnectionBindFlags, CountDownLatch latchForTesting) {
mService = service;
mContext = mService.mContext;
- mMethodMap = mService.mMethodMap;
mSettings = mService.mSettings;
mPackageManagerInternal = mService.mPackageManagerInternal;
mWindowManagerInternal = mService.mWindowManagerInternal;
@@ -295,7 +292,8 @@
return;
}
if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken);
- final InputMethodInfo info = mMethodMap.get(mSelectedMethodId);
+ final InputMethodInfo info =
+ mService.queryInputMethodForCurrentUserLocked(mSelectedMethodId);
boolean supportsStylusHwChanged =
mSupportsStylusHw != info.supportsStylusHandwriting();
mSupportsStylusHw = info.supportsStylusHandwriting();
@@ -410,7 +408,7 @@
return InputBindResult.NO_IME;
}
- InputMethodInfo info = mMethodMap.get(mSelectedMethodId);
+ InputMethodInfo info = mService.queryInputMethodForCurrentUserLocked(mSelectedMethodId);
if (info == null) {
throw new IllegalArgumentException("Unknown id: " + mSelectedMethodId);
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 0c4ecbc..1ae67dd 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -310,7 +310,7 @@
// All known input methods.
final ArrayList<InputMethodInfo> mMethodList = new ArrayList<>();
- final ArrayMap<String, InputMethodInfo> mMethodMap = new ArrayMap<>();
+ private final ArrayMap<String, InputMethodInfo> mMethodMap = new ArrayMap<>();
final InputMethodSubtypeSwitchingController mSwitchingController;
final HardwareKeyboardShortcutController mHardwareKeyboardShortcutController =
new HardwareKeyboardShortcutController();
@@ -500,6 +500,12 @@
mBindingController.advanceSequenceNumber();
}
+ @GuardedBy("ImfLock.class")
+ @Nullable
+ InputMethodInfo queryInputMethodForCurrentUserLocked(@NonNull String imeId) {
+ return mMethodMap.get(imeId);
+ }
+
/**
* The client that is currently bound to an input method.
*/
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
index c2ef83d..86e417b 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodMenuController.java
@@ -26,7 +26,6 @@
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
-import android.util.ArrayMap;
import android.util.Slog;
import android.view.LayoutInflater;
import android.view.View;
@@ -54,7 +53,6 @@
private final InputMethodManagerService mService;
private final InputMethodUtils.InputMethodSettings mSettings;
private final InputMethodSubtypeSwitchingController mSwitchingController;
- private final ArrayMap<String, InputMethodInfo> mMethodMap;
private final WindowManagerInternal mWindowManagerInternal;
private AlertDialog.Builder mDialogBuilder;
@@ -73,7 +71,6 @@
mService = service;
mSettings = mService.mSettings;
mSwitchingController = mService.mSwitchingController;
- mMethodMap = mService.mMethodMap;
mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
}
@@ -101,7 +98,8 @@
mService.getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final String curMethodId = mService.getSelectedMethodIdLocked();
- final InputMethodInfo currentImi = mMethodMap.get(curMethodId);
+ final InputMethodInfo currentImi =
+ mService.queryInputMethodForCurrentUserLocked(curMethodId);
lastInputMethodSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(
currentImi, currentSubtype.hashCode());
}
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java
index 798e1ae..1f0a375 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java
@@ -133,10 +133,11 @@
}
private void testBindCurrentMethodWithMainConnection() throws Exception {
+ final InputMethodInfo info;
synchronized (ImfLock.class) {
mBindingController.setSelectedMethodId(TEST_IME_ID);
+ info = mInputMethodManagerService.queryInputMethodForCurrentUserLocked(TEST_IME_ID);
}
- InputMethodInfo info = mInputMethodManagerService.mMethodMap.get(TEST_IME_ID);
assertThat(info).isNotNull();
assertThat(info.getId()).isEqualTo(TEST_IME_ID);
assertThat(info.getServiceName()).isEqualTo(TEST_SERVICE_NAME);