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

Commit 5503bec5 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Introduce IMMS#mExperimentalConcurrentMultiUserModeEnabled

This is a preparation to start implementing a special runtime mode in
InputMethodManagerService that is used when and only when concurrent
multi-user IME support is enabled.

This CL only introduces a boolean field to IMMS without any behavior
change.

Bug: 341199701
Test: presubmit
Flag: android.view.inputmethod.concurrent_input_methods
Change-Id: If8f48331256e28cf34794043903cc7cf619f2aed
parent 78762176
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -282,6 +282,28 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    @NonNull
    private final String[] mNonPreemptibleInputMethods;

    /**
     * See {@link #shouldEnableExperimentalConcurrentMultiUserMode(Context)} about when set to be
     * {@code true}.
     */
    private final boolean mExperimentalConcurrentMultiUserModeEnabled;

    /**
     * Returns {@code true} if experimental concurrent multi-user mode is enabled.
     *
     * <p>Currently not compatible with profiles (e.g. work profile).</p>
     *
     * @param context {@link Context} to be used to query
     *                {@link PackageManager#FEATURE_AUTOMOTIVE}
     * @return {@code true} if experimental concurrent multi-user mode is enabled.
     */
    static boolean shouldEnableExperimentalConcurrentMultiUserMode(@NonNull Context context) {
        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
                && UserManager.isVisibleBackgroundUsersEnabled()
                && context.getResources().getBoolean(android.R.bool.config_perDisplayFocusEnabled)
                && Flags.concurrentInputMethods();
    }

    final Context mContext;
    final Resources mRes;
    private final Handler mHandler;
@@ -1191,8 +1213,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    public static final class Lifecycle extends SystemService {
        private final InputMethodManagerService mService;


        public Lifecycle(Context context) {
            this(context, new InputMethodManagerService(context));
            this(context, new InputMethodManagerService(context,
                            shouldEnableExperimentalConcurrentMultiUserMode(context)));
        }

        public Lifecycle(
@@ -1291,17 +1315,21 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        mHandler.post(task);
    }

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

    @VisibleForTesting
    InputMethodManagerService(
            Context context,
            boolean experimentalConcurrentMultiUserModeEnabled,
            @Nullable ServiceThread serviceThreadForTesting,
            @Nullable ServiceThread packageMonitorThreadForTesting,
            @Nullable IntFunction<InputMethodBindingController> bindingControllerForTesting) {
        synchronized (ImfLock.class) {
            mExperimentalConcurrentMultiUserModeEnabled =
                    experimentalConcurrentMultiUserModeEnabled;
            mContext = context;
            mRes = context.getResources();
            SecureSettingsWrapper.onStart(mContext);
@@ -5945,6 +5973,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            mVisibilityStateComputer.dump(pw, "  ");
            p.println("  mInFullscreenMode=" + mInFullscreenMode);
            p.println("  mSystemReady=" + mSystemReady + " mInteractive=" + mIsInteractive);
            p.println("  mExperimentalConcurrentMultiUserModeEnabled="
                    + mExperimentalConcurrentMultiUserModeEnabled);
            p.println("  ENABLE_HIDE_IME_CAPTION_BAR="
                    + InputMethodService.ENABLE_HIDE_IME_CAPTION_BAR);
            p.println("  mSettingsObserver=" + mSettingsObserver);
+4 −2
Original line number Diff line number Diff line
@@ -231,8 +231,10 @@ public class InputMethodManagerServiceTestBase {
                        "immstest2",
                        Process.THREAD_PRIORITY_FOREGROUND,
                        true /* allowIo */);
        mInputMethodManagerService = new InputMethodManagerService(mContext, mServiceThread,
                mPackageMonitorThread, unusedUserId -> mMockInputMethodBindingController);
        mInputMethodManagerService = new InputMethodManagerService(mContext,
                InputMethodManagerService.shouldEnableExperimentalConcurrentMultiUserMode(mContext),
                mServiceThread, mPackageMonitorThread,
                unusedUserId -> mMockInputMethodBindingController);
        spyOn(mInputMethodManagerService);

        // Start a InputMethodManagerService.Lifecycle to publish and manage the lifecycle of