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

Commit 53cb5175 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Create statsToken in ImeRequestedChangedListener

This adds REASON_IME_REQUESTED_CHANGED_LISTENER and starts tracking IME
requests without statsToken from the IME requested changed listener.
While this does lead to some requests which are soon cancelled (e.g. at
PHASE_SERVER_SHOULD_HIDE), it allows observing requests that would
otherwise be picked up just before they are finished, in
InputMethodService showSoftInput/hideSoftInput.

This is only an improvement, but not a final solution for tracking new
IME requests from the refactorInsetsController changes.

Flag: EXEMPT logging
Bug: 353463205
Test: show and hide IME in various scenarios, observe logs
Change-Id: Ie71cc4ef1effed7c7927060937f23742aa13ecb1
parent c9f7abe1
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -305,6 +305,8 @@ public final class InputMethodDebug {
                return "HIDE_INPUT_TARGET_CHANGED";
                return "HIDE_INPUT_TARGET_CHANGED";
            case SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS:
            case SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS:
                return "HIDE_WINDOW_LOST_FOCUS";
                return "HIDE_WINDOW_LOST_FOCUS";
            case SoftInputShowHideReason.IME_REQUESTED_CHANGED_LISTENER:
                return "IME_REQUESTED_CHANGED_LISTENER";
            default:
            default:
                return "Unknown=" + reason;
                return "Unknown=" + reason;
        }
        }
+7 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,7 @@ import java.lang.annotation.Retention;
        SoftInputShowHideReason.SHOW_INPUT_TARGET_CHANGED,
        SoftInputShowHideReason.SHOW_INPUT_TARGET_CHANGED,
        SoftInputShowHideReason.HIDE_INPUT_TARGET_CHANGED,
        SoftInputShowHideReason.HIDE_INPUT_TARGET_CHANGED,
        SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS,
        SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS,
        SoftInputShowHideReason.IME_REQUESTED_CHANGED_LISTENER,
})
})
public @interface SoftInputShowHideReason {
public @interface SoftInputShowHideReason {
    /** Default, undefined reason. */
    /** Default, undefined reason. */
@@ -422,4 +423,10 @@ public @interface SoftInputShowHideReason {


    /** Hide soft input when the window lost focus. */
    /** Hide soft input when the window lost focus. */
    int HIDE_WINDOW_LOST_FOCUS = ImeProtoEnums.REASON_HIDE_WINDOW_LOST_FOCUS;
    int HIDE_WINDOW_LOST_FOCUS = ImeProtoEnums.REASON_HIDE_WINDOW_LOST_FOCUS;

    /**
     * Show / Hide soft input by
     *  {@link com.android.server.wm.WindowManagerInternal.OnImeRequestedChangedListener}
     */
    int IME_REQUESTED_CHANGED_LISTENER = ImeProtoEnums.REASON_IME_REQUESTED_CHANGED_LISTENER;
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -3194,7 +3194,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    }
    }


    // TODO(b/353463205) check callers to see if we can make statsToken @NonNull
    // TODO(b/353463205) check callers to see if we can make statsToken @NonNull
    boolean showCurrentInputInternal(IBinder windowToken, @Nullable ImeTracker.Token statsToken) {
    boolean showCurrentInputInternal(IBinder windowToken, @NonNull ImeTracker.Token statsToken) {
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.showCurrentInputInternal");
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.showCurrentInputInternal");
        ImeTracing.getInstance().triggerManagerServiceDump(
        ImeTracing.getInstance().triggerManagerServiceDump(
                "InputMethodManagerService#showSoftInput", mDumper);
                "InputMethodManagerService#showSoftInput", mDumper);
@@ -3214,7 +3214,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    }
    }


    // TODO(b/353463205) check callers to see if we can make statsToken @NonNull
    // TODO(b/353463205) check callers to see if we can make statsToken @NonNull
    boolean hideCurrentInputInternal(IBinder windowToken, @Nullable ImeTracker.Token statsToken) {
    boolean hideCurrentInputInternal(IBinder windowToken, @NonNull ImeTracker.Token statsToken) {
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.hideCurrentInputInternal");
        Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.hideCurrentInputInternal");
        ImeTracing.getInstance().triggerManagerServiceDump(
        ImeTracing.getInstance().triggerManagerServiceDump(
                "InputMethodManagerService#hideSoftInput", mDumper);
                "InputMethodManagerService#hideSoftInput", mDumper);
+12 −5
Original line number Original line Diff line number Diff line
@@ -445,14 +445,21 @@ final class ImeInsetsSourceProvider extends InsetsSourceProvider {
            if (controlTarget != null) {
            if (controlTarget != null) {
                final boolean imeAnimating = Flags.reportAnimatingInsetsTypes()
                final boolean imeAnimating = Flags.reportAnimatingInsetsTypes()
                        && (controlTarget.getAnimatingTypes() & WindowInsets.Type.ime()) != 0;
                        && (controlTarget.getAnimatingTypes() & WindowInsets.Type.ime()) != 0;
                ImeTracker.forLogging().onProgress(statsToken,
                final boolean imeVisible =
                        controlTarget.isRequestedVisible(WindowInsets.Type.ime()) || imeAnimating;
                final var finalStatsToken = statsToken != null ? statsToken
                        : ImeTracker.forLogging().onStart(
                                imeVisible ? ImeTracker.TYPE_SHOW : ImeTracker.TYPE_HIDE,
                                ImeTracker.ORIGIN_SERVER,
                                SoftInputShowHideReason.IME_REQUESTED_CHANGED_LISTENER,
                                false /* fromUser */);
                ImeTracker.forLogging().onProgress(finalStatsToken,
                        ImeTracker.PHASE_WM_POSTING_CHANGED_IME_VISIBILITY);
                        ImeTracker.PHASE_WM_POSTING_CHANGED_IME_VISIBILITY);
                mDisplayContent.mWmService.mH.post(() -> {
                mDisplayContent.mWmService.mH.post(() -> {
                    ImeTracker.forLogging().onProgress(statsToken,
                    ImeTracker.forLogging().onProgress(finalStatsToken,
                            ImeTracker.PHASE_WM_INVOKING_IME_REQUESTED_LISTENER);
                            ImeTracker.PHASE_WM_INVOKING_IME_REQUESTED_LISTENER);
                    imeListener.onImeRequestedChanged(controlTarget.getWindowToken(),
                    imeListener.onImeRequestedChanged(controlTarget.getWindowToken(), imeVisible,
                            controlTarget.isRequestedVisible(WindowInsets.Type.ime())
                            finalStatsToken);
                                    || imeAnimating, statsToken);
                });
                });
            } else {
            } else {
                ImeTracker.forLogging().onFailed(statsToken,
                ImeTracker.forLogging().onFailed(statsToken,
+1 −1
Original line number Original line Diff line number Diff line
@@ -371,7 +371,7 @@ public abstract class WindowManagerInternal {
         * @param statsToken the token tracking the current IME request.
         * @param statsToken the token tracking the current IME request.
         */
         */
        void onImeRequestedChanged(IBinder windowToken, boolean imeVisible,
        void onImeRequestedChanged(IBinder windowToken, boolean imeVisible,
                @Nullable ImeTracker.Token statsToken);
                @NonNull ImeTracker.Token statsToken);
    }
    }


    /**
    /**