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

Commit 34b4ebd8 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Remove the ActivityLaunchAnimCoordinator.

This coordinator was recently added for the purpose of extending the lifetime of the notification entry while the launch animation played to prevent an entry instance mismatch crash when the app cancelled and reposted it on app launch.  Unfortunately, this wasn't a scalable solution: 1) there was another launch scenario that wasn't covered by this animation, and 2) if the notification was auto-cancelled and reposted, this would not work because lifetime extenders are not allowed to extend the lifetime of user-dismissed notifications.

That bug and these new crash cases were solved by alerting the NotifCollection when the animation starts, and then not dismissing the notification when it ends if it was already dismissed by the system server. That is implemented in Ia66ae5ade3fbfdd0436d54dcbeef720618622716, but makes this coordinator and the events it listened to unnecessary.

Bug: 230540148
Bug: 227254780
Test: manually validate that crashes are still fixed
Change-Id: I28f7226a30df7730dbae264bfd101397293a9a03
parent 4a206a41
Loading
Loading
Loading
Loading
+0 −95
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection.coordinator

import com.android.systemui.statusbar.notification.collection.NotifPipeline
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender.OnEndLifetimeExtensionCallback
import com.android.systemui.statusbar.phone.NotifActivityLaunchEvents
import dagger.Binds
import dagger.Module
import javax.inject.Inject

/** Extends the lifetime of notifications while their activity launch animation is playing. */
interface ActivityLaunchAnimCoordinator : Coordinator

/** Provides an [ActivityLaunchAnimCoordinator] to [CoordinatorScope]. */
@Module(includes = [PrivateActivityStarterCoordinatorModule::class])
object ActivityLaunchAnimCoordinatorModule

@Module
private interface PrivateActivityStarterCoordinatorModule {
    @Binds
    fun bindCoordinator(impl: ActivityLaunchAnimCoordinatorImpl): ActivityLaunchAnimCoordinator
}

/**
 * Listens for [NotifActivityLaunchEvents], and then extends the lifetimes of any notifs while their
 * launch animation is playing.
 */
@CoordinatorScope
private class ActivityLaunchAnimCoordinatorImpl @Inject constructor(
    private val activityLaunchEvents: NotifActivityLaunchEvents
) : ActivityLaunchAnimCoordinator {
    // Tracks notification launches, and whether or not their lifetimes are extended.
    private val notifsLaunchingActivities = mutableMapOf<String, Boolean>()

    private var onEndLifetimeExtensionCallback: OnEndLifetimeExtensionCallback? = null

    override fun attach(pipeline: NotifPipeline) {
        activityLaunchEvents.registerListener(activityStartEventListener)
        pipeline.addNotificationLifetimeExtender(extender)
    }

    private val activityStartEventListener = object : NotifActivityLaunchEvents.Listener {
        override fun onStartLaunchNotifActivity(entry: NotificationEntry) {
            notifsLaunchingActivities[entry.key] = false
        }

        override fun onFinishLaunchNotifActivity(entry: NotificationEntry) {
            if (notifsLaunchingActivities.remove(entry.key) == true) {
                // If we were extending the lifetime of this notification, stop.
                onEndLifetimeExtensionCallback?.onEndLifetimeExtension(extender, entry)
            }
        }
    }

    private val extender = object : NotifLifetimeExtender {
        override fun getName(): String = "ActivityStarterCoordinator"

        override fun setCallback(callback: OnEndLifetimeExtensionCallback) {
            onEndLifetimeExtensionCallback = callback
        }

        override fun maybeExtendLifetime(entry: NotificationEntry, reason: Int): Boolean {
            if (entry.key in notifsLaunchingActivities) {
                // Track that we're now extending this notif
                notifsLaunchingActivities[entry.key] = true
                return true
            }
            return false
        }

        override fun cancelLifetimeExtension(entry: NotificationEntry) {
            if (entry.key in notifsLaunchingActivities) {
                notifsLaunchingActivities[entry.key] = false
            }
        }
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ class NotifCoordinatorsImpl @Inject constructor(
    smartspaceDedupingCoordinator: SmartspaceDedupingCoordinator,
    viewConfigCoordinator: ViewConfigCoordinator,
    visualStabilityCoordinator: VisualStabilityCoordinator,
    activityLaunchAnimCoordinator: ActivityLaunchAnimCoordinator
) : NotifCoordinators {

    private val mCoordinators: MutableList<Coordinator> = ArrayList()
@@ -93,7 +92,6 @@ class NotifCoordinatorsImpl @Inject constructor(
        mCoordinators.add(shadeEventCoordinator)
        mCoordinators.add(viewConfigCoordinator)
        mCoordinators.add(visualStabilityCoordinator)
//        mCoordinators.add(activityLaunchAnimCoordinator) // NOTE: will delete in followup CL
        if (notifPipelineFlags.isSmartspaceDedupingEnabled()) {
            mCoordinators.add(smartspaceDedupingCoordinator)
        }
+0 −2
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.notification.collection.coordinator.dagger

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.notification.collection.coordinator.ActivityLaunchAnimCoordinatorModule
import com.android.systemui.statusbar.notification.collection.coordinator.NotifCoordinators
import com.android.systemui.statusbar.notification.collection.coordinator.NotifCoordinatorsImpl
import dagger.Binds
@@ -48,7 +47,6 @@ interface CoordinatorsSubcomponent {
}

@Module(includes = [
    ActivityLaunchAnimCoordinatorModule::class,
])
private abstract class InternalCoordinatorsModule {
    @Binds
+0 −2
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ import com.android.systemui.statusbar.notification.stack.NotificationSectionsMan
import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.NotifActivityLaunchEventsModule;
import com.android.systemui.statusbar.phone.NotifPanelEventsModule;
import com.android.systemui.statusbar.phone.ShadeController;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -111,7 +110,6 @@ import dagger.Provides;
@Module(includes = {
        CoordinatorsModule.class,
        KeyguardNotificationVisibilityProviderModule.class,
        NotifActivityLaunchEventsModule.class,
        NotifPanelEventsModule.class,
        NotifPipelineChoreographerModule.class,
        NotificationSectionHeadersModule.class,
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.phone

import com.android.systemui.statusbar.notification.collection.NotificationEntry

/** Provides events about [android.app.Activity] launches from Notifications. */
interface NotifActivityLaunchEvents {

    /** Registers a [Listener] to be invoked when notification activity launch events occur. */
    fun registerListener(listener: Listener)

    /** Unregisters a [Listener] previously registered via [registerListener] */
    fun unregisterListener(listener: Listener)

    /** Listener for events about [android.app.Activity] launches from Notifications. */
    interface Listener {

        /** Invoked when an activity has started launching from a notification. */
        fun onStartLaunchNotifActivity(entry: NotificationEntry)

        /** Invoked when an activity has finished launching. */
        fun onFinishLaunchNotifActivity(entry: NotificationEntry)
    }
}
Loading