summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Tuttle <juliatuttle@google.com> 2023-11-11 03:49:28 -0500
committer Julia Tuttle <juliatuttle@google.com> 2023-11-14 16:22:07 -0500
commitc0fc00cb0b3075d0dd748acd5b1fa8f0fa5f5a9a (patch)
tree67d6781781624e0c6ecd5cf0b9dc4c49125a073b
parenta69318560c94fe1588bf84e48b2569cf7a3aa7d6 (diff)
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
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapper.kt16
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProvider.kt71
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt8
3 files changed, 82 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapper.kt
index d7f0baf4f002..f732e8d74675 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/NotificationInterruptStateProviderWrapper.kt
@@ -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) }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProvider.kt
index da8474e92629..de8863c64873 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProvider.kt
@@ -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
*/
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt
index 6344d08b18dd..2b6e1a168b3c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderImpl.kt
@@ -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)
}