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

Commit 5b15365f authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Reduce member fileds in InputMethodMenuController" into main

parents 55eb88bf f6b23a6b
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -276,7 +276,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    final Context mContext;
    final Resources mRes;
    private final Handler mHandler;
    final InputMethodSettings mSettings;
    private final InputMethodSettings mSettings;
    final SettingsObserver mSettingsObserver;
    private final SparseBooleanArray mLoggedDeniedGetInputMethodWindowVisibleHeightForUid =
            new SparseBooleanArray(0);
@@ -316,7 +316,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    // Mapping from deviceId to the device-specific imeId for that device.
    private final SparseArray<String> mVirtualDeviceMethodMap = new SparseArray<>();

    final InputMethodSubtypeSwitchingController mSwitchingController;
    private final InputMethodSubtypeSwitchingController mSwitchingController;
    final HardwareKeyboardShortcutController mHardwareKeyboardShortcutController =
            new HardwareKeyboardShortcutController();

@@ -4812,7 +4812,20 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                        Slog.e(TAG, "Unknown subtype picker mode = " + msg.arg1);
                        return false;
                }
                mMenuController.showInputMethodMenu(showAuxSubtypes, displayId);
                synchronized (ImfLock.class) {
                    final boolean isScreenLocked = mWindowManagerInternal.isKeyguardLocked()
                            && mWindowManagerInternal.isKeyguardSecure(
                                    mSettings.getCurrentUserId());
                    final String lastInputMethodId = mSettings.getSelectedInputMethod();
                    int lastInputMethodSubtypeId =
                            mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);

                    final List<ImeSubtypeListItem> imList = mSwitchingController
                            .getSortedInputMethodAndSubtypeListForImeMenuLocked(
                                    showAuxSubtypes, isScreenLocked);
                    mMenuController.showInputMethodMenuLocked(showAuxSubtypes, displayId,
                            lastInputMethodId, lastInputMethodSubtypeId, imList);
                }
                return true;

            // ---------------------------------------------------------
+116 −124
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.inputmethod;
import static com.android.server.inputmethod.InputMethodManagerService.DEBUG;
import static com.android.server.inputmethod.InputMethodUtils.NOT_A_SUBTYPE_ID;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AlertDialog;
import android.content.Context;
@@ -52,8 +53,6 @@ final class InputMethodMenuController {
    private static final String TAG = InputMethodMenuController.class.getSimpleName();

    private final InputMethodManagerService mService;
    private final InputMethodUtils.InputMethodSettings mSettings;
    private final InputMethodSubtypeSwitchingController mSwitchingController;
    private final WindowManagerInternal mWindowManagerInternal;

    private AlertDialog.Builder mDialogBuilder;
@@ -70,44 +69,36 @@ final class InputMethodMenuController {

    InputMethodMenuController(InputMethodManagerService service) {
        mService = service;
        mSettings = mService.mSettings;
        mSwitchingController = mService.mSwitchingController;
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
    }

    void showInputMethodMenu(boolean showAuxSubtypes, int displayId) {
    @GuardedBy("ImfLock.class")
    void showInputMethodMenuLocked(boolean showAuxSubtypes, int displayId,
            String preferredInputMethodId, int preferredInputMethodSubtypeId,
            @NonNull List<ImeSubtypeListItem> imList) {
        if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);

        synchronized (ImfLock.class) {
        final int userId = mService.getCurrentImeUserIdLocked();
            final boolean isScreenLocked = mWindowManagerInternal.isKeyguardLocked()
                    && mWindowManagerInternal.isKeyguardSecure(userId);
            final String lastInputMethodId = mSettings.getSelectedInputMethod();
            int lastInputMethodSubtypeId =
                    mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
            if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);

            final List<ImeSubtypeListItem> imList = mSwitchingController
                    .getSortedInputMethodAndSubtypeListForImeMenuLocked(
                            showAuxSubtypes, isScreenLocked);

        if (imList.isEmpty()) {
            return;
        }

        hideInputMethodMenuLocked();

            if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
        if (preferredInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype =
                    mService.getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final String curMethodId = mService.getSelectedMethodIdLocked();
                final InputMethodInfo currentImi =
                        mService.queryInputMethodForCurrentUserLocked(curMethodId);
                    lastInputMethodSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(
                preferredInputMethodSubtypeId = SubtypeUtils.getSubtypeIdFromHashCode(
                        currentImi, currentSubtype.hashCode());
            }
        }

        // Find out which item should be checked by default.
        final int size = imList.size();
        mIms = new InputMethodInfo[size];
        mSubtypeIds = new int[size];
@@ -116,11 +107,11 @@ final class InputMethodMenuController {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
                if (mIms[i].getId().equals(lastInputMethodId)) {
            if (mIms[i].getId().equals(preferredInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID)
                            || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
                            || (subtypeId == lastInputMethodSubtypeId)) {
                        || (preferredInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0)
                        || (subtypeId == preferredInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
@@ -165,6 +156,8 @@ final class InputMethodMenuController {
            hideInputMethodMenu();
        });

        // Fill the list items with onClick listener, which takes care of IME (and subtype)
        // switching when clicked.
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext,
                com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
        final DialogInterface.OnClickListener choiceListener = (dialog, which) -> {
@@ -188,6 +181,7 @@ final class InputMethodMenuController {
        };
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);

        // Final steps to instantiate a dialog to show it up.
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        final Window w = mSwitchingDialog.getWindow();
@@ -204,8 +198,6 @@ final class InputMethodMenuController {
        mService.updateSystemUiLocked();
        mService.sendOnNavButtonFlagsChangedLocked();
        mSwitchingDialog.show();

        }
    }

    void updateKeyboardFromSettingsLocked() {