Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationData.java +8 −1 Original line number Diff line number Diff line Loading @@ -422,8 +422,15 @@ public class NotificationData { } } if (mSortedAndFiltered.size() == 1) { // HACK: We need the comparator to run on all children in order to set the // isHighPriority field. If there is only one child, then the comparison won't be run, // so we have to trigger it manually. Get rid of this code as soon as possible. mRankingComparator.compare(mSortedAndFiltered.get(0), mSortedAndFiltered.get(0)); } else { Collections.sort(mSortedAndFiltered, mRankingComparator); } } public void dump(PrintWriter pw, String indent) { int filteredLen = mSortedAndFiltered.size(); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java +64 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.app.Notification.CATEGORY_CALL; import static android.app.Notification.CATEGORY_EVENT; import static android.app.Notification.CATEGORY_MESSAGE; import static android.app.Notification.CATEGORY_REMINDER; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_MIN; Loading Loading @@ -62,6 +63,8 @@ import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.util.ArraySet; import androidx.test.filters.SmallTest; import com.android.systemui.Dependency; import com.android.systemui.ForegroundServiceController; import com.android.systemui.InitController; Loading @@ -84,8 +87,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import androidx.test.filters.SmallTest; @SmallTest @RunWith(AndroidTestingRunner.class) @RunWithLooper Loading Loading @@ -113,6 +114,7 @@ public class NotificationDataTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL); when(mMockStatusBarNotification.cloneLight()).thenReturn(mMockStatusBarNotification); when(mMockStatusBarNotification.getKey()).thenReturn("mock_key"); when(mMockPackageManager.checkUidPermission( eq(Manifest.permission.NOTIFICATION_DURING_SETUP), Loading Loading @@ -231,6 +233,7 @@ public class NotificationDataTest extends SysuiTestCase { Notification n = mMockStatusBarNotification.getNotification(); n.flags = Notification.FLAG_FOREGROUND_SERVICE; NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); mNotificationData.add(entry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); Loading @@ -249,6 +252,7 @@ public class NotificationDataTest extends SysuiTestCase { n = nb.build(); when(mMockStatusBarNotification.getNotification()).thenReturn(n); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); mNotificationData.add(entry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); Loading @@ -262,6 +266,7 @@ public class NotificationDataTest extends SysuiTestCase { public void testIsExemptFromDndVisualSuppression_system() { initStatusBarNotification(false); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); entry.mIsSystemNotification = true; mNotificationData.add(entry); Bundle override = new Bundle(); Loading @@ -276,6 +281,7 @@ public class NotificationDataTest extends SysuiTestCase { public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() { initStatusBarNotification(false); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); entry.mIsSystemNotification = true; Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT); Loading Loading @@ -528,6 +534,62 @@ public class NotificationDataTest extends SysuiTestCase { assertEquals(-1, mNotificationData.mRankingComparator.compare(a, b)); } @Test public void testSort_properlySetsIsTopBucket() { Notification notification = new Notification.Builder(mContext, "test") .build(); StatusBarNotification sbn = new StatusBarNotification( "pkg", "pkg", 0, "tag", 0, 0, notification, mContext.getUser(), "", 0); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_DEFAULT); mNotificationData.rankingOverrides.put(sbn.getKey(), override); NotificationEntry entry = new NotificationEntry(sbn); entry.setRow(mRow); mNotificationData.add(entry); assertTrue(entry.isTopBucket()); } @Test public void testSort_properlySetsIsNotTopBucket() { Notification notification = new Notification.Builder(mContext, "test") .build(); StatusBarNotification sbn = new StatusBarNotification( "pkg", "pkg", 0, "tag", 0, 0, notification, mContext.getUser(), "", 0); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); mNotificationData.rankingOverrides.put(sbn.getKey(), override); NotificationEntry entry = new NotificationEntry(sbn); entry.setRow(mRow); mNotificationData.add(entry); assertFalse(entry.isTopBucket()); } private void initStatusBarNotification(boolean allowDuringSetup) { Bundle bundle = new Bundle(); bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup); Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationData.java +8 −1 Original line number Diff line number Diff line Loading @@ -422,8 +422,15 @@ public class NotificationData { } } if (mSortedAndFiltered.size() == 1) { // HACK: We need the comparator to run on all children in order to set the // isHighPriority field. If there is only one child, then the comparison won't be run, // so we have to trigger it manually. Get rid of this code as soon as possible. mRankingComparator.compare(mSortedAndFiltered.get(0), mSortedAndFiltered.get(0)); } else { Collections.sort(mSortedAndFiltered, mRankingComparator); } } public void dump(PrintWriter pw, String indent) { int filteredLen = mSortedAndFiltered.size(); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java +64 −2 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.app.Notification.CATEGORY_CALL; import static android.app.Notification.CATEGORY_EVENT; import static android.app.Notification.CATEGORY_MESSAGE; import static android.app.Notification.CATEGORY_REMINDER; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_MIN; Loading Loading @@ -62,6 +63,8 @@ import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; import android.util.ArraySet; import androidx.test.filters.SmallTest; import com.android.systemui.Dependency; import com.android.systemui.ForegroundServiceController; import com.android.systemui.InitController; Loading @@ -84,8 +87,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import androidx.test.filters.SmallTest; @SmallTest @RunWith(AndroidTestingRunner.class) @RunWithLooper Loading Loading @@ -113,6 +114,7 @@ public class NotificationDataTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL); when(mMockStatusBarNotification.cloneLight()).thenReturn(mMockStatusBarNotification); when(mMockStatusBarNotification.getKey()).thenReturn("mock_key"); when(mMockPackageManager.checkUidPermission( eq(Manifest.permission.NOTIFICATION_DURING_SETUP), Loading Loading @@ -231,6 +233,7 @@ public class NotificationDataTest extends SysuiTestCase { Notification n = mMockStatusBarNotification.getNotification(); n.flags = Notification.FLAG_FOREGROUND_SERVICE; NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); mNotificationData.add(entry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); Loading @@ -249,6 +252,7 @@ public class NotificationDataTest extends SysuiTestCase { n = nb.build(); when(mMockStatusBarNotification.getNotification()).thenReturn(n); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); mNotificationData.add(entry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); Loading @@ -262,6 +266,7 @@ public class NotificationDataTest extends SysuiTestCase { public void testIsExemptFromDndVisualSuppression_system() { initStatusBarNotification(false); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); entry.mIsSystemNotification = true; mNotificationData.add(entry); Bundle override = new Bundle(); Loading @@ -276,6 +281,7 @@ public class NotificationDataTest extends SysuiTestCase { public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() { initStatusBarNotification(false); NotificationEntry entry = new NotificationEntry(mMockStatusBarNotification); entry.setRow(mRow); entry.mIsSystemNotification = true; Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT); Loading Loading @@ -528,6 +534,62 @@ public class NotificationDataTest extends SysuiTestCase { assertEquals(-1, mNotificationData.mRankingComparator.compare(a, b)); } @Test public void testSort_properlySetsIsTopBucket() { Notification notification = new Notification.Builder(mContext, "test") .build(); StatusBarNotification sbn = new StatusBarNotification( "pkg", "pkg", 0, "tag", 0, 0, notification, mContext.getUser(), "", 0); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_DEFAULT); mNotificationData.rankingOverrides.put(sbn.getKey(), override); NotificationEntry entry = new NotificationEntry(sbn); entry.setRow(mRow); mNotificationData.add(entry); assertTrue(entry.isTopBucket()); } @Test public void testSort_properlySetsIsNotTopBucket() { Notification notification = new Notification.Builder(mContext, "test") .build(); StatusBarNotification sbn = new StatusBarNotification( "pkg", "pkg", 0, "tag", 0, 0, notification, mContext.getUser(), "", 0); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); mNotificationData.rankingOverrides.put(sbn.getKey(), override); NotificationEntry entry = new NotificationEntry(sbn); entry.setRow(mRow); mNotificationData.add(entry); assertFalse(entry.isTopBucket()); } private void initStatusBarNotification(boolean allowDuringSetup) { Bundle bundle = new Bundle(); bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup); Loading