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

Commit 06f75983 authored by Ioana Stefan's avatar Ioana Stefan Committed by Android (Google) Code Review
Browse files

Merge changes from topics "ime-tracing-interface",...

Merge changes from topics "ime-tracing-interface", "optimized-ime-tracing-clients", "optimized-ime-tracing-imms", "optimized-ime-tracing-ims"

* changes:
  Log only current client data in IME tracing
  Optimized workflow for IME tracing on InputMethodManagerService side
  Optimized workflow for IME tracing on InputMethodService side
  Optimized workflow for IME tracing on clients side
parents 781e61d2 45296595
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.proto.ProtoOutputStream;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.InputConnection;
@@ -195,15 +196,13 @@ public abstract class AbstractInputMethodService extends Service
    public abstract AbstractInputMethodSessionImpl onCreateInputMethodSessionInterface();

    /**
     * Dumps the internal state of IME to a protocol buffer output stream initialized using the
     * given {@link FileDescriptor}.
     * Dumps the internal state of IME to a protocol buffer output stream.
     *
     * @param fd The file descriptor to which proto dump should be written.
     * @param args The arguments passed to the dump method.
     * @param proto ProtoOutputStream to dump data to.
     * @hide
     */
    @SuppressWarnings("HiddenAbstractMethod")
    abstract void dumpProtoInternal(FileDescriptor fd, String[] args);
    public abstract void dumpProtoInternal(ProtoOutputStream proto);

    /**
     * Implement this to handle {@link android.os.Binder#dump Binder.dump()}
+2 −15
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.inputmethodservice;

import static android.util.imetracing.ImeTracing.PROTO_ARG;

import android.annotation.BinderThread;
import android.annotation.MainThread;
import android.annotation.Nullable;
@@ -157,20 +155,9 @@ class IInputMethodWrapper extends IInputMethod.Stub
                    return;
                }
                SomeArgs args = (SomeArgs)msg.obj;
                String[] dumpArgs = (String[]) args.arg3;
                boolean protoDumpRequested = false;
                for (String arg : dumpArgs) {
                    if (arg.equals(PROTO_ARG)) {
                        protoDumpRequested = true;
                        break;
                    }
                }
                try {
                    if (protoDumpRequested) {
                        target.dumpProtoInternal((FileDescriptor) args.arg1, dumpArgs);
                    } else {
                        target.dump((FileDescriptor) args.arg1, (PrintWriter) args.arg2, dumpArgs);
                    }
                    target.dump((FileDescriptor) args.arg1,
                            (PrintWriter) args.arg2, (String[]) args.arg3);
                } catch (RuntimeException e) {
                    ((PrintWriter)args.arg2).println("Exception: " + e);
                }
+18 −3
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ import android.text.method.MovementMethod;
import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.imetracing.ImeTracing;
import android.util.proto.ProtoOutputStream;
import android.view.Gravity;
import android.view.KeyCharacterMap;
@@ -116,6 +117,7 @@ import android.view.inputmethod.InputBinding;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputContentInfo;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodEditorTraceProto.InputMethodServiceTraceProto;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.FrameLayout;
@@ -708,6 +710,8 @@ public class InputMethodService extends AbstractInputMethodService {
                        + " Use requestHideSelf(int) itself");
                return;
            }
            ImeTracing.getInstance().triggerServiceDump(
                    "InputMethodService.InputMethodImpl#hideSoftInput", InputMethodService.this);
            final boolean wasVisible = isInputViewShown();
            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.hideSoftInput");

@@ -762,6 +766,8 @@ public class InputMethodService extends AbstractInputMethodService {
                Binder.disableTracing();
            }
            Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMS.showSoftInput");
            ImeTracing.getInstance().triggerServiceDump(
                    "InputMethodService.InputMethodImpl#showSoftInput", InputMethodService.this);
            final boolean wasVisible = isInputViewShown();
            if (dispatchOnShowInputRequested(flags, false)) {

@@ -2133,6 +2139,8 @@ public class InputMethodService extends AbstractInputMethodService {
            return;
        }

        ImeTracing.getInstance().triggerServiceDump("InputMethodService#showWindow", this);

        mDecorViewWasVisible = mDecorViewVisible;
        mInShowWindow = true;
        final int previousImeWindowStatus =
@@ -2207,6 +2215,8 @@ public class InputMethodService extends AbstractInputMethodService {
     * @param setVisible {@code true} to make it visible, false to hide it.
     */
    private void applyVisibilityInInsetsConsumerIfNecessary(boolean setVisible) {
        ImeTracing.getInstance().triggerServiceDump(
                "InputMethodService#applyVisibilityInInsetsConsumerIfNecessary", this);
        mPrivOps.applyImeVisibility(setVisible
                ? mCurShowInputToken : mCurHideInputToken, setVisible);
    }
