From a725209c5aea801912b4be9a12b34346a668fb16 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Wed, 16 Mar 2022 13:15:20 -0400 Subject: [PATCH] Extend notif lifetime if not anim activity launch While ag/17110765 expanded the lifetime extension to account for the intent launch animation, it failed to account for no launch animation, which means that lifetime extension needs to continue until the end of the synchronous method. Fixes: 224686965 Test: 1. Install Notify.apk (go/notify-apk) 2. In the Notify app: Check off Delayed 5000 and Auto Cancel 3. Click "Add" and spam click "Update" (5-10 times should suffice) 4. Lock device, go to lock screen (*not* AOD) 5. Immediately tap the Notify notification when it gets posted Observe: no crashing Change-Id: I1177719d6061f1fcb0fba726e6780a096beceedb --- .../NotificationLaunchAnimatorController.kt | 10 +++++----- .../StatusBarNotificationActivityStarter.java | 19 +++++++++++++++---- ...tusBarNotificationActivityStarterTest.java | 11 +++++++++++ 3 files changed, 31 insertions(+), 9 deletions(-) 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 7fbb0f1182c07..02aa1f2fd585b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationLaunchAnimatorController.kt @@ -25,7 +25,7 @@ class NotificationLaunchAnimatorControllerProvider @Inject constructor( @JvmOverloads fun getAnimatorController( notification: ExpandableNotificationRow, - onFinishAnimationCallback: Runnable = Runnable {} + onFinishAnimationCallback: Runnable? = null ): NotificationLaunchAnimatorController { return NotificationLaunchAnimatorController( notificationShadeWindowViewController, @@ -49,7 +49,7 @@ class NotificationLaunchAnimatorController( private val headsUpManager: HeadsUpManagerPhone, private val notification: ExpandableNotificationRow, private val jankMonitor: InteractionJankMonitor, - private val onFinishAnimationCallback: Runnable + private val onFinishAnimationCallback: Runnable? ) : ActivityLaunchAnimator.Controller { companion object { @@ -123,7 +123,7 @@ class NotificationLaunchAnimatorController( if (!willAnimate) { removeHun(animate = true) - onFinishAnimationCallback.run() + onFinishAnimationCallback?.run() } } @@ -142,7 +142,7 @@ class NotificationLaunchAnimatorController( notificationShadeWindowViewController.setExpandAnimationRunning(false) notificationEntry.isExpandAnimationRunning = false removeHun(animate = true) - onFinishAnimationCallback.run() + onFinishAnimationCallback?.run() } override fun onLaunchAnimationStart(isExpandingFullyAbove: Boolean) { @@ -162,7 +162,7 @@ class NotificationLaunchAnimatorController( notificationListContainer.setExpandingNotification(null) applyParams(null) removeHun(animate = false) - onFinishAnimationCallback.run() + onFinishAnimationCallback?.run() } private fun applyParams(params: ExpandAnimationParameters?) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java index 637e4bee8948d..6fe92fafc0751 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java @@ -397,15 +397,25 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte mMainThreadHandler.post(() -> { final Runnable removeNotification = () -> { mOnUserInteractionCallback.onDismiss(entry, REASON_CLICK, summaryToRemove); + if (!animate) { + // If we're animating, this would be invoked after the activity launch + // animation completes. Since we're not animating, the launch already + // happened synchronously, so we notify the launch is complete here after + // onDismiss. + mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry); + } }; if (mPresenter.isCollapsing()) { - // To avoid lags we're only performing the remove - // after the shade is collapsed + // To avoid lags we're only performing the remove after the shade is collapsed mShadeController.addPostCollapseAction(removeNotification); } else { removeNotification.run(); } }); + } else if (!canBubble && !animate) { + // Not animating, this is the end of the launch flow (see above comment for more info). + mMainThreadHandler.post( + () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry)); } mIsCollapsingToShowActivityOverLockscreen = false; @@ -481,8 +491,9 @@ class StatusBarNotificationActivityStarter implements NotificationActivityStarte boolean isActivityIntent) { mLogger.logStartNotificationIntent(entry.getKey(), intent); try { - Runnable onFinishAnimationCallback = - () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry); + Runnable onFinishAnimationCallback = animate + ? () -> mLaunchEventsEmitter.notifyFinishLaunchNotifActivity(entry) + : null; ActivityLaunchAnimator.Controller animationController = new StatusBarLaunchAnimatorController( mNotificationAnimationProvider 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 d48ce8c6803e3..fa867e2796f7c 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 @@ -447,4 +447,15 @@ public class StatusBarNotificationActivityStarterTest extends SysuiTestCase { controllerCaptor.getValue().onIntentStarted(false); verify(listener).onFinishLaunchNotifActivity(mNotificationRow.getEntry()); } + + @Test + public void testNotifActivityStarterEventSourceFinishEvent_postPanelCollapse_noAnimate() { + NotifActivityLaunchEvents.Listener listener = + mock(NotifActivityLaunchEvents.Listener.class); + mLaunchEventsEmitter.registerListener(listener); + when(mCentralSurfaces.shouldAnimateLaunch(anyBoolean())).thenReturn(false); + mNotificationActivityStarter + .onNotificationClicked(mNotificationRow.getEntry().getSbn(), mNotificationRow); + verify(listener).onFinishLaunchNotifActivity(mNotificationRow.getEntry()); + } }