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

Commit 2c963d25 authored by Gus Prevas's avatar Gus Prevas
Browse files

Changes notification ordering for new interruption model.

This change modifies NotificationComparator such that when the new
interruption model is enabled, notifications are sorted with the
primary criterion being whether they are importance >= DEFAULT,
outweighing other criteria that are currently considered first
(colorization, ongoingness, messaging, people).  This allows us
to ensure that high priority (>= DEFAULT) and low priority
(< DEFAULT) notifications are contiguous so that thedisplay of them
as two distinct groups makes sense.

Test: atest NotificationComparatorTest
Change-Id: Ifa1405546b75b9da4b8411f861675cd47793785c
parent afafd66d
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -15,12 +15,15 @@
 */
package com.android.server.notification;

import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.provider.Settings;
import android.telecom.TelecomManager;

import com.android.internal.util.NotificationMessagingUtil;
@@ -47,6 +50,21 @@ public class NotificationComparator

    @Override
    public int compare(NotificationRecord left, NotificationRecord right) {
        final int leftImportance = left.getImportance();
        final int rightImportance = right.getImportance();
        final boolean isLeftHighImportance = leftImportance >= IMPORTANCE_DEFAULT;
        final boolean isRightHighImportance = rightImportance >= IMPORTANCE_DEFAULT;

        // With new interruption model, prefer importance bucket above all other criteria
        // (to ensure buckets are contiguous)
        if (Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) == 1) {
            if (isLeftHighImportance != isRightHighImportance) {
                // by importance bucket, high importance higher than low importance
                return -1 * Boolean.compare(isLeftHighImportance, isRightHighImportance);
            }
        }

        // first all colorized notifications
        boolean leftImportantColorized = isImportantColorized(left);
        boolean rightImportantColorized = isImportantColorized(right);
@@ -86,8 +104,6 @@ public class NotificationComparator
            return -1 * Boolean.compare(leftPeople, rightPeople);
        }

        final int leftImportance = left.getImportance();
        final int rightImportance = right.getImportance();
        if (leftImportance != rightImportance) {
            // by importance, high to low
            return -1 * Integer.compare(leftImportance, rightImportance);
+9 −8
Original line number Diff line number Diff line
@@ -15,8 +15,9 @@
 */
package com.android.server.notification;

import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -34,8 +35,8 @@ import android.os.Build;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.telecom.TelecomManager;
import android.support.test.runner.AndroidJUnit4;
import android.telecom.TelecomManager;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.server.UiServiceTestCase;
@@ -211,7 +212,7 @@ public class NotificationComparatorTest extends UiServiceTestCase {
        mRecordColorized = new NotificationRecord(mContext, new StatusBarNotification(pkg2,
                pkg2, 1, "colorized", uid2, uid2, n13,
                new UserHandle(userId), "", 1999), getDefaultChannel());
        mRecordHighCall.setSystemImportance(NotificationManager.IMPORTANCE_HIGH);
        mRecordColorized.setSystemImportance(NotificationManager.IMPORTANCE_HIGH);

        Notification n14 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                .setCategory(Notification.CATEGORY_CALL)
@@ -225,11 +226,11 @@ public class NotificationComparatorTest extends UiServiceTestCase {
    }

    @Test
    public void testOrdering() throws Exception {
    public void testOrdering() {
        final List<NotificationRecord> expected = new ArrayList<>();
        expected.add(mRecordColorizedCall);
        expected.add(mRecordDefaultMedia);
        expected.add(mRecordColorized);
        expected.add(mRecordDefaultMedia);
        expected.add(mRecordHighCall);
        expected.add(mRecordInlineReply);
        if (mRecordSms != null) {
@@ -250,11 +251,11 @@ public class NotificationComparatorTest extends UiServiceTestCase {

        Collections.sort(actual, new NotificationComparator(mContext));

        assertEquals(expected, actual);
        assertThat(actual, contains(expected.toArray()));
    }

    @Test
    public void testMessaging() throws Exception {
    public void testMessaging() {
        NotificationComparator comp = new NotificationComparator(mContext);
        assertTrue(comp.isImportantMessaging(mRecordInlineReply));
        if (mRecordSms != null) {
@@ -265,7 +266,7 @@ public class NotificationComparatorTest extends UiServiceTestCase {
    }

    @Test
    public void testPeople() throws Exception {
    public void testPeople() {
        NotificationComparator comp = new NotificationComparator(mContext);
        assertTrue(comp.isImportantPeople(mRecordStarredContact));
        assertTrue(comp.isImportantPeople(mRecordContact));