Show channel groups in settings
Empty groups shouldn't be visible to client code. Test: runtest systemui-notification Change-Id: I319b035886ce1bd4b6839ebf46a2c3be7b2387cf
This commit is contained in:
@@ -64,7 +64,7 @@ public final class NotificationChannelGroup implements Parcelable {
|
||||
mId = null;
|
||||
}
|
||||
mName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
|
||||
in.readList(mChannels, NotificationChannel.class.getClassLoader());
|
||||
in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,6 +19,8 @@ import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.content.pm.ParceledListSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface RankingConfig {
|
||||
|
||||
void setImportance(String packageName, int uid, int importance);
|
||||
@@ -26,6 +28,8 @@ public interface RankingConfig {
|
||||
void setShowBadge(String packageName, int uid, boolean showBadge);
|
||||
boolean canShowBadge(String packageName, int uid);
|
||||
|
||||
Collection<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
|
||||
int uid);
|
||||
void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group,
|
||||
boolean fromTargetApp);
|
||||
ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
|
||||
|
||||
@@ -47,6 +47,7 @@ import org.xmlpull.v1.XmlSerializer;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -691,13 +692,28 @@ public class RankingHelper implements RankingConfig {
|
||||
}
|
||||
}
|
||||
}
|
||||
groups.addAll(r.groups.values());
|
||||
for (NotificationChannelGroup group : r.groups.values()) {
|
||||
if (group.getChannels().size() > 0) {
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
if (nonGrouped.getChannels().size() > 0) {
|
||||
groups.add(nonGrouped);
|
||||
}
|
||||
return new ParceledListSlice<>(groups);
|
||||
}
|
||||
|
||||
@Override
|
||||
@VisibleForTesting
|
||||
public Collection<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
|
||||
int uid) {
|
||||
Record r = getRecord(pkg, uid);
|
||||
if (r == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return r.groups.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParceledListSlice<NotificationChannel> getNotificationChannels(String pkg, int uid,
|
||||
boolean includeDeleted) {
|
||||
|
||||
@@ -805,7 +805,7 @@ public class RankingHelperTest {
|
||||
public void testCreateGroup() throws Exception {
|
||||
NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1");
|
||||
mHelper.createNotificationChannelGroup(pkg, uid, ncg, true);
|
||||
assertEquals(ncg, mHelper.getNotificationChannelGroups(pkg, uid, false).getList().get(0));
|
||||
assertEquals(ncg, mHelper.getNotificationChannelGroups(pkg, uid).iterator().next());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -834,6 +834,8 @@ public class RankingHelperTest {
|
||||
|
||||
@Test
|
||||
public void testGetChannelGroups() throws Exception {
|
||||
NotificationChannelGroup unused = new NotificationChannelGroup("unused", "s");
|
||||
mHelper.createNotificationChannelGroup(pkg, uid, unused, true);
|
||||
NotificationChannelGroup ncg = new NotificationChannelGroup("group1", "name1");
|
||||
mHelper.createNotificationChannelGroup(pkg, uid, ncg, true);
|
||||
NotificationChannelGroup ncg2 = new NotificationChannelGroup("group2", "name2");
|
||||
|
||||
Reference in New Issue
Block a user