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

Commit 07a443a6 authored by Jeff DeCew's avatar Jeff DeCew Committed by Automerger Merge Worker
Browse files

Merge changes from topic "register_future_dismissal" into tm-dev am: 38a97b78 am: 1f828de0

parents d6ce158f 1f828de0
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