Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d0ec07f authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Remove unnecessary invocations of UserDataRepository#getOrCreate()

Historically we have called

  UserDataRepository#getOrCreate()

immediately after a user becomes available. However such invocations
are redundant and not necessary as the method name implies. Let's
remove them in favor of simplicity.

There must be no user observable behavior change in this CL.

Bug: 343601565
Test: presubmit
Flag: EXEMPT refactor
Change-Id: I6a5a528bec84c5eb4e1756f9f58106951c0f841b
parent 1057c67c
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -1017,7 +1017,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            final int userId = user.getUserIdentifier();
            SecureSettingsWrapper.onUserStarting(userId);
            synchronized (ImfLock.class) {
                mService.getUserData(userId);
                if (mService.mConcurrentMultiUserModeEnabled) {
                    if (mService.mCurrentUserId != userId && mService.mSystemReady) {
                        mService.initializeVisibleBackgroundUserLocked(userId);
@@ -1116,9 +1115,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            mUserDataRepository = new UserDataRepository(mHandler, mUserManagerInternal,
                    bindingControllerForTesting != null ? bindingControllerForTesting
                            : bindingControllerFactory);
            for (int id : mUserManagerInternal.getUserIds()) {
                getUserData(id);
            }

            mMenuController = new InputMethodMenuController(this);
            mVisibilityStateComputer = new ImeVisibilityStateComputer(this);
+0 −10
Original line number Diff line number Diff line
@@ -74,16 +74,6 @@ final class UserDataRepository {
                            }
                        });
                    }

                    @Override
                    public void onUserCreated(UserInfo user, Object unusedToken) {
                        final int userId = user.id;
                        handler.post(() -> {
                            synchronized (ImfLock.class) {
                                getOrCreate(userId);
                            }
                        });
                    }
                });
    }

+9 −12
Original line number Diff line number Diff line
@@ -99,14 +99,8 @@ public final class UserDataRepositoryTest {
        listener.onUserCreated(userInfo, /* unused token */ new Object());
        waitForIdle();

        // Assert UserDataRepository contains the expected UserData
        final var allUserData = collectUserData(repository);
        assertThat(allUserData).hasSize(1);
        assertThat(allUserData.get(0).mUserId).isEqualTo(ANY_USER_ID);

        // Assert UserDataRepository called the InputMethodBindingController creator function.
        verify(bindingControllerFactorySpy).apply(ANY_USER_ID);
        assertThat(allUserData.get(0).mBindingController.getUserId()).isEqualTo(ANY_USER_ID);
        // Assert UserDataRepository remains to be empty.
        assertThat(collectUserData(repository)).isEmpty();
    }

    @Test
@@ -121,12 +115,15 @@ public final class UserDataRepositoryTest {
        final var listener = captor.getValue();

        // Add one UserData ...
        final var userInfo = new UserInfo();
        userInfo.id = ANY_USER_ID;
        listener.onUserCreated(userInfo, /* unused token */ new Object());
        waitForIdle();
        synchronized (ImfLock.class) {
            final var userData = repository.getOrCreate(ANY_USER_ID);
            assertThat(userData.mUserId).isEqualTo(ANY_USER_ID);
        }

        // ... and then call onUserRemoved
        assertThat(collectUserData(repository)).hasSize(1);
        final var userInfo = new UserInfo();
        userInfo.id = ANY_USER_ID;
        listener.onUserRemoved(userInfo);
        waitForIdle();