diff options
| author | 2018-12-03 15:49:06 -0500 | |
|---|---|---|
| committer | 2018-12-05 10:54:51 -0500 | |
| commit | 2c963d258d6240687d4225b1682da633b07a73ce (patch) | |
| tree | d33524fe9b2f492fb09d3c0ceeadac00f196b9d0 | |
| parent | afafd66da28a3bf48ce63df5c8309600572ea2cc (diff) | |
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
2 files changed, 27 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationComparator.java b/services/core/java/com/android/server/notification/NotificationComparator.java index 2584187fffe6..9b9f4de7a18f 100644 --- a/services/core/java/com/android/server/notification/NotificationComparator.java +++ b/services/core/java/com/android/server/notification/NotificationComparator.java @@ -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); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java index b30bb4b37c12..068129569d14 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java @@ -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)); |