Skip to content

Commit 96db30b

Browse files
committed
Do not polute settings and cache in case scheduling excepts
1 parent 078f4f9 commit 96db30b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ public ScheduleNotificationTask(int id, Notification.Builder builder) {
2828
@Override
2929
public boolean run(Context context, Set<String> notificationIds) {
3030
String id = String.valueOf(notificationId);
31-
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder);
32-
return notificationIds.add(id);
31+
try {
32+
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder);
33+
return notificationIds.add(id);
34+
} finally {
35+
// if failed to schedule or replace, remove from settings and cache, so the status is correctly reported
36+
if (!notificationIds.contains(id)) {
37+
UnityNotificationManager.deleteExpiredNotificationIntent(context, id);
38+
UnityNotificationManager.removeScheduledNotification(Integer.valueOf(notificationId));
39+
}
40+
}
3341
}
3442
}
3543

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ private static synchronized Notification getScheduledNotification(Integer id) {
864864
return mScheduledNotifications.get(id);
865865
}
866866

867-
private static synchronized Notification removeScheduledNotification(Integer id) {
867+
protected static synchronized Notification removeScheduledNotification(Integer id) {
868868
return mScheduledNotifications.remove(id);
869869
}
870870
}

0 commit comments

Comments
 (0)