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

Commit 1fca74b0 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Use a dedicated thread for IMMS.MyPackageMonitor" into main

parents 01223bb5 81a9a1ba
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -262,6 +262,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    private static final int NOT_A_SUBTYPE_ID = InputMethodUtils.NOT_A_SUBTYPE_ID;
    private static final String TAG_TRY_SUPPRESSING_IME_SWITCHER = "TrySuppressingImeSwitcher";
    private static final String HANDLER_THREAD_NAME = "android.imms";
    private static final String PACKAGE_MONITOR_THREAD_NAME = "android.imms2";

    /**
     * When set, {@link #startInputUncheckedLocked} will return
@@ -285,6 +286,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    final Resources mRes;
    private final Handler mHandler;

    @NonNull
    private final Handler mPackageMonitorHandler;

    @MultiUserUnawareField
    @UserIdInt
    @GuardedBy("ImfLock.class")
@@ -1288,13 +1292,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    }

    public InputMethodManagerService(Context context) {
        this(context, null, null);
        this(context, null, null, null);
    }

    @VisibleForTesting
    InputMethodManagerService(
            Context context,
            @Nullable ServiceThread serviceThreadForTesting,
            @Nullable ServiceThread packageMonitorThreadForTesting,
            @Nullable IntFunction<InputMethodBindingController> bindingControllerForTesting) {
        synchronized (ImfLock.class) {
            mContext = context;
@@ -1312,6 +1317,17 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                                    true /* allowIo */);
            thread.start();
            mHandler = Handler.createAsync(thread.getLooper(), this);
            {
                final ServiceThread packageMonitorThread =
                        packageMonitorThreadForTesting != null
                                ? packageMonitorThreadForTesting
                                : new ServiceThread(
                                        PACKAGE_MONITOR_THREAD_NAME,
                                        Process.THREAD_PRIORITY_FOREGROUND,
                                        true /* allowIo */);
                packageMonitorThread.start();
                mPackageMonitorHandler = Handler.createAsync(packageMonitorThread.getLooper());
            }
            SystemLocaleWrapper.onStart(context, this::onActionLocaleChanged, mHandler);
            mImeTrackerService = new ImeTrackerService(serviceThreadForTesting != null
                    ? serviceThreadForTesting.getLooper() : Looper.getMainLooper());
@@ -1585,7 +1601,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    }
                }, "Lazily initialize IMMS#mImeDrawsImeNavBarRes");

                mMyPackageMonitor.register(mContext, UserHandle.ALL, mHandler);
                mMyPackageMonitor.register(mContext, UserHandle.ALL, mPackageMonitorHandler);
                mSettingsObserver.registerContentObserverLocked(currentUserId);

                final IntentFilter broadcastFilterForAllUsers = new IntentFilter();
+14 −4
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public class InputMethodManagerServiceTestBase {
    protected IInputMethodInvoker mMockInputMethodInvoker;
    protected InputMethodManagerService mInputMethodManagerService;
    protected ServiceThread mServiceThread;
    protected ServiceThread mPackageMonitorThread;
    protected boolean mIsLargeScreen;
    private InputManagerGlobal.TestSession mInputManagerGlobalSession;

@@ -222,11 +223,16 @@ public class InputMethodManagerServiceTestBase {

        mServiceThread =
                new ServiceThread(
                        "TestServiceThread",
                        Process.THREAD_PRIORITY_FOREGROUND, /* allowIo */
                        false);
                        "immstest1",
                        Process.THREAD_PRIORITY_FOREGROUND,
                        true /* allowIo */);
        mPackageMonitorThread =
                new ServiceThread(
                        "immstest2",
                        Process.THREAD_PRIORITY_FOREGROUND,
                        true /* allowIo */);
        mInputMethodManagerService = new InputMethodManagerService(mContext, mServiceThread,
                unusedUserId -> mMockInputMethodBindingController);
                mPackageMonitorThread, unusedUserId -> mMockInputMethodBindingController);
        spyOn(mInputMethodManagerService);

        // Start a InputMethodManagerService.Lifecycle to publish and manage the lifecycle of
@@ -259,6 +265,10 @@ public class InputMethodManagerServiceTestBase {
            mInputMethodManagerService.mInputMethodDeviceConfigs.destroy();
        }

        if (mPackageMonitorThread != null) {
            mPackageMonitorThread.quitSafely();
        }

        if (mServiceThread != null) {
            mServiceThread.quitSafely();
        }