Skip to content

Commit 78ec6af

Browse files
committed
Refactor Samsung guard to separate method
1 parent 4373ef2 commit 78ec6af

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,8 @@ protected static Intent buildOpenAppIntent(Context context, Class className) {
358358
// Build a notification Intent to store the PendingIntent.
359359
private static synchronized Intent buildNotificationIntentUpdateList(Context context, int notificationId) {
360360
Set<String> ids = getScheduledNotificationIDs(context);
361-
if (android.os.Build.MANUFACTURER.equals("samsung") && ids.size() >= (SAMSUNG_NOTIFICATION_LIMIT - 1)) {
362-
// There seems to be a limit of 500 concurrently scheduled alarms on Samsung devices.
363-
// Attempting to schedule more than that might cause the app to crash.
364-
Log.w(TAG_UNITY, String.format("Attempting to schedule more than %1$d notifications. There is a limit of %1$d concurrently scheduled Alarms on Samsung devices" +
365-
" either wait for the currently scheduled ones to be triggered or cancel them if you wish to schedule additional notifications.",
366-
SAMSUNG_NOTIFICATION_LIMIT));
361+
if (!canScheduleMoreAlarms(ids))
367362
return null;
368-
}
369363

370364
Intent intent = buildNotificationIntent(context);
371365
ids = new HashSet<>(ids);
@@ -374,6 +368,21 @@ private static synchronized Intent buildNotificationIntentUpdateList(Context con
374368
return intent;
375369
}
376370

371+
protected static boolean canScheduleMoreAlarms(Set<String> ids) {
372+
if (ids.size() < (SAMSUNG_NOTIFICATION_LIMIT - 1))
373+
return true;
374+
if ("samsung".equals(android.os.Build.MANUFACTURER)) {
375+
// There seems to be a limit of 500 concurrently scheduled alarms on Samsung devices.
376+
// Attempting to schedule more than that might cause the app to crash.
377+
Log.w(TAG_UNITY, String.format("Attempting to schedule more than %1$d notifications. There is a limit of %1$d concurrently scheduled Alarms on Samsung devices" +
378+
" either wait for the currently scheduled ones to be triggered or cancel them if you wish to schedule additional notifications.",
379+
SAMSUNG_NOTIFICATION_LIMIT));
380+
return false;
381+
}
382+
383+
return true;
384+
}
385+
377386
protected static void performNotificationHousekeeping(Context context, Set<String> ids) {
378387
Log.d(TAG_UNITY, "Checking for invalid notification IDs still hanging around");
379388

0 commit comments

Comments
 (0)