Skip to content

Commit a99008e

Browse files
authored
Merge pull request #215 from Unity-Technologies/rework-serialization
Rework serialization
2 parents abc3504 + 996ab39 commit a99008e

File tree

7 files changed

+432
-168
lines changed

7 files changed

+432
-168
lines changed

com.unity.mobile.notifications/Runtime/Android/AndroidNotificationCenter.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void CollectMethods(AndroidJavaClass clazz)
114114
setNotificationGroupAlertBehavior = JniApi.FindMethod(clazz, "setNotificationGroupAlertBehavior", "(Landroid/app/Notification$Builder;I)V", true);
115115
getNotificationGroupAlertBehavior = JniApi.FindMethod(clazz, "getNotificationGroupAlertBehavior", "(Landroid/app/Notification;)I", true);
116116
getNotificationChannelId = JniApi.FindMethod(clazz, "getNotificationChannelId", "(Landroid/app/Notification;)Ljava/lang/String;", true);
117-
scheduleNotification = JniApi.FindMethod(clazz, "scheduleNotification", "(Landroid/app/Notification$Builder;)I", false);
117+
scheduleNotification = JniApi.FindMethod(clazz, "scheduleNotification", "(Landroid/app/Notification$Builder;Z)I", false);
118118
createNotificationBuilder = JniApi.FindMethod(clazz, "createNotificationBuilder", "(Ljava/lang/String;)Landroid/app/Notification$Builder;", false);
119119
}
120120

@@ -195,9 +195,9 @@ public void DeleteNotificationChannel(string channelId)
195195
self.Call("deleteNotificationChannel", channelId);
196196
}
197197

198-
public int ScheduleNotification(AndroidJavaObject notificationBuilder)
198+
public int ScheduleNotification(AndroidJavaObject notificationBuilder, bool customized)
199199
{
200-
return self.Call<int>(scheduleNotification, notificationBuilder);
200+
return self.Call<int>(scheduleNotification, notificationBuilder, customized);
201201
}
202202

203203
public bool CheckIfPendingNotificationIsRegistered(int id)
@@ -678,11 +678,8 @@ public static int SendNotification(AndroidNotification notification, string chan
678678
if (!Initialize())
679679
return -1;
680680

681-
int id;
682681
using (var builder = CreateNotificationBuilder(notification, channelId))
683-
SendNotification(builder, out id);
684-
685-
return id;
682+
return ScheduleNotification(builder, false);
686683
}
687684

