Rename InputMethodManagerServiceTestBase#mCallingUserId to mUserId
This CL mechanically renames mCallingUserId to mUserId in
InputMethodManagerServiceTestBase, as there is absolutely zero reason
to initialize it with UserHandle.getCallingUserId() in unit tests.
Bug: 352615651
Flag: TEST_ONLY
Test: atest FrameworksInputMethodSystemServerTests
Change-Id: I926888cbbc4f007a642d566156dde9e9e26ab179
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java
index 9e46f2f..efcc23f 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/DefaultImeVisibilityApplierTest.java
@@ -70,14 +70,11 @@
public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTestBase {
private DefaultImeVisibilityApplier mVisibilityApplier;
- private int mUserId = 0;
-
@Before
public void setUp() throws RemoteException {
super.setUp();
synchronized (ImfLock.class) {
mVisibilityApplier = mInputMethodManagerService.getVisibilityApplierLocked();
- mUserId = mInputMethodManagerService.getCurrentImeUserIdLocked();
mInputMethodManagerService.setAttachedClientForTesting(requireNonNull(
mInputMethodManagerService.getClientStateLocked(mMockInputMethodClient)));
}
@@ -248,7 +245,7 @@
mMockRemoteInputConnection /* inputConnection */,
mMockRemoteAccessibilityInputConnection /* remoteAccessibilityInputConnection */,
mTargetSdkVersion /* unverifiedTargetSdkVersion */,
- mCallingUserId /* userId */,
+ mUserId /* userId */,
mMockImeOnBackInvokedDispatcher /* imeDispatcher */);
}
}
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 4d28b3c..1e3b7e9 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodBindingControllerTest.java
@@ -140,8 +140,7 @@
final InputMethodInfo info;
synchronized (ImfLock.class) {
mBindingController.setSelectedMethodId(TEST_IME_ID);
- info = InputMethodSettingsRepository.get(mCallingUserId).getMethodMap()
- .get(TEST_IME_ID);
+ info = InputMethodSettingsRepository.get(mUserId).getMethodMap().get(TEST_IME_ID);
}
assertThat(info).isNotNull();
assertThat(info.getId()).isEqualTo(TEST_IME_ID);
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java
index 1dc5126..461697c 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java
@@ -50,7 +50,6 @@
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.os.UserHandle;
import android.util.ArraySet;
import android.view.InputChannel;
import android.view.inputmethod.EditorInfo;
@@ -128,7 +127,7 @@
protected Context mContext;
protected MockitoSession mMockingSession;
protected int mTargetSdkVersion;
- protected int mCallingUserId;
+ protected int mUserId;
protected EditorInfo mEditorInfo;
protected IInputMethodInvoker mMockInputMethodInvoker;
protected InputMethodManagerService mInputMethodManagerService;
@@ -165,12 +164,12 @@
.spyStatic(AdditionalSubtypeUtils.class)
.startMocking();
- mContext = spy(InstrumentationRegistry.getInstrumentation().getContext());
+ mContext = spy(InstrumentationRegistry.getInstrumentation().getTargetContext());
mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
mIsLargeScreen = mContext.getResources().getConfiguration()
.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE);
- mCallingUserId = UserHandle.getCallingUserId();
+ mUserId = mContext.getUserId();
mEditorInfo = new EditorInfo();
mEditorInfo.packageName = TEST_EDITOR_PKG_NAME;
@@ -202,7 +201,7 @@
// Injecting and mocked InputMethodBindingController and InputMethod.
mMockInputMethodInvoker = IInputMethodInvoker.create(mMockInputMethod);
mInputManagerGlobalSession = InputManagerGlobal.createTestSession(mMockIInputManager);
- when(mMockInputMethodBindingController.getUserId()).thenReturn(mCallingUserId);
+ when(mMockInputMethodBindingController.getUserId()).thenReturn(mUserId);
synchronized (ImfLock.class) {
when(mMockInputMethodBindingController.getCurMethod())
.thenReturn(mMockInputMethodInvoker);
@@ -222,7 +221,7 @@
.thenReturn(new int[] {0});
when(mMockUserManagerInternal.getUserIds()).thenReturn(new int[] {0});
when(mMockActivityManagerInternal.isSystemReady()).thenReturn(true);
- when(mMockActivityManagerInternal.getCurrentUserId()).thenReturn(mCallingUserId);
+ when(mMockActivityManagerInternal.getCurrentUserId()).thenReturn(mUserId);
when(mMockPackageManagerInternal.getPackageUid(anyString(), anyLong(), anyInt()))
.thenReturn(Binder.getCallingUid());
when(mMockPackageManagerInternal.isSameApp(anyString(), anyLong(), anyInt(), anyInt()))
@@ -272,14 +271,13 @@
// Certain tests rely on TEST_IME_ID that is installed with AndroidTest.xml.
// TODO(b/352615651): Consider just synthesizing test InputMethodInfo then injecting it.
- AdditionalSubtypeMapRepository.initializeIfNecessary(mCallingUserId);
+ AdditionalSubtypeMapRepository.initializeIfNecessary(mUserId);
final var settings = InputMethodManagerService.queryInputMethodServicesInternal(mContext,
- mCallingUserId, AdditionalSubtypeMapRepository.get(mCallingUserId),
- DirectBootAwareness.AUTO);
- InputMethodSettingsRepository.put(mCallingUserId, settings);
+ mUserId, AdditionalSubtypeMapRepository.get(mUserId), DirectBootAwareness.AUTO);
+ InputMethodSettingsRepository.put(mUserId, settings);
// Emulate that the user initialization is done.
- mInputMethodManagerService.getUserData(mCallingUserId).mBackgroundLoadLatch.countDown();
+ mInputMethodManagerService.getUserData(mUserId).mBackgroundLoadLatch.countDown();
// After this boot phase, services can broadcast Intents.
lifecycle.onBootPhase(SystemService.PHASE_ACTIVITY_MANAGER_READY);
@@ -291,7 +289,7 @@
@After
public void tearDown() {
- InputMethodSettingsRepository.remove(mCallingUserId);
+ InputMethodSettingsRepository.remove(mUserId);
if (mInputMethodManagerService != null) {
mInputMethodManagerService.mInputMethodDeviceConfigs.destroy();
@@ -347,8 +345,8 @@
synchronized (ImfLock.class) {
ClientState cs = mInputMethodManagerService.getClientStateLocked(client);
cs.mCurSession = new InputMethodManagerService.SessionState(cs,
- mMockInputMethodInvoker, mMockInputMethodSession, mock(
- InputChannel.class), mCallingUserId);
+ mMockInputMethodInvoker, mMockInputMethodSession, mock(InputChannel.class),
+ mUserId);
}
}
}
diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java
index ffc4df8..c5b5668 100644
--- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java
+++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceWindowGainedFocusTest.java
@@ -263,7 +263,7 @@
mMockRemoteInputConnection /* inputConnection */,
mMockRemoteAccessibilityInputConnection /* remoteAccessibilityInputConnection */,
mTargetSdkVersion /* unverifiedTargetSdkVersion */,
- mCallingUserId /* userId */,
+ mUserId /* userId */,
mMockImeOnBackInvokedDispatcher /* imeDispatcher */);
}