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

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

Simplify InputMethodSubtypeSwitchingController a bit

This simplifies InputMethodSubtypeSwitchingController a bit by taking
advantage of InputMethodSettings, which is in general a super set of
InputMethodMap and user ID.

This is a mechanical refactoring CL. There must be no semantic
behavior change.

Bug: 305849394
Bug: 346662143
Bug: 347693610
Flag: EXEMPT refactor
Test: atest InputMethodSubtypeSwitchingControllerTest
Change-Id: Ibc1410c6a49401983a5216a1b8973fb95f117e20
parent 34053329
Loading
Loading
Loading
Loading
+6 −9
Original line number Original line Diff line number Diff line
@@ -1296,8 +1296,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.


            final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);
            final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);


            mSwitchingController = new InputMethodSubtypeSwitchingController(context,
            mSwitchingController = new InputMethodSubtypeSwitchingController(context, settings);
                    settings.getMethodMap(), settings.getUserId());
            getUserData(mCurrentUserId).mHardwareKeyboardShortcutController.update(settings);
            getUserData(mCurrentUserId).mHardwareKeyboardShortcutController.update(settings);
            mMenuController = new InputMethodMenuController(this);
            mMenuController = new InputMethodMenuController(this);
            mVisibilityStateComputer = new ImeVisibilityStateComputer(this);
            mVisibilityStateComputer = new ImeVisibilityStateComputer(this);
@@ -3042,10 +3041,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.


        // TODO: Instantiate mSwitchingController for each user.
        // TODO: Instantiate mSwitchingController for each user.
        if (userId == mSwitchingController.getUserId()) {
        if (userId == mSwitchingController.getUserId()) {
            mSwitchingController.resetCircularListLocked(settings.getMethodMap());
            mSwitchingController.resetCircularListLocked(settings);
        } else {
        } else {
            mSwitchingController = new InputMethodSubtypeSwitchingController(mContext,
            mSwitchingController = new InputMethodSubtypeSwitchingController(mContext, settings);
                    settings.getMethodMap(), userId);
        }
        }
        getUserData(userId).mHardwareKeyboardShortcutController.update(settings);
        getUserData(userId).mHardwareKeyboardShortcutController.update(settings);
        sendOnNavButtonFlagsChangedLocked();
        sendOnNavButtonFlagsChangedLocked();
@@ -4917,7 +4915,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    final List<ImeSubtypeListItem> imList = InputMethodSubtypeSwitchingController
                    final List<ImeSubtypeListItem> imList = InputMethodSubtypeSwitchingController
                            .getSortedInputMethodAndSubtypeList(
                            .getSortedInputMethodAndSubtypeList(
                                    showAuxSubtypes, isScreenLocked, true /* forImeMenu */,
                                    showAuxSubtypes, isScreenLocked, true /* forImeMenu */,
                                    mContext, settings.getMethodMap(), settings.getUserId());
                                    mContext, settings);
                    if (imList.isEmpty()) {
                    if (imList.isEmpty()) {
                        Slog.w(TAG, "Show switching menu failed, imList is empty,"
                        Slog.w(TAG, "Show switching menu failed, imList is empty,"
                                + " showAuxSubtypes: " + showAuxSubtypes
                                + " showAuxSubtypes: " + showAuxSubtypes
@@ -5307,10 +5305,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.


        // TODO: Instantiate mSwitchingController for each user.
        // TODO: Instantiate mSwitchingController for each user.
        if (userId == mSwitchingController.getUserId()) {
        if (userId == mSwitchingController.getUserId()) {
            mSwitchingController.resetCircularListLocked(settings.getMethodMap());
            mSwitchingController.resetCircularListLocked(settings);
        } else {
        } else {
            mSwitchingController = new InputMethodSubtypeSwitchingController(mContext,
            mSwitchingController = new InputMethodSubtypeSwitchingController(mContext, settings);
                    settings.getMethodMap(), mCurrentUserId);
        }
        }
        getUserData(userId).mHardwareKeyboardShortcutController.update(settings);
        getUserData(userId).mHardwareKeyboardShortcutController.update(settings);


+7 −8
Original line number Original line Diff line number Diff line
@@ -163,13 +163,12 @@ final class InputMethodSubtypeSwitchingController {
    @NonNull
    @NonNull
    static List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(
    static List<ImeSubtypeListItem> getSortedInputMethodAndSubtypeList(
            boolean includeAuxiliarySubtypes, boolean isScreenLocked, boolean forImeMenu,
            boolean includeAuxiliarySubtypes, boolean isScreenLocked, boolean forImeMenu,
            @NonNull Context context, @NonNull InputMethodMap methodMap,
            @NonNull Context context, @NonNull InputMethodSettings settings) {
            @UserIdInt int userId) {
        final int userId = settings.getUserId();
        final Context userAwareContext = context.getUserId() == userId
        final Context userAwareContext = context.getUserId() == userId
                ? context
                ? context
                : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
                : context.createContextAsUser(UserHandle.of(userId), 0 /* flags */);
        final String mSystemLocaleStr = SystemLocaleWrapper.get(userId).get(0).toLanguageTag();
        final String mSystemLocaleStr = SystemLocaleWrapper.get(userId).get(0).toLanguageTag();
        final InputMethodSettings settings = InputMethodSettings.create(methodMap, userId);


        final ArrayList<InputMethodInfo> imis = settings.getEnabledInputMethodList();
        final ArrayList<InputMethodInfo> imis = settings.getEnabledInputMethodList();
        if (imis.isEmpty()) {
        if (imis.isEmpty()) {
@@ -487,13 +486,13 @@ final class InputMethodSubtypeSwitchingController {
    private ControllerImpl mController;
    private ControllerImpl mController;


    InputMethodSubtypeSwitchingController(@NonNull Context context,
    InputMethodSubtypeSwitchingController(@NonNull Context context,
            @NonNull InputMethodMap methodMap, @UserIdInt int userId) {
            @NonNull InputMethodSettings settings) {
        mContext = context;
        mContext = context;
        mUserId = userId;
        mUserId = settings.getUserId();
        mController = ControllerImpl.createFrom(null,
        mController = ControllerImpl.createFrom(null,
                getSortedInputMethodAndSubtypeList(
                getSortedInputMethodAndSubtypeList(
                        false /* includeAuxiliarySubtypes */, false /* isScreenLocked */,
                        false /* includeAuxiliarySubtypes */, false /* isScreenLocked */,
                        false /* forImeMenu */, context, methodMap, userId));
                        false /* forImeMenu */, context, settings));
    }
    }


    @AnyThread
    @AnyThread
@@ -507,11 +506,11 @@ final class InputMethodSubtypeSwitchingController {
        mController.onUserActionLocked(imi, subtype);
        mController.onUserActionLocked(imi, subtype);
    }
    }


    public void resetCircularListLocked(@NonNull InputMethodMap methodMap) {
    public void resetCircularListLocked(@NonNull InputMethodSettings settings) {
        mController = ControllerImpl.createFrom(mController,
        mController = ControllerImpl.createFrom(mController,
                getSortedInputMethodAndSubtypeList(
                getSortedInputMethodAndSubtypeList(
                        false /* includeAuxiliarySubtypes */, false /* isScreenLocked */,
                        false /* includeAuxiliarySubtypes */, false /* isScreenLocked */,
                        false /* forImeMenu */, mContext, methodMap, mUserId));
                        false /* forImeMenu */, mContext, settings));
    }
    }


    @Nullable
    @Nullable