Skip to content

Commit 8c5b541

Browse files
committed
Pass around if notification may have been customized
1 parent 45ba3ba commit 8c5b541

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ private static abstract class Task {
2323
private static class ScheduleNotificationTask extends Task {
2424
private int notificationId;
2525
private Notification.Builder notificationBuilder;
26+
private boolean isCustomized;
2627
private boolean isNew;
2728

28-
public ScheduleNotificationTask(int id, Notification.Builder builder, boolean addedNew) {
29+
public ScheduleNotificationTask(int id, Notification.Builder builder, boolean customized, boolean addedNew) {
2930
notificationId = id;
3031
notificationBuilder = builder;
32+
isCustomized = customized;
3133
isNew = addedNew;
3234
}
3335

@@ -37,7 +39,7 @@ public boolean run(Context context, ConcurrentHashMap<Integer, Notification.Buil
3739
Integer ID = Integer.valueOf(notificationId);
3840
boolean didSchedule = false;
3941
try {
40-
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder);
42+
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder, isCustomized);
4143
didSchedule = true;
4244
} finally {
4345
// if failed to schedule or replace, remove
@@ -122,8 +124,8 @@ public UnityNotificationBackgroundThread(Context context, ConcurrentHashMap<Inte
122124
loadNotifications();
123125
}
124126

125-
public void enqueueNotification(int id, Notification.Builder notificationBuilder, boolean addedNew) {
126-
mTasks.add(new UnityNotificationBackgroundThread.ScheduleNotificationTask(id, notificationBuilder, addedNew));
127+
public void enqueueNotification(int id, Notification.Builder notificationBuilder, boolean customized, boolean addedNew) {
128+
mTasks.add(new UnityNotificationBackgroundThread.ScheduleNotificationTask(id, notificationBuilder, customized, addedNew));
127129
}
128130

129131
public void enqueueCancelNotification(int id) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ public int scheduleNotification(Notification.Builder notificationBuilder, boolea
323323
}
324324

325325
boolean addedNew = mScheduledNotifications.putIfAbsent(id, notificationBuilder) == null;
326-
mBackgroundThread.enqueueNotification(id, notificationBuilder, addedNew);
326+
mBackgroundThread.enqueueNotification(id, notificationBuilder, customized, addedNew);
327327
return id;
328328
}
329329

330-
protected void performNotificationScheduling(int id, Notification.Builder notificationBuilder) {
330+
protected void performNotificationScheduling(int id, Notification.Builder notificationBuilder, boolean customized) {
331331
Bundle extras = notificationBuilder.getExtras();
332332
long repeatInterval = extras.getLong(KEY_REPEAT_INTERVAL, -1);
333333
long fireTime = extras.getLong(KEY_FIRE_TIME, -1);
@@ -343,7 +343,7 @@ protected void performNotificationScheduling(int id, Notification.Builder notifi
343343
Intent intent = buildNotificationIntent(mContext);
344344

345345
if (intent != null) {
346-
saveNotification(mContext, notificationBuilder.build());
346+
saveNotification(mContext, notificationBuilder.build(), customized);
347347
scheduleAlarmWithNotification(notificationBuilder, intent, fireTime);
348348
}
349349
}
@@ -493,10 +493,10 @@ public static PendingIntent getBroadcastPendingIntent(Context context, int id, I
493493

494494
// Save the notification intent to SharedPreferences if reschedule_on_restart is true,
495495
// which will be consumed by UnityNotificationRestartOnBootReceiver for device reboot.
496-
protected static synchronized void saveNotification(Context context, Notification notification) {
496+
protected static synchronized void saveNotification(Context context, Notification notification, boolean customized) {
497497
String notification_id = Integer.toString(notification.extras.getInt(KEY_ID, -1));
498498
SharedPreferences prefs = context.getSharedPreferences(getSharedPrefsNameByNotificationId(notification_id), Context.MODE_PRIVATE);
499-
UnityNotificationUtilities.serializeNotification(prefs, notification);
499+
UnityNotificationUtilities.serializeNotification(prefs, notification, customized);
500500
}
501501

502502
protected static String getSharedPrefsNameByNotificationId(String id)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected static int findResourceIdInContextByName(Context context, String name)
7878
When notification is serialized as-is, it may contain references to resources and in case
7979
of app update may fail to deserialize due to resources now missing, hence always save fallback version.
8080
*/
81-
protected static void serializeNotification(SharedPreferences prefs, Notification notification) {
81+
protected static void serializeNotification(SharedPreferences prefs, Notification notification, boolean serializeParcel) {
8282
try {
8383
String serialized = null, fallback = null;
8484
ByteArrayOutputStream data = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)