Loading services/core/java/com/android/server/notification/NotificationComparator.java +18 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java +9 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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) Loading @@ -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) { Loading @@ -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) { Loading @@ -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)); Loading Loading
services/core/java/com/android/server/notification/NotificationComparator.java +18 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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); Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java +9 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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) Loading @@ -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) { Loading @@ -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) { Loading @@ -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)); Loading