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

Commit d5ba5e42 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Changes notification ordering for new interruption model."

parents efd355c1 2c963d25
Loading
Loading
Loading
Loading
+18 −2
Original line number Original line Diff line number Diff line
@@ -15,12 +15,15 @@
 */
 */
package com.android.server.notification;
package com.android.server.notification;


import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

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


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


    @Override
    @Override
    public int compare(NotificationRecord left, NotificationRecord right) {
    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
        // first all colorized notifications
        boolean leftImportantColorized = isImportantColorized(left);
        boolean leftImportantColorized = isImportantColorized(left);
        boolean rightImportantColorized = isImportantColorized(right);
        boolean rightImportantColorized = isImportantColorized(right);
@@ -86,8 +104,6 @@ public class NotificationComparator
            return -1 * Boolean.compare(leftPeople, rightPeople);
            return -1 * Boolean.compare(leftPeople, rightPeople);
        }
        }


        final int leftImportance = left.getImportance();
        final int rightImportance = right.getImportance();
        if (leftImportance != rightImportance) {
        if (leftImportance != rightImportance) {
            // by importance, high to low
            // by importance, high to low
            return -1 * Integer.compare(leftImportance, rightImportance);
            return -1 * Integer.compare(leftImportance, rightImportance);
+9 −8
Original line number Original line Diff line number Diff line
@@ -15,8 +15,9 @@
 */
 */
package com.android.server.notification;
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.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.anyString;
@@ -34,8 +35,8 @@ import android.os.Build;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.service.notification.StatusBarNotification;
import android.telecom.TelecomManager;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.runner.AndroidJUnit4;
import android.telecom.TelecomManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


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


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


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


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


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


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


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