Skip to content

Commit 749cea6

Browse files
committed
Do not serialize extras is custom
1 parent 5646bdd commit 749cea6

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class UnityNotificationUtilities {
4242
// magic stands for "Unity Mobile Notifications Notification"
4343
static final byte[] UNITY_MAGIC_NUMBER = new byte[] { 'U', 'M', 'N', 'N'};
4444
private static final byte[] UNITY_MAGIC_NUMBER_PARCELLED = new byte[] { 'U', 'M', 'N', 'P'};
45-
private static final int NOTIFICATION_SERIALIZATION_VERSION = 1;
45+
private static final int NOTIFICATION_SERIALIZATION_VERSION = 2;
4646
private static final int INTENT_SERIALIZATION_VERSION = 0;
4747

4848
static final String SAVED_NOTIFICATION_PRIMARY_KEY = "data";
@@ -134,25 +134,19 @@ private static boolean serializeNotificationCustom(Notification notification, Da
134134

135135
// serialize extras
136136
boolean showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN, false);
137-
byte[] extras = serializeParcelable(notification.extras);
138-
out.writeInt(extras == null ? 0 : extras.length);
139-
if (extras != null && extras.length > 0)
140-
out.write(extras);
141-
else {
142-
// parcelling may fail in case it contains binder object, when that happens serialize manually what we care about
143-
out.writeInt(notification.extras.getInt(KEY_ID));
144-
serializeString(out, notification.extras.getString(Notification.EXTRA_TITLE));
145-
serializeString(out, notification.extras.getString(Notification.EXTRA_TEXT));
146-
serializeString(out, notification.extras.getString(KEY_SMALL_ICON));
147-
serializeString(out, notification.extras.getString(KEY_LARGE_ICON));
148-
out.writeLong(notification.extras.getLong(KEY_FIRE_TIME, -1));
149-
out.writeLong(notification.extras.getLong(KEY_REPEAT_INTERVAL, -1));
150-
serializeString(out, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? null : notification.extras.getString(Notification.EXTRA_BIG_TEXT));
151-
out.writeBoolean(notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER, false));
152-
out.writeBoolean(showWhen);
153-
serializeString(out, notification.extras.getString(KEY_INTENT_DATA));
154-
out.writeBoolean(notification.extras.getBoolean(KEY_SHOW_IN_FOREGROUND, true));
155-
}
137+
138+
out.writeInt(notification.extras.getInt(KEY_ID));
139+
serializeString(out, notification.extras.getString(Notification.EXTRA_TITLE));
140+
serializeString(out, notification.extras.getString(Notification.EXTRA_TEXT));
141+
serializeString(out, notification.extras.getString(KEY_SMALL_ICON));
142+
serializeString(out, notification.extras.getString(KEY_LARGE_ICON));
143+
out.writeLong(notification.extras.getLong(KEY_FIRE_TIME, -1));
144+
out.writeLong(notification.extras.getLong(KEY_REPEAT_INTERVAL, -1));
145+
serializeString(out, Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? null : notification.extras.getString(Notification.EXTRA_BIG_TEXT));
146+
out.writeBoolean(notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER, false));
147+
out.writeBoolean(showWhen);
148+
serializeString(out, notification.extras.getString(KEY_INTENT_DATA));
149+
out.writeBoolean(notification.extras.getBoolean(KEY_SHOW_IN_FOREGROUND, true));
156150

157151
serializeString(out, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? null : notification.getChannelId());
158152
Integer color = UnityNotificationManager.getNotificationColor(notification);
@@ -285,12 +279,12 @@ private static Notification.Builder deserializeNotificationCustom(DataInputStrea
285279
long fireTime, repeatInterval;
286280
boolean usesStopWatch, showWhen, showInForeground = true;
287281
Bundle extras = null;
288-
try {
282+
if (version < 2) {
283+
// no longer serialized since v2
289284
extras = deserializeParcelable(in);
290-
} catch (ClassCastException cce) {
291-
Log.e(TAG_UNITY, "Unexpect type of deserialized object", cce);
292285
}
293286

287+
// before v2 it was extras or variables, since 2 always both
294288
if (extras == null) {
295289
// extras serialized manually
296290
id = in.readInt();

0 commit comments

Comments
 (0)