diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt index 22c3eda03b1e3..9da7d21886ab3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt @@ -16,7 +16,8 @@ import kotlin.math.max class NotificationLaunchAnimatorControllerProvider( private val notificationShadeWindowViewController: NotificationShadeWindowViewController, private val notificationListContainer: NotificationListContainer, - private val headsUpManager: HeadsUpManagerPhone + private val headsUpManager: HeadsUpManagerPhone, + private val jankMonitor: InteractionJankMonitor ) { fun getAnimatorController( notification: ExpandableNotificationRow @@ -25,7 +26,8 @@ class NotificationLaunchAnimatorControllerProvider( notificationShadeWindowViewController, notificationListContainer, headsUpManager, - notification + notification, + jankMonitor ) } } @@ -39,7 +41,8 @@ class NotificationLaunchAnimatorController( private val notificationShadeWindowViewController: NotificationShadeWindowViewController, private val notificationListContainer: NotificationListContainer, private val headsUpManager: HeadsUpManagerPhone, - private val notification: ExpandableNotificationRow + private val notification: ExpandableNotificationRow, + private val jankMonitor: InteractionJankMonitor ) : ActivityLaunchAnimator.Controller { companion object { @@ -137,12 +140,12 @@ class NotificationLaunchAnimatorController( notification.isExpandAnimationRunning = true notificationListContainer.setExpandingNotification(notification) - InteractionJankMonitor.getInstance().begin(notification, + jankMonitor.begin(notification, InteractionJankMonitor.CUJ_NOTIFICATION_APP_START) } override fun onLaunchAnimationEnd(isExpandingFullyAbove: Boolean) { - InteractionJankMonitor.getInstance().end(InteractionJankMonitor.CUJ_NOTIFICATION_APP_START) + jankMonitor.end(InteractionJankMonitor.CUJ_NOTIFICATION_APP_START) notification.isExpandAnimationRunning = false notificationShadeWindowViewController.setExpandAnimationRunning(false) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java index 41a80c7aceeba..71dcc5d4ee88b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutController.java @@ -183,6 +183,7 @@ public class NotificationStackScrollLayoutController { private final NotificationGroupManagerLegacy mLegacyGroupManager; private final SectionHeaderController mSilentHeaderController; private final LockscreenShadeTransitionController mLockscreenShadeTransitionController; + private final InteractionJankMonitor mJankMonitor; private NotificationStackScrollLayout mView; private boolean mFadeNotificationsOnDismiss; @@ -661,7 +662,8 @@ public class NotificationStackScrollLayoutController { LayoutInflater layoutInflater, NotificationRemoteInputManager remoteInputManager, VisualStabilityManager visualStabilityManager, - ShadeController shadeController) { + ShadeController shadeController, + InteractionJankMonitor jankMonitor) { mAllowLongPress = allowLongPress; mNotificationGutsManager = notificationGutsManager; mVisibilityProvider = visibilityProvider; @@ -684,6 +686,7 @@ public class NotificationStackScrollLayoutController { mNotificationSwipeHelperBuilder = notificationSwipeHelperBuilder; mStatusBar = statusBar; mScrimController = scrimController; + mJankMonitor = jankMonitor; groupManager.registerGroupExpansionChangeListener( (changedRow, expanded) -> mView.onGroupExpandChanged(changedRow, expanded)); legacyGroupManager.registerGroupChangeListener(new OnGroupChangeListener() { @@ -1784,9 +1787,9 @@ public class NotificationStackScrollLayoutController { // We log any touches other than down, which will be captured by onTouchEvent. // In the intercept we only start tracing when it's not a down (otherwise that down // would be duplicated when intercepted). - if (scrollWantsIt && ev.getActionMasked() != MotionEvent.ACTION_DOWN) { - InteractionJankMonitor.getInstance().begin(mView, - CUJ_NOTIFICATION_SHADE_SCROLL_FLING); + if (mJankMonitor != null && scrollWantsIt + && ev.getActionMasked() != MotionEvent.ACTION_DOWN) { + mJankMonitor.begin(mView, CUJ_NOTIFICATION_SHADE_SCROLL_FLING); } return swipeWantsIt || scrollWantsIt || expandWantsIt || longPressWantsIt; } @@ -1854,24 +1857,25 @@ public class NotificationStackScrollLayoutController { } private void traceJankOnTouchEvent(int action, boolean scrollerWantsIt) { + if (mJankMonitor == null) { + Log.w(TAG, "traceJankOnTouchEvent, mJankMonitor is null"); + return; + } // Handle interaction jank monitor cases. switch (action) { case MotionEvent.ACTION_DOWN: if (scrollerWantsIt) { - InteractionJankMonitor.getInstance() - .begin(mView, CUJ_NOTIFICATION_SHADE_SCROLL_FLING); + mJankMonitor.begin(mView, CUJ_NOTIFICATION_SHADE_SCROLL_FLING); } break; case MotionEvent.ACTION_UP: if (scrollerWantsIt && !mView.isFlingAfterUpEvent()) { - InteractionJankMonitor.getInstance() - .end(CUJ_NOTIFICATION_SHADE_SCROLL_FLING); + mJankMonitor.end(CUJ_NOTIFICATION_SHADE_SCROLL_FLING); } break; case MotionEvent.ACTION_CANCEL: if (scrollerWantsIt) { - InteractionJankMonitor.getInstance() - .cancel(CUJ_NOTIFICATION_SHADE_SCROLL_FLING); + mJankMonitor.cancel(CUJ_NOTIFICATION_SHADE_SCROLL_FLING); } break; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 2ba70df8a1da6..ec95d5745b846 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -116,6 +116,7 @@ import androidx.lifecycle.LifecycleRegistry; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.colorextraction.ColorExtractor; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.UiEvent; import com.android.internal.logging.UiEventLogger; @@ -677,6 +678,8 @@ public class StatusBar extends CoreStartable implements private final ColorExtractor.OnColorsChangedListener mOnColorsChangedListener = (extractor, which) -> updateTheme(); + private final InteractionJankMonitor mJankMonitor; + /** * Public constructor for StatusBar. @@ -779,7 +782,8 @@ public class StatusBar extends CoreStartable implements WallpaperManager wallpaperManager, Optional startingSurfaceOptional, ActivityLaunchAnimator activityLaunchAnimator, - NotifPipelineFlags notifPipelineFlags) { + NotifPipelineFlags notifPipelineFlags, + InteractionJankMonitor jankMonitor) { super(context); mNotificationsController = notificationsController; mFragmentService = fragmentService; @@ -867,6 +871,7 @@ public class StatusBar extends CoreStartable implements mMainExecutor = delayableExecutor; mMessageRouter = messageRouter; mWallpaperManager = wallpaperManager; + mJankMonitor = jankMonitor; mLockscreenShadeTransitionController = lockscreenShadeTransitionController; mStartingSurfaceOptional = startingSurfaceOptional; @@ -1387,7 +1392,8 @@ public class StatusBar extends CoreStartable implements mNotificationAnimationProvider = new NotificationLaunchAnimatorControllerProvider( mNotificationShadeWindowViewController, mStackScrollerController.getNotificationListContainer(), - mHeadsUpManager + mHeadsUpManager, + mJankMonitor ); // TODO: inject this. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java index f93a8dcad2234..c6ef4b5865413 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/dagger/StatusBarPhoneModule.java @@ -24,6 +24,7 @@ import android.os.Handler; import android.os.PowerManager; import android.util.DisplayMetrics; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.logging.MetricsLogger; import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.ViewMediatorCallback; @@ -227,7 +228,8 @@ public interface StatusBarPhoneModule { WallpaperManager wallpaperManager, Optional startingSurfaceOptional, ActivityLaunchAnimator activityLaunchAnimator, - NotifPipelineFlags notifPipelineFlags) { + NotifPipelineFlags notifPipelineFlags, + InteractionJankMonitor jankMonitor) { return new StatusBar( context, notificationsController, @@ -321,7 +323,8 @@ public interface StatusBarPhoneModule { wallpaperManager, startingSurfaceOptional, activityLaunchAnimator, - notifPipelineFlags + notifPipelineFlags, + jankMonitor ); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorControllerTest.kt index c74437f5ad945..3a60c049b3f3e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorControllerTest.kt @@ -4,6 +4,7 @@ import android.testing.AndroidTestingRunner import android.testing.TestableLooper import android.testing.TestableLooper.RunWithLooper import androidx.test.filters.SmallTest +import com.android.internal.jank.InteractionJankMonitor import com.android.systemui.SysuiTestCase import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.NotificationTestHelper @@ -29,6 +30,7 @@ class NotificationLaunchAnimatorControllerTest : SysuiTestCase() { @Mock lateinit var notificationShadeWindowViewController: NotificationShadeWindowViewController @Mock lateinit var notificationListContainer: NotificationListContainer @Mock lateinit var headsUpManager: HeadsUpManagerPhone + @Mock lateinit var jankMonitor: InteractionJankMonitor private lateinit var notificationTestHelper: NotificationTestHelper private lateinit var notification: ExpandableNotificationRow @@ -49,7 +51,8 @@ class NotificationLaunchAnimatorControllerTest : SysuiTestCase() { notificationShadeWindowViewController, notificationListContainer, headsUpManager, - notification + notification, + jankMonitor ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java index 7194c6620e12b..4cc1be6966376 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayoutControllerTest.java @@ -38,6 +38,7 @@ import android.view.LayoutInflater; import androidx.test.filters.SmallTest; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.nano.MetricsProto; @@ -135,6 +136,7 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase { @Mock private NotificationRemoteInputManager mRemoteInputManager; @Mock private VisualStabilityManager mVisualStabilityManager; @Mock private ShadeController mShadeController; + @Mock private InteractionJankMonitor mJankMonitor; @Captor private ArgumentCaptor mStateListenerArgumentCaptor; @@ -188,7 +190,8 @@ public class NotificationStackScrollLayoutControllerTest extends SysuiTestCase { mLayoutInflater, mRemoteInputManager, mVisualStabilityManager, - mShadeController + mShadeController, + mJankMonitor ); when(mNotificationStackScrollLayout.isAttachedToWindow()).thenReturn(true); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java index 07ec0e23aa019..743311f99ca2c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarterTest.java @@ -48,6 +48,7 @@ import android.testing.TestableLooper; import androidx.test.filters.SmallTest; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.logging.MetricsLogger; import com.android.internal.statusbar.NotificationVisibility; import com.android.internal.widget.LockPatternUtils; @@ -64,7 +65,6 @@ import com.android.systemui.statusbar.NotificationPresenter; import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.notification.NotifPipelineFlags; -import com.android.systemui.statusbar.notification.NotificationActivityStarter; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.NotificationLaunchAnimatorControllerProvider; import com.android.systemui.statusbar.notification.collection.NotifPipeline; @@ -143,6 +143,8 @@ public class StatusBarNotificationActivityStarterTest extends SysuiTestCase { private StatusBarNotificationActivityStarter mNotificationActivityStarter; @Mock private ActivityLaunchAnimator mActivityLaunchAnimator; + @Mock + private InteractionJankMonitor mJankMonitor; private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock()); private NotificationTestHelper mNotificationTestHelper; @@ -197,7 +199,8 @@ public class StatusBarNotificationActivityStarterTest extends SysuiTestCase { new NotificationLaunchAnimatorControllerProvider( mock(NotificationShadeWindowViewController.class), mock( NotificationListContainer.class), - headsUpManager); + headsUpManager, + mJankMonitor); mNotificationActivityStarter = new StatusBarNotificationActivityStarter.Builder( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java index 9d5b17ea67389..554e1d91af779 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java @@ -69,6 +69,7 @@ import android.view.WindowManager; import androidx.test.filters.SmallTest; import com.android.internal.colorextraction.ColorExtractor; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.testing.FakeMetricsLogger; import com.android.internal.statusbar.IStatusBarService; @@ -276,6 +277,7 @@ public class StatusBarTest extends SysuiTestCase { @Mock private ActivityLaunchAnimator mActivityLaunchAnimator; @Mock private NotifPipelineFlags mNotifPipelineFlags; @Mock private NotifLiveDataStore mNotifLiveDataStore; + @Mock private InteractionJankMonitor mJankMonitor; private ShadeController mShadeController; private final FakeSystemClock mFakeSystemClock = new FakeSystemClock(); private FakeExecutor mMainExecutor = new FakeExecutor(mFakeSystemClock); @@ -459,7 +461,8 @@ public class StatusBarTest extends SysuiTestCase { mWallpaperManager, Optional.of(mStartingSurface), mActivityLaunchAnimator, - mNotifPipelineFlags); + mNotifPipelineFlags, + mJankMonitor); when(mKeyguardViewMediator.registerStatusBar( any(StatusBar.class), any(NotificationPanelViewController.class),