@onekeyfe/react-native-jpush 6.7.0-alpha.449 → 6.7.0-alpha.464

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/android/fcm/src/test/java/com/onekey/jpush/fcm/FcmAdapterTest.java +212 -0
  2. package/android/src/main/cpp/cpp-adapter.cpp +41 -1
  3. package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +6 -9
  4. package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +14 -2
  5. package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +476 -348
  6. package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1 -0
  7. package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +13 -2
  8. package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +38 -2
  9. package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +46 -15
  10. package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +0 -3
  11. package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +0 -1
  12. package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +223 -272
  13. package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +1 -1
  14. package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +51 -16
  15. package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +76 -32
  16. package/ios/bridge/RCTJPushModule.m +215 -150
  17. package/ios/jcore/JCOREConfiguration.h +5 -0
  18. package/ios/jcore/JCOREConfiguration.m +44 -4
  19. package/ios/jcore/JCORECrypto.m +10 -12
  20. package/ios/jcore/JCORETcpSession.m +197 -45
  21. package/ios/jcore/JCOREWireProtocol.m +20 -7
  22. package/ios/jpush/JPUSHNotificationManager.m +7 -1
  23. package/ios/jpush/JPUSHService.m +7 -9
  24. package/package.json +1 -1
@@ -51,6 +51,7 @@ public class ActionHelper {
51
51
  public static final String DEFAULT_CHANNEL_ID = "jpush_default_channel";
52
52
  public static final String DEFAULT_SILENT_CHANNEL_ID = "jpush_silent_channel";
53
53
 
54
+ private static final String KEY_CONTENT_GENERATION = "jpush_content_generation";
54
55
  private static final String KEY_EVENT_TYPE = "jpush_event_type";
55
56
  private static final String KEY_SEQUENCE = "jpush_sequence";
56
57
  private static final String KEY_ERROR_CODE = "jpush_error_code";
@@ -114,6 +115,7 @@ public class ActionHelper {
114
115
  }
115
116
 
116
117
  public void doAction(Context context, String action, Object data) {
118
+ long contentGeneration = JCoreStorage.getContentGeneration();
117
119
  if (!(data instanceof Bundle) || JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context)) {
118
120
  return;
119
121
  }
@@ -143,6 +145,9 @@ public class ActionHelper {
143
145
  return;
144
146
  }
145
147
  message.notificationId = bundle.getInt("noti_id", message.notificationId);
148
+ if (contentGeneration != JCoreStorage.getContentGeneration() || !isContentAllowed(context)) {
149
+ return;
150
+ }
146
151
  if (JThirdPlatFormInterface.ACTION_PLUGIN_PALTFORM_ON_MESSAGING.equals(action)) {
147
152
  try {
148
153
  JSONObject json = new JSONObject(decoded);
@@ -160,17 +165,24 @@ public class ActionHelper {
160
165
  return;
161
166
  }
162
167
  postSystemNotification(context, message);
163
- dispatchNotificationEvent(context, "notify_arrived", message);
168
+ if (contentGeneration == JCoreStorage.getContentGeneration()) {
169
+ dispatchNotificationEvent(context, "notify_arrived", message);
170
+ }
164
171
  }
165
172
  } catch (Exception invalidMessage) {
166
173
  cn.jiguang.plugins.push.common.JLogger.w("FCM payload rejected");
167
174
  }
168
175
  } else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_ARRIVED.equals(action)) {
169
- recordNotificationPosted(context, message.notificationId);
176
+ synchronized (JCoreStorage.class) {
177
+ if (contentGeneration != JCoreStorage.getContentGeneration() || !isContentAllowed(context)) return;
178
+ recordNotificationPosted(context, message.notificationId);
179
+ }
170
180
  dispatchNotificationEvent(context, "notify_arrived", message);
171
181
  } else if (JThirdPlatFormInterface.ACTION_NOTIFICATION_CLCKED.equals(action)) {
172
- dispatchNotificationEvent(context, "notify_opened", message);
173
- broadcastNotificationOpened(context, message);
182
+ Intent click = new Intent(JPushInterface.ACTION_NOTIFICATION_OPENED);
183
+ click.setPackage(context.getPackageName());
184
+ click.putExtra("multi_notification_msg", message);
185
+ handleNotificationIntent(context, click);
174
186
  }
175
187
  }
176
188
 
@@ -201,8 +213,18 @@ public class ActionHelper {
201
213
  return null;
202
214
  }
203
215
 
