diff options
| author | 2024-06-20 11:00:52 +0000 | |
|---|---|---|
| committer | 2024-07-02 06:35:31 +0000 | |
| commit | 97e569a3fe2b4987b54130733e00572c7ec821c8 (patch) | |
| tree | d26c92df6cbff07dd54deee0d007fac574107c8e | |
| parent | b2ea8ff778743a9c92641767d762316319c11f7b (diff) | |
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
| -rw-r--r-- | core/java/com/android/internal/jank/InteractionJankMonitor.java | 42 | ||||
| -rw-r--r-- | core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java | 23 |
2 files changed, 64 insertions, 1 deletions
diff --git a/core/java/com/android/internal/jank/InteractionJankMonitor.java b/core/java/com/android/internal/jank/InteractionJankMonitor.java index b86cbfb69490..33610a09b7c8 100644 --- a/core/java/com/android/internal/jank/InteractionJankMonitor.java +++ b/core/java/com/android/internal/jank/InteractionJankMonitor.java @@ -325,6 +325,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. + * * @param builder the builder of the configurations for instrumenting the CUJ. * @return boolean true if the tracker is begun successfully, false otherwise. */ diff --git a/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java b/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java index f76398465378..5af272c8bead 100644 --- a/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java +++ b/core/tests/coretests/src/com/android/internal/jank/InteractionJankMonitorTest.java @@ -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()); @@ -103,6 +108,22 @@ public class InteractionJankMonitorTest { } @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); |