Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RankingCoordinator.java +11 −13 Original line number Original line Diff line number Diff line Loading @@ -45,7 +45,8 @@ public class RankingCoordinator implements Coordinator { public void attach(NotifPipeline pipeline) { public void attach(NotifPipeline pipeline) { mStatusBarStateController.addCallback(mStatusBarStateCallback); mStatusBarStateController.addCallback(mStatusBarStateCallback); pipeline.addPreGroupFilter(mNotifFilter); pipeline.addPreGroupFilter(mSuspendedFilter); pipeline.addPreGroupFilter(mDozingFilter); } } /** /** Loading @@ -53,33 +54,30 @@ public class RankingCoordinator implements Coordinator { * NotifListBuilder invalidates the notification list each time the ranking is updated, * NotifListBuilder invalidates the notification list each time the ranking is updated, * so we don't need to explicitly invalidate this filter on ranking update. * so we don't need to explicitly invalidate this filter on ranking update. */ */ private final NotifFilter mNotifFilter = new NotifFilter(TAG) { private final NotifFilter mSuspendedFilter = new NotifFilter("IsSuspendedFilter") { @Override @Override public boolean shouldFilterOut(NotificationEntry entry, long now) { public boolean shouldFilterOut(NotificationEntry entry, long now) { // App suspended from Ranking return entry.getRanking().isSuspended(); if (entry.getRanking().isSuspended()) { return true; } } }; private final NotifFilter mDozingFilter = new NotifFilter("IsDozingFilter") { @Override public boolean shouldFilterOut(NotificationEntry entry, long now) { // Dozing + DND Settings from Ranking object // Dozing + DND Settings from Ranking object if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) { if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) { return true; return true; } } if (!mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList()) { return !mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList(); return true; } return false; } } }; }; private final StatusBarStateController.StateListener mStatusBarStateCallback = private final StatusBarStateController.StateListener mStatusBarStateCallback = new StatusBarStateController.StateListener() { new StatusBarStateController.StateListener() { @Override @Override public void onDozingChanged(boolean isDozing) { public void onDozingChanged(boolean isDozing) { mNotifFilter.invalidateList(); mDozingFilter.invalidateList(); } } }; }; } } packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RankingCoordinatorTest.java +19 −16 Original line number Original line Diff line number Diff line Loading @@ -19,9 +19,8 @@ package com.android.systemui.statusbar.notification.collection.coordinator; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; import static junit.framework.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.Mockito.when; Loading @@ -42,6 +41,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations; Loading @@ -51,20 +51,23 @@ public class RankingCoordinatorTest extends SysuiTestCase { @Mock private StatusBarStateController mStatusBarStateController; @Mock private StatusBarStateController mStatusBarStateController; @Mock private NotifPipeline mNotifPipeline; @Mock private NotifPipeline mNotifPipeline; @Captor private ArgumentCaptor<NotifFilter> mNotifFilterCaptor; private NotificationEntry mEntry; private NotificationEntry mEntry; private RankingCoordinator mRankingCoordinator; private NotifFilter mCapturedSuspendedFilter; private NotifFilter mRankingFilter; private NotifFilter mCapturedDozingFilter; @Before @Before public void setup() { public void setup() { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); mRankingCoordinator = new RankingCoordinator(mStatusBarStateController); RankingCoordinator rankingCoordinator = new RankingCoordinator(mStatusBarStateController); mEntry = new NotificationEntryBuilder().build(); mEntry = new NotificationEntryBuilder().build(); ArgumentCaptor<NotifFilter> filterCaptor = ArgumentCaptor.forClass(NotifFilter.class); rankingCoordinator.attach(mNotifPipeline); mRankingCoordinator.attach(mNotifPipeline); verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture()); verify(mNotifPipeline, times(1)).addPreGroupFilter(filterCaptor.capture()); mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0); mRankingFilter = filterCaptor.getValue(); mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1); } } @Test @Test Loading @@ -73,7 +76,7 @@ public class RankingCoordinatorTest extends SysuiTestCase { mEntry.setRanking(getRankingForUnfilteredNotif().build()); mEntry.setRanking(getRankingForUnfilteredNotif().build()); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -84,7 +87,7 @@ public class RankingCoordinatorTest extends SysuiTestCase { .build()); .build()); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -98,13 +101,13 @@ public class RankingCoordinatorTest extends SysuiTestCase { when(mStatusBarStateController.isDozing()).thenReturn(true); when(mStatusBarStateController.isDozing()).thenReturn(true); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); // WHEN it's not dozing (showing the notification list) // WHEN it's not dozing (showing the notification list) when(mStatusBarStateController.isDozing()).thenReturn(false); when(mStatusBarStateController.isDozing()).thenReturn(false); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -118,13 +121,13 @@ public class RankingCoordinatorTest extends SysuiTestCase { when(mStatusBarStateController.isDozing()).thenReturn(true); when(mStatusBarStateController.isDozing()).thenReturn(true); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); // WHEN it's not dozing (showing the notification list) // WHEN it's not dozing (showing the notification list) when(mStatusBarStateController.isDozing()).thenReturn(false); when(mStatusBarStateController.isDozing()).thenReturn(false); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); } } private RankingBuilder getRankingForUnfilteredNotif() { private RankingBuilder getRankingForUnfilteredNotif() { Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/RankingCoordinator.java +11 −13 Original line number Original line Diff line number Diff line Loading @@ -45,7 +45,8 @@ public class RankingCoordinator implements Coordinator { public void attach(NotifPipeline pipeline) { public void attach(NotifPipeline pipeline) { mStatusBarStateController.addCallback(mStatusBarStateCallback); mStatusBarStateController.addCallback(mStatusBarStateCallback); pipeline.addPreGroupFilter(mNotifFilter); pipeline.addPreGroupFilter(mSuspendedFilter); pipeline.addPreGroupFilter(mDozingFilter); } } /** /** Loading @@ -53,33 +54,30 @@ public class RankingCoordinator implements Coordinator { * NotifListBuilder invalidates the notification list each time the ranking is updated, * NotifListBuilder invalidates the notification list each time the ranking is updated, * so we don't need to explicitly invalidate this filter on ranking update. * so we don't need to explicitly invalidate this filter on ranking update. */ */ private final NotifFilter mNotifFilter = new NotifFilter(TAG) { private final NotifFilter mSuspendedFilter = new NotifFilter("IsSuspendedFilter") { @Override @Override public boolean shouldFilterOut(NotificationEntry entry, long now) { public boolean shouldFilterOut(NotificationEntry entry, long now) { // App suspended from Ranking return entry.getRanking().isSuspended(); if (entry.getRanking().isSuspended()) { return true; } } }; private final NotifFilter mDozingFilter = new NotifFilter("IsDozingFilter") { @Override public boolean shouldFilterOut(NotificationEntry entry, long now) { // Dozing + DND Settings from Ranking object // Dozing + DND Settings from Ranking object if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) { if (mStatusBarStateController.isDozing() && entry.shouldSuppressAmbient()) { return true; return true; } } if (!mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList()) { return !mStatusBarStateController.isDozing() && entry.shouldSuppressNotificationList(); return true; } return false; } } }; }; private final StatusBarStateController.StateListener mStatusBarStateCallback = private final StatusBarStateController.StateListener mStatusBarStateCallback = new StatusBarStateController.StateListener() { new StatusBarStateController.StateListener() { @Override @Override public void onDozingChanged(boolean isDozing) { public void onDozingChanged(boolean isDozing) { mNotifFilter.invalidateList(); mDozingFilter.invalidateList(); } } }; }; } }
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/RankingCoordinatorTest.java +19 −16 Original line number Original line Diff line number Diff line Loading @@ -19,9 +19,8 @@ package com.android.systemui.statusbar.notification.collection.coordinator; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; import static junit.framework.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.Mockito.when; Loading @@ -42,6 +41,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations; Loading @@ -51,20 +51,23 @@ public class RankingCoordinatorTest extends SysuiTestCase { @Mock private StatusBarStateController mStatusBarStateController; @Mock private StatusBarStateController mStatusBarStateController; @Mock private NotifPipeline mNotifPipeline; @Mock private NotifPipeline mNotifPipeline; @Captor private ArgumentCaptor<NotifFilter> mNotifFilterCaptor; private NotificationEntry mEntry; private NotificationEntry mEntry; private RankingCoordinator mRankingCoordinator; private NotifFilter mCapturedSuspendedFilter; private NotifFilter mRankingFilter; private NotifFilter mCapturedDozingFilter; @Before @Before public void setup() { public void setup() { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); mRankingCoordinator = new RankingCoordinator(mStatusBarStateController); RankingCoordinator rankingCoordinator = new RankingCoordinator(mStatusBarStateController); mEntry = new NotificationEntryBuilder().build(); mEntry = new NotificationEntryBuilder().build(); ArgumentCaptor<NotifFilter> filterCaptor = ArgumentCaptor.forClass(NotifFilter.class); rankingCoordinator.attach(mNotifPipeline); mRankingCoordinator.attach(mNotifPipeline); verify(mNotifPipeline, times(2)).addPreGroupFilter(mNotifFilterCaptor.capture()); verify(mNotifPipeline, times(1)).addPreGroupFilter(filterCaptor.capture()); mCapturedSuspendedFilter = mNotifFilterCaptor.getAllValues().get(0); mRankingFilter = filterCaptor.getValue(); mCapturedDozingFilter = mNotifFilterCaptor.getAllValues().get(1); } } @Test @Test Loading @@ -73,7 +76,7 @@ public class RankingCoordinatorTest extends SysuiTestCase { mEntry.setRanking(getRankingForUnfilteredNotif().build()); mEntry.setRanking(getRankingForUnfilteredNotif().build()); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -84,7 +87,7 @@ public class RankingCoordinatorTest extends SysuiTestCase { .build()); .build()); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedSuspendedFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -98,13 +101,13 @@ public class RankingCoordinatorTest extends SysuiTestCase { when(mStatusBarStateController.isDozing()).thenReturn(true); when(mStatusBarStateController.isDozing()).thenReturn(true); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); // WHEN it's not dozing (showing the notification list) // WHEN it's not dozing (showing the notification list) when(mStatusBarStateController.isDozing()).thenReturn(false); when(mStatusBarStateController.isDozing()).thenReturn(false); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); } } @Test @Test Loading @@ -118,13 +121,13 @@ public class RankingCoordinatorTest extends SysuiTestCase { when(mStatusBarStateController.isDozing()).thenReturn(true); when(mStatusBarStateController.isDozing()).thenReturn(true); // THEN don't filter out the notification // THEN don't filter out the notification assertFalse(mRankingFilter.shouldFilterOut(mEntry, 0)); assertFalse(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); // WHEN it's not dozing (showing the notification list) // WHEN it's not dozing (showing the notification list) when(mStatusBarStateController.isDozing()).thenReturn(false); when(mStatusBarStateController.isDozing()).thenReturn(false); // THEN filter out the notification // THEN filter out the notification assertTrue(mRankingFilter.shouldFilterOut(mEntry, 0)); assertTrue(mCapturedDozingFilter.shouldFilterOut(mEntry, 0)); } } private RankingBuilder getRankingForUnfilteredNotif() { private RankingBuilder getRankingForUnfilteredNotif() { Loading