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

Commit 1ec914a0 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Implement an experimental init code for visible bg users

This CL implementas an experimental initialization logic for visible
background users in InputMethodManagerService.

When a visible background user becomes available the following fields
will be initialized.

 * Settings.Secure.DEFAULT_INPUT_METHOD
 * InputMethodBindingController#mSelectedMethodId

Keep in mind that this type of initializations are unique to
concurrent multi-user IME support, and we are effectively introducing
a new code fragmentation, which probably needs to be addressed in the
future.

Note also that callbacks from InputMethodBindingController to IMMS are
not yet fully multi-user aware as you can see by searching "mService."
in InputMethodBindingController.java. You cannot yet call

  InputMethodBindingController#bindCurrentMethod()

until these callbacks are fully upgraded to be multi-user aware.

There must be no observable behavior change on non-automotive form
factors. This behavior is fully guarded behind

  IMMS#mExperimentalConcurrentMultiUserModeEnabled.

Fix: 341199701
Flag: android.view.inputmethod.concurrent_input_methods
Test: presubmit
Change-Id: I82cfc366b614d7e55a0f4fa11d5eaf5f0f8eb0a8
parent 5503bec5
Loading
Loading
Loading
Loading
+53 −2
Original line number Diff line number Diff line
@@ -1268,9 +1268,15 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        @Override
        public void onUserStarting(TargetUser user) {
            // Called on ActivityManager thread.
            SecureSettingsWrapper.onUserStarting(user.getUserIdentifier());
            final int userId = user.getUserIdentifier();
            SecureSettingsWrapper.onUserStarting(userId);
            synchronized (ImfLock.class) {
                mService.mUserDataRepository.getOrCreate(user.getUserIdentifier());
                mService.mUserDataRepository.getOrCreate(userId);
                if (mService.mExperimentalConcurrentMultiUserModeEnabled) {
                    if (mService.mCurrentUserId != userId) {
                        mService.experimentalInitializeVisibleBackgroundUserLocked(userId);
                    }
                }
            }
        }

@@ -1291,6 +1297,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                // We need to rebuild IMEs.
                postInputMethodSettingUpdatedLocked(false /* resetDefaultEnabledIme */);
                updateInputMethodsFromSettingsLocked(true /* enabledChanged */);
            } else if (mExperimentalConcurrentMultiUserModeEnabled) {
                experimentalInitializeVisibleBackgroundUserLocked(userId);
            }
        }
    }
@@ -2922,6 +2930,49 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        mMenuController.updateKeyboardFromSettingsLocked();
    }

    /**
     * This is an experimental implementation used when and only when
     * {@link #mExperimentalConcurrentMultiUserModeEnabled}.
     *
     * <p>Never assume what this method is doing is officially supported. For the canonical and
     * desired behaviors always refer to single-user code paths such as
     * {@link #updateInputMethodsFromSettingsLocked(boolean)}.</p>
     *
     * <p>Here are examples of missing features.</p>
     * <ul>
     *     <li>Subtypes are not supported at all!</li>
     *     <li>Profiles are not supported.</li>
     *     <li>
     *         {@link PackageManager#COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED} is not updated.
     *     </li>
     *     <li>{@link #mDeviceIdToShowIme} is ignored.</li>
     *     <li>{@link #mSwitchingController} is ignored.</li>
     *     <li>{@link #mHardwareKeyboardShortcutController} is ignored.</li>
     *     <li>{@link #mPreventImeStartupUnlessTextEditor} is ignored.</li>
     *     <li>and so on.</li>
     * </ul>
     */
    @GuardedBy("ImfLock.class")
    void experimentalInitializeVisibleBackgroundUserLocked(@UserIdInt int userId) {
        if (!mUserManagerInternal.isUserVisible(userId)) {
            return;
        }
        final var settings = InputMethodSettingsRepository.get(userId);
        String id = settings.getSelectedInputMethod();
        if (TextUtils.isEmpty(id)) {
            final InputMethodInfo imi = InputMethodInfoUtils.getMostApplicableDefaultIME(
                    settings.getEnabledInputMethodList());
            if (imi == null) {
                return;
            }
            id = imi.getId();
            settings.putSelectedInputMethod(id);
        }
        final var userData = mUserDataRepository.getOrCreate(userId);
        final var bindingController = userData.mBindingController;
        bindingController.setSelectedMethodId(id);
    }

    @GuardedBy("ImfLock.class")
    void updateInputMethodsFromSettingsLocked(boolean enabledMayChange) {
        final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);