Loading services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +40 −15 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ import android.content.pm.PackageManagerInternal; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.hardware.input.InputManager; import android.inputmethodservice.InputMethodService; Loading Loading @@ -303,6 +304,28 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @NonNull private final String[] mNonPreemptibleInputMethods; /** * Whether the new Input Method Switcher menu is enabled. * * @see #shouldEnableNewInputMethodSwitcherMenu */ @SharedByAllUsersField private final boolean mNewInputMethodSwitcherMenuEnabled; /** * Returns {@code true} if the new Input Method Switcher menu is enabled. This will be * {@code false} for watches and small screen devices. * * @param context the context to check the device configuration for. */ private static boolean shouldEnableNewInputMethodSwitcherMenu(@NonNull Context context) { final boolean isWatch = context.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_WATCH); final boolean isSmallScreen = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL; return Flags.imeSwitcherRevamp() && !isWatch && !isSmallScreen; } /** * See {@link #shouldEnableConcurrentMultiUserMode(Context)} about when set to be {@code true}. */ Loading Loading @@ -591,7 +614,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. private void onSecureSettingsChangedLocked(@NonNull String key, @UserIdInt int userId) { switch (key) { case Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD: { if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { if (userId == mCurrentUserId) { mMenuController.updateKeyboardFromSettingsLocked(); } Loading Loading @@ -660,7 +683,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } } } if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { synchronized (ImfLock.class) { final var bindingController = getInputMethodBindingController(senderUserId); mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), Loading Loading @@ -1151,6 +1174,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); mNewInputMethodSwitcherMenuEnabled = shouldEnableNewInputMethodSwitcherMenu(mContext); mShowOngoingImeSwitcherForPhones = false; Loading @@ -1163,7 +1187,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. : bindingControllerFactory); mMenuController = new InputMethodMenuController(this); mMenuControllerNew = Flags.imeSwitcherRevamp() mMenuControllerNew = mNewInputMethodSwitcherMenuEnabled ? new InputMethodMenuControllerNew() : null; mVisibilityStateComputer = new ImeVisibilityStateComputer(this); mVisibilityApplier = new DefaultImeVisibilityApplier(this); Loading Loading @@ -1784,7 +1808,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. ImeTracker.PHASE_SERVER_WAIT_IME); userData.mCurStatsToken = null; // TODO: Make mMenuController multi-user aware if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId); } else { mMenuController.hideInputMethodMenuLocked(); Loading Loading @@ -2599,7 +2623,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mShowOngoingImeSwitcherForPhones) return false; // When the IME switcher dialog is shown, the IME switcher button should be hidden. // TODO(b/305849394): Make mMenuController multi-user aware. final boolean switcherMenuShowing = Flags.imeSwitcherRevamp() final boolean switcherMenuShowing = mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.getSwitchingDialogLocked() != null; if (switcherMenuShowing) { Loading @@ -2619,7 +2643,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. || (visibility & InputMethodService.IME_INVISIBLE) != 0) { return false; } if (mWindowManagerInternal.isHardKeyboardAvailable() && !Flags.imeSwitcherRevamp()) { if (mWindowManagerInternal.isHardKeyboardAvailable() && !mNewInputMethodSwitcherMenuEnabled) { // When physical keyboard is attached, we show the ime switcher (or notification if // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently // exists in the IME switcher dialog. Might be OK to remove this condition once Loading @@ -2630,7 +2655,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { // The IME switcher button should be shown when the current IME specified a // language settings activity. final var curImi = settings.getMethodMap().get(settings.getSelectedInputMethod()); Loading Loading @@ -2806,7 +2831,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } final var curId = bindingController.getCurId(); // TODO(b/305849394): Make mMenuController multi-user aware. final boolean switcherMenuShowing = Flags.imeSwitcherRevamp() final boolean switcherMenuShowing = mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.getSwitchingDialogLocked() != null; if (switcherMenuShowing Loading @@ -2828,7 +2853,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @GuardedBy("ImfLock.class") void updateFromSettingsLocked(boolean enabledMayChange, @UserIdInt int userId) { updateInputMethodsFromSettingsLocked(enabledMayChange, userId); if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { mMenuController.updateKeyboardFromSettingsLocked(); } } Loading Loading @@ -3983,7 +4008,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @IInputMethodManagerImpl.PermissionVerified(Manifest.permission.TEST_INPUT_METHOD) public boolean isInputMethodPickerShownForTest() { synchronized (ImfLock.class) { return Flags.imeSwitcherRevamp() return mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.isisInputMethodPickerShownForTestLocked(); } Loading Loading @@ -4689,7 +4714,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. proto.write(IS_INTERACTIVE, mIsInteractive); proto.write(BACK_DISPOSITION, bindingController.getBackDisposition()); proto.write(IME_WINDOW_VISIBILITY, bindingController.getImeWindowVis()); if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { proto.write(SHOW_IME_WITH_HARD_KEYBOARD, mMenuController.getShowImeWithHardKeyboard()); } Loading Loading @@ -5014,7 +5039,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. return false; } if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { if (DEBUG) { Slog.v(TAG, "Show IME switcher menu," + " showAuxSubtypes=" + showAuxSubtypes Loading Loading @@ -5105,7 +5130,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // -------------------------------------------------------------- case MSG_HARD_KEYBOARD_SWITCH_CHANGED: if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { mMenuController.handleHardKeyboardStatusChange(msg.arg1 == 1); } synchronized (ImfLock.class) { Loading Loading @@ -5905,7 +5930,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // the next focused window starting the input connection. if (mVisibilityStateComputer.getLastImeTargetWindow() != userData.mImeBindingState.mFocusedWindow) { if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { final var bindingController = getInputMethodBindingController(userId); mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId); } else { Loading Loading @@ -6261,7 +6286,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. }; mUserDataRepository.forAllUserData(userDataDump); if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { p.println(" menuControllerNew:"); mMenuControllerNew.dump(p, " "); } else { Loading Loading
services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +40 −15 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ import android.content.pm.PackageManagerInternal; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.content.pm.UserInfo; import android.content.res.Configuration; import android.content.res.Resources; import android.hardware.input.InputManager; import android.inputmethodservice.InputMethodService; Loading Loading @@ -303,6 +304,28 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @NonNull private final String[] mNonPreemptibleInputMethods; /** * Whether the new Input Method Switcher menu is enabled. * * @see #shouldEnableNewInputMethodSwitcherMenu */ @SharedByAllUsersField private final boolean mNewInputMethodSwitcherMenuEnabled; /** * Returns {@code true} if the new Input Method Switcher menu is enabled. This will be * {@code false} for watches and small screen devices. * * @param context the context to check the device configuration for. */ private static boolean shouldEnableNewInputMethodSwitcherMenu(@NonNull Context context) { final boolean isWatch = context.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_WATCH); final boolean isSmallScreen = (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL; return Flags.imeSwitcherRevamp() && !isWatch && !isSmallScreen; } /** * See {@link #shouldEnableConcurrentMultiUserMode(Context)} about when set to be {@code true}. */ Loading Loading @@ -591,7 +614,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. private void onSecureSettingsChangedLocked(@NonNull String key, @UserIdInt int userId) { switch (key) { case Settings.Secure.SHOW_IME_WITH_HARD_KEYBOARD: { if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { if (userId == mCurrentUserId) { mMenuController.updateKeyboardFromSettingsLocked(); } Loading Loading @@ -660,7 +683,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } } } if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { synchronized (ImfLock.class) { final var bindingController = getInputMethodBindingController(senderUserId); mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), Loading Loading @@ -1151,6 +1174,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); mSlotIme = mContext.getString(com.android.internal.R.string.status_bar_ime); mNewInputMethodSwitcherMenuEnabled = shouldEnableNewInputMethodSwitcherMenu(mContext); mShowOngoingImeSwitcherForPhones = false; Loading @@ -1163,7 +1187,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. : bindingControllerFactory); mMenuController = new InputMethodMenuController(this); mMenuControllerNew = Flags.imeSwitcherRevamp() mMenuControllerNew = mNewInputMethodSwitcherMenuEnabled ? new InputMethodMenuControllerNew() : null; mVisibilityStateComputer = new ImeVisibilityStateComputer(this); mVisibilityApplier = new DefaultImeVisibilityApplier(this); Loading Loading @@ -1784,7 +1808,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. ImeTracker.PHASE_SERVER_WAIT_IME); userData.mCurStatsToken = null; // TODO: Make mMenuController multi-user aware if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId); } else { mMenuController.hideInputMethodMenuLocked(); Loading Loading @@ -2599,7 +2623,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (!mShowOngoingImeSwitcherForPhones) return false; // When the IME switcher dialog is shown, the IME switcher button should be hidden. // TODO(b/305849394): Make mMenuController multi-user aware. final boolean switcherMenuShowing = Flags.imeSwitcherRevamp() final boolean switcherMenuShowing = mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.getSwitchingDialogLocked() != null; if (switcherMenuShowing) { Loading @@ -2619,7 +2643,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. || (visibility & InputMethodService.IME_INVISIBLE) != 0) { return false; } if (mWindowManagerInternal.isHardKeyboardAvailable() && !Flags.imeSwitcherRevamp()) { if (mWindowManagerInternal.isHardKeyboardAvailable() && !mNewInputMethodSwitcherMenuEnabled) { // When physical keyboard is attached, we show the ime switcher (or notification if // NavBar is not available) because SHOW_IME_WITH_HARD_KEYBOARD settings currently // exists in the IME switcher dialog. Might be OK to remove this condition once Loading @@ -2630,7 +2655,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } final InputMethodSettings settings = InputMethodSettingsRepository.get(userId); if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { // The IME switcher button should be shown when the current IME specified a // language settings activity. final var curImi = settings.getMethodMap().get(settings.getSelectedInputMethod()); Loading Loading @@ -2806,7 +2831,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } final var curId = bindingController.getCurId(); // TODO(b/305849394): Make mMenuController multi-user aware. final boolean switcherMenuShowing = Flags.imeSwitcherRevamp() final boolean switcherMenuShowing = mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.getSwitchingDialogLocked() != null; if (switcherMenuShowing Loading @@ -2828,7 +2853,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @GuardedBy("ImfLock.class") void updateFromSettingsLocked(boolean enabledMayChange, @UserIdInt int userId) { updateInputMethodsFromSettingsLocked(enabledMayChange, userId); if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { mMenuController.updateKeyboardFromSettingsLocked(); } } Loading Loading @@ -3983,7 +4008,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. @IInputMethodManagerImpl.PermissionVerified(Manifest.permission.TEST_INPUT_METHOD) public boolean isInputMethodPickerShownForTest() { synchronized (ImfLock.class) { return Flags.imeSwitcherRevamp() return mNewInputMethodSwitcherMenuEnabled ? mMenuControllerNew.isShowing() : mMenuController.isisInputMethodPickerShownForTestLocked(); } Loading Loading @@ -4689,7 +4714,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. proto.write(IS_INTERACTIVE, mIsInteractive); proto.write(BACK_DISPOSITION, bindingController.getBackDisposition()); proto.write(IME_WINDOW_VISIBILITY, bindingController.getImeWindowVis()); if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { proto.write(SHOW_IME_WITH_HARD_KEYBOARD, mMenuController.getShowImeWithHardKeyboard()); } Loading Loading @@ -5014,7 +5039,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. return false; } if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { if (DEBUG) { Slog.v(TAG, "Show IME switcher menu," + " showAuxSubtypes=" + showAuxSubtypes Loading Loading @@ -5105,7 +5130,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // -------------------------------------------------------------- case MSG_HARD_KEYBOARD_SWITCH_CHANGED: if (!Flags.imeSwitcherRevamp()) { if (!mNewInputMethodSwitcherMenuEnabled) { mMenuController.handleHardKeyboardStatusChange(msg.arg1 == 1); } synchronized (ImfLock.class) { Loading Loading @@ -5905,7 +5930,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. // the next focused window starting the input connection. if (mVisibilityStateComputer.getLastImeTargetWindow() != userData.mImeBindingState.mFocusedWindow) { if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { final var bindingController = getInputMethodBindingController(userId); mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId); } else { Loading Loading @@ -6261,7 +6286,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. }; mUserDataRepository.forAllUserData(userDataDump); if (Flags.imeSwitcherRevamp()) { if (mNewInputMethodSwitcherMenuEnabled) { p.println(" menuControllerNew:"); mMenuControllerNew.dump(p, " "); } else { Loading