Loading services/core/java/com/android/server/notification/RankingHelper.java +1 −3 Original line number Original line Diff line number Diff line Loading @@ -106,9 +106,7 @@ public class RankingHelper { synchronized (mProxyByGroupTmp) { synchronized (mProxyByGroupTmp) { // record individual ranking result and nominate proxies for each group // 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 for (int i = 0; i < N; i++) { // in a string compare below for (int i = N - 1; i >= 0; i--) { final NotificationRecord record = notificationList.get(i); final NotificationRecord record = notificationList.get(i); record.setAuthoritativeRank(i); record.setAuthoritativeRank(i); final String groupKey = record.getGroupKey(); final String groupKey = record.getGroupKey(); Loading services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +50 −6 Original line number Original line Diff line number Diff line Loading @@ -15,8 +15,11 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_LOW; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt; Loading Loading @@ -153,7 +156,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification( mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user, PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("B") .setContentTitle("B") Loading @@ -163,7 +166,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification( mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user, PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("C") .setContentTitle("C") Loading @@ -171,7 +174,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("D") .setContentTitle("D") Loading @@ -179,7 +182,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("E") .setContentTitle("E") Loading @@ -188,7 +191,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mAudioAttributes = new AudioAttributes.Builder() mAudioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) Loading @@ -197,11 +200,16 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); } } private NotificationChannel getDefaultChannel() { private NotificationChannel getLowChannel() { return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", IMPORTANCE_LOW); IMPORTANCE_LOW); } } private NotificationChannel getDefaultChannel() { return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", IMPORTANCE_DEFAULT); } @Test @Test public void testSortShouldRespectCritical() throws Exception { public void testSortShouldRespectCritical() throws Exception { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(7); ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(7); Loading Loading @@ -285,4 +293,40 @@ public class RankingHelperTest extends UiServiceTestCase { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(); ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(); mHelper.sort(notificationList); 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)); } } } Loading
services/core/java/com/android/server/notification/RankingHelper.java +1 −3 Original line number Original line Diff line number Diff line Loading @@ -106,9 +106,7 @@ public class RankingHelper { synchronized (mProxyByGroupTmp) { synchronized (mProxyByGroupTmp) { // record individual ranking result and nominate proxies for each group // 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 for (int i = 0; i < N; i++) { // in a string compare below for (int i = N - 1; i >= 0; i--) { final NotificationRecord record = notificationList.get(i); final NotificationRecord record = notificationList.get(i); record.setAuthoritativeRank(i); record.setAuthoritativeRank(i); final String groupKey = record.getGroupKey(); final String groupKey = record.getGroupKey(); Loading
services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +50 −6 Original line number Original line Diff line number Diff line Loading @@ -15,8 +15,11 @@ */ */ package com.android.server.notification; package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_LOW; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyInt; Loading Loading @@ -153,7 +156,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification( mRecordGroupGSortA = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user, PKG, PKG, 1, null, 0, 0, mNotiGroupGSortA, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiGroupGSortB = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("B") .setContentTitle("B") Loading @@ -163,7 +166,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification( mRecordGroupGSortB = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user, PKG, PKG, 1, null, 0, 0, mNotiGroupGSortB, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroup = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("C") .setContentTitle("C") Loading @@ -171,7 +174,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroup = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroup, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroup2 = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("D") .setContentTitle("D") Loading @@ -179,7 +182,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroup2 = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroup2, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) mNotiNoGroupSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("E") .setContentTitle("E") Loading @@ -188,7 +191,7 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification( mRecordNoGroupSortA = new NotificationRecord(mContext, new StatusBarNotification( PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user, PKG, PKG, 1, null, 0, 0, mNotiNoGroupSortA, user, null, System.currentTimeMillis()), getDefaultChannel()); null, System.currentTimeMillis()), getLowChannel()); mAudioAttributes = new AudioAttributes.Builder() mAudioAttributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) .setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN) Loading @@ -197,11 +200,16 @@ public class RankingHelperTest extends UiServiceTestCase { .build(); .build(); } } private NotificationChannel getDefaultChannel() { private NotificationChannel getLowChannel() { return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", IMPORTANCE_LOW); IMPORTANCE_LOW); } } private NotificationChannel getDefaultChannel() { return new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name", IMPORTANCE_DEFAULT); } @Test @Test public void testSortShouldRespectCritical() throws Exception { public void testSortShouldRespectCritical() throws Exception { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(7); ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(7); Loading Loading @@ -285,4 +293,40 @@ public class RankingHelperTest extends UiServiceTestCase { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(); ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(); mHelper.sort(notificationList); 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)); } } }