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

Commit 25baebe5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move #mDeviceIdToShowIme to binding controller" into main

parents ad728039 7c7f51f8
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.inputmethod;

import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_DENIED;
import static android.content.Context.DEVICE_ID_DEFAULT;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import static android.view.Display.INVALID_DISPLAY;

@@ -91,6 +92,7 @@ final class InputMethodBindingController {

    /** The display id for which the latest startInput was called. */
    @GuardedBy("ImfLock.class") private int mDisplayIdToShowIme = INVALID_DISPLAY;
    @GuardedBy("ImfLock.class") private int mDeviceIdToShowIme = DEVICE_ID_DEFAULT;

    @Nullable private CountDownLatch mLatchForTesting;

@@ -609,4 +611,14 @@ final class InputMethodBindingController {
    int getDisplayIdToShowIme() {
        return mDisplayIdToShowIme;
    }

    @GuardedBy("ImfLock.class")
    void setDeviceIdToShowIme(int deviceId) {
        mDeviceIdToShowIme = deviceId;
    }

    @GuardedBy("ImfLock.class")
    int getDeviceIdToShowIme() {
        return mDeviceIdToShowIme;
    }
}
+20 −18
Original line number Diff line number Diff line
@@ -382,10 +382,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    @MultiUserUnawareField
    private HardwareKeyboardShortcutController mHardwareKeyboardShortcutController;

    @GuardedBy("ImfLock.class")
    @MultiUserUnawareField
    private int mDeviceIdToShowIme = DEVICE_ID_DEFAULT;

    @Nullable
    private StatusBarManagerInternal mStatusBarManagerInternal;
    @SharedByAllUsersField
@@ -2143,7 +2139,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        if (deviceMethodId == null) {
            mVisibilityStateComputer.getImePolicy().setImeHiddenByDisplayPolicy(true);
        } else if (!Objects.equals(deviceMethodId, selectedMethodId)) {
            setInputMethodLocked(deviceMethodId, NOT_A_SUBTYPE_ID, mDeviceIdToShowIme);
            setInputMethodLocked(deviceMethodId, NOT_A_SUBTYPE_ID,
                    bindingController.getDeviceIdToShowIme());
            selectedMethodId = deviceMethodId;
        }

@@ -2256,11 +2253,12 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        }

        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        final int oldDeviceId = mDeviceIdToShowIme;
        final var bindingController = getInputMethodBindingController(userId);
        final int oldDeviceId = bindingController.getDeviceIdToShowIme();
        final int displayIdToShowIme = bindingController.getDisplayIdToShowIme();
        mDeviceIdToShowIme = mVdmInternal.getDeviceIdForDisplayId(displayIdToShowIme);
        if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) {
        final int newDeviceId = mVdmInternal.getDeviceIdForDisplayId(displayIdToShowIme);
        bindingController.setDeviceIdToShowIme(newDeviceId);
        if (newDeviceId == DEVICE_ID_DEFAULT) {
            if (oldDeviceId == DEVICE_ID_DEFAULT) {
                return currentMethodId;
            }
@@ -2272,13 +2270,12 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            return defaultDeviceMethodId;
        }

        final String deviceMethodId =
                mVirtualDeviceMethodMap.get(mDeviceIdToShowIme, currentMethodId);
        final String deviceMethodId = mVirtualDeviceMethodMap.get(newDeviceId, currentMethodId);
        if (Objects.equals(deviceMethodId, currentMethodId)) {
            return currentMethodId;
        } else if (!settings.getMethodMap().containsKey(deviceMethodId)) {
            if (DEBUG) {
                Slog.v(TAG, "Disabling IME on virtual device with id " + mDeviceIdToShowIme
                Slog.v(TAG, "Disabling IME on virtual device with id " + newDeviceId
                        + " because its custom input method is not available: " + deviceMethodId);
            }
            return null;
@@ -2293,7 +2290,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        if (DEBUG) {
            Slog.v(TAG, "Switching current input method from " + currentMethodId
                    + " to device-specific one " + deviceMethodId + " because the current display "
                    + displayIdToShowIme + " belongs to device with id " + mDeviceIdToShowIme);
                    + displayIdToShowIme + " belongs to device with id " + newDeviceId);
        }
        return deviceMethodId;
    }
@@ -2934,7 +2931,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
     *     <li>
     *         {@link PackageManager#COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED} is not updated.
     *     </li>
     *     <li>{@link #mDeviceIdToShowIme} is ignored.</li>
     *     <li>{@link InputMethodBindingController#getDeviceIdToShowIme()} is ignored.</li>
     *     <li>{@link #mSwitchingController} is ignored.</li>
     *     <li>{@link #mHardwareKeyboardShortcutController} is ignored.</li>
     *     <li>{@link #mPreventImeStartupUnlessTextEditor} is ignored.</li>
@@ -3004,7 +3001,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            }
        }

        if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) {
        final var bindingController = getInputMethodBindingController(mCurrentUserId);
        if (bindingController.getDeviceIdToShowIme() == DEVICE_ID_DEFAULT) {
            String ime = SecureSettingsWrapper.getString(
                    Settings.Secure.DEFAULT_INPUT_METHOD, null, userId);
            String defaultDeviceIme = SecureSettingsWrapper.getString(
@@ -3122,8 +3120,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            return;
        }

        final var bindingController = getInputMethodBindingController(userId);
        // Changing to a different IME.
        if (mDeviceIdToShowIme != DEVICE_ID_DEFAULT && deviceId == DEVICE_ID_DEFAULT) {
        if (bindingController.getDeviceIdToShowIme() != DEVICE_ID_DEFAULT
                && deviceId == DEVICE_ID_DEFAULT) {
            // This change should only be applicable to the default device but the current input
            // method is a custom one specific to a virtual device. So only update the settings
            // entry used to restore the default device input method once we want to show the IME
@@ -5382,7 +5382,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
     */
    @GuardedBy("ImfLock.class")
    private boolean setInputMethodEnabledLocked(String id, boolean enabled) {
        final InputMethodSettings settings = InputMethodSettingsRepository.get(mCurrentUserId);
        final int userId = mCurrentUserId;
        final InputMethodSettings settings = InputMethodSettingsRepository.get(userId);
        if (enabled) {
            final String enabledImeIdsStr = settings.getEnabledInputMethodsStr();
            final String newEnabledImeIdsStr = InputMethodUtils.concatEnabledImeIds(
@@ -5401,7 +5402,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            StringBuilder builder = new StringBuilder();
            if (settings.buildAndPutEnabledInputMethodsStrRemovingId(
                    builder, enabledInputMethodsList, id)) {
                if (mDeviceIdToShowIme == DEVICE_ID_DEFAULT) {
                final var bindingController = getInputMethodBindingController(userId);
                if (bindingController.getDeviceIdToShowIme() == DEVICE_ID_DEFAULT) {
                    // Disabled input method is currently selected, switch to another one.
                    final String selId = settings.getSelectedInputMethod();
                    if (id.equals(selId) && !chooseNewDefaultIMELocked()) {
@@ -5459,9 +5461,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

    @GuardedBy("ImfLock.class")
    private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
        mDeviceIdToShowIme = DEVICE_ID_DEFAULT;
        final var bindingController = getInputMethodBindingController(mCurrentUserId);
        bindingController.setDisplayIdToShowIme(INVALID_DISPLAY);
        bindingController.setDeviceIdToShowIme(DEVICE_ID_DEFAULT);

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