@@ -58,9 +58,8 @@ private static boolean isGcmMessage(Intent intent) {
58
58
59
59
@ Override
60
60
public void onReceive (Context context , Intent intent ) {
61
- // Google Play services started sending an extra non-ordered broadcast with the mBundle:
62
- // { "COM": "RST_FULL", "from": "google.com/iid" }
63
- // Result codes are not valid with non-ordered broadcasts so omit it to prevent errors to the logcat.
61
+ // Do not process token update messages here.
62
+ // They are also non-ordered broadcasts.
64
63
Bundle bundle = intent .getExtras ();
65
64
if (bundle == null || "google.com/iid" .equals (bundle .getString ("from" )))
66
65
return ;
@@ -120,18 +119,19 @@ private static ProcessedBundleResult processOrderBroadcast(Context context, Inte
120
119
}
121
120
122
121
private static void startGCMService (Context context , Bundle bundle ) {
123
- BundleCompat taskExtras = BundleCompatFactory .getInstance ();
124
- taskExtras .putString ("json_payload" , NotificationBundleProcessor .bundleAsJSONObject (bundle ).toString ());
125
- taskExtras .putLong ("timestamp" , System .currentTimeMillis () / 1000L );
122
+ BundleCompat taskExtras ;
126
123
127
124
// If no remote resources have to be downloaded don't create a job which could add some delay.
128
125
if (!NotificationBundleProcessor .hasRemoteResource (bundle )) {
126
+ taskExtras = setCompatBundleForServer (bundle , BundleCompatFactory .getInstance ());
129
127
NotificationBundleProcessor .ProcessFromGCMIntentService (context , taskExtras , null );
130
128
return ;
131
129
}
132
130
133
131
boolean isHighPriority = Integer .parseInt (bundle .getString ("pri" , "0" )) > 9 ;
134
132
if (!isHighPriority && Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
133
+ taskExtras = setCompatBundleForServer (bundle , BundleCompatFactory .getInstance ());
134
+
135
135
ComponentName componentName = new ComponentName (context .getPackageName (),
136
136
GcmIntentJobService .class .getName ());
137
137
Random random = new Random ();
@@ -150,10 +150,18 @@ private static void startGCMService(Context context, Bundle bundle) {
150
150
else {
151
151
ComponentName componentName = new ComponentName (context .getPackageName (),
152
152
GcmIntentService .class .getName ());
153
+
154
+ taskExtras = setCompatBundleForServer (bundle , new BundleCompatBundle ());
153
155
Intent intentForService = new Intent ()
154
156
.replaceExtras ((Bundle )taskExtras .getBundle ())
155
157
.setComponent (componentName );
156
158
startWakefulService (context , intentForService );
157
159
}
158
160
}
161
+
162
+ private static BundleCompat setCompatBundleForServer (Bundle bundle , BundleCompat taskExtras ) {
163
+ taskExtras .putString ("json_payload" , NotificationBundleProcessor .bundleAsJSONObject (bundle ).toString ());
164
+ taskExtras .putLong ("timestamp" , System .currentTimeMillis () / 1000L );
165
+ return taskExtras ;
166
+ }
159
167
}
0 commit comments