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

Commit 97e569a3 authored by Devarshi Bhatt's avatar Devarshi Bhatt
Browse files

Add new API for starting a trace session with SurfaceControl input.

Test: atest InteractionJankMonitorTest
Bug: 348339127
Flag: NONE new API for tracing
Change-Id: I06a8b7c3e7d5f9217ce3c3ae846246f6f0075897
parent b2ea8ff7
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -322,6 +322,48 @@ public class InteractionJankMonitor {
        }
    }

    /**
     * Begins a trace session.
     *
     * @param surface a handle for the surface to begin tracing for.
     * @param context context to provide display and handler information.
     * @param cujType the specific {@link Cuj.CujType}.
     * @return boolean true if the tracker is started successfully, false otherwise.
     */
    public boolean begin(SurfaceControl surface, Context context, @Cuj.CujType int cujType) {
        try {
            return begin(Configuration.Builder.withSurface(cujType, context, surface));
        } catch (IllegalArgumentException ex) {
            Log.d(TAG, "Build configuration failed!", ex);
            return false;
        }
    }

    /**
     * Begins a trace session.
     *
     * @param surface a handle for the surface to begin tracing for.
     * @param context context to provide display and handler information.
     * @param cujType the specific {@link Cuj.CujType}.
     * @param tag a tag containing extra information about the interaction.
     * @return boolean true if the tracker is started successfully, false otherwise.
     */
    public boolean begin(SurfaceControl surface, Context context, @Cuj.CujType int cujType,
            String tag) {
        try {
            final Configuration.Builder builder =
                    Configuration.Builder.withSurface(cujType, context, surface);
            if (!TextUtils.isEmpty(tag)) {
                builder.setTag(tag);
            }
            return begin(builder);
        } catch (IllegalArgumentException ex) {
            Log.d(TAG, "Build configuration failed!", ex);
            return false;
        }
    }


    /**
     * Begins a trace session.
     *
+22 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.SystemClock;
import android.provider.DeviceConfig;
import android.view.SurfaceControl;
import android.view.View;
import android.view.ViewAttachTestActivity;

@@ -67,6 +68,7 @@ public class InteractionJankMonitorTest {
    private View mView;
    private Handler mHandler;
    private HandlerThread mWorker;
    private SurfaceControl mSurfaceControl;

    @Rule
    public ActivityScenarioRule<ViewAttachTestActivity> mRule =
@@ -79,6 +81,9 @@ public class InteractionJankMonitorTest {
    public void setup() {
        mRule.getScenario().onActivity(activity -> mActivity = activity);
        mView = mActivity.getWindow().getDecorView();
        mSurfaceControl = mView.getViewRootImpl().getSurfaceControl();
        // Set mNativeObject to a non-zero value to make it a valid SurfaceControl.
        mSurfaceControl.mNativeObject = 1;
        assertThat(mView.isAttachedToWindow()).isTrue();

        mHandler = spy(new Handler(mActivity.getMainLooper()));
@@ -88,7 +93,7 @@ public class InteractionJankMonitorTest {
    }

    @Test
    public void testBeginEnd() {
    public void testBeginEnd_inputView() {
        InteractionJankMonitor monitor = createMockedInteractionJankMonitor();
        FrameTracker tracker = createMockedFrameTracker();
        doReturn(tracker).when(monitor).createFrameTracker(any());
@@ -102,6 +107,22 @@ public class InteractionJankMonitorTest {
        verify(tracker).end(REASON_END_NORMAL);
    }

    @Test
    public void testBeginEnd_inputSurfaceControl() {
        InteractionJankMonitor monitor = createMockedInteractionJankMonitor();
        FrameTracker tracker = createMockedFrameTracker();
        doReturn(tracker).when(monitor).createFrameTracker(any());
        doNothing().when(tracker).begin();
        doReturn(true).when(tracker).end(anyInt());

        // Simulate a trace session and see if begin / end are invoked.
        assertThat(monitor.begin(mSurfaceControl, mActivity.getApplicationContext(),
                Cuj.CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE)).isTrue();
        verify(tracker).begin();
        assertThat(monitor.end(Cuj.CUJ_NOTIFICATION_SHADE_EXPAND_COLLAPSE)).isTrue();
        verify(tracker).end(REASON_END_NORMAL);
    }

    @Test
    public void testDisabledThroughDeviceConfig() {
        InteractionJankMonitor monitor = new InteractionJankMonitor(mWorker);