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
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 46c5772..419a0a6 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 @@
@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 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 @@
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 @@
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 2bbd3c0..3b25cb1 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 @@
"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