216
+ private static boolean isContentAllowed(Context context) {
217
+ return !JCoreStorage.isPushStopped(context) && JCoreStorage.isCollectionAuth(context);
218
+ }
219
+
220
+ private static boolean isContentEvent(String eventType) {
221
+ return eventType != null && (eventType.startsWith("notify_")
222
+ || eventType.startsWith("inapp_") || "custom_msg".equals(eventType));
223
+ }
224
+
204
225
  public void handleNotificationIntent(Context context, Intent intent) {
205
- if (context == null || intent == null) {
226
+ long contentGeneration = JCoreStorage.getContentGeneration();
227
+ if (context == null || intent == null || !isContentAllowed(context)) {
206
228
  return;
207
229
  }
208
230
  try {
@@ -218,6 +240,9 @@ public class ActionHelper {
218
240
  && !appPkg.equals(targetPkg)) {
219
241
  return;
220
242
  }
243
+ if (intent.getComponent() != null && !appPkg.equals(intent.getComponent().getPackageName())) {
244
+ return;
245
+ }
221
246
  Serializable msg = intent.getSerializableExtra("multi_notification_msg");
222
247
  boolean fcmClick = !(msg instanceof NotificationMessage) && intent.hasExtra("JMessageExtra");
223
248
  if (fcmClick) {
@@ -232,19 +257,22 @@ public class ActionHelper {
232
257
  }
233
258
  if (msg instanceof NotificationMessage) {
234
259
  NotificationMessage notificationMessage = (NotificationMessage) msg;
235
- if (notificationMessage.platform == 8
236
- && (JCoreStorage.isPushStopped(context) || !JCoreStorage.isCollectionAuth(context))) {
260
+ if (notificationMessage.msgId == null || notificationMessage.msgId.isEmpty() || !isContentAllowed(context)
261
+ || contentGeneration != JCoreStorage.getContentGeneration()) {
237
262
  return;
238
263
  }
239
264
  dispatchNotificationEvent(context, "notify_opened", notificationMessage);
265
+ if (contentGeneration != JCoreStorage.getContentGeneration() || !isContentAllowed(context)) {
266
+ return;
267
+ }
240
268
  broadcastNotificationOpened(context, notificationMessage);
241
- if (fcmClick || notificationMessage.platform == 8) {
242
- android.content.pm.PackageManager manager = context.getPackageManager();
243
- Intent launcher = manager != null ? manager.getLaunchIntentForPackage(appPkg) : null;
244
- if (launcher != null) {
245
- launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
246
- context.startActivity(launcher);
247
- }
269
+ android.content.pm.PackageManager manager = context.getPackageManager();
270
+ Intent launcher = manager != null ? manager.getLaunchIntentForPackage(appPkg) : null;
271
+ if (launcher != null && launcher.getComponent() != null
272
+ && appPkg.equals(launcher.getComponent().getPackageName()) && isContentAllowed(context)
273
+ && contentGeneration == JCoreStorage.getContentGeneration()) {
274
+ launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
275
+ context.startActivity(launcher);
248
276
  }
249
277
  }
250
278
  } catch (Throwable ignored) {
@@ -253,7 +281,7 @@ public class ActionHelper {
253
281
 
254
282
  public void broadcastNotificationOpened(Context context, NotificationMessage message) {
255
283
  Context app = JCoreStorage.getAppContext(context);
256
- if (app == null || message == null) {
284
+ if (app == null || message == null || !isContentAllowed(app)) {
257
285
  return;
258
286
  }
259
287
  try {
@@ -336,7 +364,8 @@ public class ActionHelper {
336
364
  }
337
365
 
338
366
  public void postSystemNotification(Context context, NotificationMessage message) {
339
- if (message == null) {
367
+ long contentGeneration = JCoreStorage.getContentGeneration();
368
+ if (message == null || !isContentAllowed(context)) {
340
369
  return;
341
370
  }
342
371
  Context app = JCoreStorage.getAppContext(context);
@@ -351,7 +380,6 @@ public class ActionHelper {
351
380
  int notifyId = message.notificationId != 0
352
381
  ? message.notificationId
353
382
  : (message.msgId != null ? Math.abs(message.msgId.hashCode()) : 1);
354
- recordNotificationPosted(app, notifyId);
355
383
  if (app == null) {
356
384
  return;
357
385
  }
@@ -411,18 +439,23 @@ public class ActionHelper {
411
439
  if (Build.VERSION.SDK_INT >= 23) {
412
440
  flags |= PendingIntent.FLAG_IMMUTABLE;
413
441
  }
414
- PendingIntent pendingIntent = PendingIntent.getActivity(app, message.notificationId, clickIntent, flags);
415
- if (pendingIntent != null) {
416
- builder.setContentIntent(pendingIntent);
417
- }
418
-
419
442
  Notification notification = builder.build();
420
- nm.notify(notifyId, notification);
443
+ synchronized (JCoreStorage.class) {
444
+ if (contentGeneration != JCoreStorage.getContentGeneration() || !isContentAllowed(app)) return;
445
+ PendingIntent pendingIntent = PendingIntent.getActivity(app, message.notificationId, clickIntent, flags);
446
+ if (pendingIntent != null) notification.contentIntent = pendingIntent;
447
+ nm.notify(notifyId, notification);
448
+ recordNotificationPosted(app, notifyId);
449
+ }
421
450
  } catch (Throwable ignored) {
422
451
  }
423
452
  }
424
453
 
425
454
  public void handleDownlinkPushMessage(Context context, byte messageType, long messageId, String rawContent) {
455
+ long contentGeneration = JCoreStorage.getContentGeneration();
456
+ if (!isContentAllowed(context)) {
457
+ return;
458
+ }
426
459
  String content = rawContent != null ? rawContent : "";
427
460
  int lastNewline = content.lastIndexOf('\n');
428
461
  if (lastNewline >= 0 && lastNewline + 1 < content.length()) {
@@ -471,8 +504,13 @@ public class ActionHelper {
471
504
  JCoreWireCodec.extractJsonInt(content, "notificaion_type", 0)
472
505
  );
473
506
  notification.platform = JCoreWireCodec.extractJsonInt(content, "platform", 0);
507
+ if (contentGeneration != JCoreStorage.getContentGeneration() || !isContentAllowed(context)) {
508
+ return;
509
+ }
474
510
  postSystemNotification(context, notification);
475
- dispatchNotificationEvent(context, "notify_arrived", notification);
511
+ if (contentGeneration == JCoreStorage.getContentGeneration()) {
512
+ dispatchNotificationEvent(context, "notify_arrived", notification);
513
+ }
476
514
  return;
477
515
  }
478
516
 
@@ -490,7 +528,9 @@ public class ActionHelper {
490
528
  custom.contentType = JCoreWireCodec.extractJsonString(content, "content_type");
491
529
  custom.extra = extractJsonObjectAsString(content, "extras", "n_extras");
492
530
  custom.platform = (byte) JCoreWireCodec.extractJsonInt(content, "platform", 0);
493
- dispatchCustomMessageEvent(context, custom);
531
+ if (contentGeneration == JCoreStorage.getContentGeneration()) {
532
+ dispatchCustomMessageEvent(context, custom);
533
+ }
494
534
  }
495
535
 
496
536
  private static String extractJsonObjectAsString(String json, String primaryKey, String fallbackKey) {
@@ -538,35 +578,32 @@ public class ActionHelper {
538
578
  return sb.toString();
539
579
  }
540
580
 
541
- public void setAliasAndTagsWithCallBack(
542
- final Context context,
543
- final String alias,
544
- final Set<String> tags,
545
- final TagAliasCallback callback,
546
- int protoType,
547
- int action
548
- ) {
549
- JCoreTcpEngine.getInstance().executeAsync(new Runnable() {
550
- @Override
551
- public void run() {
552
- if (alias != null) {
553
- JCoreStorage.saveAlias(context, alias);
554
- }
555
- Set<String> validTags = JPushInterface.filterValidTags(tags);
556
- if (tags != null) {
557
- JCoreStorage.saveTags(context, validTags);
558
- }
559
- if (callback != null) {
560
- callback.gotResult(0, alias, validTags);
561
- }
562
- }
563
- });
564
- }
565
-
566
- private boolean shouldQueueOrWaitForServerAck() {
581
+ public void setAliasAndTagsWithCallBack(final Context context, final String alias, final Set<String> tags,
582
+ final TagAliasCallback callback, int protoType, int action) {
583
+ final Set<String> validTags = JPushInterface.filterValidTags(tags);
584
+ final java.util.concurrent.atomic.AtomicInteger remaining = new java.util.concurrent.atomic.AtomicInteger(
585
+ (alias != null ? 1 : 0) + (tags != null ? 1 : 0));
586
+ final java.util.concurrent.atomic.AtomicInteger error = new java.util.concurrent.atomic.AtomicInteger();
587
+ if (remaining.get() == 0) {
588
+ if (callback != null) callback.gotResult(0, alias, validTags);
589
+ return;
590
+ }
591
+ final Runnable finish = () -> {
592
+ if (remaining.decrementAndGet() == 0 && callback != null) callback.gotResult(error.get(), alias, validTags);
593
+ };
567
594
  JCoreTcpEngine engine = JCoreTcpEngine.getInstance();
568
- return engine.isRequireServerAckForOperations()
569
- || (!engine.isLoggedIn() && !engine.getCustomHost().isEmpty());
595
+ if (alias != null) engine.enqueueOrSendRequest(context, JCoreWireCodec.CMD_ALIAS_OP, JCoreWireCodec.VER_ALIAS_OP,
596
+ JCoreStorage.nextRid(), JCoreWireCodec.buildAliasOperationPayload(2, 0, alias), engine.getDefaultRequestTimeoutMs(), 0,
597
+ (frame, code) -> {
598
+ if (code == 0) JCoreStorage.saveAlias(context, alias); else error.compareAndSet(0, code);
599
+ finish.run();
600
+ });
601
+ if (tags != null) engine.enqueueOrSendRequest(context, JCoreWireCodec.CMD_TAG_OP, JCoreWireCodec.VER_TAG_OP,
602
+ JCoreStorage.nextRid(), JCoreWireCodec.buildTagOperationPayload(2, 0, validTags), engine.getDefaultRequestTimeoutMs(), 0,
603
+ (frame, code) -> {
604
+ if (code == 0) JCoreStorage.saveTags(context, validTags); else error.compareAndSet(0, code);
605
+ finish.run();
606
+ });
570
607
  }
571
608
 
572
609
  public void setAliasWithCallBack(
@@ -578,10 +615,7 @@ public class ActionHelper {
578
615
  ) {
579
616
  final String previousAlias = JCoreStorage.getAlias(context);
580
617
  String resolvedAlias = alias != null ? alias : "";
581
- if (action == 2) {
582
- JCoreStorage.saveAlias(context, resolvedAlias);
583
- } else if (action == 3) {
584
- JCoreStorage.saveAlias(context, "");
618
+ if (action == 3) {
585
619
  resolvedAlias = "";
586
620
  } else if (action == 5) {
587
621
  resolvedAlias = previousAlias;
@@ -589,69 +623,45 @@ public class ActionHelper {
589
623
  final String effectiveAlias = resolvedAlias;
590
624
 
591
625
  byte[] wireBody = JCoreWireCodec.buildAliasOperationPayload(action, sequence, effectiveAlias);
592
- if (shouldQueueOrWaitForServerAck()) {
593
- JCoreTcpEngine.getInstance().enqueueOrSendRequest(
594
- context,
595
- JCoreWireCodec.CMD_ALIAS_OP,
596
- JCoreWireCodec.VER_ALIAS_OP,
597
- sequence,
598
- wireBody,
599
- JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
600
- 0,
601
- new JCoreTcpEngine.RequestCallback() {
602
- @Override
603
- public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
604
- if (statusCode != 0 && (action == 2 || action == 3)) {
605
- JCoreStorage.saveAlias(context, previousAlias);
606
- }
607
- String resultAlias = effectiveAlias;
608
- if (statusCode == 0 && responseFrame != null && responseFrame.body != null && responseFrame.body.length > 0) {
609
- String respJson = JCoreWireCodec.parseJsonCommandBody(responseFrame.body);
610
- if (action == 5 && respJson.contains("\"alias\"")) {
611
- String srvAlias = JCoreWireCodec.extractJsonString(respJson, "alias");
612
- JCoreStorage.saveAlias(context, srvAlias);
613
- resultAlias = srvAlias;
614
- }
626
+
627
+ JCoreTcpEngine.getInstance().enqueueOrSendRequest(
628
+ context,
629
+ JCoreWireCodec.CMD_ALIAS_OP,
630
+ JCoreWireCodec.VER_ALIAS_OP,
631
+ JCoreStorage.nextRid(),
632
+ wireBody,
633
+ JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
634
+ 0,
635
+ new JCoreTcpEngine.RequestCallback() {
636
+ @Override
637
+ public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
638
+ if (statusCode == 0 && (action == 2 || action == 3)) {
639
+ JCoreStorage.saveAlias(context, effectiveAlias);
640
+ }
641
+ String resultAlias = effectiveAlias;
642
+ if (statusCode == 0 && responseFrame != null && responseFrame.body != null && responseFrame.body.length > 0) {
643
+ String respJson = JCoreWireCodec.parseJsonCommandBody(responseFrame.body);
644
+ if (action == 5 && respJson.contains("\"alias\"")) {
645
+ String srvAlias = JCoreWireCodec.extractJsonString(respJson, "alias");
646
+ JCoreStorage.saveAlias(context, srvAlias);
647
+ resultAlias = srvAlias;
615
648
  }
616
- Intent intent = buildBaseReceiverIntent(context, "alias_op", sequence, statusCode);
617
- intent.putExtra(KEY_ALIAS, resultAlias);
618
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
619
- JPushMessage msg = new JPushMessage();
620
- msg.setSequence(sequence);
621
- msg.setErrorCode(statusCode);
622
- msg.setAlias(resultAlias);
623
- for (JPushMessageReceiver receiver : registeredReceivers) {
624
- receiver.onAliasOperatorResult(context, msg);
625
- }
649
+ }
650
+ Intent intent = buildBaseReceiverIntent(context, "alias_op", sequence, statusCode);
651
+ intent.putExtra(KEY_ALIAS, resultAlias);
652
+ if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
653
+ JPushMessage msg = new JPushMessage();
654
+ msg.setSequence(sequence);
655
+ msg.setErrorCode(statusCode);
656
+ msg.setAlias(resultAlias);
657
+ for (JPushMessageReceiver receiver : registeredReceivers) {
658
+ receiver.onAliasOperatorResult(context, msg);
626
659
  }
627
- sendToReceiver(context, intent);
628
660
  }
661
+ sendToReceiver(context, intent);
629
662
  }
630
- );
631
- return;
632
- }
633
-
634
- JCoreTcpEngine.getInstance().sendFrameRaw(
635
- JCoreWireCodec.CMD_ALIAS_OP,
636
- JCoreWireCodec.VER_ALIAS_OP,
637
- sequence,
638
- JCoreTcpEngine.getInstance().getSessionId(),
639
- JCoreStorage.getUid(context),
640
- wireBody
641
- );
642
-
643
- Intent intent = buildBaseReceiverIntent(context, "alias_op", sequence, 0);
644
- intent.putExtra(KEY_ALIAS, effectiveAlias);
645
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
646
- JPushMessage msg = new JPushMessage();
647
- msg.setSequence(sequence);
648
- msg.setErrorCode(0);
649
- msg.setAlias(effectiveAlias);
650
- for (JPushMessageReceiver receiver : registeredReceivers) {
651
- receiver.onAliasOperatorResult(context, msg);
652
663
  }
653
- }
654
- sendToReceiver(context, intent);
664
+ );
655
665
  }
656
666
 
657
667
  public void setTagsWithCallBack(
@@ -663,55 +673,43 @@ public class ActionHelper {
663
673
  ) {
664
674
  final Set<String> validInput = JPushInterface.filterValidTags(tags);
665
675
  Set<String> stored = JCoreStorage.getTags(context);
666
- final Set<String> previousTags = new HashSet<String>(stored);
667
676
 
668
677
  if (action == 1) { // add
669
678
  stored.addAll(validInput);
670
- JCoreStorage.saveTags(context, stored);
671
679
  } else if (action == 2) { // set
672
680
  stored = new HashSet<String>(validInput);
673
- JCoreStorage.saveTags(context, stored);
674
681
  } else if (action == 3) { // delete
675
682
  stored.removeAll(validInput);
676
- JCoreStorage.saveTags(context, stored);
677
683
  } else if (action == 4) { // clean
678
684
  stored.clear();
679
- JCoreStorage.saveTags(context, stored);
680
685
  }
681
686
  final Set<String> finalStored = new HashSet<String>(stored);
682
687
 
683
688
  byte[] wireBody = JCoreWireCodec.buildTagOperationPayload(action, sequence, validInput);
684
- if (shouldQueueOrWaitForServerAck()) {
685
- JCoreTcpEngine.getInstance().enqueueOrSendRequest(
686
- context,
687
- JCoreWireCodec.CMD_TAG_OP,
688
- JCoreWireCodec.VER_TAG_OP,
689
- sequence,
690
- wireBody,
691
- JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
692
- 0,
693
- new JCoreTcpEngine.RequestCallback() {
694
- @Override
695
- public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
696
- if (statusCode != 0 && action >= 1 && action <= 4) {
697
- JCoreStorage.saveTags(context, previousTags);
698
- }
699
- dispatchTagResultIntent(context, sequence, action, statusCode, validInput, finalStored, responseFrame);
700
- }
701
- }
702
- );
703
- return;
704
- }
705
689
 
706
- JCoreTcpEngine.getInstance().sendFrameRaw(
690
+ JCoreTcpEngine.getInstance().enqueueOrSendRequest(
691
+ context,
707
692
  JCoreWireCodec.CMD_TAG_OP,
708
693
  JCoreWireCodec.VER_TAG_OP,
709
- sequence,
710
- JCoreTcpEngine.getInstance().getSessionId(),
711
- JCoreStorage.getUid(context),
712
- wireBody
694
+ JCoreStorage.nextRid(),
695
+ wireBody,
696
+ JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
697
+ 0,
698
+ new JCoreTcpEngine.RequestCallback() {
699
+ @Override
700
+ public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
701
+ if (statusCode == 0 && action >= 1 && action <= 4) {
702
+ Set<String> current = JCoreStorage.getTags(context);
703
+ if (action == 1) current.addAll(validInput);
704
+ else if (action == 2) current = new HashSet<String>(validInput);
705
+ else if (action == 3) current.removeAll(validInput);
706
+ else current.clear();
707
+ JCoreStorage.saveTags(context, current);
708
+ }
709
+ dispatchTagResultIntent(context, sequence, action, statusCode, validInput, finalStored, responseFrame);
710
+ }
711
+ }
713
712
  );
714
- dispatchTagResultIntent(context, sequence, action, 0, validInput, finalStored, null);
715
713
  }
716
714
 
717
715
  private static boolean parseJsonBindFlag(String respJson, boolean defaultBind) {
@@ -825,149 +823,95 @@ public class ActionHelper {
825
823
  int protoType,
826
824
  final int action
827
825
  ) {
826
+ final Map<String, Object> requestedProperties = properties != null ? new HashMap<String, Object>(properties) : null;
828
827
  Map<String, Object> stored = JCoreStorage.getProperties(context);
829
828
  final Map<String, Object> previousProps = new HashMap<String, Object>(stored);
830
- if (action == 1 && properties != null) {
831
- stored.putAll(properties);
832
- JCoreStorage.saveProperties(context, stored);
833
- } else if (action == 2 && properties != null) {
834
- for (String key : properties.keySet()) {
829
+ if (action == 1 && requestedProperties != null) {
830
+ stored.putAll(requestedProperties);
831
+ } else if (action == 2 && requestedProperties != null) {
832
+ for (String key : requestedProperties.keySet()) {
835
833
  stored.remove(key);
836
834
  }
837
- JCoreStorage.saveProperties(context, stored);
838
835
  } else if (action == 3) {
839
836
  stored.clear();
840
- JCoreStorage.saveProperties(context, stored);
841
837
  }
842
838
  final Map<String, Object> finalStored = new HashMap<String, Object>(stored);
843
839
 
844
- byte[] wireBody = JCoreWireCodec.buildPropertyOperationPayload(action, sequence, properties);
845
- if (shouldQueueOrWaitForServerAck()) {
846
- JCoreTcpEngine.getInstance().enqueueOrSendRequest(
847
- context,
848
- JCoreWireCodec.CMD_PROPERTY_OP,
849
- JCoreWireCodec.VER_PROPERTY_OP,
850
- sequence,
851
- wireBody,
852
- JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
853
- 0,
854
- new JCoreTcpEngine.RequestCallback() {
855
- @Override
856
- public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
857
- if (statusCode != 0) {
858
- JCoreStorage.saveProperties(context, previousProps);
859
- }
860
- Intent intent = buildBaseReceiverIntent(context, "property_op", sequence, statusCode);
861
- HashMap<String, Object> serializableProps = new HashMap<String, Object>();
862
- if ((action == 1 || action == 2) && properties != null) {
863
- serializableProps.putAll(properties);
864
- } else {
865
- serializableProps.putAll(statusCode == 0 ? finalStored : previousProps);
866
- }
867
- intent.putExtra(KEY_PROPS_MAP, serializableProps);
868
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
869
- JPushMessage msg = new JPushMessage();
870
- msg.setSequence(sequence);
871
- msg.setErrorCode(statusCode);
872
- msg.setPros(serializableProps);
873
- for (JPushMessageReceiver receiver : registeredReceivers) {
874
- receiver.onPropertyOperatorResult(context, msg);
875
- }
876
- }
877
- sendToReceiver(context, intent);
878
- }
879
- }
880
- );
881
- return;
882
- }
840
+ byte[] wireBody = JCoreWireCodec.buildPropertyOperationPayload(action, sequence, requestedProperties);
883
841
 
884
- JCoreTcpEngine.getInstance().sendFrameRaw(
842
+ JCoreTcpEngine.getInstance().enqueueOrSendRequest(
843
+ context,
885
844
  JCoreWireCodec.CMD_PROPERTY_OP,
886
845
  JCoreWireCodec.VER_PROPERTY_OP,
887
- sequence,
888
- JCoreTcpEngine.getInstance().getSessionId(),
889
- JCoreStorage.getUid(context),
890
- wireBody
891
- );
892
-
893
- Intent intent = buildBaseReceiverIntent(context, "property_op", sequence, 0);
894
- HashMap<String, Object> serializableProps = new HashMap<String, Object>();
895
- if ((action == 1 || action == 2) && properties != null) {
896
- serializableProps.putAll(properties);
897
- } else {
898
- serializableProps.putAll(finalStored);
899
- }
900
- intent.putExtra(KEY_PROPS_MAP, serializableProps);
901
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
902
- JPushMessage msg = new JPushMessage();
903
- msg.setSequence(sequence);
904
- msg.setErrorCode(0);
905
- msg.setPros(serializableProps);
906
- for (JPushMessageReceiver receiver : registeredReceivers) {
907
- receiver.onPropertyOperatorResult(context, msg);
846
+ JCoreStorage.nextRid(),
847
+ wireBody,
848
+ JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
849
+ 0,
850
+ new JCoreTcpEngine.RequestCallback() {
851
+ @Override
852
+ public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
853
+ if (statusCode == 0) {
854
+ Map<String, Object> current = JCoreStorage.getProperties(context);
855
+ if (action == 1 && requestedProperties != null) current.putAll(requestedProperties);
856
+ else if (action == 2 && requestedProperties != null) for (String key : requestedProperties.keySet()) current.remove(key);
857
+ else if (action == 3) current.clear();
858
+ JCoreStorage.saveProperties(context, current);
859
+ }
860
+ Intent intent = buildBaseReceiverIntent(context, "property_op", sequence, statusCode);
861
+ HashMap<String, Object> serializableProps = new HashMap<String, Object>();
862
+ if ((action == 1 || action == 2) && requestedProperties != null) {
863
+ serializableProps.putAll(requestedProperties);
864
+ } else {
865
+ serializableProps.putAll(statusCode == 0 ? finalStored : previousProps);
866
+ }
867
+ intent.putExtra(KEY_PROPS_MAP, serializableProps);
868
+ if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
869
+ JPushMessage msg = new JPushMessage();
870
+ msg.setSequence(sequence);
871
+ msg.setErrorCode(statusCode);
872
+ msg.setPros(serializableProps);
873
+ for (JPushMessageReceiver receiver : registeredReceivers) {
874
+ receiver.onPropertyOperatorResult(context, msg);
875
+ }
876
+ }
877
+ sendToReceiver(context, intent);
878
+ }
908
879
  }
909
- }
910
- sendToReceiver(context, intent);
880
+ );
911
881
  }
912
882
 
913
883
  public void setMobileNumberWithCallBack(final Context context, final int sequence, final String mobileNumber) {
914
- final String previousMobile = JCoreStorage.getMobileNumber(context);
915
- JCoreStorage.saveMobileNumber(context, mobileNumber);
916
884
  byte[] wireBody = JCoreWireCodec.buildMobileNumberPayload(sequence, mobileNumber);
917
- if (shouldQueueOrWaitForServerAck()) {
918
- JCoreTcpEngine.getInstance().enqueueOrSendRequest(
919
- context,
920
- JCoreWireCodec.CMD_MOBILE_NUMBER,
921
- JCoreWireCodec.VER_MOBILE_NUMBER,
922
- sequence,
923
- wireBody,
924
- JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
925
- 0,
926
- new JCoreTcpEngine.RequestCallback() {
927
- @Override
928
- public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
929
- if (statusCode != 0) {
930
- JCoreStorage.saveMobileNumber(context, previousMobile);
931
- }
932
- Intent intent = buildBaseReceiverIntent(context, "mobile_number_op", sequence, statusCode);
933
- intent.putExtra(KEY_MOBILE_NUMBER, mobileNumber != null ? mobileNumber : "");
934
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
935
- JPushMessage msg = new JPushMessage();
936
- msg.setSequence(sequence);
937
- msg.setErrorCode(statusCode);
938
- msg.setMobileNumber(mobileNumber != null ? mobileNumber : "");
939
- for (JPushMessageReceiver receiver : registeredReceivers) {
940
- receiver.onMobileNumberOperatorResult(context, msg);
941
- }
942
- }
943
- sendToReceiver(context, intent);
944
- }
945
- }
946
- );
947
- return;
948
- }
949
885
 
950
- JCoreTcpEngine.getInstance().sendFrameRaw(
886
+ JCoreTcpEngine.getInstance().enqueueOrSendRequest(
887
+ context,
951
888
  JCoreWireCodec.CMD_MOBILE_NUMBER,
952
889
  JCoreWireCodec.VER_MOBILE_NUMBER,
953
- sequence,
954
- JCoreTcpEngine.getInstance().getSessionId(),
955
- JCoreStorage.getUid(context),
956
- wireBody
957
- );
958
-
959
- Intent intent = buildBaseReceiverIntent(context, "mobile_number_op", sequence, 0);
960
- intent.putExtra(KEY_MOBILE_NUMBER, mobileNumber != null ? mobileNumber : "");
961
- if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
962
- JPushMessage msg = new JPushMessage();
963
- msg.setSequence(sequence);
964
- msg.setErrorCode(0);
965
- msg.setMobileNumber(mobileNumber != null ? mobileNumber : "");
966
- for (JPushMessageReceiver receiver : registeredReceivers) {
967
- receiver.onMobileNumberOperatorResult(context, msg);
890
+ JCoreStorage.nextRid(),
891
+ wireBody,
892
+ JCoreTcpEngine.getInstance().getDefaultRequestTimeoutMs(),
893
+ 0,
894
+ new JCoreTcpEngine.RequestCallback() {
895
+ @Override
896
+ public void onResult(JCoreWireCodec.DecodedFrame responseFrame, int statusCode) {
897
+ if (statusCode == 0) {
898
+ JCoreStorage.saveMobileNumber(context, mobileNumber);
899
+ }
900
+ Intent intent = buildBaseReceiverIntent(context, "mobile_number_op", sequence, statusCode);
901
+ intent.putExtra(KEY_MOBILE_NUMBER, mobileNumber != null ? mobileNumber : "");
902
+ if (intent.getStringExtra(KEY_EVENT_TYPE) == null) {
903
+ JPushMessage msg = new JPushMessage();
904
+ msg.setSequence(sequence);
905
+ msg.setErrorCode(statusCode);
906
+ msg.setMobileNumber(mobileNumber != null ? mobileNumber : "");
907
+ for (JPushMessageReceiver receiver : registeredReceivers) {
908
+ receiver.onMobileNumberOperatorResult(context, msg);
909
+ }
910
+ }
911
+ sendToReceiver(context, intent);
912
+ }
968
913
  }
969
- }
970
- sendToReceiver(context, intent);
914
+ );
971
915
  }
972
916
 
973
917
  public void setThirdTokenWithCallBack(
@@ -1006,7 +950,7 @@ public class ActionHelper {
1006
950
  public void setPushStatusWithCallBack(Context context, int protoType, int action) {
1007
951
  boolean stopped = (action == 0);
1008
952
  byte[] wireBody = JCoreWireCodec.buildPushControlPayload(stopped);
1009
- if (!stopped && shouldQueueOrWaitForServerAck()) {
953
+ if (!stopped) {
1010
954
  JCoreTcpEngine.getInstance().enqueueOrSendRequest(
1011
955
  context,
1012
956
  JCoreWireCodec.CMD_PUSH_CTRL,
@@ -1087,7 +1031,7 @@ public class ActionHelper {
1087
1031
  }
1088
1032
 
1089
1033
  public void dispatchNotificationEvent(Context context, String eventType, NotificationMessage message) {
1090
- if (message == null) {
1034
+ if (message == null || !isContentAllowed(context)) {
1091
1035
  return;
1092
1036
  }
1093
1037
  Intent intent = buildBaseReceiverIntent(context, eventType, 0, 0);
@@ -1096,7 +1040,7 @@ public class ActionHelper {
1096
1040
  }
1097
1041
 
1098
1042
  public void dispatchCustomMessageEvent(Context context, CustomMessage message) {
1099
- if (message == null) {
1043
+ if (message == null || !isContentAllowed(context)) {
1100
1044
  return;
1101
1045
  }
1102
1046
  Intent intent = buildBaseReceiverIntent(context, "custom_msg", 0, 0);
@@ -1117,6 +1061,9 @@ public class ActionHelper {
1117
1061
  } catch (Throwable ignored) {
1118
1062
  }
1119
1063
  }
1064
+ if (isContentEvent(eventType)) {
1065
+ intent.putExtra(KEY_CONTENT_GENERATION, JCoreStorage.getContentGeneration());
1066
+ }
1120
1067
  intent.putExtra(KEY_EVENT_TYPE, eventType);
1121
1068
  intent.putExtra(KEY_SEQUENCE, sequence);
1122
1069
  intent.putExtra(KEY_ERROR_CODE, errorCode);
@@ -1151,6 +1098,10 @@ public class ActionHelper {
1151
1098
  if (eventType == null) {
1152
1099
  return;
1153
1100
  }
1101
+ if (isContentEvent(eventType) && (!isContentAllowed(context)
1102
+ || intent.getLongExtra(KEY_CONTENT_GENERATION, JCoreStorage.getContentGeneration()) != JCoreStorage.getContentGeneration())) {
1103
+ return;
1104
+ }
1154
1105
  int sequence = intent.getIntExtra(KEY_SEQUENCE, 0);
1155
1106
  int errorCode = intent.getIntExtra(KEY_ERROR_CODE, 0);
1156
1107