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

Commit d2018b52 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Fix accesses to InputMethodMenuController#mSettings without lock

This CL fixes an existing issue that

  InputMethodMenuController#mSettings

gets accessed without acquiring ImfLock.class.

While it's OK to access

  InputMethodMenuController#mWindowManagerInternal

and its methods without acquiring ImfLock.class, mSettings isn't
because it's still a mutable object that can change at any time.

Bug: 309868254
Test: presubmit
Change-Id: Id3108004d9f120a51cc28fe53321f6c62bd0b16a
parent 8cd82f49
Loading
Loading
Loading
Loading
+8 −11
Original line number Diff line number Diff line
@@ -77,13 +77,14 @@ final class InputMethodMenuController {
    void showInputMethodMenu(boolean showAuxSubtypes, int displayId) {
        if (DEBUG) Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);

        final boolean isScreenLocked = isScreenLocked();

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

        synchronized (ImfLock.class) {
            final List<ImeSubtypeListItem> imList = mSwitchingController
                    .getSortedInputMethodAndSubtypeListForImeMenuLocked(
                            showAuxSubtypes, isScreenLocked);
@@ -200,12 +201,8 @@ final class InputMethodMenuController {
            mService.updateSystemUiLocked();
            mService.sendOnNavButtonFlagsChangedLocked();
            mSwitchingDialog.show();
        }
    }

    private boolean isScreenLocked() {
        return mWindowManagerInternal.isKeyguardLocked()
                && mWindowManagerInternal.isKeyguardSecure(mSettings.getCurrentUserId());
        }
    }

    void updateKeyboardFromSettingsLocked() {