diff --git a/core/java/android/app/NotificationChannelGroup.java b/core/java/android/app/NotificationChannelGroup.java index 3341b915931a3..68cac27cb7cac 100644 --- a/core/java/android/app/NotificationChannelGroup.java +++ b/core/java/android/app/NotificationChannelGroup.java @@ -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 diff --git a/services/core/java/com/android/server/notification/RankingConfig.java b/services/core/java/com/android/server/notification/RankingConfig.java index 2e35e3dbc5e1d..6a0072216f700 100644 --- a/services/core/java/com/android/server/notification/RankingConfig.java +++ b/services/core/java/com/android/server/notification/RankingConfig.java @@ -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 getNotificationChannelGroups(String pkg, + int uid); void createNotificationChannelGroup(String pkg, int uid, NotificationChannelGroup group, boolean fromTargetApp); ParceledListSlice getNotificationChannelGroups(String pkg, diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 01cca2d0f35ca..5b6ac692aede1 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -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 getNotificationChannelGroups(String pkg, + int uid) { + Record r = getRecord(pkg, uid); + if (r == null) { + return new ArrayList<>(); + } + return r.groups.values(); + } + @Override public ParceledListSlice getNotificationChannels(String pkg, int uid, boolean includeDeleted) { diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java index 5be6e91ba8634..b53ec4548393a 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -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");