688685
/// <summary>
@@ -696,9 +693,7 @@ public static void SendNotificationWithExplicitID(AndroidNotification notificati
696693
{
697694
if (Initialize())
698695
using (var builder = CreateNotificationBuilder(id, notification, channelId))
699-
{
700-
SendNotification(builder);
701-
}
696+
ScheduleNotification(builder, false);
702697
}
703698

704699
/// <summary>
@@ -708,7 +703,7 @@ public static void SendNotificationWithExplicitID(AndroidNotification notificati
708703
public static void SendNotification(AndroidJavaObject notificationBuilder)
709704
{
710705
if (Initialize())
711-
s_Jni.NotificationManager.ScheduleNotification(notificationBuilder);
706+
ScheduleNotification(notificationBuilder, true);
712707
}
713708

714709
/// <summary>
@@ -720,7 +715,12 @@ public static void SendNotification(AndroidJavaObject notificationBuilder, out i
720715
{
721716
id = -1;
722717
if (Initialize())
723-
id = s_Jni.NotificationManager.ScheduleNotification(notificationBuilder);
718+
id = ScheduleNotification(notificationBuilder, true);
719+
}
720+
721+
static int ScheduleNotification(AndroidJavaObject notificationBuilder, bool customized)
722+
{
723+
return s_Jni.NotificationManager.ScheduleNotification(notificationBuilder, customized);
724724
}
725725

726726
/// <summary>

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
@@ -22,11 +22,13 @@ private static abstract class Task {
2222
private static class ScheduleNotificationTask extends Task {
2323
private int notificationId;
2424
private Notification.Builder notificationBuilder;
25+
private boolean isCustomized;
2526
private boolean isNew;
2627

27-
public ScheduleNotificationTask(int id, Notification.Builder builder, boolean addedNew) {
28+
public ScheduleNotificationTask(int id, Notification.Builder builder, boolean customized, boolean addedNew) {
2829
notificationId = id;
2930
notificationBuilder = builder;
31+
isCustomized = customized;
3032
isNew = addedNew;
3133
}
3234

@@ -36,7 +38,7 @@ public boolean run(UnityNotificationManager manager, ConcurrentHashMap<Integer,
3638
Integer ID = Integer.valueOf(notificationId);
3739
boolean didSchedule = false;
3840
try {
39-
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder);
41+
UnityNotificationManager.mUnityNotificationManager.performNotificationScheduling(notificationId, notificationBuilder, isCustomized);
4042
didSchedule = true;
4143
} finally {
4244
// if failed to schedule or replace, remove
@@ -121,8 +123,8 @@ public UnityNotificationBackgroundThread(UnityNotificationManager manager, Concu
121123
loadNotifications();
122124
}
123125

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

128130
public void enqueueCancelNotification(int id) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private int generateUniqueId() {
308308
return id;
309309
}
310310

311-
public int scheduleNotification(Notification.Builder notificationBuilder) {
311+
public int scheduleNotification(Notification.Builder notificationBuilder, boolean customized) {
312312
Bundle extras = notificationBuilder.getExtras();
313313
int id;
314314
if (extras.containsKey(KEY_ID))
@@ -319,11 +319,11 @@ public int scheduleNotification(Notification.Builder notificationBuilder) {
319319
}
320320

321321
boolean addedNew = mScheduledNotifications.putIfAbsent(id, notificationBuilder) == null;
322-
mBackgroundThread.enqueueNotification(id, notificationBuilder, addedNew);
322+
mBackgroundThread.enqueueNotification(id, notificationBuilder, customized, addedNew);
323323
return id;
324324
}
325325

326-
void performNotificationScheduling(int id, Notification.Builder notificationBuilder) {
326+
void performNotificationScheduling(int id, Notification.Builder notificationBuilder, boolean customized) {
327327
Bundle extras = notificationBuilder.getExtras();
328328
long repeatInterval = extras.getLong(KEY_REPEAT_INTERVAL, -1);
329329
long fireTime = extras.getLong(KEY_FIRE_TIME, -1);
@@ -339,7 +339,7 @@ void performNotificationScheduling(int id, Notification.Builder notificationBuil
339339
Intent intent = buildNotificationIntent();
340340

341341
if (intent != null) {
342-
saveNotification(notificationBuilder.build());
342+
saveNotification(notificationBuilder.build(), customized);
343343
scheduleAlarmWithNotification(notificationBuilder, intent, fireTime);
344344
}
345345
}
@@ -467,10 +467,10 @@ private PendingIntent getBroadcastPendingIntent(int id, Intent intent, int flags
467467

468468
// Save the notification intent to SharedPreferences if reschedule_on_restart is true,
469469
// which will be consumed by UnityNotificationRestartOnBootReceiver for device reboot.
470-
synchronized void saveNotification(Notification notification) {
470+
synchronized void saveNotification(Notification notification, boolean customized) {
471471
String notification_id = Integer.toString(notification.extras.getInt(KEY_ID, -1));
472472
SharedPreferences prefs = mContext.getSharedPreferences(getSharedPrefsNameByNotificationId(notification_id), Context.MODE_PRIVATE);
473-
UnityNotificationUtilities.serializeNotification(prefs, notification);
473+
UnityNotificationUtilities.serializeNotification(prefs, notification, customized);
474474
}
475475

476476
static String getSharedPrefsNameByNotificationId(String id) {

0 commit comments

Comments
 (0)