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

Commit 7d56c73b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove unnecessary invocations of UserDataRepository#getOrCreate()" into main

parents be180c8b 4d0ec07f
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();