@@ -2231,6 +2241,7 @@ public class InputMethodService extends AbstractInputMethodService {

    public void hideWindow() {
        if (DEBUG) Log.v(TAG, "CALL: hideWindow");
        ImeTracing.getInstance().triggerServiceDump("InputMethodService#hideWindow", this);
        mWindowVisible = false;
        finishViews(false /* finishingInput */);
        if (mDecorViewVisible) {
@@ -2301,6 +2312,7 @@ public class InputMethodService extends AbstractInputMethodService {
    
    void doFinishInput() {
        if (DEBUG) Log.v(TAG, "CALL: doFinishInput");
        ImeTracing.getInstance().triggerServiceDump("InputMethodService#doFinishInput", this);
        finishViews(true /* finishingInput */);
        if (mInputStarted) {
            mInlineSuggestionSessionController.notifyOnFinishInput();
@@ -2316,6 +2328,7 @@ public class InputMethodService extends AbstractInputMethodService {
        if (!restarting) {
            doFinishInput();
        }
        ImeTracing.getInstance().triggerServiceDump("InputMethodService#doStartInput", this);
        mInputStarted = true;
        mStartedInputConnection = ic;
        mInputEditorInfo = attribute;
@@ -2474,6 +2487,7 @@ public class InputMethodService extends AbstractInputMethodService {
     * @param flags Provides additional operating flags.
     */
    public void requestHideSelf(int flags) {
        ImeTracing.getInstance().triggerServiceDump("InputMethodService#requestHideSelf", this);
        mPrivOps.hideMySoftInput(flags);
    }

@@ -2486,6 +2500,7 @@ public class InputMethodService extends AbstractInputMethodService {
     * @param flags Provides additional operating flags.
     */
    public final void requestShowSelf(int flags) {
        ImeTracing.getInstance().triggerServiceDump("InputMethodService#requestShowSelf", this);
        mPrivOps.showMySoftInput(flags);
    }

@@ -3305,8 +3320,8 @@ public class InputMethodService extends AbstractInputMethodService {
     * @hide
     */
    @Override
    final void dumpProtoInternal(FileDescriptor fd, String[] args) {
        final ProtoOutputStream proto = new ProtoOutputStream(fd);
    public final void dumpProtoInternal(ProtoOutputStream proto) {
        final long token = proto.start(InputMethodServiceTraceProto.INPUT_METHOD_SERVICE);
        mWindow.dumpDebug(proto, SOFT_INPUT_WINDOW);
        proto.write(VIEWS_CREATED, mViewsCreated);
        proto.write(DECOR_VIEW_VISIBLE, mDecorViewVisible);
@@ -3334,6 +3349,6 @@ public class InputMethodService extends AbstractInputMethodService {
        proto.write(STATUS_ICON, mStatusIcon);
        mTmpInsets.dumpDebug(proto, LAST_COMPUTED_INSETS);
        proto.write(SETTINGS_OBSERVER, Objects.toString(mSettingsObserver));
        proto.flush();
        proto.end(token);
    }
}
+43 −4
Original line number Diff line number Diff line
@@ -18,12 +18,14 @@ package android.util.imetracing;

import android.app.ActivityThread;
import android.content.Context;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ShellCommand;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.view.IInputMethodManager;

@@ -40,10 +42,18 @@ public abstract class ImeTracing {
    static final String TAG = "imeTracing";
    public static final String PROTO_ARG = "--proto-com-android-imetracing";

    /* Constants describing the component type that triggered a dump. */
    public static final int IME_TRACING_FROM_CLIENT = 0;
    public static final int IME_TRACING_FROM_IMS = 1;
    public static final int IME_TRACING_FROM_IMMS = 2;

    private static ImeTracing sInstance;
    static boolean sEnabled = false;
    IInputMethodManager mService;

    protected boolean mDumpInProgress;
    protected final Object mDumpInProgressLock = new Object();

    ImeTracing() throws ServiceNotFoundException {
        mService = IInputMethodManager.Stub.asInterface(
                ServiceManager.getServiceOrThrow(Context.INPUT_METHOD_SERVICE));
@@ -69,15 +79,22 @@ public abstract class ImeTracing {
    }

    /**
     * Sends request to start proto dump to {@link ImeTracingServerImpl} when called from a
     * server process and to {@link ImeTracingClientImpl} when called from a client process.
     * Transmits the information from client or InputMethodService side to the server, in order to
     * be stored persistently to the current IME tracing dump.
     *
     * @param protoDump client or service side information to be stored by the server
     * @param source where the information is coming from, refer to {@see #IME_TRACING_FROM_CLIENT}
     * and {@see #IME_TRACING_FROM_IMS}
     * @param where
     */
    public abstract void triggerDump();
    public void sendToService(byte[] protoDump, int source, String where) throws RemoteException {
        mService.startProtoDump(protoDump, source, where);
    }

    /**
     * @param proto dump to be added to the buffer
     */
    public abstract void addToBuffer(ProtoOutputStream proto);
    public abstract void addToBuffer(ProtoOutputStream proto, int source);

    /**
     * @param shell The shell command to process
@@ -85,6 +102,28 @@ public abstract class ImeTracing {
     */
    public abstract int onShellCommand(ShellCommand shell);

    /**
     * Starts a proto dump of the client side information.
     *
     * @param where Place where the trace was triggered.
     * @param immInstance The {@link InputMethodManager} instance to dump.
     */
    public abstract void triggerClientDump(String where, InputMethodManager immInstance);

    /**
     * Starts a proto dump of the currently connected InputMethodService information.
     *
     * @param where Place where the trace was triggered.
     */
    public abstract void triggerServiceDump(String where, AbstractInputMethodService service);

    /**
     * Starts a proto dump of the InputMethodManagerService information.
     *
     * @param where Place where the trace was triggered.
     */
    public abstract void triggerManagerServiceDump(String where);

    /**
     * Sets whether ime tracing is enabled.
     *
+49 −23
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.util.imetracing;

import android.annotation.NonNull;
import android.inputmethodservice.AbstractInputMethodService;
import android.os.RemoteException;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ShellCommand;
@@ -27,16 +29,12 @@ import android.view.inputmethod.InputMethodManager;
 * @hide
 */
class ImeTracingClientImpl extends ImeTracing {

    private boolean mDumpInProgress;
    private final Object mDumpInProgressLock = new Object();

    ImeTracingClientImpl() throws ServiceNotFoundException, RemoteException {
        sEnabled = mService.isImeTraceEnabled();
    }

    @Override
    public void addToBuffer(ProtoOutputStream proto) {
    public void addToBuffer(ProtoOutputStream proto, int source) {
    }

    @Override
@@ -45,27 +43,55 @@ class ImeTracingClientImpl extends ImeTracing {
    }

    @Override
    public void triggerDump() {
        if (isAvailable() && isEnabled()) {
            boolean doDump = false;
    public void triggerClientDump(String where, @NonNull InputMethodManager immInstance) {
        if (!isEnabled() || !isAvailable()) {
            return;
        }

        synchronized (mDumpInProgressLock) {
                if (!mDumpInProgress) {
                    mDumpInProgress = true;
                    doDump = true;
            if (mDumpInProgress) {
                return;
            }
            mDumpInProgress = true;
        }

            if (doDump) {
        try {
            ProtoOutputStream proto = new ProtoOutputStream();
                    InputMethodManager.dumpProto(proto);
                    mService.startProtoDump(proto.getBytes());
            immInstance.dumpDebug(proto);
            sendToService(proto.getBytes(), IME_TRACING_FROM_CLIENT, where);
        } catch (RemoteException e) {
            Log.e(TAG, "Exception while sending ime-related client dump to server", e);
        } finally {
            mDumpInProgress = false;
        }
    }

    @Override
    public void triggerServiceDump(String where, @NonNull AbstractInputMethodService service) {
        if (!isEnabled() || !isAvailable()) {
            return;
        }

        synchronized (mDumpInProgressLock) {
            if (mDumpInProgress) {
                return;
            }
            mDumpInProgress = true;
        }

        try {
            ProtoOutputStream proto = new ProtoOutputStream();
            service.dumpProtoInternal(proto);
            sendToService(proto.getBytes(), IME_TRACING_FROM_IMS, where);
        } catch (RemoteException e) {
            Log.e(TAG, "Exception while sending ime-related service dump to server", e);
        } finally {
            mDumpInProgress = false;
        }
    }

    @Override
    public void triggerManagerServiceDump(String where) {
        // Intentionally left empty, this is implemented in ImeTracingServerImpl
    }
}
Loading