Skip to content

Commit d4232fc

Browse files
committed
Less allocations when no channels
1 parent fff14d0 commit d4232fc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

com.unity.mobile.notifications/Runtime/Android/Plugins/com/unity/androidnotifications/UnityNotificationManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ public void deleteNotificationChannel(String id) {
278278
public NotificationChannelWrapper[] getNotificationChannels() {
279279
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
280280
List<NotificationChannel> channels = getNotificationManager().getNotificationChannels();
281+
if (channels.size() == 0)
282+
return null;
281283
NotificationChannelWrapper[] channelList = new NotificationChannelWrapper[channels.size()];
282284
int i = 0;
283285
for (NotificationChannel ch : channels) {
@@ -288,7 +290,8 @@ public NotificationChannelWrapper[] getNotificationChannels() {
288290
} else {
289291
SharedPreferences prefs = mContext.getSharedPreferences(NOTIFICATION_CHANNELS_SHARED_PREFS, Context.MODE_PRIVATE);
290292
Set<String> channelIdsSet = prefs.getStringSet(NOTIFICATION_CHANNELS_SHARED_PREFS_KEY, new HashSet());
291-
293+
if (channelIdsSet.size() == 0)
294+
return null;
292295
NotificationChannelWrapper[] channels = new NotificationChannelWrapper[channelIdsSet.size()];
293296
int i = 0;
294297
for (String k : channelIdsSet) {

0 commit comments

Comments
 (0)