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

Commit a725209c authored by Steve Elliott's avatar Steve Elliott
Browse files

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
parent 40ca086c
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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?) {
+15 −4
Original line number Diff line number Diff line
@@ -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
+11 −0
Original line number Diff line number Diff line
@@ -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());
    }
}