Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −1 Original line number Diff line number Diff line Loading @@ -3583,8 +3583,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<ConversationChannelWrapper> getConversations( boolean onlyImportant) { enforceSystemOrSystemUI("getConversations"); IntArray userIds = mUserProfiles.getCurrentProfileIds(); ArrayList<ConversationChannelWrapper> conversations = mPreferencesHelper.getConversations(onlyImportant); mPreferencesHelper.getConversations(userIds, onlyImportant); for (ConversationChannelWrapper conversation : conversations) { if (mShortcutHelper == null) { conversation.setShortcutInfo(null); Loading services/core/java/com/android/server/notification/PreferencesHelper.java +29 −25 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.service.notification.RankingHelperProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; Loading Loading @@ -1385,18 +1386,20 @@ public class PreferencesHelper implements RankingConfig { return null; } public ArrayList<ConversationChannelWrapper> getConversations(boolean onlyImportant) { public ArrayList<ConversationChannelWrapper> getConversations(IntArray userIds, boolean onlyImportant) { synchronized (mPackagePreferences) { ArrayList<ConversationChannelWrapper> conversations = new ArrayList<>(); for (PackagePreferences p : mPackagePreferences.values()) { if (userIds.binarySearch(UserHandle.getUserId(p.uid)) >= 0) { int N = p.channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel nc = p.channels.valueAt(i); if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted() && !nc.isDemoted() && (nc.isImportantConversation() || !onlyImportant)) { ConversationChannelWrapper conversation = new ConversationChannelWrapper(); ConversationChannelWrapper conversation = new ConversationChannelWrapper(); conversation.setPkg(p.pkg); conversation.setUid(p.uid); conversation.setNotificationChannel(nc); Loading @@ -1419,6 +1422,7 @@ public class PreferencesHelper implements RankingConfig { } } } } return conversations; } Loading services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.TestableContentResolver; import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.StatsEvent; import android.util.Xml; Loading Loading @@ -3318,7 +3319,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setImportantConversation(true); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(3, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading @@ -3326,6 +3328,44 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue(conversationWrapperContainsChannel(convos, channel2)); } @Test public void testGetConversations_multiUser() { String convoId = "convo"; NotificationChannel messages = new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel(PKG_O, UID_O, messages, true, false); NotificationChannel messagesUser10 = new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel( PKG_O, UID_O + UserHandle.PER_USER_RANGE, messagesUser10, true, false); NotificationChannel messagesFromB = new NotificationChannel("B person msgs", "messages from B", IMPORTANCE_DEFAULT); messagesFromB.setConversationId(messages.getId(), "different convo"); mHelper.createNotificationChannel(PKG_O, UID_O, messagesFromB, true, false); NotificationChannel messagesFromBUser10 = new NotificationChannel("B person msgs", "messages from B", IMPORTANCE_DEFAULT); messagesFromBUser10.setConversationId(messagesUser10.getId(), "different convo"); mHelper.createNotificationChannel( PKG_O, UID_O + UserHandle.PER_USER_RANGE, messagesFromBUser10, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(1, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, messagesFromB)); convos = mHelper.getConversations(IntArray.wrap(new int[] {0, UserHandle.getUserId(UID_O + UserHandle.PER_USER_RANGE)}), false); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, messagesFromB)); assertTrue(conversationWrapperContainsChannel(convos, messagesFromBUser10)); } @Test public void testGetConversations_notDemoted() { String convoId = "convo"; Loading Loading @@ -3356,7 +3396,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setImportantConversation(true); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading Loading @@ -3394,7 +3435,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setConversationId(calls.getId(), convoId); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(true); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), true); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −1 Original line number Diff line number Diff line Loading @@ -3583,8 +3583,9 @@ public class NotificationManagerService extends SystemService { public ParceledListSlice<ConversationChannelWrapper> getConversations( boolean onlyImportant) { enforceSystemOrSystemUI("getConversations"); IntArray userIds = mUserProfiles.getCurrentProfileIds(); ArrayList<ConversationChannelWrapper> conversations = mPreferencesHelper.getConversations(onlyImportant); mPreferencesHelper.getConversations(userIds, onlyImportant); for (ConversationChannelWrapper conversation : conversations) { if (mShortcutHelper == null) { conversation.setShortcutInfo(null); Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +29 −25 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ import android.service.notification.RankingHelperProto; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.Slog; import android.util.SparseBooleanArray; Loading Loading @@ -1385,18 +1386,20 @@ public class PreferencesHelper implements RankingConfig { return null; } public ArrayList<ConversationChannelWrapper> getConversations(boolean onlyImportant) { public ArrayList<ConversationChannelWrapper> getConversations(IntArray userIds, boolean onlyImportant) { synchronized (mPackagePreferences) { ArrayList<ConversationChannelWrapper> conversations = new ArrayList<>(); for (PackagePreferences p : mPackagePreferences.values()) { if (userIds.binarySearch(UserHandle.getUserId(p.uid)) >= 0) { int N = p.channels.size(); for (int i = 0; i < N; i++) { final NotificationChannel nc = p.channels.valueAt(i); if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted() && !nc.isDemoted() && (nc.isImportantConversation() || !onlyImportant)) { ConversationChannelWrapper conversation = new ConversationChannelWrapper(); ConversationChannelWrapper conversation = new ConversationChannelWrapper(); conversation.setPkg(p.pkg); conversation.setUid(p.uid); conversation.setNotificationChannel(nc); Loading @@ -1419,6 +1422,7 @@ public class PreferencesHelper implements RankingConfig { } } } } return conversations; } Loading
services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +45 −3 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ import android.test.suitebuilder.annotation.SmallTest; import android.testing.TestableContentResolver; import android.util.ArrayMap; import android.util.ArraySet; import android.util.IntArray; import android.util.Pair; import android.util.StatsEvent; import android.util.Xml; Loading Loading @@ -3318,7 +3319,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setImportantConversation(true); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(3, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading @@ -3326,6 +3328,44 @@ public class PreferencesHelperTest extends UiServiceTestCase { assertTrue(conversationWrapperContainsChannel(convos, channel2)); } @Test public void testGetConversations_multiUser() { String convoId = "convo"; NotificationChannel messages = new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel(PKG_O, UID_O, messages, true, false); NotificationChannel messagesUser10 = new NotificationChannel("messages", "Messages", IMPORTANCE_DEFAULT); mHelper.createNotificationChannel( PKG_O, UID_O + UserHandle.PER_USER_RANGE, messagesUser10, true, false); NotificationChannel messagesFromB = new NotificationChannel("B person msgs", "messages from B", IMPORTANCE_DEFAULT); messagesFromB.setConversationId(messages.getId(), "different convo"); mHelper.createNotificationChannel(PKG_O, UID_O, messagesFromB, true, false); NotificationChannel messagesFromBUser10 = new NotificationChannel("B person msgs", "messages from B", IMPORTANCE_DEFAULT); messagesFromBUser10.setConversationId(messagesUser10.getId(), "different convo"); mHelper.createNotificationChannel( PKG_O, UID_O + UserHandle.PER_USER_RANGE, messagesFromBUser10, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(1, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, messagesFromB)); convos = mHelper.getConversations(IntArray.wrap(new int[] {0, UserHandle.getUserId(UID_O + UserHandle.PER_USER_RANGE)}), false); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, messagesFromB)); assertTrue(conversationWrapperContainsChannel(convos, messagesFromBUser10)); } @Test public void testGetConversations_notDemoted() { String convoId = "convo"; Loading Loading @@ -3356,7 +3396,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setImportantConversation(true); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(false); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), false); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading Loading @@ -3394,7 +3435,8 @@ public class PreferencesHelperTest extends UiServiceTestCase { channel2.setConversationId(calls.getId(), convoId); mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false); List<ConversationChannelWrapper> convos = mHelper.getConversations(true); List<ConversationChannelWrapper> convos = mHelper.getConversations(IntArray.wrap(new int[] {0}), true); assertEquals(2, convos.size()); assertTrue(conversationWrapperContainsChannel(convos, channel)); Loading