From 5503bec515a8149212e1f86d53ca793027872579 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Fri, 17 May 2024 22:31:46 +0900 Subject: 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 --- .../inputmethod/InputMethodManagerService.java | 36 ++++++++++++++++++++-- .../InputMethodManagerServiceTestBase.java | 6 ++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 46c5772453c7..419a0a648775 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -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. + * + *

Currently not compatible with profiles (e.g. work profile).

+ * + * @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 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); diff --git a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java index 2bbd3c06556f..3b25cb13e66c 100644 --- a/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java +++ b/services/tests/InputMethodSystemServerTests/src/com/android/server/inputmethod/InputMethodManagerServiceTestBase.java @@ -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 -- cgit v1.2.3-59-g8ed1b