From c69933ac6003f1db05d57bf8001a8b3c560879f8 Mon Sep 17 00:00:00 2001 From: Jay Aliomer Date: Wed, 22 Jun 2022 20:53:23 +0000 Subject: [PATCH] Cache Blockable state of Notif. Entry Bug: 235128948 Bug: 235578225 Test: NotificationEntryTest Change-Id: I31249bafacabec2eaae06121c80b90c3089bcd07 --- .../collection/NotificationEntry.java | 18 ++++++++++++++---- .../collection/NotificationEntryTest.java | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index aedbd1b566222..0a16fb65b1ac3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -175,6 +175,10 @@ public final class NotificationEntry extends ListEntry { public boolean mRemoteEditImeAnimatingAway; public boolean mRemoteEditImeVisible; private boolean mExpandAnimationRunning; + /** + * Flag to determine if the entry is blockable by DnD filters + */ + private boolean mBlockable; /** * @param sbn the StatusBarNotification from system server @@ -253,6 +257,7 @@ public final class NotificationEntry extends ListEntry { } mRanking = ranking.withAudiblyAlertedInfo(mRanking); + updateIsBlockable(); } /* @@ -781,15 +786,20 @@ public final class NotificationEntry extends ListEntry { * or is not in an allowList). */ public boolean isBlockable() { + return mBlockable; + } + + private void updateIsBlockable() { if (getChannel() == null) { - return false; + mBlockable = false; + return; } if (getChannel().isImportanceLockedByCriticalDeviceFunction() && !getChannel().isBlockable()) { - return false; + mBlockable = false; + return; } - - return true; + mBlockable = true; } private boolean shouldSuppressVisualEffect(int effect) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationEntryTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationEntryTest.java index 769143ddbc0de..d4add7547656b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationEntryTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationEntryTest.java @@ -108,6 +108,7 @@ public class NotificationEntryTest extends SysuiTestCase { @Test public void testBlockableEntryWhenCritical() { doReturn(true).when(mChannel).isBlockable(); + mEntry.setRanking(mEntry.getRanking()); assertTrue(mEntry.isBlockable()); } @@ -117,6 +118,7 @@ public class NotificationEntryTest extends SysuiTestCase { public void testBlockableEntryWhenCriticalAndChannelNotBlockable() { doReturn(true).when(mChannel).isBlockable(); doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction(); + mEntry.setRanking(mEntry.getRanking()); assertTrue(mEntry.isBlockable()); } @@ -125,6 +127,7 @@ public class NotificationEntryTest extends SysuiTestCase { public void testNonBlockableEntryWhenCriticalAndChannelNotBlockable() { doReturn(false).when(mChannel).isBlockable(); doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction(); + mEntry.setRanking(mEntry.getRanking()); assertFalse(mEntry.isBlockable()); } @@ -164,6 +167,9 @@ public class NotificationEntryTest extends SysuiTestCase { doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction(); doReturn(false).when(mChannel).isBlockable(); + mEntry.setRanking(mEntry.getRanking()); + + assertFalse(mEntry.isBlockable()); assertTrue(mEntry.isExemptFromDndVisualSuppression()); assertFalse(mEntry.shouldSuppressAmbient()); }