@@ -42,7 +42,7 @@ class UnityNotificationUtilities {
42
42
// magic stands for "Unity Mobile Notifications Notification"
43
43
static final byte [] UNITY_MAGIC_NUMBER = new byte [] { 'U' , 'M' , 'N' , 'N' };
44
44
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 ;
46
46
private static final int INTENT_SERIALIZATION_VERSION = 0 ;
47
47
48
48
static final String SAVED_NOTIFICATION_PRIMARY_KEY = "data" ;
@@ -134,25 +134,19 @@ private static boolean serializeNotificationCustom(Notification notification, Da
134
134
135
135
// serialize extras
136
136
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 ));
156
150
157
151
serializeString (out , Build .VERSION .SDK_INT < Build .VERSION_CODES .O ? null : notification .getChannelId ());
158
152
Integer color = UnityNotificationManager .getNotificationColor (notification );
@@ -285,12 +279,12 @@ private static Notification.Builder deserializeNotificationCustom(DataInputStrea
285
279
long fireTime , repeatInterval ;
286
280
boolean usesStopWatch , showWhen , showInForeground = true ;
287
281
Bundle extras = null ;
288
- try {
282
+ if (version < 2 ) {
283
+ // no longer serialized since v2
289
284
extras = deserializeParcelable (in );
290
- } catch (ClassCastException cce ) {
291
- Log .e (TAG_UNITY , "Unexpect type of deserialized object" , cce );
292
285
}
293
286
287
+ // before v2 it was extras or variables, since 2 always both
294
288
if (extras == null ) {
295
289
// extras serialized manually
296
290
id = in .readInt ();
0 commit comments