From a9a94a185b2347dd0975a477b3cf8234bd7b1010 Mon Sep 17 00:00:00 2001 From: Beth Thibodeau Date: Thu, 12 Jan 2023 17:57:52 -0600 Subject: [PATCH] Check ongoing flag for media control dismissal To match NotificationEntry#isDismissible, use the ongoing flag instead to determine whether or not the control can be cleared. This enables media controls with only the NO_CLEAR flag to be dismissed manually, which matches notification behavior. Bug: 264179692 Test: atest MediaDataManagerTest Change-Id: I869cae5c53115fe6131071b23b21339696721972 --- .../controls/pipeline/MediaDataManager.kt | 2 +- .../controls/pipeline/MediaDataManagerTest.kt | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt index 2dd339d409a62..2c9e1fa0da70c 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt @@ -848,7 +848,7 @@ class MediaDataManager( notificationKey = key, hasCheckedForResume = hasCheckedForResume, isPlaying = isPlaying, - isClearable = sbn.isClearable(), + isClearable = !sbn.isOngoing, lastActive = lastActive, instanceId = instanceId, appUid = appUid diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataManagerTest.kt index 52b694fac07c8..9a29376bcc167 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDataManagerTest.kt @@ -17,6 +17,7 @@ package com.android.systemui.media.controls.pipeline import android.app.Notification +import android.app.Notification.FLAG_NO_CLEAR import android.app.Notification.MediaStyle import android.app.PendingIntent import android.app.smartspace.SmartspaceAction @@ -1349,6 +1350,39 @@ class MediaDataManagerTest : SysuiTestCase() { assertThat(mediaDataCaptor.value.semanticActions).isNull() } + @Test + fun testNoClearNotOngoing_canDismiss() { + mediaNotification = + SbnBuilder().run { + setPkg(PACKAGE_NAME) + modifyNotification(context).also { + it.setSmallIcon(android.R.drawable.ic_media_pause) + it.setStyle(MediaStyle().apply { setMediaSession(session.sessionToken) }) + it.setOngoing(false) + it.setFlag(FLAG_NO_CLEAR, true) + } + build() + } + addNotificationAndLoad() + assertThat(mediaDataCaptor.value.isClearable).isTrue() + } + + @Test + fun testOngoing_cannotDismiss() { + mediaNotification = + SbnBuilder().run { + setPkg(PACKAGE_NAME) + modifyNotification(context).also { + it.setSmallIcon(android.R.drawable.ic_media_pause) + it.setStyle(MediaStyle().apply { setMediaSession(session.sessionToken) }) + it.setOngoing(true) + } + build() + } + addNotificationAndLoad() + assertThat(mediaDataCaptor.value.isClearable).isFalse() + } + /** Helper function to add a media notification and capture the resulting MediaData */ private fun addNotificationAndLoad() { mediaDataManager.onNotificationAdded(KEY, mediaNotification)