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

Commit df3b9060 authored by Antonio Kantek's avatar Antonio Kantek
Browse files

Introduce per IME binding data

This is a placeholder for IMMS fields linked to some specific user on
some given display.

This is just a refactoring and cleanup change, no regression is
expected.

Bug: 314149476
Bug: 305849394
Test: atest CtsInputMethodTestCases FrameworksServicesTests
Change-Id: I29864548ea586bc4fe05aef1c8f44b8f66d6e04f
parent b98bc87e
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -91,10 +91,10 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {
                if (DEBUG_IME_VISIBILITY) {
                    EventLog.writeEvent(IMF_SHOW_IME,
                            statsToken != null ? statsToken.getTag() : ImeTracker.TOKEN_NONE,
                            Objects.toString(mService.mCurFocusedWindow),
                            Objects.toString(mService.mImeBindingState.mFocusedWindow),
                            InputMethodDebug.softInputDisplayReasonToString(reason),
                            InputMethodDebug.softInputModeToString(
                                    mService.mCurFocusedWindowSoftInputMode));
                                    mService.mImeBindingState.mFocusedWindowSoftInputMode));
                }
                mService.onShowHideSoftInputRequested(true /* show */, showInputToken, reason,
                        statsToken);
@@ -122,10 +122,10 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {
                if (DEBUG_IME_VISIBILITY) {
                    EventLog.writeEvent(IMF_HIDE_IME,
                            statsToken != null ? statsToken.getTag() : ImeTracker.TOKEN_NONE,
                            Objects.toString(mService.mCurFocusedWindow),
                            Objects.toString(mService.mImeBindingState.mFocusedWindow),
                            InputMethodDebug.softInputDisplayReasonToString(reason),
                            InputMethodDebug.softInputModeToString(
                                    mService.mCurFocusedWindowSoftInputMode));
                                    mService.mImeBindingState.mFocusedWindowSoftInputMode));
                }
                mService.onShowHideSoftInputRequested(false /* show */, hideInputToken, reason,
                        statsToken);
@@ -207,7 +207,8 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {
    @Override
    public boolean removeImeScreenshot(int displayId) {
        if (mImeTargetVisibilityPolicy.removeImeScreenshot(displayId)) {
            mService.onShowHideSoftInputRequested(false /* show */, mService.mCurFocusedWindow,
            mService.onShowHideSoftInputRequested(false /* show */,
                    mService.mImeBindingState.mFocusedWindow,
                    REMOVE_IME_SCREENSHOT_FROM_IMMS, null /* statsToken */);
            return true;
        }
+109 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.inputmethod;

import static android.server.inputmethod.InputMethodManagerServiceProto.CUR_FOCUSED_WINDOW_NAME;
import static android.server.inputmethod.InputMethodManagerServiceProto.CUR_FOCUSED_WINDOW_SOFT_INPUT_MODE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;

import android.annotation.Nullable;
import android.os.IBinder;
import android.util.Printer;
import android.util.proto.ProtoOutputStream;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.inputmethod.EditorInfo;

import com.android.internal.inputmethod.InputMethodDebug;
import com.android.server.wm.WindowManagerInternal;

/**
 * Stores information related to one active IME client on one display.
 */
final class ImeBindingState {

    /**
     * The last window token that we confirmed to be focused.  This is always updated upon
     * reports from the input method client. If the window state is already changed before the
     * report is handled, this field just keeps the last value.
     */
    @Nullable
    final IBinder mFocusedWindow;

    /**
     * {@link WindowManager.LayoutParams#softInputMode} of {@link #mFocusedWindow}.
     *
     * @see #mFocusedWindow
     */
    @SoftInputModeFlags
    final int mFocusedWindowSoftInputMode;

    /**
     * The client by which {@link #mFocusedWindow} was reported. This gets updated whenever
     * an
     * IME-focusable window gained focus (without necessarily starting an input connection),
     * while {@link InputMethodManagerService#mClient} only gets updated when we actually start an
     * input connection.
     *
     * @see #mFocusedWindow
     */
    @Nullable
    final ClientState mFocusedWindowClient;

    /**
     * The editor info by which {@link #mFocusedWindow} was reported. This differs from
     * {@link InputMethodManagerService#mCurEditorInfo} the same way {@link #mFocusedWindowClient}
     * differs from {@link InputMethodManagerService#mCurClient}.
     *
     * @see #mFocusedWindow
     */
    @Nullable
    final EditorInfo mFocusedWindowEditorInfo;

    void dumpDebug(ProtoOutputStream proto, WindowManagerInternal windowManagerInternal) {
        proto.write(CUR_FOCUSED_WINDOW_NAME,
                windowManagerInternal.getWindowName(mFocusedWindow));
        proto.write(CUR_FOCUSED_WINDOW_SOFT_INPUT_MODE,
                InputMethodDebug.softInputModeToString(mFocusedWindowSoftInputMode));
    }

    void dump(String prefix, Printer p) {
        p.println(prefix + "mFocusedWindow()=" + mFocusedWindow);
        p.println(prefix + "softInputMode=" + InputMethodDebug.softInputModeToString(
                mFocusedWindowSoftInputMode));
        p.println(prefix + "mFocusedWindowClient=" + mFocusedWindowClient);
    }

    static ImeBindingState newEmptyState() {
        return new ImeBindingState(
                /*focusedWindow=*/ null,
                /*focusedWindowSoftInputMode=*/ SOFT_INPUT_STATE_UNSPECIFIED,
                /*focusedWindowClient=*/ null,
                /*focusedWindowEditorInfo=*/ null
        );
    }

    ImeBindingState(@Nullable IBinder focusedWindow,
            @SoftInputModeFlags int focusedWindowSoftInputMode,
            @Nullable ClientState focusedWindowClient,
            @Nullable EditorInfo focusedWindowEditorInfo) {
        mFocusedWindow = focusedWindow;
        mFocusedWindowSoftInputMode = focusedWindowSoftInputMode;
        mFocusedWindowClient = focusedWindowClient;
        mFocusedWindowEditorInfo = focusedWindowEditorInfo;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -548,7 +548,7 @@ public final class ImeVisibilityStateComputer {
            }
        }
        // Fallback to the focused window for some edge cases (e.g. relaunching the activity)
        return mService.mCurFocusedWindow;
        return mService.mImeBindingState.mFocusedWindow;
    }

    IBinder getWindowTokenFrom(ImeTargetWindowState windowState) {
+62 −98

File changed.

Preview size limit exceeded, changes collapsed.