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

Commit 88023a37 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Use IO thread more in IMMS

This CL fixes the remaing cases when the following classes do I/O
operations not in the dedicated I/O thread.

  * AdditionalSubtypeMapRepository
  * InputMethodSettingsRepository

Other than that there must be no observable behavior change.

Bug: 343601565
Test: atest FrameworksInputMethodSystemServerTests
Flag: EXEMPT refactor
Change-Id: Id797c68e7966c9fb3b298a9a0843b942b8ffe004
parent 1c303cdc
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -225,17 +225,17 @@ final class AdditionalSubtypeMapRepository {
        sWriter.startThread();
    }

    static void initialize(@NonNull Handler handler, @NonNull Context context) {
    static void initialize(@NonNull Handler ioHandler, @NonNull Context context) {
        final UserManagerInternal userManagerInternal =
                LocalServices.getService(UserManagerInternal.class);
        handler.post(() -> {
        ioHandler.post(() -> {
            userManagerInternal.addUserLifecycleListener(
                    new UserManagerInternal.UserLifecycleListener() {
                        @Override
                        public void onUserCreated(UserInfo user, @Nullable Object token) {
                            final int userId = user.id;
                            sWriter.onUserCreated(userId);
                            handler.post(() -> {
                            ioHandler.post(() -> {
                                synchronized (ImfLock.class) {
                                    if (!sPerUserMap.contains(userId)) {
                                        final AdditionalSubtypeMap additionalSubtypeMap =
@@ -257,7 +257,7 @@ final class AdditionalSubtypeMapRepository {
                        public void onUserRemoved(UserInfo user) {
                            final int userId = user.id;
                            sWriter.onUserRemoved(userId);
                            handler.post(() -> {
                            ioHandler.post(() -> {
                                synchronized (ImfLock.class) {
                                    sPerUserMap.remove(userId);
                                }
+2 −2
Original line number Diff line number Diff line
@@ -1107,8 +1107,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            // Search for InputMethodSettingsRepository.put() to find where and when it's actually
            // being updated. In general IMMS should refrain from exposing the existence of IMEs
            // until systemReady().
            InputMethodSettingsRepository.initialize(mHandler, mContext);
            AdditionalSubtypeMapRepository.initialize(mHandler, mContext);
            InputMethodSettingsRepository.initialize(mIoHandler, mContext);
            AdditionalSubtypeMapRepository.initialize(mIoHandler, mContext);

            mCurrentUserId = mActivityManagerInternal.getCurrentUserId();
            @SuppressWarnings("GuardedBy") final IntFunction<InputMethodBindingController>
+3 −3
Original line number Diff line number Diff line
@@ -54,16 +54,16 @@ final class InputMethodSettingsRepository {
        sPerUserMap.put(userId, obj);
    }

    static void initialize(@NonNull Handler handler, @NonNull Context context) {
    static void initialize(@NonNull Handler ioHandler, @NonNull Context context) {
        final UserManagerInternal userManagerInternal =
                LocalServices.getService(UserManagerInternal.class);
        handler.post(() -> {
        ioHandler.post(() -> {
            userManagerInternal.addUserLifecycleListener(
                    new UserManagerInternal.UserLifecycleListener() {
                        @Override
                        public void onUserRemoved(UserInfo user) {
                            final int userId = user.id;
                            handler.post(() -> {
                            ioHandler.post(() -> {
                                synchronized (ImfLock.class) {
                                    sPerUserMap.remove(userId);
                                }
+5 −1
Original line number Diff line number Diff line
@@ -243,9 +243,13 @@ public class InputMethodManagerServiceTestBase {
                        Process.THREAD_PRIORITY_FOREGROUND,
                        true /* allowIo */);
        mIoThread.start();

        final var ioHandler = spy(Handler.createAsync(mIoThread.getLooper()));
        doReturn(true).when(ioHandler).post(any());

        mInputMethodManagerService = new InputMethodManagerService(mContext,
                InputMethodManagerService.shouldEnableConcurrentMultiUserMode(mContext),
                mServiceThread.getLooper(), Handler.createAsync(mIoThread.getLooper()),
                mServiceThread.getLooper(), ioHandler,
                unusedUserId -> mMockInputMethodBindingController);
        spyOn(mInputMethodManagerService);