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

Commit c0fc00cb authored by Julia Tuttle's avatar Julia Tuttle
Browse files

Move {add,remove}{Condition,Filter} to common interface

Bug: 261728888
Test: atest NotificationInterruptStateProviderWrapperTest
Test: atest VisualInterruptionDecisionProviderImplTest
Flag: ACONFIG com.android.systemui.visual_interruptions_refactor DEVELOPMENT
Change-Id: I35e0aa31534f95f8be9db6197cecd3e474493f44
parent a6931856
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.systemui.statusbar.notification.interruption

import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.RefactorFlagUtils
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider.FullScreenIntentDecision.NO_FSI_SUPPRESSED_ONLY_BY_DND
import com.android.systemui.statusbar.notification.interruption.VisualInterruptionDecisionProvider.Decision
@@ -62,6 +63,21 @@ class NotificationInterruptStateProviderWrapper(
        wrapped.removeSuppressor(suppressor)
    }

    override fun addCondition(condition: VisualInterruptionCondition) = notValidInLegacyMode()

    override fun removeCondition(condition: VisualInterruptionCondition) = notValidInLegacyMode()

    override fun addFilter(filter: VisualInterruptionFilter) = notValidInLegacyMode()

    override fun removeFilter(filter: VisualInterruptionFilter) = notValidInLegacyMode()

    private fun notValidInLegacyMode() {
        RefactorFlagUtils.assertOnEngBuild(
            "This method is only implemented in VisualInterruptionDecisionProviderImpl, " +
                "and so should only be called when FLAG_VISUAL_INTERRUPTIONS_REFACTOR is enabled."
        )
    }

    override fun makeUnloggedHeadsUpDecision(entry: NotificationEntry): Decision =
        wrapped.checkHeadsUp(entry, /* log= */ false).let { DecisionImpl.of(it) }

+62 −9
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.interruption

import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.statusbar.notification.collection.NotificationEntry

/**
@@ -51,33 +52,77 @@ interface VisualInterruptionDecisionProvider {
        val wouldInterruptWithoutDnd: Boolean
    }

    /**
     * Initializes the provider.
     *
     * Must be called before any method except [addLegacySuppressor].
     */
    /** Initializes the provider. */
    fun start() {}

    /**
     * Adds a [component][suppressor] that can suppress visual interruptions.
     * Adds a [NotificationInterruptSuppressor] that can suppress visual interruptions.
     *
     * This method may be called before [start] has been called.
     *
     * This class may call suppressors in any order.
     * This class may call suppressors, conditions, and filters in any order.
     *
     * @param[suppressor] the suppressor to add
     */
    fun addLegacySuppressor(suppressor: NotificationInterruptSuppressor)

    /**
     * Removes a [component][suppressor] that can suppress visual interruptions.
     * Removes a previously-added suppressor.
     *
     * This method may be called before [start] has been called.
     *
     * @param[suppressor] the suppressor to remove
     */
    fun removeLegacySuppressor(suppressor: NotificationInterruptSuppressor)
    @VisibleForTesting fun removeLegacySuppressor(suppressor: NotificationInterruptSuppressor)

    /**
     * Adds a [VisualInterruptionCondition] that can suppress visual interruptions without examining
     * individual notifications.
     *
     * This method may be called before [start] has been called.
     *
     * This class may call suppressors, conditions, and filters in any order.
     *
     * @param[condition] the condition to add
     */
    fun addCondition(condition: VisualInterruptionCondition)

    /**
     * Removes a previously-added condition.
     *
     * This method may be called before [start] has been called.
     *
     * @param[condition] the condition to remove
     */
    @VisibleForTesting fun removeCondition(condition: VisualInterruptionCondition)

    /**
     * Adds a [VisualInterruptionFilter] that can suppress visual interruptions based on individual
     * notifications.
     *
     * This method may be called before [start] has been called.
     *
     * This class may call suppressors, conditions, and filters in any order.
     *
     * @param[filter] the filter to add
     */
    fun addFilter(filter: VisualInterruptionFilter)

    /**
     * Removes a previously-added filter.
     *
     * This method may be called before [start] has been called.
     *
     * @param[filter] the filter to remove
     */
    @VisibleForTesting fun removeFilter(filter: VisualInterruptionFilter)

    /**
     * Decides whether a [notification][entry] should display as heads-up or not, but does not log
     * that decision.
     *
     * [start] must be called before this method can be called.
     *
     * @param[entry] the notification that this decision is about
     * @return the decision to display that notification as heads-up or not
     */
@@ -93,6 +138,8 @@ interface VisualInterruptionDecisionProvider {
     * If the device is dozing, the decision will consider whether the notification should "pulse"
     * (wake the screen up and display the ambient view of the notification).
     *
     * [start] must be called before this method can be called.
     *
     * @see[makeUnloggedHeadsUpDecision]
     *
     * @param[entry] the notification that this decision is about
@@ -106,6 +153,8 @@ interface VisualInterruptionDecisionProvider {
     *
     * The returned decision can be logged by passing it to [logFullScreenIntentDecision].
     *
     * [start] must be called before this method can be called.
     *
     * @see[makeAndLogHeadsUpDecision]
     *
     * @param[entry] the notification that this decision is about
@@ -116,6 +165,8 @@ interface VisualInterruptionDecisionProvider {
    /**
     * Logs a previous [decision] to launch a full-screen intent or not.
     *
     * [start] must be called before this method can be called.
     *
     * @param[decision] the decision to log
     */
    fun logFullScreenIntentDecision(decision: FullScreenIntentDecision)
@@ -123,6 +174,8 @@ interface VisualInterruptionDecisionProvider {
    /**
     * Decides whether a [notification][entry] should display as a bubble or not.
     *
     * [start] must be called before this method can be called.
     *
     * @param[entry] the notification that this decision is about
     * @return the decision to display that notification as a bubble or not
     */
+4 −4
Original line number Diff line number Diff line
@@ -171,23 +171,23 @@ constructor(
        legacySuppressors.remove(suppressor)
    }

    fun addCondition(condition: VisualInterruptionCondition) {
    override fun addCondition(condition: VisualInterruptionCondition) {
        conditions.add(condition)
        condition.start()
    }

    @VisibleForTesting
    fun removeCondition(condition: VisualInterruptionCondition) {
    override fun removeCondition(condition: VisualInterruptionCondition) {
        conditions.remove(condition)
    }

    fun addFilter(filter: VisualInterruptionFilter) {
    override fun addFilter(filter: VisualInterruptionFilter) {
        filters.add(filter)
        filter.start()
    }

    @VisibleForTesting
    fun removeFilter(filter: VisualInterruptionFilter) {
    override fun removeFilter(filter: VisualInterruptionFilter) {
        filters.remove(filter)
    }