Loading core/java/android/app/NotificationChannelGroup.java +13 −8 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.annotation.SystemApi; import android.annotation.TestApi; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.Intent; import android.content.Intent; import android.content.pm.ParceledListSlice; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; import android.text.TextUtils; import android.text.TextUtils; Loading Loading @@ -67,7 +66,7 @@ public final class NotificationChannelGroup implements Parcelable { private CharSequence mName; private CharSequence mName; private String mDescription; private String mDescription; private boolean mBlocked; private boolean mBlocked; private ParceledListSlice<NotificationChannel> mChannels; private List<NotificationChannel> mChannels = new ArrayList<>(); // Bitwise representation of fields that have been changed by the user // Bitwise representation of fields that have been changed by the user private int mUserLockedFields; private int mUserLockedFields; Loading Loading @@ -101,8 +100,7 @@ public final class NotificationChannelGroup implements Parcelable { } else { } else { mDescription = null; mDescription = null; } } mChannels = in.readParcelable( in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader(), android.app.NotificationChannel.class); NotificationChannelGroup.class.getClassLoader(), ParceledListSlice.class); mBlocked = in.readBoolean(); mBlocked = in.readBoolean(); mUserLockedFields = in.readInt(); mUserLockedFields = in.readInt(); } } Loading @@ -129,7 +127,7 @@ public final class NotificationChannelGroup implements Parcelable { } else { } else { dest.writeByte((byte) 0); dest.writeByte((byte) 0); } } dest.writeParcelable(mChannels, flags); dest.writeParcelableList(mChannels, flags); dest.writeBoolean(mBlocked); dest.writeBoolean(mBlocked); dest.writeInt(mUserLockedFields); dest.writeInt(mUserLockedFields); } } Loading Loading @@ -159,7 +157,7 @@ public final class NotificationChannelGroup implements Parcelable { * Returns the list of channels that belong to this group * Returns the list of channels that belong to this group */ */ public List<NotificationChannel> getChannels() { public List<NotificationChannel> getChannels() { return mChannels == null ? new ArrayList<>() : mChannels.getList(); return mChannels; } } /** /** Loading Loading @@ -190,11 +188,18 @@ public final class NotificationChannelGroup implements Parcelable { mBlocked = blocked; mBlocked = blocked; } } /** * @hide */ public void addChannel(NotificationChannel channel) { mChannels.add(channel); } /** /** * @hide * @hide */ */ public void setChannels(List<NotificationChannel> channels) { public void setChannels(List<NotificationChannel> channels) { mChannels = new ParceledListSlice<>(channels); mChannels = channels; } } /** /** Loading Loading @@ -329,7 +334,7 @@ public final class NotificationChannelGroup implements Parcelable { proto.write(NotificationChannelGroupProto.NAME, mName.toString()); proto.write(NotificationChannelGroupProto.NAME, mName.toString()); proto.write(NotificationChannelGroupProto.DESCRIPTION, mDescription); proto.write(NotificationChannelGroupProto.DESCRIPTION, mDescription); proto.write(NotificationChannelGroupProto.IS_BLOCKED, mBlocked); proto.write(NotificationChannelGroupProto.IS_BLOCKED, mBlocked); for (NotificationChannel channel : mChannels.getList()) { for (NotificationChannel channel : mChannels) { channel.dumpDebug(proto, NotificationChannelGroupProto.CHANNELS); channel.dumpDebug(proto, NotificationChannelGroupProto.CHANNELS); } } proto.end(token); proto.end(token); Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -98,7 +98,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { @Test @Test fun testPrepareDialogForApp_onlyDefaultChannel() { fun testPrepareDialogForApp_onlyDefaultChannel() { group.channels = listOf(channelDefault) group.addChannel(channelDefault) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, setOf(channelDefault), appIcon, clickListener) setOf(channelDefault), appIcon, clickListener) Loading services/core/java/com/android/server/notification/PreferencesHelper.java +22 −28 Original line number Original line Diff line number Diff line Loading @@ -86,7 +86,6 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; import java.util.Collection; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.List; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; Loading Loading @@ -1328,17 +1327,16 @@ public class PreferencesHelper implements RankingConfig { return null; return null; } } NotificationChannelGroup group = r.groups.get(groupId).clone(); NotificationChannelGroup group = r.groups.get(groupId).clone(); ArrayList channels = new ArrayList(); group.setChannels(new ArrayList<>()); int N = r.channels.size(); int N = r.channels.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); final NotificationChannel nc = r.channels.valueAt(i); if (includeDeleted || !nc.isDeleted()) { if (includeDeleted || !nc.isDeleted()) { if (groupId.equals(nc.getGroup())) { if (groupId.equals(nc.getGroup())) { channels.add(nc); group.addChannel(nc); } } } } } } group.setChannels(channels); return group; return group; } } } } Loading @@ -1359,48 +1357,44 @@ public class PreferencesHelper implements RankingConfig { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { Objects.requireNonNull(pkg); Objects.requireNonNull(pkg); List<NotificationChannelGroup> groups = new ArrayList<>(); Map<String, NotificationChannelGroup> groups = new ArrayMap<>(); synchronized (mPackagePreferences) { synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { if (r == null) { return ParceledListSlice.emptyList(); return ParceledListSlice.emptyList(); } } Map<String, ArrayList<NotificationChannel>> groupedChannels = new HashMap(); NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null); int N = r.channels.size(); int N = r.channels.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); final NotificationChannel nc = r.channels.valueAt(i); if (includeDeleted || !nc.isDeleted()) { if (includeDeleted || !nc.isDeleted()) { if (nc.getGroup() != null) { if (nc.getGroup() != null) { if (r.groups.get(nc.getGroup()) != null) { if (r.groups.get(nc.getGroup()) != null) { ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault( NotificationChannelGroup ncg = groups.get(nc.getGroup()); nc.getGroup(), new ArrayList<>()); if (ncg == null) { channels.add(nc); ncg = r.groups.get(nc.getGroup()).clone(); groupedChannels.put(nc.getGroup(), channels); ncg.setChannels(new ArrayList<>()); groups.put(nc.getGroup(), ncg); } ncg.addChannel(nc); } } } else { } else { ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault( nonGrouped.addChannel(nc); null, new ArrayList<>()); } channels.add(nc); groupedChannels.put(null, channels); } } } } if (includeNonGrouped && nonGrouped.getChannels().size() > 0) { groups.put(null, nonGrouped); } } if (includeEmpty) { for (NotificationChannelGroup group : r.groups.values()) { for (NotificationChannelGroup group : r.groups.values()) { ArrayList<NotificationChannel> channels = if (!groups.containsKey(group.getId())) { groupedChannels.getOrDefault(group.getId(), new ArrayList<>()); groups.put(group.getId(), group); if (includeEmpty || !channels.isEmpty()) { NotificationChannelGroup clone = group.clone(); clone.setChannels(channels); groups.add(clone); } } } } if (includeNonGrouped && groupedChannels.containsKey(null)) { NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null); nonGrouped.setChannels(groupedChannels.get(null)); groups.add(nonGrouped); } } return new ParceledListSlice<>(groups); return new ParceledListSlice<>(new ArrayList<>(groups.values())); } } } } Loading Loading
core/java/android/app/NotificationChannelGroup.java +13 −8 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ import android.annotation.SystemApi; import android.annotation.TestApi; import android.annotation.TestApi; import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage; import android.content.Intent; import android.content.Intent; import android.content.pm.ParceledListSlice; import android.os.Parcel; import android.os.Parcel; import android.os.Parcelable; import android.os.Parcelable; import android.text.TextUtils; import android.text.TextUtils; Loading Loading @@ -67,7 +66,7 @@ public final class NotificationChannelGroup implements Parcelable { private CharSequence mName; private CharSequence mName; private String mDescription; private String mDescription; private boolean mBlocked; private boolean mBlocked; private ParceledListSlice<NotificationChannel> mChannels; private List<NotificationChannel> mChannels = new ArrayList<>(); // Bitwise representation of fields that have been changed by the user // Bitwise representation of fields that have been changed by the user private int mUserLockedFields; private int mUserLockedFields; Loading Loading @@ -101,8 +100,7 @@ public final class NotificationChannelGroup implements Parcelable { } else { } else { mDescription = null; mDescription = null; } } mChannels = in.readParcelable( in.readParcelableList(mChannels, NotificationChannel.class.getClassLoader(), android.app.NotificationChannel.class); NotificationChannelGroup.class.getClassLoader(), ParceledListSlice.class); mBlocked = in.readBoolean(); mBlocked = in.readBoolean(); mUserLockedFields = in.readInt(); mUserLockedFields = in.readInt(); } } Loading @@ -129,7 +127,7 @@ public final class NotificationChannelGroup implements Parcelable { } else { } else { dest.writeByte((byte) 0); dest.writeByte((byte) 0); } } dest.writeParcelable(mChannels, flags); dest.writeParcelableList(mChannels, flags); dest.writeBoolean(mBlocked); dest.writeBoolean(mBlocked); dest.writeInt(mUserLockedFields); dest.writeInt(mUserLockedFields); } } Loading Loading @@ -159,7 +157,7 @@ public final class NotificationChannelGroup implements Parcelable { * Returns the list of channels that belong to this group * Returns the list of channels that belong to this group */ */ public List<NotificationChannel> getChannels() { public List<NotificationChannel> getChannels() { return mChannels == null ? new ArrayList<>() : mChannels.getList(); return mChannels; } } /** /** Loading Loading @@ -190,11 +188,18 @@ public final class NotificationChannelGroup implements Parcelable { mBlocked = blocked; mBlocked = blocked; } } /** * @hide */ public void addChannel(NotificationChannel channel) { mChannels.add(channel); } /** /** * @hide * @hide */ */ public void setChannels(List<NotificationChannel> channels) { public void setChannels(List<NotificationChannel> channels) { mChannels = new ParceledListSlice<>(channels); mChannels = channels; } } /** /** Loading Loading @@ -329,7 +334,7 @@ public final class NotificationChannelGroup implements Parcelable { proto.write(NotificationChannelGroupProto.NAME, mName.toString()); proto.write(NotificationChannelGroupProto.NAME, mName.toString()); proto.write(NotificationChannelGroupProto.DESCRIPTION, mDescription); proto.write(NotificationChannelGroupProto.DESCRIPTION, mDescription); proto.write(NotificationChannelGroupProto.IS_BLOCKED, mBlocked); proto.write(NotificationChannelGroupProto.IS_BLOCKED, mBlocked); for (NotificationChannel channel : mChannels.getList()) { for (NotificationChannel channel : mChannels) { channel.dumpDebug(proto, NotificationChannelGroupProto.CHANNELS); channel.dumpDebug(proto, NotificationChannelGroupProto.CHANNELS); } } proto.end(token); proto.end(token); Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ChannelEditorDialogControllerTest.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -98,7 +98,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() { @Test @Test fun testPrepareDialogForApp_onlyDefaultChannel() { fun testPrepareDialogForApp_onlyDefaultChannel() { group.channels = listOf(channelDefault) group.addChannel(channelDefault) controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID, setOf(channelDefault), appIcon, clickListener) setOf(channelDefault), appIcon, clickListener) Loading
services/core/java/com/android/server/notification/PreferencesHelper.java +22 −28 Original line number Original line Diff line number Diff line Loading @@ -86,7 +86,6 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.ArrayList; import java.util.Arrays; import java.util.Arrays; import java.util.Collection; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.List; import java.util.Map; import java.util.Map; import java.util.Objects; import java.util.Objects; Loading Loading @@ -1328,17 +1327,16 @@ public class PreferencesHelper implements RankingConfig { return null; return null; } } NotificationChannelGroup group = r.groups.get(groupId).clone(); NotificationChannelGroup group = r.groups.get(groupId).clone(); ArrayList channels = new ArrayList(); group.setChannels(new ArrayList<>()); int N = r.channels.size(); int N = r.channels.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); final NotificationChannel nc = r.channels.valueAt(i); if (includeDeleted || !nc.isDeleted()) { if (includeDeleted || !nc.isDeleted()) { if (groupId.equals(nc.getGroup())) { if (groupId.equals(nc.getGroup())) { channels.add(nc); group.addChannel(nc); } } } } } } group.setChannels(channels); return group; return group; } } } } Loading @@ -1359,48 +1357,44 @@ public class PreferencesHelper implements RankingConfig { public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroups(String pkg, int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { int uid, boolean includeDeleted, boolean includeNonGrouped, boolean includeEmpty) { Objects.requireNonNull(pkg); Objects.requireNonNull(pkg); List<NotificationChannelGroup> groups = new ArrayList<>(); Map<String, NotificationChannelGroup> groups = new ArrayMap<>(); synchronized (mPackagePreferences) { synchronized (mPackagePreferences) { PackagePreferences r = getPackagePreferencesLocked(pkg, uid); PackagePreferences r = getPackagePreferencesLocked(pkg, uid); if (r == null) { if (r == null) { return ParceledListSlice.emptyList(); return ParceledListSlice.emptyList(); } } Map<String, ArrayList<NotificationChannel>> groupedChannels = new HashMap(); NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null); int N = r.channels.size(); int N = r.channels.size(); for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) { final NotificationChannel nc = r.channels.valueAt(i); final NotificationChannel nc = r.channels.valueAt(i); if (includeDeleted || !nc.isDeleted()) { if (includeDeleted || !nc.isDeleted()) { if (nc.getGroup() != null) { if (nc.getGroup() != null) { if (r.groups.get(nc.getGroup()) != null) { if (r.groups.get(nc.getGroup()) != null) { ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault( NotificationChannelGroup ncg = groups.get(nc.getGroup()); nc.getGroup(), new ArrayList<>()); if (ncg == null) { channels.add(nc); ncg = r.groups.get(nc.getGroup()).clone(); groupedChannels.put(nc.getGroup(), channels); ncg.setChannels(new ArrayList<>()); groups.put(nc.getGroup(), ncg); } ncg.addChannel(nc); } } } else { } else { ArrayList<NotificationChannel> channels = groupedChannels.getOrDefault( nonGrouped.addChannel(nc); null, new ArrayList<>()); } channels.add(nc); groupedChannels.put(null, channels); } } } } if (includeNonGrouped && nonGrouped.getChannels().size() > 0) { groups.put(null, nonGrouped); } } if (includeEmpty) { for (NotificationChannelGroup group : r.groups.values()) { for (NotificationChannelGroup group : r.groups.values()) { ArrayList<NotificationChannel> channels = if (!groups.containsKey(group.getId())) { groupedChannels.getOrDefault(group.getId(), new ArrayList<>()); groups.put(group.getId(), group); if (includeEmpty || !channels.isEmpty()) { NotificationChannelGroup clone = group.clone(); clone.setChannels(channels); groups.add(clone); } } } } if (includeNonGrouped && groupedChannels.containsKey(null)) { NotificationChannelGroup nonGrouped = new NotificationChannelGroup(null, null); nonGrouped.setChannels(groupedChannels.get(null)); groups.add(nonGrouped); } } return new ParceledListSlice<>(groups); return new ParceledListSlice<>(new ArrayList<>(groups.values())); } } } } Loading