Merge "Filter conversation list by current users" into rvc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9bf2c7aaf3
@@ -3534,8 +3534,9 @@ public class NotificationManagerService extends SystemService {
|
|||||||
public ParceledListSlice<ConversationChannelWrapper> getConversations(
|
public ParceledListSlice<ConversationChannelWrapper> getConversations(
|
||||||
boolean onlyImportant) {
|
boolean onlyImportant) {
|
||||||
enforceSystemOrSystemUI("getConversations");
|
enforceSystemOrSystemUI("getConversations");
|
||||||
|
IntArray userIds = mUserProfiles.getCurrentProfileIds();
|
||||||
ArrayList<ConversationChannelWrapper> conversations =
|
ArrayList<ConversationChannelWrapper> conversations =
|
||||||
mPreferencesHelper.getConversations(onlyImportant);
|
mPreferencesHelper.getConversations(userIds, onlyImportant);
|
||||||
for (ConversationChannelWrapper conversation : conversations) {
|
for (ConversationChannelWrapper conversation : conversations) {
|
||||||
if (mShortcutHelper == null) {
|
if (mShortcutHelper == null) {
|
||||||
conversation.setShortcutInfo(null);
|
conversation.setShortcutInfo(null);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import android.service.notification.RankingHelperProto;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
import android.util.IntArray;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
@@ -1348,36 +1349,39 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<ConversationChannelWrapper> getConversations(boolean onlyImportant) {
|
public ArrayList<ConversationChannelWrapper> getConversations(IntArray userIds,
|
||||||
|
boolean onlyImportant) {
|
||||||
synchronized (mPackagePreferences) {
|
synchronized (mPackagePreferences) {
|
||||||
ArrayList<ConversationChannelWrapper> conversations = new ArrayList<>();
|
ArrayList<ConversationChannelWrapper> conversations = new ArrayList<>();
|
||||||
|
|
||||||
for (PackagePreferences p : mPackagePreferences.values()) {
|
for (PackagePreferences p : mPackagePreferences.values()) {
|
||||||
int N = p.channels.size();
|
if (userIds.binarySearch(UserHandle.getUserId(p.uid)) >= 0) {
|
||||||
for (int i = 0; i < N; i++) {
|
int N = p.channels.size();
|
||||||
final NotificationChannel nc = p.channels.valueAt(i);
|
for (int i = 0; i < N; i++) {
|
||||||
if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted()
|
final NotificationChannel nc = p.channels.valueAt(i);
|
||||||
&& !nc.isDemoted()
|
if (!TextUtils.isEmpty(nc.getConversationId()) && !nc.isDeleted()
|
||||||
&& (nc.isImportantConversation() || !onlyImportant)) {
|
&& !nc.isDemoted()
|
||||||
ConversationChannelWrapper conversation = new ConversationChannelWrapper();
|
&& (nc.isImportantConversation() || !onlyImportant)) {
|
||||||
conversation.setPkg(p.pkg);
|
ConversationChannelWrapper conversation =
|
||||||
conversation.setUid(p.uid);
|
new ConversationChannelWrapper();
|
||||||
conversation.setNotificationChannel(nc);
|
conversation.setPkg(p.pkg);
|
||||||
conversation.setParentChannelLabel(
|
conversation.setUid(p.uid);
|
||||||
p.channels.get(nc.getParentChannelId()).getName());
|
conversation.setNotificationChannel(nc);
|
||||||
boolean blockedByGroup = false;
|
conversation.setParentChannelLabel(
|
||||||
if (nc.getGroup() != null) {
|
p.channels.get(nc.getParentChannelId()).getName());
|
||||||
NotificationChannelGroup group = p.groups.get(nc.getGroup());
|
boolean blockedByGroup = false;
|
||||||
if (group != null) {
|
if (nc.getGroup() != null) {
|
||||||
if (group.isBlocked()) {
|
NotificationChannelGroup group = p.groups.get(nc.getGroup());
|
||||||
blockedByGroup = true;
|
if (group != null) {
|
||||||
} else {
|
if (group.isBlocked()) {
|
||||||
conversation.setGroupLabel(group.getName());
|
blockedByGroup = true;
|
||||||
|
} else {
|
||||||
|
conversation.setGroupLabel(group.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!blockedByGroup) {
|
||||||
if (!blockedByGroup) {
|
conversations.add(conversation);
|
||||||
conversations.add(conversation);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ import android.test.suitebuilder.annotation.SmallTest;
|
|||||||
import android.testing.TestableContentResolver;
|
import android.testing.TestableContentResolver;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
import android.util.IntArray;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.util.StatsEvent;
|
import android.util.StatsEvent;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
@@ -3247,7 +3248,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
channel2.setImportantConversation(true);
|
channel2.setImportantConversation(true);
|
||||||
mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false);
|
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());
|
assertEquals(3, convos.size());
|
||||||
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
||||||
@@ -3255,6 +3257,44 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
assertTrue(conversationWrapperContainsChannel(convos, channel2));
|
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
|
@Test
|
||||||
public void testGetConversations_notDemoted() {
|
public void testGetConversations_notDemoted() {
|
||||||
String convoId = "convo";
|
String convoId = "convo";
|
||||||
@@ -3285,7 +3325,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
channel2.setImportantConversation(true);
|
channel2.setImportantConversation(true);
|
||||||
mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false);
|
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());
|
assertEquals(2, convos.size());
|
||||||
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
||||||
@@ -3323,7 +3364,8 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
channel2.setConversationId(calls.getId(), convoId);
|
channel2.setConversationId(calls.getId(), convoId);
|
||||||
mHelper.createNotificationChannel(PKG_O, UID_O, channel2, true, false);
|
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());
|
assertEquals(2, convos.size());
|
||||||
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
assertTrue(conversationWrapperContainsChannel(convos, channel));
|
||||||
|
|||||||
Reference in New Issue
Block a user