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

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
@@ -656,6 +656,7 @@ public final class JCoreWireCodec {
656
656
  return clientDecoded;
657
657
  }
658
658
  }
659
+ if ((flag & 1) != 0 && decrypted.length == 0) return null;
659
660
  body = decrypted;
660
661
  }
661
662
 
@@ -26,13 +26,24 @@ import cn.jiguang.plugins.push.JPushModule;
26
26
 
27
27
  public class JCoreModule extends ReactContextBaseJavaModule {
28
28
 
29
- public static ReactApplicationContext reactContext;
29
+ public static volatile ReactApplicationContext reactContext;
30
+ private boolean invalidated;
30
31
 
31
32
 
32
33
  public JCoreModule(ReactApplicationContext reactApplicationContext) {
33
34
  super(reactApplicationContext);
34
35
  reactContext = reactApplicationContext;
35
- JPushModule.registerReactContext(reactApplicationContext);
36
+ JPushModule.retainReactContext(reactApplicationContext);
37
+ }
38
+
39
+ @Override
40
+ public void invalidate() {
41
+ synchronized (this) {
42
+ if (invalidated) return;
43
+ invalidated = true;
44
+ }
45
+ JPushModule.releaseReactContext(getReactApplicationContext());
46
+ super.invalidate();
36
47
  }
37
48
 
38
49
  @Override
@@ -26,6 +26,7 @@ import java.util.Collections;
26
26
  import java.util.HashMap;
27
27
  import java.util.HashSet;
28
28
  import java.util.Set;
29
+ import java.util.Map;
29
30
  import java.util.concurrent.CopyOnWriteArraySet;
30
31
  import java.lang.*;
31
32
 
@@ -40,10 +41,13 @@ import cn.jpush.android.data.JPushLocalNotification;
40
41
 
41
42
  public class JPushModule extends ReactContextBaseJavaModule {
42
43
 
43
- public static ReactApplicationContext reactContext;
44
+ public static volatile ReactApplicationContext reactContext;
44
45
  private static final Set<ReactApplicationContext> ACTIVE_CONTEXTS =
45
46
  new CopyOnWriteArraySet<ReactApplicationContext>();
46
47
 
48
+ private static final Map<ReactApplicationContext, Integer> CONTEXT_OWNERS = new HashMap<ReactApplicationContext, Integer>();
49
+ private boolean invalidated;
50
+
47
51
  public static boolean isAppForeground = false;
48
52
 
49
53
  public static void registerReactContext(ReactApplicationContext ctx) {
@@ -56,11 +60,33 @@ public class JPushModule extends ReactContextBaseJavaModule {
56
60
  }
57
61
  }
58
62
 
63
+ public static void retainReactContext(ReactApplicationContext ctx) {
64
+ if (ctx == null) return;
65
+ synchronized (CONTEXT_OWNERS) {
66
+ Integer count = CONTEXT_OWNERS.get(ctx);
67
+ CONTEXT_OWNERS.put(ctx, count == null ? 1 : count + 1);
68
+ }
69
+ registerReactContext(ctx);
70
+ }
71
+
72
+ public static void releaseReactContext(ReactApplicationContext ctx) {
73
+ if (ctx == null) return;
74
+ synchronized (CONTEXT_OWNERS) {
75
+ Integer count = CONTEXT_OWNERS.get(ctx);
76
+ if (count != null && count > 1) { CONTEXT_OWNERS.put(ctx, count - 1); return; }
77
+ CONTEXT_OWNERS.remove(ctx);
78
+ ACTIVE_CONTEXTS.remove(ctx);
79
+ if (reactContext == ctx) reactContext = ACTIVE_CONTEXTS.isEmpty() ? null : ACTIVE_CONTEXTS.iterator().next();
80
+ if (cn.jiguang.plugins.core.JCoreModule.reactContext == ctx) cn.jiguang.plugins.core.JCoreModule.reactContext = reactContext;
81
+ }
82
+ }
83
+
59
84
  public static Set<ReactApplicationContext> getActiveReactContexts() {
60
85
  return Collections.unmodifiableSet(ACTIVE_CONTEXTS);
61
86
  }
62
87
 
63
88
  public static void clearActiveReactContexts() {
89
+ synchronized (CONTEXT_OWNERS) { CONTEXT_OWNERS.clear(); }
64
90
  ACTIVE_CONTEXTS.clear();
65
91
  reactContext = null;
66
92
  }
@@ -68,7 +94,17 @@ public class JPushModule extends ReactContextBaseJavaModule {
68
94
  public JPushModule(ReactApplicationContext reactApplicationContext) {
69
95
  super(reactApplicationContext);
70
96
  reactContext = reactApplicationContext;
71
- registerReactContext(reactApplicationContext);
97
+ retainReactContext(reactApplicationContext);
98
+ }
99
+
100
+ @Override
101
+ public void invalidate() {
102
+ synchronized (this) {
103
+ if (invalidated) return;
104
+ invalidated = true;
105
+ }
106
+ releaseReactContext(getReactApplicationContext());
107
+ super.invalidate();
72
108
  }
73
109
 
74
110
  @Override
@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
26
26
  import java.util.concurrent.CopyOnWriteArrayList;
27
27
  import java.util.concurrent.atomic.AtomicInteger;
28
28
 
29
+ import cn.jiguang.core.JCoreStorage;
29
30
  import cn.jiguang.plugins.push.JPushModule;
30
31
  import cn.jiguang.plugins.push.common.JConstants;
31
32
  import cn.jiguang.plugins.push.common.JLogger;
@@ -42,16 +43,19 @@ public class JPushHelper {
42
43
 
43
44
  private static final class PendingEvent {
44
45
  final String eventName;
46
+ final long contentGeneration;
45
47
  final WritableMap params;
46
48
  final Map<String, Object> mapParams;
47
49
 
48
- PendingEvent(String eventName, WritableMap params) {
50
+ PendingEvent(String eventName, WritableMap params, long contentGeneration) {
51
+ this.contentGeneration = contentGeneration;
49
52
  this.eventName = eventName;
50
53
  this.params = params;
51
54
  this.mapParams = null;
52
55
  }
53
56
 
54
- PendingEvent(String eventName, Map<String, Object> mapParams) {
57
+ PendingEvent(String eventName, Map<String, Object> mapParams, long contentGeneration) {
58
+ this.contentGeneration = contentGeneration;
55
59
  this.eventName = eventName;
56
60
  this.params = null;
57
61
  this.mapParams = mapParams != null
@@ -62,9 +66,11 @@ public class JPushHelper {
62
66
 
63
67
  private static final class PendingNitroEvent {
64
68
  final String eventName;
69
+ final long contentGeneration;
65
70
  final String payloadJson;
66
71
 
67
- PendingNitroEvent(String eventName, String payloadJson) {
72
+ PendingNitroEvent(String eventName, String payloadJson, long contentGeneration) {
73
+ this.contentGeneration = contentGeneration;
68
74
  this.eventName = eventName;
69
75
  this.payloadJson = payloadJson;
70
76
  }
@@ -121,6 +127,20 @@ public class JPushHelper {
121
127
  return s == null || s.length() == 0;
122
128
  }
123
129
 
130
+ private static boolean isContentEvent(String eventName) {
131
+ return JConstants.NOTIFICATION_EVENT.equals(eventName)
132
+ || JConstants.LOCAL_NOTIFICATION_EVENT.equals(eventName)
133
+ || JConstants.CUSTOM_MESSAGE_EVENT.equals(eventName)
134
+ || JConstants.INAPP_MESSAGE_EVENT.equals(eventName)
135
+ || JConstants.NOTIFY_BUTTON_CLICK_EVENT.equals(eventName);
136
+ }
137
+
138
+ private static boolean canDeliver(String eventName, long contentGeneration) {
139
+ Context context = JCoreStorage.getAppContext(null);
140
+ return !isContentEvent(eventName) || (contentGeneration == JCoreStorage.getContentGeneration()
141
+ && JCoreStorage.isCollectionAuth(context) && !JCoreStorage.isPushStopped(context));
142
+ }
143
+
124
144
  public static void flushPendingNitroEvents() {
125
145
  if (PENDING_NITRO_EVENTS.isEmpty() || NITRO_LISTENERS.isEmpty()) {
126
146
  return;
@@ -131,8 +151,9 @@ public class JPushHelper {
131
151
  if (pending == null || isEmpty(pending.eventName)) {
132
152
  continue;
133
153
  }
134
- for (NitroEventListener listener : NITRO_LISTENERS.values()) {
135
- if (listener != null) {
154
+ for (Map.Entry<Integer, NitroEventListener> entry : NITRO_LISTENERS.entrySet()) {
155
+ NitroEventListener listener = entry.getValue();
156
+ if (listener != null && NITRO_LISTENERS.get(entry.getKey()) == listener && canDeliver(pending.eventName, pending.contentGeneration)) {
136
157
  try {
137
158
  listener.onEvent(pending.eventName, pending.payloadJson);
138
159
  } catch (Throwable inner) {
@@ -166,6 +187,8 @@ public class JPushHelper {
166
187
  }
167
188
  }
168
189
  for (ReactApplicationContext ctx : targets) {
190
+ if (!canDeliver(pending.eventName, pending.contentGeneration)) break;
191
+ if (!getTargetContexts().contains(ctx)) continue;
169
192
  try {
170
193
  WritableMap payload = (total > 1 && index > 0)
171
194
  ? cloneWritableMap(baseWritable)
@@ -182,14 +205,16 @@ public class JPushHelper {
182
205
  }
183
206
 
184
207
  public static void sendEventMap(String eventName, Map<String, Object> params) {
185
- if (isEmpty(eventName)) {
208
+ long contentGeneration = JCoreStorage.getContentGeneration();
209
+ if (isEmpty(eventName) || !canDeliver(eventName, contentGeneration)) {
186
210
  return;
187
211
  }
188
212
  try {
189
213
  String payloadJson = mapToJsonString(params);
190
214
  if (!NITRO_LISTENERS.isEmpty()) {
191
- for (NitroEventListener listener : NITRO_LISTENERS.values()) {
192
- if (listener != null) {
215
+ for (Map.Entry<Integer, NitroEventListener> entry : NITRO_LISTENERS.entrySet()) {
216
+ NitroEventListener listener = entry.getValue();
217
+ if (listener != null && NITRO_LISTENERS.get(entry.getKey()) == listener && canDeliver(eventName, contentGeneration)) {
193
218
  try {
194
219
  listener.onEvent(eventName, payloadJson);
195
220
  } catch (Throwable inner) {
@@ -201,7 +226,7 @@ public class JPushHelper {
201
226
  if (PENDING_NITRO_EVENTS.size() >= 64) {
202
227
  PENDING_NITRO_EVENTS.remove(0);
203
228
  }
204
- PENDING_NITRO_EVENTS.add(new PendingNitroEvent(eventName, payloadJson));
229
+ PENDING_NITRO_EVENTS.add(new PendingNitroEvent(eventName, payloadJson, contentGeneration));
205
230
  }
206
231
 
207
232
  Set<ReactApplicationContext> targets = getTargetContexts();
@@ -214,6 +239,8 @@ public class JPushHelper {
214
239
  int index = 0;
215
240
  int total = targets.size();
216
241
  for (ReactApplicationContext ctx : targets) {
242
+ if (!canDeliver(eventName, contentGeneration)) break;
243
+ if (!getTargetContexts().contains(ctx)) continue;
217
244
  WritableMap payload = (total > 1 && index > 0) ? cloneWritableMap(writable) : writable;
218
245
  index++;
219
246
  ctx.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, payload);
@@ -226,7 +253,7 @@ public class JPushHelper {
226
253
  if (PENDING_EVENTS.size() >= 64) {
227
254
  PENDING_EVENTS.remove(0);
228
255
  }
229
- PENDING_EVENTS.add(new PendingEvent(eventName, params));
256
+ PENDING_EVENTS.add(new PendingEvent(eventName, params, contentGeneration));
230
257
  }
231
258
  } catch (Throwable throwable) {
232
259
  JLogger.e("sendEventMap error:" + throwable.getMessage());
@@ -250,14 +277,16 @@ public class JPushHelper {
250
277
  }
251
278
 
252
279
  public static void sendEvent(String eventName, WritableMap params) {
253
- if (isEmpty(eventName)) {
280
+ long contentGeneration = JCoreStorage.getContentGeneration();
281
+ if (isEmpty(eventName) || !canDeliver(eventName, contentGeneration)) {
254
282
  return;
255
283
  }
256
284
  try {
257
285
  String payloadJson = readableMapToJsonObject(params).toString();
258
286
  if (!NITRO_LISTENERS.isEmpty()) {
259
- for (NitroEventListener listener : NITRO_LISTENERS.values()) {
260
- if (listener != null) {
287
+ for (Map.Entry<Integer, NitroEventListener> entry : NITRO_LISTENERS.entrySet()) {
288
+ NitroEventListener listener = entry.getValue();
289
+ if (listener != null && NITRO_LISTENERS.get(entry.getKey()) == listener && canDeliver(eventName, contentGeneration)) {
261
290
  try {
262
291
  listener.onEvent(eventName, payloadJson);
263
292
  } catch (Throwable inner) {
@@ -269,7 +298,7 @@ public class JPushHelper {
269
298
  if (PENDING_NITRO_EVENTS.size() >= 64) {
270
299
  PENDING_NITRO_EVENTS.remove(0);
271
300
  }
272
- PENDING_NITRO_EVENTS.add(new PendingNitroEvent(eventName, payloadJson));
301
+ PENDING_NITRO_EVENTS.add(new PendingNitroEvent(eventName, payloadJson, contentGeneration));
273
302
  }
274
303
 
275
304
  Set<ReactApplicationContext> targets = getTargetContexts();
@@ -277,6 +306,8 @@ public class JPushHelper {
277
306
  int index = 0;
278
307
  int total = targets.size();
279
308
  for (ReactApplicationContext ctx : targets) {
309
+ if (!canDeliver(eventName, contentGeneration)) break;
310
+ if (!getTargetContexts().contains(ctx)) continue;
280
311
  try {
281
312
  WritableMap payload = (total > 1 && index > 0) ? cloneWritableMap(params) : params;
282
313
  index++;
@@ -291,7 +322,7 @@ public class JPushHelper {
291
322
  if (PENDING_EVENTS.size() >= 64) {
292
323
  PENDING_EVENTS.remove(0);
293
324
  }
294
- PENDING_EVENTS.add(new PendingEvent(eventName, cloneWritableMap(params)));
325
+ PENDING_EVENTS.add(new PendingEvent(eventName, cloneWritableMap(params), contentGeneration));
295
326
  }
296
327
  } catch (Throwable throwable) {
297
328
  JLogger.e("sendEvent error:" + throwable.getMessage());
@@ -88,9 +88,6 @@ public class JPushModuleReceiver extends JPushMessageReceiver {
88
88
  + notificationMessage.notificationId
89
89
  );
90
90
  }
91
- if (!JPushModule.isAppForeground) {
92
- JPushHelper.launchApp(context);
93
- }
94
91
  Map<String, Object> map = JPushHelper.convertNotificationToMapObject(JConstants.NOTIFICATION_OPENED, notificationMessage);
95
92
  if (notificationMessage != null && notificationMessage.notificationType == 1) {
96
93
  JPushHelper.sendEventMap(JConstants.LOCAL_NOTIFICATION_EVENT, map);
@@ -98,7 +98,6 @@ public class JPushInterface {
98
98
 
99
99
  public static void stopPush(Context context) {
100
100
  JCoreStorage.setPushStopped(context, true);
101
- ActionHelper.getInstance().setPushStatusWithCallBack(context, 4, 0);
102
101
  JCoreTcpEngine.getInstance().stop(context);
103
102
  }
104
103