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

Commit 6af3add6 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Add trace debug for onTouch/onTouchEvent

In order to measure and clarify the jank caused by application when
handling View.onTouchListener#onTouch and View#onTouchEvent slowly.

Bug: 256549451
Test: test with PTS CUJ tests and verify if onTouch/onTouchEvent shown
in the perfetto trace when enabling "view" trace tag in ftrace_config

Change-Id: I030f038ca57846bc9e7e66dc7e8bcbf8ffcd3d1e
parent c652d588
Loading
Loading
Loading
Loading
+31 −14
Original line number Diff line number Diff line
@@ -15858,20 +15858,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        if (onFilterTouchEventForSecurity(event)) {
            if ((mViewFlags & ENABLED_MASK) == ENABLED && handleScrollBarDragging(event)) {
                result = true;
            }
            //noinspection SimplifiableIfStatement
            ListenerInfo li = mListenerInfo;
            if (li != null && li.mOnTouchListener != null
                    && (mViewFlags & ENABLED_MASK) == ENABLED
                    && li.mOnTouchListener.onTouch(this, event)) {
                result = true;
            }
            if (!result && onTouchEvent(event)) {
                result = true;
            }
            result = performOnTouchCallback(event);
        }
        if (!result && mInputEventConsistencyVerifier != null) {
@@ -15890,6 +15877,36 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return result;
    }
    /**
     * Returns {@code true} if the {@link MotionEvent} from {@link #dispatchTouchEvent} was
     * handled by this view.
     */
    private boolean performOnTouchCallback(MotionEvent event) {
        boolean handled = false;
        if ((mViewFlags & ENABLED_MASK) == ENABLED && handleScrollBarDragging(event)) {
            handled = true;
        }
        //noinspection SimplifiableIfStatement
        ListenerInfo li = mListenerInfo;
        if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED) {
            try {
                Trace.traceBegin(Trace.TRACE_TAG_VIEW, "View.onTouchListener#onTouch");
                handled = li.mOnTouchListener.onTouch(this, event);
            } finally {
                Trace.traceEnd(Trace.TRACE_TAG_VIEW);
            }
        }
        if (handled) {
            return true;
        }
        try {
            Trace.traceBegin(Trace.TRACE_TAG_VIEW, "View#onTouchEvent");
            return onTouchEvent(event);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
        }
    }
    boolean isAccessibilityFocusedViewOrHost() {
        return isAccessibilityFocused() || (getViewRootImpl() != null && getViewRootImpl()
                .getAccessibilityFocusedHost() == this);