Loading services/core/java/com/android/server/notification/RankingHelper.java +2 −4 Original line number Diff line number Diff line Loading @@ -25,22 +25,18 @@ import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ParceledListSlice; import android.content.pm.Signature; import android.metrics.LogMaker; import android.os.Build; import android.os.UserHandle; import android.print.PrintManager; import android.provider.Settings.Secure; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.RankingHelperProto; import android.service.notification.RankingHelperProto.RecordProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.proto.ProtoOutputStream; Loading Loading @@ -156,6 +152,8 @@ public class RankingHelper implements RankingConfig { } } mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1; updateChannelsBypassingDnd(); } Loading services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +58 −7 Original line number Diff line number Diff line Loading @@ -33,8 +33,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -115,7 +117,9 @@ public class RankingHelperTest extends UiServiceTestCase { @Mock PackageManager mPm; @Mock IContentProvider mTestIContentProvider; @Mock Context mContext; @Mock ZenModeHelper mMockZenModeHelper; private NotificationManager.Policy mTestNotificationPolicy; private Notification mNotiGroupGSortA; private Notification mNotiGroupGSortB; private Notification mNotiNoGroup; Loading Loading @@ -172,12 +176,12 @@ public class RankingHelperTest extends UiServiceTestCase { when(mTestIContentProvider.uncanonicalize(any(), eq(CANONICAL_SOUND_URI))) .thenReturn(SOUND_URI); ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); mHelper = new RankingHelper(getContext(), mPm, mHandler, mockZenModeHelper, mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); when(mockZenModeHelper.getNotificationPolicy()).thenReturn(new NotificationManager.Policy( 0, 0, 0)); resetZenModeHelper(); mNotiGroupGSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("A") Loading Loading @@ -299,6 +303,11 @@ public class RankingHelperTest extends UiServiceTestCase { return null; } private void resetZenModeHelper() { reset(mMockZenModeHelper); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); } @Test public void testFindAfterRankingWithASplitGroup() throws Exception { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(3); Loading Loading @@ -1136,9 +1145,12 @@ public class RankingHelperTest extends UiServiceTestCase { public void testCreateAndDeleteCanChannelsBypassDnd() throws Exception { // create notification channel that can't bypass dnd // expected result: areChannelsBypassingDnd = false // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG, UID, channel, true, false); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); // create notification channel that can bypass dnd // expected result: areChannelsBypassingDnd = true Loading @@ -1146,34 +1158,73 @@ public class RankingHelperTest extends UiServiceTestCase { channel2.setBypassDnd(true); mHelper.createNotificationChannel(PKG, UID, channel2, true, true); assertTrue(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); // delete channels mHelper.deleteNotificationChannel(PKG, UID, channel.getId()); assertTrue(mHelper.areChannelsBypassingDnd()); // channel2 can still bypass DND verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); mHelper.deleteNotificationChannel(PKG, UID, channel2.getId()); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testUpdateCanChannelsBypassDnd() throws Exception { // create notification channel that can't bypass dnd // expected result: areChannelsBypassingDnd = false // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG, UID, channel, true, false); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); // update channel so it CAN bypass dnd: // expected result: areChannelsBypassingDnd = true channel.setBypassDnd(true); mHelper.updateNotificationChannel(PKG, UID, channel, true); assertTrue(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); // update channel so it can't bypass dnd: // expected result: areChannelsBypassingDnd = false channel.setBypassDnd(false); mHelper.updateNotificationChannel(PKG, UID, channel, true); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testSetupNewZenModeHelper_canBypass() { // start notification policy off with mAreChannelsBypassingDnd = true, but // RankingHelper should change to false mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testSetupNewZenModeHelper_cannotBypass() { // start notification policy off with mAreChannelsBypassingDnd = false mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, 0); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); } @Test Loading Loading
services/core/java/com/android/server/notification/RankingHelper.java +2 −4 Original line number Diff line number Diff line Loading @@ -25,22 +25,18 @@ import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ParceledListSlice; import android.content.pm.Signature; import android.metrics.LogMaker; import android.os.Build; import android.os.UserHandle; import android.print.PrintManager; import android.provider.Settings.Secure; import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.RankingHelperProto; import android.service.notification.RankingHelperProto.RecordProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; import android.util.proto.ProtoOutputStream; Loading Loading @@ -156,6 +152,8 @@ public class RankingHelper implements RankingConfig { } } mAreChannelsBypassingDnd = (mZenModeHelper.getNotificationPolicy().state & NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND) == 1; updateChannelsBypassingDnd(); } Loading
services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +58 −7 Original line number Diff line number Diff line Loading @@ -33,8 +33,10 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -115,7 +117,9 @@ public class RankingHelperTest extends UiServiceTestCase { @Mock PackageManager mPm; @Mock IContentProvider mTestIContentProvider; @Mock Context mContext; @Mock ZenModeHelper mMockZenModeHelper; private NotificationManager.Policy mTestNotificationPolicy; private Notification mNotiGroupGSortA; private Notification mNotiGroupGSortB; private Notification mNotiNoGroup; Loading Loading @@ -172,12 +176,12 @@ public class RankingHelperTest extends UiServiceTestCase { when(mTestIContentProvider.uncanonicalize(any(), eq(CANONICAL_SOUND_URI))) .thenReturn(SOUND_URI); ZenModeHelper mockZenModeHelper = mock(ZenModeHelper.class); mHelper = new RankingHelper(getContext(), mPm, mHandler, mockZenModeHelper, mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); when(mockZenModeHelper.getNotificationPolicy()).thenReturn(new NotificationManager.Policy( 0, 0, 0)); resetZenModeHelper(); mNotiGroupGSortA = new Notification.Builder(mContext, TEST_CHANNEL_ID) .setContentTitle("A") Loading Loading @@ -299,6 +303,11 @@ public class RankingHelperTest extends UiServiceTestCase { return null; } private void resetZenModeHelper() { reset(mMockZenModeHelper); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); } @Test public void testFindAfterRankingWithASplitGroup() throws Exception { ArrayList<NotificationRecord> notificationList = new ArrayList<NotificationRecord>(3); Loading Loading @@ -1136,9 +1145,12 @@ public class RankingHelperTest extends UiServiceTestCase { public void testCreateAndDeleteCanChannelsBypassDnd() throws Exception { // create notification channel that can't bypass dnd // expected result: areChannelsBypassingDnd = false // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG, UID, channel, true, false); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); // create notification channel that can bypass dnd // expected result: areChannelsBypassingDnd = true Loading @@ -1146,34 +1158,73 @@ public class RankingHelperTest extends UiServiceTestCase { channel2.setBypassDnd(true); mHelper.createNotificationChannel(PKG, UID, channel2, true, true); assertTrue(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); // delete channels mHelper.deleteNotificationChannel(PKG, UID, channel.getId()); assertTrue(mHelper.areChannelsBypassingDnd()); // channel2 can still bypass DND verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); mHelper.deleteNotificationChannel(PKG, UID, channel2.getId()); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testUpdateCanChannelsBypassDnd() throws Exception { // create notification channel that can't bypass dnd // expected result: areChannelsBypassingDnd = false // setNotificationPolicy isn't called since areChannelsBypassingDnd was already false NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW); mHelper.createNotificationChannel(PKG, UID, channel, true, false); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); // update channel so it CAN bypass dnd: // expected result: areChannelsBypassingDnd = true channel.setBypassDnd(true); mHelper.updateNotificationChannel(PKG, UID, channel, true); assertTrue(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); // update channel so it can't bypass dnd: // expected result: areChannelsBypassingDnd = false channel.setBypassDnd(false); mHelper.updateNotificationChannel(PKG, UID, channel, true); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testSetupNewZenModeHelper_canBypass() { // start notification policy off with mAreChannelsBypassingDnd = true, but // RankingHelper should change to false mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, NotificationManager.Policy.STATE_CHANNELS_BYPASSING_DND); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any()); resetZenModeHelper(); } @Test public void testSetupNewZenModeHelper_cannotBypass() { // start notification policy off with mAreChannelsBypassingDnd = false mTestNotificationPolicy = new NotificationManager.Policy(0, 0, 0, 0, 0); when(mMockZenModeHelper.getNotificationPolicy()).thenReturn(mTestNotificationPolicy); mHelper = new RankingHelper(getContext(), mPm, mHandler, mMockZenModeHelper, mUsageStats, new String[] {ImportanceExtractor.class.getName()}); assertFalse(mHelper.areChannelsBypassingDnd()); verify(mMockZenModeHelper, never()).setNotificationPolicy(any()); resetZenModeHelper(); } @Test Loading