summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/notification/RankingHelper.java4
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java56
2 files changed, 51 insertions, 9 deletions
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index b1e914442871..b145e1eee3a3 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -106,9 +106,7 @@ public class RankingHelper {
synchronized (mProxyByGroupTmp) {
// record individual ranking result and nominate proxies for each group
- // Note: iteration is done backwards such that the index can be used as a sort key
- // in a string compare below
- for (int i = N - 1; i >= 0; i--) {
+ for (int i = 0; i < N; i++) {
final NotificationRecord record = notificationList.get(i);
record.setAuthoritativeRank(i);
final String groupKey = record.getGroupKey();
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java
index 5638cb360c78..c79e1db0a745 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java
@@ -15,8 +15,11 @@
*/
package com.android.server.notification;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static junit.framework.TestCase.assertEquals;
+
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyInt;
@@ -153,7 +156,7 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification(
PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user,
- null, System.currentTimeMillis()), getDefaultChannel());
+ null, System.currentTimeMillis()), getLowChannel());
mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID)
.setContentTitle("B")
@@ -163,7 +166,7 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification(
PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user,
- null, System.currentTimeMillis()), getDefaultChannel());
+ null, System.currentTimeMillis()), getLowChannel());
mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID)
.setContentTitle("C")
@@ -171,7 +174,7 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification(
PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user,
- null, System.currentTimeMillis()), getDefaultChannel());
+ null, System.currentTimeMillis()), getLowChannel());
mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
.setContentTitle("D")
@@ -179,7 +182,7 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification(
PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user,
- null, System.currentTimeMillis()), getDefaultChannel());
+ null, System.currentTimeMillis()), getLowChannel());
mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID)
.setContentTitle("E")
@@ -188,7 +191,7 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification(
PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user,
- null, System.currentTimeMillis()), getDefaultChannel());
+ null, System.currentTimeMillis()), getLowChannel());
mAudioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
@@ -197,11 +200,16 @@ public class RankingHelperTest extends UiServiceTestCase {
.build();
}
- private NotificationChannel getDefaultChannel() {
+ private NotificationChannel getLowChannel() {
return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name",
IMPORTANCE_LOW);
}
+ private NotificationChannel getDefaultChannel() {
+ return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name",
+ IMPORTANCE_DEFAULT);
+ }
+
@Test
public void testSortShouldRespectCritical() throws Exception {
ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(7);
@@ -285,4 +293,40 @@ public class RankingHelperTest extends UiServiceTestCase {
ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>();
mHelper.sort(notificationList);
}
+
+ @Test
+ public void testGroupNotifications_highestIsProxy() {
+ ArrayList<NotificationRecord> notificationList = new ArrayList<>();
+ // this should be the last in the list, except it's in a group with a high child
+ Notification lowSummaryN = new Notification.Builder(mContext, "")
+ .setGroup("group")
+ .setGroupSummary(true)
+ .build();
+ NotificationRecord lowSummary = new NotificationRecord(mContext, new StatusBarNotification(
+ PKG, PKG, 1, "summary", 0, 0, lowSummaryN, USER,
+ null, System.currentTimeMillis()), getLowChannel());
+ notificationList.add(lowSummary);
+
+ Notification lowN = new Notification.Builder(mContext, "").build();
+ NotificationRecord low = new NotificationRecord(mContext, new StatusBarNotification(
+ PKG, PKG, 1, "low", 0, 0, lowN, USER,
+ null, System.currentTimeMillis()), getLowChannel());
+ low.setContactAffinity(0.5f);
+ notificationList.add(low);
+
+ Notification highChildN = new Notification.Builder(mContext, "")
+ .setGroup("group")
+ .setGroupSummary(false)
+ .build();
+ NotificationRecord highChild = new NotificationRecord(mContext, new StatusBarNotification(
+ PKG, PKG, 1, "child", 0, 0, highChildN, USER,
+ null, System.currentTimeMillis()), getDefaultChannel());
+ notificationList.add(highChild);
+
+ mHelper.sort(notificationList);
+
+ assertEquals(lowSummary, notificationList.get(0));
+ assertEquals(highChild, notificationList.get(1));
+ assertEquals(low, notificationList.get(2));
+ }
}