diff options
| author | 2023-10-31 16:14:02 -0400 | |
|---|---|---|
| committer | 2023-11-01 22:54:16 -0400 | |
| commit | 79e14a7ab60f4652315b59f0a9c06fa229aa546f (patch) | |
| tree | f85e88f6cd277c16c848fb4fd744b1d19dfa085c | |
| parent | 974bbf59171946297209c75af8082ab54b6fbf1d (diff) | |
Implement remaining bubble suppression logic
Bug: 261728888
Test: atest NotificationInterruptStateProviderWrapperTest
Test: atest VisualInterruptionDecisionProviderImplTest
Flag: ACONFIG com.android.systemui.visual_interruptions_refactor DEVELOPMENT
Change-Id: I316150ef1a75fc6effc891abda850b1b2f9390e1
3 files changed, 61 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt index 11c982590477..73bac872f0a6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/CommonVisualInterruptionSuppressors.kt @@ -16,6 +16,7 @@ package com.android.systemui.statusbar.notification.interruption +import android.app.Notification.BubbleMetadata import android.app.Notification.VISIBILITY_PRIVATE import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.app.NotificationManager.IMPORTANCE_HIGH @@ -31,6 +32,7 @@ import com.android.systemui.settings.UserTracker import com.android.systemui.statusbar.StatusBarState.SHADE import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProviderImpl.MAX_HUN_WHEN_AGE_MS +import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.BUBBLE import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PEEK import com.android.systemui.statusbar.notification.interruption.VisualInterruptionType.PULSE import com.android.systemui.statusbar.policy.BatteryController @@ -180,3 +182,17 @@ class PulseLowImportanceSuppressor() : VisualInterruptionFilter(types = setOf(PULSE), reason = "importance less than DEFAULT") { override fun shouldSuppress(entry: NotificationEntry) = entry.importance < IMPORTANCE_DEFAULT } + +class BubbleNotAllowedSuppressor() : + VisualInterruptionFilter(types = setOf(BUBBLE), reason = "not allowed") { + override fun shouldSuppress(entry: NotificationEntry) = !entry.canBubble() +} + +class BubbleNoMetadataSuppressor() : + VisualInterruptionFilter(types = setOf(BUBBLE), reason = "no bubble metadata") { + + private fun isValidMetadata(metadata: BubbleMetadata?) = + metadata != null && (metadata.intent != null || metadata.shortcutId != null) + + override fun shouldSuppress(entry: NotificationEntry) = !isValidMetadata(entry.bubbleMetadata) +} 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 7f144bf14615..b319a74c6292 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 @@ -65,6 +65,8 @@ constructor( addFilter(PulseEffectSuppressor()) addFilter(PulseLockscreenVisibilityPrivateSuppressor()) addFilter(PulseLowImportanceSuppressor()) + addFilter(BubbleNotAllowedSuppressor()) + addFilter(BubbleNoMetadataSuppressor()) started = true } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt index df1228965749..cedf1eac4d14 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/VisualInterruptionDecisionProviderTestBase.kt @@ -306,9 +306,27 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { } @Test - fun testShouldBubble() { + fun testShouldBubble_withIntentAndIcon() { ensureBubbleState() - assertShouldBubble(buildBubbleEntry()) + assertShouldBubble(buildBubbleEntry { bubbleIsShortcut = false }) + } + + @Test + fun testShouldBubble_withShortcut() { + ensureBubbleState() + assertShouldBubble(buildBubbleEntry { bubbleIsShortcut = true }) + } + + @Test + fun testShouldNotBubble_notAllowed() { + ensureBubbleState() + assertShouldNotBubble(buildBubbleEntry { canBubble = false }) + } + + @Test + fun testShouldNotBubble_noBubbleMetadata() { + ensureBubbleState() + assertShouldNotBubble(buildBubbleEntry { hasBubbleMetadata = false }) } @Test @@ -487,20 +505,29 @@ abstract class VisualInterruptionDecisionProviderTestBase : SysuiTestCase() { var canBubble: Boolean? = null var isBubble = false var hasBubbleMetadata = false - var bubbleSuppressNotification: Boolean? = null - - private fun buildBubbleMetadata() = - BubbleMetadata.Builder( - PendingIntent.getActivity( - context, - /* requestCode = */ 0, - Intent().setPackage(context.packageName), - FLAG_MUTABLE - ), - Icon.createWithResource(context.resources, R.drawable.android) - ) - .apply { bubbleSuppressNotification?.let { setSuppressNotification(it) } } - .build() + var bubbleIsShortcut = false + var bubbleSuppressesNotification: Boolean? = null + + private fun buildBubbleMetadata(): BubbleMetadata { + val builder = + if (bubbleIsShortcut) { + BubbleMetadata.Builder(context.packageName + ":test_shortcut_id") + } else { + BubbleMetadata.Builder( + PendingIntent.getActivity( + context, + /* requestCode = */ 0, + Intent().setPackage(context.packageName), + FLAG_MUTABLE + ), + Icon.createWithResource(context.resources, R.drawable.android) + ) + } + + bubbleSuppressesNotification?.let { builder.setSuppressNotification(it) } + + return builder.build() + } fun build() = Notification.Builder(context, TEST_CHANNEL_ID) |