Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b460f1f5 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Rank group with highest member

Since it's likely that the summary and children
won't agree on ranking position.

Test: atest
Change-Id: Ib4e990c6f0b8af1d2826ee90ce85ab759c4256bf
Fixes: 120639321
parent 559e3426
Loading
Loading
Loading
Loading
+1 −3
Original line number Original line Diff line number Diff line
@@ -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();
+50 −6
Original line number Original line Diff line number Diff line
@@ -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;
@@ -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")
@@ -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")
@@ -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")
@@ -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")
@@ -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)
@@ -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);
@@ -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));
    }
}
}